mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #12632 from ptabor/20210119-fix-coverage-report
Fix code coverage measurement
This commit is contained in:
commit
1d73d2e85e
2
Makefile
2
Makefile
@ -177,7 +177,7 @@ docker-test-coverage:
|
||||
$(TMP_DIR_MOUNT_FLAG) \
|
||||
--mount type=bind,source=`pwd`,destination=/go/src/go.etcd.io/etcd \
|
||||
gcr.io/etcd-development/etcd-test:go$(GO_VERSION) \
|
||||
/bin/bash -c "COVERDIR=covdir PASSES='build build_cov cov' ./test.sh 2>&1 | tee docker-test-coverage-$(TEST_SUFFIX).log && /codecov -t 6040de41-c073-4d6f-bbf8-d89256ef31e1"
|
||||
/bin/bash -c "set -o pipefail; (COVERDIR=covdir PASSES='build build_cov cov' ./test.sh 2>&1 | tee docker-test-coverage-$(TEST_SUFFIX).log) && /codecov -t 6040de41-c073-4d6f-bbf8-d89256ef31e1"
|
||||
! egrep "(--- FAIL:|DATA RACE|panic: test timed out|appears to have leaked)" -B50 -A10 docker-test-coverage-$(TEST_SUFFIX).log
|
||||
|
||||
|
||||
|
@ -158,6 +158,10 @@ function run_for_module {
|
||||
)
|
||||
}
|
||||
|
||||
function module_dirs() {
|
||||
echo "api pkg raft client/v2 client/v3 server etcdctl tests ."
|
||||
}
|
||||
|
||||
function modules() {
|
||||
modules=(
|
||||
"${ROOT_MODULE}/api/v3"
|
||||
@ -184,15 +188,9 @@ function modules_exp() {
|
||||
function run_for_modules {
|
||||
local pkg="${PKG:-./...}"
|
||||
if [ -z "${USERMOD}" ]; then
|
||||
run_for_module "api" "$@" "${pkg}" || return "$?"
|
||||
run_for_module "pkg" "$@" "${pkg}" || return "$?"
|
||||
run_for_module "raft" "$@" "${pkg}" || return "$?"
|
||||
run_for_module "client/v2" "$@" "${pkg}" || return "$?"
|
||||
run_for_module "client/v3" "$@" "${pkg}" || return "$?"
|
||||
run_for_module "server" "$@" "${pkg}" || return "$?"
|
||||
run_for_module "etcdctl" "$@" "${pkg}" || return "$?"
|
||||
run_for_module "tests" "$@" "${pkg}" || return "$?"
|
||||
run_for_module "." "$@" "${pkg}" || return "$?"
|
||||
for m in $(module_dirs); do
|
||||
run_for_module "${m}" "$@" "${pkg}" || return "$?"
|
||||
done
|
||||
else
|
||||
run_for_module "${USERMOD}" "$@" "${pkg}" || return "$?"
|
||||
fi
|
||||
@ -265,7 +263,6 @@ function go_test {
|
||||
failures=("${failures[@]}" "${pkg}")
|
||||
fi
|
||||
fi
|
||||
echo
|
||||
done
|
||||
|
||||
if [ -n "${failures[*]}" ] ; then
|
||||
|
17
test.sh
17
test.sh
@ -197,9 +197,8 @@ function grpcproxy_pass {
|
||||
|
||||
# Builds artifacts used by tests/e2e in coverage mode.
|
||||
function build_cov_pass {
|
||||
local out="${BINDIR:-./bin}"
|
||||
run go test -tags cov -c -covermode=set -coverpkg="./..." -o "${out}/etcd_test"
|
||||
run go test -tags cov -c -covermode=set -coverpkg="./..." -o "${out}/etcdctl_test" "./etcdctl"
|
||||
run_for_module "server" run go test -tags cov -c -covermode=set -coverpkg="./..." -o "../bin/etcd_test"
|
||||
run_for_module "etcdctl" run go test -tags cov -c -covermode=set -coverpkg="./..." -o "../bin/etcdctl_test"
|
||||
}
|
||||
|
||||
# pkg_to_coverflag [prefix] [pkgs]
|
||||
@ -212,6 +211,10 @@ function pkg_to_coverprofileflag {
|
||||
echo -n "-coverprofile=${coverdir}/${prefix}_${pkgs_normalized}.coverprofile"
|
||||
}
|
||||
|
||||
function not_test_packages {
|
||||
run_for_modules pkgs_in_module "./..." | grep -v /etcd/tests/v3/
|
||||
}
|
||||
|
||||
function cov_pass {
|
||||
# shellcheck disable=SC2153
|
||||
if [ -z "$COVERDIR" ]; then
|
||||
@ -230,7 +233,7 @@ function cov_pass {
|
||||
rm -f "${coverdir}/*.coverprofile" "${coverdir}/cover.*"
|
||||
|
||||
local covpkgs
|
||||
covpkgs=$(pkgs_in_module "./...")
|
||||
covpkgs=$(not_test_packages)
|
||||
local coverpkg_comma
|
||||
coverpkg_comma=$(echo "${covpkgs[@]}" | xargs | tr ' ' ',')
|
||||
local gocov_build_flags=("-covermode=set" "-coverpkg=$coverpkg_comma")
|
||||
@ -238,8 +241,10 @@ function cov_pass {
|
||||
local failed=""
|
||||
|
||||
log_callout "Collecting coverage from unit tests ..."
|
||||
go_test "./..." "keep_going" "pkg_to_coverprofileflag unit" -short -timeout=30m \
|
||||
"${gocov_build_flags[@]}" "$@" || failed="$failed unit"
|
||||
for m in $(module_dirs); do
|
||||
run_for_module "${m}" go_test "./..." "keep_going" "pkg_to_coverprofileflag unit" -short -timeout=30m \
|
||||
"${gocov_build_flags[@]}" "$@" || failed="$failed unit"
|
||||
done
|
||||
|
||||
log_callout "Collecting coverage from integration tests ..."
|
||||
run_for_module "tests" go_test "./integration/..." "keep_going" "pkg_to_coverprofileflag integration" \
|
||||
|
Loading…
x
Reference in New Issue
Block a user