summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitri Shuralyov <dmitshur@golang.org>2023-05-06 22:52:06 -0400
committerGopher Robot <gobot@golang.org>2023-05-12 18:47:14 +0000
commit202ba7deab99251577027b8a1360d5d21c76e75d (patch)
treec3db7c74176e9a6424df0e52c485838d03216864
parentacd8dc95833182df86831ec78e7470864bdb3b88 (diff)
downloadgo-git-202ba7deab99251577027b8a1360d5d21c76e75d.tar.gz
cmd/internal/bootstrap_test: update TestExperimentToolID for Go 1.21
This test is configured to run only when explicitly requested due to being costly. Apply two updates so it can run on the toolchain today: - overlay GOROOT/lib for zoneinfo.zip (similarly to CL 462279) - stop expecting framepointer to be listed in the GOEXPERIMENT section of the compiler version (see CL 49252 and CL 249857) I checked if by now there's another test that would report a problem if the fix made in CL 186200 had regressed. Running all.bash locally with GO_TEST_SHORT=0 GO_BUILDER_NAME=darwin-arm64-longtest passed ok, while this manual test did catch the problem. Also simplify the test implementation while here so it's less different from TestRepeatBootstrap. For #33091. Change-Id: I14eea18c19c2e8996bcba31c80e03dcf679f56ab Reviewed-on: https://go-review.googlesource.com/c/go/+/493475 Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
-rw-r--r--src/cmd/internal/bootstrap_test/experiment_toolid_test.go60
-rw-r--r--src/cmd/internal/bootstrap_test/reboot_test.go2
2 files changed, 33 insertions, 29 deletions
diff --git a/src/cmd/internal/bootstrap_test/experiment_toolid_test.go b/src/cmd/internal/bootstrap_test/experiment_toolid_test.go
index cc60509ecb..ff2379c899 100644
--- a/src/cmd/internal/bootstrap_test/experiment_toolid_test.go
+++ b/src/cmd/internal/bootstrap_test/experiment_toolid_test.go
@@ -3,18 +3,13 @@
// license that can be found in the LICENSE file.
//go:build explicit
-// +build explicit
-
-// This test verifies that GOEXPERIMENT settings built
-// into the toolchain influence tool ids in the Go command.
-// This test requires bootstrapping the toolchain twice, so it's very expensive.
-// It must be run explicitly with -tags=explicit.
-// Verifies golang.org/issue/33091.
package bootstrap_test
import (
"bytes"
+ "errors"
+ "internal/testenv"
"os"
"os/exec"
"path/filepath"
@@ -22,30 +17,39 @@ import (
"testing"
)
+// TestExperimentToolID verifies that GOEXPERIMENT settings built
+// into the toolchain influence tool ids in the Go command.
+// This test requires bootstrapping the toolchain twice, so it's very expensive.
+// It must be run explicitly with -tags=explicit.
+// Verifies go.dev/issue/33091.
func TestExperimentToolID(t *testing.T) {
- // Set up GOROOT
- goroot, err := os.MkdirTemp("", "experiment-goroot")
- if err != nil {
- t.Fatal(err)
+ if testing.Short() {
+ t.Skip("skipping test that rebuilds the entire toolchain twice")
+ }
+ switch runtime.GOOS {
+ case "android", "ios", "js", "wasip1":
+ t.Skipf("skipping because the toolchain does not have to bootstrap on GOOS=%s", runtime.GOOS)
}
- defer os.RemoveAll(goroot)
+ realGoroot := testenv.GOROOT(t)
+
+ // Set up GOROOT.
+ goroot := t.TempDir()
gorootSrc := filepath.Join(goroot, "src")
- if err := overlayDir(gorootSrc, filepath.Join(runtime.GOROOT(), "src")); err != nil {
+ if err := overlayDir(gorootSrc, filepath.Join(realGoroot, "src")); err != nil {
+ t.Fatal(err)
+ }
+ gorootLib := filepath.Join(goroot, "lib")
+ if err := overlayDir(gorootLib, filepath.Join(realGoroot, "lib")); err != nil {
t.Fatal(err)
}
-
if err := os.WriteFile(filepath.Join(goroot, "VERSION"), []byte("go1.999"), 0666); err != nil {
t.Fatal(err)
}
- env := append(os.Environ(), "GOROOT=", "GOROOT_BOOTSTRAP="+runtime.GOROOT())
+ env := append(os.Environ(), "GOROOT=", "GOROOT_BOOTSTRAP="+realGoroot)
// Use a clean cache.
- gocache, err := os.MkdirTemp("", "experiment-gocache")
- if err != nil {
- t.Fatal(err)
- }
- defer os.RemoveAll(gocache)
+ gocache := t.TempDir()
env = append(env, "GOCACHE="+gocache)
// Build the toolchain without GOEXPERIMENT.
@@ -58,18 +62,15 @@ func TestExperimentToolID(t *testing.T) {
default:
makeScript = "make.bash"
}
- makeScriptPath := filepath.Join(runtime.GOROOT(), "src", makeScript)
+ makeScriptPath := filepath.Join(realGoroot, "src", makeScript)
runCmd(t, gorootSrc, env, makeScriptPath)
// Verify compiler version string.
goCmdPath := filepath.Join(goroot, "bin", "go")
- if runtime.GOOS == "windows" {
- goCmdPath += ".exe"
- }
gotVersion := bytes.TrimSpace(runCmd(t, gorootSrc, env, goCmdPath, "tool", "compile", "-V=full"))
wantVersion := []byte(`compile version go1.999`)
if !bytes.Equal(gotVersion, wantVersion) {
- t.Errorf("compile version without experiment: got %q, want %q", gotVersion, wantVersion)
+ t.Errorf("compile version without experiment is unexpected:\ngot %q\nwant %q", gotVersion, wantVersion)
}
// Build a package in a mode not handled by the make script.
@@ -81,9 +82,9 @@ func TestExperimentToolID(t *testing.T) {
// Verify compiler version string.
gotVersion = bytes.TrimSpace(runCmd(t, gorootSrc, env, goCmdPath, "tool", "compile", "-V=full"))
- wantVersion = []byte(`compile version go1.999 X:fieldtrack,framepointer`)
+ wantVersion = []byte(`compile version go1.999 X:fieldtrack`)
if !bytes.Equal(gotVersion, wantVersion) {
- t.Errorf("compile version with experiment: got %q, want %q", gotVersion, wantVersion)
+ t.Errorf("compile version with experiment is unexpected:\ngot %q\nwant %q", gotVersion, wantVersion)
}
// Build the same package. We should not get a cache conflict.
@@ -96,7 +97,10 @@ func runCmd(t *testing.T, dir string, env []string, path string, args ...string)
cmd.Env = env
out, err := cmd.Output()
if err != nil {
- t.Fatal(err)
+ if ee := (*exec.ExitError)(nil); errors.As(err, &ee) {
+ out = append(out, ee.Stderr...)
+ }
+ t.Fatalf("%s failed:\n%s\n%s", cmd, out, err)
}
return out
}
diff --git a/src/cmd/internal/bootstrap_test/reboot_test.go b/src/cmd/internal/bootstrap_test/reboot_test.go
index eca024fa89..fedf58c05c 100644
--- a/src/cmd/internal/bootstrap_test/reboot_test.go
+++ b/src/cmd/internal/bootstrap_test/reboot_test.go
@@ -21,7 +21,7 @@ import (
func TestRepeatBootstrap(t *testing.T) {
if testing.Short() {
- t.Skipf("skipping test that rebuilds the entire toolchain")
+ t.Skip("skipping test that rebuilds the entire toolchain")
}
switch runtime.GOOS {
case "android", "ios", "js", "wasip1":