Skip to content

Commit b2b5e95

Browse files
committed
Add the pool_coarse_file test
Add the pool_coarse_file test that tests the coarse provider with upstream file provider and two pool managers: jemalloc and scalable pool. Signed-off-by: Lukasz Dorau <[email protected]>
1 parent f4b83c2 commit b2b5e95

File tree

2 files changed

+61
-4
lines changed

2 files changed

+61
-4
lines changed

test/CMakeLists.txt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ if(UMF_BUILD_LIBUMF_POOL_DISJOINT)
168168
endif()
169169

170170
if(UMF_BUILD_LIBUMF_POOL_DISJOINT
171-
AND UMF_BUILD_LIBUMF_POOL_JEMALLOC
171+
AND UMF_POOL_JEMALLOC_ENABLED
172172
AND UMF_POOL_SCALABLE_ENABLED
173173
AND (NOT UMF_DISABLE_HWLOC))
174174
add_umf_test(
@@ -177,7 +177,7 @@ if(UMF_BUILD_LIBUMF_POOL_DISJOINT
177177
LIBS disjoint_pool jemalloc_pool ${JEMALLOC_LIBRARIES})
178178
endif()
179179

180-
if(UMF_BUILD_LIBUMF_POOL_JEMALLOC AND (NOT UMF_DISABLE_HWLOC))
180+
if(UMF_POOL_JEMALLOC_ENABLED AND (NOT UMF_DISABLE_HWLOC))
181181
add_umf_test(
182182
NAME jemalloc_pool
183183
SRCS pools/jemalloc_pool.cpp malloc_compliance_tests.cpp
@@ -190,8 +190,7 @@ if(UMF_POOL_SCALABLE_ENABLED AND (NOT UMF_DISABLE_HWLOC))
190190
endif()
191191

192192
if(LINUX AND (NOT UMF_DISABLE_HWLOC)) # OS-specific functions are implemented
193-
# only for
194-
# Linux now
193+
# only for Linux now
195194
if(PkgConfig_FOUND)
196195
pkg_check_modules(LIBNUMA numa)
197196
endif()
@@ -257,6 +256,15 @@ if(LINUX AND (NOT UMF_DISABLE_HWLOC)) # OS-specific functions are implemented
257256
NAME provider_file_memory
258257
SRCS provider_file_memory.cpp
259258
LIBS ${UMF_UTILS_FOR_TEST})
259+
260+
# This test requires Linux-only file memory provider
261+
if(UMF_POOL_JEMALLOC_ENABLED AND UMF_POOL_SCALABLE_ENABLED)
262+
add_umf_test(
263+
NAME pool_coarse_file
264+
SRCS pools/pool_coarse_file.cpp malloc_compliance_tests.cpp
265+
LIBS jemalloc_pool)
266+
endif()
267+
260268
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND UMF_BUILD_FUZZTESTS)
261269
add_subdirectory(fuzz)
262270
endif()

test/pools/pool_coarse_file.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (C) 2024 Intel Corporation
2+
// Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
3+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
#include "umf/pools/pool_jemalloc.h"
6+
#include "umf/pools/pool_scalable.h"
7+
#include "umf/providers/provider_coarse.h"
8+
#include "umf/providers/provider_file_memory.h"
9+
10+
#include "pool.hpp"
11+
#include "poolFixtures.hpp"
12+
13+
using umf_test::test;
14+
using namespace umf_test;
15+
16+
#define INIT_BUFFER_SIZE 4096
17+
#define FILE_PATH ((char *)"/tmp/file_provider")
18+
19+
coarse_memory_provider_params_t getCoarseParams(size_t init_buffer_size) {
20+
coarse_memory_provider_params_t coarse_memory_provider_params;
21+
22+
// make sure there are no undefined members - prevent a UB
23+
memset(&coarse_memory_provider_params, 0,
24+
sizeof(coarse_memory_provider_params));
25+
26+
// upstream_memory_provider will be set later in umfPoolTest
27+
coarse_memory_provider_params.upstream_memory_provider = nullptr;
28+
coarse_memory_provider_params.immediate_init_from_upstream = true;
29+
coarse_memory_provider_params.init_buffer = nullptr;
30+
coarse_memory_provider_params.init_buffer_size = init_buffer_size;
31+
coarse_memory_provider_params.destroy_upstream_memory_provider = true;
32+
33+
return coarse_memory_provider_params;
34+
}
35+
36+
auto coarseParams = getCoarseParams(INIT_BUFFER_SIZE);
37+
auto fileParams = umfFileMemoryProviderParamsDefault(FILE_PATH);
38+
39+
INSTANTIATE_TEST_SUITE_P(jemallocCoarseFileTest, umfPoolTest,
40+
::testing::Values(poolCreateExtParams{
41+
umfJemallocPoolOps(), nullptr,
42+
umfFileMemoryProviderOps(), &fileParams,
43+
&coarseParams}));
44+
45+
INSTANTIATE_TEST_SUITE_P(scalableCoarseFileTest, umfPoolTest,
46+
::testing::Values(poolCreateExtParams{
47+
umfScalablePoolOps(), nullptr,
48+
umfFileMemoryProviderOps(), &fileParams,
49+
&coarseParams}));

0 commit comments

Comments
 (0)