Skip to content

Commit fd86199

Browse files
Merge branch 'main' into houliston/priority-changes
2 parents 5097525 + 28d18fa commit fd86199

25 files changed

+224
-61
lines changed

.github/workflows/gcc.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,14 @@ jobs:
9292

9393
- name: Test
9494
timeout-minutes: 2
95-
working-directory: build/tests
96-
run: ctest --output-on-failure -E "dsl/UDP"
95+
working-directory: build
96+
run: ninja run_all_tests -k 0
97+
98+
- name: Test Summary
99+
if: ${{ !cancelled() }}
100+
uses: test-summary/action@v2
101+
with:
102+
paths: "build/reports/tests/*.junit.xml"
97103

98104
- name: Upload Traces
99105
if: ${{ !cancelled() }}

.github/workflows/macos.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,14 @@ jobs:
6060

6161
- name: Test
6262
timeout-minutes: 5
63-
working-directory: build/tests
64-
run: ctest --output-on-failure
63+
working-directory: build
64+
run: ninja run_all_tests -k 0
65+
66+
- name: Test Summary
67+
if: ${{ !cancelled() }}
68+
uses: test-summary/action@v2
69+
with:
70+
paths: "build/reports/tests/*.junit.xml"
6571

6672
- name: Upload Traces
6773
if: ${{ !cancelled() }}

.github/workflows/sonarcloud.yaml

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ jobs:
3333
uses: SonarSource/sonarcloud-github-c-cpp@v3
3434

3535
- name: Install CMake
36-
uses: lukka/get-cmake@latest
36+
uses: lukka/get-cmake@v3.30.5
3737
with:
38-
cmakeVersion: 3.27.1
38+
cmakeVersion: 3.30.5
3939
ninjaVersion: 1.11.1
4040

4141
- name: Setup CCache
@@ -45,14 +45,16 @@ jobs:
4545
max-size: 100M
4646

4747
- name: Configure CMake
48+
env:
49+
CXXFLAGS: -DNUCLEAR_TEST_TIME_UNIT_DEN=10
4850
run: |
4951
cmake -E make_directory build
5052
cmake -S . -B build \
5153
-GNinja \
5254
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
5355
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
54-
-DBUILD_TESTS=ON \
5556
-DCMAKE_BUILD_TYPE=Debug \
57+
-DBUILD_TESTS=ON \
5658
-DCI_BUILD=ON \
5759
-DENABLE_COVERAGE=ON \
5860
-DENABLE_CLANG_TIDY=OFF
@@ -63,12 +65,28 @@ jobs:
6365

6466
- name: Run tests to generate coverage statistics
6567
timeout-minutes: 10
66-
working-directory: build/tests
67-
run: ctest --output-on-failure
68+
working-directory: build
69+
run: ninja run_all_tests -j1 -k 0
70+
71+
- name: Test Summary
72+
if: ${{ !cancelled() }}
73+
uses: test-summary/action@v2
74+
with:
75+
paths: "build/reports/tests/*.junit.xml"
6876

6977
- name: Collect coverage into one XML report
7078
if: ${{ !cancelled() }}
71-
run: gcovr --gcov-ignore-parse-errors=negative_hits.warn_once_per_file --exclude-unreachable-branches --exclude-noncode-lines --sonarqube > coverage.xml
79+
run: |
80+
gcovr \
81+
--root . \
82+
--object-directory build \
83+
--force-color \
84+
--no-markers \
85+
--decisions \
86+
--calls \
87+
--exclude-noncode-lines \
88+
--gcov-ignore-parse-errors negative_hits.warn \
89+
--sonarqube "coverage.xml"
7290
7391
- name: Upload coverage report
7492
if: ${{ !cancelled() }}
@@ -86,6 +104,10 @@ jobs:
86104
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
87105
run: |
88106
sonar-scanner \
107+
--define sonar.projectKey=Fastcode_NUClear \
108+
--define sonar.organization=fastcode \
109+
--define sonar.sources=src \
110+
--define sonar.tests=tests \
89111
--define sonar.cfamily.compile-commands=build/compile_commands.json \
90112
--define sonar.coverageReportPaths=coverage.xml
91113

.github/workflows/windows.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,14 @@ jobs:
8181

8282
- name: Test
8383
timeout-minutes: 5
84-
working-directory: build/tests
85-
run: ctest --output-on-failure
84+
working-directory: build
85+
run: ninja run_all_tests -k 0
86+
87+
- name: Test Summary
88+
if: ${{ !cancelled() }}
89+
uses: test-summary/action@v2
90+
with:
91+
paths: "build/reports/tests/*.junit.xml"
8692

8793
- name: Upload Traces
8894
if: ${{ !cancelled() }}

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ option(BUILD_TESTS "Builds all of the NUClear unit tests." ON)
8989
if(BUILD_TESTS)
9090
enable_testing()
9191
add_subdirectory(tests)
92+
include(TestRunner)
9293
endif()
9394

9495
# Add the documentation subdirectory

cmake/TestRunner.cmake

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Collect all currently added targets in all subdirectories
2+
#
3+
# Parameters:
4+
# - _result the list containing all found targets
5+
# - _dir root directory to start looking from
6+
function(get_all_catch_test_targets _result _dir)
7+
get_property(
8+
_subdirs
9+
DIRECTORY "${_dir}"
10+
PROPERTY SUBDIRECTORIES
11+
)
12+
foreach(_subdir IN LISTS _subdirs)
13+
get_all_catch_test_targets(${_result} "${_subdir}")
14+
endforeach()
15+
16+
unset(catch_targets)
17+
get_directory_property(_sub_targets DIRECTORY "${_dir}" BUILDSYSTEM_TARGETS)
18+
foreach(target ${_sub_targets})
19+
get_target_property(target_type ${target} TYPE)
20+
if(target_type STREQUAL "EXECUTABLE")
21+
get_target_property(target_link_libraries ${target} INTERFACE_LINK_LIBRARIES)
22+
if(target_link_libraries MATCHES "Catch2::Catch2")
23+
list(APPEND catch_targets ${target})
24+
endif()
25+
endif()
26+
endforeach()
27+
28+
set(${_result}
29+
${${_result}} ${catch_targets}
30+
PARENT_SCOPE
31+
)
32+
endfunction()
33+
34+
# Find all executable targets that link to Catch2::Catch2WithMain || Catch2::Catch2
35+
get_all_catch_test_targets(all_targets ${PROJECT_SOURCE_DIR})
36+
37+
# Create a custom command for each test target to run it
38+
# Make sure that coverage data is written with paths relative to the source directory
39+
unset(reports)
40+
foreach(target ${all_targets})
41+
42+
set(sonarqube_report_file "${PROJECT_BINARY_DIR}/reports/tests/${target}.sonarqube.xml")
43+
set(junit_report_file "${PROJECT_BINARY_DIR}/reports/tests/${target}.junit.xml")
44+
list(APPEND reports ${sonarqube_report_file} ${junit_report_file})
45+
add_custom_command(
46+
OUTPUT ${sonarqube_report_file} ${junit_report_file}
47+
COMMAND $<TARGET_FILE:${target}> --reporter console --reporter SonarQube::out=${sonarqube_report_file} --reporter
48+
JUnit::out=${junit_report_file}
49+
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
50+
USES_TERMINAL
51+
COMMENT "Running test ${target}"
52+
)
53+
endforeach()
54+
55+
# Create a custom target that depends on all test targets
56+
add_custom_target(
57+
run_all_tests
58+
DEPENDS ${reports}
59+
COMMENT "Running all Catch2 tests"
60+
)

sonar-project.properties

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/CMakeLists.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ target_link_libraries(nuclear ${CMAKE_THREAD_LIBS_INIT})
3737
set_target_properties(nuclear PROPERTIES POSITION_INDEPENDENT_CODE ON)
3838
target_compile_features(nuclear PUBLIC cxx_std_14)
3939

40-
# When enabling coverage, just set it on the nuclear target so it doesn't end up on catch2
41-
option(ENABLE_COVERAGE "Enable coverage support" OFF)
40+
option(ENABLE_COVERAGE "Compile with coverage support enabled.")
4241
if(ENABLE_COVERAGE)
43-
target_compile_options(nuclear PUBLIC "-fprofile-arcs" "-ftest-coverage" "-fprofile-abs-path")
44-
target_link_options(nuclear PUBLIC "-fprofile-arcs" "-ftest-coverage" "-fprofile-abs-path")
45-
endif()
42+
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
43+
message(WARNING "Coverage is enabled but not build in debug mode. Coverage results may be misleading.")
44+
endif()
45+
target_compile_options(nuclear PUBLIC -fprofile-arcs -ftest-coverage -fprofile-abs-path -fprofile-update=atomic)
46+
target_link_options(nuclear PUBLIC -fprofile-arcs)
47+
endif(ENABLE_COVERAGE)
4648

4749
# Enable warnings, and all warnings are errors
4850
if(MSVC)

src/dsl/store/ThreadStore.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
#ifndef NUCLEAR_DSL_STORE_THREADSTORE_HPP
2424
#define NUCLEAR_DSL_STORE_THREADSTORE_HPP
2525

26-
#include "../../util/platform.hpp"
27-
2826
namespace NUClear {
2927
namespace dsl {
3028
namespace store {
@@ -46,12 +44,12 @@ namespace dsl {
4644
*/
4745
template <typename DataType, int Index = 0>
4846
struct ThreadStore {
49-
static ATTRIBUTE_TLS DataType* value; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
47+
static thread_local DataType* value; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
5048
};
5149

5250
template <typename DataType, int index>
5351
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
54-
ATTRIBUTE_TLS DataType* ThreadStore<DataType, index>::value = nullptr;
52+
thread_local DataType* ThreadStore<DataType, index>::value = nullptr;
5553

5654
} // namespace store
5755
} // namespace dsl

src/dsl/word/TaskScope.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
#include "../../id.hpp"
2626
#include "../../threading/ReactionTask.hpp"
27-
#include "../../util/platform.hpp"
2827

2928
namespace NUClear {
3029
namespace dsl {
@@ -93,12 +92,12 @@ namespace dsl {
9392
private:
9493
/// The current task id that is running
9594
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
96-
static ATTRIBUTE_TLS NUClear::id_t current_task_id;
95+
static thread_local NUClear::id_t current_task_id;
9796
};
9897

9998
// Initialise the current task id
10099
template <typename Group> // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
101-
ATTRIBUTE_TLS NUClear::id_t TaskScope<Group>::current_task_id{0};
100+
thread_local NUClear::id_t TaskScope<Group>::current_task_id{0};
102101

103102
} // namespace word
104103
} // namespace dsl

0 commit comments

Comments
 (0)