Skip to content

Commit e7af428

Browse files
add qemu for cortex m4 and m7
1 parent 2a5f046 commit e7af428

31 files changed

Lines changed: 674 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,42 @@ jobs:
5858
with:
5959
name: test-logs
6060
path: build/host/Testing/Temporary/
61+
qemu_arm_tests:
62+
name: QEMU ARM Tests (${{ matrix.preset }})
63+
runs-on: ubuntu-latest
64+
container:
65+
image: gabrielfrasantos/embedded-devcontainer-cpp:v7.3.0@sha256:4f92e9c86dfc5a9688b6134944e7a40c9eb3c658022ea62dc9e57e4c3b056940
66+
strategy:
67+
fail-fast: false
68+
matrix:
69+
preset: [qemu-cortex-m4, qemu-cortex-m7]
70+
steps:
71+
- name: Configure Git
72+
run: |
73+
git config --global url."https://${{ secrets.PRIVATE_REPO_TOKEN }}@github.com/".insteadOf "https://github.com/"
74+
git config --global url."https://github.com/".insteadOf "git@github.com:"
75+
git config --global --add safe.directory '*'
76+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
77+
with:
78+
persist-credentials: false
79+
- uses: hendrikmuhs/ccache-action@d62db5f07c26379fc4b4e0916f098a92573c3b03 # v1.2.23
80+
with:
81+
key: ${{ github.job }}-${{ matrix.preset }}
82+
max-size: 2G
83+
save: ${{ github.ref == 'refs/heads/main' }}
84+
- uses: lukka/run-cmake@5d55ea7949e25f69f0ecb516d8d572297e03a956 # v10.9
85+
with:
86+
configurePreset: ${{ matrix.preset }}
87+
buildPreset: ${{ matrix.preset }}-RelWithDebInfo
88+
testPreset: ${{ matrix.preset }}
89+
configurePresetAdditionalArgs: "['-DCMAKE_C_COMPILER_LAUNCHER=ccache', '-DCMAKE_CXX_COMPILER_LAUNCHER=ccache']"
90+
- name: Upload test logs
91+
if: ${{ failure() }}
92+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
93+
with:
94+
name: test-logs-${{ matrix.preset }}
95+
path: build/${{ matrix.preset }}/Testing/Temporary/
96+
6197
host_build_test:
6298
name: Host Build & Test
6399
runs-on: ${{ matrix.os }}

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,16 @@ if (NUMERICAL_TOOLBOX_STANDALONE)
4646
set(EMIL_BUILD_ECHO_COMPILERS Off CACHE BOOL "" FORCE)
4747
set(EMIL_ENABLE_DOCKER_TOOLS Off CACHE BOOL "" FORCE)
4848

49+
if(DEFINED QEMU_MACHINE)
50+
set(gtest_disable_pthreads ON CACHE BOOL "" FORCE)
51+
endif()
52+
4953
FetchContent_MakeAvailable(emil)
54+
55+
if(DEFINED QEMU_MACHINE)
56+
function(emil_add_test target)
57+
endfunction()
58+
endif()
5059
endif()
5160

5261
project(numerical-toolbox LANGUAGES C CXX ASM VERSION 2.0.0) # x-release-please-version
@@ -85,6 +94,12 @@ elseif (NUMERICAL_TOOLBOX_BUILD_INTEGRATION_TESTS)
8594
include(CTest)
8695
endif()
8796

97+
include(QemuHelpers)
98+
99+
if(DEFINED QEMU_MACHINE)
100+
add_subdirectory(platform/qemu)
101+
endif()
102+
88103
add_subdirectory(numerical)
89104

90105
if (NUMERICAL_TOOLBOX_BUILD_SIMULATOR)

CMakePresets.json

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,34 @@
5656
"NUMERICAL_TOOLBOX_BUILD_TESTS": false,
5757
"NUMERICAL_TOOLBOX_BUILD_SIMULATOR": false
5858
}
59+
},
60+
{
61+
"name": "qemu-cortex-m4",
62+
"displayName": "QEMU Cortex-M4 Tests",
63+
"inherits": "defaults",
64+
"toolchainFile": "${sourceDir}/build/${presetName}/_deps/emil-src/cmake/toolchain-arm-gcc-m4-fpv4-sp-d16.cmake",
65+
"generator": "Ninja Multi-Config",
66+
"cacheVariables": {
67+
"CMAKE_CONFIGURATION_TYPES": "RelWithDebInfo",
68+
"NUMERICAL_TOOLBOX_BUILD_TESTS": "On",
69+
"NUMERICAL_TOOLBOX_BUILD_SIMULATOR": "Off",
70+
"QEMU_MACHINE": "mps2-an386",
71+
"CMAKE_CXX_FLAGS": "-DGTEST_HAS_STREAM_REDIRECTION=0 -DGTEST_HAS_POSIX_RE=0 -D_POSIX_C_SOURCE=200112L"
72+
}
73+
},
74+
{
75+
"name": "qemu-cortex-m7",
76+
"displayName": "QEMU Cortex-M7 Tests",
77+
"inherits": "defaults",
78+
"toolchainFile": "${sourceDir}/build/${presetName}/_deps/emil-src/cmake/toolchain-arm-gcc-m7-fpv5-d16.cmake",
79+
"generator": "Ninja Multi-Config",
80+
"cacheVariables": {
81+
"CMAKE_CONFIGURATION_TYPES": "RelWithDebInfo",
82+
"NUMERICAL_TOOLBOX_BUILD_TESTS": "On",
83+
"NUMERICAL_TOOLBOX_BUILD_SIMULATOR": "Off",
84+
"QEMU_MACHINE": "mps2-an500",
85+
"CMAKE_CXX_FLAGS": "-DGTEST_HAS_STREAM_REDIRECTION=0 -DGTEST_HAS_POSIX_RE=0 -D_POSIX_C_SOURCE=200112L"
86+
}
5987
}
6088
],
6189
"buildPresets": [
@@ -92,6 +120,56 @@
92120
"name": "integration-Debug",
93121
"configuration": "Debug",
94122
"configurePreset": "integration"
123+
},
124+
{
125+
"name": "qemu-cortex-m4-RelWithDebInfo",
126+
"configuration": "RelWithDebInfo",
127+
"configurePreset": "qemu-cortex-m4",
128+
"targets": [
129+
"numerical.analysis_test",
130+
"numerical.analysis.windowing_test",
131+
"numerical.control_analysis_test",
132+
"numerical.controllers_test",
133+
"numerical.estimators.offline_test",
134+
"numerical.estimators.online_test",
135+
"numerical.filters.active_test",
136+
"numerical.filters.passive_test",
137+
"numerical.math_test",
138+
"numerical.neural_network.activation_test",
139+
"numerical.neural_network.layer_test",
140+
"numerical.neural_network.losses_test",
141+
"numerical.neural_network.model_test",
142+
"numerical.nonlinear_control_test",
143+
"numerical.optimization_test",
144+
"numerical.regularization_test",
145+
"numerical.robust_control_test",
146+
"numerical.solvers_test"
147+
]
148+
},
149+
{
150+
"name": "qemu-cortex-m7-RelWithDebInfo",
151+
"configuration": "RelWithDebInfo",
152+
"configurePreset": "qemu-cortex-m7",
153+
"targets": [
154+
"numerical.analysis_test",
155+
"numerical.analysis.windowing_test",
156+
"numerical.control_analysis_test",
157+
"numerical.controllers_test",
158+
"numerical.estimators.offline_test",
159+
"numerical.estimators.online_test",
160+
"numerical.filters.active_test",
161+
"numerical.filters.passive_test",
162+
"numerical.math_test",
163+
"numerical.neural_network.activation_test",
164+
"numerical.neural_network.layer_test",
165+
"numerical.neural_network.losses_test",
166+
"numerical.neural_network.model_test",
167+
"numerical.nonlinear_control_test",
168+
"numerical.optimization_test",
169+
"numerical.regularization_test",
170+
"numerical.robust_control_test",
171+
"numerical.solvers_test"
172+
]
95173
}
96174
],
97175
"testPresets": [
@@ -129,6 +207,18 @@
129207
"configurePreset": "integration",
130208
"configuration": "Debug",
131209
"inherits": "defaults"
210+
},
211+
{
212+
"name": "qemu-cortex-m4",
213+
"configurePreset": "qemu-cortex-m4",
214+
"configuration": "RelWithDebInfo",
215+
"inherits": "defaults"
216+
},
217+
{
218+
"name": "qemu-cortex-m7",
219+
"configurePreset": "qemu-cortex-m7",
220+
"configuration": "RelWithDebInfo",
221+
"inherits": "defaults"
132222
}
133223
]
134224
}

cmake/QemuHelpers.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function(numerical_add_qemu_test target)
2+
if(NOT DEFINED QEMU_MACHINE)
3+
return()
4+
endif()
5+
target_link_libraries(${target} PRIVATE platform_qemu_startup)
6+
target_link_libraries(${target} PRIVATE -lrdimon)
7+
add_test(
8+
NAME qemu.${target}
9+
COMMAND qemu-system-arm
10+
-machine ${QEMU_MACHINE}
11+
-nographic
12+
-semihosting-config enable=on,target=native
13+
-kernel $<TARGET_FILE:${target}>
14+
)
15+
set_tests_properties(qemu.${target} PROPERTIES TIMEOUT 120)
16+
endfunction()

numerical/analysis/test/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ target_link_libraries(numerical.analysis_test PUBLIC
88
numerical.math_test_helper
99
)
1010

11+
numerical_add_qemu_test(numerical.analysis_test)
12+
1113
target_sources(numerical.analysis_test PRIVATE
1214
TestConvolutionCorrelation.cpp
1315
TestDecibels.cpp

numerical/analysis/test/TestPowerDensitySpectrum.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ TYPED_TEST(TestPowerSpectralDensity, when_input_smaller_than_fft_size_throws_ass
6060
for (std::size_t i = 0; i < this->length - 1; ++i)
6161
input.push_back(TypeParam(0.1f));
6262

63-
EXPECT_DEATH(this->powerDensitySpectrum->Calculate(input), "");
63+
EXPECT_DEATH_IF_SUPPORTED(this->powerDensitySpectrum->Calculate(input), "");
6464
}
6565

6666
TYPED_TEST(TestPowerSpectralDensity, output_size_equals_half_segment_size_plus_one)

numerical/analysis/windowing/test/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ target_link_libraries(numerical.analysis.windowing_test PUBLIC
77
numerical.analysis.windowing
88
)
99

10+
numerical_add_qemu_test(numerical.analysis.windowing_test)
11+
1012
target_sources(numerical.analysis.windowing_test PRIVATE
1113
TestWindowing.cpp
1214
)

numerical/control_analysis/test/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ target_link_libraries(numerical.control_analysis_test PUBLIC
88
numerical.math_test_helper
99
)
1010

11+
numerical_add_qemu_test(numerical.control_analysis_test)
12+
1113
target_sources(numerical.control_analysis_test PRIVATE
1214
TestContinuousToDiscrete.cpp
1315
TestControllabilityObservability.cpp

numerical/controllers/implementations/test/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ target_link_libraries(numerical.controllers_test PUBLIC
88
numerical.math_test_helper
99
)
1010

11+
numerical_add_qemu_test(numerical.controllers_test)
12+
1113
target_sources(numerical.controllers_test PRIVATE
1214
TestBangBangHysteresis.cpp
1315
TestFeedforward2Dof.cpp

numerical/estimators/offline/test/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ target_link_libraries(numerical.estimators.offline_test PUBLIC
77
numerical.estimators.offline
88
)
99

10+
numerical_add_qemu_test(numerical.estimators.offline_test)
11+
1012
target_sources(numerical.estimators.offline_test PRIVATE
1113
TestExpectationMaximization.cpp
1214
TestLinearRegression.cpp

0 commit comments

Comments
 (0)