mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-17 05:15:25 +03:00
Improve unittest build system (#13554)
* unittest - fix duplicate symbols in unittests Some symbols were declared again With clang -fcommon, this resulted in allocatin in common segment and prevented error. (tentative definitions in C standard). -fno-common (now default in clang https://reviews.llvm.org/D75056) causes compilation errors. Declarations are now marked extern. * unittest - fix scheduler array size for unittest Unittest needs extra space for canary * unittest - fix missing include (needed for clang-16) * unittest - remove unused varibles -Werror in clang 15+ * unittest - increase max supported version to clang-16 * unittest - conditionaly disable useless output in unittests * unittest - C++11 version of STATIC_ASSERT * unittest - fix initializers for g++ - Change order of initializers to match order in struct - make valueTable initializion consistent (necessary for C++) - adapt controlRateConfig * unittest - adapt scheduler_unitest for g++ scheduler_stubs.c is necessary to initialize task_attributes * unittest - fix ledstrip unittest only part of config was zeroed * unittest - fix g++ warnings - memcpy when length is known and \0 is not copied - isError is local stub, no extern - serialReadStub - don't memcpy into object, use initializer * cli - cleanup cliGetSettingIndex - compare only passed bytes (old version may read data after name) - input string is const * unittest - fix ld warning from PG sections move pg data sections after .rodata. Sections were marked as writable due to relocation (!?). That marked .text output section (containing .pg_data) as writable too and linker correctly complained that executable section is writable. * unittest - cleanup * unittest - adapt after code cleanup, add gcc - remove clang flags that are not necessary now (tested on clang-11 and clang-16) - add support for gcc ( make test CC=gcc CXX=g++ ) - add suport for different optimization level (detects some code problems) : make test OPTIMIZE=-O2 - fallback to clang on Linux too * fixup! unittest - conditionaly disable useless output in unittests
This commit is contained in:
parent
d20d42dd48
commit
d447d795f4
17 changed files with 247 additions and 179 deletions
|
@ -64,9 +64,9 @@ extern "C" {
|
|||
void *cliGetValuePointer(const clivalue_t *value);
|
||||
|
||||
const clivalue_t valueTable[] = {
|
||||
{ "array_unit_test", VAR_INT8 | MODE_ARRAY | MASTER_VALUE, .config.array.length = 3, PG_RESERVED_FOR_TESTING_1, 0 },
|
||||
{ "str_unit_test", VAR_UINT8 | MODE_STRING | MASTER_VALUE, .config.string = { 0, 16, 0 }, PG_RESERVED_FOR_TESTING_1, 0 },
|
||||
{ "wos_unit_test", VAR_UINT8 | MODE_STRING | MASTER_VALUE, .config.string = { 0, 16, STRING_FLAGS_WRITEONCE }, PG_RESERVED_FOR_TESTING_1, 0 },
|
||||
{ .name = "array_unit_test", .type = VAR_INT8 | MODE_ARRAY | MASTER_VALUE, .config = { .array = { .length = 3}}, .pgn = PG_RESERVED_FOR_TESTING_1, .offset = 0 },
|
||||
{ .name = "str_unit_test", .type = VAR_UINT8 | MODE_STRING | MASTER_VALUE, .config = { .string = { 0, 16, 0 }}, .pgn = PG_RESERVED_FOR_TESTING_1, .offset = 0 },
|
||||
{ .name = "wos_unit_test", .type = VAR_UINT8 | MODE_STRING | MASTER_VALUE, .config = { .string = { 0, 16, STRING_FLAGS_WRITEONCE }}, .pgn = PG_RESERVED_FOR_TESTING_1, .offset = 0 },
|
||||
};
|
||||
const uint16_t valueTableEntryCount = ARRAYLEN(valueTable);
|
||||
const lookupTableEntry_t lookupTables[] = {};
|
||||
|
@ -103,6 +103,8 @@ extern "C" {
|
|||
#include "unittest_macros.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
const bool PRINT_TEST_DATA = false;
|
||||
|
||||
TEST(CLIUnittest, TestCliSetArray)
|
||||
{
|
||||
char *str = (char *)"array_unit_test = 123, -3 , 1";
|
||||
|
@ -112,14 +114,15 @@ TEST(CLIUnittest, TestCliSetArray)
|
|||
EXPECT_LT(index, valueTableEntryCount);
|
||||
|
||||
const clivalue_t val = valueTable[index];
|
||||
|
||||
printf("\n===============================\n");
|
||||
int8_t *data = (int8_t *)cliGetValuePointer(&val);
|
||||
for(int i=0; i < val.config.array.length; i++){
|
||||
printf("data[%d] = %d\n", i, data[i]);
|
||||
}
|
||||
printf("\n===============================\n");
|
||||
|
||||
if (PRINT_TEST_DATA) {
|
||||
printf("\n===============================\n");
|
||||
for(int i = 0; i < val.config.array.length; i++){
|
||||
printf("data[%d] = %d\n", i, data[i]);
|
||||
}
|
||||
printf("\n===============================\n");
|
||||
}
|
||||
|
||||
EXPECT_EQ(123, data[0]);
|
||||
EXPECT_EQ( -3, data[1]);
|
||||
|
@ -135,14 +138,15 @@ TEST(CLIUnittest, TestCliSetStringNoFlags)
|
|||
EXPECT_LT(index, valueTableEntryCount);
|
||||
|
||||
const clivalue_t val = valueTable[index];
|
||||
|
||||
printf("\n===============================\n");
|
||||
uint8_t *data = (uint8_t *)cliGetValuePointer(&val);
|
||||
for(int i = 0; i < val.config.string.maxlength && data[i] != 0; i++){
|
||||
printf("data[%d] = %d (%c)\n", i, data[i], data[i]);
|
||||
}
|
||||
printf("\n===============================\n");
|
||||
|
||||
if (PRINT_TEST_DATA) {
|
||||
printf("\n===============================\n");
|
||||
for(int i = 0; i < val.config.string.maxlength && data[i] != 0; i++){
|
||||
printf("data[%d] = %d (%c)\n", i, data[i], data[i]);
|
||||
}
|
||||
printf("\n===============================\n");
|
||||
}
|
||||
|
||||
EXPECT_EQ('S', data[0]);
|
||||
EXPECT_EQ('A', data[1]);
|
||||
|
@ -164,13 +168,14 @@ TEST(CLIUnittest, TestCliSetStringWriteOnce)
|
|||
|
||||
const clivalue_t val = valueTable[index];
|
||||
|
||||
printf("\n===============================\n");
|
||||
uint8_t *data = (uint8_t *)cliGetValuePointer(&val);
|
||||
for(int i = 0; i < val.config.string.maxlength && data[i] != 0; i++){
|
||||
printf("data[%d] = %d (%c)\n", i, data[i], data[i]);
|
||||
if (PRINT_TEST_DATA) {
|
||||
printf("\n===============================\n");
|
||||
for(int i = 0; i < val.config.string.maxlength && data[i] != 0; i++){
|
||||
printf("data[%d] = %d (%c)\n", i, data[i], data[i]);
|
||||
}
|
||||
printf("\n===============================\n");
|
||||
}
|
||||
printf("\n===============================\n");
|
||||
|
||||
EXPECT_EQ('S', data[0]);
|
||||
EXPECT_EQ('A', data[1]);
|
||||
EXPECT_EQ('M', data[2]);
|
||||
|
@ -198,8 +203,6 @@ TEST(CLIUnittest, TestCliSetStringWriteOnce)
|
|||
EXPECT_EQ('L', data[4]);
|
||||
EXPECT_EQ('E', data[5]);
|
||||
EXPECT_EQ(0, data[6]);
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
// STUBS
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue