Skip to content

Commit e213cbe

Browse files
committed
Enable jemalloc pool test with Fixed provider
1 parent de5f8c0 commit e213cbe

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

test/pools/jemalloc_pool.cpp

Lines changed: 37 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,44 @@ umf_result_t destroyOsMemoryProviderParams(void *params) {
3028
(umf_os_memory_provider_params_handle_t)params);
3129
}
3230

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

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

0 commit comments

Comments
 (0)