Skip to content

Skip tests requiring NUMA if NUMA is not supported #655

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
merged 1 commit into from
Aug 8, 2024
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
20 changes: 15 additions & 5 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ else()
endif()

if(LINUX)
set(UMF_TEST_SKIP_RETURN_CODE 125)

set(EXAMPLE_NAME umf_example_memspace_numa)

add_umf_executable(
Expand All @@ -175,8 +177,10 @@ if(LINUX)
LIBS umf ${LIBHWLOC_LIBRARIES} numa)

target_include_directories(
${EXAMPLE_NAME} PRIVATE ${UMF_CMAKE_SOURCE_DIR}/src/utils
${UMF_CMAKE_SOURCE_DIR}/include)
${EXAMPLE_NAME}
PRIVATE ${UMF_CMAKE_SOURCE_DIR}/src/utils
${UMF_CMAKE_SOURCE_DIR}/include
${UMF_CMAKE_SOURCE_DIR}/examples/common)

target_link_directories(${EXAMPLE_NAME} PRIVATE ${LIBHWLOC_LIBRARY_DIRS})

Expand All @@ -185,6 +189,9 @@ if(LINUX)
COMMAND ${EXAMPLE_NAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

set_tests_properties(${EXAMPLE_NAME} PROPERTIES
SKIP_RETURN_CODE ${UMF_TEST_SKIP_RETURN_CODE})

set(EXAMPLE_NAME umf_example_memspace_hmat)

add_umf_executable(
Expand All @@ -193,8 +200,10 @@ if(LINUX)
LIBS umf ${LIBHWLOC_LIBRARIES} numa)

target_include_directories(
${EXAMPLE_NAME} PRIVATE ${UMF_CMAKE_SOURCE_DIR}/src/utils
${UMF_CMAKE_SOURCE_DIR}/include)
${EXAMPLE_NAME}
PRIVATE ${UMF_CMAKE_SOURCE_DIR}/src/utils
${UMF_CMAKE_SOURCE_DIR}/include
${UMF_CMAKE_SOURCE_DIR}/examples/common)

target_link_directories(${EXAMPLE_NAME} PRIVATE ${LIBHWLOC_LIBRARY_DIRS})

Expand All @@ -203,7 +212,8 @@ if(LINUX)
COMMAND ${EXAMPLE_NAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

set_tests_properties(${EXAMPLE_NAME} PROPERTIES SKIP_RETURN_CODE 125)
set_tests_properties(${EXAMPLE_NAME} PROPERTIES
SKIP_RETURN_CODE ${UMF_TEST_SKIP_RETURN_CODE})
set(EXAMPLE_NAME umf_example_file_provider)

add_umf_executable(
Expand Down
16 changes: 16 additions & 0 deletions examples/common/utils_examples.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
*
* Copyright (C) 2024 Intel Corporation
*
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*/

#ifndef UMF_EXAMPLE_UTILS_H
#define UMF_EXAMPLE_UTILS_H

// Needed for CI
#define TEST_SKIP_ERROR_CODE 125

#endif /* UMF_EXAMPLE_UTILS_H */
7 changes: 3 additions & 4 deletions examples/memspace/memspace_hmat.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
#include <stdio.h>
#include <string.h>

// Needed for CI
#define test_skip_error_code 125
#include "utils_examples.h"

// Function to create a memory provider which allocates memory from the specified NUMA node
int createMemoryProvider(umf_memory_provider_handle_t *hProvider,
Expand Down Expand Up @@ -63,13 +62,13 @@ int main(void) {
// Check if NUMA is available
if (numa_available() < 0) {
fprintf(stderr, "NUMA is not available on this system.\n");
return -1;
return TEST_SKIP_ERROR_CODE;
}

// Create the memory provider that allocates memory from the highest bandwidth numa nodes
ret = createMemoryProvider(&hProvider, umfMemspaceHighestBandwidthGet());
if (ret != UMF_RESULT_SUCCESS) {
return ret == 1 ? test_skip_error_code : -1;
return ret == 1 ? TEST_SKIP_ERROR_CODE : -1;
}

// Allocate memory from the memory provider
Expand Down
4 changes: 3 additions & 1 deletion examples/memspace/memspace_numa.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <stdio.h>
#include <string.h>

#include "utils_examples.h"

// Function to create a memory provider which allocates memory from the specified NUMA node
int createMemoryProvider(umf_memory_provider_handle_t *hProvider,
unsigned numa) {
Expand Down Expand Up @@ -65,7 +67,7 @@ int main(void) {
// Check if NUMA is available
if (numa_available() < 0) {
fprintf(stderr, "NUMA is not available on this system.\n");
return -1;
return TEST_SKIP_ERROR_CODE;
}

// Create the memory provider that allocates memory from the specified NUMA node
Expand Down
3 changes: 3 additions & 0 deletions test/common/test_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
extern "C" {
#endif

// Needed for CI
#define TEST_SKIP_ERROR_CODE 125

static inline void UT_FATAL(const char *format, ...) {
va_list args_list;
va_start(args_list, format);
Expand Down
6 changes: 5 additions & 1 deletion test/memspaces/memspace_fixtures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct numaNodesTest : ::umf_test::test {
::umf_test::test::SetUp();

if (numa_available() == -1 || numa_all_nodes_ptr == nullptr) {
GTEST_FAIL() << "Failed to initialize libnuma";
GTEST_SKIP() << "No available NUMA support; skipped";
}

int maxNode = numa_max_node();
Expand Down Expand Up @@ -59,6 +59,10 @@ struct memspaceGetTest : ::numaNodesTest,
void SetUp() override {
::numaNodesTest::SetUp();

if (numa_available() == -1 || numa_all_nodes_ptr == nullptr) {
GTEST_SKIP() << "No available NUMA support; skipped";
}

auto [isQuerySupported, memspaceGet] = this->GetParam();

if (!isQuerySupported(nodeIds.front())) {
Expand Down
8 changes: 8 additions & 0 deletions test/memspaces/memspace_numa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ struct memspaceNumaTest : ::numaNodesTest {
void SetUp() override {
::numaNodesTest::SetUp();

if (numa_available() == -1) {
GTEST_SKIP() << "NUMA not supported on this system; test skipped";
}

umf_result_t ret = umfMemspaceCreateFromNumaArray(
nodeIds.data(), nodeIds.size(), &hMemspace);
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
Expand All @@ -34,6 +38,10 @@ struct memspaceNumaProviderTest : ::memspaceNumaTest {
void SetUp() override {
::memspaceNumaTest::SetUp();

if (numa_available() == -1) {
GTEST_SKIP() << "NUMA not supported on this system; test skipped";
}

umf_result_t ret =
umfMemoryProviderCreateFromMemspace(hMemspace, nullptr, &hProvider);
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
Expand Down
26 changes: 21 additions & 5 deletions test/provider_os_memory_multiple_numa_nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ static umf_os_memory_provider_params_t UMF_OS_MEMORY_PROVIDER_PARAMS_TEST =
umfOsMemoryProviderParamsDefault();

std::vector<unsigned> get_available_numa_nodes() {
UT_ASSERTne(numa_available(), -1);
UT_ASSERTne(numa_all_nodes_ptr, nullptr);
if (numa_available() == -1 || numa_all_nodes_ptr == nullptr) {
return std::vector<unsigned>();
}

std::vector<unsigned> available_numa_nodes;
// Get all available NUMA nodes numbers.
Expand Down Expand Up @@ -57,9 +58,6 @@ std::vector<int> get_available_cpus() {
}

void set_all_available_nodemask_bits(bitmask *nodemask) {
UT_ASSERTne(numa_available(), -1);
UT_ASSERTne(numa_all_nodes_ptr, nullptr);

numa_bitmask_clearall(nodemask);

// Set all available NUMA nodes numbers.
Expand Down Expand Up @@ -124,6 +122,24 @@ struct testNuma : testing::Test {
struct testNumaOnEachNode : testNuma, testing::WithParamInterface<unsigned> {};
struct testNumaOnEachCpu : testNuma, testing::WithParamInterface<int> {};

/*
- In case of the lack of support for NUMA on the system
get_available_numa_nodes() returns an empty vector<unsigned>
- Then in INSTANTIATE_TEST_SUITE_P an empty container is passed as the 3rd arg
(param_generator)
- Therefore INSTANTIATE_TEST_SUITE_P expands to nothing, which causes the test
to fail in the test suite GoogleTestVerification
- GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(testNumaOnEachNode) allows the
test suite testNumaOnEachNode to be uninstantiated, suppressing
the test failure
- Additionally, the fixture testNumaOnEachNode uses SetUp from testNuma before
running every test, thus the test is eventually skipped when the lack of NUMA
support is determined by numa_available()
- (Therefore probably a vector with dummy values could be returned instead of
using the macro)
*/
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(testNumaOnEachNode);

INSTANTIATE_TEST_SUITE_P(testNumaNodesAllocations, testNumaOnEachNode,
::testing::ValuesIn(get_available_numa_nodes()));

Expand Down
Loading