zephyr/tests/unit/Makefile.unittest

47 lines
999 B
Makefile
Raw Normal View History

# 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 += -O0 -Wall -Werror
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
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 $< -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)