Skip to content

Commit e3fdd5b

Browse files
committed
Add provider_tracking_fixture_tests
Signed-off-by: Lukasz Dorau <[email protected]>
1 parent fa49dae commit e3fdd5b

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

test/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,11 @@ if(LINUX AND (NOT UMF_DISABLE_HWLOC)) # OS-specific functions are implemented
347347
NAME provider_tracking
348348
SRCS provider_tracking.cpp
349349
LIBS ${UMF_UTILS_FOR_TEST})
350+
add_umf_test(
351+
NAME provider_tracking_fixture_tests
352+
SRCS provider_tracking_fixture_tests.cpp malloc_compliance_tests.cpp
353+
${BA_SOURCES_FOR_TEST}
354+
LIBS ${UMF_UTILS_FOR_TEST})
350355

351356
# This test requires Linux-only file memory provider
352357
if(UMF_POOL_JEMALLOC_ENABLED)
+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright (C) 2025 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/memory_provider.h>
6+
#include <umf/pools/pool_proxy.h>
7+
#include <umf/providers/provider_file_memory.h>
8+
9+
#include "base.hpp"
10+
#include "provider.hpp"
11+
12+
#include "cpp_helpers.hpp"
13+
#include "test_helpers.h"
14+
#ifndef _WIN32
15+
#include "test_helpers_linux.h"
16+
#endif
17+
18+
#include "poolFixtures.hpp"
19+
20+
#define FILE_PATH ((char *)"tmp_file")
21+
22+
struct provider_from_pool : public umf_test::provider_base_t {
23+
umf_memory_pool_handle_t pool;
24+
umf_result_t initialize(umf_memory_pool_handle_t _pool) noexcept {
25+
if (!_pool) {
26+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
27+
}
28+
pool = _pool;
29+
return UMF_RESULT_SUCCESS;
30+
}
31+
umf_result_t alloc(size_t size, size_t align, void **ptr) noexcept {
32+
*ptr = umfPoolAlignedMalloc(pool, size, align);
33+
return (*ptr) ? UMF_RESULT_SUCCESS
34+
: UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
35+
}
36+
umf_result_t free(void *ptr, size_t) noexcept {
37+
return umfPoolFree(pool, ptr);
38+
}
39+
const char *get_name() noexcept { return "provider_from_pool"; }
40+
41+
virtual ~provider_from_pool() {
42+
if (pool) {
43+
umfPoolDestroy(pool);
44+
pool = nullptr;
45+
}
46+
}
47+
};
48+
49+
umf_memory_provider_ops_t PROVIDER_FROM_POOL_OPS =
50+
umf::providerMakeCOps<provider_from_pool, umf_memory_pool_t>();
51+
52+
static void *providerFromPoolParamsCreate(void) {
53+
umf_file_memory_provider_params_handle_t paramsFile = NULL;
54+
umf_result_t umf_result =
55+
umfFileMemoryProviderParamsCreate(&paramsFile, FILE_PATH);
56+
EXPECT_EQ(umf_result, UMF_RESULT_SUCCESS);
57+
EXPECT_NE(paramsFile, nullptr);
58+
59+
umf_memory_provider_handle_t providerFile = nullptr;
60+
umf_result = umfMemoryProviderCreate(umfFileMemoryProviderOps(), paramsFile,
61+
&providerFile);
62+
EXPECT_EQ(umf_result, UMF_RESULT_SUCCESS);
63+
EXPECT_NE(providerFile, nullptr);
64+
65+
umf_memory_pool_handle_t poolProxyFile = nullptr;
66+
umf_result =
67+
umfPoolCreate(umfProxyPoolOps(), providerFile, nullptr,
68+
UMF_POOL_CREATE_FLAG_OWN_PROVIDER, &poolProxyFile);
69+
EXPECT_EQ(umf_result, UMF_RESULT_SUCCESS);
70+
EXPECT_NE(poolProxyFile, nullptr);
71+
72+
umf_result = umfFileMemoryProviderParamsDestroy(paramsFile);
73+
EXPECT_EQ(umf_result, UMF_RESULT_SUCCESS);
74+
paramsFile = nullptr;
75+
76+
return poolProxyFile;
77+
}
78+
79+
// TESTS
80+
81+
INSTANTIATE_TEST_SUITE_P(TrackingProviderPoolTest, umfPoolTest,
82+
::testing::Values(poolCreateExtParams{
83+
umfProxyPoolOps(), nullptr, nullptr,
84+
&PROVIDER_FROM_POOL_OPS,
85+
providerFromPoolParamsCreate, nullptr}));
86+
87+
INSTANTIATE_TEST_SUITE_P(TrackingProviderMultiPoolTest, umfMultiPoolTest,
88+
::testing::Values(poolCreateExtParams{
89+
umfProxyPoolOps(), nullptr, nullptr,
90+
&PROVIDER_FROM_POOL_OPS,
91+
providerFromPoolParamsCreate, nullptr}));

0 commit comments

Comments
 (0)