Skip to content

Commit

Permalink
cmd/go: fix tests that fail when running a cross-compiled GOARCH
Browse files Browse the repository at this point in the history
In CL 356611 I changed cmd/go to run most of its tests (instead of
skipping them all) when cross-compiled, such as with GOARCH=386 on an
amd64 host. Unfortunately, since we don't have a CI builder that runs
long tests in a cross-compiled configuration, some of the tests have
rotted since then.

This fixes 'GOARCH=386 go test cmd/go' on my workstation.

For #64963.
Updates #53936.

Change-Id: If7f4bc8e8d1ace7d36010d7a1b652fc7b2ceb276
Cq-Include-Trybots: luci.golang.try:gotip-linux-386-longtest,gotip-windows-amd64-longtest
Reviewed-on: https://go-review.googlesource.com/c/go/+/560782
Auto-Submit: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
  • Loading branch information
Bryan C. Mills authored and pull[bot] committed Feb 6, 2024
1 parent 1202a7b commit 8274451
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/cmd/go/scriptconds_test.go
Expand Up @@ -55,6 +55,7 @@ func scriptConditions() map[string]script.Cond {
add("msan", sysCondition("-msan", platform.MSanSupported, true))
add("mustlinkext", script.Condition("platform always requires external linking", mustLinkExt))
add("net", script.PrefixCondition("can connect to external network host <suffix>", hasNet))
add("pielinkext", script.Condition("platform requires external linking for PIE", pieLinkExt))
add("race", sysCondition("-race", platform.RaceDetectorSupported, true))
add("symlink", lazyBool("testenv.HasSymlink()", testenv.HasSymlink))
add("trimpath", script.OnceCondition("test binary was built with -trimpath", isTrimpath))
Expand Down Expand Up @@ -233,3 +234,9 @@ func mustLinkExt(s *script.State) (bool, error) {
GOARCH, _ := s.LookupEnv("GOARCH")
return platform.MustLinkExternal(GOOS, GOARCH, false), nil
}

func pieLinkExt(s *script.State) (bool, error) {
GOOS, _ := s.LookupEnv("GOOS")
GOARCH, _ := s.LookupEnv("GOARCH")
return !platform.InternalLinkPIESupported(GOOS, GOARCH), nil
}
2 changes: 2 additions & 0 deletions src/cmd/go/testdata/script/README
Expand Up @@ -410,6 +410,8 @@ The available conditions are:
platform always requires external linking
[net:*]
can connect to external network host <suffix>
[pielinkext]
platform requires external linking for PIE
[race]
GOOS/GOARCH supports -race
[root]
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/go/testdata/script/build_plugin_reproducible.txt
@@ -1,5 +1,6 @@
[!buildmode:plugin] skip
[short] skip
[!cgo] skip '-buildmode=plugin requires external linking'

go build -trimpath -buildvcs=false -buildmode=plugin -o a.so main.go
go build -trimpath -buildvcs=false -buildmode=plugin -o b.so main.go
Expand All @@ -8,4 +9,4 @@ cmp -q a.so b.so
-- main.go --
package main

func main() {}
func main() {}
7 changes: 3 additions & 4 deletions src/cmd/go/testdata/script/version.txt
Expand Up @@ -57,8 +57,9 @@ stdout '^test2json.exe: .+'
stdout '^\tpath\tcmd/test2json$'
! stdout 'mod[^e]'

# Repeat the test with -buildmode=pie.
# Repeat the test with -buildmode=pie and default linking.
[!buildmode:pie] stop
[pielinkext] [!cgo] stop
go build -buildmode=pie -o external.exe rsc.io/fortune
go version external.exe
stdout '^external.exe: .+'
Expand All @@ -68,9 +69,7 @@ stdout '^\tpath\trsc.io/fortune'
stdout '^\tmod\trsc.io/fortune\tv1.0.0'

# Also test PIE with internal linking.
# currently only supported on linux/amd64, linux/arm64 and windows/amd64.
[!GOOS:linux] [!GOOS:windows] stop
[!GOARCH:amd64] [!GOARCH:arm64] stop
[pielinkext] stop
go build -buildmode=pie -ldflags=-linkmode=internal -o internal.exe rsc.io/fortune
go version internal.exe
stdout '^internal.exe: .+'
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/version_cshared.txt
@@ -1,4 +1,5 @@
[short] skip
[!cgo] skip '-buildmode=c-shared requires external linking'
[!buildmode:c-shared] stop

env GO111MODULE=on
Expand Down

0 comments on commit 8274451

Please sign in to comment.