test: add automatic unit test coverage generation
Using lcov, generate an HTML report via "make coverage-report" describing the coverage of each file. Ideally, this will get added to an automated testing pipeline. Signed-off-by: Max Regan <mgregan2@gmail.com>
This commit is contained in:
50
Makefile
50
Makefile
@@ -1,4 +1,5 @@
|
|||||||
OUT=build
|
OUT=build
|
||||||
|
COV_DIR=$(OUT)/coverage/
|
||||||
SRC_DIR=src
|
SRC_DIR=src
|
||||||
APP_DIR=src/apps/
|
APP_DIR=src/apps/
|
||||||
|
|
||||||
@@ -55,10 +56,8 @@ gbasm: $(OUT)/apps/gbasm
|
|||||||
|
|
||||||
.PHONY: gbasm-test sample-test tests
|
.PHONY: gbasm-test sample-test tests
|
||||||
|
|
||||||
gbasm-test: $(OUT)/apps/gbasm-test
|
TESTS=$(OUT)/apps/gbasm-test $(OUT)/apps/tri-test
|
||||||
sample-test: $(OUT)/apps/sample-test
|
tests: $(TESTS)
|
||||||
tri-test: $(OUT)/apps/tri-test
|
|
||||||
tests: gbasm-test sample-test tri-test
|
|
||||||
|
|
||||||
$(ALL_APPS) $(ALL_OBJS): $(CONFIG)
|
$(ALL_APPS) $(ALL_OBJS): $(CONFIG)
|
||||||
|
|
||||||
@@ -73,7 +72,48 @@ $(APPS): $(OBJS) $$@.o
|
|||||||
@$(shell mkdir -p $(@D))
|
@$(shell mkdir -p $(@D))
|
||||||
@$(CC) $^ $(LDFLAGS) -o $@
|
@$(CC) $^ $(LDFLAGS) -o $@
|
||||||
|
|
||||||
.PHONY: clean realclean
|
|
||||||
|
.PHONY: check cov-report
|
||||||
|
|
||||||
|
define run_tests =
|
||||||
|
@for i in $(TESTS); do \
|
||||||
|
$$i; \
|
||||||
|
if [ $$? -ne 0 ]; then \
|
||||||
|
exit 1; \
|
||||||
|
fi; \
|
||||||
|
done;
|
||||||
|
endef
|
||||||
|
|
||||||
|
.PHONY: check coverage coverage-report
|
||||||
|
|
||||||
|
check: $(TESTS)
|
||||||
|
$(run_tests)
|
||||||
|
|
||||||
|
|
||||||
|
COV_BASE=$(COV_DIR)/cov_base.info
|
||||||
|
.PHONY: $(COV_BASE)
|
||||||
|
|
||||||
|
|
||||||
|
$(COV_BASE):
|
||||||
|
@mkdir -p $(COV_DIR)
|
||||||
|
@lcov -c -i -d $(OUT) -o $(COV_BASE)
|
||||||
|
|
||||||
|
$(COV_DIR)/coverage.info coverage: $(TESTS) $(COV_BASE)
|
||||||
|
@for test in $(TESTS); do \
|
||||||
|
$$test; \
|
||||||
|
lcov -c -d $(OUT) -o $(COV_DIR)/$$(basename $$test).info -t $$(basename $$test); \
|
||||||
|
done
|
||||||
|
lcov $$(for i in $$(ls -1 $(COV_DIR)/*.info); do echo "-a $$i"; done) -o $(COV_DIR)/coverage.info
|
||||||
|
|
||||||
|
coverage-report: coverage
|
||||||
|
@mkdir -p $(COV_DIR)/html/
|
||||||
|
@genhtml --prefix $(PWD) --output-directory=$(COV_DIR)/html $(COV_DIR)/coverage.info
|
||||||
|
|
||||||
|
.PHONY: clean realclean cov-clean
|
||||||
|
cov-clean:
|
||||||
|
@find $(OUT)/ \( -iname *.gcno -o -iname *.gcda \) -delete
|
||||||
|
@rm
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@rm -f $(ALL_OBJS) $(APPS)
|
@rm -f $(ALL_OBJS) $(APPS)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user