Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #45 #61

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions .github/workflows/low_level_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ jobs:
{ cc: clang-12, cxx: clang++-12 },
{ cc: clang-13, cxx: clang++-13 },
{ cc: clang-14, cxx: clang++-14 },
#{ cc: clang-15, cxx: clang++-15 },
{ cc: clang-16, cxx: clang++-16 } ]
{ cc: clang-15, cxx: clang++-15 },
# { cc: clang-16, cxx: clang++-16 },
{ cc: clang-17, cxx: clang++-17 } ]
build: [ Release, Debug ]
env:
CC: ${{ matrix.compiler.cc }}
Expand All @@ -31,7 +32,11 @@ jobs:
sudo add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy main"
sudo add-apt-repository "deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy main"
sudo apt-get update
sudo apt-get install -y wget g++-9 g++-10 g++-11 protobuf-compiler valgrind python3-protobuf clang-*
sudo apt-get install -y wget g++-9 g++-10 g++-11 protobuf-compiler valgrind python3-protobuf clang-* scons
- name: Run NanoPB Tests
run: |
cd Src/Messages/External/nanopb/tests/
scons
- name: Set up Build
run: cmake -B build -DCMAKE_BUILD_TYPE=${{ matrix.build }}
- name: Build and run tests
Expand All @@ -43,7 +48,7 @@ jobs:
- uses: actions/upload-artifact@v3
with:
name: ${{ matrix.compiler.cc }}
path: build/Tests/LowLevel
path: .

Report:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -78,20 +83,20 @@ jobs:
needs: Run-Tests
if: ${{ always() }}
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- uses: actions/download-artifact@v3
with:
name: gcc-11
- run: tree
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y lcov
- 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 --capture --directory build -o local.info
lcov -a local.info -o coverage.info
- name: Gen HTML
run: genhtml coverage.info --output-directory coverage
- name: Move HTML
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@
[submodule "Messages"]
path = Src/Messages
url = https://github.com/ToolboxPlane/Messages.git
[submodule "Tests/LowLevel/Mock"]
path = Tests/LowLevel/Mock
url = https://github.com/ToolboxPlane/MockTools.git
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ else ()
message(STATUS "Not building for AVR")
endif ()

add_subdirectory(Tests)
add_subdirectory(Src)
add_subdirectory(Tests)
5 changes: 2 additions & 3 deletions Src/Drivers/protobuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static void uart_callback(uint8_t data) {
}

void protobuf_init(void) {
message_decoding_init(&message_decoding_data, FC_SP_ID);
message_decoding_init(&message_decoding_data, FC_SP_ID, ToolboxPlaneMessages_FlightControllerSetpoint_fields);
ring_buffer_data = ring_buffer_init();
uart_init(UART_ID, UART_BAUD, NONE, 1, uart_callback);
}
Expand All @@ -43,8 +43,7 @@ bool protobuf_available(void) {
bool res = false;
uint8_t data = 0;
while (ring_buffer_get(&ring_buffer_data, &data)) {
if (message_decoding_decode(&message_decoding_data, data, &ToolboxPlaneMessages_FlightControllerSetpoint_msg,
&setpoint_message)) {
if (message_decoding_decode(&message_decoding_data, data, &setpoint_message)) {
res = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Src/HAL
2 changes: 1 addition & 1 deletion Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file main.c
* @author Paul Nykiel
* @date 12.04.19
* @brief Main file of the Flightcontroller firmware.
* @brief Main file of the Flight-Controller firmware.
*/
#include "Application/application.h"

Expand Down
6 changes: 1 addition & 5 deletions Tests/LowLevel/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
add_subdirectory(Mock)
function(make_fc_test)
cmake_parse_arguments(MAKE_FC_TEST
"" # Options
Expand All @@ -9,7 +8,7 @@ function(make_fc_test)
set(headers)
foreach (module ${MAKE_FC_TEST_DEPS})
set(LOCAL_HEADER ${CMAKE_SOURCE_DIR}/Src/${module}.h)
set(SYSTEM_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/Mock/System/${module}.h)
set(SYSTEM_HEADER ${MockLib_SOURCE_DIR}/../System/${module}.h)
if (EXISTS ${LOCAL_HEADER})
list(APPEND headers ${LOCAL_HEADER})
elseif (EXISTS ${SYSTEM_HEADER})
Expand Down Expand Up @@ -48,9 +47,6 @@ make_fc_test(MODULE Drivers/ppm DEPS HAL/pwm16bit avr/io)
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)
make_fc_test(MODULE HAL/pwm16bit DEPS avr/io)
make_fc_test(MODULE HAL/timer8bit DEPS avr/io)
make_fc_test(MODULE HAL/uart DEPS avr/io)

target_link_libraries(MessageEncoding.mock PUBLIC ToolboxPlaneMessageDefs)
target_link_libraries(MessageDecoding.mock PUBLIC ToolboxPlaneMessageDefs)
Expand Down
40 changes: 18 additions & 22 deletions Tests/LowLevel/Drivers/protobuf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ TEST(TEST_NAME, init) {

EXPECT_TRUE(uartHandle.functionGotCalled<uart_init>(0, 115200U, NONE, 1, std::ignore));
EXPECT_TRUE(ringBufferHandle.functionGotCalled<ring_buffer_init>());
EXPECT_TRUE(decodeHandle.functionGotCalled<message_decoding_init>(std::ignore, 0x40));
EXPECT_TRUE(decodeHandle.functionGotCalled<message_decoding_init>(
std::ignore, 0x40, ToolboxPlaneMessages_FlightControllerSetpoint_fields));
}

TEST(TEST_NAME, send_fc) {
Expand Down Expand Up @@ -92,7 +93,7 @@ TEST(TEST_NAME, rx_fill_buffer) {
EXPECT_TRUE(ringBufferHandle.functionGotCalled<ring_buffer_put>(std::ignore, 54));
}

TEST(TEST_NAME, available_read_buffer) {
TEST(TEST_NAME, available__read_buffer) {
auto uartHandle = mock::uart.getHandle();
auto decodeHandle = mock::MessageDecoding.getHandle();
auto ringBufferHandle = mock::ring_buffer.getHandle();
Expand All @@ -109,18 +110,14 @@ TEST(TEST_NAME, available_read_buffer) {
return count <= 4;
});
decodeHandle.overrideFunc<message_decoding_decode>([](message_decoding_data_t * /*messageDecodingData*/,
uint8_t /*data*/, const pb_msgdesc_t * /*fields*/,
uint8_t /*data*/,
void * /*message*/) -> bool { return false; });

protobuf_available();
EXPECT_TRUE(decodeHandle.functionGotCalled<message_decoding_decode>(
std::ignore, 1, &ToolboxPlaneMessages_FlightControllerSetpoint_msg, std::ignore));
EXPECT_TRUE(decodeHandle.functionGotCalled<message_decoding_decode>(
std::ignore, 2, &ToolboxPlaneMessages_FlightControllerSetpoint_msg, std::ignore));
EXPECT_TRUE(decodeHandle.functionGotCalled<message_decoding_decode>(
std::ignore, 3, &ToolboxPlaneMessages_FlightControllerSetpoint_msg, std::ignore));
EXPECT_TRUE(decodeHandle.functionGotCalled<message_decoding_decode>(
std::ignore, 4, &ToolboxPlaneMessages_FlightControllerSetpoint_msg, std::ignore));
EXPECT_TRUE(decodeHandle.functionGotCalled<message_decoding_decode>(std::ignore, 1, std::ignore));
EXPECT_TRUE(decodeHandle.functionGotCalled<message_decoding_decode>(std::ignore, 2, std::ignore));
EXPECT_TRUE(decodeHandle.functionGotCalled<message_decoding_decode>(std::ignore, 3, std::ignore));
EXPECT_TRUE(decodeHandle.functionGotCalled<message_decoding_decode>(std::ignore, 4, std::ignore));
}

TEST(TEST_NAME, receive_pb_no_decode) {
Expand All @@ -141,7 +138,7 @@ TEST(TEST_NAME, receive_pb_no_decode) {
});

decodeHandle.overrideFunc<message_decoding_decode>([](message_decoding_data_t * /*messageDecodingData*/,
uint8_t /*data*/, const pb_msgdesc_t * /*fields*/,
uint8_t /*data*/,
void * /*message*/) -> bool { return false; });

EXPECT_FALSE(protobuf_available());
Expand All @@ -165,7 +162,7 @@ TEST(TEST_NAME, receive_pb_yes_decode) {
});

decodeHandle.overrideFunc<message_decoding_decode>([](message_decoding_data_t * /*messageDecodingData*/,
uint8_t /*data*/, const pb_msgdesc_t * /*fields*/,
uint8_t /*data*/,
void * /*message*/) -> bool { return true; });

EXPECT_TRUE(protobuf_available());
Expand All @@ -188,15 +185,14 @@ TEST(TEST_NAME, receive_pb_decode_data) {
return count == 1;
});

decodeHandle.overrideFunc<message_decoding_decode>([](message_decoding_data_t * /*messageDecodingData*/,
uint8_t /*data*/, const pb_msgdesc_t * /*fields*/,
void *message) -> bool {
auto fcData = static_cast<ToolboxPlaneMessages_FlightControllerSetpoint *>(message);
fcData->motor = 1337;
fcData->pitch = 17;
fcData->roll = 34;
return true;
});
decodeHandle.overrideFunc<message_decoding_decode>(
[](message_decoding_data_t * /*messageDecodingData*/, uint8_t /*data*/, void *message) -> bool {
auto fcData = static_cast<ToolboxPlaneMessages_FlightControllerSetpoint *>(message);
fcData->motor = 1337;
fcData->pitch = 17;
fcData->roll = 34;
return true;
});

EXPECT_TRUE(protobuf_available());
EXPECT_EQ(protobuf_get().motor, 1337);
Expand Down
Empty file removed Tests/LowLevel/HAL/pwm16bit.cpp
Empty file.
Empty file removed Tests/LowLevel/HAL/timer8bit.cpp
Empty file.
Empty file removed Tests/LowLevel/HAL/uart.cpp
Empty file.
1 change: 0 additions & 1 deletion Tests/LowLevel/Mock
Submodule Mock deleted from 035195
9 changes: 0 additions & 9 deletions Tests/LowLevel/main.cpp

This file was deleted.