2025-01-29 21:21:18 +00:00
|
|
|
#ifndef _H_MCU_TEST
|
|
|
|
#define _H_MCU_TEST
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
typedef struct mcu_test_case_s {
|
|
|
|
const char* short_name;
|
|
|
|
int (*test_fn)(void);
|
|
|
|
// If `test_fn` returns non zero, it will get the (ret_val - 1) value of this array,
|
|
|
|
// if this is null it will show up as `(none)`, so return 1 for the first error type.
|
2025-02-04 13:03:27 +00:00
|
|
|
char** error_types;
|
2025-01-29 21:21:18 +00:00
|
|
|
} mcu_test_case_t;
|
|
|
|
|
|
|
|
|
|
|
|
#define RUN_TEST_CASES(cases) \
|
|
|
|
for (size_t i = 0; i < sizeof(cases)/sizeof(mcu_test_case_t); i++) { \
|
|
|
|
mcu_test_case_t* test_case = &(cases)[i]; \
|
2025-02-04 13:32:09 +00:00
|
|
|
const char* sn = test_case->short_name; \
|
|
|
|
printf("Running test case: %s\n", test_case->short_name); \
|
2025-01-29 21:21:18 +00:00
|
|
|
int ret = (test_case->test_fn)(); \
|
2025-02-04 13:32:09 +00:00
|
|
|
if (ret) { \
|
|
|
|
printf("(%s) FAIL - Returned non zero (%d)\n", sn, ret); \
|
|
|
|
printf("(%s) REASON: %s\n", sn, test_case->error_types[ret]); \
|
2025-01-29 21:21:18 +00:00
|
|
|
exit(1); \
|
|
|
|
} else { \
|
2025-02-04 13:32:09 +00:00
|
|
|
printf("(%s) PASS\n", sn); \
|
2025-01-29 21:21:18 +00:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // _H_MCU_TEST
|
|
|
|
|