Skip to content

Commit 1c7bc25

Browse files
authored
Merge pull request #1193 from ldorau/Enable_jemalloc_pool_test_with_Fixed_provider
Enable jemalloc pool test with Fixed provider
2 parents de5f8c0 + 8cd3383 commit 1c7bc25

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

test/pools/jemalloc_pool.cpp

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
using umf_test::test;
1212
using namespace umf_test;
1313

14-
using os_params_unique_handle_t =
15-
std::unique_ptr<umf_os_memory_provider_params_t,
16-
decltype(&umfOsMemoryProviderParamsDestroy)>;
14+
using void_unique_ptr = std::unique_ptr<void, decltype(&free)>;
1715

1816
void *createOsMemoryProviderParams() {
1917
umf_os_memory_provider_params_handle_t params = nullptr;
@@ -30,11 +28,43 @@ umf_result_t destroyOsMemoryProviderParams(void *params) {
3028
(umf_os_memory_provider_params_handle_t)params);
3129
}
3230

31+
void *createFixedMemoryProviderParams() {
32+
// Allocate a memory buffer to use with the fixed memory provider.
33+
// The umfPoolTest.malloc_compliance test requires a lot of memory.
34+
size_t memory_size = (1UL << 31);
35+
static void_unique_ptr memory_buffer =
36+
void_unique_ptr(malloc(memory_size), free);
37+
if (memory_buffer.get() == NULL) {
38+
throw std::runtime_error(
39+
"Failed to allocate memory for Fixed memory provider");
40+
}
41+
42+
umf_fixed_memory_provider_params_handle_t params = nullptr;
43+
umf_result_t res = umfFixedMemoryProviderParamsCreate(
44+
&params, memory_buffer.get(), memory_size);
45+
if (res != UMF_RESULT_SUCCESS) {
46+
throw std::runtime_error(
47+
"Failed to create Fixed memory provider params");
48+
}
49+
50+
return params;
51+
}
52+
53+
umf_result_t destroyFixedMemoryProviderParams(void *params) {
54+
return umfFixedMemoryProviderParamsDestroy(
55+
(umf_fixed_memory_provider_params_handle_t)params);
56+
}
57+
3358
INSTANTIATE_TEST_SUITE_P(
3459
jemallocPoolTest, umfPoolTest,
35-
::testing::Values(poolCreateExtParams{
36-
umfJemallocPoolOps(), nullptr, nullptr, umfOsMemoryProviderOps(),
37-
createOsMemoryProviderParams, destroyOsMemoryProviderParams}));
60+
::testing::Values(poolCreateExtParams{umfJemallocPoolOps(), nullptr,
61+
nullptr, umfOsMemoryProviderOps(),
62+
createOsMemoryProviderParams,
63+
destroyOsMemoryProviderParams},
64+
poolCreateExtParams{umfJemallocPoolOps(), nullptr,
65+
nullptr, umfFixedMemoryProviderOps(),
66+
createFixedMemoryProviderParams,
67+
destroyFixedMemoryProviderParams}));
3868

3969
// this test makes sure that jemalloc does not use
4070
// memory provider to allocate metadata (and hence

0 commit comments

Comments
 (0)