Skip to content
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
9 changes: 8 additions & 1 deletion test/coarse_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,14 @@ INSTANTIATE_TEST_SUITE_P(
CoarseWithMemoryStrategyTest, CoarseWithMemoryStrategyTest,
::testing::Values(UMF_COARSE_MEMORY_STRATEGY_FASTEST,
UMF_COARSE_MEMORY_STRATEGY_FASTEST_BUT_ONE,
UMF_COARSE_MEMORY_STRATEGY_CHECK_ALL_SIZE));
UMF_COARSE_MEMORY_STRATEGY_CHECK_ALL_SIZE),
([](auto const &info) -> std::string {
static const char *names[] = {
"UMF_COARSE_MEMORY_STRATEGY_FASTEST",
"UMF_COARSE_MEMORY_STRATEGY_FASTEST_BUT_ONE",
"UMF_COARSE_MEMORY_STRATEGY_CHECK_ALL_SIZE"};
return names[info.index];
}));

TEST_P(CoarseWithMemoryStrategyTest, coarseTest_basic_provider) {
umf_memory_provider_handle_t malloc_memory_provider;
Expand Down
32 changes: 32 additions & 0 deletions test/common/pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,38 @@
#include "provider.hpp"
#include "utils/cpp_helpers.hpp"

typedef void *(*pfnPoolParamsCreate)();
typedef umf_result_t (*pfnPoolParamsDestroy)(void *);

typedef void *(*pfnProviderParamsCreate)();
typedef umf_result_t (*pfnProviderParamsDestroy)(void *);

using poolCreateExtParams =
std::tuple<const umf_memory_pool_ops_t *, pfnPoolParamsCreate,
pfnPoolParamsDestroy, const umf_memory_provider_ops_t *,
pfnProviderParamsCreate, pfnProviderParamsDestroy>;

std::string poolCreateExtParamsNameGen(
const testing::TestParamInfo<poolCreateExtParams> &info) {

const umf_memory_pool_ops_t *pool_ops = std::get<0>(info.param);
const umf_memory_provider_ops_t *provider_ops = std::get<3>(info.param);

const char *poolName = NULL;
pool_ops->get_name(NULL, &poolName);

const char *providerName = NULL;
provider_ops->get_name(NULL, &providerName);

// if there are multiple cases with the same pool and provider combination,
// add the index to the name
std::string poolParams = std::get<1>(info.param)
? "_w_params_" + std::to_string(info.index)
: "";

return std::string(poolName) + poolParams + "_" + providerName;
}

namespace umf_test {

umf_memory_pool_handle_t
Expand Down
30 changes: 30 additions & 0 deletions test/common/provider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,36 @@
#include "test_helpers.h"
#include "utils/cpp_helpers.hpp"

typedef void *(*pfnProviderParamsCreate)();
typedef umf_result_t (*pfnProviderParamsDestroy)(void *);

using providerCreateExtParams =
std::tuple<const umf_memory_provider_ops_t *, void *>;

std::string providerCreateExtParamsNameGen(
const testing::TestParamInfo<providerCreateExtParams> param) {
const umf_memory_provider_ops_t *provider_ops = std::get<0>(param.param);

const char *providerName = NULL;
provider_ops->get_name(NULL, &providerName);

return providerName;
}

void providerCreateExt(providerCreateExtParams params,
umf_test::provider_unique_handle_t *handle) {
umf_memory_provider_handle_t hProvider = nullptr;
auto [provider_ops, provider_params] = params;

auto ret =
umfMemoryProviderCreate(provider_ops, provider_params, &hProvider);
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
ASSERT_NE(hProvider, nullptr);

*handle = umf_test::provider_unique_handle_t(hProvider,
&umfMemoryProviderDestroy);
}

namespace umf_test {

umf_memory_provider_handle_t
Expand Down
8 changes: 7 additions & 1 deletion test/disjoint_pool_file_prov.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ INSTANTIATE_TEST_SUITE_P(
FileWithMemoryStrategyTest, FileWithMemoryStrategyTest,
::testing::Values(UMF_COARSE_MEMORY_STRATEGY_FASTEST,
UMF_COARSE_MEMORY_STRATEGY_FASTEST_BUT_ONE,
UMF_COARSE_MEMORY_STRATEGY_CHECK_ALL_SIZE));
UMF_COARSE_MEMORY_STRATEGY_CHECK_ALL_SIZE),
([](auto const &info) -> std::string {
const char *names[] = {"UMF_COARSE_MEMORY_STRATEGY_FASTEST",
"UMF_COARSE_MEMORY_STRATEGY_FASTEST_BUT_ONE",
"UMF_COARSE_MEMORY_STRATEGY_CHECK_ALL_SIZE"};
return names[info.index];
}));

TEST_P(FileWithMemoryStrategyTest, disjointFileMallocPool_simple1) {
umf_memory_provider_handle_t malloc_memory_provider = nullptr;
Expand Down
3 changes: 2 additions & 1 deletion test/ipcAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,5 @@ INSTANTIATE_TEST_SUITE_P(umfIpcTestSuite, umfIpcTest,
::testing::Values(ipcTestParams{
umfProxyPoolOps(), nullptr, nullptr,
&IPC_MOCK_PROVIDER_OPS, nullptr, nullptr,
&hostMemoryAccessor}));
&hostMemoryAccessor}),
ipcTestParamsNameGen);
44 changes: 35 additions & 9 deletions test/ipcFixtures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,29 @@
#ifndef UMF_TEST_IPC_FIXTURES_HPP
#define UMF_TEST_IPC_FIXTURES_HPP

#include "base.hpp"
#include "multithread_helpers.hpp"
#include "pool.hpp"
#include "test_helpers.h"
#include <algorithm>
#include <cstring>
#include <numeric>
#include <random>
#include <tuple>

#include <umf/ipc.h>
#include <umf/memory_pool.h>
#include <umf/memory_provider.h>
#include <umf/pools/pool_proxy.h>

#include <algorithm>
#include <cstring>
#include <numeric>
#include <random>
#include <tuple>
#include "base.hpp"
#include "multithread_helpers.hpp"
#include "pool.hpp"
#include "test_helpers.h"

class MemoryAccessor {
public:
virtual ~MemoryAccessor() = default;
virtual void fill(void *ptr, size_t size, const void *pattern,
size_t pattern_size) = 0;
virtual void copy(void *dst_ptr, void *src_ptr, size_t size) = 0;
virtual const char *getName() = 0;
};

class HostMemoryAccessor : public MemoryAccessor {
Expand All @@ -47,6 +48,8 @@ class HostMemoryAccessor : public MemoryAccessor {
void copy(void *dst_ptr, void *src_ptr, size_t size) override {
std::memcpy(dst_ptr, src_ptr, size);
}

const char *getName() override { return "HostMemoryAccessor"; }
};

typedef void *(*pfnPoolParamsCreate)();
Expand All @@ -65,6 +68,29 @@ using ipcTestParams =
pfnProviderParamsCreate, pfnProviderParamsDestroy,
MemoryAccessor *>;

std::string
ipcTestParamsNameGen(const ::testing::TestParamInfo<ipcTestParams> &info) {
const umf_memory_pool_ops_t *pool_ops = std::get<0>(info.param);
const umf_memory_provider_ops_t *provider_ops = std::get<3>(info.param);

const char *poolName = NULL;
pool_ops->get_name(NULL, &poolName);

const char *providerName = NULL;
provider_ops->get_name(NULL, &providerName);

// if there are multiple cases with the same pool and provider combination,
// add index to the name
std::string poolParams = std::get<1>(info.param)
? "_w_params_" + std::to_string(info.index)
: "";

MemoryAccessor *memAccessor = std::get<6>(info.param);

return std::string(poolName) + poolParams + "_" + providerName + "_" +
memAccessor->getName();
}

struct umfIpcTest : umf_test::test,
::testing::WithParamInterface<ipcTestParams> {
umfIpcTest() {}
Expand Down
65 changes: 47 additions & 18 deletions test/memoryPoolAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// This file contains tests for UMF pool API

#include "base.hpp"
#include "pool.hpp"
#include "poolFixtures.hpp"
#include "provider.hpp"
#include "provider_null.h"
#include "provider_trace.h"
#include "test_helpers.h"
#include <array>
#include <string>
#include <thread>
#include <type_traits>
#include <unordered_map>
#include <variant>

#include <umf/memory_provider.h>
#include <umf/pools/pool_disjoint.h>
Expand All @@ -19,12 +18,13 @@
#include <umf/proxy_lib_new_delete.h>
#endif

#include <array>
#include <string>
#include <thread>
#include <type_traits>
#include <unordered_map>
#include <variant>
#include "base.hpp"
#include "pool.hpp"
#include "poolFixtures.hpp"
#include "provider.hpp"
#include "provider_null.h"
#include "provider_trace.h"
#include "test_helpers.h"

using umf_test::test;
using namespace umf_test;
Expand Down Expand Up @@ -309,16 +309,23 @@ INSTANTIATE_TEST_SUITE_P(
&BA_GLOBAL_PROVIDER_OPS, nullptr, nullptr},
poolCreateExtParams{umfDisjointPoolOps(), defaultDisjointPoolConfig,
defaultDisjointPoolConfigDestroy,
&BA_GLOBAL_PROVIDER_OPS, nullptr, nullptr}));
&BA_GLOBAL_PROVIDER_OPS, nullptr, nullptr}),
poolCreateExtParamsNameGen);

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

INSTANTIATE_TEST_SUITE_P(umfPoolWithCreateFlagsTest, umfPoolWithCreateFlagsTest,
::testing::Values(0,
UMF_POOL_CREATE_FLAG_OWN_PROVIDER));
UMF_POOL_CREATE_FLAG_OWN_PROVIDER),
([](auto const &info) -> std::string {
static const char *names[] = {
"NONE", "UMF_POOL_CREATE_FLAG_OWN_PROVIDER"};
return names[info.index];
}));

////////////////// Negative test cases /////////////////

Expand Down Expand Up @@ -382,7 +389,14 @@ INSTANTIATE_TEST_SUITE_P(
::testing::Values(UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY,
UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC,
UMF_RESULT_ERROR_INVALID_ARGUMENT,
UMF_RESULT_ERROR_UNKNOWN));
UMF_RESULT_ERROR_UNKNOWN),
([](auto const &info) -> std::string {
static const char *names[] = {
"UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY",
"UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC",
"UMF_RESULT_ERROR_INVALID_ARGUMENT", "UMF_RESULT_ERROR_UNKNOWN"};
return names[info.index];
}));

TEST_P(poolInitializeTest, errorPropagation) {
auto nullProvider = umf_test::wrapProviderUnique(nullProviderCreate());
Expand Down Expand Up @@ -559,4 +573,19 @@ INSTANTIATE_TEST_SUITE_P(
umf_test::withGeneratedArgs(umfPoolGetMemoryProvider),
umf_test::withGeneratedArgs(umfPoolByPtr),
umf_test::withGeneratedArgs(umfPoolSetTag),
umf_test::withGeneratedArgs(umfPoolGetTag)));
umf_test::withGeneratedArgs(umfPoolGetTag)),
([](auto const &info) -> std::string {
static const char *names[] = {"umfPoolMalloc",
"umfPoolAlignedMalloc",
"umfPoolFree",
"umfPoolCalloc",
"umfPoolRealloc",
"umfPoolMallocUsableSize",
"umfPoolGetLastAllocationError",
"umfPoolGetName",
"umfPoolGetMemoryProvider",
"umfPoolByPtr",
"umfPoolSetTag",
"umfPoolGetTag"};
return names[info.index];
}));
21 changes: 19 additions & 2 deletions test/memoryProviderAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,14 @@ INSTANTIATE_TEST_SUITE_P(
::testing::Values(UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY,
UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC,
UMF_RESULT_ERROR_INVALID_ARGUMENT,
UMF_RESULT_ERROR_UNKNOWN));
UMF_RESULT_ERROR_UNKNOWN),
([](auto const &info) -> std::string {
static const char *names[] = {
"UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY",
"UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC",
"UMF_RESULT_ERROR_INVALID_ARGUMENT", "UMF_RESULT_ERROR_UNKNOWN"};
return names[info.index];
}));

TEST_P(providerInitializeTest, errorPropagation) {
struct provider : public umf_test::provider_base_t {
Expand Down Expand Up @@ -389,4 +396,14 @@ INSTANTIATE_TEST_SUITE_P(
umf_test::withGeneratedArgs(umfMemoryProviderGetMinPageSize),
umf_test::withGeneratedArgs(umfMemoryProviderPurgeLazy),
umf_test::withGeneratedArgs(umfMemoryProviderPurgeForce),
umf_test::withGeneratedArgs(umfMemoryProviderGetName)));
umf_test::withGeneratedArgs(umfMemoryProviderGetName)),
([](auto const &info) -> std::string {
static const char *names[] = {"umfMemoryProviderAlloc",
"umfMemoryProviderFree",
"umfMemoryProviderGetRecommendedPageSize",
"umfMemoryProviderGetMinPageSize",
"umfMemoryProviderPurgeLazy",
"umfMemoryProviderPurgeForce",
"umfMemoryProviderGetName"};
return names[info.index];
}));
29 changes: 19 additions & 10 deletions test/memspaces/memspace_highest_bandwidth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,25 @@ static void canQueryBandwidth(size_t nodeId) {
}
}

INSTANTIATE_TEST_SUITE_P(memspaceLowestLatencyTest, memspaceGetTest,
::testing::Values(memspaceGetParams{
canQueryBandwidth,
umfMemspaceHighestBandwidthGet}));

INSTANTIATE_TEST_SUITE_P(memspaceLowestLatencyProviderTest,
memspaceProviderTest,
::testing::Values(memspaceGetParams{
canQueryBandwidth,
umfMemspaceHighestBandwidthGet}));
INSTANTIATE_TEST_SUITE_P(
memspaceLowestLatencyTest, memspaceGetTest,
::testing::Values(memspaceGetParams{canQueryBandwidth,
umfMemspaceHighestBandwidthGet}),
([](auto const &info) -> std::string {
static const char *names[] = {"canQueryBandwidth",
"umfMemspaceHighestBandwidthGet"};
return names[info.index];
}));

INSTANTIATE_TEST_SUITE_P(
memspaceLowestLatencyProviderTest, memspaceProviderTest,
::testing::Values(memspaceGetParams{canQueryBandwidth,
umfMemspaceHighestBandwidthGet}),
([](auto const &info) -> std::string {
static const char *names[] = {"canQueryBandwidth",
"umfMemspaceHighestBandwidthGet"};
return names[info.index];
}));

TEST_F(numaNodesTest, PerCoreBandwidthPlacement) {
const size_t allocSize = 4096;
Expand Down
16 changes: 14 additions & 2 deletions test/memspaces/memspace_lowest_latency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,21 @@ static void canQueryLatency(size_t nodeId) {

INSTANTIATE_TEST_SUITE_P(memspaceLowestLatencyTest, memspaceGetTest,
::testing::Values(memspaceGetParams{
canQueryLatency, umfMemspaceLowestLatencyGet}));
canQueryLatency, umfMemspaceLowestLatencyGet}),
([](auto const &info) -> std::string {
static const char *names[] = {
"canQueryLatency",
"umfMemspaceLowestLatencyGet"};
return names[info.index];
}));

INSTANTIATE_TEST_SUITE_P(memspaceLowestLatencyProviderTest,
memspaceProviderTest,
::testing::Values(memspaceGetParams{
canQueryLatency, umfMemspaceLowestLatencyGet}));
canQueryLatency, umfMemspaceLowestLatencyGet}),
([](auto const &info) -> std::string {
static const char *names[] = {
"canQueryLatency",
"umfMemspaceLowestLatencyGet"};
return names[info.index];
}));
Loading