From f24a6e761f9707a1f573221aba67a25c1ba33e29 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Tue, 3 May 2022 12:54:21 +1000 Subject: [PATCH] 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 --- src/runtime/go-test.sh | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/runtime/go-test.sh b/src/runtime/go-test.sh index a13eff347e32..38dceef8f4af 100755 --- a/src/runtime/go-test.sh +++ b/src/runtime/go-test.sh @@ -15,14 +15,19 @@ long_options=( [package:]="Specify test package to run" ) -# Set default test run timeout value. -# -# KATA_GO_TEST_TIMEOUT can be set to any value accepted by -# "go test -timeout X" -timeout_value=${KATA_GO_TEST_TIMEOUT:-30s} +# 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" + go_test_flags="-v -timeout ${KATA_GO_TEST_TIMEOUT:-30s}" + + # -race flag is not supported on s390x + [ "$(go env GOARCH)" != "s390x" ] && go_test_flags+=" -race" -# -race flag is not supported on s390x -[ "$(go env GOARCH)" != "s390x" ] && race="-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 }