Skip to content

Commit 94eb254

Browse files
committed
Add the jemalloc_pool_coarse_file test
Signed-off-by: Lukasz Dorau <[email protected]>
1 parent 0721d4d commit 94eb254

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

test/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ if(UMF_BUILD_LIBUMF_POOL_JEMALLOC AND (NOT UMF_DISABLE_HWLOC))
182182
NAME jemalloc_pool
183183
SRCS pools/jemalloc_pool.cpp malloc_compliance_tests.cpp
184184
LIBS jemalloc_pool)
185+
# This tests requires Linux-only file memory provider.
186+
if(LINUX)
187+
add_umf_test(
188+
NAME jemalloc_pool_coarse_file
189+
SRCS pools/jemalloc_pool_coarse_file.cpp malloc_compliance_tests.cpp
190+
LIBS jemalloc_pool)
191+
endif()
185192
endif()
186193

187194
if(UMF_POOL_SCALABLE_ENABLED AND (NOT UMF_DISABLE_HWLOC))
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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/providers/provider_coarse.h"
7+
#include "umf/providers/provider_file_memory.h"
8+
9+
#include "pool.hpp"
10+
#include "poolFixtures.hpp"
11+
12+
using umf_test::test;
13+
using namespace umf_test;
14+
15+
#define INIT_BUFFER_SIZE 4096
16+
#define FILE_PATH ((char *)"/tmp/file_provider")
17+
18+
umf_memory_provider_handle_t getFileProvider(void) {
19+
umf_memory_provider_handle_t FileProvider = nullptr;
20+
auto defaultFileParams = umfFileMemoryProviderParamsDefault(FILE_PATH);
21+
(void)umfMemoryProviderCreate(umfFileMemoryProviderOps(),
22+
&defaultFileParams, &FileProvider);
23+
return FileProvider;
24+
}
25+
26+
coarse_memory_provider_params_t
27+
getCoarseParams(umf_memory_provider_handle_t upstream_memory_provider,
28+
size_t init_buffer_size) {
29+
coarse_memory_provider_params_t coarse_memory_provider_params;
30+
// make sure there are no undefined members - prevent a UB
31+
memset(&coarse_memory_provider_params, 0,
32+
sizeof(coarse_memory_provider_params));
33+
coarse_memory_provider_params.upstream_memory_provider =
34+
upstream_memory_provider;
35+
coarse_memory_provider_params.immediate_init_from_upstream = true;
36+
coarse_memory_provider_params.init_buffer = NULL;
37+
coarse_memory_provider_params.init_buffer_size = init_buffer_size;
38+
39+
return coarse_memory_provider_params;
40+
}
41+
42+
auto coarseParams = getCoarseParams(getFileProvider(), INIT_BUFFER_SIZE);
43+
INSTANTIATE_TEST_SUITE_P(jemallocPoolTest, umfPoolTest,
44+
::testing::Values(poolCreateExtParams{
45+
umfJemallocPoolOps(), nullptr,
46+
umfCoarseMemoryProviderOps(), &coarseParams}));

0 commit comments

Comments
 (0)