From e843e9da835f058e09810cfeba7c60d0b270e7b3 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Sat, 27 Feb 2021 20:31:17 +1300 Subject: Move unity-test-runner to submodule --- .gitmodules | 3 +++ Makefile | 13 +++++++------ linker_list.lds | 8 -------- test_runner.c | 21 --------------------- test_runner.h | 32 -------------------------------- unity-test-runner | 1 + 6 files changed, 11 insertions(+), 67 deletions(-) delete mode 100644 linker_list.lds delete mode 100644 test_runner.c delete mode 100644 test_runner.h create mode 160000 unity-test-runner diff --git a/.gitmodules b/.gitmodules index 5c07d44..81baad2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "unity"] path = unity url = https://github.com/ThrowTheSwitch/Unity/ +[submodule "unity-test-runner"] + path = unity-test-runner + url = nah.nz:/srv/git/public/unity-test-runner diff --git a/Makefile b/Makefile index 05c24bc..6ba3a4f 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,8 @@ SIM_ELF = build/altimeter_sim.elf # options for native (i.e. unit test) UNITY_SRC ?= unity/src -CFLAGS += -Wall -Wextra -I$(UNITY_SRC) -g3 +TEST_RUNNER ?= unity-test-runner +CFLAGS += -Wall -Wextra -I$(UNITY_SRC) -I$(TEST_RUNNER) -g3 LDFLAGS += -lm # options for cross-compile @@ -30,7 +31,7 @@ AVR_COMMON_LDFLAGS += -Wl,-u,vfprintf -lprintf_flt AVR_LDFLAGS += $(AVR_COMMON_LDFLAGS) -mmcu=$(MCU) SIM_LDFLAGS += $(AVR_COMMON_LDFLAGS) -mmcu=$(SIM_MCU) -$(shell mkdir -p build/{real,sim,native{,/$(UNITY_SRC)}}) +$(shell mkdir -p build/{real,sim,native{,/$(UNITY_SRC),/$(TEST_RUNNER)}}) all: build/altimeter_sim.elf build/altimeter.hex test size @@ -56,7 +57,7 @@ NATIVE_DIR = $(BUILD_DIR)/native TEST_OBJ = \ $(NATIVE_DIR)/$(UNITY_SRC)/unity.o \ - $(NATIVE_DIR)/test_runner.o \ + $(NATIVE_DIR)/$(TEST_RUNNER)/test_runner.o \ $(NATIVE_DIR)/test_util.o \ $(NATIVE_DIR)/test_data_manager.o \ $(NATIVE_DIR)/data_manager.o \ @@ -80,11 +81,11 @@ SIM_OBJ = \ ALL_OBJ = $(TEST_OBJ) $(REAL_OBJ) $(SIM_OBJ) ALL_SOURCE = $(ALL_OBJ:.o=.c) -test: build/native/test_runner +test: build/native/unity-test-runner/test_runner ./$^ -build/native/test_runner: $(TEST_OBJ) - $(CC) $(LDFLAGS) -Wl,-T,linker_list.lds -o $@ $^ +build/native/unity-test-runner/test_runner: $(TEST_OBJ) + $(CC) $(LDFLAGS) -Wl,-T,$(TEST_RUNNER)/linker_list.lds -o $@ $^ # ELF for real hardware. No mock/sim hardware included (except barometer, # haven't written that code yet) diff --git a/linker_list.lds b/linker_list.lds deleted file mode 100644 index bb70bd8..0000000 --- a/linker_list.lds +++ /dev/null @@ -1,8 +0,0 @@ -SECTIONS { - __test_runner_list_start = .; - .test_runner_list : { - KEEP(*(SORT(.test_runner_list*))); - } - __test_runner_list_end = .; -} -INSERT BEFORE .bss; diff --git a/test_runner.c b/test_runner.c deleted file mode 100644 index 7887118..0000000 --- a/test_runner.c +++ /dev/null @@ -1,21 +0,0 @@ -#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); - } - return UNITY_END(); -} diff --git a/test_runner.h b/test_runner.h deleted file mode 100644 index 5b891b0..0000000 --- a/test_runner.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -/* Linker-generated lists derived from U-Boot source `include/linker_lists.h` - * with minor modification to store function pointers */ -#define list_head(entry_type, list_name) \ - ({ static char head[0] __attribute__((__aligned__(4), unused, section(".test_runner_list_2_"#list_name"_1")));(entry_type*)&head; }) - -#define list_tail(entry_type, list_name) \ - ({ static char tail[0] __attribute__((__aligned__(4), unused, section(".test_runner_list_2_"#list_name"_3")));(entry_type*)&tail; }) - -#define list_entry_count(entry_type, list_name) \ - ({ \ - entry_type* head = list_head(entry_type, list_name); \ - entry_type* tail = list_tail(entry_type, list_name); \ - (size_t)(tail - head); \ - }) - -#define list_entry(entry_type, list_name, entry_name) \ - entry_type _test_runner_list_2_##list_name_2_##entry_name __attribute__((__aligned__(4), unused, section(".test_runner_list_2_"#list_name"_2_"#entry_name))) - -#define RUNNER_DECLARE_TEST(test_name) \ - void test_name(void);\ - list_entry(struct test_fn, test_list, test_name) = { .name = #test_name, .file = __FILE__, .line = __LINE__, .fn = test_name}; \ - void test_name(void) - -struct test_fn { - const char *name; - const char *file; - int line; - void (*fn)(); -}; - diff --git a/unity-test-runner b/unity-test-runner new file mode 160000 index 0000000..1c1b4e3 --- /dev/null +++ b/unity-test-runner @@ -0,0 +1 @@ +Subproject commit 1c1b4e3b6c95169ac05aa4831870a1a5949b248e -- cgit v1.1