Skip to content

Commit 910c9f8

Browse files
vinser52ldorau
authored andcommitted
Enable jemalloc pool test with Fixed provider
1 parent de5f8c0 commit 910c9f8

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

test/pools/jemalloc_pool.cpp

Lines changed: 35 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,42 @@ 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+
size_t memory_size = (1 << 30);
34+
static void_unique_ptr memory_buffer =
35+
void_unique_ptr(malloc(memory_size), free);
36+
if (memory_buffer.get() == NULL) {
37+
throw std::runtime_error(
38+
"Failed to allocate memory for Fixed memory provider");
39+
}
40+
41+
umf_fixed_memory_provider_params_handle_t params = nullptr;
42+
umf_result_t res = umfFixedMemoryProviderParamsCreate(
43+
&params, memory_buffer.get(), memory_size);
44+
if (res != UMF_RESULT_SUCCESS) {
45+
throw std::runtime_error(
46+
"Failed to create Fixed memory provider params");
47+
}
48+
49+
return params;
50+
}
51+
52+
umf_result_t destroyFixedMemoryProviderParams(void *params) {
53+
return umfFixedMemoryProviderParamsDestroy(
54+
(umf_fixed_memory_provider_params_handle_t)params);
55+
}
56+
3357
INSTANTIATE_TEST_SUITE_P(
3458
jemallocPoolTest, umfPoolTest,
35-
::testing::Values(poolCreateExtParams{
36-
umfJemallocPoolOps(), nullptr, nullptr, umfOsMemoryProviderOps(),
37-
createOsMemoryProviderParams, destroyOsMemoryProviderParams}));
59+
::testing::Values(poolCreateExtParams{umfJemallocPoolOps(), nullptr,
60+
nullptr, umfOsMemoryProviderOps(),
61+
createOsMemoryProviderParams,
62+
destroyOsMemoryProviderParams},
63+
poolCreateExtParams{umfJemallocPoolOps(), nullptr,
64+
nullptr, umfFixedMemoryProviderOps(),
65+
createFixedMemoryProviderParams,
66+
destroyFixedMemoryProviderParams}));
3867

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

0 commit comments

Comments
 (0)