From 06d74ec5d2124703f379018899abe9a02909a355 Mon Sep 17 00:00:00 2001 From: Paul Nykiel Date: Sun, 29 Jan 2023 19:53:35 +0100 Subject: [PATCH 01/22] Added files for tests --- Tests/LowLevel/CMakeLists.txt | 4 ++++ Tests/LowLevel/Messages/MessageDecoding.cpp | 6 ++++++ Tests/LowLevel/Messages/MessageEncoding.cpp | 6 ++++++ 3 files changed, 16 insertions(+) create mode 100644 Tests/LowLevel/Messages/MessageDecoding.cpp create mode 100644 Tests/LowLevel/Messages/MessageEncoding.cpp diff --git a/Tests/LowLevel/CMakeLists.txt b/Tests/LowLevel/CMakeLists.txt index 31c09c2..e373bf9 100644 --- a/Tests/LowLevel/CMakeLists.txt +++ b/Tests/LowLevel/CMakeLists.txt @@ -51,6 +51,10 @@ 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) +make_fc_test(MODULE Messages/MessageDecoding) +target_link_libraries(MessageDecoding.test PUBLIC ToolboxPlaneMessageDefs) +make_fc_test(MODULE Messages/MessageEncoding) +target_link_libraries(MessageEncoding.test PUBLIC ToolboxPlaneMessageDefs) target_link_libraries(MessageEncoding.mock PUBLIC ToolboxPlaneMessageDefs) target_link_libraries(MessageDecoding.mock PUBLIC ToolboxPlaneMessageDefs) diff --git a/Tests/LowLevel/Messages/MessageDecoding.cpp b/Tests/LowLevel/Messages/MessageDecoding.cpp new file mode 100644 index 0000000..83cb967 --- /dev/null +++ b/Tests/LowLevel/Messages/MessageDecoding.cpp @@ -0,0 +1,6 @@ +/** + * @file MessageDecoding.cpp + * @author Paul Nykiel + * @date 29.01.23 + * @brief Description here TODO + */ diff --git a/Tests/LowLevel/Messages/MessageEncoding.cpp b/Tests/LowLevel/Messages/MessageEncoding.cpp new file mode 100644 index 0000000..4104e11 --- /dev/null +++ b/Tests/LowLevel/Messages/MessageEncoding.cpp @@ -0,0 +1,6 @@ +/** + * @file MessageEncoding.cpp + * @author Paul Nykiel + * @date 29.01.23 + * @brief Description here TODO + */ From 26b6058e561722d51484eb7962fd6a12e8f697eb Mon Sep 17 00:00:00 2001 From: Paul Nykiel Date: Mon, 30 Jan 2023 19:51:07 +0100 Subject: [PATCH 02/22] Updated messages, started with tests --- Src/Messages | 2 +- Tests/LowLevel/Messages/MessageDecoding.cpp | 181 +++++++++++++++++++- 2 files changed, 176 insertions(+), 7 deletions(-) diff --git a/Src/Messages b/Src/Messages index 3f52ae8..11f253f 160000 --- a/Src/Messages +++ b/Src/Messages @@ -1 +1 @@ -Subproject commit 3f52ae897f52ade0f3ae96b34585f395eaa4bae4 +Subproject commit 11f253f4196d7352c2c9a9bf90badfd7c272cc94 diff --git a/Tests/LowLevel/Messages/MessageDecoding.cpp b/Tests/LowLevel/Messages/MessageDecoding.cpp index 83cb967..2b957fc 100644 --- a/Tests/LowLevel/Messages/MessageDecoding.cpp +++ b/Tests/LowLevel/Messages/MessageDecoding.cpp @@ -1,6 +1,175 @@ -/** - * @file MessageDecoding.cpp - * @author Paul Nykiel - * @date 29.01.23 - * @brief Description here TODO - */ +#include + +extern "C" { +#include +} + +#include "FlightControllerSetpoint.pb.h" + +TEST(TEST_NAME, decode__nominal_decode) { + /* + * Nominal decode test. + * Test: + * * Initialize with message_id as 17 + * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect false + * * Feed 17 to transition to IN_DATA, expect false + * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect true + */ + message_decoding_data_t decodingData; + message_decoding_init(&decodingData, 17, ToolboxPlaneMessages_FlightControllerSetpoint_fields); + + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 17, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + ToolboxPlaneMessages_FlightControllerSetpoint buf; + EXPECT_TRUE(message_decoding_decode(&decodingData, 0x0F, &buf)); +} + +TEST(TEST_NAME, decode__premature_end) { + /* + * Premature end test. + * Test: + * * Initialize with message_id as 17 + * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect false + * * Feed 17 to transition to IN_DATA, expect false + * * Feed 0x08 to keep in IN_DATA, expect false + * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false + * * Feed 0x01 to transition to IN_DATA, expect false + * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect true + */ + message_decoding_data_t decodingData; + message_decoding_init(&decodingData, 17, ToolboxPlaneMessages_FlightControllerSetpoint_fields); + + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 17, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0x08, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0x01, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + ToolboxPlaneMessages_FlightControllerSetpoint buf; + EXPECT_TRUE(message_decoding_decode(&decodingData, 0x0F, &buf)); +} + +TEST(TEST_NAME, decode__wrong_data) { + /* + * Wrong data test. + * Test: + * * Initialize with message_id as 17 + * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect false + * * Feed 18 to transition to IN_DATA, expect false + * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect false + * * Feed 17 to transition to IN_DATA, expect false + * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect true + */ + message_decoding_data_t decodingData; + message_decoding_init(&decodingData, 17, ToolboxPlaneMessages_FlightControllerSetpoint_fields); + + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 18, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 17, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + ToolboxPlaneMessages_FlightControllerSetpoint buf; + EXPECT_TRUE(message_decoding_decode(&decodingData, 0x0F, &buf)); +} + +TEST(TEST_NAME, decode__wrong_data_premature_end) { + /* + * Wrong Data Premature end test. + * Test: + * * Initialize with message_id as 17 + * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect false + * * Feed 18 to transition to IN_DATA, expect false + * * Feed 0x08 to keep in IN_DATA, expect false + * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false + * * Feed 0x01 to transition to IN_DATA, expect false + * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect false + * * Feed 17 to transition to IN_DATA, expect false + * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect true + */ + message_decoding_data_t decodingData; + message_decoding_init(&decodingData, 17, ToolboxPlaneMessages_FlightControllerSetpoint_fields); + + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 18, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0x08, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0x01, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 17, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + ToolboxPlaneMessages_FlightControllerSetpoint buf; + EXPECT_TRUE(message_decoding_decode(&decodingData, 0x0F, &buf)); +} + +TEST(TEST_NAME, decode__multiple_init) { + /* + * Multiple init decode test. + * Test: + * * Initialize with message_id as 17 + * * Feed 0x00 to keep in initial + * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect false + * * Feed 17 to transition to IN_DATA, expect false + * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect true + */ + message_decoding_data_t decodingData; + message_decoding_init(&decodingData, 17, ToolboxPlaneMessages_FlightControllerSetpoint_fields); + + EXPECT_FALSE(message_decoding_decode(&decodingData, 0x00, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 17, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + ToolboxPlaneMessages_FlightControllerSetpoint buf; + EXPECT_TRUE(message_decoding_decode(&decodingData, 0x0F, &buf)); +} + +TEST(TEST_NAME, decode__init_wrong_end) { + /* + * Init wrong end test. + * Test: + * * Initialize with message_id as 17 + * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0x00 to transition to INITIAL, expect false + * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect false + * * Feed 17 to transition to IN_DATA, expect false + * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect true + */ + message_decoding_data_t decodingData; + message_decoding_init(&decodingData, 17, ToolboxPlaneMessages_FlightControllerSetpoint_fields); + + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0x00, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 17, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + ToolboxPlaneMessages_FlightControllerSetpoint buf; + EXPECT_TRUE(message_decoding_decode(&decodingData, 0x0F, &buf)); +} + +// echo "power: 1337, pitch: 17, roll: 34" | protoc --encode=ToolboxPlaneMessages.FlightControllerSetpoint +// Src/Messages/Definitions/FlightControllerSetpoint.proto | xxd + + +// @TODO test strategy for actual decoding From 69806faebf21842693f28ad8fc82fdeaac809967 Mon Sep 17 00:00:00 2001 From: Paul Nykiel Date: Mon, 30 Jan 2023 19:56:58 +0100 Subject: [PATCH 03/22] Adapted protobuf tests for new decoding interface --- Src/Drivers/protobuf.c | 5 ++-- Tests/LowLevel/Drivers/protobuf.cpp | 40 +++++++++++++---------------- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/Src/Drivers/protobuf.c b/Src/Drivers/protobuf.c index 4af81a5..3678db7 100644 --- a/Src/Drivers/protobuf.c +++ b/Src/Drivers/protobuf.c @@ -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); } @@ -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; } } diff --git a/Tests/LowLevel/Drivers/protobuf.cpp b/Tests/LowLevel/Drivers/protobuf.cpp index 9df8664..2f42252 100644 --- a/Tests/LowLevel/Drivers/protobuf.cpp +++ b/Tests/LowLevel/Drivers/protobuf.cpp @@ -19,7 +19,8 @@ TEST(TEST_NAME, init) { EXPECT_TRUE(uartHandle.functionGotCalled(0, 115200U, NONE, 1, std::ignore)); EXPECT_TRUE(ringBufferHandle.functionGotCalled()); - EXPECT_TRUE(decodeHandle.functionGotCalled(std::ignore, 0x40)); + EXPECT_TRUE(decodeHandle.functionGotCalled( + std::ignore, 0x40, ToolboxPlaneMessages_FlightControllerSetpoint_fields)); } TEST(TEST_NAME, send_fc) { @@ -92,7 +93,7 @@ TEST(TEST_NAME, rx_fill_buffer) { EXPECT_TRUE(ringBufferHandle.functionGotCalled(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(); @@ -109,18 +110,14 @@ TEST(TEST_NAME, available_read_buffer) { return count <= 4; }); decodeHandle.overrideFunc([](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( - std::ignore, 1, &ToolboxPlaneMessages_FlightControllerSetpoint_msg, std::ignore)); - EXPECT_TRUE(decodeHandle.functionGotCalled( - std::ignore, 2, &ToolboxPlaneMessages_FlightControllerSetpoint_msg, std::ignore)); - EXPECT_TRUE(decodeHandle.functionGotCalled( - std::ignore, 3, &ToolboxPlaneMessages_FlightControllerSetpoint_msg, std::ignore)); - EXPECT_TRUE(decodeHandle.functionGotCalled( - std::ignore, 4, &ToolboxPlaneMessages_FlightControllerSetpoint_msg, std::ignore)); + EXPECT_TRUE(decodeHandle.functionGotCalled(std::ignore, 1, std::ignore)); + EXPECT_TRUE(decodeHandle.functionGotCalled(std::ignore, 2, std::ignore)); + EXPECT_TRUE(decodeHandle.functionGotCalled(std::ignore, 3, std::ignore)); + EXPECT_TRUE(decodeHandle.functionGotCalled(std::ignore, 4, std::ignore)); } TEST(TEST_NAME, receive_pb_no_decode) { @@ -141,7 +138,7 @@ TEST(TEST_NAME, receive_pb_no_decode) { }); decodeHandle.overrideFunc([](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()); @@ -165,7 +162,7 @@ TEST(TEST_NAME, receive_pb_yes_decode) { }); decodeHandle.overrideFunc([](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()); @@ -188,15 +185,14 @@ TEST(TEST_NAME, receive_pb_decode_data) { return count == 1; }); - decodeHandle.overrideFunc([](message_decoding_data_t * /*messageDecodingData*/, - uint8_t /*data*/, const pb_msgdesc_t * /*fields*/, - void *message) -> bool { - auto fcData = static_cast(message); - fcData->motor = 1337; - fcData->pitch = 17; - fcData->roll = 34; - return true; - }); + decodeHandle.overrideFunc( + [](message_decoding_data_t * /*messageDecodingData*/, uint8_t /*data*/, void *message) -> bool { + auto fcData = static_cast(message); + fcData->motor = 1337; + fcData->pitch = 17; + fcData->roll = 34; + return true; + }); EXPECT_TRUE(protobuf_available()); EXPECT_EQ(protobuf_get().motor, 1337); From 5a54fb7c907cf385f77f5fc63b7c9dbbed76b84e Mon Sep 17 00:00:00 2001 From: Paul Nykiel Date: Tue, 31 Jan 2023 19:33:53 +0100 Subject: [PATCH 04/22] Added message decoding tests and started with encoding tests --- Tests/LowLevel/CMakeLists.txt | 8 + Tests/LowLevel/Messages/MessageDecoding.cpp | 267 +++++++++++++++++++- Tests/LowLevel/Messages/MessageEncoding.cpp | 25 +- Tests/LowLevel/Messages/generate_tests.sh | 35 +++ 4 files changed, 326 insertions(+), 9 deletions(-) create mode 100755 Tests/LowLevel/Messages/generate_tests.sh diff --git a/Tests/LowLevel/CMakeLists.txt b/Tests/LowLevel/CMakeLists.txt index e373bf9..0848ec2 100644 --- a/Tests/LowLevel/CMakeLists.txt +++ b/Tests/LowLevel/CMakeLists.txt @@ -51,10 +51,18 @@ 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) + + +add_custom_target(generate_tests + COMMAND ${CMAKE_CURRENT_LIST_DIR}/Messages/generate_tests.sh ${CMAKE_SOURCE_DIR} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS ${CMAKE_CURRENT_LIST_DIR}/Messages/generate_tests.sh) make_fc_test(MODULE Messages/MessageDecoding) target_link_libraries(MessageDecoding.test PUBLIC ToolboxPlaneMessageDefs) +add_dependencies(MessageDecoding.test generate_tests) make_fc_test(MODULE Messages/MessageEncoding) target_link_libraries(MessageEncoding.test PUBLIC ToolboxPlaneMessageDefs) +add_dependencies(MessageEncoding.test generate_tests) target_link_libraries(MessageEncoding.mock PUBLIC ToolboxPlaneMessageDefs) target_link_libraries(MessageDecoding.mock PUBLIC ToolboxPlaneMessageDefs) diff --git a/Tests/LowLevel/Messages/MessageDecoding.cpp b/Tests/LowLevel/Messages/MessageDecoding.cpp index 2b957fc..a85cb50 100644 --- a/Tests/LowLevel/Messages/MessageDecoding.cpp +++ b/Tests/LowLevel/Messages/MessageDecoding.cpp @@ -1,3 +1,4 @@ +#include #include extern "C" { @@ -168,8 +169,268 @@ TEST(TEST_NAME, decode__init_wrong_end) { EXPECT_TRUE(message_decoding_decode(&decodingData, 0x0F, &buf)); } -// echo "power: 1337, pitch: 17, roll: 34" | protoc --encode=ToolboxPlaneMessages.FlightControllerSetpoint -// Src/Messages/Definitions/FlightControllerSetpoint.proto | xxd +TEST(TEST_NAME, decode__fcs_decode) { + /* + * Flight-Controller-Set-Point min power test: + * * Initialize with message_id as 0 + * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect false + * * Feed 0 to transition to IN_DATA, expect false + * * Feed data from fcs_min_power.bin, expect false for every byte + * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect true + * * Check return message, expect: + * * motor: -2147483648 + * * pitch: 0 + * * roll: 0 + */ + message_decoding_data_t decodingData; + message_decoding_init(&decodingData, 0, ToolboxPlaneMessages_FlightControllerSetpoint_fields); + + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0, nullptr)); + + std::ifstream stream{"fcs_decode.bin"}; + using c_stream_it = std::istreambuf_iterator; + + for (auto it = c_stream_it{stream}; it != c_stream_it{}; ++it) { + EXPECT_FALSE(message_decoding_decode(&decodingData, *it, nullptr)); + } + + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + ToolboxPlaneMessages_FlightControllerSetpoint buf; + EXPECT_TRUE(message_decoding_decode(&decodingData, 0x0F, &buf)); + + EXPECT_EQ(buf.motor, 17); + EXPECT_EQ(buf.pitch, -18); + EXPECT_EQ(buf.roll, 19); +} + +TEST(TEST_NAME, decode__fcs_min_power) { + /* + * Flight-Controller-Set-Point min power test: + * * Initialize with message_id as 0 + * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect false + * * Feed 0 to transition to IN_DATA, expect false + * * Feed data from fcs_min_power.bin, expect false for every byte + * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect true + * * Check return message, expect: + * * motor: -2147483648 + * * pitch: 0 + * * roll: 0 + */ + message_decoding_data_t decodingData; + message_decoding_init(&decodingData, 0, ToolboxPlaneMessages_FlightControllerSetpoint_fields); + + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0, nullptr)); + + std::ifstream stream{"fcs_min_power.bin"}; + using c_stream_it = std::istreambuf_iterator; + + for (auto it = c_stream_it{stream}; it != c_stream_it{}; ++it) { + EXPECT_FALSE(message_decoding_decode(&decodingData, *it, nullptr)); + } + + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + ToolboxPlaneMessages_FlightControllerSetpoint buf; + EXPECT_TRUE(message_decoding_decode(&decodingData, 0x0F, &buf)); + + EXPECT_EQ(buf.motor, -2147483648); + EXPECT_EQ(buf.pitch, 0); + EXPECT_EQ(buf.roll, 0); +} + +TEST(TEST_NAME, decode__fcs_max_power) { + /* + * Flight-Controller-Set-Point min power test: + * * Initialize with message_id as 0 + * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect false + * * Feed 0 to transition to IN_DATA, expect false + * * Feed data from fcs_max_power.bin, expect false for every byte + * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect true + * * Check return message, expect: + * * motor: 2147483647 + * * pitch: 0 + * * roll: 0 + */ + message_decoding_data_t decodingData; + message_decoding_init(&decodingData, 0, ToolboxPlaneMessages_FlightControllerSetpoint_fields); + + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0, nullptr)); + + std::ifstream stream{"fcs_max_power.bin"}; + using c_stream_it = std::istreambuf_iterator; + + for (auto it = c_stream_it{stream}; it != c_stream_it{}; ++it) { + EXPECT_FALSE(message_decoding_decode(&decodingData, *it, nullptr)); + } + + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + ToolboxPlaneMessages_FlightControllerSetpoint buf; + EXPECT_TRUE(message_decoding_decode(&decodingData, 0x0F, &buf)); + + EXPECT_EQ(buf.motor, 2147483647); + EXPECT_EQ(buf.pitch, 0); + EXPECT_EQ(buf.roll, 0); +} + +TEST(TEST_NAME, decode__fcs_min_pitch) { + /* + * Flight-Controller-Set-Point min power test: + * * Initialize with message_id as 0 + * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect false + * * Feed 0 to transition to IN_DATA, expect false + * * Feed data from fcs_min_pitch.bin, expect false for every byte + * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect true + * * Check return message, expect: + * * motor: 0 + * * pitch: -2147483648 + * * roll: 0 + */ + message_decoding_data_t decodingData; + message_decoding_init(&decodingData, 0, ToolboxPlaneMessages_FlightControllerSetpoint_fields); + + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0, nullptr)); + + std::ifstream stream{"fcs_min_pitch.bin"}; + using c_stream_it = std::istreambuf_iterator; + for (auto it = c_stream_it{stream}; it != c_stream_it{}; ++it) { + EXPECT_FALSE(message_decoding_decode(&decodingData, *it, nullptr)); + } + + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + ToolboxPlaneMessages_FlightControllerSetpoint buf; + EXPECT_TRUE(message_decoding_decode(&decodingData, 0x0F, &buf)); + + EXPECT_EQ(buf.motor, 0); + EXPECT_EQ(buf.pitch, -2147483648); + EXPECT_EQ(buf.roll, 0); +} + +TEST(TEST_NAME, decode__fcs_max_pitch) { + /* + * Flight-Controller-Set-Point min power test: + * * Initialize with message_id as 0 + * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect false + * * Feed 0 to transition to IN_DATA, expect false + * * Feed data from fcs_max_pitch.bin, expect false for every byte + * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect true + * * Check return message, expect: + * * motor: 0 + * * pitch: 2147483647 + * * roll: 0 + */ + message_decoding_data_t decodingData; + message_decoding_init(&decodingData, 0, ToolboxPlaneMessages_FlightControllerSetpoint_fields); -// @TODO test strategy for actual decoding + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0, nullptr)); + + std::ifstream stream{"fcs_max_pitch.bin"}; + using c_stream_it = std::istreambuf_iterator; + + for (auto it = c_stream_it{stream}; it != c_stream_it{}; ++it) { + EXPECT_FALSE(message_decoding_decode(&decodingData, *it, nullptr)); + } + + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + ToolboxPlaneMessages_FlightControllerSetpoint buf; + EXPECT_TRUE(message_decoding_decode(&decodingData, 0x0F, &buf)); + + EXPECT_EQ(buf.motor, 0); + EXPECT_EQ(buf.pitch, 2147483647); + EXPECT_EQ(buf.roll, 0); +} + +TEST(TEST_NAME, decode__fcs_min_roll) { + /* + * Flight-Controller-Set-Point min power test: + * * Initialize with message_id as 0 + * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect false + * * Feed 0 to transition to IN_DATA, expect false + * * Feed data from fcs_min_roll.bin, expect false for every byte + * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect true + * * Check return message, expect: + * * motor: 0 + * * pitch: 0 + * * roll: -2147483648 + */ + message_decoding_data_t decodingData; + message_decoding_init(&decodingData, 0, ToolboxPlaneMessages_FlightControllerSetpoint_fields); + + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0, nullptr)); + + std::ifstream stream{"fcs_min_roll.bin"}; + using c_stream_it = std::istreambuf_iterator; + + for (auto it = c_stream_it{stream}; it != c_stream_it{}; ++it) { + EXPECT_FALSE(message_decoding_decode(&decodingData, *it, nullptr)); + } + + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + ToolboxPlaneMessages_FlightControllerSetpoint buf; + EXPECT_TRUE(message_decoding_decode(&decodingData, 0x0F, &buf)); + + EXPECT_EQ(buf.motor, 0); + EXPECT_EQ(buf.pitch, 0); + EXPECT_EQ(buf.roll, -2147483648); +} + +TEST(TEST_NAME, decode__fcs_max_roll) { + /* + * Flight-Controller-Set-Point min power test: + * * Initialize with message_id as 0 + * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect false + * * Feed 0 to transition to IN_DATA, expect false + * * Feed data from fcs_max_roll.bin, expect false for every byte + * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false + * * Feed 0x0F to transition to START_FOUND, expect true + * * Check return message, expect: + * * motor: 0 + * * pitch: 0 + * * roll: 2147483647 + */ + message_decoding_data_t decodingData; + message_decoding_init(&decodingData, 0, ToolboxPlaneMessages_FlightControllerSetpoint_fields); + + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); + EXPECT_FALSE(message_decoding_decode(&decodingData, 0, nullptr)); + + std::ifstream stream{"fcs_max_roll.bin"}; + using c_stream_it = std::istreambuf_iterator; + + for (auto it = c_stream_it{stream}; it != c_stream_it{}; ++it) { + EXPECT_FALSE(message_decoding_decode(&decodingData, *it, nullptr)); + } + + EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); + ToolboxPlaneMessages_FlightControllerSetpoint buf; + EXPECT_TRUE(message_decoding_decode(&decodingData, 0x0F, &buf)); + + EXPECT_EQ(buf.motor, 0); + EXPECT_EQ(buf.pitch, 0); + EXPECT_EQ(buf.roll, 2147483647); +} diff --git a/Tests/LowLevel/Messages/MessageEncoding.cpp b/Tests/LowLevel/Messages/MessageEncoding.cpp index 4104e11..2bd78e8 100644 --- a/Tests/LowLevel/Messages/MessageEncoding.cpp +++ b/Tests/LowLevel/Messages/MessageEncoding.cpp @@ -1,6 +1,19 @@ -/** - * @file MessageEncoding.cpp - * @author Paul Nykiel - * @date 29.01.23 - * @brief Description here TODO - */ +#include + +extern "C" { +#include +} + +#include "FlightControllerSetpoint.pb.h" + +TEST(TEST_NAME, encode) { + std::array buf; + ToolboxPlaneMessages_FlightControllerSetpoint data{.motor = 0, .pitch = 0, .roll = 0}; + EXPECT_EQ(message_encode(buf.data(), buf.size(), ToolboxPlaneMessages_FlightControllerSetpoint_fields, &data, 17), + 3); + EXPECT_EQ(buf[0], 0x0F); + EXPECT_EQ(buf[1], 17); + EXPECT_EQ(buf[2], 0xF0); +} + +// TODO actual message encoding, decoding tests diff --git a/Tests/LowLevel/Messages/generate_tests.sh b/Tests/LowLevel/Messages/generate_tests.sh new file mode 100755 index 0000000..7bfed68 --- /dev/null +++ b/Tests/LowLevel/Messages/generate_tests.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +echo "motor: 17, pitch: -18, roll: 19" | \ + protoc --encode=ToolboxPlaneMessages.FlightControllerSetpoint \ + --proto_path "$1" \ + Src/Messages/Definitions/FlightControllerSetpoint.proto > fcs_decode.bin + +echo "motor: -2147483648, pitch: 0, roll: 0" | \ + protoc --encode=ToolboxPlaneMessages.FlightControllerSetpoint \ + --proto_path "$1" \ + Src/Messages/Definitions/FlightControllerSetpoint.proto > fcs_min_power.bin + +echo "motor: 2147483647, pitch: 0, roll: 0" | \ + protoc --encode=ToolboxPlaneMessages.FlightControllerSetpoint \ + --proto_path "$1" \ + Src/Messages/Definitions/FlightControllerSetpoint.proto > fcs_max_power.bin + +echo "motor: 0, pitch: -2147483648, roll: 0" | \ + protoc --encode=ToolboxPlaneMessages.FlightControllerSetpoint \ + --proto_path "$1" \ + Src/Messages/Definitions/FlightControllerSetpoint.proto > fcs_min_pitch.bin + +echo "motor: 0, pitch: 2147483647, roll: 0" | \ + protoc --encode=ToolboxPlaneMessages.FlightControllerSetpoint \ + --proto_path "$1" \ + Src/Messages/Definitions/FlightControllerSetpoint.proto > fcs_max_pitch.bin + +echo "motor: 0, pitch: 0, roll: -2147483648" | \ + protoc --encode=ToolboxPlaneMessages.FlightControllerSetpoint \ + --proto_path "$1" \ + Src/Messages/Definitions/FlightControllerSetpoint.proto > fcs_min_roll.bin + +echo "motor: 0, pitch: 0, roll: 2147483647" | \ + protoc --encode=ToolboxPlaneMessages.FlightControllerSetpoint \ + --proto_path "$1" \ + Src/Messages/Definitions/FlightControllerSetpoint.proto > fcs_max_roll.bin From dd7b20810293607985f5780ca4e21895afd92f01 Mon Sep 17 00:00:00 2001 From: Paul Nykiel Date: Wed, 1 Feb 2023 16:39:08 +0100 Subject: [PATCH 05/22] Updated submodule and tests --- Src/Messages | 2 +- Src/main.c | 2 +- Tests/LowLevel/Messages/MessageDecoding.cpp | 38 ++++++++++----------- Tests/LowLevel/Messages/MessageEncoding.cpp | 12 +++++-- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/Src/Messages b/Src/Messages index 11f253f..8e77636 160000 --- a/Src/Messages +++ b/Src/Messages @@ -1 +1 @@ -Subproject commit 11f253f4196d7352c2c9a9bf90badfd7c272cc94 +Subproject commit 8e77636813a1683f9723a3792f0636dfd1a38f0e diff --git a/Src/main.c b/Src/main.c index 6f1938d..3988a19 100644 --- a/Src/main.c +++ b/Src/main.c @@ -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" diff --git a/Tests/LowLevel/Messages/MessageDecoding.cpp b/Tests/LowLevel/Messages/MessageDecoding.cpp index a85cb50..1dd07b9 100644 --- a/Tests/LowLevel/Messages/MessageDecoding.cpp +++ b/Tests/LowLevel/Messages/MessageDecoding.cpp @@ -12,7 +12,7 @@ TEST(TEST_NAME, decode__nominal_decode) { * Nominal decode test. * Test: * * Initialize with message_id as 17 - * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0xF0 to transition to END_FOUND, expect false * * Feed 0x0F to transition to START_FOUND, expect false * * Feed 17 to transition to IN_DATA, expect false * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false @@ -34,7 +34,7 @@ TEST(TEST_NAME, decode__premature_end) { * Premature end test. * Test: * * Initialize with message_id as 17 - * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0xF0 to transition to END_FOUND, expect false * * Feed 0x0F to transition to START_FOUND, expect false * * Feed 17 to transition to IN_DATA, expect false * * Feed 0x08 to keep in IN_DATA, expect false @@ -62,10 +62,10 @@ TEST(TEST_NAME, decode__wrong_data) { * Wrong data test. * Test: * * Initialize with message_id as 17 - * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0xF0 to transition to END_FOUND, expect false * * Feed 0x0F to transition to START_FOUND, expect false - * * Feed 18 to transition to IN_DATA, expect false - * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false + * * Feed 18 to transition to INITIAL, expect false + * * Feed 0xF0 to transition to END_FOUND, expect false * * Feed 0x0F to transition to START_FOUND, expect false * * Feed 17 to transition to IN_DATA, expect false * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false @@ -90,11 +90,11 @@ TEST(TEST_NAME, decode__wrong_data_premature_end) { * Wrong Data Premature end test. * Test: * * Initialize with message_id as 17 - * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0xF0 to transition to END_FOUND, expect false * * Feed 0x0F to transition to START_FOUND, expect false - * * Feed 18 to transition to IN_DATA, expect false - * * Feed 0x08 to keep in IN_DATA, expect false - * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false + * * Feed 18 to transition to INITIAL, expect false + * * Feed 0x08 to keep in INITIAL, expect false + * * Feed 0xF0 to transition to END_FOUND, expect false * * Feed 0x01 to transition to IN_DATA, expect false * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false * * Feed 0x0F to transition to START_FOUND, expect false @@ -125,7 +125,7 @@ TEST(TEST_NAME, decode__multiple_init) { * Test: * * Initialize with message_id as 17 * * Feed 0x00 to keep in initial - * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0xF0 to transition to END_FOUND, expect false * * Feed 0x0F to transition to START_FOUND, expect false * * Feed 17 to transition to IN_DATA, expect false * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false @@ -148,9 +148,9 @@ TEST(TEST_NAME, decode__init_wrong_end) { * Init wrong end test. * Test: * * Initialize with message_id as 17 - * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0xF0 to transition to END_FOUND, expect false * * Feed 0x00 to transition to INITIAL, expect false - * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0xF0 to transition to END_FOUND, expect false * * Feed 0x0F to transition to START_FOUND, expect false * * Feed 17 to transition to IN_DATA, expect false * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false @@ -173,7 +173,7 @@ TEST(TEST_NAME, decode__fcs_decode) { /* * Flight-Controller-Set-Point min power test: * * Initialize with message_id as 0 - * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0xF0 to transition to END_FOUND, expect false * * Feed 0x0F to transition to START_FOUND, expect false * * Feed 0 to transition to IN_DATA, expect false * * Feed data from fcs_min_power.bin, expect false for every byte @@ -211,7 +211,7 @@ TEST(TEST_NAME, decode__fcs_min_power) { /* * Flight-Controller-Set-Point min power test: * * Initialize with message_id as 0 - * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0xF0 to transition to END_FOUND, expect false * * Feed 0x0F to transition to START_FOUND, expect false * * Feed 0 to transition to IN_DATA, expect false * * Feed data from fcs_min_power.bin, expect false for every byte @@ -249,7 +249,7 @@ TEST(TEST_NAME, decode__fcs_max_power) { /* * Flight-Controller-Set-Point min power test: * * Initialize with message_id as 0 - * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0xF0 to transition to END_FOUND, expect false * * Feed 0x0F to transition to START_FOUND, expect false * * Feed 0 to transition to IN_DATA, expect false * * Feed data from fcs_max_power.bin, expect false for every byte @@ -287,7 +287,7 @@ TEST(TEST_NAME, decode__fcs_min_pitch) { /* * Flight-Controller-Set-Point min power test: * * Initialize with message_id as 0 - * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0xF0 to transition to END_FOUND, expect false * * Feed 0x0F to transition to START_FOUND, expect false * * Feed 0 to transition to IN_DATA, expect false * * Feed data from fcs_min_pitch.bin, expect false for every byte @@ -325,7 +325,7 @@ TEST(TEST_NAME, decode__fcs_max_pitch) { /* * Flight-Controller-Set-Point min power test: * * Initialize with message_id as 0 - * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0xF0 to transition to END_FOUND, expect false * * Feed 0x0F to transition to START_FOUND, expect false * * Feed 0 to transition to IN_DATA, expect false * * Feed data from fcs_max_pitch.bin, expect false for every byte @@ -363,7 +363,7 @@ TEST(TEST_NAME, decode__fcs_min_roll) { /* * Flight-Controller-Set-Point min power test: * * Initialize with message_id as 0 - * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0xF0 to transition to END_FOUND, expect false * * Feed 0x0F to transition to START_FOUND, expect false * * Feed 0 to transition to IN_DATA, expect false * * Feed data from fcs_min_roll.bin, expect false for every byte @@ -401,7 +401,7 @@ TEST(TEST_NAME, decode__fcs_max_roll) { /* * Flight-Controller-Set-Point min power test: * * Initialize with message_id as 0 - * * Feed 0xF0 to transition to INITIAL_END_FOUND, expect false + * * Feed 0xF0 to transition to END_FOUND, expect false * * Feed 0x0F to transition to START_FOUND, expect false * * Feed 0 to transition to IN_DATA, expect false * * Feed data from fcs_max_roll.bin, expect false for every byte diff --git a/Tests/LowLevel/Messages/MessageEncoding.cpp b/Tests/LowLevel/Messages/MessageEncoding.cpp index 2bd78e8..1a76a67 100644 --- a/Tests/LowLevel/Messages/MessageEncoding.cpp +++ b/Tests/LowLevel/Messages/MessageEncoding.cpp @@ -1,3 +1,4 @@ +#include #include extern "C" { @@ -6,8 +7,15 @@ extern "C" { #include "FlightControllerSetpoint.pb.h" -TEST(TEST_NAME, encode) { - std::array buf; +TEST(TEST_NAME, encode__buffer_format) { + /* + * Encode message with all zero data and id 17, expect: + * * Returned length: 3 + * * First byte: 0x0F + * * Second byte: 17 + * * Third byte: 0xF0 + */ + std::array buf{}; ToolboxPlaneMessages_FlightControllerSetpoint data{.motor = 0, .pitch = 0, .roll = 0}; EXPECT_EQ(message_encode(buf.data(), buf.size(), ToolboxPlaneMessages_FlightControllerSetpoint_fields, &data, 17), 3); From 23d933da31b479c5486f0c9134e2f4a490c81059 Mon Sep 17 00:00:00 2001 From: Paul Nykiel Date: Wed, 1 Feb 2023 18:41:06 +0100 Subject: [PATCH 06/22] Started with encoding tests --- Tests/LowLevel/Messages/MessageEncoding.cpp | 63 +++++++++++++++++++-- Tests/LowLevel/Messages/generate_tests.sh | 27 +++++++++ 2 files changed, 85 insertions(+), 5 deletions(-) diff --git a/Tests/LowLevel/Messages/MessageEncoding.cpp b/Tests/LowLevel/Messages/MessageEncoding.cpp index 1a76a67..f8851d2 100644 --- a/Tests/LowLevel/Messages/MessageEncoding.cpp +++ b/Tests/LowLevel/Messages/MessageEncoding.cpp @@ -5,7 +5,7 @@ extern "C" { #include } -#include "FlightControllerSetpoint.pb.h" +#include "FlightController.pb.h" TEST(TEST_NAME, encode__buffer_format) { /* @@ -15,13 +15,66 @@ TEST(TEST_NAME, encode__buffer_format) { * * Second byte: 17 * * Third byte: 0xF0 */ - std::array buf{}; - ToolboxPlaneMessages_FlightControllerSetpoint data{.motor = 0, .pitch = 0, .roll = 0}; - EXPECT_EQ(message_encode(buf.data(), buf.size(), ToolboxPlaneMessages_FlightControllerSetpoint_fields, &data, 17), + std::array buf{}; + ToolboxPlaneMessages_FlightController data{}; + EXPECT_EQ(message_encode(buf.data(), buf.size(), ToolboxPlaneMessages_FlightController_fields, &data, 17), 3); EXPECT_EQ(buf[0], 0x0F); EXPECT_EQ(buf[1], 17); EXPECT_EQ(buf[2], 0xF0); } -// TODO actual message encoding, decoding tests +TEST(TEST_NAME, encode__fc_encode) { + /* + * Encode message with all zero data and id 17, expect: + * * Returned length: 3 + * * First byte: 0x0F + * * Second byte: 17 + * * Third byte: 0xF0 + */ + ToolboxPlaneMessages_FlightController data{ + .has_imu = true, + .imu = { + .imu_ok = true, + .roll_mul_16 = 17, + .pitch_mul_16 = -18, + .yaw_mul_16 = 19, + .dRoll_mul_16 = -20, + .dPitch_mul_16 = 21, + .dYaw_mul_16 = -22, + .accX_mul_100 = 23, + .accY_mul_100 = -24, + .accZ_mul_100 = 25 + }, + .has_remote = true, + .remote = { + .remote_ok = false, + .throttleMixed = -26, + .elevonLeftMixed = 27, + .elevonRightMixed = -28, + .isArmed = true, + .overrideActive = false, + }, + .motor = 29, + .servoLeft = 30, + .servoRight = 31 + }; + + std::ifstream stream{"fc_encode.bin"}; + using c_stream_it = std::istreambuf_iterator; + std::vector expectedData; + expectedData.emplace_back(0x0F); + expectedData.emplace_back(17); + for (auto it = c_stream_it{stream}; it != c_stream_it{}; ++it) { + expectedData.emplace_back(*it); + } + expectedData.emplace_back(0xF0); + + EXPECT_LT(expectedData.size(), ToolboxPlaneMessages_FlightController_size + 3); + std::array buf{}; + EXPECT_EQ(message_encode(buf.data(), buf.size(), ToolboxPlaneMessages_FlightController_fields, &data, 17), + expectedData.size()); + for (auto idx =0U; idx fcs_max_roll.bin + +echo "imu: { + imu_ok: true, + roll_mul_16: 17, + pitch_mul_16: -18 + yaw_mul_16: 19, + dRoll_mul_16: -20, + dPitch_mul_16: 21, + dYaw_mul_16: -22 + accX_mul_100: 23, + accY_mul_100: -24, + accZ_mul_100: 25 + }, + remote: { + remote_ok: false; + throttleMixed: -26; + elevonLeftMixed: 27; + elevonRightMixed: -28; + isArmed: true; + overrideActive: false; + }, + motor: 29, + servoLeft: 30, + servoRight: 31" | \ + protoc --encode=ToolboxPlaneMessages.FlightController \ + --proto_path "$1" \ + Src/Messages/Definitions/FlightController.proto > fc_encode.bin From 08bc525925a737c1c5d0001ed475226a55e682f4 Mon Sep 17 00:00:00 2001 From: Paul Nykiel Date: Mon, 6 Feb 2023 19:55:25 +0100 Subject: [PATCH 07/22] Updated messages --- .github/workflows/low_level_tests.yml | 36 ++++++++++++++++++++++++++- CMakeLists.txt | 2 +- Tests/LowLevel/CMakeLists.txt | 24 +++++++++--------- 3 files changed, 48 insertions(+), 14 deletions(-) diff --git a/.github/workflows/low_level_tests.yml b/.github/workflows/low_level_tests.yml index 368cacc..34575cc 100644 --- a/.github/workflows/low_level_tests.yml +++ b/.github/workflows/low_level_tests.yml @@ -32,6 +32,9 @@ jobs: 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-* + - name: Run NanoPB Tests + run: | + scons -f Src/Messages/External/nanopb/tests BUILDDIR=build/ - name: Set up Build run: cmake -B build -DCMAKE_BUILD_TYPE=${{ matrix.build }} - name: Build and run tests @@ -39,12 +42,43 @@ jobs: - uses: actions/upload-artifact@v3 with: name: RunResults - path: build/Tests/LowLevel + path: build/Tests/LowLevel, - uses: actions/upload-artifact@v3 with: name: ${{ matrix.compiler.cc }} path: build/Tests/LowLevel + NanoPB: + name: NanoPB Tests + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + compiler: [ { cc: gcc-10, cxx: g++-10 }, + { cc: gcc-11, cxx: g++-11 }, + { cc: clang-11, cxx: clang++-11 }, + { 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 } ] + build: [ Release, Debug ] + env: + CC: ${{ matrix.compiler.cc }} + CXX: ${{ matrix.compiler.cxx }} + steps: + - uses: actions/checkout@v2 + with: + submodules: recursive + - name: Install dependencies + run: | + # Taken from https://apt.llvm.org/ + wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - + 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 g++-9 g++-10 g++-11 protobuf-compiler valgrind python3-protobuf clang-* scons lcov + Report: runs-on: ubuntu-latest needs: Run-Tests diff --git a/CMakeLists.txt b/CMakeLists.txt index d5281b2..ba386d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,5 +20,5 @@ else () message(STATUS "Not building for AVR") endif () -add_subdirectory(Tests) add_subdirectory(Src) +add_subdirectory(Tests) diff --git a/Tests/LowLevel/CMakeLists.txt b/Tests/LowLevel/CMakeLists.txt index 0848ec2..8870788 100644 --- a/Tests/LowLevel/CMakeLists.txt +++ b/Tests/LowLevel/CMakeLists.txt @@ -1,4 +1,4 @@ -add_subdirectory(Mock) +#add_subdirectory(Mock) function(make_fc_test) cmake_parse_arguments(MAKE_FC_TEST "" # Options @@ -9,7 +9,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}) @@ -53,16 +53,16 @@ make_fc_test(MODULE HAL/timer8bit DEPS avr/io) make_fc_test(MODULE HAL/uart DEPS avr/io) -add_custom_target(generate_tests - COMMAND ${CMAKE_CURRENT_LIST_DIR}/Messages/generate_tests.sh ${CMAKE_SOURCE_DIR} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS ${CMAKE_CURRENT_LIST_DIR}/Messages/generate_tests.sh) -make_fc_test(MODULE Messages/MessageDecoding) -target_link_libraries(MessageDecoding.test PUBLIC ToolboxPlaneMessageDefs) -add_dependencies(MessageDecoding.test generate_tests) -make_fc_test(MODULE Messages/MessageEncoding) -target_link_libraries(MessageEncoding.test PUBLIC ToolboxPlaneMessageDefs) -add_dependencies(MessageEncoding.test generate_tests) +#add_custom_target(generate_tests +# COMMAND ${CMAKE_CURRENT_LIST_DIR}/Messages/generate_tests.sh ${CMAKE_SOURCE_DIR} +# WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} +# DEPENDS ${CMAKE_CURRENT_LIST_DIR}/Messages/generate_tests.sh) +#make_fc_test(MODULE Messages/MessageDecoding) +#target_link_libraries(MessageDecoding.test PUBLIC ToolboxPlaneMessageDefs) +#add_dependencies(MessageDecoding.test generate_tests) +#make_fc_test(MODULE Messages/MessageEncoding) +#target_link_libraries(MessageEncoding.test PUBLIC ToolboxPlaneMessageDefs) +#add_dependencies(MessageEncoding.test generate_tests) target_link_libraries(MessageEncoding.mock PUBLIC ToolboxPlaneMessageDefs) target_link_libraries(MessageDecoding.mock PUBLIC ToolboxPlaneMessageDefs) From c1c746b996ec1d554887050740634b59b54c7829 Mon Sep 17 00:00:00 2001 From: Paul Nykiel Date: Mon, 6 Feb 2023 20:00:34 +0100 Subject: [PATCH 08/22] Install scons --- .github/workflows/low_level_tests.yml | 33 +-------------------------- Src/Messages | 2 +- 2 files changed, 2 insertions(+), 33 deletions(-) diff --git a/.github/workflows/low_level_tests.yml b/.github/workflows/low_level_tests.yml index 34575cc..1e5dccb 100644 --- a/.github/workflows/low_level_tests.yml +++ b/.github/workflows/low_level_tests.yml @@ -31,7 +31,7 @@ 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: | scons -f Src/Messages/External/nanopb/tests BUILDDIR=build/ @@ -48,37 +48,6 @@ jobs: name: ${{ matrix.compiler.cc }} path: build/Tests/LowLevel - NanoPB: - name: NanoPB Tests - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - compiler: [ { cc: gcc-10, cxx: g++-10 }, - { cc: gcc-11, cxx: g++-11 }, - { cc: clang-11, cxx: clang++-11 }, - { 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 } ] - build: [ Release, Debug ] - env: - CC: ${{ matrix.compiler.cc }} - CXX: ${{ matrix.compiler.cxx }} - steps: - - uses: actions/checkout@v2 - with: - submodules: recursive - - name: Install dependencies - run: | - # Taken from https://apt.llvm.org/ - wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - - 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 g++-9 g++-10 g++-11 protobuf-compiler valgrind python3-protobuf clang-* scons lcov - Report: runs-on: ubuntu-latest needs: Run-Tests diff --git a/Src/Messages b/Src/Messages index 8e77636..43d3f11 160000 --- a/Src/Messages +++ b/Src/Messages @@ -1 +1 @@ -Subproject commit 8e77636813a1683f9723a3792f0636dfd1a38f0e +Subproject commit 43d3f11adff06637f1bc64a457230839ebe356a8 From b4a52706581d907a1a13c1351a06397612ab40b2 Mon Sep 17 00:00:00 2001 From: Paul Nykiel Date: Mon, 6 Feb 2023 20:04:07 +0100 Subject: [PATCH 09/22] Murks --- .github/workflows/low_level_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/low_level_tests.yml b/.github/workflows/low_level_tests.yml index 1e5dccb..cff1121 100644 --- a/.github/workflows/low_level_tests.yml +++ b/.github/workflows/low_level_tests.yml @@ -34,7 +34,7 @@ jobs: sudo apt-get install -y wget g++-9 g++-10 g++-11 protobuf-compiler valgrind python3-protobuf clang-* scons - name: Run NanoPB Tests run: | - scons -f Src/Messages/External/nanopb/tests BUILDDIR=build/ + scons -f Src/Messages/External/nanopb/tests/SConstruct BUILDDIR=build/ - name: Set up Build run: cmake -B build -DCMAKE_BUILD_TYPE=${{ matrix.build }} - name: Build and run tests From aec6d2ee935019ca536fe2b32fb00149f85398ac Mon Sep 17 00:00:00 2001 From: Paul Nykiel Date: Mon, 6 Feb 2023 20:16:05 +0100 Subject: [PATCH 10/22] Clang murks --- .github/workflows/low_level_tests.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/low_level_tests.yml b/.github/workflows/low_level_tests.yml index cff1121..4a17b63 100644 --- a/.github/workflows/low_level_tests.yml +++ b/.github/workflows/low_level_tests.yml @@ -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 }} From 8c171e70a45d3caaae0a71f35f70a5e39cd8efb9 Mon Sep 17 00:00:00 2001 From: Paul Nykiel Date: Mon, 6 Feb 2023 20:16:38 +0100 Subject: [PATCH 11/22] Murks --- .github/workflows/low_level_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/low_level_tests.yml b/.github/workflows/low_level_tests.yml index 4a17b63..5d8a470 100644 --- a/.github/workflows/low_level_tests.yml +++ b/.github/workflows/low_level_tests.yml @@ -43,7 +43,7 @@ jobs: - uses: actions/upload-artifact@v3 with: name: RunResults - path: build/Tests/LowLevel, + path: build/Tests/LowLevel - uses: actions/upload-artifact@v3 with: name: ${{ matrix.compiler.cc }} From e428968371bbf52508b83a45cc18b9a54a4a29fe Mon Sep 17 00:00:00 2001 From: Paul Nykiel Date: Wed, 8 Feb 2023 19:33:21 +0100 Subject: [PATCH 12/22] Maybe fixed coverage --- .github/workflows/low_level_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/low_level_tests.yml b/.github/workflows/low_level_tests.yml index 5d8a470..187363a 100644 --- a/.github/workflows/low_level_tests.yml +++ b/.github/workflows/low_level_tests.yml @@ -43,7 +43,7 @@ jobs: - uses: actions/upload-artifact@v3 with: name: RunResults - path: build/Tests/LowLevel + path: build - uses: actions/upload-artifact@v3 with: name: ${{ matrix.compiler.cc }} From 4788a660aeac3b7fc52c56b9f1f00f4ead136e5a Mon Sep 17 00:00:00 2001 From: Paul Nykiel Date: Wed, 8 Feb 2023 19:34:47 +0100 Subject: [PATCH 13/22] Removed clang-16 from matrix --- .github/workflows/low_level_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/low_level_tests.yml b/.github/workflows/low_level_tests.yml index 187363a..1cab177 100644 --- a/.github/workflows/low_level_tests.yml +++ b/.github/workflows/low_level_tests.yml @@ -15,7 +15,7 @@ jobs: { 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-16, cxx: clang++-16 }, { cc: clang-17, cxx: clang++-17 } ] build: [ Release, Debug ] env: From 7fe67eea7c809a2ed19881990964fe3fed6d8d9a Mon Sep 17 00:00:00 2001 From: Paul Nykiel Date: Wed, 8 Feb 2023 19:35:18 +0100 Subject: [PATCH 14/22] Updated messages --- Src/Messages | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Messages b/Src/Messages index 43d3f11..c5a465d 160000 --- a/Src/Messages +++ b/Src/Messages @@ -1 +1 @@ -Subproject commit 43d3f11adff06637f1bc64a457230839ebe356a8 +Subproject commit c5a465d003f5b47deb4de6c80af7191e1c75dbe0 From 68316600cd74c1e85c83c9cc3140a33c75394598 Mon Sep 17 00:00:00 2001 From: Paul Nykiel Date: Fri, 10 Feb 2023 20:05:26 +0100 Subject: [PATCH 15/22] Coverage murks --- .github/workflows/low_level_tests.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/low_level_tests.yml b/.github/workflows/low_level_tests.yml index 1cab177..bfd58b4 100644 --- a/.github/workflows/low_level_tests.yml +++ b/.github/workflows/low_level_tests.yml @@ -35,7 +35,9 @@ jobs: sudo apt-get install -y wget g++-9 g++-10 g++-11 protobuf-compiler valgrind python3-protobuf clang-* scons - name: Run NanoPB Tests run: | - scons -f Src/Messages/External/nanopb/tests/SConstruct BUILDDIR=build/ + cd Src/Messages/External/nanopb/tests/ + scons + cp -r build ../../../../.. - name: Set up Build run: cmake -B build -DCMAKE_BUILD_TYPE=${{ matrix.build }} - name: Build and run tests @@ -88,6 +90,7 @@ jobs: - uses: actions/download-artifact@v3 with: name: gcc-11 + - run: tree - name: Install dependencies run: | sudo apt-get update From c6d2e75fba6aadf5669a4894abaab87be22a2abe Mon Sep 17 00:00:00 2001 From: Paul Nykiel Date: Mon, 13 Feb 2023 16:29:31 +0100 Subject: [PATCH 16/22] Maybe fixed coverage --- .github/workflows/low_level_tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/low_level_tests.yml b/.github/workflows/low_level_tests.yml index bfd58b4..b45cba1 100644 --- a/.github/workflows/low_level_tests.yml +++ b/.github/workflows/low_level_tests.yml @@ -45,11 +45,11 @@ jobs: - uses: actions/upload-artifact@v3 with: name: RunResults - path: build + path: build/Tests/LowLevel - uses: actions/upload-artifact@v3 with: name: ${{ matrix.compiler.cc }} - path: build/Tests/LowLevel + path: build Report: runs-on: ubuntu-latest From 365ad7817f5b79e6c9c514f10f3d5e0c071503e0 Mon Sep 17 00:00:00 2001 From: Paul Nykiel Date: Mon, 13 Feb 2023 19:05:48 +0100 Subject: [PATCH 17/22] Murksi murksi murks --- .github/workflows/low_level_tests.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/low_level_tests.yml b/.github/workflows/low_level_tests.yml index b45cba1..a44c61d 100644 --- a/.github/workflows/low_level_tests.yml +++ b/.github/workflows/low_level_tests.yml @@ -37,7 +37,6 @@ jobs: run: | cd Src/Messages/External/nanopb/tests/ scons - cp -r build ../../../../.. - name: Set up Build run: cmake -B build -DCMAKE_BUILD_TYPE=${{ matrix.build }} - name: Build and run tests @@ -50,6 +49,10 @@ jobs: with: name: ${{ matrix.compiler.cc }} path: build + - uses: actions/upload-artifact@v3 + with: + name: nanopb_${{ matrix.compiler.cc }} + path: Src/Messages/External/nanopb/tests/build Report: runs-on: ubuntu-latest @@ -90,6 +93,9 @@ jobs: - uses: actions/download-artifact@v3 with: name: gcc-11 + - uses: actions/download-artifact@v3 + with: + name: nanopb_gcc-11 - run: tree - name: Install dependencies run: | From b125d92893e9dc38bab7a3a72b2ad2163c7e8c3d Mon Sep 17 00:00:00 2001 From: Paul Nykiel Date: Mon, 13 Feb 2023 19:48:09 +0100 Subject: [PATCH 18/22] Testing --- .github/workflows/low_level_tests.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/low_level_tests.yml b/.github/workflows/low_level_tests.yml index a44c61d..7dd7e3c 100644 --- a/.github/workflows/low_level_tests.yml +++ b/.github/workflows/low_level_tests.yml @@ -48,11 +48,7 @@ jobs: - uses: actions/upload-artifact@v3 with: name: ${{ matrix.compiler.cc }} - path: build - - uses: actions/upload-artifact@v3 - with: - name: nanopb_${{ matrix.compiler.cc }} - path: Src/Messages/External/nanopb/tests/build + path: . Report: runs-on: ubuntu-latest @@ -104,7 +100,9 @@ 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 --capture --directory build --output-file coverage.info + lcov --no-external --capture --directory Src/Messages/External/nanopb/tests/build --output-file coverage.info - name: Gen HTML run: genhtml coverage.info --output-directory coverage - name: Move HTML From 693277729730f8c54a11b4b51729a03e866110bb Mon Sep 17 00:00:00 2001 From: Paul Nykiel Date: Mon, 13 Feb 2023 20:15:27 +0100 Subject: [PATCH 19/22] Murks --- .github/workflows/low_level_tests.yml | 6 --- Src/Messages | 2 +- Tests/LowLevel/Messages/MessageEncoding.cpp | 56 ++++++++++----------- 3 files changed, 27 insertions(+), 37 deletions(-) diff --git a/.github/workflows/low_level_tests.yml b/.github/workflows/low_level_tests.yml index 7dd7e3c..02232e9 100644 --- a/.github/workflows/low_level_tests.yml +++ b/.github/workflows/low_level_tests.yml @@ -83,15 +83,9 @@ jobs: needs: Run-Tests if: ${{ always() }} steps: - - uses: actions/checkout@v2 - with: - submodules: recursive - uses: actions/download-artifact@v3 with: name: gcc-11 - - uses: actions/download-artifact@v3 - with: - name: nanopb_gcc-11 - run: tree - name: Install dependencies run: | diff --git a/Src/Messages b/Src/Messages index c5a465d..51c759a 160000 --- a/Src/Messages +++ b/Src/Messages @@ -1 +1 @@ -Subproject commit c5a465d003f5b47deb4de6c80af7191e1c75dbe0 +Subproject commit 51c759ad97cb421476c143822e712a2947b3f0b1 diff --git a/Tests/LowLevel/Messages/MessageEncoding.cpp b/Tests/LowLevel/Messages/MessageEncoding.cpp index f8851d2..e28fae4 100644 --- a/Tests/LowLevel/Messages/MessageEncoding.cpp +++ b/Tests/LowLevel/Messages/MessageEncoding.cpp @@ -17,8 +17,7 @@ TEST(TEST_NAME, encode__buffer_format) { */ std::array buf{}; ToolboxPlaneMessages_FlightController data{}; - EXPECT_EQ(message_encode(buf.data(), buf.size(), ToolboxPlaneMessages_FlightController_fields, &data, 17), - 3); + EXPECT_EQ(message_encode(buf.data(), buf.size(), ToolboxPlaneMessages_FlightController_fields, &data, 17), 3); EXPECT_EQ(buf[0], 0x0F); EXPECT_EQ(buf[1], 17); EXPECT_EQ(buf[2], 0xF0); @@ -32,33 +31,30 @@ TEST(TEST_NAME, encode__fc_encode) { * * Second byte: 17 * * Third byte: 0xF0 */ - ToolboxPlaneMessages_FlightController data{ - .has_imu = true, - .imu = { - .imu_ok = true, - .roll_mul_16 = 17, - .pitch_mul_16 = -18, - .yaw_mul_16 = 19, - .dRoll_mul_16 = -20, - .dPitch_mul_16 = 21, - .dYaw_mul_16 = -22, - .accX_mul_100 = 23, - .accY_mul_100 = -24, - .accZ_mul_100 = 25 - }, - .has_remote = true, - .remote = { - .remote_ok = false, - .throttleMixed = -26, - .elevonLeftMixed = 27, - .elevonRightMixed = -28, - .isArmed = true, - .overrideActive = false, - }, - .motor = 29, - .servoLeft = 30, - .servoRight = 31 - }; + ToolboxPlaneMessages_FlightController data{.has_imu = true, + .imu = {.imu_ok = true, + .roll_mul_16 = 17, + .pitch_mul_16 = -18, + .yaw_mul_16 = 19, + .dRoll_mul_16 = -20, + .dPitch_mul_16 = 21, + .dYaw_mul_16 = -22, + .accX_mul_100 = 23, + .accY_mul_100 = -24, + .accZ_mul_100 = 25}, + .has_remote = true, + .remote = + { + .remote_ok = false, + .throttleMixed = -26, + .elevonLeftMixed = 27, + .elevonRightMixed = -28, + .isArmed = true, + .overrideActive = false, + }, + .motor = 29, + .servoLeft = 30, + .servoRight = 31}; std::ifstream stream{"fc_encode.bin"}; using c_stream_it = std::istreambuf_iterator; @@ -74,7 +70,7 @@ TEST(TEST_NAME, encode__fc_encode) { std::array buf{}; EXPECT_EQ(message_encode(buf.data(), buf.size(), ToolboxPlaneMessages_FlightController_fields, &data, 17), expectedData.size()); - for (auto idx =0U; idx Date: Tue, 14 Feb 2023 20:47:45 +0100 Subject: [PATCH 20/22] Maybe fixed coverage --- .github/workflows/low_level_tests.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/low_level_tests.yml b/.github/workflows/low_level_tests.yml index 02232e9..507407f 100644 --- a/.github/workflows/low_level_tests.yml +++ b/.github/workflows/low_level_tests.yml @@ -95,8 +95,9 @@ jobs: run: cmake -B build - name: Run LCOV run: | - lcov --no-external --capture --directory build --output-file coverage.info - lcov --no-external --capture --directory Src/Messages/External/nanopb/tests/build --output-file coverage.info + lcov --no-external --capture --directory build -o local.info + lcov --no-external --capture --directory Src/Messages/External/nanopb/tests/build -o nanopb.info + lcov -a local.info -a nanopb.info -o coverage.info - name: Gen HTML run: genhtml coverage.info --output-directory coverage - name: Move HTML From c1b59203c7284d8fd5d2e46a9f561bacd405a481 Mon Sep 17 00:00:00 2001 From: Paul Nykiel Date: Fri, 17 Feb 2023 19:47:53 +0100 Subject: [PATCH 21/22] No nanopb coverage reports --- .github/workflows/low_level_tests.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/low_level_tests.yml b/.github/workflows/low_level_tests.yml index 507407f..ccf5678 100644 --- a/.github/workflows/low_level_tests.yml +++ b/.github/workflows/low_level_tests.yml @@ -96,8 +96,7 @@ jobs: - name: Run LCOV run: | lcov --no-external --capture --directory build -o local.info - lcov --no-external --capture --directory Src/Messages/External/nanopb/tests/build -o nanopb.info - lcov -a local.info -a nanopb.info -o coverage.info + lcov -a local.info -o coverage.info - name: Gen HTML run: genhtml coverage.info --output-directory coverage - name: Move HTML From 00910b4bacdbc2d33f82eafc77a58c337c3a8f85 Mon Sep 17 00:00:00 2001 From: Paul Nykiel Date: Mon, 20 Feb 2023 19:57:07 +0100 Subject: [PATCH 22/22] HAL and Messages structure update, removed files which were moved to submodules --- .gitmodules | 3 - Src/HAL | 2 +- Src/Messages | 2 +- Tests/LowLevel/CMakeLists.txt | 16 - Tests/LowLevel/HAL/pwm16bit.cpp | 0 Tests/LowLevel/HAL/timer8bit.cpp | 0 Tests/LowLevel/HAL/uart.cpp | 0 Tests/LowLevel/Messages/MessageDecoding.cpp | 436 -------------------- Tests/LowLevel/Messages/MessageEncoding.cpp | 76 ---- Tests/LowLevel/Messages/generate_tests.sh | 62 --- Tests/LowLevel/Mock | 1 - Tests/LowLevel/main.cpp | 9 - 12 files changed, 2 insertions(+), 605 deletions(-) delete mode 100644 Tests/LowLevel/HAL/pwm16bit.cpp delete mode 100644 Tests/LowLevel/HAL/timer8bit.cpp delete mode 100644 Tests/LowLevel/HAL/uart.cpp delete mode 100644 Tests/LowLevel/Messages/MessageDecoding.cpp delete mode 100644 Tests/LowLevel/Messages/MessageEncoding.cpp delete mode 100755 Tests/LowLevel/Messages/generate_tests.sh delete mode 160000 Tests/LowLevel/Mock delete mode 100644 Tests/LowLevel/main.cpp diff --git a/.gitmodules b/.gitmodules index 36c4ff6..239114a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/Src/HAL b/Src/HAL index 8472324..9c284fc 160000 --- a/Src/HAL +++ b/Src/HAL @@ -1 +1 @@ -Subproject commit 84723244ae261f433f541e668b2f5e838480307d +Subproject commit 9c284fc0a9b33f4f773e1f0cfefa3c1a3382e44b diff --git a/Src/Messages b/Src/Messages index 51c759a..dccfb61 160000 --- a/Src/Messages +++ b/Src/Messages @@ -1 +1 @@ -Subproject commit 51c759ad97cb421476c143822e712a2947b3f0b1 +Subproject commit dccfb61076df3b6fef8af663fc3033c050c1bec9 diff --git a/Tests/LowLevel/CMakeLists.txt b/Tests/LowLevel/CMakeLists.txt index 8870788..d473d1a 100644 --- a/Tests/LowLevel/CMakeLists.txt +++ b/Tests/LowLevel/CMakeLists.txt @@ -1,4 +1,3 @@ -#add_subdirectory(Mock) function(make_fc_test) cmake_parse_arguments(MAKE_FC_TEST "" # Options @@ -48,21 +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) - - -#add_custom_target(generate_tests -# COMMAND ${CMAKE_CURRENT_LIST_DIR}/Messages/generate_tests.sh ${CMAKE_SOURCE_DIR} -# WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} -# DEPENDS ${CMAKE_CURRENT_LIST_DIR}/Messages/generate_tests.sh) -#make_fc_test(MODULE Messages/MessageDecoding) -#target_link_libraries(MessageDecoding.test PUBLIC ToolboxPlaneMessageDefs) -#add_dependencies(MessageDecoding.test generate_tests) -#make_fc_test(MODULE Messages/MessageEncoding) -#target_link_libraries(MessageEncoding.test PUBLIC ToolboxPlaneMessageDefs) -#add_dependencies(MessageEncoding.test generate_tests) target_link_libraries(MessageEncoding.mock PUBLIC ToolboxPlaneMessageDefs) target_link_libraries(MessageDecoding.mock PUBLIC ToolboxPlaneMessageDefs) diff --git a/Tests/LowLevel/HAL/pwm16bit.cpp b/Tests/LowLevel/HAL/pwm16bit.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/Tests/LowLevel/HAL/timer8bit.cpp b/Tests/LowLevel/HAL/timer8bit.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/Tests/LowLevel/HAL/uart.cpp b/Tests/LowLevel/HAL/uart.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/Tests/LowLevel/Messages/MessageDecoding.cpp b/Tests/LowLevel/Messages/MessageDecoding.cpp deleted file mode 100644 index 1dd07b9..0000000 --- a/Tests/LowLevel/Messages/MessageDecoding.cpp +++ /dev/null @@ -1,436 +0,0 @@ -#include -#include - -extern "C" { -#include -} - -#include "FlightControllerSetpoint.pb.h" - -TEST(TEST_NAME, decode__nominal_decode) { - /* - * Nominal decode test. - * Test: - * * Initialize with message_id as 17 - * * Feed 0xF0 to transition to END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect false - * * Feed 17 to transition to IN_DATA, expect false - * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect true - */ - message_decoding_data_t decodingData; - message_decoding_init(&decodingData, 17, ToolboxPlaneMessages_FlightControllerSetpoint_fields); - - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 17, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - ToolboxPlaneMessages_FlightControllerSetpoint buf; - EXPECT_TRUE(message_decoding_decode(&decodingData, 0x0F, &buf)); -} - -TEST(TEST_NAME, decode__premature_end) { - /* - * Premature end test. - * Test: - * * Initialize with message_id as 17 - * * Feed 0xF0 to transition to END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect false - * * Feed 17 to transition to IN_DATA, expect false - * * Feed 0x08 to keep in IN_DATA, expect false - * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false - * * Feed 0x01 to transition to IN_DATA, expect false - * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect true - */ - message_decoding_data_t decodingData; - message_decoding_init(&decodingData, 17, ToolboxPlaneMessages_FlightControllerSetpoint_fields); - - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 17, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0x08, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0x01, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - ToolboxPlaneMessages_FlightControllerSetpoint buf; - EXPECT_TRUE(message_decoding_decode(&decodingData, 0x0F, &buf)); -} - -TEST(TEST_NAME, decode__wrong_data) { - /* - * Wrong data test. - * Test: - * * Initialize with message_id as 17 - * * Feed 0xF0 to transition to END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect false - * * Feed 18 to transition to INITIAL, expect false - * * Feed 0xF0 to transition to END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect false - * * Feed 17 to transition to IN_DATA, expect false - * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect true - */ - message_decoding_data_t decodingData; - message_decoding_init(&decodingData, 17, ToolboxPlaneMessages_FlightControllerSetpoint_fields); - - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 18, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 17, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - ToolboxPlaneMessages_FlightControllerSetpoint buf; - EXPECT_TRUE(message_decoding_decode(&decodingData, 0x0F, &buf)); -} - -TEST(TEST_NAME, decode__wrong_data_premature_end) { - /* - * Wrong Data Premature end test. - * Test: - * * Initialize with message_id as 17 - * * Feed 0xF0 to transition to END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect false - * * Feed 18 to transition to INITIAL, expect false - * * Feed 0x08 to keep in INITIAL, expect false - * * Feed 0xF0 to transition to END_FOUND, expect false - * * Feed 0x01 to transition to IN_DATA, expect false - * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect false - * * Feed 17 to transition to IN_DATA, expect false - * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect true - */ - message_decoding_data_t decodingData; - message_decoding_init(&decodingData, 17, ToolboxPlaneMessages_FlightControllerSetpoint_fields); - - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 18, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0x08, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0x01, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 17, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - ToolboxPlaneMessages_FlightControllerSetpoint buf; - EXPECT_TRUE(message_decoding_decode(&decodingData, 0x0F, &buf)); -} - -TEST(TEST_NAME, decode__multiple_init) { - /* - * Multiple init decode test. - * Test: - * * Initialize with message_id as 17 - * * Feed 0x00 to keep in initial - * * Feed 0xF0 to transition to END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect false - * * Feed 17 to transition to IN_DATA, expect false - * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect true - */ - message_decoding_data_t decodingData; - message_decoding_init(&decodingData, 17, ToolboxPlaneMessages_FlightControllerSetpoint_fields); - - EXPECT_FALSE(message_decoding_decode(&decodingData, 0x00, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 17, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - ToolboxPlaneMessages_FlightControllerSetpoint buf; - EXPECT_TRUE(message_decoding_decode(&decodingData, 0x0F, &buf)); -} - -TEST(TEST_NAME, decode__init_wrong_end) { - /* - * Init wrong end test. - * Test: - * * Initialize with message_id as 17 - * * Feed 0xF0 to transition to END_FOUND, expect false - * * Feed 0x00 to transition to INITIAL, expect false - * * Feed 0xF0 to transition to END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect false - * * Feed 17 to transition to IN_DATA, expect false - * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect true - */ - message_decoding_data_t decodingData; - message_decoding_init(&decodingData, 17, ToolboxPlaneMessages_FlightControllerSetpoint_fields); - - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0x00, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 17, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - ToolboxPlaneMessages_FlightControllerSetpoint buf; - EXPECT_TRUE(message_decoding_decode(&decodingData, 0x0F, &buf)); -} - -TEST(TEST_NAME, decode__fcs_decode) { - /* - * Flight-Controller-Set-Point min power test: - * * Initialize with message_id as 0 - * * Feed 0xF0 to transition to END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect false - * * Feed 0 to transition to IN_DATA, expect false - * * Feed data from fcs_min_power.bin, expect false for every byte - * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect true - * * Check return message, expect: - * * motor: -2147483648 - * * pitch: 0 - * * roll: 0 - */ - message_decoding_data_t decodingData; - message_decoding_init(&decodingData, 0, ToolboxPlaneMessages_FlightControllerSetpoint_fields); - - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0, nullptr)); - - std::ifstream stream{"fcs_decode.bin"}; - using c_stream_it = std::istreambuf_iterator; - - for (auto it = c_stream_it{stream}; it != c_stream_it{}; ++it) { - EXPECT_FALSE(message_decoding_decode(&decodingData, *it, nullptr)); - } - - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - ToolboxPlaneMessages_FlightControllerSetpoint buf; - EXPECT_TRUE(message_decoding_decode(&decodingData, 0x0F, &buf)); - - EXPECT_EQ(buf.motor, 17); - EXPECT_EQ(buf.pitch, -18); - EXPECT_EQ(buf.roll, 19); -} - -TEST(TEST_NAME, decode__fcs_min_power) { - /* - * Flight-Controller-Set-Point min power test: - * * Initialize with message_id as 0 - * * Feed 0xF0 to transition to END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect false - * * Feed 0 to transition to IN_DATA, expect false - * * Feed data from fcs_min_power.bin, expect false for every byte - * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect true - * * Check return message, expect: - * * motor: -2147483648 - * * pitch: 0 - * * roll: 0 - */ - message_decoding_data_t decodingData; - message_decoding_init(&decodingData, 0, ToolboxPlaneMessages_FlightControllerSetpoint_fields); - - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0, nullptr)); - - std::ifstream stream{"fcs_min_power.bin"}; - using c_stream_it = std::istreambuf_iterator; - - for (auto it = c_stream_it{stream}; it != c_stream_it{}; ++it) { - EXPECT_FALSE(message_decoding_decode(&decodingData, *it, nullptr)); - } - - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - ToolboxPlaneMessages_FlightControllerSetpoint buf; - EXPECT_TRUE(message_decoding_decode(&decodingData, 0x0F, &buf)); - - EXPECT_EQ(buf.motor, -2147483648); - EXPECT_EQ(buf.pitch, 0); - EXPECT_EQ(buf.roll, 0); -} - -TEST(TEST_NAME, decode__fcs_max_power) { - /* - * Flight-Controller-Set-Point min power test: - * * Initialize with message_id as 0 - * * Feed 0xF0 to transition to END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect false - * * Feed 0 to transition to IN_DATA, expect false - * * Feed data from fcs_max_power.bin, expect false for every byte - * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect true - * * Check return message, expect: - * * motor: 2147483647 - * * pitch: 0 - * * roll: 0 - */ - message_decoding_data_t decodingData; - message_decoding_init(&decodingData, 0, ToolboxPlaneMessages_FlightControllerSetpoint_fields); - - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0, nullptr)); - - std::ifstream stream{"fcs_max_power.bin"}; - using c_stream_it = std::istreambuf_iterator; - - for (auto it = c_stream_it{stream}; it != c_stream_it{}; ++it) { - EXPECT_FALSE(message_decoding_decode(&decodingData, *it, nullptr)); - } - - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - ToolboxPlaneMessages_FlightControllerSetpoint buf; - EXPECT_TRUE(message_decoding_decode(&decodingData, 0x0F, &buf)); - - EXPECT_EQ(buf.motor, 2147483647); - EXPECT_EQ(buf.pitch, 0); - EXPECT_EQ(buf.roll, 0); -} - -TEST(TEST_NAME, decode__fcs_min_pitch) { - /* - * Flight-Controller-Set-Point min power test: - * * Initialize with message_id as 0 - * * Feed 0xF0 to transition to END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect false - * * Feed 0 to transition to IN_DATA, expect false - * * Feed data from fcs_min_pitch.bin, expect false for every byte - * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect true - * * Check return message, expect: - * * motor: 0 - * * pitch: -2147483648 - * * roll: 0 - */ - message_decoding_data_t decodingData; - message_decoding_init(&decodingData, 0, ToolboxPlaneMessages_FlightControllerSetpoint_fields); - - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0, nullptr)); - - std::ifstream stream{"fcs_min_pitch.bin"}; - using c_stream_it = std::istreambuf_iterator; - - for (auto it = c_stream_it{stream}; it != c_stream_it{}; ++it) { - EXPECT_FALSE(message_decoding_decode(&decodingData, *it, nullptr)); - } - - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - ToolboxPlaneMessages_FlightControllerSetpoint buf; - EXPECT_TRUE(message_decoding_decode(&decodingData, 0x0F, &buf)); - - EXPECT_EQ(buf.motor, 0); - EXPECT_EQ(buf.pitch, -2147483648); - EXPECT_EQ(buf.roll, 0); -} - -TEST(TEST_NAME, decode__fcs_max_pitch) { - /* - * Flight-Controller-Set-Point min power test: - * * Initialize with message_id as 0 - * * Feed 0xF0 to transition to END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect false - * * Feed 0 to transition to IN_DATA, expect false - * * Feed data from fcs_max_pitch.bin, expect false for every byte - * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect true - * * Check return message, expect: - * * motor: 0 - * * pitch: 2147483647 - * * roll: 0 - */ - message_decoding_data_t decodingData; - message_decoding_init(&decodingData, 0, ToolboxPlaneMessages_FlightControllerSetpoint_fields); - - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0, nullptr)); - - std::ifstream stream{"fcs_max_pitch.bin"}; - using c_stream_it = std::istreambuf_iterator; - - for (auto it = c_stream_it{stream}; it != c_stream_it{}; ++it) { - EXPECT_FALSE(message_decoding_decode(&decodingData, *it, nullptr)); - } - - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - ToolboxPlaneMessages_FlightControllerSetpoint buf; - EXPECT_TRUE(message_decoding_decode(&decodingData, 0x0F, &buf)); - - EXPECT_EQ(buf.motor, 0); - EXPECT_EQ(buf.pitch, 2147483647); - EXPECT_EQ(buf.roll, 0); -} - -TEST(TEST_NAME, decode__fcs_min_roll) { - /* - * Flight-Controller-Set-Point min power test: - * * Initialize with message_id as 0 - * * Feed 0xF0 to transition to END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect false - * * Feed 0 to transition to IN_DATA, expect false - * * Feed data from fcs_min_roll.bin, expect false for every byte - * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect true - * * Check return message, expect: - * * motor: 0 - * * pitch: 0 - * * roll: -2147483648 - */ - message_decoding_data_t decodingData; - message_decoding_init(&decodingData, 0, ToolboxPlaneMessages_FlightControllerSetpoint_fields); - - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0, nullptr)); - - std::ifstream stream{"fcs_min_roll.bin"}; - using c_stream_it = std::istreambuf_iterator; - - for (auto it = c_stream_it{stream}; it != c_stream_it{}; ++it) { - EXPECT_FALSE(message_decoding_decode(&decodingData, *it, nullptr)); - } - - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - ToolboxPlaneMessages_FlightControllerSetpoint buf; - EXPECT_TRUE(message_decoding_decode(&decodingData, 0x0F, &buf)); - - EXPECT_EQ(buf.motor, 0); - EXPECT_EQ(buf.pitch, 0); - EXPECT_EQ(buf.roll, -2147483648); -} - -TEST(TEST_NAME, decode__fcs_max_roll) { - /* - * Flight-Controller-Set-Point min power test: - * * Initialize with message_id as 0 - * * Feed 0xF0 to transition to END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect false - * * Feed 0 to transition to IN_DATA, expect false - * * Feed data from fcs_max_roll.bin, expect false for every byte - * * Feed 0xF0 to transition to IN_DATA_END_FOUND, expect false - * * Feed 0x0F to transition to START_FOUND, expect true - * * Check return message, expect: - * * motor: 0 - * * pitch: 0 - * * roll: 2147483647 - */ - message_decoding_data_t decodingData; - message_decoding_init(&decodingData, 0, ToolboxPlaneMessages_FlightControllerSetpoint_fields); - - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0x0F, nullptr)); - EXPECT_FALSE(message_decoding_decode(&decodingData, 0, nullptr)); - - std::ifstream stream{"fcs_max_roll.bin"}; - using c_stream_it = std::istreambuf_iterator; - - for (auto it = c_stream_it{stream}; it != c_stream_it{}; ++it) { - EXPECT_FALSE(message_decoding_decode(&decodingData, *it, nullptr)); - } - - EXPECT_FALSE(message_decoding_decode(&decodingData, 0xF0, nullptr)); - ToolboxPlaneMessages_FlightControllerSetpoint buf; - EXPECT_TRUE(message_decoding_decode(&decodingData, 0x0F, &buf)); - - EXPECT_EQ(buf.motor, 0); - EXPECT_EQ(buf.pitch, 0); - EXPECT_EQ(buf.roll, 2147483647); -} diff --git a/Tests/LowLevel/Messages/MessageEncoding.cpp b/Tests/LowLevel/Messages/MessageEncoding.cpp deleted file mode 100644 index e28fae4..0000000 --- a/Tests/LowLevel/Messages/MessageEncoding.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include -#include - -extern "C" { -#include -} - -#include "FlightController.pb.h" - -TEST(TEST_NAME, encode__buffer_format) { - /* - * Encode message with all zero data and id 17, expect: - * * Returned length: 3 - * * First byte: 0x0F - * * Second byte: 17 - * * Third byte: 0xF0 - */ - std::array buf{}; - ToolboxPlaneMessages_FlightController data{}; - EXPECT_EQ(message_encode(buf.data(), buf.size(), ToolboxPlaneMessages_FlightController_fields, &data, 17), 3); - EXPECT_EQ(buf[0], 0x0F); - EXPECT_EQ(buf[1], 17); - EXPECT_EQ(buf[2], 0xF0); -} - -TEST(TEST_NAME, encode__fc_encode) { - /* - * Encode message with all zero data and id 17, expect: - * * Returned length: 3 - * * First byte: 0x0F - * * Second byte: 17 - * * Third byte: 0xF0 - */ - ToolboxPlaneMessages_FlightController data{.has_imu = true, - .imu = {.imu_ok = true, - .roll_mul_16 = 17, - .pitch_mul_16 = -18, - .yaw_mul_16 = 19, - .dRoll_mul_16 = -20, - .dPitch_mul_16 = 21, - .dYaw_mul_16 = -22, - .accX_mul_100 = 23, - .accY_mul_100 = -24, - .accZ_mul_100 = 25}, - .has_remote = true, - .remote = - { - .remote_ok = false, - .throttleMixed = -26, - .elevonLeftMixed = 27, - .elevonRightMixed = -28, - .isArmed = true, - .overrideActive = false, - }, - .motor = 29, - .servoLeft = 30, - .servoRight = 31}; - - std::ifstream stream{"fc_encode.bin"}; - using c_stream_it = std::istreambuf_iterator; - std::vector expectedData; - expectedData.emplace_back(0x0F); - expectedData.emplace_back(17); - for (auto it = c_stream_it{stream}; it != c_stream_it{}; ++it) { - expectedData.emplace_back(*it); - } - expectedData.emplace_back(0xF0); - - EXPECT_LT(expectedData.size(), ToolboxPlaneMessages_FlightController_size + 3); - std::array buf{}; - EXPECT_EQ(message_encode(buf.data(), buf.size(), ToolboxPlaneMessages_FlightController_fields, &data, 17), - expectedData.size()); - for (auto idx = 0U; idx < expectedData.size(); ++idx) { - EXPECT_EQ(buf[idx], expectedData[idx]); - } -} diff --git a/Tests/LowLevel/Messages/generate_tests.sh b/Tests/LowLevel/Messages/generate_tests.sh deleted file mode 100755 index 75f6952..0000000 --- a/Tests/LowLevel/Messages/generate_tests.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env bash -echo "motor: 17, pitch: -18, roll: 19" | \ - protoc --encode=ToolboxPlaneMessages.FlightControllerSetpoint \ - --proto_path "$1" \ - Src/Messages/Definitions/FlightControllerSetpoint.proto > fcs_decode.bin - -echo "motor: -2147483648, pitch: 0, roll: 0" | \ - protoc --encode=ToolboxPlaneMessages.FlightControllerSetpoint \ - --proto_path "$1" \ - Src/Messages/Definitions/FlightControllerSetpoint.proto > fcs_min_power.bin - -echo "motor: 2147483647, pitch: 0, roll: 0" | \ - protoc --encode=ToolboxPlaneMessages.FlightControllerSetpoint \ - --proto_path "$1" \ - Src/Messages/Definitions/FlightControllerSetpoint.proto > fcs_max_power.bin - -echo "motor: 0, pitch: -2147483648, roll: 0" | \ - protoc --encode=ToolboxPlaneMessages.FlightControllerSetpoint \ - --proto_path "$1" \ - Src/Messages/Definitions/FlightControllerSetpoint.proto > fcs_min_pitch.bin - -echo "motor: 0, pitch: 2147483647, roll: 0" | \ - protoc --encode=ToolboxPlaneMessages.FlightControllerSetpoint \ - --proto_path "$1" \ - Src/Messages/Definitions/FlightControllerSetpoint.proto > fcs_max_pitch.bin - -echo "motor: 0, pitch: 0, roll: -2147483648" | \ - protoc --encode=ToolboxPlaneMessages.FlightControllerSetpoint \ - --proto_path "$1" \ - Src/Messages/Definitions/FlightControllerSetpoint.proto > fcs_min_roll.bin - -echo "motor: 0, pitch: 0, roll: 2147483647" | \ - protoc --encode=ToolboxPlaneMessages.FlightControllerSetpoint \ - --proto_path "$1" \ - Src/Messages/Definitions/FlightControllerSetpoint.proto > fcs_max_roll.bin - -echo "imu: { - imu_ok: true, - roll_mul_16: 17, - pitch_mul_16: -18 - yaw_mul_16: 19, - dRoll_mul_16: -20, - dPitch_mul_16: 21, - dYaw_mul_16: -22 - accX_mul_100: 23, - accY_mul_100: -24, - accZ_mul_100: 25 - }, - remote: { - remote_ok: false; - throttleMixed: -26; - elevonLeftMixed: 27; - elevonRightMixed: -28; - isArmed: true; - overrideActive: false; - }, - motor: 29, - servoLeft: 30, - servoRight: 31" | \ - protoc --encode=ToolboxPlaneMessages.FlightController \ - --proto_path "$1" \ - Src/Messages/Definitions/FlightController.proto > fc_encode.bin diff --git a/Tests/LowLevel/Mock b/Tests/LowLevel/Mock deleted file mode 160000 index 0351958..0000000 --- a/Tests/LowLevel/Mock +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 035195821dbaf42353318c11e041f6739d6bed09 diff --git a/Tests/LowLevel/main.cpp b/Tests/LowLevel/main.cpp deleted file mode 100644 index 7c6d6df..0000000 --- a/Tests/LowLevel/main.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -int main(int argc, char **argv) { - feenableexcept(FE_INVALID | FE_OVERFLOW | FE_DIVBYZERO); // Floating point exceptions - - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -}