FreeRTOS-Kernel/FreeRTOS/Test/CMock/Makefile
Paul Bartell 570ae6bb52
Add unity memory extension, fake_assert, and enable -fsanitize=address (#506)
* Enable libunitymemory extension to track dynamic memory usage during unit tests
* Use UnityMemory in timers_utest.c
* Add fake_assert.h to allow mocking of configASSERT calls
* Add .editorconfig to make github show indentation correctly
* Add unity memory and fake_assert to queue_utest.c
* Add -fsanitize=address CFLAG when running unit tests
* Define mtCOVERAGE_TEST_MARKER macro to include mtCOVERAGE_TEST_MARKER lines in coverage figures
* Add additional memory check / protection CFLAGS for CMock tests
* Fix out of bounds array access in list_utest.c
* Move the fake_assert.h include to the top of FreeRTOSConfig.h
2021-02-18 10:15:01 -08:00

98 lines
2.9 KiB
Makefile

# Change to match installed location
export CC ?= /usr/local/bin/gcc
export LD ?= /usr/local/bin/ld
# Add units here when adding a new unit test directory with the same name
UNITS := queue list timers
include makefile.in
.PHONY: all doc clean $(UNITS) directories coverage zero_coverage
.PHONY: run run_formatted run_col_formatted run_col
all: doc coverage
execs: $(UNITS) | directories
$(UNITS) : ${LIB_DIR}/libcmock.so \
${LIB_DIR}/libunity.so \
${LIB_DIR}/libunitymemory.so \
| directories
$(MAKE) -C $@
doc: | directories
$(MAKE) -C doc all
directories : $(BUILD_DIR) $(GENERATED_DIR) $(COVERAGE_DIR) $(BIN_DIR) $(DOC_DIR) $(LIB_DIR)
$(BUILD_DIR) :
-mkdir $(BUILD_DIR)
$(GENERATED_DIR) :
-mkdir -p $(GENERATED_DIR)
$(COVERAGE_DIR) :
-mkdir -p $(COVERAGE_DIR)
$(BIN_DIR) :
-mkdir -p $(BIN_DIR)
$(DOC_DIR) :
-mkdir -p $(DOC_DIR)
$(LIB_DIR) :
-mkdir -p $(LIB_DIR)
clean:
rm -rf build
help:
@echo -e 'Usage: $$ make <unit>\n '
@echo -e ' where <unit> is one of: $(UNITS) doc all run run_formatted run_col run_col_formatted coverage'
$(LIB_DIR)/libcmock.so : ${CMOCK_SRC_DIR}/cmock.c \
${CMOCK_SRC_DIR}/cmock.h \
${LIB_DIR}/libunity.so \
Makefile | directories
${CC} -o $@ -shared -fPIC $< ${INCLUDE_DIR}
$(LIB_DIR)/libunity.so : ${UNITY_SRC_DIR}/unity.c \
${UNITY_SRC_DIR}/unity.h \
Makefile | directories
${CC} -o $@ -shared -fPIC $<
$(LIB_DIR)/libunitymemory.so: ${UNITY_EXTRAS_DIR}/memory/src/unity_memory.c \
${UNITY_EXTRAS_DIR}/memory/src/unity_memory.h \
${LIB_DIR}/libunity.so \
Makefile | directories
${CC} -o $@ -shared -fPIC $< ${INCLUDE_DIR}
run : $(UNITS) directories
-rm $(BUILD_DIR)/unit_test_report.txt
for f in $(BIN_DIR)/*; do \
$${f} | tee -a $(BUILD_DIR)/unit_test_report.txt; \
done
cd $(BUILD_DIR) && \
ruby $(UNITY_BIN_DIR)/parse_output.rb -xml \
$(BUILD_DIR)/unit_test_report.txt
run_col : $(UNITS) zero_coverage | directories
for f in $(BIN_DIR)/*; do \
ruby -r $(UNITY_BIN_DIR)/colour_reporter.rb -e "report('`$${f}`')"; done
run_formatted : $(UNITS) zero_coverage | directories
for f in $(BIN_DIR)/*; do \
$${f} > $(BUILD_DIR)/output; \
ruby $(UNITY_BIN_DIR)/parse_output.rb $(BUILD_DIR)/output ; \
done
run_col_formatted : $(UNITS) zero_coverage | directories
for f in $(BIN_DIR)/*; do \
$${f} > $(BUILD_DIR)/output; \
ruby -r $(UNITY_BIN_DIR)/colour_reporter.rb \
-e "report('$$(ruby $(UNITY_BIN_DIR)/parse_output.rb \
$(BUILD_DIR)/output)')"; \
done
zero_coverage :
lcov --zerocounters --directory $(BUILD_DIR)
coverage : run_col
lcov --base-directory . --directory . -c --rc lcov_branch_coverage=1 \
--rc genhtml_branch_coverage=1 -o $(BUILD_DIR)/cmock_test.info
genhtml $(BUILD_DIR)/cmock_test.info --branch-coverage \
--output-directory $(COVERAGE_DIR)