Skip to content

Commit

Permalink
Add the jemalloc_pool_coarse_file test
Browse files Browse the repository at this point in the history
Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
  • Loading branch information
ldorau committed Oct 15, 2024
1 parent 0721d4d commit 94eb254
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ if(UMF_BUILD_LIBUMF_POOL_JEMALLOC AND (NOT UMF_DISABLE_HWLOC))
NAME jemalloc_pool
SRCS pools/jemalloc_pool.cpp malloc_compliance_tests.cpp
LIBS jemalloc_pool)
# This tests requires Linux-only file memory provider.
if(LINUX)
add_umf_test(
NAME jemalloc_pool_coarse_file
SRCS pools/jemalloc_pool_coarse_file.cpp malloc_compliance_tests.cpp
LIBS jemalloc_pool)
endif()
endif()

if(UMF_POOL_SCALABLE_ENABLED AND (NOT UMF_DISABLE_HWLOC))
Expand Down
46 changes: 46 additions & 0 deletions test/pools/jemalloc_pool_coarse_file.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (C) 2024 Intel Corporation
// Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include "umf/pools/pool_jemalloc.h"
#include "umf/providers/provider_coarse.h"
#include "umf/providers/provider_file_memory.h"

#include "pool.hpp"
#include "poolFixtures.hpp"

using umf_test::test;
using namespace umf_test;

#define INIT_BUFFER_SIZE 4096
#define FILE_PATH ((char *)"/tmp/file_provider")

umf_memory_provider_handle_t getFileProvider(void) {
umf_memory_provider_handle_t FileProvider = nullptr;
auto defaultFileParams = umfFileMemoryProviderParamsDefault(FILE_PATH);
(void)umfMemoryProviderCreate(umfFileMemoryProviderOps(),
&defaultFileParams, &FileProvider);
return FileProvider;
}

coarse_memory_provider_params_t
getCoarseParams(umf_memory_provider_handle_t upstream_memory_provider,
size_t init_buffer_size) {
coarse_memory_provider_params_t coarse_memory_provider_params;
// make sure there are no undefined members - prevent a UB
memset(&coarse_memory_provider_params, 0,
sizeof(coarse_memory_provider_params));
coarse_memory_provider_params.upstream_memory_provider =
upstream_memory_provider;
coarse_memory_provider_params.immediate_init_from_upstream = true;
coarse_memory_provider_params.init_buffer = NULL;
coarse_memory_provider_params.init_buffer_size = init_buffer_size;

return coarse_memory_provider_params;
}

auto coarseParams = getCoarseParams(getFileProvider(), INIT_BUFFER_SIZE);
INSTANTIATE_TEST_SUITE_P(jemallocPoolTest, umfPoolTest,
::testing::Values(poolCreateExtParams{
umfJemallocPoolOps(), nullptr,
umfCoarseMemoryProviderOps(), &coarseParams}));

0 comments on commit 94eb254

Please sign in to comment.