Skip to content

Commit

Permalink
Try code coverage in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ckormanyos committed May 30, 2022
1 parent 965728d commit a8bf73e
Show file tree
Hide file tree
Showing 8 changed files with 342 additions and 15 deletions.
114 changes: 114 additions & 0 deletions .gcov/make/make_gcov_01_generic.gmk
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# ------------------------------------------------------------------------------
# Copyright Christopher Kormanyos 2022.
# Distributed under the Boost Software License,
# Version 1.0. (See accompanying file LICENSE_1_0.txt
# or copy at http://www.boost.org/LICENSE_1_0.txt)
# ------------------------------------------------------------------------------

PATH_MAKE = $(CURDIR)
PATH_PRJ = $(PATH_MAKE)/../..
PATH_SRC = $(PATH_PRJ)
PATH_BIN = $(PATH_MAKE)/bin
PATH_ERR = $(PATH_MAKE)/err
PATH_OBJ = $(PATH_MAKE)/obj

CAT = cat
GNUECHO = echo
LS = ls
MKDIR = mkdir
GCOV = gcov
LCOV = lcov
GENHTML = genhtml
RM = rm
SED = sed

include make_gcov_02_files.gmk
include make_gcov_03_flags.gmk

FILES_ALL = $(FILES_PRJ)
FILES_O = $(addprefix $(PATH_OBJ)/, $(notdir $(addsuffix .o, $(FILES_ALL))))
FILES_GCOV = $(addprefix $(PATH_OBJ)/, $(notdir $(addsuffix .gcov, $(FILES_ALL))))

# ------------------------------------------------------------------------------
# VPATH definition: VPATH is required for make to find the source files.
# ------------------------------------------------------------------------------
VPATH := $(sort $(dir $(FILES_ALL)))


# ------------------------------------------------------------------------------
# Executable file:
# ------------------------------------------------------------------------------

.PHONY: $(PATH_BIN)/wide_integer.exe
$(PATH_BIN)/wide_integer.exe: $(FILES_O)
# Link coverage-instrumented executable
@$(GNUECHO) +++ link object files to $(PATH_BIN)/wide_integer.exe
@$(CC) -x none $(CXXFLAGS) $(FILES_O) -o $(PATH_BIN)/wide_integer.exe
@$(GNUECHO)


# ------------------------------------------------------------------------------
# Main dependency:
# Compile all files and link them.
# Run gcov and get results.
# (See also https://github.com/codecov/example-cpp11-cmake)
# ------------------------------------------------------------------------------

.PHONY: gcov
gcov: $(PATH_BIN)/wide_integer.exe
# Obtain results
@$(GNUECHO) +++ execute $(PATH_BIN)/wide_integer.exe
@$(PATH_BIN)/wide_integer.exe
@$(GNUECHO)
@$(GNUECHO) +++ running gcov
@$(GCOV) $(GCOV_FLAGS) $(addsuffix .cpp,$(FILES_PRJ))
@$(GNUECHO)
@$(GNUECHO) +++ running lcov
@$(LCOV) $(LCOV_BRANCH) -c --directory obj --output-file coverage_unfiltered.info
@$(LCOV) $(LCOV_BRANCH) --remove coverage_unfiltered.info $(LCOV_REMOVES) --output-file coverage.info
@$(GNUECHO)
@$(GNUECHO) +++ running genhtml
@$(GENHTML) coverage.info $(LCOV_BRANCH) --demangle-cpp --output-directory $(PATH_BIN)/report
@$(GNUECHO)

# ------------------------------------------------------------------------------
# Clean temporary files.
# ------------------------------------------------------------------------------

.PHONY: clean
clean:
# creating output directories
@$(GNUECHO) +++ cleaning output directories
@-$(RM) -rf $(PATH_BIN)* || uname -r
@-$(RM) -rf $(PATH_ERR)* || uname -r
@-$(RM) -rf $(PATH_OBJ)* || uname -r
@-$(RM) -f *.gcov || uname -r
@-$(RM) -f coverage* || uname -r
@$(GNUECHO)


# ------------------------------------------------------------------------------
# Prepare the gcov build.
# ------------------------------------------------------------------------------

.PHONY: prepare
prepare: clean
@$(GNUECHO) +++ creating output directories
@-$(MKDIR) -p $(PATH_BIN)
@-$(MKDIR) -p $(PATH_ERR)
@-$(MKDIR) -p $(PATH_OBJ)
@$(GNUECHO)
@$(GNUECHO) +++ print gcov version
@$(GCOV) --version
@$(GNUECHO)
@$(GNUECHO) +++ print include paths
@$(GNUECHO) $(C_INCLUDES)
@$(GNUECHO)

# ------------------------------------------------------------------------------
# pattern rule for compilation of cpp-files
# ------------------------------------------------------------------------------
$(PATH_OBJ)/%.o : %.cpp
@-$(GNUECHO) +++ compiling: $(notdir $<) to $(notdir $(PATH_OBJ)/$(basename $(@F)).o)
@-$(CC) $(CXXFLAGS) -x c++ -c $(C_INCLUDES) $(C_DEFINES) $< -o $(PATH_OBJ)/$(basename $(@F)).o 2> $(PATH_ERR)/$(basename $(@F)).err
@-$(SED) -e 's|.h:\([0-9]*\),|.h(\1) :|' -e 's|:\([0-9]*\):|(\1) :|' $(PATH_ERR)/$(basename $(@F)).err
36 changes: 36 additions & 0 deletions .gcov/make/make_gcov_02_files.gmk
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# ------------------------------------------------------------------------------
# Copyright Christopher Kormanyos 2022.
# Distributed under the Boost Software License,
# Version 1.0. (See accompanying file LICENSE_1_0.txt
# or copy at http://www.boost.org/LICENSE_1_0.txt)
# ------------------------------------------------------------------------------

FILES_PRJ = $(PATH_SRC)/test/test \
$(PATH_SRC)/test/test_uintwide_t_boost_backend \
$(PATH_SRC)/test/test_uintwide_t_edge_cases \
$(PATH_SRC)/test/test_uintwide_t_examples \
$(PATH_SRC)/test/test_uintwide_t_float_convert \
$(PATH_SRC)/test/test_uintwide_t_int_convert \
$(PATH_SRC)/test/test_uintwide_t_n_base \
$(PATH_SRC)/test/test_uintwide_t_n_binary_ops_base \
$(PATH_SRC)/test/test_uintwide_t_spot_values \
$(PATH_SRC)/examples/example000a_builtin_convert \
$(PATH_SRC)/examples/example000_numeric_limits \
$(PATH_SRC)/examples/example001_mul_div \
$(PATH_SRC)/examples/example001a_div_mod \
$(PATH_SRC)/examples/example002_shl_shr \
$(PATH_SRC)/examples/example003_sqrt \
$(PATH_SRC)/examples/example003a_cbrt \
$(PATH_SRC)/examples/example004_rootk_pow \
$(PATH_SRC)/examples/example005_powm \
$(PATH_SRC)/examples/example005a_pow_factors_of_p99 \
$(PATH_SRC)/examples/example006_gcd \
$(PATH_SRC)/examples/example007_random_generator \
$(PATH_SRC)/examples/example008_miller_rabin_prime \
$(PATH_SRC)/examples/example008a_miller_rabin_prime \
$(PATH_SRC)/examples/example009_timed_mul \
$(PATH_SRC)/examples/example009a_timed_mul_4_by_4 \
$(PATH_SRC)/examples/example009b_timed_mul_8_by_8 \
$(PATH_SRC)/examples/example010_uint48_t \
$(PATH_SRC)/examples/example011_uint24_t \
$(PATH_SRC)/examples/example012_rsa_crypto
80 changes: 80 additions & 0 deletions .gcov/make/make_gcov_03_flags.gmk
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# ------------------------------------------------------------------------------
# Copyright Christopher Kormanyos 2022.
# Distributed under the Boost Software License,
# Version 1.0. (See accompanying file LICENSE_1_0.txt
# or copy at http://www.boost.org/LICENSE_1_0.txt)
# ------------------------------------------------------------------------------

BOOST_ROOT_FOR_GCOV = /mnt/c/boost/boost_1_78_0
CC = g++
STD = c++11
ALL_COV = 0

ifneq ($(MY_BOOST_ROOT),)
BOOST_ROOT_FOR_GCOV := $(MY_BOOST_ROOT)
endif

ifneq ($(MY_CC),)
CC := $(MY_CC)
endif

ifneq ($(MY_STD),)
STD := $(MY_STD)
endif

ifneq ($(MY_STD),)
STD := $(MY_STD)
endif

ifneq ($(MY_ALL_COV),)
ALL_COV := $(MY_ALL_COV)
endif

CXXFLAGS = -march=native \
-mtune=native \
-O2 \
-Wall \
-Wextra \
-Wconversion \
-Wsign-conversion \
-std=$(STD) \
-pthread \
-lpthread \
-fno-inline-functions \
-fprofile-arcs \
-ftest-coverage

C_DEFINES = WIDE_INTEGER_HAS_COVERAGE \
WIDE_INTEGER_HAS_LIMB_TYPE_UINT64

C_INCLUDES = $(PATH_SRC) \
$(BOOST_ROOT_FOR_GCOV)

C_DEFINES :=$(addprefix -D,$(C_DEFINES))
C_INCLUDES :=$(addprefix -I,$(C_INCLUDES))

GCOV_FLAGS = --object-directory obj \
--demangled-names


# ------------------------------------------------------------------------------
# All gcov flags: The GCOV_FLAGS below are equivalent to -abcfu
# ------------------------------------------------------------------------------

ifneq ($(ALL_COV),0)
GCOV_FLAGS := $(GCOV_FLAGS) \
--all-blocks \
--branch-counts \
--branch-probabilities \
--function-summaries \
--unconditional-branches
endif

LCOV_BRANCH =

ifneq ($(ALL_COV),0)
LCOV_BRANCH := --rc lcov_branch_coverage=1
endif

LCOV_REMOVES = '/usr/*' \
'*boost/*'
62 changes: 62 additions & 0 deletions .github/workflows/wide_integer_codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# ------------------------------------------------------------------------------
# Copyright Christopher Kormanyos 2022.
# Distributed under the Boost Software License,
# Version 1.0. (See accompanying file LICENSE_1_0.txt
# or copy at http://www.boost.org/LICENSE_1_0.txt)
# ------------------------------------------------------------------------------

name: wide_integer_codecov
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
jobs:
gnumake-gcc-gcov-native:
runs-on: ubuntu-20.04
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
standard: [ c++11 ]
compiler: [ g++ ]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: '0'
- name: update-tools
run: sudo apt install lcov
- name: clone-submods-bootstrap-headers-boost-develop
run: |
git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root
cd ../boost-root
git submodule update --init tools
git submodule update --init libs/config
git submodule update --init libs/multiprecision
./bootstrap.sh
./b2 headers
- name: gnumake-gcc-gcov-native
run: |
grep BOOST_VERSION ../boost-root/boost/version.hpp
cd .gcov/make
echo "build and run gcov/lcov/genhtml"
echo "make prepare -f make_gcov_01_generic.gmk MY_ALL_COV=0 MY_BOOST_ROOT=../../../boost-root MY_CC=${{ matrix.compiler }} MY_STD=${{ matrix.standard }}"
echo
make prepare -f make_gcov_01_generic.gmk MY_ALL_COV=0 MY_BOOST_ROOT=../../../boost-root MY_CC=${{ matrix.compiler }} MY_STD=${{ matrix.standard }}
echo
echo "make gcov -f make_gcov_01_generic.gmk --jobs=8 MY_ALL_COV=0 MY_BOOST_ROOT=../../../boost-root MY_CC=${{ matrix.compiler }} MY_STD=${{ matrix.standard }}"
echo
make gcov -f make_gcov_01_generic.gmk --jobs=8 MY_ALL_COV=0 MY_BOOST_ROOT=../../../boost-root MY_CC=${{ matrix.compiler }} MY_STD=${{ matrix.standard }}
echo
echo "return to wide-integer root directory"
cd ../..
- name: upload-codecov
uses: codecov/codecov-action@v2
with:
files: .gcov/make/coverage.info
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
functionalities: fix
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[![Coverity Scan](https://scan.coverity.com/projects/24742/badge.svg)](https://scan.coverity.com/projects/ckormanyos-wide-integer)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ckormanyos_wide-integer&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=ckormanyos_wide-integer)
[![Boost Software License 1.0](https://img.shields.io/badge/license-BSL%201.0-blue.svg)](https://github.com/ckormanyos/wide-integer/blob/master/LICENSE_1_0.txt)
[![GitHub commit activity](https://img.shields.io/github/commit-activity/y/ckormanyos/wide-integer)](https://img.shields.io/github/commit-activity/y/ckormanyos/wide-integer)
[![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/ckormanyos/wide-integer)](https://github.com/ckormanyos/wide-integer)

Wide-integer implements a generic C++ template for extended width
Expand Down
Loading

0 comments on commit a8bf73e

Please sign in to comment.