Skip to content

Commit 9bbed73

Browse files
committed
Separate main for HPX tests
1 parent 545e0fb commit 9bbed73

File tree

4 files changed

+96
-11
lines changed

4 files changed

+96
-11
lines changed

src/plssvm/backends/HPX/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ set(PLSSVM_HPX_SOURCES
4040
# set target properties
4141
set_local_and_parent(PLSSVM_HPX_BACKEND_LIBRARY_NAME plssvm-HPX)
4242
add_library(${PLSSVM_HPX_BACKEND_LIBRARY_NAME} SHARED ${PLSSVM_HPX_SOURCES})
43-
target_link_libraries(${PLSSVM_HPX_BACKEND_LIBRARY_NAME} PUBLIC HPX::hpx HPX::wrap_main)
43+
target_link_libraries(${PLSSVM_HPX_BACKEND_LIBRARY_NAME} PUBLIC HPX::hpx)
4444

4545
# additional compilation flags
4646
target_compile_options(${PLSSVM_HPX_BACKEND_LIBRARY_NAME} PRIVATE $<$<COMPILE_LANG_AND_ID:CXX,GNU,Clang>:-Wconversion>)

tests/backends/HPX/CMakeLists.txt

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,36 @@ set(PLSSVM_HPX_TEST_SOURCES
1414
${CMAKE_CURRENT_LIST_DIR}/hpx_csvm.cpp
1515
)
1616

17+
# check if HPX can be enabled
18+
message(CHECK_START "Checking for HPX backend")
19+
20+
find_package(HPX 1.9.0)
21+
22+
if (NOT HPX_FOUND)
23+
message(CHECK_FAIL "not found")
24+
if (PLSSVM_ENABLE_HPX_BACKEND MATCHES "ON")
25+
message(SEND_ERROR "Cannot find requested backend: HPX!")
26+
endif ()
27+
return()
28+
else ()
29+
if (NOT DEFINED PLSSVM_CPU_TARGET_ARCHS)
30+
if (PLSSVM_ENABLE_HPX_BACKEND MATCHES "ON")
31+
message(SEND_ERROR "Found requested HPX backend, but no \"cpu\" targets were specified!")
32+
else ()
33+
message(STATUS "Found HPX backend, but no \"cpu\" targets were specified!")
34+
endif ()
35+
message(CHECK_FAIL "skipped")
36+
return()
37+
endif ()
38+
endif ()
39+
message(CHECK_PASS "found ")
40+
41+
1742
# add test executable
18-
add_executable(${PLSSVM_HPX_TEST_NAME} ${CMAKE_CURRENT_LIST_DIR}/../../main.cpp ${PLSSVM_HPX_TEST_SOURCES})
43+
add_executable(${PLSSVM_HPX_TEST_NAME} ${CMAKE_CURRENT_LIST_DIR}/../../hpx_main.cpp ${PLSSVM_HPX_TEST_SOURCES})
1944

2045
# link against test library
21-
target_link_libraries(${PLSSVM_HPX_TEST_NAME} PRIVATE ${PLSSVM_BASE_TEST_LIBRARY_NAME})
46+
target_link_libraries(${PLSSVM_HPX_TEST_NAME} PRIVATE ${PLSSVM_BASE_TEST_LIBRARY_NAME} HPX::hpx HPX::wrap_main)
2247

2348
# add tests to google test
2449
include(GoogleTest)

tests/hpx_main.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* @file
3+
* @author Alexander Van Craen
4+
* @author Marcel Breyer
5+
* @copyright 2018-today The PLSSVM project - All Rights Reserved
6+
* @license This file is part of the PLSSVM project which is released under the MIT license.
7+
* See the LICENSE.md file in the project root for full license information.
8+
*
9+
* @brief Contains the googletest main function. Sets the DeathTest to "threadsafe" execution instead of "fast".
10+
*/
11+
12+
#include "plssvm/environment.hpp" // plssvm::environment::scope_guard
13+
14+
#include "gtest/gtest.h" // RUN_ALL_TESTS, ::testing::{InitGoogleTest, GTEST_FLAG},GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST definitions
15+
16+
#include <cstdlib> // std::atexit
17+
18+
// Workaround as HPX runtime not working properly with Google Test
19+
// Run the entire main function in HPX runtime
20+
#include <hpx/hpx_main.hpp>
21+
22+
// silence GTest warnings/test errors
23+
24+
// generic CSVM tests
25+
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GenericCSVM);
26+
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GenericCSVMKernelFunction);
27+
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GenericCSVMSolver);
28+
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GenericCSVMSolverKernelFunction);
29+
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GenericCSVMKernelFunctionClassification);
30+
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GenericCSVMSolverKernelFunctionClassification);
31+
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GenericCSVMDeathTest);
32+
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GenericCSVMSolverDeathTest);
33+
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GenericCSVMKernelFunctionDeathTest);
34+
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GenericCSVMSolverKernelFunctionDeathTest);
35+
// generic GPU CSVM tests
36+
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GenericGPUCSVM);
37+
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GenericGPUCSVMKernelFunction);
38+
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GenericGPUCSVMDeathTest);
39+
// pinned memory tests
40+
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(PinnedMemory);
41+
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(PinnedMemoryLayout);
42+
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(PinnedMemoryDeathTest);
43+
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(PinnedMemoryLayoutDeathTest);
44+
// device pointer tests
45+
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DevicePtr);
46+
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DevicePtrLayout);
47+
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DevicePtrDeathTest);
48+
// exception tests
49+
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(Exception);
50+
51+
int main(int argc, char **argv) {
52+
::testing::InitGoogleTest(&argc, argv);
53+
54+
// prevent problems with fork() in the presence of multiple threads
55+
// https://github.com/google/googletest/blob/main/docs/advanced.md#death-tests-and-threads
56+
// NOTE: may reduce performance of the (death) tests
57+
#if !defined(_WIN32)
58+
::testing::GTEST_FLAG(death_test_style) = "threadsafe";
59+
#endif
60+
return RUN_ALL_TESTS();
61+
}

tests/main.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,12 @@
99
* @brief Contains the googletest main function. Sets the DeathTest to "threadsafe" execution instead of "fast".
1010
*/
1111

12-
#include "plssvm/environment.hpp" // plssvm::environment::scope_guard
12+
#include "plssvm/environment.hpp" // plssvm::environment::{scope_guard, initialize, finalize}
1313

1414
#include "gtest/gtest.h" // RUN_ALL_TESTS, ::testing::{InitGoogleTest, GTEST_FLAG},GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST definitions
1515

1616
#include <cstdlib> // std::atexit
1717

18-
#if defined(PLSSVM_HAS_HPX_BACKEND)
19-
// Workaround as Scope Guard not working properly with Google Test
20-
// Run the entire main function in HPX rutime
21-
#include <hpx/hpx_main.hpp>
22-
#endif
23-
2418
// silence GTest warnings/test errors
2519

2620
// generic CSVM tests
@@ -57,9 +51,14 @@ void ensure_finalization() {
5751
int main(int argc, char **argv) {
5852
::testing::InitGoogleTest(&argc, argv);
5953

54+
#if defined(PLSSVM_HAS_HPX_BACKEND)
6055
// initialize environments
56+
plssvm::environment::initialize();
57+
#else
58+
// initialize environments and manage lifetime with Scope Guard
6159
const plssvm::environment::scope_guard environment_guard{};
62-
// Note: necessary for Kokkos::SYCL
60+
#endif
61+
// Note: necessary for Kokkos::SYCL and HPX
6362
[[maybe_unused]] const int ret = std::atexit(ensure_finalization);
6463

6564
// prevent problems with fork() in the presence of multiple threads

0 commit comments

Comments
 (0)