Skip to content

Commit

Permalink
Getting codecov to work on every PRs (istio#3673)
Browse files Browse the repository at this point in the history
* Getting code coverage to work

* Fixed typo in codecov script name

* Print summary at the end

* Add a skip file

* Remove codecov from flaky

* Merging steps for testing

Skipping security integration tests
  • Loading branch information
sebastienvas authored Feb 26, 2018
1 parent 9323eb9 commit fe9a593
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 109 deletions.
36 changes: 10 additions & 26 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -314,31 +314,16 @@ jobs:
steps:
- checkout
- run: make submodule-sync
- run: mkdir -p /tmp/coverage
- run:
name: Running Kubernetes API Server standalone
command: make localTestEnv
- run: cd /go/src/istio.io/istio; maxprocs=6 bin/parallel-codecov.sh pilot
- run:
command: |
bash <(curl -s https://codecov.io/bash) -F pilot
- run: cd /go/src/istio.io/istio; maxprocs=6 bin/parallel-codecov.sh security/pkg
- run: cd /go/src/istio.io/istio; maxprocs=6 bin/parallel-codecov.sh security/cmd
- run:
command: |
bash <(curl -s https://codecov.io/bash) -F security
- run: cd /go/src/istio.io/istio; maxprocs=6 bin/parallel-codecov.sh broker
- run:
name: Starting Kubernetes API Server standalone and running tests
command: |
bash <(curl -s https://codecov.io/bash) -F broker
- run: cd /go/src/istio.io/istio; maxprocs=6 bin/parallel-codecov.sh mixer
- run:
command: |
bash <(curl -s https://codecov.io/bash) -F mixer
- run: cd /go/src/istio.io/istio; maxprocs=6 bin/parallel-codecov.sh pkg
make localTestEnv
cd /go/src/istio.io/istio
MAXPROCS=6 bin/codecov.sh
- run:
command: |
bash <(curl -s https://codecov.io/bash) -F common
name: Uploading code coverage to codecov.io
when: always
command: bash <(curl -s https://codecov.io/bash)

test:
<<: *defaults
Expand Down Expand Up @@ -583,17 +568,13 @@ workflows:
- build:
requires:
- dependencies
- codecov:
requires:
- build
- racetest:
requires:
- dependencies
- e2e-mixer:
requires:
- build


all:
jobs:
- dependencies
Expand All @@ -606,6 +587,9 @@ workflows:
- test:
requires:
- dependencies
- codecov:
requires:
- build
- e2e-pilot:
requires:
- build
Expand Down
4 changes: 3 additions & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
coverage:
precision: 0
round: up
ignore:
- "**/*.pb.go" # Auto-generated proto files
- "tests/" # Test infrastructure coverage does not affect core coverage
Expand All @@ -10,4 +12,4 @@ coverage:
- "release/"
- "samples/"
- "**/prow/"

96 changes: 79 additions & 17 deletions bin/codecov.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,91 @@
#!/usr/bin/env bash
set -e
set -u
SCRIPTPATH=$( cd "$(dirname "$0")" ; pwd -P )
ROOTDIR=$(dirname $SCRIPTPATH)
cd $ROOTDIR

echo "Code coverage test"
SCRIPTPATH="$(cd "$(dirname "$0")" ; pwd -P)"
ROOTDIR="$(dirname ${SCRIPTPATH})"
DIR="./..."
CODECOV_SKIP="${ROOTDIR}/codecov.skip"
SKIPPED_TESTS_GREP_ARGS=

OUT=coverage.txt
PROF=profile.out
if [ "${1:-}" != "" ]; then
DIR="./$1/..."
fi

echo "" > ${OUT}
for d in $(go list ./... | grep -v vendor); do
#FIXME remove mixer tools exclusions after tests can be run without bazel
if [[ $d == "istio.io/istio/tests"* || \
$d == "istio.io/istio/mixer/tools/codegen"* ]];then
echo "Skipped $d"
continue
COVERAGEDIR="$(mktemp -d /tmp/XXXXX.coverage)"
mkdir -p $COVERAGEDIR

# coverage test needs to run one package per command.
# This script runs nproc/2 in parallel.
# Script fails if any one of the tests fail.

# half the number of cpus seem to saturate
if [[ -z ${MAXPROCS:-} ]];then
MAXPROCS=$[$(getconf _NPROCESSORS_ONLN)/2]
fi
PIDS=()
FAILED_TESTS=()

declare -a PKGS

function code_coverage() {
local filename="$(echo ${1} | tr '/' '-')"
go test -coverprofile=${COVERAGEDIR}/${filename}.txt ${1} &
local pid=$!
PKGS[${pid}]=${1}
PIDS+=(${pid})
}

function wait_for_proc() {
local num=$(jobs -p | wc -l)
while [ ${num} -gt ${MAXPROCS} ]; do
sleep 2
num=$(jobs -p|wc -l)
done
}

function join_procs() {
local p
for p in ${PIDS[@]}; do
if ! wait ${p}; then
FAILED_TESTS+=(${PKGS[${p}]})
fi
done
}

function parse_skipped_tests() {
while read entry; do
if [[ "${SKIPPED_TESTS_GREP_ARGS}" != '' ]]; then
SKIPPED_TESTS_GREP_ARGS+='\|'
fi
SKIPPED_TESTS_GREP_ARGS+="\(${entry}\)"
done < "${CODECOV_SKIP}"
}

cd "${ROOTDIR}"

go test -coverprofile=${PROF} $d
parse_skipped_tests

if [ -f ${PROF} ]; then
cat ${PROF} >> ${OUT}
rm ${PROF}
echo "Code coverage test (concurrency ${MAXPROCS})"
for P in $(go list ${DIR} | grep -v vendor); do
#FIXME remove mixer tools exclusion after tests can be run without bazel
if echo ${P} | grep -q "${SKIPPED_TESTS_GREP_ARGS}"; then
echo "Skipped ${P}"
continue
fi
code_coverage "${P}"
wait_for_proc
done

join_procs

touch "${COVERAGEDIR}/empty"
cat "${COVERAGEDIR}"/* > coverage.txt

if [[ -n ${FAILED_TESTS:-} ]]; then
echo "The following tests failed"
for T in ${FAILED_TESTS[@]}; do
echo "FAIL: $T"
done
exit 1
fi
65 changes: 0 additions & 65 deletions bin/parallel-codecov.sh

This file was deleted.

3 changes: 3 additions & 0 deletions codecov.skip
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
istio.io/istio/tests*
istio.io/istio/mixer/tools/codegen*
istio.io/istio/security/tests/integration*

0 comments on commit fe9a593

Please sign in to comment.