[FL-2601] Move Infrared unit test data to assets (#1396)

* Move samsung raw data to assets
* Add more assets and fix bugs
* Clean up code
* Implement all raw data as assets
* Remove input data from old test files
* Better signal names
* Better file opening logic
* Implement loading parsed data from files
* Move most of RC5 tests into assets
* Add more test cases
* Add more test cases
* Eliminate RUN_DECODER macro
* Better code structure
* Implement run_encoder function
* More encoder tests
* Move all encoder tests to assets
* Move all test data to assets
* Normalise function names
* Rename code files
* Uncomment other tests
* Swich test order to avoid weird memory leaks
* UnitTests: cleanup output and redirect it into stdout
* UnitTests: selectable tests and better reporting

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
Georgii Surkov
2022-07-17 12:21:56 +03:00
committed by GitHub
parent 877c5c8122
commit 80629de01e
23 changed files with 4385 additions and 2019 deletions

View File

@@ -10,8 +10,8 @@
#define TAG "UnitTests"
int run_minunit();
int run_minunit_test_infrared_decoder_encoder();
int run_minunit_test_furi();
int run_minunit_test_infrared();
int run_minunit_test_rpc();
int run_minunit_test_flipper_format();
int run_minunit_test_flipper_format_string();
@@ -21,14 +21,35 @@ int run_minunit_test_subghz();
int run_minunit_test_dirwalk();
int run_minunit_test_nfc();
void minunit_print_progress(void) {
static char progress[] = {'\\', '|', '/', '-'};
typedef int (*UnitTestEntry)();
typedef struct {
const char* name;
const UnitTestEntry entry;
} UnitTest;
const UnitTest unit_tests[] = {
{.name = "furi", .entry = run_minunit_test_furi},
{.name = "storage", .entry = run_minunit_test_storage},
{.name = "stream", .entry = run_minunit_test_stream},
{.name = "dirwalk", .entry = run_minunit_test_dirwalk},
{.name = "flipper_format", .entry = run_minunit_test_flipper_format},
{.name = "flipper_format_string", .entry = run_minunit_test_flipper_format_string},
{.name = "rpc", .entry = run_minunit_test_rpc},
{.name = "subghz", .entry = run_minunit_test_subghz},
{.name = "infrared", .entry = run_minunit_test_infrared},
{.name = "nfc", .entry = run_minunit_test_nfc},
};
void minunit_print_progress() {
static const char progress[] = {'\\', '|', '/', '-'};
static uint8_t progress_counter = 0;
static TickType_t last_tick = 0;
TickType_t current_tick = xTaskGetTickCount();
if(current_tick - last_tick > 20) {
last_tick = current_tick;
printf("[%c]\033[3D", progress[++progress_counter % COUNT_OF(progress)]);
fflush(stdout);
}
}
@@ -40,7 +61,7 @@ void unit_tests_cli(Cli* cli, string_t args, void* context) {
UNUSED(cli);
UNUSED(args);
UNUSED(context);
uint32_t test_result = 0;
uint32_t failed_tests = 0;
minunit_run = 0;
minunit_assert = 0;
minunit_fail = 0;
@@ -51,7 +72,7 @@ void unit_tests_cli(Cli* cli, string_t args, void* context) {
// TODO: lock device while test running
if(loader_is_locked(loader)) {
FURI_LOG_E(TAG, "RPC: stop all applications to run tests");
printf("RPC: stop all applications to run tests\r\n");
notification_message(notification, &sequence_blink_magenta_100);
} else {
notification_message_block(notification, &sequence_set_only_blue_255);
@@ -59,34 +80,39 @@ void unit_tests_cli(Cli* cli, string_t args, void* context) {
uint32_t heap_before = memmgr_get_free_heap();
uint32_t cycle_counter = furi_hal_get_tick();
test_result |= run_minunit();
test_result |= run_minunit_test_storage();
test_result |= run_minunit_test_stream();
test_result |= run_minunit_test_dirwalk();
test_result |= run_minunit_test_flipper_format();
test_result |= run_minunit_test_flipper_format_string();
test_result |= run_minunit_test_infrared_decoder_encoder();
test_result |= run_minunit_test_rpc();
test_result |= run_minunit_test_subghz();
test_result |= run_minunit_test_nfc();
cycle_counter = (furi_hal_get_tick() - cycle_counter);
FURI_LOG_I(TAG, "Consumed: %u us", cycle_counter);
if(test_result == 0) {
furi_hal_delay_ms(200); /* wait for tested services and apps to deallocate */
uint32_t heap_after = memmgr_get_free_heap();
notification_message(notification, &sequence_success);
if(heap_after != heap_before) {
FURI_LOG_E(TAG, "Leaked: %d", heap_before - heap_after);
} else {
FURI_LOG_I(TAG, "No leaks");
for(size_t i = 0; i < COUNT_OF(unit_tests); i++) {
if(cli_cmd_interrupt_received(cli)) {
break;
}
FURI_LOG_I(TAG, "PASSED");
if(string_size(args)) {
if(string_cmp_str(args, unit_tests[i].name) == 0) {
failed_tests += unit_tests[i].entry();
} else {
printf("Skipping %s\r\n", unit_tests[i].name);
}
} else {
failed_tests += unit_tests[i].entry();
}
}
printf("\r\nFailed tests: %lu\r\n", failed_tests);
// Time report
cycle_counter = (furi_hal_get_tick() - cycle_counter);
printf("Consumed: %lu ms\r\n", cycle_counter);
// Wait for tested services and apps to deallocate memory
furi_hal_delay_ms(200);
uint32_t heap_after = memmgr_get_free_heap();
printf("Leaked: %ld\r\n", heap_before - heap_after);
// Final Report
if(failed_tests == 0) {
notification_message(notification, &sequence_success);
printf("Status: PASSED\r\n");
} else {
notification_message(notification, &sequence_error);
FURI_LOG_E(TAG, "FAILED");
printf("Status: FAILED\r\n");
}
}