Skip to content

Commit 7ba1625

Browse files
Merge pull request #655 from EuphoricThinking/skipping1
Skip tests requiring NUMA if NUMA is not supported
2 parents 0b15b1f + 80e6459 commit 7ba1625

File tree

8 files changed

+74
-16
lines changed

8 files changed

+74
-16
lines changed

examples/CMakeLists.txt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ else()
167167
endif()
168168

169169
if(LINUX)
170+
set(UMF_TEST_SKIP_RETURN_CODE 125)
171+
170172
set(EXAMPLE_NAME umf_example_memspace_numa)
171173

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

177179
target_include_directories(
178-
${EXAMPLE_NAME} PRIVATE ${UMF_CMAKE_SOURCE_DIR}/src/utils
179-
${UMF_CMAKE_SOURCE_DIR}/include)
180+
${EXAMPLE_NAME}
181+
PRIVATE ${UMF_CMAKE_SOURCE_DIR}/src/utils
182+
${UMF_CMAKE_SOURCE_DIR}/include
183+
${UMF_CMAKE_SOURCE_DIR}/examples/common)
180184

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

@@ -185,6 +189,9 @@ if(LINUX)
185189
COMMAND ${EXAMPLE_NAME}
186190
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
187191

192+
set_tests_properties(${EXAMPLE_NAME} PROPERTIES
193+
SKIP_RETURN_CODE ${UMF_TEST_SKIP_RETURN_CODE})
194+
188195
set(EXAMPLE_NAME umf_example_memspace_hmat)
189196

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

195202
target_include_directories(
196-
${EXAMPLE_NAME} PRIVATE ${UMF_CMAKE_SOURCE_DIR}/src/utils
197-
${UMF_CMAKE_SOURCE_DIR}/include)
203+
${EXAMPLE_NAME}
204+
PRIVATE ${UMF_CMAKE_SOURCE_DIR}/src/utils
205+
${UMF_CMAKE_SOURCE_DIR}/include
206+
${UMF_CMAKE_SOURCE_DIR}/examples/common)
198207

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

@@ -203,7 +212,8 @@ if(LINUX)
203212
COMMAND ${EXAMPLE_NAME}
204213
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
205214

206-
set_tests_properties(${EXAMPLE_NAME} PROPERTIES SKIP_RETURN_CODE 125)
215+
set_tests_properties(${EXAMPLE_NAME} PROPERTIES
216+
SKIP_RETURN_CODE ${UMF_TEST_SKIP_RETURN_CODE})
207217
set(EXAMPLE_NAME umf_example_file_provider)
208218

209219
add_umf_executable(

examples/common/utils_examples.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
*
3+
* Copyright (C) 2024 Intel Corporation
4+
*
5+
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
6+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
*
8+
*/
9+
10+
#ifndef UMF_EXAMPLE_UTILS_H
11+
#define UMF_EXAMPLE_UTILS_H
12+
13+
// Needed for CI
14+
#define TEST_SKIP_ERROR_CODE 125
15+
16+
#endif /* UMF_EXAMPLE_UTILS_H */

examples/memspace/memspace_hmat.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
#include <stdio.h>
1616
#include <string.h>
1717

18-
// Needed for CI
19-
#define test_skip_error_code 125
18+
#include "utils_examples.h"
2019

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

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

7574
// Allocate memory from the memory provider

examples/memspace/memspace_numa.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <stdio.h>
1616
#include <string.h>
1717

18+
#include "utils_examples.h"
19+
1820
// Function to create a memory provider which allocates memory from the specified NUMA node
1921
int createMemoryProvider(umf_memory_provider_handle_t *hProvider,
2022
unsigned numa) {
@@ -65,7 +67,7 @@ int main(void) {
6567
// Check if NUMA is available
6668
if (numa_available() < 0) {
6769
fprintf(stderr, "NUMA is not available on this system.\n");
68-
return -1;
70+
return TEST_SKIP_ERROR_CODE;
6971
}
7072

7173
// Create the memory provider that allocates memory from the specified NUMA node

test/common/test_helpers.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
extern "C" {
2020
#endif
2121

22+
// Needed for CI
23+
#define TEST_SKIP_ERROR_CODE 125
24+
2225
static inline void UT_FATAL(const char *format, ...) {
2326
va_list args_list;
2427
va_start(args_list, format);

test/memspaces/memspace_fixtures.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct numaNodesTest : ::umf_test::test {
3030
::umf_test::test::SetUp();
3131

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

3636
int maxNode = numa_max_node();
@@ -59,6 +59,10 @@ struct memspaceGetTest : ::numaNodesTest,
5959
void SetUp() override {
6060
::numaNodesTest::SetUp();
6161

62+
if (numa_available() == -1 || numa_all_nodes_ptr == nullptr) {
63+
GTEST_SKIP() << "No available NUMA support; skipped";
64+
}
65+
6266
auto [isQuerySupported, memspaceGet] = this->GetParam();
6367

6468
if (!isQuerySupported(nodeIds.front())) {

test/memspaces/memspace_numa.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ struct memspaceNumaTest : ::numaNodesTest {
1414
void SetUp() override {
1515
::numaNodesTest::SetUp();
1616

17+
if (numa_available() == -1) {
18+
GTEST_SKIP() << "NUMA not supported on this system; test skipped";
19+
}
20+
1721
umf_result_t ret = umfMemspaceCreateFromNumaArray(
1822
nodeIds.data(), nodeIds.size(), &hMemspace);
1923
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
@@ -34,6 +38,10 @@ struct memspaceNumaProviderTest : ::memspaceNumaTest {
3438
void SetUp() override {
3539
::memspaceNumaTest::SetUp();
3640

41+
if (numa_available() == -1) {
42+
GTEST_SKIP() << "NUMA not supported on this system; test skipped";
43+
}
44+
3745
umf_result_t ret =
3846
umfMemoryProviderCreateFromMemspace(hMemspace, nullptr, &hProvider);
3947
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);

test/provider_os_memory_multiple_numa_nodes.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ static umf_os_memory_provider_params_t UMF_OS_MEMORY_PROVIDER_PARAMS_TEST =
1818
umfOsMemoryProviderParamsDefault();
1919

2020
std::vector<unsigned> get_available_numa_nodes() {
21-
UT_ASSERTne(numa_available(), -1);
22-
UT_ASSERTne(numa_all_nodes_ptr, nullptr);
21+
if (numa_available() == -1 || numa_all_nodes_ptr == nullptr) {
22+
return std::vector<unsigned>();
23+
}
2324

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

5960
void set_all_available_nodemask_bits(bitmask *nodemask) {
60-
UT_ASSERTne(numa_available(), -1);
61-
UT_ASSERTne(numa_all_nodes_ptr, nullptr);
62-
6361
numa_bitmask_clearall(nodemask);
6462

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

125+
/*
126+
- In case of the lack of support for NUMA on the system
127+
get_available_numa_nodes() returns an empty vector<unsigned>
128+
- Then in INSTANTIATE_TEST_SUITE_P an empty container is passed as the 3rd arg
129+
(param_generator)
130+
- Therefore INSTANTIATE_TEST_SUITE_P expands to nothing, which causes the test
131+
to fail in the test suite GoogleTestVerification
132+
- GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(testNumaOnEachNode) allows the
133+
test suite testNumaOnEachNode to be uninstantiated, suppressing
134+
the test failure
135+
- Additionally, the fixture testNumaOnEachNode uses SetUp from testNuma before
136+
running every test, thus the test is eventually skipped when the lack of NUMA
137+
support is determined by numa_available()
138+
- (Therefore probably a vector with dummy values could be returned instead of
139+
using the macro)
140+
*/
141+
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(testNumaOnEachNode);
142+
127143
INSTANTIATE_TEST_SUITE_P(testNumaNodesAllocations, testNumaOnEachNode,
128144
::testing::ValuesIn(get_available_numa_nodes()));
129145

0 commit comments

Comments
 (0)