mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
[FL-3885] Put errno into TCB (#3893)
* feat: thread-safe errno
* ci: fix pvs warning
* ci: silence pvs warning
* fix: 🤯
* test: convert test app into a unit test
This commit is contained in:
51
applications/debug/unit_tests/tests/furi/furi_errno_test.c
Normal file
51
applications/debug/unit_tests/tests/furi/furi_errno_test.c
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <furi.h>
|
||||
#include <errno.h>
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
|
||||
#define TAG "ErrnoTest"
|
||||
#define THREAD_CNT 16
|
||||
#define ITER_CNT 1000
|
||||
|
||||
static int32_t errno_fuzzer(void* context) {
|
||||
int start_value = (int)context;
|
||||
int32_t fails = 0;
|
||||
|
||||
for(int i = start_value; i < start_value + ITER_CNT; i++) {
|
||||
errno = i;
|
||||
furi_thread_yield();
|
||||
if(errno != i) fails++;
|
||||
}
|
||||
|
||||
for(int i = 0; i < ITER_CNT; i++) {
|
||||
errno = 0;
|
||||
furi_thread_yield();
|
||||
UNUSED(strtol("123456", NULL, 10)); // -V530
|
||||
furi_thread_yield();
|
||||
if(errno != 0) fails++;
|
||||
|
||||
errno = 0;
|
||||
furi_thread_yield();
|
||||
UNUSED(strtol("123456123456123456123456123456123456123456123456", NULL, 10)); // -V530
|
||||
furi_thread_yield();
|
||||
if(errno != ERANGE) fails++;
|
||||
}
|
||||
|
||||
return fails;
|
||||
}
|
||||
|
||||
void test_errno_saving(void) {
|
||||
FuriThread* threads[THREAD_CNT];
|
||||
|
||||
for(int i = 0; i < THREAD_CNT; i++) {
|
||||
int start_value = i * ITER_CNT;
|
||||
threads[i] = furi_thread_alloc_ex("ErrnoFuzzer", 1024, errno_fuzzer, (void*)start_value);
|
||||
furi_thread_set_priority(threads[i], FuriThreadPriorityNormal);
|
||||
furi_thread_start(threads[i]);
|
||||
}
|
||||
|
||||
for(int i = 0; i < THREAD_CNT; i++) {
|
||||
furi_thread_join(threads[i]);
|
||||
mu_assert_int_eq(0, furi_thread_get_return_code(threads[i]));
|
||||
furi_thread_free(threads[i]);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ void test_furi_concurrent_access(void);
|
||||
void test_furi_pubsub(void);
|
||||
void test_furi_memmgr(void);
|
||||
void test_furi_event_loop(void);
|
||||
void test_errno_saving(void);
|
||||
|
||||
static int foo = 0;
|
||||
|
||||
@@ -42,6 +43,10 @@ MU_TEST(mu_test_furi_event_loop) {
|
||||
test_furi_event_loop();
|
||||
}
|
||||
|
||||
MU_TEST(mu_test_errno_saving) {
|
||||
test_errno_saving();
|
||||
}
|
||||
|
||||
MU_TEST_SUITE(test_suite) {
|
||||
MU_SUITE_CONFIGURE(&test_setup, &test_teardown);
|
||||
MU_RUN_TEST(test_check);
|
||||
@@ -51,6 +56,7 @@ MU_TEST_SUITE(test_suite) {
|
||||
MU_RUN_TEST(mu_test_furi_pubsub);
|
||||
MU_RUN_TEST(mu_test_furi_memmgr);
|
||||
MU_RUN_TEST(mu_test_furi_event_loop);
|
||||
MU_RUN_TEST(mu_test_errno_saving);
|
||||
}
|
||||
|
||||
int run_minunit_test_furi(void) {
|
||||
|
||||
Reference in New Issue
Block a user