From 950339caae083850f05ec58d364d5e8b45867755 Mon Sep 17 00:00:00 2001 From: Trent Houliston Date: Fri, 18 Oct 2024 10:56:04 +1100 Subject: [PATCH 01/16] Try some coverage stuff --- .github/workflows/gcc.yaml | 12 +++++-- .github/workflows/macos.yaml | 10 ++++-- .github/workflows/sonarcloud.yaml | 42 ++++++++++++++++------ .github/workflows/windows.yaml | 12 +++++-- cmake/TestRunner.cmake | 59 +++++++++++++++++++++++++++++++ sonar-project.properties | 9 ----- src/CMakeLists.txt | 9 +++++ 7 files changed, 125 insertions(+), 28 deletions(-) create mode 100644 cmake/TestRunner.cmake delete mode 100644 sonar-project.properties diff --git a/.github/workflows/gcc.yaml b/.github/workflows/gcc.yaml index d12005087..09d408a84 100644 --- a/.github/workflows/gcc.yaml +++ b/.github/workflows/gcc.yaml @@ -92,11 +92,17 @@ jobs: - name: Test timeout-minutes: 2 - working-directory: build/tests - run: ctest --output-on-failure -E "dsl/UDP" + working-directory: build + run: ninja run_all_tests -k 0 + + - name: Test Summary + if: ${{ !cancelled() }} + uses: test-summary/action@v2 + with: + paths: "build/reports/tests/*.junit.xml" - name: Upload Traces - if: always() + if: ${{ !cancelled() }} uses: actions/upload-artifact@v4 with: name: traces-gcc-${{ matrix.toolchain.version }} diff --git a/.github/workflows/macos.yaml b/.github/workflows/macos.yaml index cc949da1d..eaf53f915 100644 --- a/.github/workflows/macos.yaml +++ b/.github/workflows/macos.yaml @@ -61,10 +61,16 @@ jobs: - name: Test timeout-minutes: 5 working-directory: build/tests - run: ctest --output-on-failure + run: ninja run_all_tests -k 0 + + - name: Test Summary + if: ${{ !cancelled() }} + uses: test-summary/action@v2 + with: + paths: "build/reports/tests/*.junit.xml" - name: Upload Traces - if: always() + if: ${{ !cancelled() }} uses: actions/upload-artifact@v4 with: name: traces-macos diff --git a/.github/workflows/sonarcloud.yaml b/.github/workflows/sonarcloud.yaml index 3a02f51e5..a7e407937 100644 --- a/.github/workflows/sonarcloud.yaml +++ b/.github/workflows/sonarcloud.yaml @@ -27,15 +27,15 @@ jobs: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - name: Install gcovr - run: pip install gcovr==7.2 + run: pip install gcovr==8.2 - name: Install sonar-scanner and build-wrapper uses: SonarSource/sonarcloud-github-c-cpp@v3 - name: Install CMake - uses: lukka/get-cmake@latest + uses: lukka/get-cmake@v3.30.5 with: - cmakeVersion: 3.27.1 + cmakeVersion: 3.30.5 ninjaVersion: 1.11.1 - name: Setup CCache @@ -49,12 +49,12 @@ jobs: cmake -E make_directory build cmake -S . -B build \ -GNinja \ - -DCMAKE_CXX_FLAGS="--coverage" \ -DCMAKE_C_COMPILER_LAUNCHER=ccache \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ - -DBUILD_TESTS=ON \ -DCMAKE_BUILD_TYPE=Debug \ + -DBUILD_TESTS=ON \ -DCI_BUILD=ON \ + -DENABLE_COVERAGE=ON \ -DENABLE_CLANG_TIDY=OFF - name: Build the code in debug mode @@ -63,25 +63,45 @@ jobs: - name: Run tests to generate coverage statistics timeout-minutes: 10 - working-directory: build/tests - run: ctest --output-on-failure + working-directory: build + run: ninja run_all_tests -k 0 + + - name: Test Summary + if: ${{ !cancelled() }} + uses: test-summary/action@v2 + with: + paths: "build/reports/tests/*.junit.xml" - name: Collect coverage into one XML report - if: always() - run: gcovr --gcov-ignore-parse-errors=negative_hits.warn_once_per_file --exclude-unreachable-branches --exclude-noncode-lines --sonarqube > coverage.xml + if: ${{ !cancelled() }} + run: | + gcovr \ + --root . \ + --object-directory build \ + --force-color \ + --no-markers \ + --decisions \ + --calls \ + --exclude-noncode-lines \ + --gcov-ignore-parse-errors negative_hits.warn \ + --sonarqube "coverage.xml" - name: Run sonar-scanner - if: always() + if: ${{ !cancelled() }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} run: | sonar-scanner \ + --define sonar.projectKey=Fastcode_NUClear \ + --define sonar.organization=fastcode \ + --define sonar.sources=src \ + --define sonar.tests=tests \ --define sonar.cfamily.compile-commands=build/compile_commands.json \ --define sonar.coverageReportPaths=coverage.xml - name: Upload Traces - if: always() + if: ${{ !cancelled }} uses: actions/upload-artifact@v4 with: name: traces-sonar diff --git a/.github/workflows/windows.yaml b/.github/workflows/windows.yaml index 2163cc35b..dd728120b 100644 --- a/.github/workflows/windows.yaml +++ b/.github/workflows/windows.yaml @@ -81,11 +81,17 @@ jobs: - name: Test timeout-minutes: 5 - working-directory: build/tests - run: ctest --output-on-failure + working-directory: build + run: ninja run_all_tests -k 0 + + - name: Test Summary + if: ${{ !cancelled() }} + uses: test-summary/action@v2 + with: + paths: "build/reports/tests/*.junit.xml" - name: Upload Traces - if: always() + if: ${{ !cancelled() }} uses: actions/upload-artifact@v4 with: name: traces-windows-${{ matrix.toolchain.name }} diff --git a/cmake/TestRunner.cmake b/cmake/TestRunner.cmake new file mode 100644 index 000000000..f2f2c617a --- /dev/null +++ b/cmake/TestRunner.cmake @@ -0,0 +1,59 @@ +# Collect all currently added targets in all subdirectories +# +# Parameters: +# - _result the list containing all found targets +# - _dir root directory to start looking from +function(get_all_catch_test_targets _result _dir) + get_property( + _subdirs + DIRECTORY "${_dir}" + PROPERTY SUBDIRECTORIES + ) + foreach(_subdir IN LISTS _subdirs) + get_all_catch_test_targets(${_result} "${_subdir}") + endforeach() + + unset(catch_targets) + get_directory_property(_sub_targets DIRECTORY "${_dir}" BUILDSYSTEM_TARGETS) + foreach(target ${_sub_targets}) + get_target_property(target_type ${target} TYPE) + if(target_type STREQUAL "EXECUTABLE") + get_target_property(target_link_libraries ${target} INTERFACE_LINK_LIBRARIES) + if(target_link_libraries MATCHES "Catch2::Catch2") + list(APPEND catch_targets ${target}) + endif() + endif() + endforeach() + + set(${_result} + ${${_result}} ${catch_targets} + PARENT_SCOPE + ) +endfunction() + +# Find all executable targets that link to Catch2::Catch2WithMain || Catch2::Catch2 +get_all_catch_test_targets(all_targets ${PROJECT_SOURCE_DIR}) + +# Create a custom command for each test target to run it +# Make sure that coverage data is written with paths relative to the source directory +unset(reports) +foreach(target ${all_targets}) + + set(sonarqube_report_file "${PROJECT_BINARY_DIR}/reports/tests/${target}.sonarqube.xml") + set(junit_report_file "${PROJECT_BINARY_DIR}/reports/tests/${target}.junit.xml") + list(APPEND reports ${sonarqube_report_file} ${junit_report_file}) + add_custom_command( + OUTPUT ${sonarqube_report_file} ${junit_report_file} + COMMAND $ --reporter console --reporter SonarQube::out=${sonarqube_report_file} --reporter + JUnit::out=${junit_report_file} + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + COMMENT "Running test ${target}" + ) +endforeach() + +# Create a custom target that depends on all test targets +add_custom_target( + run_all_tests + DEPENDS ${reports} + COMMENT "Running all Catch2 tests" +) diff --git a/sonar-project.properties b/sonar-project.properties deleted file mode 100644 index 60dc88e40..000000000 --- a/sonar-project.properties +++ /dev/null @@ -1,9 +0,0 @@ -sonar.projectName=NUClear -sonar.projectKey=Fastcode_NUClear -sonar.organization=fastcode -sonar.projectVersion=1.0 - -sonar.sources=src -sonar.tests=tests - -sonar.sourceEncoding=UTF-8 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9ce7a65ac..65f180916 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -37,6 +37,15 @@ target_link_libraries(nuclear ${CMAKE_THREAD_LIBS_INIT}) set_target_properties(nuclear PROPERTIES POSITION_INDEPENDENT_CODE ON) target_compile_features(nuclear PUBLIC cxx_std_14) +option(ENABLE_COVERAGE "Compile with coverage support enabled.") +if(ENABLE_COVERAGE) + if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") + message(WARNING "Coverage is enabled but not build in debug mode. Coverage results may be misleading.") + endif() + target_compile_options(nuclear PUBLIC -fprofile-arcs -ftest-coverage -fprofile-abs-path -fprofile-update=atomic) + target_link_options(nuclear PUBLIC -fprofile-arcs) +endif(ENABLE_COVERAGE) + # Enable warnings, and all warnings are errors if(MSVC) target_compile_options(nuclear PRIVATE /W4 /WX) From eeca6f2a5d51bac4372667f5b340a6d6904b361b Mon Sep 17 00:00:00 2001 From: Trent Houliston Date: Fri, 18 Oct 2024 11:11:36 +1100 Subject: [PATCH 02/16] add the test runner --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b5064757d..4c70ae8a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,6 +89,7 @@ option(BUILD_TESTS "Builds all of the NUClear unit tests." ON) if(BUILD_TESTS) enable_testing() add_subdirectory(tests) + include(TestRunner) endif() # Add the documentation subdirectory From 6f6ded8a020c73f17781b69f49cfce010d4335ad Mon Sep 17 00:00:00 2001 From: Trent Houliston Date: Fri, 18 Oct 2024 11:13:08 +1100 Subject: [PATCH 03/16] Fix mac --- .github/workflows/macos.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/macos.yaml b/.github/workflows/macos.yaml index eaf53f915..4483dd9f6 100644 --- a/.github/workflows/macos.yaml +++ b/.github/workflows/macos.yaml @@ -60,7 +60,7 @@ jobs: - name: Test timeout-minutes: 5 - working-directory: build/tests + working-directory: build run: ninja run_all_tests -k 0 - name: Test Summary From d84c30b9baa0872d603fd0f3eceee726d0e2c6c1 Mon Sep 17 00:00:00 2001 From: Trent Houliston Date: Fri, 18 Oct 2024 11:41:53 +1100 Subject: [PATCH 04/16] . --- .github/workflows/sonarcloud.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yaml b/.github/workflows/sonarcloud.yaml index a7e407937..75739d9f1 100644 --- a/.github/workflows/sonarcloud.yaml +++ b/.github/workflows/sonarcloud.yaml @@ -101,7 +101,7 @@ jobs: --define sonar.coverageReportPaths=coverage.xml - name: Upload Traces - if: ${{ !cancelled }} + if: ${{ !cancelled() }} uses: actions/upload-artifact@v4 with: name: traces-sonar From c08a7030a50d0922ac31eb44f5d0854a4c30dbf8 Mon Sep 17 00:00:00 2001 From: Trent Houliston Date: Sat, 26 Oct 2024 14:52:32 +1100 Subject: [PATCH 05/16] 1 at a time --- .github/workflows/sonarcloud.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yaml b/.github/workflows/sonarcloud.yaml index 75739d9f1..07bc629b2 100644 --- a/.github/workflows/sonarcloud.yaml +++ b/.github/workflows/sonarcloud.yaml @@ -64,7 +64,7 @@ jobs: - name: Run tests to generate coverage statistics timeout-minutes: 10 working-directory: build - run: ninja run_all_tests -k 0 + run: ninja run_all_tests -j1 -k 0 - name: Test Summary if: ${{ !cancelled() }} From 570ccbb9b4e9a414bcadb710a239bb5c120d7ac0 Mon Sep 17 00:00:00 2001 From: Trent Houliston Date: Tue, 21 Jan 2025 20:06:00 +1100 Subject: [PATCH 06/16] Add code to skip ipv4 multicast if it's not available --- tests/test_util/has_ipv4_multicast.cpp | 40 ++++++++++++++++++++++++++ tests/test_util/has_ipv4_multicast.hpp | 32 +++++++++++++++++++++ tests/tests/dsl/UDP.cpp | 7 +++-- 3 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 tests/test_util/has_ipv4_multicast.cpp create mode 100644 tests/test_util/has_ipv4_multicast.hpp diff --git a/tests/test_util/has_ipv4_multicast.cpp b/tests/test_util/has_ipv4_multicast.cpp new file mode 100644 index 000000000..cc67d3337 --- /dev/null +++ b/tests/test_util/has_ipv4_multicast.cpp @@ -0,0 +1,40 @@ +/* + * MIT License + * + * Copyright (c) 2023 NUClear Contributors + * + * This file is part of the NUClear codebase. + * See https://github.com/Fastcode/NUClear for further info. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "has_ipv4_multicast.hpp" + +#include + +#include "util/network/get_interfaces.hpp" +#include "util/platform.hpp" + +namespace test_util { + +bool has_ipv6() { + // See if any interface has multicast ipv4 + auto ifaces = NUClear::util::network::get_interfaces(); + return std::any_of(ifaces.begin(), ifaces.end(), [](const auto& iface) { + return iface.ip.sock.sa_family == AF_INET && iface.flags.multicast; + }); +} + +} // namespace test_util diff --git a/tests/test_util/has_ipv4_multicast.hpp b/tests/test_util/has_ipv4_multicast.hpp new file mode 100644 index 000000000..5ee4b5532 --- /dev/null +++ b/tests/test_util/has_ipv4_multicast.hpp @@ -0,0 +1,32 @@ +/* + * MIT License + * + * Copyright (c) 2025 NUClear Contributors + * + * This file is part of the NUClear codebase. + * See https://github.com/Fastcode/NUClear for further info. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef TEST_UTIL_HAS_IPV4_MULTICAST_HPP +#define TEST_UTIL_HAS_IPV4_MULTICAST_HPP + +namespace test_util { + +bool has_ipv4_multicast(); + +} // namespace test_util + +#endif // TEST_UTIL_HAS_IPV4_MULTICAST_HPP diff --git a/tests/tests/dsl/UDP.cpp b/tests/tests/dsl/UDP.cpp index 38ede4176..a274f4616 100644 --- a/tests/tests/dsl/UDP.cpp +++ b/tests/tests/dsl/UDP.cpp @@ -35,6 +35,7 @@ #include "nuclear" #include "test_util/TestBase.hpp" #include "test_util/common.hpp" +#include "test_util/has_ipv4_multicast.hpp" #include "test_util/has_ipv6.hpp" #include "util/network/get_interfaces.hpp" #include "util/platform.hpp" @@ -377,8 +378,10 @@ TEST_CASE("Testing sending and receiving of UDP messages", "[api][network][udp]" } active_tests.push_back(BROADCAST_V4_KNOWN); active_tests.push_back(BROADCAST_V4_EPHEMERAL); - active_tests.push_back(MULTICAST_V4_KNOWN); - active_tests.push_back(MULTICAST_V4_EPHEMERAL); + if (test_util::has_ipv4_multicast()) { + active_tests.push_back(MULTICAST_V4_KNOWN); + active_tests.push_back(MULTICAST_V4_EPHEMERAL); + } if (test_util::has_ipv6()) { active_tests.push_back(MULTICAST_V6_KNOWN); active_tests.push_back(MULTICAST_V6_EPHEMERAL); From cd9327e751ba384c82167964a2908153331574dc Mon Sep 17 00:00:00 2001 From: Trent Houliston Date: Tue, 21 Jan 2025 20:12:28 +1100 Subject: [PATCH 07/16] . --- tests/test_util/has_ipv4_multicast.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_util/has_ipv4_multicast.cpp b/tests/test_util/has_ipv4_multicast.cpp index cc67d3337..20c3d6b2b 100644 --- a/tests/test_util/has_ipv4_multicast.cpp +++ b/tests/test_util/has_ipv4_multicast.cpp @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2023 NUClear Contributors + * Copyright (c) 2025 NUClear Contributors * * This file is part of the NUClear codebase. * See https://github.com/Fastcode/NUClear for further info. @@ -29,7 +29,7 @@ namespace test_util { -bool has_ipv6() { +bool has_ipv4_multicast() { // See if any interface has multicast ipv4 auto ifaces = NUClear::util::network::get_interfaces(); return std::any_of(ifaces.begin(), ifaces.end(), [](const auto& iface) { From 658d559f3aded92df3bf323801d016470df41b74 Mon Sep 17 00:00:00 2001 From: Trent Houliston Date: Tue, 21 Jan 2025 20:16:07 +1100 Subject: [PATCH 08/16] try both v4 and v6? --- .../{has_ipv4_multicast.cpp => has_multicast.cpp} | 10 ++++++++-- .../{has_ipv4_multicast.hpp => has_multicast.hpp} | 1 + tests/tests/dsl/UDP.cpp | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) rename tests/test_util/{has_ipv4_multicast.cpp => has_multicast.cpp} (85%) rename tests/test_util/{has_ipv4_multicast.hpp => has_multicast.hpp} (98%) diff --git a/tests/test_util/has_ipv4_multicast.cpp b/tests/test_util/has_multicast.cpp similarity index 85% rename from tests/test_util/has_ipv4_multicast.cpp rename to tests/test_util/has_multicast.cpp index 20c3d6b2b..e37e5de99 100644 --- a/tests/test_util/has_ipv4_multicast.cpp +++ b/tests/test_util/has_multicast.cpp @@ -20,10 +20,9 @@ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "has_ipv4_multicast.hpp" - #include +#include "has_ipv4_multicast.hpp" #include "util/network/get_interfaces.hpp" #include "util/platform.hpp" @@ -37,4 +36,11 @@ bool has_ipv4_multicast() { }); } +bool has_ipv6_multicast() { + // See if any interface has multicast ipv6 + auto ifaces = NUClear::util::network::get_interfaces(); + return std::any_of(ifaces.begin(), ifaces.end(), [](const auto& iface) { + return iface.ip.sock.sa_family == AF_INET6 && iface.flags.multicast; + }); + } // namespace test_util diff --git a/tests/test_util/has_ipv4_multicast.hpp b/tests/test_util/has_multicast.hpp similarity index 98% rename from tests/test_util/has_ipv4_multicast.hpp rename to tests/test_util/has_multicast.hpp index 5ee4b5532..d94b2e179 100644 --- a/tests/test_util/has_ipv4_multicast.hpp +++ b/tests/test_util/has_multicast.hpp @@ -26,6 +26,7 @@ namespace test_util { bool has_ipv4_multicast(); +bool has_ipv6_multicast(); } // namespace test_util diff --git a/tests/tests/dsl/UDP.cpp b/tests/tests/dsl/UDP.cpp index a274f4616..16ca247db 100644 --- a/tests/tests/dsl/UDP.cpp +++ b/tests/tests/dsl/UDP.cpp @@ -35,8 +35,8 @@ #include "nuclear" #include "test_util/TestBase.hpp" #include "test_util/common.hpp" -#include "test_util/has_ipv4_multicast.hpp" #include "test_util/has_ipv6.hpp" +#include "test_util/has_multicast.hpp" #include "util/network/get_interfaces.hpp" #include "util/platform.hpp" @@ -382,7 +382,7 @@ TEST_CASE("Testing sending and receiving of UDP messages", "[api][network][udp]" active_tests.push_back(MULTICAST_V4_KNOWN); active_tests.push_back(MULTICAST_V4_EPHEMERAL); } - if (test_util::has_ipv6()) { + if (test_util::has_ipv6() && test_util::has_ipv6_multicast()) { active_tests.push_back(MULTICAST_V6_KNOWN); active_tests.push_back(MULTICAST_V6_EPHEMERAL); } From 142c05061d05079d07eaab2a90a54380a3dad989 Mon Sep 17 00:00:00 2001 From: Trent Houliston Date: Tue, 21 Jan 2025 20:17:44 +1100 Subject: [PATCH 09/16] . --- tests/test_util/has_multicast.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_util/has_multicast.cpp b/tests/test_util/has_multicast.cpp index e37e5de99..3dc5230f7 100644 --- a/tests/test_util/has_multicast.cpp +++ b/tests/test_util/has_multicast.cpp @@ -20,9 +20,10 @@ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include "has_multicast.hpp" + #include -#include "has_ipv4_multicast.hpp" #include "util/network/get_interfaces.hpp" #include "util/platform.hpp" From d3d1708efbaf7471edc780f9d4349480920ade05 Mon Sep 17 00:00:00 2001 From: Trent Houliston Date: Sat, 25 Jan 2025 09:28:33 +1100 Subject: [PATCH 10/16] Fix compile error --- tests/test_util/has_multicast.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_util/has_multicast.cpp b/tests/test_util/has_multicast.cpp index 3dc5230f7..4b5b0fbca 100644 --- a/tests/test_util/has_multicast.cpp +++ b/tests/test_util/has_multicast.cpp @@ -43,5 +43,6 @@ bool has_ipv6_multicast() { return std::any_of(ifaces.begin(), ifaces.end(), [](const auto& iface) { return iface.ip.sock.sa_family == AF_INET6 && iface.flags.multicast; }); +} } // namespace test_util From 65f9a72462e0a837bba0565f4b5164a1324c0ceb Mon Sep 17 00:00:00 2001 From: Trent Houliston Date: Sat, 25 Jan 2025 09:36:49 +1100 Subject: [PATCH 11/16] Remove the missed TLS shim --- src/util/platform.hpp | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/util/platform.hpp b/src/util/platform.hpp index a151deaf3..95a1ba98a 100644 --- a/src/util/platform.hpp +++ b/src/util/platform.hpp @@ -96,17 +96,6 @@ #endif // _WIN32 -/******************************************* - * SHIM FOR THREAD LOCAL STORAGE * - *******************************************/ -#if defined(__GNUC__) - #define ATTRIBUTE_TLS __thread -#elif defined(_WIN32) - #define ATTRIBUTE_TLS __declspec(thread) -#else // !__GNUC__ && !_MSC_VER - #error "Define a thread local storage qualifier for your compiler/platform!" -#endif - /******************************************* * SHIM FOR NETWORKING * *******************************************/ From 223f5afe74a870db852135008e75015452dfe800 Mon Sep 17 00:00:00 2001 From: Trent Houliston Date: Sat, 25 Jan 2025 14:32:39 +1100 Subject: [PATCH 12/16] Give debug compiled code more time to run --- .github/workflows/sonarcloud.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/sonarcloud.yaml b/.github/workflows/sonarcloud.yaml index 8c172e1b6..f147354d5 100644 --- a/.github/workflows/sonarcloud.yaml +++ b/.github/workflows/sonarcloud.yaml @@ -45,6 +45,8 @@ jobs: max-size: 100M - name: Configure CMake + env: + CXXFLAGS: -DNUCLEAR_TEST_TIME_UNIT_DEN=10 run: | cmake -E make_directory build cmake -S . -B build \ From 976be11f38c6f923db131e6ae1ceb4b848eb48b7 Mon Sep 17 00:00:00 2001 From: Trent Houliston Date: Sat, 25 Jan 2025 14:51:56 +1100 Subject: [PATCH 13/16] Uses terminal so it prints stuff as it goes --- cmake/TestRunner.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/TestRunner.cmake b/cmake/TestRunner.cmake index f2f2c617a..0d3070821 100644 --- a/cmake/TestRunner.cmake +++ b/cmake/TestRunner.cmake @@ -47,6 +47,7 @@ foreach(target ${all_targets}) COMMAND $ --reporter console --reporter SonarQube::out=${sonarqube_report_file} --reporter JUnit::out=${junit_report_file} WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + USES_TERMINAL COMMENT "Running test ${target}" ) endforeach() From 18c79d1baac4052910d42b1255438bb9aaeab67e Mon Sep 17 00:00:00 2001 From: Trent Houliston Date: Sat, 25 Jan 2025 19:25:02 +1100 Subject: [PATCH 14/16] Swap to basing timeouts on time unit so CI tests get longer timeouts --- tests/test_util/TestBase.hpp | 3 ++- tests/tests/dsl/Every.cpp | 2 +- tests/tests/dsl/Idle.cpp | 2 +- tests/tests/dsl/IdleSingleGlobal.cpp | 2 +- tests/tests/dsl/SyncOrder.cpp | 3 ++- tests/tests/dsl/TCP.cpp | 2 +- tests/tests/dsl/emit/Delay.cpp | 2 +- 7 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/test_util/TestBase.hpp b/tests/test_util/TestBase.hpp index f2ae21517..4c5dcc318 100644 --- a/tests/test_util/TestBase.hpp +++ b/tests/test_util/TestBase.hpp @@ -28,6 +28,7 @@ #include #include "nuclear" +#include "test_util/TimeUnit.hpp" // IWYU pragma: export #include "test_util/diff_string.hpp" // IWYU pragma: export namespace test_util { @@ -57,7 +58,7 @@ class TestBase : public NUClear::Reactor { private: explicit TestBase(std::unique_ptr environment, const bool& shutdown_on_idle = true, - const std::chrono::milliseconds& timeout = std::chrono::milliseconds(1000)) + const std::chrono::milliseconds& timeout = TimeUnit(20)) : Reactor(std::move(environment)) { // Shutdown if the system is idle diff --git a/tests/tests/dsl/Every.cpp b/tests/tests/dsl/Every.cpp index ca6b00df3..0540fe1c6 100644 --- a/tests/tests/dsl/Every.cpp +++ b/tests/tests/dsl/Every.cpp @@ -39,7 +39,7 @@ class TestReactor : public test_util::TestBase { public: TestReactor(std::unique_ptr environment) - : TestBase(std::move(environment), false, std::chrono::seconds(10)) { + : TestBase(std::move(environment), false, test_util::TimeUnit(200)) { // Trigger on 3 different types of every on>>().then([this]() { every_times.push_back(NUClear::clock::now()); }); diff --git a/tests/tests/dsl/Idle.cpp b/tests/tests/dsl/Idle.cpp index 5e4026f30..318c202d6 100644 --- a/tests/tests/dsl/Idle.cpp +++ b/tests/tests/dsl/Idle.cpp @@ -57,7 +57,7 @@ class TestReactor : public test_util::TestBase { } explicit TestReactor(std::unique_ptr environment) - : TestBase(std::move(environment), false, std::chrono::seconds(5)) { + : TestBase(std::move(environment), false, test_util::TimeUnit(100)) { start_time = NUClear::clock::now(); diff --git a/tests/tests/dsl/IdleSingleGlobal.cpp b/tests/tests/dsl/IdleSingleGlobal.cpp index 76c044c2f..1724d0dd1 100644 --- a/tests/tests/dsl/IdleSingleGlobal.cpp +++ b/tests/tests/dsl/IdleSingleGlobal.cpp @@ -59,7 +59,7 @@ class TestReactor : public test_util::TestBase { static constexpr int n_loops = 10000; explicit TestReactor(std::unique_ptr environment) - : TestBase(std::move(environment), false, std::chrono::seconds(2)) { + : TestBase(std::move(environment), false, test_util::TimeUnit(50)) { /* * Run idle on the default pool, and a task on the main pool. diff --git a/tests/tests/dsl/SyncOrder.cpp b/tests/tests/dsl/SyncOrder.cpp index a9caa2c7e..361af021e 100644 --- a/tests/tests/dsl/SyncOrder.cpp +++ b/tests/tests/dsl/SyncOrder.cpp @@ -39,7 +39,8 @@ class TestReactor : public test_util::TestBase { Message(int val) : val(val) {}; }; - TestReactor(std::unique_ptr environment) : TestBase(std::move(environment)) { + TestReactor(std::unique_ptr environment) + : TestBase(std::move(environment), true, test_util::TimeUnit(50)) { on>, Sync>().then([this](const Message<'A'>& m) { // events.emplace_back('A', m.val); diff --git a/tests/tests/dsl/TCP.cpp b/tests/tests/dsl/TCP.cpp index db872e631..d354d6b9c 100644 --- a/tests/tests/dsl/TCP.cpp +++ b/tests/tests/dsl/TCP.cpp @@ -84,7 +84,7 @@ class TestReactor : public test_util::TestBase { } TestReactor(std::unique_ptr environment, const std::vector& active_tests_) - : TestBase(std::move(environment), false, std::chrono::seconds(2)), active_tests(active_tests_) { + : TestBase(std::move(environment), false, test_util::TimeUnit(50)), active_tests(active_tests_) { for (const auto& t : active_tests) { switch (t) { diff --git a/tests/tests/dsl/emit/Delay.cpp b/tests/tests/dsl/emit/Delay.cpp index c221dc43d..01ef51f8a 100644 --- a/tests/tests/dsl/emit/Delay.cpp +++ b/tests/tests/dsl/emit/Delay.cpp @@ -54,7 +54,7 @@ class TestReactor : public test_util::TestBase { struct FinishTest {}; TestReactor(std::unique_ptr environment) - : TestBase(std::move(environment), false, std::chrono::seconds(2)) { + : TestBase(std::move(environment), false, test_util::TimeUnit(50)) { // Measure when messages were sent and received and print those values on>().then([this](const DelayedMessage& m) { From 64ee1e0b0bdc53fac7bb90f2ed418a5d3857b7af Mon Sep 17 00:00:00 2001 From: Trent Houliston Date: Sat, 25 Jan 2025 19:45:34 +1100 Subject: [PATCH 15/16] How slow are these tests with atomic counters? --- tests/tests/dsl/IdleSingleGlobal.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests/dsl/IdleSingleGlobal.cpp b/tests/tests/dsl/IdleSingleGlobal.cpp index 1724d0dd1..3ac6f814b 100644 --- a/tests/tests/dsl/IdleSingleGlobal.cpp +++ b/tests/tests/dsl/IdleSingleGlobal.cpp @@ -59,7 +59,7 @@ class TestReactor : public test_util::TestBase { static constexpr int n_loops = 10000; explicit TestReactor(std::unique_ptr environment) - : TestBase(std::move(environment), false, test_util::TimeUnit(50)) { + : TestBase(std::move(environment), false, test_util::TimeUnit(200)) { /* * Run idle on the default pool, and a task on the main pool. From 7ba4b52c157c2eb964205b1c5c1802c2631f0ecf Mon Sep 17 00:00:00 2001 From: Trent Houliston Date: Sat, 25 Jan 2025 19:55:17 +1100 Subject: [PATCH 16/16] more time --- tests/tests/dsl/SyncOrder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests/dsl/SyncOrder.cpp b/tests/tests/dsl/SyncOrder.cpp index 361af021e..760f9c533 100644 --- a/tests/tests/dsl/SyncOrder.cpp +++ b/tests/tests/dsl/SyncOrder.cpp @@ -40,7 +40,7 @@ class TestReactor : public test_util::TestBase { }; TestReactor(std::unique_ptr environment) - : TestBase(std::move(environment), true, test_util::TimeUnit(50)) { + : TestBase(std::move(environment), true, test_util::TimeUnit(150)) { on>, Sync>().then([this](const Message<'A'>& m) { // events.emplace_back('A', m.val);