30 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			30 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| #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.
 | |
|     char** error_types;
 | |
| } 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];                           \
 | |
|         printf("(%s): ", test_case->short_name);                            \
 | |
|         int ret = (test_case->test_fn)();                                   \
 | |
|         if (ret) {                                                         \
 | |
|             printf("FAIL - Returned non zero (%d)\n", ret);                 \
 | |
|             printf("REASON: %s\n", test_case->error_types[ret]);            \
 | |
|             exit(1);                                                        \
 | |
|         } else {                                                            \
 | |
|             printf("PASS\n");                                               \
 | |
|         }                                                                   \
 | |
|     }
 | |
| 
 | |
| #endif // _H_MCU_TEST
 | |
| 
 |