Skip to content

Commit d8f9481

Browse files
committed
Add CTest label support and direct-test registration helper
Extend test registration helpers to accept LABELS and auto-derive suite labels for easier selective execution across platforms. Introduce a helper for direct CTest command registration so non-shell tests follow the same labeling conventions as shell-driven tests.
1 parent 7b18cbc commit d8f9481

34 files changed

Lines changed: 137 additions & 76 deletions

File tree

tests/API/probes/CMakeLists.txt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ target_include_directories(test_api_probes_smoke PUBLIC
88
"${CMAKE_SOURCE_DIR}/src/OVAL/probes/public"
99
"${CMAKE_SOURCE_DIR}/src/common"
1010
)
11-
add_oscap_test("test_api_probes_smoke.sh")
11+
add_oscap_test("test_api_probes_smoke.sh" LABELS api probes)
1212

1313
add_oscap_test_executable(test_fsdev_is_local_fs
1414
"test_fsdev_is_local_fs.c"
1515
)
1616
target_include_directories(test_fsdev_is_local_fs PUBLIC
1717
"${CMAKE_SOURCE_DIR}/src/OVAL/probes"
1818
)
19-
add_oscap_test("test_fsdev_is_local_fs.sh")
19+
add_oscap_test("test_fsdev_is_local_fs.sh" LABELS api probes)
2020

2121
file(GLOB_RECURSE OVAL_RESULTS_SOURCES "${CMAKE_SOURCE_DIR}/src/OVAL/results/oval_cmp*.c")
2222
add_oscap_test_executable(oval_fts_list
@@ -38,7 +38,7 @@ target_include_directories(oval_fts_list PUBLIC
3838
"${CMAKE_SOURCE_DIR}/src/common"
3939
)
4040
target_link_libraries(oval_fts_list openscap)
41-
add_oscap_test("fts.sh")
41+
add_oscap_test("fts.sh" LABELS api probes)
4242

4343
add_oscap_test_executable(test_memusage
4444
"test_memusage.c"
@@ -47,4 +47,13 @@ add_oscap_test_executable(test_memusage
4747
target_include_directories(test_memusage PUBLIC
4848
"${CMAKE_SOURCE_DIR}/src/common"
4949
)
50-
add_oscap_test("test_memusage.sh")
50+
add_oscap_test("test_memusage.sh" LABELS api probes)
51+
52+
add_oscap_test_executable(test_memusage_platform
53+
"test_memusage_platform.c"
54+
"${CMAKE_SOURCE_DIR}/src/common/bfind.c"
55+
)
56+
target_include_directories(test_memusage_platform PUBLIC
57+
"${CMAKE_SOURCE_DIR}/src/common"
58+
)
59+
add_oscap_test("test_memusage_platform.sh" LABELS api probes freebsd macos linux)

tests/CMakeLists.txt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,66 @@
1+
include(CMakeParseArguments)
2+
13
function(add_oscap_test TEST_SCRIPT)
4+
set(options)
5+
set(oneValueArgs)
6+
set(multiValueArgs LABELS)
7+
cmake_parse_arguments(OSCAP_TEST "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
8+
29
string(REPLACE "${CMAKE_SOURCE_DIR}/tests/" "" TEST_NAME "${CMAKE_CURRENT_SOURCE_DIR}/${TEST_SCRIPT}")
310
add_test(NAME ${TEST_NAME}
411
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/${TEST_SCRIPT}
512
)
13+
set(TEST_LABELS "shell")
14+
# Add a suite label derived from the first path component (api, probes, report, ...)
15+
string(REGEX MATCH "^[^/]+" TEST_SUITE "${TEST_NAME}")
16+
if(TEST_SUITE)
17+
string(TOLOWER "${TEST_SUITE}" TEST_SUITE_LOWER)
18+
list(APPEND TEST_LABELS "${TEST_SUITE_LOWER}")
19+
endif()
20+
if(OSCAP_TEST_LABELS)
21+
list(APPEND TEST_LABELS ${OSCAP_TEST_LABELS})
22+
endif()
23+
list(REMOVE_DUPLICATES TEST_LABELS)
624
set_tests_properties(${TEST_NAME}
725
PROPERTIES
826
SKIP_RETURN_CODE 255
27+
LABELS "${TEST_LABELS}"
928
ENVIRONMENT "srcdir=${CMAKE_CURRENT_SOURCE_DIR};top_srcdir=${CMAKE_SOURCE_DIR};builddir=${CMAKE_BINARY_DIR}"
1029
)
1130
endfunction()
1231

32+
function(add_oscap_ctest TEST_NAME)
33+
set(options)
34+
set(oneValueArgs)
35+
set(multiValueArgs COMMAND LABELS)
36+
cmake_parse_arguments(OSCAP_CTEST "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
37+
38+
if(NOT OSCAP_CTEST_COMMAND)
39+
message(FATAL_ERROR "add_oscap_ctest requires COMMAND arguments")
40+
endif()
41+
42+
add_test(NAME ${TEST_NAME}
43+
COMMAND ${OSCAP_CTEST_COMMAND}
44+
)
45+
46+
set(TEST_LABELS "ctest")
47+
string(REPLACE "${CMAKE_SOURCE_DIR}/tests/" "" TEST_REL_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
48+
string(REGEX MATCH "^[^/]+" TEST_SUITE "${TEST_REL_DIR}")
49+
if(TEST_SUITE)
50+
string(TOLOWER "${TEST_SUITE}" TEST_SUITE_LOWER)
51+
list(APPEND TEST_LABELS "${TEST_SUITE_LOWER}")
52+
endif()
53+
if(OSCAP_CTEST_LABELS)
54+
list(APPEND TEST_LABELS ${OSCAP_CTEST_LABELS})
55+
endif()
56+
list(REMOVE_DUPLICATES TEST_LABELS)
57+
58+
set_tests_properties(${TEST_NAME}
59+
PROPERTIES
60+
LABELS "${TEST_LABELS}"
61+
)
62+
endfunction()
63+
1364
# builds a binary from a C source that will be used in a test
1465
# EXECUTABLE_NAME - name of the binary executable to be build
1566
# SOURCE_FILE - C program with a test
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
if(ENABLE_PROBES_INDEPENDENT)
2-
add_oscap_test("test_probes_environmentvariable.sh")
2+
add_oscap_test("test_probes_environmentvariable.sh" LABELS independent)
33
endif()
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
if(ENABLE_PROBES_INDEPENDENT)
2-
add_oscap_test("test_probes_environmentvariable58.sh")
3-
add_oscap_test("test_probes_environmentvariable58_offline_mode.sh")
2+
add_oscap_test("test_probes_environmentvariable58.sh" LABELS independent)
3+
add_oscap_test("test_probes_environmentvariable58_offline_mode.sh" LABELS independent)
44
endif()

tests/probes/family/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
if(ENABLE_PROBES_INDEPENDENT)
2-
add_oscap_test("test_probes_family.sh")
2+
add_oscap_test("test_probes_family.sh" LABELS independent)
33
endif()

tests/probes/file/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
if(ENABLE_PROBES_UNIX)
2-
add_oscap_test("test_probes_file.sh")
3-
add_oscap_test("test_probes_file_behaviour.sh")
4-
add_oscap_test("test_probes_file_multiple_file_paths.sh")
2+
add_oscap_test("test_probes_file.sh" LABELS unix)
3+
add_oscap_test("test_probes_file_behaviour.sh" LABELS unix)
4+
add_oscap_test("test_probes_file_multiple_file_paths.sh" LABELS unix)
55
endif()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
if(ENABLE_PROBES_UNIX)
2-
add_oscap_test("test_probes_fileextendedattribute.sh")
2+
add_oscap_test("test_probes_fileextendedattribute.sh" LABELS unix)
33
endif()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
if(OPENSCAP_PROBE_INDEPENDENT_FILEHASH)
2-
add_oscap_test("test_probes_filehash.sh")
2+
add_oscap_test("test_probes_filehash.sh" LABELS independent)
33
endif()
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
if(ENABLE_PROBES_INDEPENDENT)
2-
add_oscap_test("test_probes_filehash58.sh")
3-
add_oscap_test("rhbz1959570_segfault.sh")
2+
add_oscap_test("test_probes_filehash58.sh" LABELS independent)
3+
add_oscap_test("rhbz1959570_segfault.sh" LABELS independent)
44
endif()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
if(ENABLE_PROBES_INDEPENDENT)
2-
add_oscap_test("test_probes_filemd5.sh")
2+
add_oscap_test("test_probes_filemd5.sh" LABELS independent)
33
endif()

0 commit comments

Comments
 (0)