runtime: Consolidate flags setting in unit tests script

One of the responsibilities of the go-test.sh script is setting up the
default flags for 'go test'.  This is constructed across several different
places in the script using several unneeded intermediate variables though.

Consolidate all the flag construction into one place.

fixes #4190

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
David Gibson 2022-05-03 12:54:21 +10:00
parent cf465feb02
commit f24a6e761f

View File

@ -15,14 +15,19 @@ long_options=(
[package:]="Specify test package to run"
)
# Set default test run timeout value.
#
# Set up go test flags
go_test_flags="${KATA_GO_TEST_FLAGS}"
if [ -z "$go_test_flags" ]; then
# KATA_GO_TEST_TIMEOUT can be set to any value accepted by
# "go test -timeout X"
timeout_value=${KATA_GO_TEST_TIMEOUT:-30s}
go_test_flags="-v -timeout ${KATA_GO_TEST_TIMEOUT:-30s}"
# -race flag is not supported on s390x
[ "$(go env GOARCH)" != "s390x" ] && race="-race"
[ "$(go env GOARCH)" != "s390x" ] && go_test_flags+=" -race"
# s390x requires special linker flags
[ "$(go env GOARCH)" = s390x ] && go_test_flags+=" -ldflags '-extldflags -Wl,--s390-pgste'"
fi
# The "master" coverage file that contains the coverage results for
# all packages run under all scenarios.
@ -156,12 +161,6 @@ main()
shift
done
local go_ldflags
[ "$(go env GOARCH)" = s390x ] && go_ldflags="-extldflags -Wl,--s390-pgste"
# KATA_GO_TEST_FLAGS can be set to change the flags passed to "go test".
go_test_flags=${KATA_GO_TEST_FLAGS:-"-v $race -timeout $timeout_value -ldflags '$go_ldflags'"}
test_coverage
}