]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/bootstrap_test: update TestExperimentToolID for Go 1.21
authorDmitri Shuralyov <dmitshur@golang.org>
Sun, 7 May 2023 02:52:06 +0000 (22:52 -0400)
committerGopher Robot <gobot@golang.org>
Fri, 12 May 2023 18:47:14 +0000 (18:47 +0000)
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>
src/cmd/internal/bootstrap_test/experiment_toolid_test.go
src/cmd/internal/bootstrap_test/reboot_test.go

index cc60509ecb67161949596035e6b2738fef348768..ff2379c8998c76247dd2c3da38debeb576ed5741 100644 (file)
@@ -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
 }
index eca024fa8961dc80238ea5723316cc5b92321dfe..fedf58c05c8b9eed9161fda97242e70aac4c3a72 100644 (file)
@@ -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":