Skip to content

Commit

Permalink
runtime: Consolidate flags setting in unit tests script
Browse files Browse the repository at this point in the history
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 kata-containers#4190

Signed-off-by: David Gibson <[email protected]>
  • Loading branch information
dgibson committed May 13, 2022
1 parent cf465fe commit f24a6e7
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/runtime/go-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit f24a6e7

Please sign in to comment.