1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

Merged in james-duley/librepilot/unit_tests (pull request #168)

LP-223: Fix up unit tests
This commit is contained in:
Fredrik Arvidsson 2016-01-30 10:09:19 +01:00
commit 56bd378183
3 changed files with 63 additions and 63 deletions

View File

@ -305,64 +305,6 @@ uploader_clean:
##############################
#
# Unit Tests
#
##############################
ALL_UNITTESTS := logfs math lednotification
# Build the directory for the unit tests
UT_OUT_DIR := $(BUILD_DIR)/unit_tests
DIRS += $(UT_OUT_DIR)
.PHONY: all_ut
all_ut: $(addsuffix _elf, $(addprefix ut_, $(ALL_UNITTESTS)))
.PHONY: all_ut_xml
all_ut_xml: $(addsuffix _xml, $(addprefix ut_, $(ALL_UNITTESTS)))
.PHONY: all_ut_run
all_ut_run: $(addsuffix _run, $(addprefix ut_, $(ALL_UNITTESTS)))
.PHONY: all_ut_clean
all_ut_clean:
@$(ECHO) " CLEAN $(call toprel, $(UT_OUT_DIR))"
$(V1) [ ! -d "$(UT_OUT_DIR)" ] || $(RM) -r "$(UT_OUT_DIR)"
# $(1) = Unit test name
define UT_TEMPLATE
.PHONY: ut_$(1)
ut_$(1): ut_$(1)_run
ut_$(1)_%: $$(UT_OUT_DIR)
$(V1) $(MKDIR) -p $(UT_OUT_DIR)/$(1)
$(V1) cd $(ROOT_DIR)/flight/tests/$(1) && \
$$(MAKE) -r --no-print-directory \
BUILD_TYPE=ut \
BOARD_SHORT_NAME=$(1) \
TOPDIR=$(ROOT_DIR)/flight/tests/$(1) \
OUTDIR="$(UT_OUT_DIR)/$(1)" \
TARGET=$(1) \
$$*
.PHONY: ut_$(1)_clean
ut_$(1)_clean:
@$(ECHO) " CLEAN $(call toprel, $(UT_OUT_DIR)/$(1))"
$(V1) [ ! -d "$(UT_OUT_DIR)/$(1)" ] || $(RM) -r "$(UT_OUT_DIR)/$(1)"
endef
# Expand the unittest rules
$(foreach ut, $(ALL_UNITTESTS), $(eval $(call UT_TEMPLATE,$(ut))))
# Disable parallel make when the all_ut_run target is requested otherwise the TAP
# output is interleaved with the rest of the make output.
ifneq ($(strip $(filter all_ut_run,$(MAKECMDGOALS))),)
.NOTPARALLEL:
$(info $(EMPTY) NOTE Parallel make disabled by all_ut_run target so we have sane console output)
endif
##############################
#
# Packaging components

View File

@ -254,3 +254,62 @@ flight_uavobjects: $(UAVOBJGENERATOR)
$(V1) cd $(FLIGHT_UAVOBJ_DIR) && \
$(UAVOBJGENERATOR) -flight $(UAVOBJ_XML_DIR) $(FLIGHT_ROOT_DIR)/..
##############################
#
# Unit Tests
#
##############################
ALL_UNITTESTS := logfs math lednotification
# Build the directory for the unit tests
UT_OUT_DIR := $(BUILD_DIR)/unit_tests
DIRS += $(UT_OUT_DIR)
.PHONY: all_ut
all_ut: $(addsuffix _elf, $(addprefix ut_, $(ALL_UNITTESTS)))
.PHONY: all_ut_xml
all_ut_xml: $(addsuffix _xml, $(addprefix ut_, $(ALL_UNITTESTS)))
.PHONY: all_ut_run
all_ut_run: $(addsuffix _run, $(addprefix ut_, $(ALL_UNITTESTS)))
.PHONY: all_ut_clean
all_ut_clean:
@$(ECHO) " CLEAN $(call toprel, $(UT_OUT_DIR))"
$(V1) [ ! -d "$(UT_OUT_DIR)" ] || $(RM) -r "$(UT_OUT_DIR)"
# $(1) = Unit test name
define UT_TEMPLATE
.PHONY: ut_$(1)
ut_$(1): ut_$(1)_run
ut_$(1)_%: $$(UT_OUT_DIR)
$(V1) $(MKDIR) -p $(UT_OUT_DIR)/$(1)
$(V1) cd $(ROOT_DIR)/flight/tests/$(1) && \
$$(MAKE) -r --no-print-directory \
BUILD_TYPE=ut \
BOARD_SHORT_NAME=$(1) \
TOPDIR=$(ROOT_DIR)/flight/tests/$(1) \
OUTDIR="$(UT_OUT_DIR)/$(1)" \
TARGET=$(1) \
$$*
.PHONY: ut_$(1)_clean
ut_$(1)_clean:
@$(ECHO) " CLEAN $(call toprel, $(UT_OUT_DIR)/$(1))"
$(V1) [ ! -d "$(UT_OUT_DIR)/$(1)" ] || $(RM) -r "$(UT_OUT_DIR)/$(1)"
endef
# Expand the unittest rules
$(foreach ut, $(ALL_UNITTESTS), $(eval $(call UT_TEMPLATE,$(ut))))
# Disable parallel make when the all_ut_run target is requested otherwise the TAP
# output is interleaved with the rest of the make output.
ifneq ($(strip $(filter all_ut_run,$(MAKECMDGOALS))),)
.NOTPARALLEL:
$(info $(EMPTY) NOTE Parallel make disabled by all_ut_run target so we have sane console output)
endif

View File

@ -28,19 +28,18 @@
override ARM_SDK_PREFIX :=
override THUMB :=
GTEST_SRC_DIR := $(GTEST_DIR)/src
# Unit test source files
ALLSRC := $(SRC) $(wildcard ./*.c)
ALLCPPSRC := $(wildcard ./*.cpp) $(GTEST_DIR)/src/gtest_main.cc
ALLCPPSRC := $(wildcard ./*.cpp) $(GTEST_SRC_DIR)/gtest_main.cc
ALLSRCBASE := $(notdir $(basename $(ALLSRC) $(ALLCPPSRC)))
ALLOBJ := $(addprefix $(OUTDIR)/, $(addsuffix .o, $(ALLSRCBASE)))
$(foreach src,$(ALLSRC),$(eval $(call COMPILE_C_TEMPLATE,$(src))))
$(foreach src,$(ALLCPPSRC),$(eval $(call COMPILE_CXX_TEMPLATE,$(src))))
# Specific extensions to CPPFLAGS only for the google test library
$(OUTDIR)/gtest-all.o: CPPFLAGS += -I$(GTEST_DIR)
$(eval $(call COMPILE_CXX_TEMPLATE, $(GTEST_DIR)/src/gtest-all.cc))
$(eval $(call COMPILE_CXX_TEMPLATE, $(GTEST_SRC_DIR)/gtest-all.cc))
$(eval $(call LINK_CXX_TEMPLATE,$(OUTDIR)/$(TARGET).elf,$(ALLOBJ) $(OUTDIR)/gtest-all.o))
# Flags passed to the preprocessor