summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Sundvik <fsundvik@gmail.com>2016-02-14 00:20:14 +0200
committerFred Sundvik <fsundvik@gmail.com>2016-02-14 00:20:14 +0200
commite9a1474bb6a92024c8d4e3095d6b871833db1cf4 (patch)
treefd735d0ef317193a2a4086e9c2668ac0d2907b18
parente70cefc12fb897f7221f7b1bc6fe0ce595eb2de1 (diff)
Add makefile for compiling and running unit tests
-rw-r--r--serial_link.mk1
-rw-r--r--tests/Makefile49
2 files changed, 50 insertions, 0 deletions
diff --git a/serial_link.mk b/serial_link.mk
index 51d33fcb41..8e8de807f5 100644
--- a/serial_link.mk
+++ b/serial_link.mk
@@ -2,6 +2,7 @@ CGREEN_LIB = $(BUILDDIR)/cgreen/build-c/src/libcgreen.a
.phony testserial:
testserial: $(CGREEN_LIB)
+ make -C $(SERIAL_DIR)/tests BUILDDIR=../../$(BUILDDIR)
CGREEN_DIR = "$(CURDIR)/$(SERIAL_DIR)/cgreen/cgreen"
CGREEN_BUILD_DIR = "$(CURDIR)/$(BUILDDIR)/cgreen"
diff --git a/tests/Makefile b/tests/Makefile
new file mode 100644
index 0000000000..239e9f6093
--- /dev/null
+++ b/tests/Makefile
@@ -0,0 +1,49 @@
+CC = gcc
+CFLAGS =
+INCLUDES = -I.
+LDFLAGS = -L$(BUILDDIR)/cgreen/build-c/src
+LDLIBS = -lcgreen
+UNITOBJ = $(BUILDDIR)/testserial/unitobj
+DEPDIR = $(BUILDDIR)/testserial/unit.d
+UNITEXE = $(BUILDDIR)/testserial/unitexe
+DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td
+EXT =
+UNAME := $(shell uname)
+ifneq (, $(findstring mingw, $(UNAME)))
+ EXT += exe
+endif
+ifneq (, $(findstring cygwin, $(UNAME)))
+ EXT += exe
+endif
+
+SRC = $(wildcard *.c)
+EXE = $(patsubst %.c, $(UNITEXE)/%$(EXT), $(SRC))
+$(shell mkdir -p $(DEPDIR) >/dev/null)
+
+test: $(EXE)
+ @for f in $^; do \
+ echo "++++++++++++++++++"; \
+ echo "Running unit tests"; \
+ echo $$(basename $$f); \
+ echo "++++++++++++++++++"; \
+ echo ""; \
+ $$f || exit 1; \
+ echo ""; \
+ echo "******************"; \
+ echo ""; \
+ done
+
+$(UNITEXE)/%$(EXT): $(UNITOBJ)/%.o
+ mkdir -p $(UNITEXE)
+ $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
+
+$(UNITOBJ)/%.o : %.c
+$(UNITOBJ)/%.o: %.c $(DEPDIR)/%.d
+ mkdir -p $(UNITOBJ)
+ $(CC) $(CFLAGS) $(DEPFLAGS) -c $< -o $@
+ mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d
+
+$(DEPDIR)/%.d: ;
+.PRECIOUS: $(DEPDIR)/%.d
+
+-include $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRC).c)) \ No newline at end of file