diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6517a2c0..7c56406d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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/ 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..c0536a1c 100644 --- a/Make.inc +++ b/Make.inc @@ -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 @@ -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 $@ diff --git a/Makefile b/Makefile index d7ff9e19..17e03a07 100644 --- a/Makefile +++ b/Makefile @@ -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 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