From 4710921284adbf5005421515fbab5dd1aa38e9aa Mon Sep 17 00:00:00 2001 From: David Phillips Date: Sat, 13 Feb 2021 18:21:36 +1300 Subject: Add test runner This patch adds a "magic" test runner which discovers all test cases in the executable into which it is linked. This is achieved through the use of a special macro used to declare tests, so that they are added onto a linker- generated list. The linker list logic is largely taken from U-Boot source code, with minor some tweaks made. This linker-generated list is then used at runtime in order to pick out every test case which can be run, resulting in a cross-file "suite" of unity unit tests, rather than separate test executables per module. A sample test module, test_test.c is provided to illustrate the test runner's ability to correctly discover tests across multiple translation units. --- test_runner.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 test_runner.c (limited to 'test_runner.c') diff --git a/test_runner.c b/test_runner.c new file mode 100644 index 0000000..9d3ad65 --- /dev/null +++ b/test_runner.c @@ -0,0 +1,21 @@ +#include + +#include "test_runner.h" +#include "unity.h" + +/* unity requires these, even if empty */ +void setUp(){}; +void tearDown(){}; + +int main(void) +{ + struct test_fn *tests = list_head(struct test_fn, test_list); + size_t count = list_entry_count(struct test_fn, test_list); + printf("Suite has %zd tests\n", count); + UNITY_BEGIN(); + for (size_t i = 0; i < count; i++) { + UnitySetTestFile(tests[i].file); + UnityDefaultTestRun(tests[i].fn, tests[i].name, tests[i].line); + } + UNITY_END(); +} -- cgit v1.1