Skip to content

Commit

Permalink
Include Codecov in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth committed Nov 14, 2023
1 parent e462f0d commit f5f191a
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 37 deletions.
13 changes: 13 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
coverage:
status:
project:
default:
informational: true
patch:
default:
informational: true
comment:
require_base: false
require_changes: false
require_head: true
hide_project_coverage: false
24 changes: 24 additions & 0 deletions .github/workflows/codecov-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Code Coverage
on:
push:
branches: [ '*' ]
pull_request:
branches: [ '*' ]
concurrency:
group: code-cov-${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
codecov-ci:
runs-on: ubuntu-latest
steps:
- name: Install lcov
run: sudo apt-get -y install lcov
- uses: actions/checkout@master
- name: Run Code Coverage Build
run: ./util/generate-coverage.sh ${{ runner.temp }}/build
- name: Upload code coverage report to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
file: ${{ runner.temp }}/build/coverage.info
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,9 @@ if(UBSAN)
endif()

if(GCOV)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
endif()

if(KEEP_ASM_LOCAL_SYMBOLS)
Expand Down
64 changes: 29 additions & 35 deletions util/generate-coverage.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/usr/bin/env bash
# Copyright (c) 2016, Google Inc.
#
# Permission to use, copy, modify, and/or distribute this software for any
Expand All @@ -15,44 +15,38 @@

set -xe

SRC=$PWD
SRC=$(pwd)

BUILD=$(mktemp -d '/tmp/boringssl.XXXXXX')
BUILD_SRC=$(mktemp -d '/tmp/boringssl-src.XXXXXX')
LCOV=$(mktemp -d '/tmp/boringssl-lcov.XXXXXX')

if [ -n "$1" ]; then
LCOV=$(readlink -f "$1")
mkdir -p "$LCOV"
# Sanity check
DIRNAME=$(basename -- "${SRC}")
if [[ "${DIRNAME}" != 'aws-lc' ]]; then
echo "Script must be executed from aws-lc directory"
exit 1
fi

cd "$BUILD"
cmake "$SRC" -GNinja -DGCOV=1
ninja

cp -r "$SRC/crypto" "$SRC/include" "$SRC/ssl" "$SRC/tool" \
"$BUILD_SRC"
cp -r "$BUILD"/* "$BUILD_SRC"
mkdir "$BUILD/callgrind/"

cd "$SRC"
go run "$SRC/util/all_tests.go" -build-dir "$BUILD" -callgrind -num-workers 16
util/generate-asm-lcov.py "$BUILD/callgrind" "$BUILD" > "$BUILD/asm.info"

go run "util/all_tests.go" -build-dir "$BUILD"
BUILD="$1"
if [ -n "$BUILD" ]; then
if [ ! -e "$BUILD" ]; then
mkdir -p "$BUILD"
fi
BUILD=$(readlink -f "$BUILD")
else
echo "Must specify a build directory."
exit 1
fi

cd "$SRC/ssl/test/runner"
go test -shim-path "$BUILD/ssl/test/bssl_shim" -num-workers 1
cmake -DGCOV=1 -DDISABLE_PERL=1 -DBUILD_TESTING=1 -DBUILD_LIBSSL=1 -DCMAKE_BUILD_TYPE=Debug -S "${SRC}" -B "${BUILD}"
cmake --build "${BUILD}" --target all_tests
cmake --build "${BUILD}" --target run_tests

cd "$LCOV"
lcov -c -d "$BUILD" -b "$BUILD" -o "$BUILD/lcov.info"
lcov -r "$BUILD/lcov.info" -o "$BUILD/filtered.info" "*_test.c" "*_test.cc" "*/third_party/googletest/*"
cat "$BUILD/filtered.info" "$BUILD/asm.info" > "$BUILD/final.info"
sed -i "s;$BUILD;$BUILD_SRC;g" "$BUILD/final.info"
sed -i "s;$SRC;$BUILD_SRC;g" "$BUILD/final.info"
genhtml -p "$BUILD_SRC" "$BUILD/final.info"
#TODO: Use callgrind
#mkdir "$BUILD/callgrind/"
#go run "$SRC/util/all_tests.go" -build-dir "$BUILD" -callgrind -num-workers 16

rm -rf "$BUILD"
rm -rf "$BUILD_SRC"
shopt -s globstar

xdg-open index.html
pushd "${BUILD}"
gcov --source-prefix "${SRC}" **/*.gcda
# The duplicate "unused" in "--ignore-errors inconsistent,unused,unused" is not a typo
lcov --capture --exclude "/Applications/*" --exclude "/usr/*" --exclude "/lib/*" --directory . --ignore-errors inconsistent,unused,unused --output-file coverage.info
popd

0 comments on commit f5f191a

Please sign in to comment.