Skip to content

Add optional coarse provider to umfPoolTest fixture #808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions test/memoryPoolAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,16 @@ TEST_F(test, BasicPoolByPtrTest) {
INSTANTIATE_TEST_SUITE_P(
mallocPoolTest, umfPoolTest,
::testing::Values(poolCreateExtParams{&MALLOC_POOL_OPS, nullptr,
&UMF_NULL_PROVIDER_OPS, nullptr},
&UMF_NULL_PROVIDER_OPS, nullptr,
nullptr},
poolCreateExtParams{umfProxyPoolOps(), nullptr,
&MALLOC_PROVIDER_OPS, nullptr}));
&MALLOC_PROVIDER_OPS, nullptr,
nullptr}));

INSTANTIATE_TEST_SUITE_P(mallocMultiPoolTest, umfMultiPoolTest,
::testing::Values(poolCreateExtParams{
umfProxyPoolOps(), nullptr, &MALLOC_PROVIDER_OPS,
nullptr}));
nullptr, nullptr}));

INSTANTIATE_TEST_SUITE_P(umfPoolWithCreateFlagsTest, umfPoolWithCreateFlagsTest,
::testing::Values(0,
Expand Down
44 changes: 35 additions & 9 deletions test/poolFixtures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
// Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#ifndef UMF_TEST_MEMORY_POOL_OPS_HPP
#define UMF_TEST_MEMORY_POOL_OPS_HPP
#ifndef UMF_TEST_POOL_FIXTURES_HPP
#define UMF_TEST_POOL_FIXTURES_HPP 1

#include "pool.hpp"
#include "provider.hpp"
#include "umf/providers/provider_coarse.h"

#include <array>
#include <cstring>
Expand All @@ -17,21 +18,46 @@

#include "../malloc_compliance_tests.hpp"

using poolCreateExtParams = std::tuple<umf_memory_pool_ops_t *, void *,
umf_memory_provider_ops_t *, void *>;
using poolCreateExtParams =
std::tuple<umf_memory_pool_ops_t *, void *, umf_memory_provider_ops_t *,
void *, void *>;

umf::pool_unique_handle_t poolCreateExtUnique(poolCreateExtParams params) {
umf_memory_pool_handle_t hPool;
auto [pool_ops, pool_params, provider_ops, provider_params] = params;
auto [pool_ops, pool_params, provider_ops, provider_params, coarse_params] =
params;

umf_memory_provider_handle_t upstream_provider = nullptr;
umf_memory_provider_handle_t provider = nullptr;
auto ret =
umfMemoryProviderCreate(provider_ops, provider_params, &provider);
umf_memory_pool_handle_t hPool = nullptr;
umf_result_t ret;

ret = umfMemoryProviderCreate(provider_ops, provider_params,
&upstream_provider);
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
EXPECT_NE(upstream_provider, nullptr);

provider = upstream_provider;

if (coarse_params) {
coarse_memory_provider_params_t *coarse_memory_provider_params =
(coarse_memory_provider_params_t *)coarse_params;
coarse_memory_provider_params->upstream_memory_provider =
upstream_provider;
coarse_memory_provider_params->destroy_upstream_memory_provider = true;

umf_memory_provider_handle_t coarse_provider = nullptr;
ret = umfMemoryProviderCreate(umfCoarseMemoryProviderOps(),
coarse_params, &coarse_provider);
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
EXPECT_NE(coarse_provider, nullptr);

provider = coarse_provider;
}

ret = umfPoolCreate(pool_ops, provider, pool_params,
UMF_POOL_CREATE_FLAG_OWN_PROVIDER, &hPool);
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
EXPECT_NE(hPool, nullptr);

return umf::pool_unique_handle_t(hPool, &umfPoolDestroy);
}
Expand Down Expand Up @@ -407,4 +433,4 @@ TEST_P(umfPoolTest, realloc_compliance) {

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

#endif /* UMF_TEST_MEMORY_POOL_OPS_HPP */
#endif /* UMF_TEST_POOL_FIXTURES_HPP */
6 changes: 3 additions & 3 deletions test/pools/disjoint_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,17 @@ auto defaultPoolConfig = poolConfig();
INSTANTIATE_TEST_SUITE_P(disjointPoolTests, umfPoolTest,
::testing::Values(poolCreateExtParams{
umfDisjointPoolOps(), (void *)&defaultPoolConfig,
&MALLOC_PROVIDER_OPS, nullptr}));
&MALLOC_PROVIDER_OPS, nullptr, nullptr}));

INSTANTIATE_TEST_SUITE_P(
disjointPoolTests, umfMemTest,
::testing::Values(std::make_tuple(
poolCreateExtParams{umfDisjointPoolOps(), (void *)&defaultPoolConfig,
&MOCK_OUT_OF_MEM_PROVIDER_OPS,
(void *)&defaultPoolConfig.Capacity},
(void *)&defaultPoolConfig.Capacity, nullptr},
static_cast<int>(defaultPoolConfig.Capacity) / 2)));

INSTANTIATE_TEST_SUITE_P(disjointMultiPoolTests, umfMultiPoolTest,
::testing::Values(poolCreateExtParams{
umfDisjointPoolOps(), (void *)&defaultPoolConfig,
&MALLOC_PROVIDER_OPS, nullptr}));
&MALLOC_PROVIDER_OPS, nullptr, nullptr}));
8 changes: 5 additions & 3 deletions test/pools/jemalloc_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ auto defaultParams = umfOsMemoryProviderParamsDefault();
INSTANTIATE_TEST_SUITE_P(jemallocPoolTest, umfPoolTest,
::testing::Values(poolCreateExtParams{
umfJemallocPoolOps(), nullptr,
umfOsMemoryProviderOps(), &defaultParams}));
umfOsMemoryProviderOps(), &defaultParams,
nullptr}));

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

auto pool = poolCreateExtUnique(
{umfJemallocPoolOps(), nullptr, umfOsMemoryProviderOps(), &params});
auto pool =
poolCreateExtUnique({umfJemallocPoolOps(), nullptr,
umfOsMemoryProviderOps(), &params, nullptr});

std::vector<std::shared_ptr<void>> allocs;
for (size_t i = 0; i < numAllocs; i++) {
Expand Down
2 changes: 1 addition & 1 deletion test/pools/pool_base_alloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ umf_memory_pool_ops_t BA_POOL_OPS = umf::poolMakeCOps<base_alloc_pool, void>();
INSTANTIATE_TEST_SUITE_P(baPool, umfPoolTest,
::testing::Values(poolCreateExtParams{
&BA_POOL_OPS, nullptr,
&umf_test::BASE_PROVIDER_OPS, nullptr}));
&umf_test::BASE_PROVIDER_OPS, nullptr, nullptr}));
3 changes: 2 additions & 1 deletion test/pools/scalable_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ auto defaultParams = umfOsMemoryProviderParamsDefault();
INSTANTIATE_TEST_SUITE_P(scalablePoolTest, umfPoolTest,
::testing::Values(poolCreateExtParams{
umfScalablePoolOps(), nullptr,
umfOsMemoryProviderOps(), &defaultParams}));
umfOsMemoryProviderOps(), &defaultParams,
nullptr}));
Loading