forked from istio/istio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Getting codecov to work on every PRs (istio#3673)
* 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
1 parent
9323eb9
commit fe9a593
Showing
5 changed files
with
95 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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* |