Core api concept (#144)
* add input debounce code from old fw * exampl of input api * change input API to get/release * revert input API to read * pointer instead of instance * add input API description * add display API * rewrite display names * migrate to valuemanager * add LED API * add closing brakets * add sound api * fix led api * basic api * rename API pages * change pubsub implementation * move FURI AC -> flapp, add valuemutex example, add valuemanager implementation * pubsub usage example * user led example * update example * simplify input * add composed display * add SPI/GPIO and CC1101 bus * change cc1101 api * spi api and devices * spi api and devices * move SPI to page, add GPIO * not block pin open * backlight API and more * add minunit tests * fix logging * ignore unexisting time service on embedded targets * fix warning, issue with printf * Deprecate furi_open and furi_close (#167) Rename existing furi_open and furi_close to deprecated version * add exitcode * migrate to printf * indicate test by leds * add testing description * rename furi.h * wip basic api * add valuemutex, pubsub, split files * add value expanders * value mutex realization and tests * valuemutex test added to makefile * do not build unimplemented files * fix build furmware target f2 * redesigned minunit tests to allow testing in separate files * test file for valuemutex minunit testing * minunit partial test valuemutex * local cmsis_os2 mutex bindings * implement furi open/create, tests * migrate concurrent_access to ValueMutex * add spi header * Lib: add mlib submodule. Co-authored-by: rusdacent <rusdacentx0x08@gmail.com> Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
This commit is contained in:
@@ -16,6 +16,7 @@ C_SOURCES += $(APP_DIR)/tests/furiac_test.c
|
||||
C_SOURCES += $(APP_DIR)/tests/furi_record_test.c
|
||||
C_SOURCES += $(APP_DIR)/tests/test_index.c
|
||||
C_SOURCES += $(APP_DIR)/tests/minunit_test.c
|
||||
C_SOURCES += $(APP_DIR)/tests/furi_valuemutex_test.c
|
||||
endif
|
||||
|
||||
APP_EXAMPLE_BLINK ?= 0
|
||||
|
@@ -9,7 +9,8 @@ void coreglitch_demo_0(void* p) {
|
||||
fuprintf(log, "coreglitch demo!\n");
|
||||
|
||||
// open record
|
||||
FuriRecordSubscriber* fb_record = furi_open("u8g2_fb", false, false, NULL, NULL, NULL);
|
||||
FuriRecordSubscriber* fb_record =
|
||||
furi_open_deprecated("u8g2_fb", false, false, NULL, NULL, NULL);
|
||||
|
||||
if(fb_record == NULL) {
|
||||
fuprintf(log, "[widget] cannot create fb record\n");
|
||||
|
@@ -143,7 +143,7 @@ void display_u8g2(void* p) {
|
||||
&_u8g2); // send init sequence to the display, display is in sleep mode after this
|
||||
u8g2_SetContrast(&_u8g2, 36);
|
||||
|
||||
if(!furi_create("u8g2_fb", (void*)&_u8g2, sizeof(_u8g2))) {
|
||||
if(!furi_create_deprecated("u8g2_fb", (void*)&_u8g2, sizeof(_u8g2))) {
|
||||
fuprintf(log, "[display_u8g2] cannot create fb record\n");
|
||||
furiac_exit(NULL);
|
||||
}
|
||||
@@ -162,7 +162,7 @@ void display_u8g2(void* p) {
|
||||
|
||||
// subscribe to record. ctx will be passed to handle_fb_change
|
||||
FuriRecordSubscriber* fb_record =
|
||||
furi_open("u8g2_fb", false, false, handle_fb_change, NULL, &ctx);
|
||||
furi_open_deprecated("u8g2_fb", false, false, handle_fb_change, NULL, &ctx);
|
||||
|
||||
if(fb_record == NULL) {
|
||||
fuprintf(log, "[display] cannot open fb record\n");
|
||||
|
@@ -49,14 +49,14 @@ void fatfs_list(void* p) {
|
||||
|
||||
furi_log = get_default_log();
|
||||
|
||||
FuriRecordSubscriber* fb_record = furi_open("u8g2_fb", false, false, NULL, NULL, NULL);
|
||||
FuriRecordSubscriber* fb_record = furi_open_deprecated("u8g2_fb", false, false, NULL, NULL, NULL);
|
||||
if(fb_record == NULL) {
|
||||
fuprintf(furi_log, "[widget][fatfs_list] cannot create fb record\n");
|
||||
furiac_exit(NULL);
|
||||
}
|
||||
|
||||
FuriRecordSubscriber* event_record =
|
||||
furi_open("input_events", false, false, event_cb, NULL, event_queue);
|
||||
furi_open_deprecated("input_events", false, false, event_cb, NULL, event_queue);
|
||||
if(event_record == NULL) {
|
||||
fuprintf(furi_log, "[widget][fatfs_list] cannot register input_events callback\n");
|
||||
furiac_exit(NULL);
|
||||
|
@@ -16,9 +16,9 @@ static void event_cb(const void* value, size_t size, void* ctx) {
|
||||
void application_input_dump(void* p) {
|
||||
// open record
|
||||
FuriRecordSubscriber* state_record =
|
||||
furi_open("input_state", false, false, state_cb, NULL, NULL);
|
||||
furi_open_deprecated("input_state", false, false, state_cb, NULL, NULL);
|
||||
FuriRecordSubscriber* event_record =
|
||||
furi_open("input_events", false, false, event_cb, NULL, NULL);
|
||||
furi_open_deprecated("input_events", false, false, event_cb, NULL, NULL);
|
||||
|
||||
for(;;) {
|
||||
delay(100);
|
||||
|
@@ -60,7 +60,7 @@ void application_ipc_display(void* p) {
|
||||
}
|
||||
|
||||
// create record
|
||||
if(!furi_create("test_fb", (void*)_framebuffer, FB_SIZE)) {
|
||||
if(!furi_create_deprecated("test_fb", (void*)_framebuffer, FB_SIZE)) {
|
||||
fuprintf(log, "[display] cannot create fb record\n");
|
||||
furiac_exit(NULL);
|
||||
}
|
||||
@@ -79,7 +79,7 @@ void application_ipc_display(void* p) {
|
||||
|
||||
// subscribe to record. ctx will be passed to handle_fb_change
|
||||
FuriRecordSubscriber* fb_record =
|
||||
furi_open("test_fb", false, false, handle_fb_change, NULL, &ctx);
|
||||
furi_open_deprecated("test_fb", false, false, handle_fb_change, NULL, &ctx);
|
||||
|
||||
if(fb_record == NULL) {
|
||||
fuprintf(log, "[display] cannot open fb record\n");
|
||||
@@ -124,7 +124,8 @@ void application_ipc_widget(void* p) {
|
||||
FuriRecordSubscriber* log = get_default_log();
|
||||
|
||||
// open record
|
||||
FuriRecordSubscriber* fb_record = furi_open("test_fb", false, false, NULL, NULL, NULL);
|
||||
FuriRecordSubscriber* fb_record =
|
||||
furi_open_deprecated("test_fb", false, false, NULL, NULL, NULL);
|
||||
|
||||
if(fb_record == NULL) {
|
||||
fuprintf(log, "[widget] cannot create fb record\n");
|
||||
|
@@ -5,7 +5,7 @@ void u8g2_example(void* p) {
|
||||
FuriRecordSubscriber* log = get_default_log();
|
||||
|
||||
// open record
|
||||
FuriRecordSubscriber* fb_record = furi_open("u8g2_fb", false, false, NULL, NULL, NULL);
|
||||
FuriRecordSubscriber* fb_record = furi_open_deprecated("u8g2_fb", false, false, NULL, NULL, NULL);
|
||||
|
||||
if(fb_record == NULL) {
|
||||
fuprintf(log, "[widget] cannot create fb record\n");
|
||||
|
@@ -14,7 +14,7 @@ void u8g2_qrcode(void* p) {
|
||||
FuriRecordSubscriber* log = get_default_log();
|
||||
|
||||
// open record
|
||||
FuriRecordSubscriber* fb_record = furi_open("u8g2_fb", false, false, NULL, NULL, NULL);
|
||||
FuriRecordSubscriber* fb_record = furi_open_deprecated("u8g2_fb", false, false, NULL, NULL, NULL);
|
||||
|
||||
// Allocate a chunk of memory to store the QR code
|
||||
// https://github.com/ricmoo/QRCode
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include <input/input.h>
|
||||
#include <input_priv.h>
|
||||
#include <stdio.h>
|
||||
#include <furi.h>
|
||||
#include <flipper.h>
|
||||
|
||||
static volatile bool initialized = false;
|
||||
static SemaphoreHandle_t event;
|
||||
@@ -16,25 +16,25 @@ void input_task(void* p) {
|
||||
|
||||
event = xSemaphoreCreateCountingStatic(1, 0, &event_semaphore);
|
||||
|
||||
if(!furi_create("input_state", (void*)&input_state, sizeof(input_state))) {
|
||||
if(!furi_create_deprecated("input_state", (void*)&input_state, sizeof(input_state))) {
|
||||
printf("[input_task] cannot create the input_state record\n");
|
||||
furiac_exit(NULL);
|
||||
}
|
||||
|
||||
FuriRecordSubscriber* input_state_record =
|
||||
furi_open("input_state", false, false, NULL, NULL, NULL);
|
||||
furi_open_deprecated("input_state", false, false, NULL, NULL, NULL);
|
||||
if(input_state_record == NULL) {
|
||||
printf("[input_task] cannot open the input_state record\n");
|
||||
furiac_exit(NULL);
|
||||
}
|
||||
|
||||
if(!furi_create("input_events", NULL, 0)) {
|
||||
if(!furi_create_deprecated("input_events", NULL, 0)) {
|
||||
printf("[input_task] cannot create the input_events record\n");
|
||||
furiac_exit(NULL);
|
||||
}
|
||||
|
||||
FuriRecordSubscriber* input_events_record =
|
||||
furi_open("input_events", false, false, NULL, NULL, NULL);
|
||||
furi_open_deprecated("input_events", false, false, NULL, NULL, NULL);
|
||||
if(input_events_record == NULL) {
|
||||
printf("[input_task] cannot open the input_events record\n");
|
||||
furiac_exit(NULL);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "furi.h"
|
||||
#include "flipper.h"
|
||||
|
||||
#define FURI_LIB (const char*[])
|
||||
|
||||
|
@@ -1,245 +1,18 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "flipper.h"
|
||||
#include "flipper_v2.h"
|
||||
#include "log.h"
|
||||
#include "minunit.h"
|
||||
|
||||
/*
|
||||
TEST: pipe record
|
||||
|
||||
1. create pipe record
|
||||
2. Open/subscribe to it
|
||||
3. write data
|
||||
4. check that subscriber get data
|
||||
5. try to read, get error
|
||||
6. close record
|
||||
7. try to write, get error
|
||||
*/
|
||||
|
||||
static uint8_t pipe_record_value = 0;
|
||||
|
||||
void pipe_record_cb(const void* value, size_t size, void* ctx) {
|
||||
// hold value to static var
|
||||
pipe_record_value = *((uint8_t*)value);
|
||||
}
|
||||
|
||||
bool test_furi_pipe_record() {
|
||||
// 1. create pipe record
|
||||
if(!furi_create("test/pipe", NULL, 0)) {
|
||||
printf("cannot create record\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. Open/subscribe to it
|
||||
FuriRecordSubscriber* pipe_record =
|
||||
furi_open("test/pipe", false, false, pipe_record_cb, NULL, NULL);
|
||||
if(pipe_record == NULL) {
|
||||
printf("cannot open record\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
const uint8_t WRITE_VALUE = 1;
|
||||
// 3. write data
|
||||
if(!furi_write(pipe_record, &WRITE_VALUE, sizeof(uint8_t))) {
|
||||
printf("cannot write to record\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 4. check that subscriber get data
|
||||
if(pipe_record_value != WRITE_VALUE) {
|
||||
printf("wrong value (get %d, write %d)\n", pipe_record_value, WRITE_VALUE);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 5. try to read, get error
|
||||
uint8_t read_value = 0;
|
||||
if(furi_read(pipe_record, &read_value, sizeof(uint8_t))) {
|
||||
printf("reading from pipe record not allowed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 6. close record
|
||||
furi_close(pipe_record);
|
||||
|
||||
// 7. try to write, get error
|
||||
if(furi_write(pipe_record, &WRITE_VALUE, sizeof(uint8_t))) {
|
||||
printf("writing to closed record not allowed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
TEST: holding data
|
||||
|
||||
1. Create holding record
|
||||
2. Open/Subscribe on it
|
||||
3. Write data
|
||||
4. Check that subscriber get data
|
||||
5. Read and check data
|
||||
6. Try to write/read wrong size of data
|
||||
*/
|
||||
|
||||
static uint8_t holding_record_value = 0;
|
||||
|
||||
void holding_record_cb(const void* value, size_t size, void* ctx) {
|
||||
// hold value to static var
|
||||
holding_record_value = *((uint8_t*)value);
|
||||
}
|
||||
|
||||
bool test_furi_holding_data() {
|
||||
// 1. Create holding record
|
||||
uint8_t holder = 0;
|
||||
if(!furi_create("test/holding", (void*)&holder, sizeof(holder))) {
|
||||
printf("cannot create record\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. Open/Subscribe on it
|
||||
FuriRecordSubscriber* holding_record =
|
||||
furi_open("test/holding", false, false, holding_record_cb, NULL, NULL);
|
||||
if(holding_record == NULL) {
|
||||
printf("cannot open record\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
const uint8_t WRITE_VALUE = 1;
|
||||
// 3. write data
|
||||
if(!furi_write(holding_record, &WRITE_VALUE, sizeof(uint8_t))) {
|
||||
printf("cannot write to record\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 4. check that subscriber get data
|
||||
if(holding_record_value != WRITE_VALUE) {
|
||||
printf("wrong sub value (get %d, write %d)\n", holding_record_value, WRITE_VALUE);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 5. Read and check data
|
||||
uint8_t read_value = 0;
|
||||
if(!furi_read(holding_record, &read_value, sizeof(uint8_t))) {
|
||||
printf("cannot read from record\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(read_value != WRITE_VALUE) {
|
||||
printf("wrong read value (get %d, write %d)\n", read_value, WRITE_VALUE);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 6. Try to write/read wrong size of data
|
||||
if(furi_write(holding_record, &WRITE_VALUE, 100)) {
|
||||
printf("overflowed write not allowed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(furi_read(holding_record, &read_value, 100)) {
|
||||
printf("overflowed read not allowed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
TEST: concurrent access
|
||||
|
||||
1. Create holding record
|
||||
2. Open it twice
|
||||
3. Change value simultaneously in two app and check integrity
|
||||
*/
|
||||
|
||||
// TODO this test broke because mutex in furi is not implemented
|
||||
|
||||
typedef struct {
|
||||
// a and b must be equal
|
||||
uint8_t a;
|
||||
uint8_t b;
|
||||
} ConcurrentValue;
|
||||
|
||||
void furi_concurent_app(void* p) {
|
||||
FuriRecordSubscriber* holding_record =
|
||||
furi_open("test/concurrent", false, false, NULL, NULL, NULL);
|
||||
if(holding_record == NULL) {
|
||||
printf("cannot open record\n");
|
||||
furiac_exit(NULL);
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < 10; i++) {
|
||||
ConcurrentValue* value = (ConcurrentValue*)furi_take(holding_record);
|
||||
|
||||
if(value == NULL) {
|
||||
printf("cannot take record\n");
|
||||
furi_give(holding_record);
|
||||
furiac_exit(NULL);
|
||||
}
|
||||
// emulate read-modify-write broken by context switching
|
||||
uint8_t a = value->a;
|
||||
uint8_t b = value->b;
|
||||
a++;
|
||||
b++;
|
||||
delay(2); // this is only for test, do not add delay between take/give in prod!
|
||||
value->a = a;
|
||||
value->b = b;
|
||||
furi_give(holding_record);
|
||||
}
|
||||
|
||||
furiac_exit(NULL);
|
||||
}
|
||||
|
||||
bool test_furi_concurrent_access() {
|
||||
// 1. Create holding record
|
||||
ConcurrentValue holder = {.a = 0, .b = 0};
|
||||
if(!furi_create("test/concurrent", (void*)&holder, sizeof(ConcurrentValue))) {
|
||||
printf("cannot create record\n");
|
||||
return false;
|
||||
}
|
||||
void test_furi_create_open() {
|
||||
// 1. Create record
|
||||
uint8_t test_data = 0;
|
||||
mu_check(furi_create("test/holding", (void*)&test_data));
|
||||
|
||||
// 2. Open it
|
||||
FuriRecordSubscriber* holding_record =
|
||||
furi_open("test/concurrent", false, false, NULL, NULL, NULL);
|
||||
if(holding_record == NULL) {
|
||||
printf("cannot open record\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 3. Create second app for interact with it
|
||||
FuriApp* second_app = furiac_start(furi_concurent_app, "furi concurent app", NULL);
|
||||
|
||||
// 4. multiply ConcurrentValue::a
|
||||
for(size_t i = 0; i < 4; i++) {
|
||||
ConcurrentValue* value = (ConcurrentValue*)furi_take(holding_record);
|
||||
|
||||
if(value == NULL) {
|
||||
printf("cannot take record\n");
|
||||
furi_give(holding_record);
|
||||
return false;
|
||||
}
|
||||
// emulate read-modify-write broken by context switching
|
||||
uint8_t a = value->a;
|
||||
uint8_t b = value->b;
|
||||
a++;
|
||||
b++;
|
||||
value->a = a;
|
||||
delay(10); // this is only for test, do not add delay between take/give in prod!
|
||||
value->b = b;
|
||||
furi_give(holding_record);
|
||||
}
|
||||
|
||||
delay(50);
|
||||
|
||||
if(second_app->handler != NULL) {
|
||||
printf("second app still alive\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(holder.a != holder.b) {
|
||||
printf("broken integrity: a=%d, b=%d\n", holder.a, holder.b);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
void* record = furi_open("test/holding");
|
||||
mu_assert_pointers_eq(record, &test_data);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -309,14 +82,14 @@ void mute_record_state_cb(FlipperRecordState state, void* ctx) {
|
||||
|
||||
void furi_mute_parent_app(void* p) {
|
||||
// 1. Create pipe record
|
||||
if(!furi_create("test/mute", NULL, 0)) {
|
||||
if(!furi_create_deprecated("test/mute", NULL, 0)) {
|
||||
printf("cannot create record\n");
|
||||
furiac_exit(NULL);
|
||||
}
|
||||
|
||||
// 2. Open watch handler: solo=false, no_mute=false, subscribe to data
|
||||
FuriRecordSubscriber* watch_handler =
|
||||
furi_open("test/mute", false, false, mute_record_cb, NULL, NULL);
|
||||
furi_open_deprecated("test/mute", false, false, mute_record_cb, NULL, NULL);
|
||||
if(watch_handler == NULL) {
|
||||
printf("cannot open watch handler\n");
|
||||
furiac_exit(NULL);
|
||||
@@ -336,7 +109,7 @@ bool test_furi_mute_algorithm() {
|
||||
|
||||
// 2. Open handler A: solo=false, no_mute=false, NULL subscriber. Subscribe to state.
|
||||
FuriRecordSubscriber* handler_a =
|
||||
furi_open("test/mute", false, false, NULL, mute_record_state_cb, NULL);
|
||||
furi_open_deprecated("test/mute", false, false, NULL, mute_record_state_cb, NULL);
|
||||
if(handler_a == NULL) {
|
||||
printf("cannot open handler A\n");
|
||||
return false;
|
||||
@@ -356,7 +129,8 @@ bool test_furi_mute_algorithm() {
|
||||
}
|
||||
|
||||
// 3. Open handler B: solo=true, no_mute=true, NULL subscriber.
|
||||
FuriRecordSubscriber* handler_b = furi_open("test/mute", true, true, NULL, NULL, NULL);
|
||||
FuriRecordSubscriber* handler_b =
|
||||
furi_open_deprecated("test/mute", true, true, NULL, NULL, NULL);
|
||||
if(handler_b == NULL) {
|
||||
printf("cannot open handler B\n");
|
||||
return false;
|
||||
@@ -395,7 +169,8 @@ bool test_furi_mute_algorithm() {
|
||||
}
|
||||
|
||||
// 4. Open hadler C: solo=true, no_mute=false, NULL subscriber.
|
||||
FuriRecordSubscriber* handler_c = furi_open("test/mute", true, false, NULL, NULL, NULL);
|
||||
FuriRecordSubscriber* handler_c =
|
||||
furi_open_deprecated("test/mute", true, false, NULL, NULL, NULL);
|
||||
if(handler_c == NULL) {
|
||||
printf("cannot open handler C\n");
|
||||
return false;
|
||||
@@ -406,7 +181,8 @@ bool test_furi_mute_algorithm() {
|
||||
// TODO: Try to write data to C and check that subscriber get data.
|
||||
|
||||
// 5. Open handler D: solo=false, no_mute=false, NULL subscriber.
|
||||
FuriRecordSubscriber* handler_d = furi_open("test/mute", false, false, NULL, NULL, NULL);
|
||||
FuriRecordSubscriber* handler_d =
|
||||
furi_open_deprecated("test/mute", false, false, NULL, NULL, NULL);
|
||||
if(handler_d == NULL) {
|
||||
printf("cannot open handler D\n");
|
||||
return false;
|
||||
|
123
applications/tests/furi_valuemutex_test.c
Normal file
123
applications/tests/furi_valuemutex_test.c
Normal file
@@ -0,0 +1,123 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "flipper_v2.h"
|
||||
#include "log.h"
|
||||
|
||||
#include "minunit.h"
|
||||
|
||||
void test_furi_valuemutex() {
|
||||
const int init_value = 0xdeadbeef;
|
||||
const int changed_value = 0x12345678;
|
||||
|
||||
int value = init_value;
|
||||
bool result;
|
||||
ValueMutex valuemutex;
|
||||
|
||||
// init mutex case
|
||||
result = init_mutex(&valuemutex, &value, sizeof(value));
|
||||
mu_assert(result, "init mutex failed");
|
||||
|
||||
// acquire mutex case
|
||||
int* value_pointer = acquire_mutex(&valuemutex, 100);
|
||||
mu_assert_pointers_eq(value_pointer, &value);
|
||||
|
||||
// second acquire mutex case
|
||||
int* value_pointer_second = acquire_mutex(&valuemutex, 100);
|
||||
mu_assert_pointers_eq(value_pointer_second, NULL);
|
||||
|
||||
// change value case
|
||||
*value_pointer = changed_value;
|
||||
mu_assert_int_eq(value, changed_value);
|
||||
|
||||
// release mutex case
|
||||
result = release_mutex(&valuemutex, &value);
|
||||
mu_assert(result, "release mutex failed");
|
||||
|
||||
// TODO
|
||||
//acquire mutex blocking case
|
||||
//write mutex blocking case
|
||||
//read mutex blocking case
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
TEST: concurrent access
|
||||
|
||||
1. Create holding record
|
||||
2. Open it twice
|
||||
3. Change value simultaneously in two app and check integrity
|
||||
*/
|
||||
|
||||
// TODO this test broke because mutex in furi is not implemented
|
||||
|
||||
typedef struct {
|
||||
// a and b must be equal
|
||||
uint8_t a;
|
||||
uint8_t b;
|
||||
} ConcurrentValue;
|
||||
|
||||
void furi_concurent_app(void* p) {
|
||||
ValueMutex* mutex = (ValueMutex*)p;
|
||||
if(mutex == NULL) {
|
||||
printf("cannot open mutex\n");
|
||||
furiac_exit(NULL);
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < 10; i++) {
|
||||
ConcurrentValue* value = (ConcurrentValue*)acquire_mutex_block(mutex);
|
||||
|
||||
if(value == NULL) {
|
||||
printf("cannot take record\n");
|
||||
release_mutex(mutex, value);
|
||||
furiac_exit(NULL);
|
||||
}
|
||||
|
||||
// emulate read-modify-write broken by context switching
|
||||
uint8_t a = value->a;
|
||||
uint8_t b = value->b;
|
||||
a++;
|
||||
b++;
|
||||
delay(2);
|
||||
value->a = a;
|
||||
value->b = b;
|
||||
release_mutex(mutex, value);
|
||||
}
|
||||
|
||||
furiac_exit(NULL);
|
||||
}
|
||||
|
||||
void test_furi_concurrent_access() {
|
||||
// 1. Create holding record
|
||||
ConcurrentValue value = {.a = 0, .b = 0};
|
||||
ValueMutex mutex;
|
||||
mu_check(init_mutex(&mutex, &value, sizeof(value)));
|
||||
|
||||
// 3. Create second app for interact with it
|
||||
FuriApp* second_app = furiac_start(furi_concurent_app, "furi concurent app", (void*)&mutex);
|
||||
|
||||
// 4. multiply ConcurrentValue::a
|
||||
for(size_t i = 0; i < 4; i++) {
|
||||
ConcurrentValue* value = (ConcurrentValue*)acquire_mutex_block(&mutex);
|
||||
|
||||
if(value == NULL) {
|
||||
release_mutex(&mutex, value);
|
||||
mu_fail("cannot take record\n");
|
||||
}
|
||||
|
||||
// emulate read-modify-write broken by context switching
|
||||
uint8_t a = value->a;
|
||||
uint8_t b = value->b;
|
||||
a++;
|
||||
b++;
|
||||
value->a = a;
|
||||
delay(10); // this is only for test, do not add delay between take/give in prod!
|
||||
value->b = b;
|
||||
release_mutex(&mutex, value);
|
||||
}
|
||||
|
||||
delay(50);
|
||||
|
||||
mu_assert_pointers_eq(second_app->handler, NULL);
|
||||
|
||||
mu_assert_int_eq(value.a, value.b);
|
||||
}
|
@@ -6,12 +6,15 @@
|
||||
|
||||
bool test_furi_ac_create_kill();
|
||||
bool test_furi_ac_switch_exit();
|
||||
bool test_furi_pipe_record();
|
||||
bool test_furi_holding_data();
|
||||
bool test_furi_concurrent_access();
|
||||
|
||||
bool test_furi_nonexistent_data();
|
||||
bool test_furi_mute_algorithm();
|
||||
|
||||
// v2 tests
|
||||
void test_furi_create_open();
|
||||
void test_furi_valuemutex();
|
||||
void test_furi_concurrent_access();
|
||||
|
||||
static int foo = 0;
|
||||
|
||||
void test_setup(void) {
|
||||
@@ -34,27 +37,22 @@ MU_TEST(mu_test_furi_ac_switch_exit) {
|
||||
mu_assert_int_eq(test_furi_ac_switch_exit(), true);
|
||||
}
|
||||
|
||||
MU_TEST(mu_test_furi_pipe_record) {
|
||||
mu_assert_int_eq(test_furi_pipe_record(), true);
|
||||
}
|
||||
|
||||
MU_TEST(mu_test_furi_holding_data) {
|
||||
mu_assert_int_eq(test_furi_holding_data(), true);
|
||||
}
|
||||
|
||||
MU_TEST(mu_test_furi_concurrent_access) {
|
||||
mu_assert_int_eq(test_furi_concurrent_access(), true);
|
||||
}
|
||||
|
||||
MU_TEST(mu_test_furi_nonexistent_data) {
|
||||
mu_assert_int_eq(test_furi_nonexistent_data(), true);
|
||||
}
|
||||
|
||||
/*
|
||||
MU_TEST(mu_test_furi_mute_algorithm) {
|
||||
mu_assert_int_eq(test_furi_mute_algorithm(test_log), true);
|
||||
// v2 tests
|
||||
MU_TEST(mu_test_furi_create_open) {
|
||||
test_furi_create_open();
|
||||
}
|
||||
|
||||
MU_TEST(mu_test_furi_valuemutex) {
|
||||
test_furi_valuemutex();
|
||||
}
|
||||
|
||||
MU_TEST(mu_test_furi_concurrent_access) {
|
||||
test_furi_concurrent_access();
|
||||
}
|
||||
*/
|
||||
|
||||
MU_TEST_SUITE(test_suite) {
|
||||
MU_SUITE_CONFIGURE(&test_setup, &test_teardown);
|
||||
@@ -62,11 +60,14 @@ MU_TEST_SUITE(test_suite) {
|
||||
MU_RUN_TEST(test_check);
|
||||
MU_RUN_TEST(mu_test_furi_ac_create_kill);
|
||||
MU_RUN_TEST(mu_test_furi_ac_switch_exit);
|
||||
MU_RUN_TEST(mu_test_furi_pipe_record);
|
||||
MU_RUN_TEST(mu_test_furi_holding_data);
|
||||
MU_RUN_TEST(mu_test_furi_concurrent_access);
|
||||
|
||||
MU_RUN_TEST(mu_test_furi_nonexistent_data);
|
||||
// MU_RUN_TEST(mu_test_furi_mute_algorithm);
|
||||
|
||||
// v2 tests
|
||||
MU_RUN_TEST(mu_test_furi_create_open);
|
||||
MU_RUN_TEST(mu_test_furi_valuemutex);
|
||||
MU_RUN_TEST(mu_test_furi_concurrent_access);
|
||||
|
||||
}
|
||||
|
||||
int run_minunit() {
|
||||
|
Reference in New Issue
Block a user