mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-22 13:38:26 +00:00
runtime: Simplify package listing in go-test.sh
go-test.sh defaults to testing all the packages listed by go list, except for a number filtered out. It turns out that none of those filters are necessary any more: * We've long required a Go newer than 1.9 which means the vendor filter isn't needed * The agent filter doesn't do anything now that we've moved to the Kata 2.x unified repo * The tests filters don't hit anything on the list of modules in src/runtime (which is the only user of the script) But since we don't need to filter anything out any more, we don't even need to iterate through a list ourselves. We can simply pass "./..." directly to go test and it will iterate through all the sub-packages itself. Interestingly this more than doubles the speed of "make test" for me - I suspect because go test's internal paralellism works better over a larger pool of tests. This also lets us remove handling of non-existent coverage files from test_go_package(), since with default options we will no longer test packages without tests by default. If the user explicitly requests testing of a package with no tests, then failing makes sense. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
557c4cfd00
commit
0aff5aaa39
@ -12,7 +12,6 @@ typeset -A long_options
|
|||||||
|
|
||||||
long_options=(
|
long_options=(
|
||||||
[help]="Show usage"
|
[help]="Show usage"
|
||||||
[list]="List available packages"
|
|
||||||
[package:]="Specify test package to run"
|
[package:]="Specify test package to run"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -25,23 +24,12 @@ timeout_value=${KATA_GO_TEST_TIMEOUT:-30s}
|
|||||||
# -race flag is not supported on s390x
|
# -race flag is not supported on s390x
|
||||||
[ "$(go env GOARCH)" != "s390x" ] && race="-race"
|
[ "$(go env GOARCH)" != "s390x" ] && race="-race"
|
||||||
|
|
||||||
# Notes:
|
|
||||||
#
|
|
||||||
# - The vendor filtering is required for versions of go older than 1.9.
|
|
||||||
# - The test package filtering is required since those packages need special setup.
|
|
||||||
all_test_packages=$(go list ./... 2>/dev/null |\
|
|
||||||
grep -v "/vendor/" |\
|
|
||||||
grep -v "github.com/kata-containers/agent/protocols/grpc" |\
|
|
||||||
grep -v "github.com/kata-containers/tests/functional" |\
|
|
||||||
grep -v "github.com/kata-containers/tests/integration/docker" \
|
|
||||||
|| true)
|
|
||||||
|
|
||||||
# The "master" coverage file that contains the coverage results for
|
# The "master" coverage file that contains the coverage results for
|
||||||
# all packages run under all scenarios.
|
# all packages run under all scenarios.
|
||||||
test_coverage_file="coverage.txt"
|
test_coverage_file="coverage.txt"
|
||||||
|
|
||||||
# Temporary coverage file created for a single package. The results in this
|
# Temporary coverage file created for a "go test" run. The results in
|
||||||
# file will be added to the master coverage file.
|
# this file will be added to the master coverage file.
|
||||||
tmp_coverage_file="${test_coverage_file}.tmp"
|
tmp_coverage_file="${test_coverage_file}.tmp"
|
||||||
|
|
||||||
warn()
|
warn()
|
||||||
@ -90,11 +78,6 @@ Commands:
|
|||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
list_packages()
|
|
||||||
{
|
|
||||||
echo "$all_test_packages"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Run a command as either root or the current user (which might still be root).
|
# Run a command as either root or the current user (which might still be root).
|
||||||
#
|
#
|
||||||
# If the first argument is "root", run using sudo, else run as the current
|
# If the first argument is "root", run using sudo, else run as the current
|
||||||
@ -126,15 +109,9 @@ test_go_package()
|
|||||||
|
|
||||||
run_as_user "$user" go test "$go_test_flags" -covermode=atomic -coverprofile=$tmp_coverage_file "$pkg"
|
run_as_user "$user" go test "$go_test_flags" -covermode=atomic -coverprofile=$tmp_coverage_file "$pkg"
|
||||||
|
|
||||||
# Check for the temporary coverage file since if will
|
# Merge test results into the master coverage file.
|
||||||
# not be generated unless a package actually contains
|
run_as_user "$user" tail -n +2 "$tmp_coverage_file" >> "$test_coverage_file"
|
||||||
# tests.
|
rm -f "$tmp_coverage_file"
|
||||||
if [ -f "${tmp_coverage_file}" ]; then
|
|
||||||
# Save these package test results into the
|
|
||||||
# master coverage file.
|
|
||||||
run_as_user "$user" tail -n +2 "$tmp_coverage_file" >> "$test_coverage_file"
|
|
||||||
rm -f "$tmp_coverage_file"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Run all tests and generate a test coverage file.
|
# Run all tests and generate a test coverage file.
|
||||||
@ -161,19 +138,15 @@ test_coverage()
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "INFO: Currently running as user '$(id -un)'"
|
echo "INFO: Currently running as user '$(id -un)'"
|
||||||
for pkg in $test_packages; do
|
for user in $users; do
|
||||||
for user in $users; do
|
test_go_package "$package" "$user"
|
||||||
test_go_package "$pkg" "$user"
|
|
||||||
done
|
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# Run the tests locally
|
# Run the tests locally
|
||||||
test_local()
|
test_local()
|
||||||
{
|
{
|
||||||
for pkg in $test_packages; do
|
eval go test "$go_test_flags" "$package"
|
||||||
eval go test "$go_test_flags" "$pkg"
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
@ -187,7 +160,7 @@ main()
|
|||||||
--longoptions="$long_option_names" \
|
--longoptions="$long_option_names" \
|
||||||
-- "$@")
|
-- "$@")
|
||||||
|
|
||||||
local package
|
package="./..."
|
||||||
|
|
||||||
eval set -- "$args"
|
eval set -- "$args"
|
||||||
[ $? -ne 0 ] && { usage >&2; exit 1; }
|
[ $? -ne 0 ] && { usage >&2; exit 1; }
|
||||||
@ -196,7 +169,6 @@ main()
|
|||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-h|--help) usage; exit 0 ;;
|
-h|--help) usage; exit 0 ;;
|
||||||
--list) list_packages; exit 0 ;;
|
|
||||||
--package) package="$2"; shift 2;;
|
--package) package="$2"; shift 2;;
|
||||||
--) shift; break ;;
|
--) shift; break ;;
|
||||||
esac
|
esac
|
||||||
@ -204,12 +176,6 @@ main()
|
|||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -n "$package" ]; then
|
|
||||||
test_packages="$package"
|
|
||||||
else
|
|
||||||
test_packages="$all_test_packages"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Consume getopt cruft
|
# Consume getopt cruft
|
||||||
[ "$1" = "--" ] && shift
|
[ "$1" = "--" ] && shift
|
||||||
|
|
||||||
@ -220,8 +186,6 @@ main()
|
|||||||
run_coverage=yes
|
run_coverage=yes
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ -z "$test_packages" ] && echo "INFO: no golang code to test" && exit 0
|
|
||||||
|
|
||||||
local go_ldflags
|
local go_ldflags
|
||||||
[ "$(go env GOARCH)" = s390x ] && go_ldflags="-extldflags -Wl,--s390-pgste"
|
[ "$(go env GOARCH)" = s390x ] && go_ldflags="-extldflags -Wl,--s390-pgste"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user