2016-08-22 20:03:46 +08:00
|
|
|
# Parameters:
|
|
|
|
# OBJECTS: list of object files, default main.o
|
|
|
|
# LIBS: list of object files, relative to ZEPHYR_BASE
|
|
|
|
# O: Output directory, default outdir
|
|
|
|
|
|
|
|
OBJECTS ?= main.o
|
|
|
|
O ?= outdir
|
|
|
|
INCLUDE += tests/ztest/include tests/include include
|
2016-11-09 09:28:07 +08:00
|
|
|
CFLAGS += -Wall
|
2016-08-22 20:03:46 +08:00
|
|
|
|
2016-08-31 19:17:03 +08:00
|
|
|
ifdef COVERAGE
|
|
|
|
export GCOV_PREFIX=$(O)
|
|
|
|
CFLAGS += -fprofile-arcs -ftest-coverage \
|
|
|
|
-fno-default-inline -fno-inline
|
|
|
|
endif
|
|
|
|
|
2016-08-22 20:03:46 +08:00
|
|
|
ifneq (, $(shell which valgrind 2> /dev/null))
|
|
|
|
VALGRIND = valgrind
|
|
|
|
VALGRIND_FLAGS = --leak-check=full --error-exitcode=1 \
|
|
|
|
--log-file=$(O)/valgrind.log
|
|
|
|
endif
|
|
|
|
|
|
|
|
TARGET = $(O)/testbinary
|
|
|
|
|
|
|
|
all: $(TARGET)
|
|
|
|
|
|
|
|
ZTEST = tests/ztest/src
|
|
|
|
LIB += $(ZTEST)/ztest.o $(ZTEST)/ztest_mock.o
|
2017-04-07 20:59:56 +08:00
|
|
|
CFLAGS += -DZTEST_UNITTEST
|
2016-08-22 20:03:46 +08:00
|
|
|
|
|
|
|
OBJS = $(addprefix $(O)/, $(OBJECTS) $(LIB))
|
|
|
|
|
|
|
|
INCLUDEFLAG = -I$(ZEPHYR_BASE)/
|
|
|
|
INCLUDED = $(addprefix $(INCLUDEFLAG), $(INCLUDE))
|
|
|
|
|
|
|
|
|
|
|
|
VPATH = $(ZEPHYR_BASE)
|
|
|
|
|
|
|
|
$(O)/%.o : %.c
|
|
|
|
mkdir -p $(@D)
|
2016-08-31 19:17:03 +08:00
|
|
|
$(CC) -I$(ZEPHYR_BASE) $(CFLAGS) $(INCLUDED) -c $(realpath $<) -o $@
|
2016-08-22 20:03:46 +08:00
|
|
|
|
|
|
|
$(TARGET): $(OBJS)
|
|
|
|
mkdir -p $(@D)
|
|
|
|
$(CC) $(CFLAGS) $(OBJS) -o $@ -g
|
|
|
|
|
|
|
|
.PHONY: run-test
|
|
|
|
run-test: $(TARGET)
|
|
|
|
$(VALGRIND) $(VALGRIND_FLAGS) $(TARGET) &> $(O)/unit.log
|
|
|
|
|
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
|
|
|
rm -rf $(O)
|