tests: test_runner, working simple single-ESP "solo" test cases

This commit is contained in:
Angus Gratton 2016-02-09 21:03:50 +11:00
parent 97a46e8c1a
commit 80b191af08
7 changed files with 492 additions and 22 deletions

View file

@ -4,6 +4,12 @@
#include <stdio.h>
#include "esp/uart.h"
/* Unity is the framework with test assertions, etc. */
#include "unity.h"
/* Need to explicitly flag once a test has completed successfully. */
#define TEST_PASS do { UnityConcludeTest(); while(1) { } } while (0)
/* Types of test, defined by hardware requirements */
typedef enum {
SOLO, /* Test require "ESP A" only, no other connections */
@ -11,30 +17,43 @@ typedef enum {
EYORE_TEST, /* Test requires an eyore-test board with onboard STM32F0 */
} testcase_type_t;
typedef bool (testcase_fn_t)(void);
typedef void (testcase_fn_t)(void);
typedef struct {
char *name;
char *file;
uint8_t line;
testcase_type_t type;
testcase_fn_t *a_fn;
testcase_fn_t *b_fn;
} testcase_t;
void testcase_register(const testcase_t *ignored);
/* Register a test case using these macros. Use DEFINE_SOLO_TESTCASE for single-MCU tests,
and DEFINE_TESTCASE for all other test types.
*/
#define DEFINE_SOLO_TESTCASE(NAME) \
static testcase_fn_t a_##NAME; \
const __attribute__((section(".testcases.text"))) __attribute__((used)) \
testcase_t testcase_##NAME = { .name = #NAME, .type = SOLO, .a_fn = a_##NAME };
*/
#define DEFINE_SOLO_TESTCASE(NAME) \
static testcase_fn_t a_##NAME; \
_DEFINE_TESTCASE_COMMON(NAME, SOLO, a_##NAME, 0)
#define DEFINE_TESTCASE(NAME, TYPE) \
static testcase_fn_t a_##NAME; \
static testcase_fn_t b_##NAME; \
_DEFINE_TESTCASE_COMMON(NAME, TYPE, A_##NAME, B_##NAME)
#define DEFINE_TESTCASE(NAME, TYPE) \
static testcase_fn_t a_##NAME; \
static testcase_fn_t b_##NAME; \
const __attribute__((section(".testcases.text"))) __attribute__((used)) \
testcase_t testcase_##NAME = { .name = #NAME, .type = TYPE, .a_fn = a_##NAME, .b_fn = b_##NAME };
#define _DEFINE_TESTCASE_COMMON(NAME, TYPE, A_FN, B_FN) \
const __attribute__((section(".testcases.text"))) \
testcase_t testcase_##NAME = { .name = #NAME, \
.file = __FILE__, \
.line = __LINE__, \
.type = TYPE, \
.a_fn = A_FN, \
.b_fn = B_FN, \
}; \
void __attribute__((constructor)) testcase_ctor_##NAME() { \
testcase_register(&testcase_##NAME); \
}
#endif