Skip to content

Commit

Permalink
#45: Started with application tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aul12 committed Jan 1, 2023
1 parent bd7e6ce commit d4f10d1
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/low_level_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
- name: Set up Build
run: cmake -B build
- name: Run LCOV
run: lcov --no-external --capture --directory . --output-file coverage.info
run: lcov --no-external -r "build/*" --capture --directory . --output-file coverage.info
- name: Gen HTML
run: genhtml coverage.info --output-directory coverage
- name: Move HTML
Expand Down
2 changes: 0 additions & 2 deletions Src/Application/application.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ void application_init(void) {
actuators_init();
mode_handler_init();

imu_start_sampling();

system_post_init();

while (true) {
Expand Down
12 changes: 12 additions & 0 deletions Src/Application/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@
* The system post initialization will start the timer, which is also implemented as part of the application logic.
* This function never returns but calls wdt_reset in an infinite loop, if this idle does not run for 30ms
* (i.e. the system is continuously blocked by interrupts a reset is performed).
*
* The timer performs the following tasks:
* * Call the mode handler to determine the current mode
* * Calculate the actuator commands depending on the mode:
* * In flightcomputer mode: call the controller with the flightcomputer setpoint and the imu data
* and use the result as elevon commands, the motor command is taken directly from the flightcomputer setpoint
* * In remote mode: take the remote message as actuator command
* * In stabilisied failsave mode: call the controller with roll: 0, pitch: 0 as setpoint and the imu data
* and use the result as elevon commands, the motor command is always 0
* * In failsave mode: set all three commands to 0
* * Pass the actuator commands to the actuators
* * Every FLIGHTCOMPUTER_SEND_PERIOD frame: pass the current data to flightcomputer_send
*/
void application_init(void);

Expand Down
65 changes: 65 additions & 0 deletions Tests/LowLevel/Application/application.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include <Mock/actuators.hpp>
#include <Mock/error_handler.hpp>
#include <Mock/flightcomputer.hpp>
#include <Mock/imu.hpp>
#include <Mock/mode_handler.hpp>
#include <Mock/remote.hpp>
#include <Mock/system.hpp>
#include <gtest/gtest.h>

extern "C" {
#include <Application/application.h>
}

TEST(TEST_NAME, init) {
auto actuatorsHandle = mock::actuators.getHandle();
auto errorHandlerHandle = mock::error_handler.getHandle();
auto flighcomputerHandle = mock::flightcomputer.getHandle();
auto imuHandle = mock::imu.getHandle();
auto modeHandlerHandle = mock::mode_handler.getHandle();
auto remoteHandlerHandle = mock::remote.getHandle();
auto systemHandle = mock::system.getHandle();

systemHandle.overrideFunc<system_reset_watchdog>(
[]() { throw std::runtime_error{"EXCEPTION TO BREAK LOOP FOR TESTS"}; });

EXPECT_THROW(application_init(), std::runtime_error);

EXPECT_TRUE(systemHandle.functionGotCalled<system_pre_init>(std::ignore));
EXPECT_TRUE(errorHandlerHandle.functionGotCalled<error_handler_init>());
EXPECT_TRUE(imuHandle.functionGotCalled<imu_init>());
EXPECT_TRUE(remoteHandlerHandle.functionGotCalled<remote_init>());
EXPECT_TRUE(flighcomputerHandle.functionGotCalled<flightcomputer_init>());
EXPECT_TRUE(actuatorsHandle.functionGotCalled<actuators_init>());
EXPECT_TRUE(modeHandlerHandle.functionGotCalled<mode_handler_init>());
EXPECT_TRUE(systemHandle.functionGotCalled<system_post_init>());
}

TEST(TEST_NAME, timer) {
auto actuatorsHandle = mock::actuators.getHandle();
auto errorHandlerHandle = mock::error_handler.getHandle();
auto flighcomputerHandle = mock::flightcomputer.getHandle();
auto imuHandle = mock::imu.getHandle();
auto modeHandlerHandle = mock::mode_handler.getHandle();
auto remoteHandlerHandle = mock::remote.getHandle();
auto systemHandle = mock::system.getHandle();

system_timer_16_384ms_callback timer_callback = nullptr;
systemHandle.overrideFunc<system_pre_init>(
[&timer_callback](system_timer_16_384ms_callback callback) { timer_callback = callback; });
systemHandle.overrideFunc<system_reset_watchdog>(
[]() { throw std::runtime_error{"EXCEPTION TO BREAK LOOP FOR TESTS"}; });

EXPECT_THROW(application_init(), std::runtime_error);

EXPECT_TRUE(systemHandle.functionGotCalled<system_pre_init>(std::ignore));
EXPECT_TRUE(errorHandlerHandle.functionGotCalled<error_handler_init>());
EXPECT_TRUE(imuHandle.functionGotCalled<imu_init>());
EXPECT_TRUE(remoteHandlerHandle.functionGotCalled<remote_init>());
EXPECT_TRUE(flighcomputerHandle.functionGotCalled<flightcomputer_init>());
EXPECT_TRUE(actuatorsHandle.functionGotCalled<actuators_init>());
EXPECT_TRUE(modeHandlerHandle.functionGotCalled<mode_handler_init>());
EXPECT_TRUE(systemHandle.functionGotCalled<system_post_init>());

// Actual test
}
10 changes: 10 additions & 0 deletions Tests/LowLevel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ function(make_fc_test)
REQUIRED_HEADERS ${headers})
endfunction()

make_fc_test(MODULE Application/application
DEPS
Application/controller
Application/error_handler
Application/mode_handler
Components/actuators
Components/flightcomputer
Components/imu
Components/remote
Components/system)
make_fc_test(MODULE Application/controller)
make_fc_test(MODULE Application/error_handler DEPS avr/io avr/wdt)
make_fc_test(MODULE Application/mode_handler DEPS Application/error_handler Components/imu Components/remote Components/flightcomputer)
Expand Down

0 comments on commit d4f10d1

Please sign in to comment.