blob: b8a8f9cb967bcc339ec8d0ac1227a3c5e2617565 [file] [log] [blame]
# 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
CFLAGS += -Wall
ifdef COVERAGE
export GCOV_PREFIX=$(O)
CFLAGS += -fprofile-arcs -ftest-coverage \
-fno-default-inline -fno-inline
endif
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
CFLAGS += -DZTEST_UNITTEST
OBJS = $(addprefix $(O)/, $(OBJECTS) $(LIB))
INCLUDEFLAG = -I$(ZEPHYR_BASE)/
INCLUDED = $(addprefix $(INCLUDEFLAG), $(INCLUDE))
VPATH = $(ZEPHYR_BASE)
$(O)/%.o : %.c
mkdir -p $(@D)
$(CC) -I$(ZEPHYR_BASE) $(CFLAGS) $(INCLUDED) -c $(realpath $<) -o $@
$(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)