From 91c968cc0a9469b7d5091b0a592b59be3f6573da Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Tue, 16 Jan 2024 19:23:34 -0600 Subject: [PATCH 1/6] test: add target to gen coverage report --- .gitignore | 5 +++++ Make.inc | 9 +++++++++ Makefile | 18 +++++++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e7e0c44f..8e1c6cbb 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,8 @@ *.so* *.dylib* *.pc + +# code coverage +cov-html/ +*.gcda +*.gcno diff --git a/Make.inc b/Make.inc index 000ec53f..659ae936 100644 --- a/Make.inc +++ b/Make.inc @@ -21,6 +21,9 @@ else pkgconfigdir ?= $(libdir)/pkgconfig endif +# Build with Code Coverage +CODE_COVERAGE ?= 0 + USEGCC ?= 1 USECLANG ?= 0 @@ -162,6 +165,12 @@ LONG_DOUBLE_NOT_DOUBLE := 1 endif endif +ifeq ($(CODE_COVERAGE),1) +CFLAGS_add += -g -O0 --coverage +LDFLAGS_add += --coverage +endif # CODE_COVERAGE==1 + + %.c.o: %.c $(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_add) -c $< -o $@ diff --git a/Makefile b/Makefile index d7ff9e19..08371f9f 100644 --- a/Makefile +++ b/Makefile @@ -80,9 +80,25 @@ test/test-double: libopenlibm.$(OLM_MAJOR_MINOR_SHLIB_EXT) test/test-float: libopenlibm.$(OLM_MAJOR_MINOR_SHLIB_EXT) $(MAKE) -C test test-float -clean: +COVERAGE_DIR:=cov-html +COVERAGE_FILE:=$(COVERAGE_DIR)/libopenlibm.info +# Gen cov report with: make clean && make coverage -j +coverage: clean-coverage + mkdir $(COVERAGE_DIR) + $(MAKE) test CODE_COVERAGE=1 + lcov -d amd64 -d bsdsrc -d ld80 -d src --capture --output-file $(COVERAGE_FILE) + genhtml --output-directory $(COVERAGE_DIR)/ $(COVERAGE_FILE) + +# Zero coverage statistics and Delete report +clean-coverage: + -lcov -d amd64 -d bsdsrc -d ld80 -d src --zerocounters + rm -f ./*/*.gcda + rm -rf $(COVERAGE_DIR)/ + +clean: clean-coverage rm -f aarch64/*.o amd64/*.o arm/*.o bsdsrc/*.o i387/*.o loongarch64/*.o ld80/*.o ld128/*.o src/*.o powerpc/*.o mips/*.o s390/*.o riscv64/*.o rm -f libopenlibm.a libopenlibm.*$(SHLIB_EXT)* + rm -f ./*/*.gcno $(MAKE) -C test clean openlibm.pc: openlibm.pc.in Make.inc Makefile From b11910968d89d99e7104d39f82c8307c5a335e0f Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Tue, 16 Jan 2024 19:38:27 -0600 Subject: [PATCH 2/6] test: show branch coverage --- Makefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 08371f9f..17e03a07 100644 --- a/Makefile +++ b/Makefile @@ -86,8 +86,12 @@ COVERAGE_FILE:=$(COVERAGE_DIR)/libopenlibm.info coverage: clean-coverage mkdir $(COVERAGE_DIR) $(MAKE) test CODE_COVERAGE=1 - lcov -d amd64 -d bsdsrc -d ld80 -d src --capture --output-file $(COVERAGE_FILE) - genhtml --output-directory $(COVERAGE_DIR)/ $(COVERAGE_FILE) + lcov -d amd64 -d bsdsrc -d ld80 -d src \ + --rc lcov_branch_coverage=1 --capture --output-file $(COVERAGE_FILE) + genhtml --legend --branch-coverage \ + --title "Openlibm commit `git rev-parse HEAD`" \ + --output-directory $(COVERAGE_DIR)/ \ + $(COVERAGE_FILE) # Zero coverage statistics and Delete report clean-coverage: From 87e6c031426082b443feb8b2e5dd5c7e5cfa326c Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Tue, 16 Jan 2024 20:11:01 -0600 Subject: [PATCH 3/6] ci: setup codecov --- .github/workflows/ci.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6517a2c0..b9f0c9c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,3 +42,15 @@ jobs: install: base-devel mingw-w64-${{matrix.env}}-toolchain - run: make - run: make test + code-coverage: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup LCOV + uses: hrishikesh-kadam/setup-lcov@v1 + - name: Build and Run tests + run: make coverage -j + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + files: ./cov-html/libopenlibm.info From c1106816586f11f86d84caa2483bd224ea6c7fad Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Tue, 16 Jan 2024 20:17:10 -0600 Subject: [PATCH 4/6] Readme: add codecov badge --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index da75f31d..b6cd376e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # OpenLibm +[![codecov](https://codecov.io/gh/JuliaMath/openlibm/graph/badge.svg?token=eTAdN7d9cg)](https://codecov.io/gh/JuliaMath/openlibm) + [OpenLibm](https://openlibm.org/) is an effort to have a high quality, portable, standalone C mathematical library ([`libm`](http://en.wikipedia.org/wiki/libm)). It can be used standalone in applications and programming language From 6a595d7ae7a80122f94999fe506362a3f26f02d1 Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Tue, 16 Jan 2024 20:19:31 -0600 Subject: [PATCH 5/6] ci: upload coverage report --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b9f0c9c3..7c56406d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,3 +54,7 @@ jobs: uses: codecov/codecov-action@v3 with: files: ./cov-html/libopenlibm.info + - uses: actions/upload-artifact@v4 + with: + name: code-coverage-report + path: ./cov-html/ From b8dce32ad47a50d1d107e94bdd22a2ed0e760447 Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Tue, 16 Jan 2024 20:53:54 -0600 Subject: [PATCH 6/6] test: add note for CODE_COVERAGE flag --- Make.inc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Make.inc b/Make.inc index 659ae936..c0536a1c 100644 --- a/Make.inc +++ b/Make.inc @@ -22,6 +22,10 @@ pkgconfigdir ?= $(libdir)/pkgconfig endif # Build with Code Coverage +# Only test with Ubuntu + gcc + lcov, may not work for other platform. +# deps: https://github.com/linux-test-project/lcov +# You don't need to set this flag manually, `make coverage` will do it for you. +# Just Run: make clean && make coverage -j CODE_COVERAGE ?= 0 USEGCC ?= 1