Skip to content

Commit fc36466

Browse files
authored
test: add target to gen coverage report (#295)
* test: add target to gen coverage report * test: show branch coverage * ci: setup codecov * Readme: add codecov badge * ci: upload coverage report * test: add note for CODE_COVERAGE flag
1 parent d3be5df commit fc36466

File tree

5 files changed

+57
-1
lines changed

5 files changed

+57
-1
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,19 @@ jobs:
4242
install: base-devel mingw-w64-${{matrix.env}}-toolchain
4343
- run: make
4444
- run: make test
45+
code-coverage:
46+
runs-on: ubuntu-latest
47+
steps:
48+
- uses: actions/checkout@v4
49+
- name: Setup LCOV
50+
uses: hrishikesh-kadam/setup-lcov@v1
51+
- name: Build and Run tests
52+
run: make coverage -j
53+
- name: Upload coverage to Codecov
54+
uses: codecov/codecov-action@v3
55+
with:
56+
files: ./cov-html/libopenlibm.info
57+
- uses: actions/upload-artifact@v4
58+
with:
59+
name: code-coverage-report
60+
path: ./cov-html/

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@
55
*.so*
66
*.dylib*
77
*.pc
8+
9+
# code coverage
10+
cov-html/
11+
*.gcda
12+
*.gcno

Make.inc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ else
2121
pkgconfigdir ?= $(libdir)/pkgconfig
2222
endif
2323

24+
# Build with Code Coverage
25+
# Only test with Ubuntu + gcc + lcov, may not work for other platform.
26+
# deps: https://github.com/linux-test-project/lcov
27+
# You don't need to set this flag manually, `make coverage` will do it for you.
28+
# Just Run: make clean && make coverage -j
29+
CODE_COVERAGE ?= 0
30+
2431
USEGCC ?= 1
2532
USECLANG ?= 0
2633

@@ -162,6 +169,12 @@ LONG_DOUBLE_NOT_DOUBLE := 1
162169
endif
163170
endif
164171

172+
ifeq ($(CODE_COVERAGE),1)
173+
CFLAGS_add += -g -O0 --coverage
174+
LDFLAGS_add += --coverage
175+
endif # CODE_COVERAGE==1
176+
177+
165178
%.c.o: %.c
166179
$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_add) -c $< -o $@
167180

Makefile

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,29 @@ test/test-double: libopenlibm.$(OLM_MAJOR_MINOR_SHLIB_EXT)
8080
test/test-float: libopenlibm.$(OLM_MAJOR_MINOR_SHLIB_EXT)
8181
$(MAKE) -C test test-float
8282

83-
clean:
83+
COVERAGE_DIR:=cov-html
84+
COVERAGE_FILE:=$(COVERAGE_DIR)/libopenlibm.info
85+
# Gen cov report with: make clean && make coverage -j
86+
coverage: clean-coverage
87+
mkdir $(COVERAGE_DIR)
88+
$(MAKE) test CODE_COVERAGE=1
89+
lcov -d amd64 -d bsdsrc -d ld80 -d src \
90+
--rc lcov_branch_coverage=1 --capture --output-file $(COVERAGE_FILE)
91+
genhtml --legend --branch-coverage \
92+
--title "Openlibm commit `git rev-parse HEAD`" \
93+
--output-directory $(COVERAGE_DIR)/ \
94+
$(COVERAGE_FILE)
95+
96+
# Zero coverage statistics and Delete report
97+
clean-coverage:
98+
-lcov -d amd64 -d bsdsrc -d ld80 -d src --zerocounters
99+
rm -f ./*/*.gcda
100+
rm -rf $(COVERAGE_DIR)/
101+
102+
clean: clean-coverage
84103
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
85104
rm -f libopenlibm.a libopenlibm.*$(SHLIB_EXT)*
105+
rm -f ./*/*.gcno
86106
$(MAKE) -C test clean
87107

88108
openlibm.pc: openlibm.pc.in Make.inc Makefile

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# OpenLibm
22

3+
[![codecov](https://codecov.io/gh/JuliaMath/openlibm/graph/badge.svg?token=eTAdN7d9cg)](https://codecov.io/gh/JuliaMath/openlibm)
4+
35
[OpenLibm](https://openlibm.org/) is an effort to have a high quality, portable, standalone
46
C mathematical library ([`libm`](http://en.wikipedia.org/wiki/libm)).
57
It can be used standalone in applications and programming language

0 commit comments

Comments
 (0)