Add minunit test framework (#168)

* add minunit tests

* fix logging

* ignore unexisting time service on embedded targets

* fix warning, issue with printf

* add exitcode

* migrate to printf

* indicate test by leds

* add testing description

* redesigned minunit tests to allow testing in separate files

* add test step for local target

* add failure test

* add restore test_check

* testing description

Co-authored-by: rusdacent <rusdacentx0x08@gmail.com>
Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
This commit is contained in:
coreglitch
2020-10-10 16:32:06 +06:00
committed by GitHub
parent aa3ac5b242
commit 176e608c6d
18 changed files with 903 additions and 243 deletions

View File

@@ -22,10 +22,10 @@ void pipe_record_cb(const void* value, size_t size, void* ctx) {
pipe_record_value = *((uint8_t*)value);
}
bool test_furi_pipe_record(FuriRecordSubscriber* log) {
bool test_furi_pipe_record() {
// 1. create pipe record
if(!furi_create("test/pipe", NULL, 0)) {
fuprintf(log, "cannot create record\n");
printf("cannot create record\n");
return false;
}
@@ -33,27 +33,27 @@ bool test_furi_pipe_record(FuriRecordSubscriber* log) {
FuriRecordSubscriber* pipe_record =
furi_open("test/pipe", false, false, pipe_record_cb, NULL, NULL);
if(pipe_record == NULL) {
fuprintf(log, "cannot open record\n");
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))) {
fuprintf(log, "cannot write to record\n");
printf("cannot write to record\n");
return false;
}
// 4. check that subscriber get data
if(pipe_record_value != WRITE_VALUE) {
fuprintf(log, "wrong value (get %d, write %d)\n", 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))) {
fuprintf(log, "reading from pipe record not allowed\n");
printf("reading from pipe record not allowed\n");
return false;
}
@@ -62,7 +62,7 @@ bool test_furi_pipe_record(FuriRecordSubscriber* log) {
// 7. try to write, get error
if(furi_write(pipe_record, &WRITE_VALUE, sizeof(uint8_t))) {
fuprintf(log, "writing to closed record not allowed\n");
printf("writing to closed record not allowed\n");
return false;
}
@@ -87,11 +87,11 @@ void holding_record_cb(const void* value, size_t size, void* ctx) {
holding_record_value = *((uint8_t*)value);
}
bool test_furi_holding_data(FuriRecordSubscriber* log) {
bool test_furi_holding_data() {
// 1. Create holding record
uint8_t holder = 0;
if(!furi_create("test/holding", (void*)&holder, sizeof(holder))) {
fuprintf(log, "cannot create record\n");
printf("cannot create record\n");
return false;
}
@@ -99,43 +99,43 @@ bool test_furi_holding_data(FuriRecordSubscriber* log) {
FuriRecordSubscriber* holding_record =
furi_open("test/holding", false, false, holding_record_cb, NULL, NULL);
if(holding_record == NULL) {
fuprintf(log, "cannot open record\n");
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))) {
fuprintf(log, "cannot write to record\n");
printf("cannot write to record\n");
return false;
}
// 4. check that subscriber get data
if(holding_record_value != WRITE_VALUE) {
fuprintf(log, "wrong sub value (get %d, write %d)\n", 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))) {
fuprintf(log, "cannot read from record\n");
printf("cannot read from record\n");
return false;
}
if(read_value != WRITE_VALUE) {
fuprintf(log, "wrong read value (get %d, write %d)\n", 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)) {
fuprintf(log, "overflowed write not allowed\n");
printf("overflowed write not allowed\n");
return false;
}
if(furi_read(holding_record, &read_value, 100)) {
fuprintf(log, "overflowed read not allowed\n");
printf("overflowed read not allowed\n");
return false;
}
@@ -159,12 +159,10 @@ typedef struct {
} ConcurrentValue;
void furi_concurent_app(void* p) {
FuriRecordSubscriber* log = (FuriRecordSubscriber*)p;
FuriRecordSubscriber* holding_record =
furi_open("test/concurrent", false, false, NULL, NULL, NULL);
if(holding_record == NULL) {
fuprintf(log, "cannot open record\n");
printf("cannot open record\n");
furiac_exit(NULL);
}
@@ -172,7 +170,7 @@ void furi_concurent_app(void* p) {
ConcurrentValue* value = (ConcurrentValue*)furi_take(holding_record);
if(value == NULL) {
fuprintf(log, "cannot take record\n");
printf("cannot take record\n");
furi_give(holding_record);
furiac_exit(NULL);
}
@@ -190,11 +188,11 @@ void furi_concurent_app(void* p) {
furiac_exit(NULL);
}
bool test_furi_concurrent_access(FuriRecordSubscriber* log) {
bool test_furi_concurrent_access() {
// 1. Create holding record
ConcurrentValue holder = {.a = 0, .b = 0};
if(!furi_create("test/concurrent", (void*)&holder, sizeof(ConcurrentValue))) {
fuprintf(log, "cannot create record\n");
printf("cannot create record\n");
return false;
}
@@ -202,19 +200,19 @@ bool test_furi_concurrent_access(FuriRecordSubscriber* log) {
FuriRecordSubscriber* holding_record =
furi_open("test/concurrent", false, false, NULL, NULL, NULL);
if(holding_record == NULL) {
fuprintf(log, "cannot open record\n");
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", (void*)log);
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) {
fuprintf(log, "cannot take record\n");
printf("cannot take record\n");
furi_give(holding_record);
return false;
}
@@ -232,12 +230,12 @@ bool test_furi_concurrent_access(FuriRecordSubscriber* log) {
delay(50);
if(second_app->handler != NULL) {
fuprintf(log, "second app still alive\n");
printf("second app still alive\n");
return false;
}
if(holder.a != holder.b) {
fuprintf(log, "broken integrity: a=%d, b=%d\n", holder.a, holder.b);
printf("broken integrity: a=%d, b=%d\n", holder.a, holder.b);
return false;
}
@@ -252,7 +250,7 @@ TEST: non-existent data
TODO: implement this test
*/
bool test_furi_nonexistent_data(FuriRecordSubscriber* log) {
bool test_furi_nonexistent_data() {
return true;
}
@@ -310,11 +308,9 @@ void mute_record_state_cb(FlipperRecordState state, void* ctx) {
}
void furi_mute_parent_app(void* p) {
FuriRecordSubscriber* log = (FuriRecordSubscriber*)p;
// 1. Create pipe record
if(!furi_create("test/mute", NULL, 0)) {
fuprintf(log, "cannot create record\n");
printf("cannot create record\n");
furiac_exit(NULL);
}
@@ -322,7 +318,7 @@ void furi_mute_parent_app(void* p) {
FuriRecordSubscriber* watch_handler =
furi_open("test/mute", false, false, mute_record_cb, NULL, NULL);
if(watch_handler == NULL) {
fuprintf(log, "cannot open watch handler\n");
printf("cannot open watch handler\n");
furiac_exit(NULL);
}
@@ -332,9 +328,9 @@ void furi_mute_parent_app(void* p) {
}
}
bool test_furi_mute_algorithm(FuriRecordSubscriber* log) {
bool test_furi_mute_algorithm() {
// 1. Create "parent" application:
FuriApp* parent_app = furiac_start(furi_mute_parent_app, "parent app", (void*)log);
FuriApp* parent_app = furiac_start(furi_mute_parent_app, "parent app", NULL);
delay(2); // wait creating record
@@ -342,7 +338,7 @@ bool test_furi_mute_algorithm(FuriRecordSubscriber* log) {
FuriRecordSubscriber* handler_a =
furi_open("test/mute", false, false, NULL, mute_record_state_cb, NULL);
if(handler_a == NULL) {
fuprintf(log, "cannot open handler A\n");
printf("cannot open handler A\n");
return false;
}
@@ -350,25 +346,25 @@ bool test_furi_mute_algorithm(FuriRecordSubscriber* log) {
// Try to write data to A and check subscriber
if(!furi_write(handler_a, &test_counter, sizeof(uint8_t))) {
fuprintf(log, "write to A failed\n");
printf("write to A failed\n");
return false;
}
if(mute_last_value != test_counter) {
fuprintf(log, "value A mismatch: %d vs %d\n", mute_last_value, test_counter);
printf("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.
FuriRecordSubscriber* handler_b = furi_open("test/mute", true, true, NULL, NULL, NULL);
if(handler_b == NULL) {
fuprintf(log, "cannot open handler B\n");
printf("cannot open handler B\n");
return false;
}
// Check A state cb get FlipperRecordStateMute.
if(mute_last_state != FlipperRecordStateMute) {
fuprintf(log, "A state is not FlipperRecordStateMute: %d\n", mute_last_state);
printf("A state is not FlipperRecordStateMute: %d\n", mute_last_state);
return false;
}
@@ -376,12 +372,12 @@ bool test_furi_mute_algorithm(FuriRecordSubscriber* log) {
// Try to write data to A and check that subscriber get no data. (muted)
if(furi_write(handler_a, &test_counter, sizeof(uint8_t))) {
fuprintf(log, "A not muted\n");
printf("A not muted\n");
return false;
}
if(mute_last_value == test_counter) {
fuprintf(log, "value A must be muted\n");
printf("value A must be muted\n");
return false;
}
@@ -389,19 +385,19 @@ bool test_furi_mute_algorithm(FuriRecordSubscriber* log) {
// Try to write data to B and check that subscriber get data.
if(!furi_write(handler_b, &test_counter, sizeof(uint8_t))) {
fuprintf(log, "write to B failed\n");
printf("write to B failed\n");
return false;
}
if(mute_last_value != test_counter) {
fuprintf(log, "value B mismatch: %d vs %d\n", mute_last_value, test_counter);
printf("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.
FuriRecordSubscriber* handler_c = furi_open("test/mute", true, false, NULL, NULL, NULL);
if(handler_c == NULL) {
fuprintf(log, "cannot open handler C\n");
printf("cannot open handler C\n");
return false;
}
@@ -412,7 +408,7 @@ bool test_furi_mute_algorithm(FuriRecordSubscriber* log) {
// 5. Open handler D: solo=false, no_mute=false, NULL subscriber.
FuriRecordSubscriber* handler_d = furi_open("test/mute", false, false, NULL, NULL, NULL);
if(handler_d == NULL) {
fuprintf(log, "cannot open handler D\n");
printf("cannot open handler D\n");
return false;
}
@@ -428,7 +424,7 @@ bool test_furi_mute_algorithm(FuriRecordSubscriber* log) {
// 7. Exit "parent application"
if(!furiac_kill(parent_app)) {
fuprintf(log, "kill parent_app fail\n");
printf("kill parent_app fail\n");
return false;
}