1
mirror of https://github.com/DarkFlippers/unleashed-firmware.git synced 2025-12-12 12:42:30 +04:00

[FL-3664] 64k does not enough (#3216)

* Unit tests: add "exists" to furi_record tests
* Unit tests: mu_warn, storage 64k test
* Storage: read/write over 64k
* Unit tests: moar tests for storage r/w for >64k cases
* Apps, libs: replace uint16_t with size_t on storage r/w operations
* Unit tests: better data pattern, subghz: warning if transmission is prohibited

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
Sergey Gavrilov
2023-11-15 19:39:27 +03:00
committed by GitHub
parent 98d5718ec9
commit 4b3e8aba29
25 changed files with 188 additions and 81 deletions

View File

@@ -3,18 +3,29 @@
#include <furi.h>
#include "../minunit.h"
void test_furi_create_open() {
// 1. Create record
uint8_t test_data = 0;
furi_record_create("test/holding", (void*)&test_data);
#define TEST_RECORD_NAME "test/holding"
// 2. Open it
void* record = furi_record_open("test/holding");
void test_furi_create_open() {
// Test that record does not exist
mu_check(furi_record_exists(TEST_RECORD_NAME) == false);
// Create record
uint8_t test_data = 0;
furi_record_create(TEST_RECORD_NAME, (void*)&test_data);
// Test that record exists
mu_check(furi_record_exists(TEST_RECORD_NAME) == true);
// Open it
void* record = furi_record_open(TEST_RECORD_NAME);
mu_assert_pointers_eq(record, &test_data);
// 3. Close it
furi_record_close("test/holding");
// Close it
furi_record_close(TEST_RECORD_NAME);
// 4. Clean up
furi_record_destroy("test/holding");
// Clean up
furi_record_destroy(TEST_RECORD_NAME);
// Test that record does not exist
mu_check(furi_record_exists(TEST_RECORD_NAME) == false);
}

View File

@@ -81,6 +81,7 @@ __attribute__((unused)) static void (*minunit_teardown)(void) = NULL;
void minunit_print_progress(void);
void minunit_print_fail(const char* error);
void minunit_printf_warning(const char* format, ...);
/* Definitions */
#define MU_TEST(method_name) static void method_name(void)
@@ -150,6 +151,10 @@ void minunit_print_fail(const char* error);
minunit_end_proc_timer - minunit_proc_timer);)
#define MU_EXIT_CODE minunit_fail
/* Warnings */
#define mu_warn(message) \
MU__SAFE_BLOCK(minunit_printf_warning("%s:%d: %s", __FILE__, __LINE__, message);)
/* Assertions */
#define mu_check(test) \
MU__SAFE_BLOCK( \

View File

@@ -139,7 +139,7 @@ static bool write_file_13DA(Storage* storage, const char* path) {
File* file = storage_file_alloc(storage);
bool result = false;
if(storage_file_open(file, path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
result = storage_file_write(file, "13DA", 4) == 4;
result = (storage_file_write(file, "13DA", 4) == 4);
}
storage_file_close(file);
storage_file_free(file);

View File

@@ -115,6 +115,66 @@ MU_TEST(storage_file_open_close) {
furi_record_close(RECORD_STORAGE);
}
static bool storage_file_read_write_test(File* file, uint8_t* data, size_t test_size) {
const char* filename = UNIT_TESTS_PATH("storage_chunk.test");
// fill with pattern
for(size_t i = 0; i < test_size; i++) {
data[i] = (i % 113);
}
bool result = false;
do {
if(!storage_file_open(file, filename, FSAM_WRITE, FSOM_CREATE_ALWAYS)) break;
if(test_size != storage_file_write(file, data, test_size)) break;
storage_file_close(file);
// reset data
memset(data, 0, test_size);
if(!storage_file_open(file, filename, FSAM_READ, FSOM_OPEN_EXISTING)) break;
if(test_size != storage_file_read(file, data, test_size)) break;
storage_file_close(file);
// check that data is correct
for(size_t i = 0; i < test_size; i++) {
if(data[i] != (i % 113)) {
break;
}
}
result = true;
} while(false);
return result;
}
MU_TEST(storage_file_read_write_64k) {
Storage* storage = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(storage);
size_t size_1k = 1024;
size_t size_64k = size_1k + size_1k * 63;
size_t size_65k = size_64k + size_1k;
size_t size_max = size_65k + 8;
size_t max_ram_block = memmgr_heap_get_max_free_block();
if(max_ram_block < size_max) {
mu_warn("Not enough RAM for >64k block test");
} else {
uint8_t* data = malloc(size_max);
mu_check(storage_file_read_write_test(file, data, size_1k));
mu_check(storage_file_read_write_test(file, data, size_64k));
mu_check(storage_file_read_write_test(file, data, size_65k));
mu_check(storage_file_read_write_test(file, data, size_max));
free(data);
}
storage_file_free(file);
furi_record_close(RECORD_STORAGE);
}
MU_TEST_SUITE(storage_file) {
storage_file_open_lock_setup();
MU_RUN_TEST(storage_file_open_close);
@@ -122,6 +182,10 @@ MU_TEST_SUITE(storage_file) {
storage_file_open_lock_teardown();
}
MU_TEST_SUITE(storage_file_64k) {
MU_RUN_TEST(storage_file_read_write_64k);
}
MU_TEST(storage_dir_open_close) {
Storage* storage = furi_record_open(RECORD_STORAGE);
File* file;
@@ -640,6 +704,7 @@ MU_TEST_SUITE(test_md5_calc_suite) {
int run_minunit_test_storage() {
MU_RUN_SUITE(storage_file);
MU_RUN_SUITE(storage_file_64k);
MU_RUN_SUITE(storage_dir);
MU_RUN_SUITE(storage_rename);
MU_RUN_SUITE(test_data_path);

View File

@@ -326,6 +326,7 @@ bool subghz_hal_async_tx_test_run(SubGhzHalAsyncTxTestType type) {
furi_hal_subghz_set_frequency_and_path(433920000);
if(!furi_hal_subghz_start_async_tx(subghz_hal_async_tx_test_yield, &test)) {
mu_warn("SubGHZ transmission is prohibited");
return false;
}

View File

@@ -78,6 +78,16 @@ void minunit_print_fail(const char* str) {
printf(_FURI_LOG_CLR_E "%s\r\n" _FURI_LOG_CLR_RESET, str);
}
void minunit_printf_warning(const char* format, ...) {
FuriString* str = furi_string_alloc();
va_list args;
va_start(args, format);
furi_string_vprintf(str, format, args);
va_end(args);
printf(_FURI_LOG_CLR_W "%s\r\n" _FURI_LOG_CLR_RESET, furi_string_get_cstr(str));
furi_string_free(str);
}
void unit_tests_cli(Cli* cli, FuriString* args, void* context) {
UNUSED(cli);
UNUSED(args);