|
8 | 8 | #include "pool.hpp"
|
9 | 9 | #include "poolFixtures.hpp"
|
10 | 10 |
|
| 11 | +using umf_test::test; |
| 12 | +using namespace umf_test; |
| 13 | + |
11 | 14 | auto defaultParams = umfOsMemoryProviderParamsDefault();
|
12 | 15 | INSTANTIATE_TEST_SUITE_P(jemallocPoolTest, umfPoolTest,
|
13 | 16 | ::testing::Values(poolCreateExtParams{
|
14 | 17 | &UMF_JEMALLOC_POOL_OPS, nullptr,
|
15 | 18 | &UMF_OS_MEMORY_PROVIDER_OPS, &defaultParams}));
|
| 19 | + |
| 20 | +// this test makes sure that jemalloc does not use |
| 21 | +// memory provider to allocate metadata (and hence |
| 22 | +// is suitable for cases where memory is not accessible |
| 23 | +// on the host) |
| 24 | +TEST_F(test, metadataNotAllocatedUsingProvider) { |
| 25 | + static constexpr size_t allocSize = 1024; |
| 26 | + static constexpr size_t numAllocs = 1024; |
| 27 | + |
| 28 | + // set coarse grain allocations to PROT_NONE so that we can be sure |
| 29 | + // jemalloc does not touch any of the allocated memory |
| 30 | + auto params = umfOsMemoryProviderParamsDefault(); |
| 31 | + params.protection = UMF_PROTECTION_NONE; |
| 32 | + |
| 33 | + auto pool = poolCreateExtUnique({&UMF_JEMALLOC_POOL_OPS, nullptr, |
| 34 | + &UMF_OS_MEMORY_PROVIDER_OPS, ¶ms}); |
| 35 | + |
| 36 | + std::vector<std::shared_ptr<void>> allocs; |
| 37 | + for (size_t i = 0; i < numAllocs; i++) { |
| 38 | + allocs.emplace_back( |
| 39 | + umfPoolMalloc(pool.get(), allocSize), |
| 40 | + [pool = pool.get()](void *ptr) { umfPoolFree(pool, ptr); }); |
| 41 | + } |
| 42 | +} |
0 commit comments