Skip to content

Commit bb5b582

Browse files
committed
cmake: Introduce ctest TEST labels for testing and COST
Tests in CMake/Ctest can have labels on which can be filtered ctest --print-labels Test project /home/wjw/work/ceph/build All Labels: freebsd long run-tox unittest vstart Which allows to run certain subsets of by using RE filters in ctest. COST will determine the order in which the tests are executed. Current settings will start with long running tests. Signed-off-by: Willem Jan Withagen <[email protected]>
1 parent c5a57b6 commit bb5b582

File tree

11 files changed

+68
-23
lines changed

11 files changed

+68
-23
lines changed

cmake/modules/AddCephTest.cmake

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
11
#AddCephTest is a module for adding tests to the "make check" target which runs CTest
22

3+
macro(set_test_props labels cost cost_default timeout)
4+
if(DEFINED timeout)
5+
set_property(TEST ${test_name} PROPERTY TIMEOUT ${timeout})
6+
else()
7+
set_property(TEST ${test_name} PROPERTY TIMEOUT ${CEPH_TEST_TIMEOUT})
8+
endif()
9+
if(DEFINED cost)
10+
set_property(TEST ${test_name} PROPERTY COST ${cost})
11+
else()
12+
set_property(TEST ${test_name} PROPERTY COST ${cost_default})
13+
endif()
14+
if(DEFINED labels)
15+
set_property(TEST ${test_name} PROPERTY LABELS ${labels})
16+
endif()
17+
endmacro()
18+
319
#adds makes target/script into a test, test to check target, sets necessary environment variables
420
function(add_ceph_test test_name test_path)
5-
add_test(NAME ${test_name} COMMAND ${test_path} ${ARGN})
21+
set(options "")
22+
set(oneValueArgs COST TIMEOUT)
23+
set(multiValueArgs LABELS)
24+
cmake_parse_arguments(PROPS "${options}" "${oneValueArgs}"
25+
"${multiValueArgs}" ${ARGN} )
26+
27+
add_test(NAME ${test_name} COMMAND ${test_path} ${PROPS_UNPARSED_ARGUMENTS})
628
if(TARGET ${test_name})
729
add_dependencies(tests ${test_name})
830
endif()
@@ -17,10 +39,7 @@ function(add_ceph_test test_name test_path)
1739
PATH=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}:${CMAKE_SOURCE_DIR}/src:$ENV{PATH}
1840
PYTHONPATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cython_modules/lib.${Python${PYTHON_VERSION}_VERSION_MAJOR}:${CMAKE_SOURCE_DIR}/src/pybind
1941
CEPH_BUILD_VIRTUALENV=${CEPH_BUILD_VIRTUALENV})
20-
# none of the tests should take more than 1 hour to complete
21-
set_property(TEST
22-
${test_name}
23-
PROPERTY TIMEOUT ${CEPH_TEST_TIMEOUT})
42+
set_test_props("${PROPS_LABELS}" "${PROPS_COST}" 5.0 "${PROPS_TIMEOUT}")
2443
endfunction()
2544

2645
option(WITH_GTEST_PARALLEL "Enable running gtest based tests in parallel" OFF)
@@ -44,19 +63,21 @@ endif()
4463

4564
#sets uniform compiler flags and link libraries
4665
function(add_ceph_unittest unittest_name)
66+
cmake_parse_arguments(PROPS "" "COST;TIMEOUT" "LABELS" ${ARGN})
4767
set(UNITTEST "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${unittest_name}")
4868
# If the second argument is "parallel", it means we want a parallel run
4969
if(WITH_GTEST_PARALLEL AND "${ARGV1}" STREQUAL "parallel")
5070
set(UNITTEST ${GTEST_PARALLEL_COMMAND} ${UNITTEST})
5171
endif()
52-
add_ceph_test(${unittest_name} "${UNITTEST}")
72+
add_ceph_test(${unittest_name} "${UNITTEST}" "unittest" LABELS "unittest")
5373
target_link_libraries(${unittest_name} ${UNITTEST_LIBS})
74+
set_test_props("${PROPS_LABELS}" "${PROPS_COST}" 1.0 "${PROPS_TIMEOUT}")
5475
endfunction()
5576

5677
function(add_tox_test name)
5778
set(test_name run-tox-${name})
5879
set(venv_path ${CEPH_BUILD_VIRTUALENV}/${name}-virtualenv)
59-
cmake_parse_arguments(TOXTEST "" "TOX_PATH" "TOX_ENVS" ${ARGN})
80+
cmake_parse_arguments(TOXTEST "" "TOX_PATH;COST;TIMEOUT" "TOX_ENVS;LABELS" ${ARGN})
6081
if(DEFINED TOXTEST_TOX_PATH)
6182
set(tox_path ${TOXTEST_TOX_PATH})
6283
else()
@@ -99,4 +120,6 @@ function(add_tox_test name)
99120
PATH=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}:${CMAKE_SOURCE_DIR}/src:$ENV{PATH}
100121
PYTHONPATH=${CMAKE_SOURCE_DIR}/src/pybind)
101122
list(APPEND tox_test run-tox-${name})
123+
set_tests_properties(${test_name} PROPERTIES LABELS "tox")
124+
set_test_props("${TOXTEST_LABELS}" "${TOXTEST_COST}" 25.0 "${TOXTEST_TIMEOUT}")
102125
endfunction()

doc/dev/developer_guide/index.rst

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,25 @@ Unit tests are declared in the ``CMakeLists.txt`` files (multiple files under
777777
which are themselves defined in ``./cmake/modules/AddCephTest.cmake``. Some
778778
unit tests are scripts, while others are binaries that are compiled during the
779779
build process. The ``add_ceph_test`` function is used to declare unit test
780-
scripts, while ``add_ceph_unittest`` is used for unit test binaries.
780+
scripts, while ``add_ceph_unittest`` is used for unit test binaries.
781+
``add_tox_test`` declare tests that require ``tox`` for testing and sets up
782+
the full environment for this during testing.
783+
::
784+
785+
add_ceph_test(test_name test_path <args> <options>)
786+
add_ceph_unittest(test_name <args> <options>)
787+
add_tox_test(test_name <args> <options>)
788+
args: any parameter, not being an options keyword
789+
options:
790+
[COST <float>]
791+
Order of testing is set by COST.
792+
Highest COST are tested first.
793+
[TIMEOUT sec]
794+
Restrict the max runtime of this test to <sec>
795+
[LABELS "labels"]
796+
Append "labels" to a test.
797+
Labels can be selected with ctest -L or -LE
798+
781799

782800
Unit testing of CLI tools
783801
^^^^^^^^^^^^^^^^^^^^^^^^^

src/pybind/mgr/dashboard/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,5 @@ endif(WITH_MGR_DASHBOARD_FRONTEND AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "aarch6
9898

9999
if(WITH_TESTS)
100100
include(AddCephTest)
101-
add_tox_test(mgr-dashboard TOX_ENVS lint check)
101+
add_tox_test(mgr-dashboard TOX_ENVS lint check LABELS "long" COST 50.0)
102102
endif()

src/test/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -527,18 +527,18 @@ if(WITH_FIO OR WITH_SYSTEM_FIO)
527527
endif()
528528

529529
if(WITH_RBD)
530-
add_ceph_test(run-rbd-unit-tests.sh ${CMAKE_CURRENT_SOURCE_DIR}/run-rbd-unit-tests.sh)
530+
add_ceph_test(run-rbd-unit-tests.sh ${CMAKE_CURRENT_SOURCE_DIR}/run-rbd-unit-tests.sh LABELS "long" COST 1000.0)
531531
if(FREEBSD)
532-
add_ceph_test(rbd-ggate.sh ${CMAKE_CURRENT_SOURCE_DIR}/rbd-ggate.sh)
532+
add_ceph_test(rbd-ggate.sh ${CMAKE_CURRENT_SOURCE_DIR}/rbd-ggate.sh LABELS "vstart;freebsd" COST 160.0)
533533
endif(FREEBSD)
534534
endif(WITH_RBD)
535-
add_ceph_test(run-cli-tests ${CMAKE_CURRENT_SOURCE_DIR}/run-cli-tests)
535+
add_ceph_test(run-cli-tests ${CMAKE_CURRENT_SOURCE_DIR}/run-cli-tests LABELS "long" COST 519.0)
536536
add_ceph_test(test_objectstore_memstore.sh ${CMAKE_CURRENT_SOURCE_DIR}/test_objectstore_memstore.sh)
537537

538538
# flaky
539539
#add_ceph_test(test_pidfile.sh ${CMAKE_CURRENT_SOURCE_DIR}/test_pidfile.sh)
540540

541-
add_ceph_test(smoke.sh ${CMAKE_CURRENT_SOURCE_DIR}/smoke.sh)
541+
add_ceph_test(smoke.sh ${CMAKE_CURRENT_SOURCE_DIR}/smoke.sh LABELS "long" COST 230)
542542

543543
set_property(
544544
TEST ${tox_tests}
@@ -662,7 +662,7 @@ add_executable(unittest_bufferlist
662662
bufferlist.cc
663663
$<TARGET_OBJECTS:unit-main>
664664
)
665-
add_ceph_unittest(unittest_bufferlist)
665+
add_ceph_unittest(unittest_bufferlist LABELS "long" COST 630)
666666
target_link_libraries(unittest_bufferlist global)
667667

668668
# compiletest_cxx11_client

src/test/ObjectMap/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ add_executable(ceph_test_object_map
33
test_object_map.cc
44
KeyValueDBMemory.cc
55
)
6-
add_ceph_unittest(ceph_test_object_map)
6+
add_ceph_unittest(ceph_test_object_map LABELS "long" COST 350.0)
77
target_link_libraries(ceph_test_object_map
88
os
99
ceph-common

src/test/encoding/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# scripts
2-
add_ceph_test(check-generated.sh ${CMAKE_CURRENT_SOURCE_DIR}/check-generated.sh)
3-
add_ceph_test(readable.sh ${CMAKE_CURRENT_SOURCE_DIR}/readable.sh)
2+
add_ceph_test(check-generated.sh ${CMAKE_CURRENT_SOURCE_DIR}/check-generated.sh
3+
LABELS "long" COST 487.0)
4+
add_ceph_test(readable.sh ${CMAKE_CURRENT_SOURCE_DIR}/readable.sh
5+
LABELS "long" COST 561.0)

src/test/erasure-code/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ target_link_libraries(unittest_erasure_code_shec
201201
add_executable(unittest_erasure_code_shec_all
202202
TestErasureCodeShec_all.cc
203203
)
204-
add_ceph_unittest(unittest_erasure_code_shec_all parallel)
204+
add_ceph_unittest(unittest_erasure_code_shec_all parallel LABELS "long" COST 750.0)
205205
target_link_libraries(unittest_erasure_code_shec_all
206206
global
207207
${CMAKE_DL_LIBS}

src/test/objectstore/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ if(WITH_BLUESTORE)
103103
fastbmap_allocator_test.cc
104104
$<TARGET_OBJECTS:unit-main>
105105
)
106-
add_ceph_unittest(unittest_fastbmap_allocator)
106+
add_ceph_unittest(unittest_fastbmap_allocator LABELS "long" COST 102.0)
107107
target_link_libraries(unittest_fastbmap_allocator os global)
108108

109109
add_executable(unittest_bluefs

src/test/osd/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ install(TARGETS
3434
DESTINATION ${CMAKE_INSTALL_BINDIR})
3535

3636
# scripts
37-
add_ceph_test(safe-to-destroy.sh ${CMAKE_CURRENT_SOURCE_DIR}/safe-to-destroy.sh)
37+
add_ceph_test(safe-to-destroy.sh ${CMAKE_CURRENT_SOURCE_DIR}/safe-to-destroy.sh
38+
LABELS "long" COST 367.0)
3839

3940
# unittest_osdmap
4041
add_executable(unittest_osdmap
4142
TestOSDMap.cc
4243
)
43-
add_ceph_unittest(unittest_osdmap)
44+
add_ceph_unittest(unittest_osdmap LABELS "long" COST 91.0)
4445
target_link_libraries(unittest_osdmap global ${BLKID_LIBRARIES})
4546

4647
# unittest_osd_types

src/test/pybind/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
add_ceph_test(test_ceph_daemon.py ${CMAKE_CURRENT_SOURCE_DIR}/test_ceph_daemon.py)
2-
add_ceph_test(test_ceph_argparse.py ${CMAKE_CURRENT_SOURCE_DIR}/test_ceph_argparse.py)
2+
add_ceph_test(test_ceph_argparse.py ${CMAKE_CURRENT_SOURCE_DIR}/test_ceph_argparse.py
3+
LABELS "long" COST 104.0)

0 commit comments

Comments
 (0)