Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake_utils/cmake/test/gtest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -98,4 +99,3 @@ macro(add_xtsan_label LIST_FILE)
endforeach()
endif()
endmacro()

75 changes: 75 additions & 0 deletions cmake_utils/cmake/test/test_labels.cmake
Original file line number Diff line number Diff line change
@@ -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()
10 changes: 10 additions & 0 deletions cmake_utils/cmake/test/test_target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cpp_utils/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
23 changes: 23 additions & 0 deletions cpp_utils/test/labels/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
@@ -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
Empty file.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
SignalEventHandlerTest.erase_callback_while_other_handling
SignalEventHandlerTest.receive_n_signals
SignalEventHandlerTest.receive_signal
SignalEventHandlerTest.receive_signal_trivial
5 changes: 0 additions & 5 deletions cpp_utils/test/unittest/event/signal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 0 additions & 4 deletions cpp_utils/test/unittest/math/random/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 0 additions & 6 deletions cpp_utils/test/unittest/math/random/TEST_XFAIL.list

This file was deleted.