Changeset View
Changeset View
Standalone View
Standalone View
src/test/allocator_tests.cpp
Show First 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | #endif | ||||
BOOST_CHECK(b.stats().free == synth_size); | BOOST_CHECK(b.stats().free == synth_size); | ||||
} | } | ||||
/** Mock LockedPageAllocator for testing */ | /** Mock LockedPageAllocator for testing */ | ||||
class TestLockedPageAllocator : public LockedPageAllocator { | class TestLockedPageAllocator : public LockedPageAllocator { | ||||
public: | public: | ||||
TestLockedPageAllocator(int count_in, int lockedcount_in) | TestLockedPageAllocator(int count_in, int lockedcount_in) | ||||
: count(count_in), lockedcount(lockedcount_in) {} | : count(count_in), lockedcount(lockedcount_in) {} | ||||
void *AllocateLocked(size_t len, bool *lockingSuccess) { | void *AllocateLocked(size_t len, bool *lockingSuccess) override { | ||||
*lockingSuccess = false; | *lockingSuccess = false; | ||||
if (count > 0) { | if (count > 0) { | ||||
--count; | --count; | ||||
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 0; | ||||
} | } | ||||
void FreeLocked(void *addr, size_t len) {} | void FreeLocked(void *addr, size_t len) override {} | ||||
size_t GetLimit() { 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; | ||||
}; | }; | ||||
BOOST_AUTO_TEST_CASE(lockedpool_tests_mock) { | BOOST_AUTO_TEST_CASE(lockedpool_tests_mock) { | ||||
// Test over three virtual arenas, of which one will succeed being locked | // Test over three virtual arenas, of which one will succeed being locked | ||||
▲ Show 20 Lines • Show All 71 Lines • Show Last 20 Lines |