From 328742f9e2a557e8fff61039a04b9a85d257b373 Mon Sep 17 00:00:00 2001 From: nshaheed Date: Thu, 21 Nov 2024 15:57:08 -0800 Subject: [PATCH] add code coverage report make option (#480) --- .gitignore | 7 +++++++ src/core/makefile | 7 +++++++ src/makefile | 19 ++++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3cf3a37a0..b23a80c60 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,10 @@ xcshareddata/ .vscode .vs chuck.vcxproj.user + +# code coverage +*.gcov +*.gcda +*.gcno +*.info +/report/ diff --git a/src/core/makefile b/src/core/makefile index f285fb01e..7e702a79a 100644 --- a/src/core/makefile +++ b/src/core/makefile @@ -18,6 +18,13 @@ LD=g++ CFLAGS+=-I. -Ilo +ifneq ($(COVERAGE_REPORT),) +CFLAGS+=-fprofile-arcs +CFLAGS+=-ftest-coverage +LDFLAGS+=-lgcov +LDFLAGS+=--coverage +endif + ifneq ($(CHUCK_STAT),) CFLAGS+= -D__CHUCK_STAT_TRACK__ endif diff --git a/src/makefile b/src/makefile index 157cb8fa9..c4cf1c5ac 100644 --- a/src/makefile +++ b/src/makefile @@ -105,6 +105,16 @@ LD=$(CXX) # note: to compile with a specific c++ version (e.g., c++11) add: -std=c++11 CFLAGS+=-I. -I$(CK_CORE_DIR) -I$(CK_CORE_DIR)/lo +# Code coverage + +# enable chuck debug macros? +ifneq ($(COVERAGE_REPORT),) +CFLAGS+=-fprofile-arcs +CFLAGS+=-ftest-coverage +LDFLAGS+=-lgcov +LDFLAGS+=--coverage +endif + # track stats? ifneq ($(CHUCK_STAT),) CFLAGS+= -D__CHUCK_STAT_TRACK__ @@ -279,6 +289,12 @@ $(CXXOBJS_HOST): %.o: %.cpp test: @make -C test +###################### GENERATE CODE COVERAGE REPORT ########################### +.PHONY: coverage +coverage: test + lcov --capture --directory . --output-file coverage.info + genhtml coverage.info --output-directory report + ####################### GENERATE API DOCUMENTATION ############################ .PHONY: doc ckdoc @@ -333,7 +349,8 @@ clean-src: $(CK_CORE_DIR)/chuck.tab.h $(CK_CORE_DIR)/chuck.tab.c $(CK_CORE_DIR)/chuck.yy.c \ $(DIST_ROOT)/$(DIST_DIR) $(DIST_ROOT)/$(DIST_DIR){,.tgz,.zip} \ host-web/webchuck/js/webchuck.js host-web/webchuck/js/webchuck.wasm \ - Release Debug + Release Debug \ + @rf -rf report/ */*.gcov */*.gcda */*.gcno */*.info .PHONY: clean clean: clean-src