Skip to content

Commit d14149a

Browse files
committed
[tests] Add test for creation a pool with NULL params
1 parent fe14e00 commit d14149a

File tree

2 files changed

+137
-0
lines changed

2 files changed

+137
-0
lines changed

test/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ if(UMF_POOL_SCALABLE_ENABLED AND (NOT UMF_DISABLE_HWLOC))
269269
NAME scalable_pool
270270
SRCS pools/scalable_pool.cpp malloc_compliance_tests.cpp
271271
LIBS ${UMF_UTILS_FOR_TEST} ${UMF_BA_FOR_TEST})
272+
add_umf_test(
273+
NAME test_pool_null_params
274+
SRCS test_pool_null_params.cpp
275+
LIBS ${UMF_UTILS_FOR_TEST})
272276
endif()
273277

274278
if(LINUX AND (NOT UMF_DISABLE_HWLOC)) # OS-specific functions are implemented

test/test_pool_null_params.cpp

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
* Copyright (C) 2024-2025 Intel Corporation
3+
*
4+
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*/
7+
8+
#include <gtest/gtest.h>
9+
#include <umf/memory_pool.h>
10+
#include <umf/memory_provider.h>
11+
#include <umf/pools/pool_disjoint.h>
12+
#include <umf/pools/pool_jemalloc.h>
13+
#include <umf/pools/pool_proxy.h>
14+
#include <umf/pools/pool_scalable.h>
15+
16+
// Use correct macro for provider ops version
17+
#define UMF_MEMORY_PROVIDER_OPS_VERSION_CURRENT UMF_PROVIDER_OPS_VERSION_CURRENT
18+
19+
// Dummy provider implementation for testing
20+
typedef umf_result_t (*dummy_fn)();
21+
static umf_result_t dummy_provider_initialize(const void *, void **out) {
22+
*out = (void *)0x1;
23+
return UMF_RESULT_SUCCESS;
24+
}
25+
static umf_result_t dummy_provider_finalize(void *) {
26+
return UMF_RESULT_SUCCESS;
27+
}
28+
static umf_result_t dummy_alloc(void *, size_t, size_t, void **ptr) {
29+
*ptr = malloc(4096);
30+
return *ptr ? UMF_RESULT_SUCCESS : UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
31+
}
32+
static umf_result_t dummy_free(void *, void *, size_t) {
33+
return UMF_RESULT_SUCCESS;
34+
}
35+
static umf_result_t dummy_get_min_page_size(void *, const void *, size_t *out) {
36+
*out = 4096;
37+
return UMF_RESULT_SUCCESS;
38+
}
39+
static umf_result_t dummy_get_last_native_error(void *, const char **msg,
40+
int32_t *err) {
41+
if (msg) {
42+
*msg = "none";
43+
}
44+
if (err) {
45+
*err = 0;
46+
}
47+
return UMF_RESULT_SUCCESS;
48+
}
49+
static umf_result_t dummy_get_recommended_page_size(void *, size_t,
50+
size_t *out) {
51+
if (out) {
52+
*out = 4096;
53+
}
54+
return UMF_RESULT_SUCCESS;
55+
}
56+
static umf_result_t dummy_get_name(void *, const char **out) {
57+
if (out) {
58+
*out = "dummy";
59+
}
60+
return UMF_RESULT_SUCCESS;
61+
}
62+
63+
static umf_memory_provider_ops_t dummy_provider_ops = {
64+
UMF_MEMORY_PROVIDER_OPS_VERSION_CURRENT, // version
65+
dummy_provider_initialize, // initialize
66+
dummy_provider_finalize, // finalize
67+
dummy_alloc, // alloc
68+
dummy_free, // free
69+
dummy_get_last_native_error, // get_last_native_error
70+
dummy_get_recommended_page_size, // get_recommended_page_size
71+
dummy_get_min_page_size, // get_min_page_size
72+
dummy_get_name, // get_name
73+
NULL, // ext_purge_lazy
74+
NULL, // ext_purge_force
75+
NULL, // ext_allocation_merge
76+
NULL, // ext_allocation_split
77+
NULL, // ext_get_ipc_handle_size
78+
NULL, // ext_get_ipc_handle
79+
NULL, // ext_put_ipc_handle
80+
NULL, // ext_open_ipc_handle
81+
NULL, // ext_close_ipc_handle
82+
NULL // ext_ctl
83+
};
84+
85+
class PoolNullParamsTest : public ::testing::Test {
86+
protected:
87+
umf_memory_provider_handle_t provider = NULL;
88+
void SetUp() override {
89+
ASSERT_EQ(umfMemoryProviderCreate(&dummy_provider_ops, NULL, &provider),
90+
UMF_RESULT_SUCCESS);
91+
}
92+
void TearDown() override {
93+
if (provider) {
94+
umfMemoryProviderDestroy(provider);
95+
}
96+
}
97+
};
98+
99+
TEST_F(PoolNullParamsTest, DisjointPoolNullParams) {
100+
umf_memory_pool_handle_t pool;
101+
umf_result_t res =
102+
umfPoolCreate(umfDisjointPoolOps(), provider, NULL, 0, &pool);
103+
ASSERT_EQ(res, UMF_RESULT_SUCCESS);
104+
umfPoolDestroy(pool);
105+
}
106+
107+
TEST_F(PoolNullParamsTest, ScalablePoolNullParams) {
108+
umf_memory_pool_handle_t pool;
109+
umf_result_t res =
110+
umfPoolCreate(umfScalablePoolOps(), provider, NULL, 0, &pool);
111+
ASSERT_EQ(res, UMF_RESULT_SUCCESS);
112+
umfPoolDestroy(pool);
113+
}
114+
115+
TEST_F(PoolNullParamsTest, JemallocPoolNullParams) {
116+
#ifdef UMF_POOL_JEMALLOC_ENABLED
117+
umf_memory_pool_handle_t pool;
118+
umf_result_t res =
119+
umfPoolCreate(umfJemallocPoolOps(), provider, NULL, 0, &pool);
120+
ASSERT_EQ(res, UMF_RESULT_SUCCESS);
121+
umfPoolDestroy(pool);
122+
#else
123+
GTEST_SKIP() << "Jemalloc pool not enabled, skipping.";
124+
#endif
125+
}
126+
127+
TEST_F(PoolNullParamsTest, ProxyPoolNullParams) {
128+
umf_memory_pool_handle_t pool;
129+
umf_result_t res =
130+
umfPoolCreate(umfProxyPoolOps(), provider, NULL, 0, &pool);
131+
ASSERT_EQ(res, UMF_RESULT_SUCCESS);
132+
umfPoolDestroy(pool);
133+
}

0 commit comments

Comments
 (0)