diff --git a/cmake_utils/cmake/test/gtest.cmake b/cmake_utils/cmake/test/gtest.cmake index 2f5d67b3..0b4bc423 100644 --- a/cmake_utils/cmake/test/gtest.cmake +++ b/cmake_utils/cmake/test/gtest.cmake @@ -75,6 +75,7 @@ macro(check_gmock) endif() endmacro() +# TODO remove when possible in favor of test_utils.cmake::add_test_label macro(add_xfail_label LIST_FILE) if(EXISTS ${LIST_FILE}) file(STRINGS ${LIST_FILE} TEST_LIST) @@ -98,4 +99,3 @@ macro(add_xtsan_label LIST_FILE) endforeach() endif() endmacro() - diff --git a/cmake_utils/cmake/test/test_labels.cmake b/cmake_utils/cmake/test/test_labels.cmake new file mode 100644 index 00000000..bf4a3ec6 --- /dev/null +++ b/cmake_utils/cmake/test/test_labels.cmake @@ -0,0 +1,75 @@ +# Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# In order to centralize all the labels for all the tests, these macros has been implemented +# A variable ${PROJECT_NAME}_TEST_LABELS is set with all labels accepted (labels could be repeated) +# A variable ${PROJECT_NAME}_LABEL_TEST_${N} is set for each N and contains the name of the file +# where to read the tests that must have such label set in previous variable. +# The value N in ${PROJECT_NAME}_TEST_LABELS is the label to set in tests listed in file +# ${PROJECT_NAME}_LABEL_TEST_${N} + +macro(set_test_label_file FILE_NAME LABEL) + + message(STATUS "Set ${LABEL} label to tests in ${FILE_NAME} <${${PROJECT_NAME}_TEST_LABELS}>") + + # First check if file exists + if(NOT EXISTS ${FILE_NAME}) + message(WARNING "File ${FILE_NAME} does not exist, impossible to set label ${LABEL}") + return() + else() + # Read file + file(STRINGS ${FILE_NAME} TEST_LIST) + endif() + + list(LENGTH INTERNAL_TEST_LABELS LABELS_SIZE) + + message(STATUS "set_test_label_file <${INTERNAL_TEST_LABELS}> <${LABELS_SIZE}>") + + # Append the new label to the list + list(APPEND INTERNAL_TEST_LABELS "${LABEL}") + set(${PROJECT_NAME}_TEST_LABELS "${INTERNAL_TEST_LABELS}") + set(${PROJECT_NAME}_TEST_LABELS "${INTERNAL_TEST_LABELS}" PARENT_SCOPE) + + # Store the file content in a variable with the label index in its name + # NOTE: for some reason this must be set twice, once with parent scope and one without + set(${PROJECT_NAME}_LABEL_TEST_${LABELS_SIZE} "${TEST_LIST}") + set(${PROJECT_NAME}_LABEL_TEST_${LABELS_SIZE} "${TEST_LIST}" PARENT_SCOPE) + +endmacro() + +macro(check_and_add_tests_label TEST_NAME TEST_LABEL_LIST LABEL) + + if(${TEST_NAME} IN_LIST "${TEST_LABEL_LIST}") + message(STATUS "Setting label ${LABEL} to test ${TEST_NAME}") + set_property(TEST ${TEST_NAME} PROPERTY LABELS ${LABEL}) + endif() + +endmacro() + +macro(set_test_labels TEST_NAME) + + set (CURRENT_INDEX 0) + foreach(TEST_LABEL ${${PROJECT_NAME}_TEST_LABELS}) + + check_and_add_tests_label( + "${TEST_NAME}" + ${PROJECT_NAME}_LABEL_TEST_${CURRENT_INDEX} + "${TEST_LABEL}" + ) + + MATH(EXPR CURRENT_INDEX "${CURRENT_INDEX} + 1") + + endforeach() + +endmacro() diff --git a/cmake_utils/cmake/test/test_target.cmake b/cmake_utils/cmake/test/test_target.cmake index 709561cc..037041da 100644 --- a/cmake_utils/cmake/test/test_target.cmake +++ b/cmake_utils/cmake/test/test_target.cmake @@ -68,12 +68,21 @@ function(add_test_executable TEST_EXECUTABLE_NAME TEST_SOURCES TEST_NAME TEST_LI if(TEST_FRIENDLY_PATH) set_tests_properties(${TEST_NAME}.${test_name} PROPERTIES ENVIRONMENT "PATH=${TEST_FRIENDLY_PATH}") endif(TEST_FRIENDLY_PATH) + + # Add labels to tests + set_test_labels(${TEST_NAME}.${test_name}) + endforeach() else() + # If no tests are provided, create a single test message(STATUS "Creating general test ${TEST_NAME}.") add_test(NAME ${TEST_NAME} COMMAND ${TEST_EXECUTABLE_NAME}) + + # Add labels to tests + set_test_labels(${TEST_NAME}) + endif( TEST_LIST ) target_compile_definitions(${TEST_EXECUTABLE_NAME} @@ -87,6 +96,7 @@ function(add_test_executable TEST_EXECUTABLE_NAME TEST_SOURCES TEST_NAME TEST_LI COPYONLY) endforeach() + endfunction(add_test_executable) # Create an executable for a unittest diff --git a/cpp_utils/test/CMakeLists.txt b/cpp_utils/test/CMakeLists.txt index 19c7ffc5..e5ab38e0 100644 --- a/cpp_utils/test/CMakeLists.txt +++ b/cpp_utils/test/CMakeLists.txt @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Include utils for this specific test -include_directories("TestUtils") +# Add subdirectory with labels for tests +add_subdirectory(labels) # Add subdirectory with tests add_subdirectory(unittest) diff --git a/cpp_utils/test/labels/CMakeLists.txt b/cpp_utils/test/labels/CMakeLists.txt new file mode 100644 index 00000000..a92ef04f --- /dev/null +++ b/cpp_utils/test/labels/CMakeLists.txt @@ -0,0 +1,23 @@ +# Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Set list of tests that can fail +set_test_label_file(${CMAKE_CURRENT_SOURCE_DIR}/XFAIL.list "xfail") +# Set list of tests that can fail using TSAN +set_test_label_file(${CMAKE_CURRENT_SOURCE_DIR}/XTSAN.list "xtsan") + +# Set list of tests that can fail in windows +if (WIN32) + set_test_label_file(${CMAKE_CURRENT_SOURCE_DIR}/WINDOWS_TEST_XFAIL.list "xfail") +endif() diff --git a/cpp_utils/test/unittest/event/signal/TEST_XTSAN.list b/cpp_utils/test/labels/WINDOWS_XFAIL.list similarity index 100% rename from cpp_utils/test/unittest/event/signal/TEST_XTSAN.list rename to cpp_utils/test/labels/WINDOWS_XFAIL.list index 4841866a..3a330782 100644 --- a/cpp_utils/test/unittest/event/signal/TEST_XTSAN.list +++ b/cpp_utils/test/labels/WINDOWS_XFAIL.list @@ -1,4 +1,4 @@ -SignalEventHandlerTest.receive_signal_trivial -SignalEventHandlerTest.receive_signal -SignalEventHandlerTest.receive_n_signals SignalEventHandlerTest.erase_callback_while_other_handling +SignalEventHandlerTest.receive_n_signals +SignalEventHandlerTest.receive_signal +SignalEventHandlerTest.receive_signal_trivial diff --git a/cpp_utils/test/labels/XFAIL.list b/cpp_utils/test/labels/XFAIL.list new file mode 100644 index 00000000..e69de29b diff --git a/cpp_utils/test/unittest/event/signal/WINDOWS_TEST_XFAIL.list b/cpp_utils/test/labels/XTSAN.list similarity index 75% rename from cpp_utils/test/unittest/event/signal/WINDOWS_TEST_XFAIL.list rename to cpp_utils/test/labels/XTSAN.list index 1152bc80..3a330782 100644 --- a/cpp_utils/test/unittest/event/signal/WINDOWS_TEST_XFAIL.list +++ b/cpp_utils/test/labels/XTSAN.list @@ -1,3 +1,4 @@ SignalEventHandlerTest.erase_callback_while_other_handling SignalEventHandlerTest.receive_n_signals SignalEventHandlerTest.receive_signal +SignalEventHandlerTest.receive_signal_trivial diff --git a/cpp_utils/test/unittest/event/signal/CMakeLists.txt b/cpp_utils/test/unittest/event/signal/CMakeLists.txt index 9d3c1551..4a486764 100644 --- a/cpp_utils/test/unittest/event/signal/CMakeLists.txt +++ b/cpp_utils/test/unittest/event/signal/CMakeLists.txt @@ -40,8 +40,3 @@ add_unittest_executable( "${TEST_LIST}" "${TEST_EXTRA_LIBRARIES}" ) - -add_windows_xfail_label(${CMAKE_CURRENT_SOURCE_DIR}/WINDOWS_TEST_XFAIL.list) - -# TSAN captures and handles raised signals, thus these tests cannot succeed -add_xtsan_label(${CMAKE_CURRENT_SOURCE_DIR}/TEST_XTSAN.list) diff --git a/cpp_utils/test/unittest/math/random/CMakeLists.txt b/cpp_utils/test/unittest/math/random/CMakeLists.txt index 85a8be9b..ad81c6de 100644 --- a/cpp_utils/test/unittest/math/random/CMakeLists.txt +++ b/cpp_utils/test/unittest/math/random/CMakeLists.txt @@ -83,7 +83,3 @@ add_unittest_executable( "${TEST_EXTRA_LIBRARIES}" "${TEST_NEEDED_SOURCES}" ) - -# These tests check random behaviours, thys some of them could eventually fail -# Set flaky tests as xfail -add_xfail_label(${CMAKE_CURRENT_SOURCE_DIR}/TEST_XFAIL.list) diff --git a/cpp_utils/test/unittest/math/random/TEST_XFAIL.list b/cpp_utils/test/unittest/math/random/TEST_XFAIL.list deleted file mode 100644 index a6b8eb39..00000000 --- a/cpp_utils/test/unittest/math/random/TEST_XFAIL.list +++ /dev/null @@ -1,6 +0,0 @@ -randomTest.get_pure_random_number -randomTest.get_seed_random_number -randomTest.set_initial_seed -tsaferandomTest.get_pure_random_number -tsaferandomTest.get_seed_random_number -tsaferandomTest.set_initial_seed