Skip to content

Commit

Permalink
#45: Adapted all tests for new mocking structure
Browse files Browse the repository at this point in the history
  • Loading branch information
aul12 committed Jan 1, 2023
1 parent cec3c38 commit b1a0763
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 81 deletions.
4 changes: 2 additions & 2 deletions Tests/LowLevel/Application/error_handler.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <Mock/avr/io.hpp>
#include <Mock/avr/wdt.hpp>
#include <Mock/io.hpp>
#include <Mock/wdt.hpp>
#include <gtest/gtest.h>

extern "C" {
Expand Down
8 changes: 4 additions & 4 deletions Tests/LowLevel/Application/mode_handler.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <Mock/Application/error_handler.hpp>
#include <Mock/Components/flightcomputer.hpp>
#include <Mock/Components/imu.hpp>
#include <Mock/Components/remote.hpp>
#include <Mock/error_handler.hpp>
#include <Mock/flightcomputer.hpp>
#include <Mock/imu.hpp>
#include <Mock/remote.hpp>
#include <gtest/gtest.h>

extern "C" {
Expand Down
63 changes: 15 additions & 48 deletions Tests/LowLevel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Tests/LowLevel/Components/actuators.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <Mock/Drivers/ppm.hpp>
#include <Mock/ppm.hpp>
#include <gtest/gtest.h>

extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion Tests/LowLevel/Components/flightcomputer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <Mock/Drivers/protobuf.hpp>
#include <Mock/protobuf.hpp>
#include <gtest/gtest.h>

extern "C" {
Expand Down
6 changes: 3 additions & 3 deletions Tests/LowLevel/Components/imu.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <Mock/Application/error_handler.hpp>
#include <Mock/Drivers/bno055.hpp>
#include <Mock/util/delay.hpp>
#include <Mock/error_handler.hpp>
#include <Mock/bno055.hpp>
#include <Mock/delay.hpp>
#include <gtest/gtest.h>

extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion Tests/LowLevel/Components/remote.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <Mock/Drivers/sbus.hpp>
#include <Mock/sbus.hpp>
#include <gtest/gtest.h>

extern "C" {
Expand Down
10 changes: 5 additions & 5 deletions Tests/LowLevel/Components/system.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <Mock/Application/error_handler.hpp>
#include <Mock/HAL/timer8bit.hpp>
#include <Mock/avr/interrupt.hpp>
#include <Mock/avr/io.hpp>
#include <Mock/avr/wdt.hpp>
#include <Mock/error_handler.hpp>
#include <Mock/timer8bit.hpp>
#include <Mock/interrupt.hpp>
#include <Mock/io.hpp>
#include <Mock/wdt.hpp>
#include <gtest/gtest.h>

extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion Tests/LowLevel/Drivers/bno055.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <Mock/Drivers/bno055_uart.hpp>
#include <Mock/bno055_uart.hpp>
#include <gtest/gtest.h>

extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion Tests/LowLevel/Drivers/ppm.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <Mock/HAL/pwm16bit.hpp>
#include <Mock/pwm16bit.hpp>
#include <gtest/gtest.h>

extern "C" {
Expand Down
8 changes: 4 additions & 4 deletions Tests/LowLevel/Drivers/protobuf.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <Mock/Drivers/ring_buffer.hpp>
#include <Mock/HAL/uart.hpp>
#include <Mock/Messages/MessageDecoding.hpp>
#include <Mock/Messages/MessageEncoding.hpp>
#include <Mock/ring_buffer.hpp>
#include <Mock/uart.hpp>
#include <Mock/MessageDecoding.hpp>
#include <Mock/MessageEncoding.hpp>
#include <gtest/gtest.h>
#include <queue>

Expand Down
4 changes: 2 additions & 2 deletions Tests/LowLevel/Drivers/sbus.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <Mock/Drivers/ring_buffer.hpp>
#include <Mock/HAL/uart.hpp>
#include <Mock/ring_buffer.hpp>
#include <Mock/uart.hpp>
#include <gtest/gtest.h>

extern "C" {
Expand Down
8 changes: 4 additions & 4 deletions Tests/LowLevel/Mock/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions Tests/LowLevel/Mock/Lib/generate_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
16 changes: 14 additions & 2 deletions Tests/LowLevel/Mock/System/avr/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,20 @@

#include <stdint.h>

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 };
Expand Down

0 comments on commit b1a0763

Please sign in to comment.