Skip to content

Commit d4f10d1

Browse files
committed
#45: Started with application tests
1 parent bd7e6ce commit d4f10d1

File tree

5 files changed

+88
-3
lines changed

5 files changed

+88
-3
lines changed

.github/workflows/low_level_tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ jobs:
8787
- name: Set up Build
8888
run: cmake -B build
8989
- name: Run LCOV
90-
run: lcov --no-external --capture --directory . --output-file coverage.info
90+
run: lcov --no-external -r "build/*" --capture --directory . --output-file coverage.info
9191
- name: Gen HTML
9292
run: genhtml coverage.info --output-directory coverage
9393
- name: Move HTML

Src/Application/application.c

-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ void application_init(void) {
9393
actuators_init();
9494
mode_handler_init();
9595

96-
imu_start_sampling();
97-
9896
system_post_init();
9997

10098
while (true) {

Src/Application/application.h

+12
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@
2121
* The system post initialization will start the timer, which is also implemented as part of the application logic.
2222
* This function never returns but calls wdt_reset in an infinite loop, if this idle does not run for 30ms
2323
* (i.e. the system is continuously blocked by interrupts a reset is performed).
24+
*
25+
* The timer performs the following tasks:
26+
* * Call the mode handler to determine the current mode
27+
* * Calculate the actuator commands depending on the mode:
28+
* * In flightcomputer mode: call the controller with the flightcomputer setpoint and the imu data
29+
* and use the result as elevon commands, the motor command is taken directly from the flightcomputer setpoint
30+
* * In remote mode: take the remote message as actuator command
31+
* * In stabilisied failsave mode: call the controller with roll: 0, pitch: 0 as setpoint and the imu data
32+
* and use the result as elevon commands, the motor command is always 0
33+
* * In failsave mode: set all three commands to 0
34+
* * Pass the actuator commands to the actuators
35+
* * Every FLIGHTCOMPUTER_SEND_PERIOD frame: pass the current data to flightcomputer_send
2436
*/
2537
void application_init(void);
2638

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include <Mock/actuators.hpp>
2+
#include <Mock/error_handler.hpp>
3+
#include <Mock/flightcomputer.hpp>
4+
#include <Mock/imu.hpp>
5+
#include <Mock/mode_handler.hpp>
6+
#include <Mock/remote.hpp>
7+
#include <Mock/system.hpp>
8+
#include <gtest/gtest.h>
9+
10+
extern "C" {
11+
#include <Application/application.h>
12+
}
13+
14+
TEST(TEST_NAME, init) {
15+
auto actuatorsHandle = mock::actuators.getHandle();
16+
auto errorHandlerHandle = mock::error_handler.getHandle();
17+
auto flighcomputerHandle = mock::flightcomputer.getHandle();
18+
auto imuHandle = mock::imu.getHandle();
19+
auto modeHandlerHandle = mock::mode_handler.getHandle();
20+
auto remoteHandlerHandle = mock::remote.getHandle();
21+
auto systemHandle = mock::system.getHandle();
22+
23+
systemHandle.overrideFunc<system_reset_watchdog>(
24+
[]() { throw std::runtime_error{"EXCEPTION TO BREAK LOOP FOR TESTS"}; });
25+
26+
EXPECT_THROW(application_init(), std::runtime_error);
27+
28+
EXPECT_TRUE(systemHandle.functionGotCalled<system_pre_init>(std::ignore));
29+
EXPECT_TRUE(errorHandlerHandle.functionGotCalled<error_handler_init>());
30+
EXPECT_TRUE(imuHandle.functionGotCalled<imu_init>());
31+
EXPECT_TRUE(remoteHandlerHandle.functionGotCalled<remote_init>());
32+
EXPECT_TRUE(flighcomputerHandle.functionGotCalled<flightcomputer_init>());
33+
EXPECT_TRUE(actuatorsHandle.functionGotCalled<actuators_init>());
34+
EXPECT_TRUE(modeHandlerHandle.functionGotCalled<mode_handler_init>());
35+
EXPECT_TRUE(systemHandle.functionGotCalled<system_post_init>());
36+
}
37+
38+
TEST(TEST_NAME, timer) {
39+
auto actuatorsHandle = mock::actuators.getHandle();
40+
auto errorHandlerHandle = mock::error_handler.getHandle();
41+
auto flighcomputerHandle = mock::flightcomputer.getHandle();
42+
auto imuHandle = mock::imu.getHandle();
43+
auto modeHandlerHandle = mock::mode_handler.getHandle();
44+
auto remoteHandlerHandle = mock::remote.getHandle();
45+
auto systemHandle = mock::system.getHandle();
46+
47+
system_timer_16_384ms_callback timer_callback = nullptr;
48+
systemHandle.overrideFunc<system_pre_init>(
49+
[&timer_callback](system_timer_16_384ms_callback callback) { timer_callback = callback; });
50+
systemHandle.overrideFunc<system_reset_watchdog>(
51+
[]() { throw std::runtime_error{"EXCEPTION TO BREAK LOOP FOR TESTS"}; });
52+
53+
EXPECT_THROW(application_init(), std::runtime_error);
54+
55+
EXPECT_TRUE(systemHandle.functionGotCalled<system_pre_init>(std::ignore));
56+
EXPECT_TRUE(errorHandlerHandle.functionGotCalled<error_handler_init>());
57+
EXPECT_TRUE(imuHandle.functionGotCalled<imu_init>());
58+
EXPECT_TRUE(remoteHandlerHandle.functionGotCalled<remote_init>());
59+
EXPECT_TRUE(flighcomputerHandle.functionGotCalled<flightcomputer_init>());
60+
EXPECT_TRUE(actuatorsHandle.functionGotCalled<actuators_init>());
61+
EXPECT_TRUE(modeHandlerHandle.functionGotCalled<mode_handler_init>());
62+
EXPECT_TRUE(systemHandle.functionGotCalled<system_post_init>());
63+
64+
// Actual test
65+
}

Tests/LowLevel/CMakeLists.txt

+10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ function(make_fc_test)
2424
REQUIRED_HEADERS ${headers})
2525
endfunction()
2626

27+
make_fc_test(MODULE Application/application
28+
DEPS
29+
Application/controller
30+
Application/error_handler
31+
Application/mode_handler
32+
Components/actuators
33+
Components/flightcomputer
34+
Components/imu
35+
Components/remote
36+
Components/system)
2737
make_fc_test(MODULE Application/controller)
2838
make_fc_test(MODULE Application/error_handler DEPS avr/io avr/wdt)
2939
make_fc_test(MODULE Application/mode_handler DEPS Application/error_handler Components/imu Components/remote Components/flightcomputer)

0 commit comments

Comments
 (0)