From b1a076368ad28a98d675c0592b2f104d0ee9382b Mon Sep 17 00:00:00 2001 From: Paul Nykiel Date: Sun, 1 Jan 2023 15:24:44 +0100 Subject: [PATCH] #45: Adapted all tests for new mocking structure --- Tests/LowLevel/Application/error_handler.cpp | 4 +- Tests/LowLevel/Application/mode_handler.cpp | 8 +-- Tests/LowLevel/CMakeLists.txt | 63 +++++--------------- Tests/LowLevel/Components/actuators.cpp | 2 +- Tests/LowLevel/Components/flightcomputer.cpp | 2 +- Tests/LowLevel/Components/imu.cpp | 6 +- Tests/LowLevel/Components/remote.cpp | 2 +- Tests/LowLevel/Components/system.cpp | 10 ++-- Tests/LowLevel/Drivers/bno055.cpp | 2 +- Tests/LowLevel/Drivers/ppm.cpp | 2 +- Tests/LowLevel/Drivers/protobuf.cpp | 8 +-- Tests/LowLevel/Drivers/sbus.cpp | 4 +- Tests/LowLevel/Mock/CMakeLists.txt | 8 +-- Tests/LowLevel/Mock/Lib/generate_mock.py | 4 +- Tests/LowLevel/Mock/System/avr/io.h | 16 ++++- 15 files changed, 60 insertions(+), 81 deletions(-) diff --git a/Tests/LowLevel/Application/error_handler.cpp b/Tests/LowLevel/Application/error_handler.cpp index 78819e90..c7b706e1 100644 --- a/Tests/LowLevel/Application/error_handler.cpp +++ b/Tests/LowLevel/Application/error_handler.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include extern "C" { diff --git a/Tests/LowLevel/Application/mode_handler.cpp b/Tests/LowLevel/Application/mode_handler.cpp index f3b77708..b547d61b 100644 --- a/Tests/LowLevel/Application/mode_handler.cpp +++ b/Tests/LowLevel/Application/mode_handler.cpp @@ -1,7 +1,7 @@ -#include -#include -#include -#include +#include +#include +#include +#include #include extern "C" { diff --git a/Tests/LowLevel/CMakeLists.txt b/Tests/LowLevel/CMakeLists.txt index c726e50f..7a3303c0 100644 --- a/Tests/LowLevel/CMakeLists.txt +++ b/Tests/LowLevel/CMakeLists.txt @@ -24,58 +24,25 @@ function(make_fc_test) REQUIRED_HEADERS ${headers}) endfunction() -make_fc_test(MODULE Drivers/bno055_uart DEPS HAL/uart) +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) +make_fc_test(MODULE Components/actuators DEPS Drivers/ppm) +make_fc_test(MODULE Components/flightcomputer DEPS Drivers/protobuf) +make_fc_test(MODULE Components/imu DEPS Drivers/bno055 util/delay Application/error_handler) +make_fc_test(MODULE Components/remote DEPS Drivers/sbus) +make_fc_test(MODULE Components/system DEPS avr/io avr/wdt avr/interrupt HAL/timer8bit Application/error_handler) make_fc_test(MODULE Drivers/bno055 DEPS Drivers/bno055_uart) +make_fc_test(MODULE Drivers/bno055_uart DEPS HAL/uart) make_fc_test(MODULE Drivers/ppm DEPS HAL/pwm16bit avr/io) -make_fc_test(MODULE Drivers/protobuf DEPS HAL/uart) +make_fc_test(MODULE Drivers/protobuf DEPS HAL/uart Messages/MessageDecoding Messages/MessageEncoding Drivers/ring_buffer) +make_fc_test(MODULE Drivers/ring_buffer) +make_fc_test(MODULE Drivers/sbus DEPS HAL/uart Drivers/ring_buffer) +target_link_libraries(MessageEncoding.mock PUBLIC ToolboxPlaneMessageDefs) +target_link_libraries(MessageDecoding.mock PUBLIC ToolboxPlaneMessageDefs) +target_link_libraries(protobuf.mock PUBLIC ToolboxPlaneMessageDefs) -#make_test(Drivers/protobuf) -#target_link_libraries(Test_Drivers_protobuf PRIVATE Mock_HAL_uart) -#target_link_libraries(Test_Drivers_protobuf PRIVATE Mock_Messages_MessageDecoding) -#target_link_libraries(Test_Drivers_protobuf PRIVATE Mock_Messages_MessageEncoding) -#target_link_libraries(Test_Drivers_protobuf PRIVATE Mock_Drivers_ring_buffer) -# -#make_test(Drivers/ring_buffer) -# -#make_test(Drivers/sbus) -#target_link_libraries(Test_Drivers_sbus PRIVATE Mock_HAL_uart) -#target_link_libraries(Test_Drivers_sbus PRIVATE Mock_Drivers_ring_buffer) -# -#make_test(Components/imu) -#target_link_libraries(Test_Components_imu PRIVATE Mock_Drivers_bno055) -#target_link_libraries(Test_Components_imu PRIVATE Mock_util_delay) -#target_link_libraries(Test_Components_imu PRIVATE Mock_Application_error_handler) -# -#make_test(Components/remote) -#target_link_libraries(Test_Components_remote PRIVATE Mock_Drivers_sbus) -# -#make_test(Components/flightcomputer) -#target_link_libraries(Test_Components_flightcomputer PRIVATE Mock_Drivers_protobuf) -# -#make_test(Components/actuators) -#target_link_libraries(Test_Components_actuators PRIVATE Mock_Drivers_ppm) -# -#make_test(Components/system) -#target_link_libraries(Test_Components_system PRIVATE Mock_avr_io) -#target_link_libraries(Test_Components_system PRIVATE Mock_avr_wdt) -#target_link_libraries(Test_Components_system PRIVATE Mock_avr_interrupt) -#target_link_libraries(Test_Components_system PRIVATE Mock_HAL_timer8bit) -#target_link_libraries(Test_Components_system PRIVATE Mock_Application_error_handler) -# -#make_test(Application/controller) -# -#make_test(Application/error_handler) -#target_link_libraries(Test_Application_error_handler PRIVATE Mock_avr_io) -#target_link_libraries(Test_Application_error_handler PRIVATE Mock_avr_wdt) -# -#make_test(Application/mode_handler) -#target_link_libraries(Test_Application_mode_handler PRIVATE Mock_Application_error_handler) -#target_link_libraries(Test_Application_mode_handler PRIVATE Mock_Components_imu) -#target_link_libraries(Test_Application_mode_handler PRIVATE Mock_Components_remote) -#target_link_libraries(Test_Application_mode_handler PRIVATE Mock_Components_flightcomputer) -# -# #add_custom_target(RunAllTests DEPENDS ${AllTests}) # #add_custom_target(coverage.info diff --git a/Tests/LowLevel/Components/actuators.cpp b/Tests/LowLevel/Components/actuators.cpp index 365f8f3e..ae0f6c2a 100644 --- a/Tests/LowLevel/Components/actuators.cpp +++ b/Tests/LowLevel/Components/actuators.cpp @@ -1,4 +1,4 @@ -#include +#include #include extern "C" { diff --git a/Tests/LowLevel/Components/flightcomputer.cpp b/Tests/LowLevel/Components/flightcomputer.cpp index 2f0db964..9a339f35 100644 --- a/Tests/LowLevel/Components/flightcomputer.cpp +++ b/Tests/LowLevel/Components/flightcomputer.cpp @@ -1,4 +1,4 @@ -#include +#include #include extern "C" { diff --git a/Tests/LowLevel/Components/imu.cpp b/Tests/LowLevel/Components/imu.cpp index a256f7b5..7648e327 100644 --- a/Tests/LowLevel/Components/imu.cpp +++ b/Tests/LowLevel/Components/imu.cpp @@ -1,6 +1,6 @@ -#include -#include -#include +#include +#include +#include #include extern "C" { diff --git a/Tests/LowLevel/Components/remote.cpp b/Tests/LowLevel/Components/remote.cpp index 0d1323cc..6eefbdde 100644 --- a/Tests/LowLevel/Components/remote.cpp +++ b/Tests/LowLevel/Components/remote.cpp @@ -1,4 +1,4 @@ -#include +#include #include extern "C" { diff --git a/Tests/LowLevel/Components/system.cpp b/Tests/LowLevel/Components/system.cpp index 8433ad28..24f03c19 100644 --- a/Tests/LowLevel/Components/system.cpp +++ b/Tests/LowLevel/Components/system.cpp @@ -1,8 +1,8 @@ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include extern "C" { diff --git a/Tests/LowLevel/Drivers/bno055.cpp b/Tests/LowLevel/Drivers/bno055.cpp index 87d07dfe..4cf5094d 100644 --- a/Tests/LowLevel/Drivers/bno055.cpp +++ b/Tests/LowLevel/Drivers/bno055.cpp @@ -1,4 +1,4 @@ -#include +#include #include extern "C" { diff --git a/Tests/LowLevel/Drivers/ppm.cpp b/Tests/LowLevel/Drivers/ppm.cpp index f2802186..e8335749 100644 --- a/Tests/LowLevel/Drivers/ppm.cpp +++ b/Tests/LowLevel/Drivers/ppm.cpp @@ -1,4 +1,4 @@ -#include +#include #include extern "C" { diff --git a/Tests/LowLevel/Drivers/protobuf.cpp b/Tests/LowLevel/Drivers/protobuf.cpp index 4ac2a161..95fa8f3d 100644 --- a/Tests/LowLevel/Drivers/protobuf.cpp +++ b/Tests/LowLevel/Drivers/protobuf.cpp @@ -1,7 +1,7 @@ -#include -#include -#include -#include +#include +#include +#include +#include #include #include diff --git a/Tests/LowLevel/Drivers/sbus.cpp b/Tests/LowLevel/Drivers/sbus.cpp index 471c0636..2339c6d8 100644 --- a/Tests/LowLevel/Drivers/sbus.cpp +++ b/Tests/LowLevel/Drivers/sbus.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include extern "C" { diff --git a/Tests/LowLevel/Mock/CMakeLists.txt b/Tests/LowLevel/Mock/CMakeLists.txt index 57c82a05..bb98bb14 100644 --- a/Tests/LowLevel/Mock/CMakeLists.txt +++ b/Tests/LowLevel/Mock/CMakeLists.txt @@ -10,7 +10,7 @@ FetchContent_MakeAvailable(gtest) # Load mocking lib add_subdirectory(Lib) - +# Function to declare a library for a mocked module function(declare_mock mocked_module_header mock_lib_out) # Build names/paths get_filename_component(module_name ${mocked_module_header} NAME_WE) @@ -37,9 +37,6 @@ function(declare_mock mocked_module_header mock_lib_out) endif () endfunction() -#target_link_libraries(Mock_Messages_MessageEncoding PUBLIC ToolboxPlaneMessageDefs) -#target_link_libraries(Mock_Messages_MessageDecoding PUBLIC ToolboxPlaneMessageDefs) -#target_link_libraries(Mock_Drivers_protobuf PUBLIC ToolboxPlaneMessageDefs) set(AllTestResults) @@ -69,6 +66,9 @@ function(make_test) set(test_name "${CMAKE_C_COMPILER_ID}_${compiler_version}_${CMAKE_BUILD_TYPE}_${TestSuite}") target_compile_definitions(${TestExecutable} PRIVATE -DTEST_NAME=${test_name}) + # Include mocked system directory + target_include_directories(${TestExecutable} PRIVATE ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/System) + # Link against GTest libraries target_link_libraries(${TestExecutable} PRIVATE gtest gmock pthread) diff --git a/Tests/LowLevel/Mock/Lib/generate_mock.py b/Tests/LowLevel/Mock/Lib/generate_mock.py index f9bdf70d..da9db8d7 100644 --- a/Tests/LowLevel/Mock/Lib/generate_mock.py +++ b/Tests/LowLevel/Mock/Lib/generate_mock.py @@ -58,11 +58,11 @@ args = ", ".join([f"{arg[0]}" for arg in args_with_name]) args_forward = ", ".join([arg[1] for arg in args_with_name]) - return_statement = "return" if return_type_with_name.startswith("void") else "" + return_statement = "" if return_type_with_name.startswith("void") else "return " mock_src.write( f"{return_type_with_name}({args}) {{\n" - f"\t{return_statement} mock::{module_name}.functionCallDelegate<{name}>({args_forward});\n" + f"\t{return_statement}mock::{module_name}.functionCallDelegate<{name}>({args_forward});\n" f"}}\n\n" ) diff --git a/Tests/LowLevel/Mock/System/avr/io.h b/Tests/LowLevel/Mock/System/avr/io.h index 0b59d6af..d2ba48ba 100644 --- a/Tests/LowLevel/Mock/System/avr/io.h +++ b/Tests/LowLevel/Mock/System/avr/io.h @@ -9,8 +9,20 @@ #include -extern uint8_t DDRA, DDRB, DDRC, DDRD, DDRE, DDRH, DDRL; -extern uint8_t PORTA, PORTB, PORTC, PORTD, PORTE, PORTH, PORTL; +extern uint8_t DDRA; +extern uint8_t DDRB; +extern uint8_t DDRC; +extern uint8_t DDRD; +extern uint8_t DDRE; +extern uint8_t DDRH; +extern uint8_t DDRL; +extern uint8_t PORTA; +extern uint8_t PORTB; +extern uint8_t PORTC; +extern uint8_t PORTD; +extern uint8_t PORTE; +extern uint8_t PORTH; +extern uint8_t PORTL; extern uint8_t MCUSR; enum { WDRF, BORF };