Skip to content

Commit 4b668af

Browse files
committed
Add optional coarse provider to umfPoolTest fixture
Add optional coarse provider to umfPoolTest fixture. Add 5th argument (coarse_memory_provider_params_t *) to the poolCreateExtParams tuple (can be nullptr). If it is non-nullptr, coarse provider is created with the given provider as the upstream provider. It will be used to test the following providers: - file provider - devdax provider as the upstream providers with the coarse provider and different pool managers. Signed-off-by: Lukasz Dorau <[email protected]>
1 parent 2e740f6 commit 4b668af

File tree

6 files changed

+51
-20
lines changed

6 files changed

+51
-20
lines changed

test/memoryPoolAPI.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,16 @@ TEST_F(test, BasicPoolByPtrTest) {
181181
INSTANTIATE_TEST_SUITE_P(
182182
mallocPoolTest, umfPoolTest,
183183
::testing::Values(poolCreateExtParams{&MALLOC_POOL_OPS, nullptr,
184-
&UMF_NULL_PROVIDER_OPS, nullptr},
184+
&UMF_NULL_PROVIDER_OPS, nullptr,
185+
nullptr},
185186
poolCreateExtParams{umfProxyPoolOps(), nullptr,
186-
&MALLOC_PROVIDER_OPS, nullptr}));
187+
&MALLOC_PROVIDER_OPS, nullptr,
188+
nullptr}));
187189

188190
INSTANTIATE_TEST_SUITE_P(mallocMultiPoolTest, umfMultiPoolTest,
189191
::testing::Values(poolCreateExtParams{
190192
umfProxyPoolOps(), nullptr, &MALLOC_PROVIDER_OPS,
191-
nullptr}));
193+
nullptr, nullptr}));
192194

193195
INSTANTIATE_TEST_SUITE_P(umfPoolWithCreateFlagsTest, umfPoolWithCreateFlagsTest,
194196
::testing::Values(0,

test/poolFixtures.hpp

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
// Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

5-
#ifndef UMF_TEST_MEMORY_POOL_OPS_HPP
6-
#define UMF_TEST_MEMORY_POOL_OPS_HPP
5+
#ifndef UMF_TEST_POOL_FIXTURES_HPP
6+
#define UMF_TEST_POOL_FIXTURES_HPP 1
77

88
#include "pool.hpp"
99
#include "provider.hpp"
10+
#include "umf/providers/provider_coarse.h"
1011

1112
#include <array>
1213
#include <cstring>
@@ -17,21 +18,46 @@
1718

1819
#include "../malloc_compliance_tests.hpp"
1920

20-
using poolCreateExtParams = std::tuple<umf_memory_pool_ops_t *, void *,
21-
umf_memory_provider_ops_t *, void *>;
21+
using poolCreateExtParams =
22+
std::tuple<umf_memory_pool_ops_t *, void *, umf_memory_provider_ops_t *,
23+
void *, void *>;
2224

2325
umf::pool_unique_handle_t poolCreateExtUnique(poolCreateExtParams params) {
24-
umf_memory_pool_handle_t hPool;
25-
auto [pool_ops, pool_params, provider_ops, provider_params] = params;
26+
auto [pool_ops, pool_params, provider_ops, provider_params, coarse_params] =
27+
params;
2628

29+
umf_memory_provider_handle_t upstream_provider = nullptr;
2730
umf_memory_provider_handle_t provider = nullptr;
28-
auto ret =
29-
umfMemoryProviderCreate(provider_ops, provider_params, &provider);
31+
umf_memory_pool_handle_t hPool = nullptr;
32+
umf_result_t ret;
33+
34+
ret = umfMemoryProviderCreate(provider_ops, provider_params,
35+
&upstream_provider);
3036
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
37+
EXPECT_NE(upstream_provider, nullptr);
38+
39+
provider = upstream_provider;
40+
41+
if (coarse_params) {
42+
coarse_memory_provider_params_t *coarse_memory_provider_params =
43+
(coarse_memory_provider_params_t *)coarse_params;
44+
coarse_memory_provider_params->upstream_memory_provider =
45+
upstream_provider;
46+
coarse_memory_provider_params->destroy_upstream_memory_provider = true;
47+
48+
umf_memory_provider_handle_t coarse_provider = nullptr;
49+
ret = umfMemoryProviderCreate(umfCoarseMemoryProviderOps(),
50+
coarse_params, &coarse_provider);
51+
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
52+
EXPECT_NE(coarse_provider, nullptr);
53+
54+
provider = coarse_provider;
55+
}
3156

3257
ret = umfPoolCreate(pool_ops, provider, pool_params,
3358
UMF_POOL_CREATE_FLAG_OWN_PROVIDER, &hPool);
3459
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
60+
EXPECT_NE(hPool, nullptr);
3561

3662
return umf::pool_unique_handle_t(hPool, &umfPoolDestroy);
3763
}
@@ -407,4 +433,4 @@ TEST_P(umfPoolTest, realloc_compliance) {
407433

408434
TEST_P(umfPoolTest, free_compliance) { free_compliance_test(pool.get()); }
409435

410-
#endif /* UMF_TEST_MEMORY_POOL_OPS_HPP */
436+
#endif /* UMF_TEST_POOL_FIXTURES_HPP */

test/pools/disjoint_pool.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,17 @@ auto defaultPoolConfig = poolConfig();
148148
INSTANTIATE_TEST_SUITE_P(disjointPoolTests, umfPoolTest,
149149
::testing::Values(poolCreateExtParams{
150150
umfDisjointPoolOps(), (void *)&defaultPoolConfig,
151-
&MALLOC_PROVIDER_OPS, nullptr}));
151+
&MALLOC_PROVIDER_OPS, nullptr, nullptr}));
152152

153153
INSTANTIATE_TEST_SUITE_P(
154154
disjointPoolTests, umfMemTest,
155155
::testing::Values(std::make_tuple(
156156
poolCreateExtParams{umfDisjointPoolOps(), (void *)&defaultPoolConfig,
157157
&MOCK_OUT_OF_MEM_PROVIDER_OPS,
158-
(void *)&defaultPoolConfig.Capacity},
158+
(void *)&defaultPoolConfig.Capacity, nullptr},
159159
static_cast<int>(defaultPoolConfig.Capacity) / 2)));
160160

161161
INSTANTIATE_TEST_SUITE_P(disjointMultiPoolTests, umfMultiPoolTest,
162162
::testing::Values(poolCreateExtParams{
163163
umfDisjointPoolOps(), (void *)&defaultPoolConfig,
164-
&MALLOC_PROVIDER_OPS, nullptr}));
164+
&MALLOC_PROVIDER_OPS, nullptr, nullptr}));

test/pools/jemalloc_pool.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ auto defaultParams = umfOsMemoryProviderParamsDefault();
1515
INSTANTIATE_TEST_SUITE_P(jemallocPoolTest, umfPoolTest,
1616
::testing::Values(poolCreateExtParams{
1717
umfJemallocPoolOps(), nullptr,
18-
umfOsMemoryProviderOps(), &defaultParams}));
18+
umfOsMemoryProviderOps(), &defaultParams,
19+
nullptr}));
1920

2021
// this test makes sure that jemalloc does not use
2122
// memory provider to allocate metadata (and hence
@@ -30,8 +31,9 @@ TEST_F(test, metadataNotAllocatedUsingProvider) {
3031
auto params = umfOsMemoryProviderParamsDefault();
3132
params.protection = UMF_PROTECTION_NONE;
3233

33-
auto pool = poolCreateExtUnique(
34-
{umfJemallocPoolOps(), nullptr, umfOsMemoryProviderOps(), &params});
34+
auto pool =
35+
poolCreateExtUnique({umfJemallocPoolOps(), nullptr,
36+
umfOsMemoryProviderOps(), &params, nullptr});
3537

3638
std::vector<std::shared_ptr<void>> allocs;
3739
for (size_t i = 0; i < numAllocs; i++) {

test/pools/pool_base_alloc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ umf_memory_pool_ops_t BA_POOL_OPS = umf::poolMakeCOps<base_alloc_pool, void>();
4848
INSTANTIATE_TEST_SUITE_P(baPool, umfPoolTest,
4949
::testing::Values(poolCreateExtParams{
5050
&BA_POOL_OPS, nullptr,
51-
&umf_test::BASE_PROVIDER_OPS, nullptr}));
51+
&umf_test::BASE_PROVIDER_OPS, nullptr, nullptr}));

test/pools/scalable_pool.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ auto defaultParams = umfOsMemoryProviderParamsDefault();
1212
INSTANTIATE_TEST_SUITE_P(scalablePoolTest, umfPoolTest,
1313
::testing::Values(poolCreateExtParams{
1414
umfScalablePoolOps(), nullptr,
15-
umfOsMemoryProviderOps(), &defaultParams}));
15+
umfOsMemoryProviderOps(), &defaultParams,
16+
nullptr}));

0 commit comments

Comments
 (0)