Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/flipperzero-firmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcoreglitch <mail@s3f.ru>2020-08-26 21:32:22 +0300
committerGitHub <noreply@github.com>2020-08-26 21:32:22 +0300
commit4dc82b68d1c02ae080dc792c2ca0aa18cfb98fba (patch)
treee0309bec3331d1bb9429ae05c8c9ae2efa64437c /applications/tests
parent5094623d04db65210373c9c7d56d546228b8a4af (diff)
UART write example (#53)
* Rename test functions * rewrite furi API, segfault * make fixes in FURI, log through FURI * add uart write example blank * implement fuprintf instead of fopencookie * add gif, blank page * UART write example description Co-authored-by: Vadim Kaushan <admin@disasm.info>
Diffstat (limited to 'applications/tests')
-rw-r--r--applications/tests/furi_record_test.c158
-rw-r--r--applications/tests/furiac_test.c16
-rw-r--r--applications/tests/test_index.c66
3 files changed, 121 insertions, 119 deletions
diff --git a/applications/tests/furi_record_test.c b/applications/tests/furi_record_test.c
index 4fb1f495..cf608d51 100644
--- a/applications/tests/furi_record_test.c
+++ b/applications/tests/furi_record_test.c
@@ -1,7 +1,7 @@
#include <stdio.h>
#include <string.h>
#include "flipper.h"
-#include "debug.h"
+#include "log.h"
/*
TEST: pipe record
@@ -22,48 +22,48 @@ void pipe_record_cb(const void* value, size_t size) {
pipe_record_value = *((uint8_t*)value);
}
-bool test_furi_pipe_record(FILE* debug_uart) {
+bool test_furi_pipe_record(FuriRecordSubscriber* log) {
// 1. create pipe record
if(!furi_create("test/pipe", NULL, 0)) {
- fprintf(debug_uart, "cannot create record\n");
+ fuprintf(log, "cannot create record\n");
return false;
}
// 2. Open/subscribe to it
- FuriRecordHandler pipe_record = furi_open(
+ FuriRecordSubscriber* pipe_record = furi_open(
"test/pipe", false, false, pipe_record_cb, NULL
);
- if(pipe_record.record == NULL) {
- fprintf(debug_uart, "cannot open record\n");
+ if(pipe_record == NULL) {
+ fuprintf(log, "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))) {
- fprintf(debug_uart, "cannot write to record\n");
+ if(!furi_write(pipe_record, &WRITE_VALUE, sizeof(uint8_t))) {
+ fuprintf(log, "cannot write to record\n");
return false;
}
// 4. check that subscriber get data
if(pipe_record_value != WRITE_VALUE) {
- fprintf(debug_uart, "wrong value (get %d, write %d)\n", pipe_record_value, WRITE_VALUE);
+ fuprintf(log, "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))) {
- fprintf(debug_uart, "reading from pipe record not allowed\n");
+ if(furi_read(pipe_record, &read_value, sizeof(uint8_t))) {
+ fuprintf(log, "reading from pipe record not allowed\n");
return false;
}
// 6. close record
- furi_close(&pipe_record);
+ furi_close(pipe_record);
// 7. try to write, get error
- if(furi_write(&pipe_record, &WRITE_VALUE, sizeof(uint8_t))) {
- fprintf(debug_uart, "writing to closed record not allowed\n");
+ if(furi_write(pipe_record, &WRITE_VALUE, sizeof(uint8_t))) {
+ fuprintf(log, "writing to closed record not allowed\n");
return false;
}
@@ -88,56 +88,56 @@ void holding_record_cb(const void* value, size_t size) {
holding_record_value = *((uint8_t*)value);
}
-bool test_furi_holding_data(FILE* debug_uart) {
+bool test_furi_holding_data(FuriRecordSubscriber* log) {
// 1. Create holding record
uint8_t holder = 0;
if(!furi_create("test/holding", (void*)&holder, sizeof(holder))) {
- fprintf(debug_uart, "cannot create record\n");
+ fuprintf(log, "cannot create record\n");
return false;
}
// 2. Open/Subscribe on it
- FuriRecordHandler holding_record = furi_open(
+ FuriRecordSubscriber* holding_record = furi_open(
"test/holding", false, false, holding_record_cb, NULL
);
- if(holding_record.record == NULL) {
- fprintf(debug_uart, "cannot open record\n");
+ if(holding_record == NULL) {
+ fuprintf(log, "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))) {
- fprintf(debug_uart, "cannot write to record\n");
+ if(!furi_write(holding_record, &WRITE_VALUE, sizeof(uint8_t))) {
+ fuprintf(log, "cannot write to record\n");
return false;
}
// 4. check that subscriber get data
if(holding_record_value != WRITE_VALUE) {
- fprintf(debug_uart, "wrong sub value (get %d, write %d)\n", holding_record_value, WRITE_VALUE);
+ fuprintf(log, "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))) {
- fprintf(debug_uart, "cannot read from record\n");
+ if(!furi_read(holding_record, &read_value, sizeof(uint8_t))) {
+ fuprintf(log, "cannot read from record\n");
return false;
}
if(read_value != WRITE_VALUE) {
- fprintf(debug_uart, "wrong read value (get %d, write %d)\n", read_value, WRITE_VALUE);
+ fuprintf(log, "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)) {
- fprintf(debug_uart, "overflowed write not allowed\n");
+ if(furi_write(holding_record, &WRITE_VALUE, 100)) {
+ fuprintf(log, "overflowed write not allowed\n");
return false;
}
- if(furi_read(&holding_record, &read_value, 100)) {
- fprintf(debug_uart, "overflowed read not allowed\n");
+ if(furi_read(holding_record, &read_value, 100)) {
+ fuprintf(log, "overflowed read not allowed\n");
return false;
}
@@ -161,21 +161,22 @@ typedef struct {
} ConcurrentValue;
void furi_concurent_app(void* p) {
- FILE* debug_uart = (FILE*)p;
+ FuriRecordSubscriber* log = (FuriRecordSubscriber*)p;
- FuriRecordHandler holding_record = furi_open(
+ FuriRecordSubscriber* holding_record = furi_open(
"test/concurrent", false, false, NULL, NULL
);
- if(holding_record.record == NULL) {
- fprintf(debug_uart, "cannot open record\n");
+ if(holding_record == NULL) {
+ fuprintf(log, "cannot open record\n");
furiac_exit(NULL);
}
for(size_t i = 0; i < 10; i++) {
- ConcurrentValue* value = (ConcurrentValue*)furi_take(&holding_record);
+ ConcurrentValue* value = (ConcurrentValue*)furi_take(holding_record);
if(value == NULL) {
- fprintf(debug_uart, "cannot take record\n");
+ fuprintf(log, "cannot take record\n");
+ furi_give(holding_record);
furiac_exit(NULL);
}
// emulate read-modify-write broken by context switching
@@ -186,40 +187,41 @@ void furi_concurent_app(void* p) {
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);
+ furi_give(holding_record);
}
furiac_exit(NULL);
}
-bool test_furi_concurrent_access(FILE* debug_uart) {
+bool test_furi_concurrent_access(FuriRecordSubscriber* log) {
// 1. Create holding record
ConcurrentValue holder = {.a = 0, .b = 0};
if(!furi_create("test/concurrent", (void*)&holder, sizeof(ConcurrentValue))) {
- fprintf(debug_uart, "cannot create record\n");
+ fuprintf(log, "cannot create record\n");
return false;
}
// 2. Open it
- FuriRecordHandler holding_record = furi_open(
+ FuriRecordSubscriber* holding_record = furi_open(
"test/concurrent", false, false, NULL, NULL
);
- if(holding_record.record == NULL) {
- fprintf(debug_uart, "cannot open record\n");
+ if(holding_record == NULL) {
+ fuprintf(log, "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", (void*)debug_uart
+ furi_concurent_app, "furi concurent app", (void*)log
);
// 4. multiply ConcurrentValue::a
for(size_t i = 0; i < 4; i++) {
- ConcurrentValue* value = (ConcurrentValue*)furi_take(&holding_record);
+ ConcurrentValue* value = (ConcurrentValue*)furi_take(holding_record);
if(value == NULL) {
- fprintf(debug_uart, "cannot take record\n");
+ fuprintf(log, "cannot take record\n");
+ furi_give(holding_record);
return false;
}
// emulate read-modify-write broken by context switching
@@ -230,18 +232,18 @@ bool test_furi_concurrent_access(FILE* debug_uart) {
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);
+ furi_give(holding_record);
}
delay(20);
if(second_app->handler != NULL) {
- fprintf(debug_uart, "second app still alive\n");
+ fuprintf(log, "second app still alive\n");
return false;
}
if(holder.a != holder.b) {
- fprintf(debug_uart, "broken integrity: a=%d, b=%d\n", holder.a, holder.b);
+ fuprintf(log, "broken integrity: a=%d, b=%d\n", holder.a, holder.b);
return false;
}
@@ -256,7 +258,7 @@ TEST: non-existent data
TODO: implement this test
*/
-bool test_furi_nonexistent_data(FILE* debug_uart) {
+bool test_furi_nonexistent_data(FuriRecordSubscriber* log) {
return true;
}
@@ -315,20 +317,20 @@ void mute_record_state_cb(FlipperRecordState state) {
}
void furi_mute_parent_app(void* p) {
- FILE* debug_uart = (FILE*)p;
+ FuriRecordSubscriber* log = (FuriRecordSubscriber*)p;
// 1. Create pipe record
if(!furi_create("test/mute", NULL, 0)) {
- fprintf(debug_uart, "cannot create record\n");
+ fuprintf(log, "cannot create record\n");
furiac_exit(NULL);
}
// 2. Open watch handler: solo=false, no_mute=false, subscribe to data
- FuriRecordHandler watch_handler = furi_open(
+ FuriRecordSubscriber* watch_handler = furi_open(
"test/mute", false, false, mute_record_cb, NULL
);
- if(watch_handler.record == NULL) {
- fprintf(debug_uart, "cannot open watch handler\n");
+ if(watch_handler == NULL) {
+ fuprintf(log, "cannot open watch handler\n");
furiac_exit(NULL);
}
@@ -338,61 +340,61 @@ void furi_mute_parent_app(void* p) {
}
}
-bool test_furi_mute_algorithm(FILE* debug_uart) {
+bool test_furi_mute_algorithm(FuriRecordSubscriber* log) {
// 1. Create "parent" application:
FuriApp* parent_app = furiac_start(
- furi_mute_parent_app, "parent app", (void*)debug_uart
+ furi_mute_parent_app, "parent app", (void*)log
);
delay(2); // wait creating record
// 2. Open handler A: solo=false, no_mute=false, NULL subscriber. Subscribe to state.
- FuriRecordHandler handler_a = furi_open(
+ FuriRecordSubscriber* handler_a = furi_open(
"test/mute", false, false, NULL, mute_record_state_cb
);
- if(handler_a.record == NULL) {
- fprintf(debug_uart, "cannot open handler A\n");
+ if(handler_a == NULL) {
+ fuprintf(log, "cannot open handler A\n");
return false;
}
uint8_t test_counter = 1;
// Try to write data to A and check subscriber
- if(!furi_write(&handler_a, &test_counter, sizeof(uint8_t))) {
- fprintf(debug_uart, "write to A failed\n");
+ if(!furi_write(handler_a, &test_counter, sizeof(uint8_t))) {
+ fuprintf(log, "write to A failed\n");
return false;
}
if(mute_last_value != test_counter) {
- fprintf(debug_uart, "value A mismatch: %d vs %d\n", mute_last_value, test_counter);
+ fuprintf(log, "value A mismatch: %d vs %d\n", mute_last_value, test_counter);
return false;
}
// 3. Open handler B: solo=true, no_mute=true, NULL subscriber.
- FuriRecordHandler handler_b = furi_open(
+ FuriRecordSubscriber* handler_b = furi_open(
"test/mute", true, true, NULL, NULL
);
- if(handler_b.record == NULL) {
- fprintf(debug_uart, "cannot open handler B\n");
+ if(handler_b == NULL) {
+ fuprintf(log, "cannot open handler B\n");
return false;
}
// Check A state cb get FlipperRecordStateMute.
if(mute_last_state != FlipperRecordStateMute) {
- fprintf(debug_uart, "A state is not FlipperRecordStateMute: %d\n", mute_last_state);
+ fuprintf(log, "A state is not FlipperRecordStateMute: %d\n", mute_last_state);
return false;
}
test_counter = 2;
// Try to write data to A and check that subscriber get no data. (muted)
- if(furi_write(&handler_a, &test_counter, sizeof(uint8_t))) {
- fprintf(debug_uart, "A not muted\n");
+ if(furi_write(handler_a, &test_counter, sizeof(uint8_t))) {
+ fuprintf(log, "A not muted\n");
return false;
}
if(mute_last_value == test_counter) {
- fprintf(debug_uart, "value A must be muted\n");
+ fuprintf(log, "value A must be muted\n");
return false;
}
@@ -400,23 +402,23 @@ bool test_furi_mute_algorithm(FILE* debug_uart) {
// Try to write data to B and check that subscriber get data.
- if(!furi_write(&handler_b, &test_counter, sizeof(uint8_t))) {
- fprintf(debug_uart, "write to B failed\n");
+ if(!furi_write(handler_b, &test_counter, sizeof(uint8_t))) {
+ fuprintf(log, "write to B failed\n");
return false;
}
if(mute_last_value != test_counter) {
- fprintf(debug_uart, "value B mismatch: %d vs %d\n", mute_last_value, test_counter);
+ fuprintf(log, "value B mismatch: %d vs %d\n", mute_last_value, test_counter);
return false;
}
// 4. Open hadler C: solo=true, no_mute=false, NULL subscriber.
- FuriRecordHandler handler_c = furi_open(
+ FuriRecordSubscriber* handler_c = furi_open(
"test/mute", true, false, NULL, NULL
);
- if(handler_c.record == NULL) {
- fprintf(debug_uart, "cannot open handler C\n");
+ if(handler_c == NULL) {
+ fuprintf(log, "cannot open handler C\n");
return false;
}
@@ -425,11 +427,11 @@ bool test_furi_mute_algorithm(FILE* debug_uart) {
// TODO: Try to write data to C and check that subscriber get data.
// 5. Open handler D: solo=false, no_mute=false, NULL subscriber.
- FuriRecordHandler handler_d = furi_open(
+ FuriRecordSubscriber* handler_d = furi_open(
"test/mute", false, false, NULL, NULL
);
- if(handler_d.record == NULL) {
- fprintf(debug_uart, "cannot open handler D\n");
+ if(handler_d == NULL) {
+ fuprintf(log, "cannot open handler D\n");
return false;
}
@@ -445,7 +447,7 @@ bool test_furi_mute_algorithm(FILE* debug_uart) {
// 7. Exit "parent application"
if(!furiac_kill(parent_app)) {
- fprintf(debug_uart, "kill parent_app fail\n");
+ fuprintf(log, "kill parent_app fail\n");
return false;
}
diff --git a/applications/tests/furiac_test.c b/applications/tests/furiac_test.c
index b1810a4d..2c0f30cb 100644
--- a/applications/tests/furiac_test.c
+++ b/applications/tests/furiac_test.c
@@ -1,7 +1,7 @@
#include <stdio.h>
#include <string.h>
#include "flipper.h"
-#include "debug.h"
+#include "log.h"
/*
Test: creating and killing task
@@ -23,26 +23,26 @@ void create_kill_app(void* p) {
}
}
-bool test_furi_ac_create_kill(FILE* debug_uart) {
+bool test_furi_ac_create_kill(FuriRecordSubscriber* log) {
uint8_t counter = 0;
uint8_t value_a = counter;
FuriApp* widget = furiac_start(create_kill_app, "create_kill_app", (void*)&counter);
if(widget == NULL) {
- fprintf(debug_uart, "create widget fail\n");
+ fuprintf(log, "create widget fail\n");
return false;
}
delay(10);
if(!furiac_kill(widget)) {
- fprintf(debug_uart, "kill widget fail\n");
+ fuprintf(log, "kill widget fail\n");
return false;
}
if(value_a == counter) {
- fprintf(debug_uart, "counter unchanged\n");
+ fuprintf(log, "counter unchanged\n");
return false;
}
@@ -51,7 +51,7 @@ bool test_furi_ac_create_kill(FILE* debug_uart) {
delay(10);
if(value_a != counter) {
- fprintf(debug_uart, "counter changes after kill (counter = %d vs %d)\n", value_a, counter);
+ fuprintf(log, "counter changes after kill (counter = %d vs %d)\n", value_a, counter);
return false;
}
@@ -111,7 +111,7 @@ void task_b(void* p) {
furiac_exit(p);
}
-bool test_furi_ac_switch_exit(FILE* debug_uart) {
+bool test_furi_ac_switch_exit(FuriRecordSubscriber* log) {
// init sequence
TestSwitchSequence seq;
seq.count = 0;
@@ -124,7 +124,7 @@ bool test_furi_ac_switch_exit(FILE* debug_uart) {
seq.sequence[seq.count] = '\0';
if(strcmp(seq.sequence, "ABA/") != 0) {
- fprintf(debug_uart, "wrong sequence: %s\n", seq.sequence);
+ fuprintf(log, "wrong sequence: %s\n", seq.sequence);
return false;
}
diff --git a/applications/tests/test_index.c b/applications/tests/test_index.c
index 4b07104e..7a9d6765 100644
--- a/applications/tests/test_index.c
+++ b/applications/tests/test_index.c
@@ -1,67 +1,67 @@
#include <stdio.h>
#include "flipper.h"
-#include "debug.h"
+#include "log.h"
#include "flipper-core.h"
-bool test_furi_ac_create_kill(FILE* debug_uart);
-bool test_furi_ac_switch_exit(FILE* debug_uart);
+bool test_furi_ac_create_kill(FuriRecordSubscriber* log);
+bool test_furi_ac_switch_exit(FuriRecordSubscriber* log);
-bool test_furi_pipe_record(FILE* debug_uart);
-bool test_furi_holding_data(FILE* debug_uart);
-bool test_furi_concurrent_access(FILE* debug_uart);
-bool test_furi_nonexistent_data(FILE* debug_uart);
-bool test_furi_mute_algorithm(FILE* debug_uart);
+bool test_furi_pipe_record(FuriRecordSubscriber* log);
+bool test_furi_holding_data(FuriRecordSubscriber* log);
+bool test_furi_concurrent_access(FuriRecordSubscriber* log);
+bool test_furi_nonexistent_data(FuriRecordSubscriber* log);
+bool test_furi_mute_algorithm(FuriRecordSubscriber* log);
void flipper_test_app(void* p) {
- FILE* debug_uart = get_debug();
-
- if(test_furi_ac_create_kill(debug_uart)) {
- fprintf(debug_uart, "[TEST] test_furi_ac_create_kill PASSED\n");
+ FuriRecordSubscriber* log = get_default_log();
+
+ if(test_furi_ac_create_kill(log)) {
+ fuprintf(log, "[TEST] test_furi_ac_create_kill PASSED\n");
} else {
- fprintf(debug_uart, "[TEST] test_furi_ac_create_kill FAILED\n");
+ fuprintf(log, "[TEST] test_furi_ac_create_kill FAILED\n");
}
- if(test_furi_ac_switch_exit(debug_uart)) {
- fprintf(debug_uart, "[TEST] test_furi_ac_switch_exit PASSED\n");
+ if(test_furi_ac_switch_exit(log)) {
+ fuprintf(log, "[TEST] test_furi_ac_switch_exit PASSED\n");
} else {
- fprintf(debug_uart, "[TEST] test_furi_ac_switch_exit FAILED\n");
+ fuprintf(log, "[TEST] test_furi_ac_switch_exit FAILED\n");
}
- if(test_furi_pipe_record(debug_uart)) {
- fprintf(debug_uart, "[TEST] test_furi_pipe_record PASSED\n");
+ if(test_furi_pipe_record(log)) {
+ fuprintf(log, "[TEST] test_furi_pipe_record PASSED\n");
} else {
- fprintf(debug_uart, "[TEST] test_furi_pipe_record FAILED\n");
+ fuprintf(log, "[TEST] test_furi_pipe_record FAILED\n");
}
- if(test_furi_holding_data(debug_uart)) {
- fprintf(debug_uart, "[TEST] test_furi_holding_data PASSED\n");
+ if(test_furi_holding_data(log)) {
+ fuprintf(log, "[TEST] test_furi_holding_data PASSED\n");
} else {
- fprintf(debug_uart, "[TEST] test_furi_holding_data FAILED\n");
+ fuprintf(log, "[TEST] test_furi_holding_data FAILED\n");
}
- if(test_furi_concurrent_access(debug_uart)) {
- fprintf(debug_uart, "[TEST] test_furi_concurrent_access PASSED\n");
+ if(test_furi_concurrent_access(log)) {
+ fuprintf(log, "[TEST] test_furi_concurrent_access PASSED\n");
} else {
- fprintf(debug_uart, "[TEST] test_furi_concurrent_access FAILED\n");
+ fuprintf(log, "[TEST] test_furi_concurrent_access FAILED\n");
}
- if(test_furi_nonexistent_data(debug_uart)) {
- fprintf(debug_uart, "[TEST] test_furi_nonexistent_data PASSED\n");
+ if(test_furi_nonexistent_data(log)) {
+ fuprintf(log, "[TEST] test_furi_nonexistent_data PASSED\n");
} else {
- fprintf(debug_uart, "[TEST] test_furi_nonexistent_data FAILED\n");
+ fuprintf(log, "[TEST] test_furi_nonexistent_data FAILED\n");
}
- if(test_furi_mute_algorithm(debug_uart)) {
- fprintf(debug_uart, "[TEST] test_furi_mute_algorithm PASSED\n");
+ if(test_furi_mute_algorithm(log)) {
+ fuprintf(log, "[TEST] test_furi_mute_algorithm PASSED\n");
} else {
- fprintf(debug_uart, "[TEST] test_furi_mute_algorithm FAILED\n");
+ fuprintf(log, "[TEST] test_furi_mute_algorithm FAILED\n");
}
if(add(1, 2) == 3) {
- fprintf(debug_uart, "[TEST] Rust add PASSED\n");
+ fuprintf(log, "[TEST] Rust add PASSED\n");
} else {
- fprintf(debug_uart, "[TEST] Rust add FAILED\n");
+ fuprintf(log, "[TEST] Rust add FAILED\n");
}
furiac_exit(NULL);