Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add target to gen coverage report #295

Merged
merged 6 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,19 @@ 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
- uses: actions/upload-artifact@v4
with:
name: code-coverage-report
path: ./cov-html/
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@
*.so*
*.dylib*
*.pc

# code coverage
cov-html/
*.gcda
*.gcno
13 changes: 13 additions & 0 deletions Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ else
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
USECLANG ?= 0

Expand Down Expand Up @@ -162,6 +169,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 $@

Expand Down
22 changes: 21 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,29 @@ 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 \
--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:
-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
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down