Skip to content

Commit 4ef90e1

Browse files
committed
Add test-framework for CMake projects
Signed-off-by: Cristian Le <[email protected]>
1 parent a7e3db9 commit 4ef90e1

File tree

3 files changed

+97
-7
lines changed

3 files changed

+97
-7
lines changed

CMakeLists.txt

+10
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,16 @@ endif()
260260
option(SCALAPACK_BUILD_TESTS "Build all tests of the ScaLAPACK library" ON)
261261
if(${SCALAPACK_BUILD_TESTS})
262262
add_subdirectory(TESTING)
263+
# Make sure that the build artifacts are exported for the test-suite
264+
foreach(target IN ITEMS scalapack scalapack-F)
265+
if(TARGET ${target})
266+
export(TARGETS ${target}
267+
FILE scalapackTargets.cmake
268+
NAMESPACE scalapack::
269+
APPEND
270+
)
271+
endif()
272+
endforeach()
263273
endif()
264274

265275
# --------------------------------------------------

TESTING/CMakeLists.txt

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
cmake_minimum_required(VERSION 3.26...4.0)
22

3-
## Old test-suite to be modernized
4-
# include only if this is included via `add_subdirectory`
3+
project(scalapack-tests
4+
LANGUAGES C Fortran
5+
)
56

6-
if(DEFINED SCALAPACK_SOURCE_DIR)
7-
add_subdirectory(traditional)
7+
if(NOT TARGET scalapack::scalapack)
8+
find_package(scalapack REQUIRED CONFIG)
89
endif()
910

10-
## Modern test-suite is an independent project
11+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
12+
include(scalapack_tests_helpers)
1113

12-
# TODO: Add the implementations
13-
project(scalapack-tests)
1414
enable_testing()
15+
16+
# Old test-suite
17+
add_subdirectory(traditional)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
cmake_minimum_required(VERSION 3.26...4.0)
2+
include_guard()
3+
4+
function(scalapack_add_test test)
5+
#[===[.md
6+
# scalapack_add_test
7+
8+
Internal helper for adding functional tests of entire CMake projects
9+
10+
## Synopsis
11+
```cmake
12+
scalapack_add_test(<name>
13+
[TEST_NAME <test_name>]
14+
[CMAKE_ARGS <arg1> ...]
15+
[LABELS <label1> ...]
16+
)
17+
```
18+
19+
## Options
20+
21+
`<name>`
22+
: Test project to be configured
23+
24+
This is a subfolder relative to `${CMAKE_CURRENT_SOURCE_DIR}` containing the
25+
test project with `CMakeLists.txt`
26+
27+
`TEST_NAME` [Default: `<name>`]
28+
: Unique name of the ctest test name being created
29+
30+
`CMAKE_ARGS`
31+
: Additional CMake args passed to the configure step
32+
]===]
33+
34+
set(ARGS_Options)
35+
set(ARGS_OneValue
36+
TEST_NAME
37+
)
38+
set(ARGS_MultiValue
39+
CMAKE_ARGS
40+
LABELS
41+
)
42+
cmake_parse_arguments(PARSE_ARGV 1 ARGS "${ARGS_Options}" "${ARGS_OneValue}" "${ARGS_MultiValue}")
43+
# Check required/optional arguments
44+
if(NOT DEFINED ARGS_TEST_NAME)
45+
set(ARGS_TEST_NAME ${test})
46+
endif()
47+
48+
if(SCALAPACK_SOURCE_DIR)
49+
# If scalapack is built as part of the same project, use the build artifacts
50+
list(APPEND ARGS_CMAKE_ARGS
51+
-Dscalapack_ROOT=${SCALAPACK_BINARY_DIR}
52+
)
53+
else()
54+
# Otherwise use `scalapack_DIR` which is created after the `find_package`
55+
list(APPEND ARGS_CMAKE_ARGS
56+
-Dscalapack_ROOT=${scalapack_DIR}
57+
)
58+
endif()
59+
# Propagate the compilers used
60+
list(APPEND ARGS_CMAKE_ARGS
61+
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
62+
-DCMAKE_Fortran_COMPILER=${CMAKE_Fortran_COMPILER}
63+
)
64+
65+
add_test(NAME ${ARGS_TEST_NAME}
66+
COMMAND ${CMAKE_CTEST_COMMAND} --build-and-test ${CMAKE_CURRENT_SOURCE_DIR}/${test}
67+
${CMAKE_CURRENT_BINARY_DIR}/${test}
68+
# Use the same build environment as the current runner
69+
--build-generator "${CMAKE_GENERATOR}"
70+
--build-options
71+
${ARGS_CMAKE_ARGS}
72+
--test-command ${CMAKE_CTEST_COMMAND}
73+
--test-dir ${CMAKE_CURRENT_BINARY_DIR}/${test}
74+
--no-tests=ignore
75+
--output-on-failure
76+
)
77+
endfunction()

0 commit comments

Comments
 (0)