Changeset View
Changeset View
Standalone View
Standalone View
src/test/allocator_tests.cpp
Show First 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | #endif | ||||
for (int x = 0; x < 2048; ++x) { | for (int x = 0; x < 2048; ++x) { | ||||
b.free(addr[((x * 23) % 2048) ^ 242]); | b.free(addr[((x * 23) % 2048) ^ 242]); | ||||
} | } | ||||
addr.clear(); | addr.clear(); | ||||
// Go entirely wild: free and alloc interleaved, generate targets and sizes | // Go entirely wild: free and alloc interleaved, generate targets and sizes | ||||
// using pseudo-randomness. | // using pseudo-randomness. | ||||
for (int x = 0; x < 2048; ++x) { | for (int x = 0; x < 2048; ++x) { | ||||
addr.push_back(0); | addr.push_back(nullptr); | ||||
} | } | ||||
uint32_t s = 0x12345678; | uint32_t s = 0x12345678; | ||||
for (int x = 0; x < 5000; ++x) { | for (int x = 0; x < 5000; ++x) { | ||||
int idx = s & (addr.size() - 1); | int idx = s & (addr.size() - 1); | ||||
if (s & 0x80000000) { | if (s & 0x80000000) { | ||||
b.free(addr[idx]); | b.free(addr[idx]); | ||||
addr[idx] = 0; | addr[idx] = nullptr; | ||||
} else if (!addr[idx]) { | } else if (!addr[idx]) { | ||||
addr[idx] = b.alloc((s >> 16) & 2047); | addr[idx] = b.alloc((s >> 16) & 2047); | ||||
} | } | ||||
bool lsb = s & 1; | bool lsb = s & 1; | ||||
s >>= 1; | s >>= 1; | ||||
// LFSR period 0xf7ffffe0 | // LFSR period 0xf7ffffe0 | ||||
if (lsb) { | if (lsb) { | ||||
s ^= 0xf00f00f0; | s ^= 0xf00f00f0; | ||||
Show All 21 Lines | void *AllocateLocked(size_t len, bool *lockingSuccess) override { | ||||
if (lockedcount > 0) { | if (lockedcount > 0) { | ||||
--lockedcount; | --lockedcount; | ||||
*lockingSuccess = true; | *lockingSuccess = true; | ||||
} | } | ||||
// Fake address, do not actually use this memory | // Fake address, do not actually use this memory | ||||
return reinterpret_cast<void *>(0x08000000 + (count << 24)); | return reinterpret_cast<void *>(0x08000000 + (count << 24)); | ||||
} | } | ||||
return 0; | return nullptr; | ||||
} | } | ||||
void FreeLocked(void *addr, size_t len) override {} | void FreeLocked(void *addr, size_t len) override {} | ||||
size_t GetLimit() override { return std::numeric_limits<size_t>::max(); } | size_t GetLimit() override { return std::numeric_limits<size_t>::max(); } | ||||
private: | private: | ||||
int count; | int count; | ||||
int lockedcount; | int lockedcount; | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 74 Lines • Show Last 20 Lines |