Skip to content

Commit 7017fe7

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 3be7e4a commit 7017fe7

File tree

6 files changed

+39
-17
lines changed

6 files changed

+39
-17
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: 23 additions & 6 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,18 +18,34 @@
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) {
2426
umf_memory_pool_handle_t hPool;
25-
auto [pool_ops, pool_params, provider_ops, provider_params] = params;
27+
auto [pool_ops, pool_params, provider_ops, provider_params, coarse_params] =
28+
params;
2629

2730
umf_memory_provider_handle_t provider = nullptr;
2831
auto ret =
2932
umfMemoryProviderCreate(provider_ops, provider_params, &provider);
3033
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
3134

35+
if (coarse_params) {
36+
coarse_memory_provider_params_t *coarse_memory_provider_params =
37+
(coarse_memory_provider_params_t *)coarse_params;
38+
coarse_memory_provider_params->upstream_memory_provider = provider;
39+
coarse_memory_provider_params->destroy_upstream_memory_provider = true;
40+
41+
umf_memory_provider_handle_t coarse_provider = nullptr;
42+
auto ret = umfMemoryProviderCreate(umfCoarseMemoryProviderOps(),
43+
coarse_params, &coarse_provider);
44+
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
45+
46+
provider = coarse_provider;
47+
}
48+
3249
ret = umfPoolCreate(pool_ops, provider, pool_params,
3350
UMF_POOL_CREATE_FLAG_OWN_PROVIDER, &hPool);
3451
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
@@ -407,4 +424,4 @@ TEST_P(umfPoolTest, realloc_compliance) {
407424

408425
TEST_P(umfPoolTest, free_compliance) { free_compliance_test(pool.get()); }
409426

410-
#endif /* UMF_TEST_MEMORY_POOL_OPS_HPP */
427+
#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)