From 9e2189ef8e04d2745d18ac870ae54dcdcbc008db Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Tue, 10 Mar 2026 17:34:02 -0400 Subject: cmd/go: isolate some very long tests These tests are exceptionally slow. Move them out of the normal cmd/go test suite to try to make it more reasonable to run 'go test cmd/go' in a regular dev cycle. More tests can be moved here as needed. (Hopefully this can also help longtest sharding) Change-Id: I4ca0696d0afe72aa0234ed4ed87679ab6a6a6964 Reviewed-on: https://go-review.googlesource.com/c/go/+/753860 Reviewed-by: Dmitri Shuralyov Reviewed-by: Dmitri Shuralyov LUCI-TryBot-Result: Go LUCI Auto-Submit: Michael Matloob Reviewed-by: Michael Matloob --- src/cmd/go/internal/verylongtest/script_test.go | 26 ++ .../internal/verylongtest/testdata/script/README | 286 +++++++++++++++++ .../testdata/script/link_matching_actionid.txt | 39 +++ .../verylongtest/testdata/script/repro_build.txt | 22 ++ .../testdata/script/test_cache_inputs.txt | 356 +++++++++++++++++++++ .../go/testdata/script/link_matching_actionid.txt | 38 --- src/cmd/go/testdata/script/repro_build.txt | 22 -- src/cmd/go/testdata/script/test_cache_inputs.txt | 354 -------------------- 8 files changed, 729 insertions(+), 414 deletions(-) create mode 100644 src/cmd/go/internal/verylongtest/script_test.go create mode 100644 src/cmd/go/internal/verylongtest/testdata/script/README create mode 100644 src/cmd/go/internal/verylongtest/testdata/script/link_matching_actionid.txt create mode 100644 src/cmd/go/internal/verylongtest/testdata/script/repro_build.txt create mode 100644 src/cmd/go/internal/verylongtest/testdata/script/test_cache_inputs.txt delete mode 100644 src/cmd/go/testdata/script/link_matching_actionid.txt delete mode 100644 src/cmd/go/testdata/script/repro_build.txt delete mode 100644 src/cmd/go/testdata/script/test_cache_inputs.txt (limited to 'src') diff --git a/src/cmd/go/internal/verylongtest/script_test.go b/src/cmd/go/internal/verylongtest/script_test.go new file mode 100644 index 0000000000..640a4cf1af --- /dev/null +++ b/src/cmd/go/internal/verylongtest/script_test.go @@ -0,0 +1,26 @@ +// Copyright 2026 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package verylongtest + +import ( + "cmd/internal/script/scripttest" + "flag" + "internal/testenv" + "testing" +) + +//go:generate go test cmd/go/internal/verylongtest -v -run=TestScript/README --fixreadme + +var fixReadme = flag.Bool("fixreadme", false, "if true, update README for script tests") + +func TestScript(t *testing.T) { + if testing.Short() { + // Don't bother setting up the script engine. None of these are short tests. + t.Skip() + } + testenv.MustHaveGoBuild(t) + testenv.SkipIfShortAndSlow(t) + scripttest.RunToolScriptTest(t, nil, "testdata/script", *fixReadme) +} diff --git a/src/cmd/go/internal/verylongtest/testdata/script/README b/src/cmd/go/internal/verylongtest/testdata/script/README new file mode 100644 index 0000000000..9ec997a138 --- /dev/null +++ b/src/cmd/go/internal/verylongtest/testdata/script/README @@ -0,0 +1,286 @@ +This file is generated by 'go generate'. DO NOT EDIT. + +This directory holds test scripts *.txt run during 'go test cmd/'. +To run a specific script foo.txt + + go test cmd/ -run=Script/^foo$ + +In general script files should have short names: a few words, + not whole sentences. +The first word should be the general category of behavior being tested, +often the name of a go subcommand (build, link, compile, ...) or concept (vendor, pattern). + +Each script is a text archive (go doc internal/txtar). +The script begins with an actual command script to run +followed by the content of zero or more supporting files to +create in the script's temporary file system before it starts executing. + +As an example, run_hello.txt says: + + # hello world + go run hello.go + stderr 'hello world' + ! stdout . + + -- hello.go -- + package main + func main() { println("hello world") } + +Each script runs in a fresh temporary work directory tree, available to scripts as $WORK. +Scripts also have access to other environment variables, including: + + GOARCH= + GOOS= + TMPDIR=$WORK/tmp + devnull= + goversion= + +On Plan 9, the variables $path and $home are set instead of $PATH and $HOME. +On Windows, the variables $USERPROFILE and $TMP are set instead of +$HOME and $TMPDIR. + +The lines at the top of the script are a sequence of commands to be executed by +a small script engine configured in .../cmd/internal/script/scripttest/run.go (not the system shell). + +Each line of a script is parsed into a sequence of space-separated command +words, with environment variable expansion within each word and # marking +an end-of-line comment. Additional variables named ':' and '/' are expanded +within script arguments (expanding to the value of os.PathListSeparator and +os.PathSeparator respectively) but are not inherited in subprocess environments. + +Adding single quotes around text keeps spaces in that text from being treated +as word separators and also disables environment variable expansion. Inside a +single-quoted block of text, a repeated single quote indicates a literal single +quote, as in: + + 'Don''t communicate by sharing memory.' + +A line beginning with # is a comment and conventionally explains what is being +done or tested at the start of a new section of the script. + +Commands are executed one at a time, and errors are checked for each command; +if any command fails unexpectedly, no subsequent commands in the script are +executed. The command prefix ! indicates that the command on the rest of the +line (typically go or a matching predicate) must fail instead of succeeding. +The command prefix ? indicates that the command may or may not succeed, but the +script should continue regardless. + +The command prefix [cond] indicates that the command on the rest of the line +should only run when the condition is satisfied. + +A condition can be negated: [!root] means to run the rest of the line only if +the user is not root. Multiple conditions may be given for a single command, +for example, '[linux] [amd64] skip'. The command will run if all conditions are +satisfied. + +When TestScript runs a script and the script fails, by default TestScript shows +the execution of the most recent phase of the script (since the last # comment) +and only shows the # comments for earlier phases. + +Note also that in reported output, the actual name of the per-script temporary directory +has been consistently replaced with the literal string $WORK. + +The available commands are: +cat files... + concatenate files and print to the script's stdout buffer + + +cc args... + run the platform C compiler + + +cd dir + change the working directory + + +chmod perm paths... + change file mode bits + + Changes the permissions of the named files or directories to + be equal to perm. + Only numerical permissions are supported. + +cmp [-q] file1 file2 + compare files for differences + + By convention, file1 is the actual data and file2 is the + expected data. + The command succeeds if the file contents are identical. + File1 can be 'stdout' or 'stderr' to compare the stdout or + stderr buffer from the most recent command. + +cmpenv [-q] file1 file2 + compare files for differences, with environment expansion + + By convention, file1 is the actual data and file2 is the + expected data. + The command succeeds if the file contents are identical + after substituting variables from the script environment. + File1 can be 'stdout' or 'stderr' to compare the script's + stdout or stderr buffer. + +cp src... dst + copy files to a target file or directory + + src can include 'stdout' or 'stderr' to copy from the + script's stdout or stderr buffer. + +echo string... + display a line of text + + +env [key[=value]...] + set or log the values of environment variables + + With no arguments, print the script environment to the log. + Otherwise, add the listed key=value pairs to the environment + or print the listed keys. + +exec program [args...] [&] + run an executable program with arguments + + Note that 'exec' does not terminate the script (unlike Unix + shells). + +exists [-readonly] [-exec] file... + check that files exist + + +go [args...] [&] + run the 'go' program provided by the script host + + +grep [-count=N] [-q] 'pattern' file + find lines in a file that match a pattern + + The command succeeds if at least one match (or the exact + count, if given) is found. + The -q flag suppresses printing of matches. + +help [-v] name... + log help text for commands and conditions + + To display help for a specific condition, enclose it in + brackets: 'help [amd64]'. + To display complete documentation when listing all commands, + pass the -v flag. + +mkdir path... + create directories, if they do not already exist + + Unlike Unix mkdir, parent directories are always created if + needed. + +mv old new + rename a file or directory to a new path + + OS-specific restrictions may apply when old and new are in + different directories. + +replace [old new]... file + replace strings in a file + + The 'old' and 'new' arguments are unquoted as if in quoted + Go strings. + +rm path... + remove a file or directory + + If the path is a directory, its contents are removed + recursively. + +skip [msg] + skip the current test + + +sleep duration [&] + sleep for a specified duration + + The duration must be given as a Go time.Duration string. + +stderr [-count=N] [-q] 'pattern' file + find lines in the stderr buffer that match a pattern + + The command succeeds if at least one match (or the exact + count, if given) is found. + The -q flag suppresses printing of matches. + +stdout [-count=N] [-q] 'pattern' file + find lines in the stdout buffer that match a pattern + + The command succeeds if at least one match (or the exact + count, if given) is found. + The -q flag suppresses printing of matches. + +stop [msg] + stop execution of the script + + The message is written to the script log, but no error is + reported from the script engine. + +symlink path -> target + create a symlink + + Creates path as a symlink to target. + The '->' token (like in 'ls -l' output on Unix) is required. + +wait + wait for completion of background commands + + Waits for all background commands to complete. + The output (and any error) from each command is printed to + the log in the order in which the commands were started. + After the call to 'wait', the script's stdout and stderr + buffers contain the concatenation of the background + commands' outputs. + + + +The available conditions are: +[GOARCH:*] + runtime.GOARCH == +[GODEBUG:*] + GODEBUG contains +[GOEXPERIMENT:*] + GOEXPERIMENT is enabled +[GOOS:*] + runtime.GOOS == +[asan] + GOOS/GOARCH supports -asan +[buildmode:*] + go supports -buildmode= +[cgo] + host CGO_ENABLED +[cgolinkext] + platform requires external linking for cgo +[compiler:*] + runtime.Compiler == +[cross] + cmd/go GOOS/GOARCH != GOHOSTOS/GOHOSTARCH +[exec:*] + names an executable in the test binary's PATH +[fuzz] + GOOS/GOARCH supports -fuzz +[fuzz-instrumented] + GOOS/GOARCH supports -fuzz with instrumentation +[go-builder] + GO_BUILDER_NAME is non-empty +[link] + testenv.HasLink() +[msan] + GOOS/GOARCH supports -msan +[mustlinkext] + platform always requires external linking +[pielinkext] + platform requires external linking for PIE +[race] + GOOS/GOARCH supports -race +[root] + os.Geteuid() == 0 +[short] + testing.Short() +[symlink] + testenv.HasSymlink() +[verbose] + testing.Verbose() + diff --git a/src/cmd/go/internal/verylongtest/testdata/script/link_matching_actionid.txt b/src/cmd/go/internal/verylongtest/testdata/script/link_matching_actionid.txt new file mode 100644 index 0000000000..9f3711dd1d --- /dev/null +++ b/src/cmd/go/internal/verylongtest/testdata/script/link_matching_actionid.txt @@ -0,0 +1,39 @@ +# Checks that an identical binary is built with -trimpath from the same +# source files, with GOROOT in two different locations. +# Verifies golang.org/issue/38989 + +[short] skip +[!symlink] skip + +# Symlink the compiler to a local path +env TEST_GOROOT=$GOROOT +env GOROOT=$WORK/goroot1 +symlink $GOROOT -> $TEST_GOROOT + +# Set up fresh GOCACHE +env GOCACHE=$WORK/gocache1 +mkdir $GOCACHE + +# Build a simple binary +go build -o binary1 -trimpath -x main.go + +# Now repeat the same process with the compiler at a different local path +env GOROOT=$WORK/goroot2 +symlink $GOROOT -> $TEST_GOROOT + +env GOCACHE=$WORK/gocache2 +mkdir $GOCACHE + +go build -o binary2 -trimpath -x main.go + +# Check that the binaries match exactly +go tool buildid binary1 +cp stdout buildid1 +go tool buildid binary2 +cp stdout buildid2 +cmp buildid1 buildid2 + + +-- main.go -- +package main +func main() {} diff --git a/src/cmd/go/internal/verylongtest/testdata/script/repro_build.txt b/src/cmd/go/internal/verylongtest/testdata/script/repro_build.txt new file mode 100644 index 0000000000..7c6e317cec --- /dev/null +++ b/src/cmd/go/internal/verylongtest/testdata/script/repro_build.txt @@ -0,0 +1,22 @@ +# Check that goroutine scheduling does not affect compiler output. +# If it does, reproducible builds will not work very well. +[short] skip +[GOOS:aix] env CGO_ENABLED=0 # go.dev/issue/56896 +env GOMAXPROCS=16 +go build -a -o http16.o net/http +env GOMAXPROCS=17 +go build -a -o http17.o net/http +cmp -q http16.o http17.o +env GOMAXPROCS=18 +go build -a -o http18.o net/http +cmp -q http16.o http18.o + +# Check that goroutine scheduling does not affect linker output. +env GOMAXPROCS=16 +go build -a -o gofmt16.exe cmd/gofmt +env GOMAXPROCS=17 +go build -a -o gofmt17.exe cmd/gofmt +cmp -q gofmt16.exe gofmt17.exe +env GOMAXPROCS=18 +go build -a -o gofmt18.exe cmd/gofmt +cmp -q gofmt16.exe gofmt18.exe diff --git a/src/cmd/go/internal/verylongtest/testdata/script/test_cache_inputs.txt b/src/cmd/go/internal/verylongtest/testdata/script/test_cache_inputs.txt new file mode 100644 index 0000000000..05ffcb87e6 --- /dev/null +++ b/src/cmd/go/internal/verylongtest/testdata/script/test_cache_inputs.txt @@ -0,0 +1,356 @@ +env GO111MODULE=off +env GOPATH=$WORK/gopath +cd $WORK/gopath/src + +# Test that cached test results are invalidated in response to +# changes to the external inputs to the test. + +[short] skip +[GODEBUG:gocacheverify=1] skip + +# We're testing cache behavior, so start with a clean GOCACHE. +env GOCACHE=$WORK/cache + +# Build a helper binary to invoke os.Chtimes. +go build -o mkold$GOEXE mkold.go + +# Make test input files appear to be a minute old. +exec ./mkold$GOEXE 1m testcache/file.txt +exec ./mkold$GOEXE 1m testcache/script.sh + +# If the test reads an environment variable, changes to that variable +# should invalidate cached test results. +env TESTKEY=x +go test testcache -run=TestLookupEnv +go test testcache -run=TestLookupEnv +stdout '\(cached\)' + +# GODEBUG is always read +env GODEBUG=asdf=1 +go test testcache -run=TestLookupEnv +! stdout '\(cached\)' +go test testcache -run=TestLookupEnv +stdout '\(cached\)' +env GODEBUG= + +env TESTKEY=y +go test testcache -run=TestLookupEnv +! stdout '\(cached\)' +go test testcache -run=TestLookupEnv +stdout '\(cached\)' + +# Changes in arguments forwarded to the test should invalidate cached test +# results. +go test testcache -run=TestOSArgs -v hello +! stdout '\(cached\)' +stdout 'hello' +go test testcache -run=TestOSArgs -v goodbye +! stdout '\(cached\)' +stdout 'goodbye' + +# golang.org/issue/36134: that includes the `-timeout` argument. +go test testcache -run=TestOSArgs -timeout=20m -v +! stdout '\(cached\)' +stdout '-test\.timeout[= ]20m' +go test testcache -run=TestOSArgs -timeout=5s -v +! stdout '\(cached\)' +stdout '-test\.timeout[= ]5s' + +# If the test stats a file, changes to the file should invalidate the cache. +go test testcache -run=FileSize +go test testcache -run=FileSize +stdout '\(cached\)' + +cp 4x.txt testcache/file.txt +go test testcache -run=FileSize +! stdout '\(cached\)' +go test testcache -run=FileSize +stdout '\(cached\)' + +# Files should be tracked even if the test changes its working directory. +go test testcache -run=Chdir +go test testcache -run=Chdir +stdout '\(cached\)' +cp 6x.txt testcache/file.txt +go test testcache -run=Chdir +! stdout '\(cached\)' +go test testcache -run=Chdir +stdout '\(cached\)' + +# The content of files should affect caching, provided that the mtime also changes. +exec ./mkold$GOEXE 1m testcache/file.txt +go test testcache -run=FileContent +go test testcache -run=FileContent +stdout '\(cached\)' +cp 2y.txt testcache/file.txt +exec ./mkold$GOEXE 50s testcache/file.txt +go test testcache -run=FileContent +! stdout '\(cached\)' +go test testcache -run=FileContent +stdout '\(cached\)' + +# Directory contents read via os.ReadDirNames should affect caching. +go test testcache -run=DirList +go test testcache -run=DirList +stdout '\(cached\)' +rm testcache/file.txt +go test testcache -run=DirList +! stdout '\(cached\)' +go test testcache -run=DirList +stdout '\(cached\)' + +# Files outside GOROOT and GOPATH should not affect caching. +env TEST_EXTERNAL_FILE=$WORK/external.txt +go test testcache -run=ExternalFile +go test testcache -run=ExternalFile +stdout '\(cached\)' + +rm external.txt +go test testcache -run=ExternalFile +stdout '\(cached\)' + +# The -benchtime flag without -bench should not affect caching. +go test testcache -run=Benchtime -benchtime=1x +go test testcache -run=Benchtime -benchtime=1x +stdout '\(cached\)' + +go test testcache -run=Benchtime -bench=Benchtime -benchtime=1x +go test testcache -run=Benchtime -bench=Benchtime -benchtime=1x +! stdout '\(cached\)' + +# golang.org/issue/47355: that includes the `-failfast` argument. +go test testcache -run=TestOSArgs -failfast +! stdout '\(cached\)' +go test testcache -run=TestOSArgs -failfast +stdout '\(cached\)' + +# golang.org/issue/64638: that includes the `-fullpath` argument. +go test testcache -run=TestOSArgs -fullpath +! stdout '\(cached\)' +go test testcache -run=TestOSArgs -fullpath +stdout '\(cached\)' + +# golang.org/issue/70692: that includes the `-skip` flag +go test testcache -run=TestOdd -skip=TestOddFile +! stdout '\(cached\)' +go test testcache -run=TestOdd -skip=TestOddFile +stdout '\(cached\)' + +# Ensure that coverage profiles are being cached. +go test testcache -run=TestCoverageCache -coverprofile=coverage.out +go test testcache -run=TestCoverageCache -coverprofile=coverage.out +stdout '\(cached\)' +exists coverage.out +grep -q 'mode: set' coverage.out +grep -q 'testcache/hello.go:' coverage.out + +# A new -coverprofile file should use the cached coverage profile contents. +go test testcache -run=TestCoverageCache -coverprofile=coverage2.out +stdout '\(cached\)' +cmp coverage.out coverage2.out + +# Explicitly setting the default covermode should still use cache. +go test testcache -run=TestCoverageCache -coverprofile=coverage_set.out -covermode=set +stdout '\(cached\)' +cmp coverage.out coverage_set.out + +# A new -covermode should not use the cached coverage profile. +go test testcache -run=TestCoverageCache -coverprofile=coverage_atomic.out -covermode=atomic +! stdout '\(cached\)' +! cmp coverage.out coverage_atomic.out +grep -q 'mode: atomic' coverage_atomic.out +grep -q 'testcache/hello.go:' coverage_atomic.out + +# A new -coverpkg should not use the cached coverage profile. +go test testcache -run=TestCoverageCache -coverprofile=coverage_pkg.out -coverpkg=all +! stdout '\(cached\)' +! cmp coverage.out coverage_pkg.out + +# Test that -v doesn't prevent caching. +go test testcache -v -run=TestCoverageCache -coverprofile=coverage_v.out +go test testcache -v -run=TestCoverageCache -coverprofile=coverage_v2.out +stdout '\(cached\)' +cmp coverage_v.out coverage_v2.out + +# Test that -count affects caching. +go test testcache -run=TestCoverageCache -coverprofile=coverage_count.out -count=2 +! stdout '\(cached\)' + +# Executables within GOROOT and GOPATH should affect caching, +# even if the test does not stat them explicitly. + +[!exec:/bin/sh] skip +chmod 0755 ./testcache/script.sh + +exec ./mkold$GOEXEC 1m testcache/script.sh +go test testcache -run=Exec +go test testcache -run=Exec +stdout '\(cached\)' + +exec ./mkold$GOEXE 50s testcache/script.sh +go test testcache -run=Exec +! stdout '\(cached\)' +go test testcache -run=Exec +stdout '\(cached\)' + +-- gopath/src/testcache/file.txt -- +xx +-- gopath/src/4x.txt -- +xxxx +-- gopath/src/6x.txt -- +xxxxxx +-- gopath/src/2y.txt -- +yy +-- external.txt -- +This file is outside of GOPATH. +-- gopath/src/testcache/script.sh -- +#!/bin/sh +exit 0 +-- gopath/src/testcache/hello.go -- +package testcache + +import "fmt" + +func HelloWorld(name string) string { + if name == "" { + return "Hello, World!" + } + return fmt.Sprintf("Hello, %s!", name) +} + +-- gopath/src/testcache/testcache_test.go -- +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package testcache + +import ( + "io" + "os" + "testing" +) + +func TestChdir(t *testing.T) { + os.Chdir("..") + defer os.Chdir("testcache") + info, err := os.Stat("testcache/file.txt") + if err != nil { + t.Fatal(err) + } + if info.Size()%2 != 1 { + t.Fatal("even file") + } +} + +func TestOddFileContent(t *testing.T) { + f, err := os.Open("file.txt") + if err != nil { + t.Fatal(err) + } + data, err := io.ReadAll(f) + f.Close() + if err != nil { + t.Fatal(err) + } + if len(data)%2 != 1 { + t.Fatal("even file") + } +} + +func TestOddFileSize(t *testing.T) { + info, err := os.Stat("file.txt") + if err != nil { + t.Fatal(err) + } + if info.Size()%2 != 1 { + t.Fatal("even file") + } +} + +func TestOddGetenv(t *testing.T) { + val := os.Getenv("TESTKEY") + if len(val)%2 != 1 { + t.Fatal("even env value") + } +} + +func TestLookupEnv(t *testing.T) { + _, ok := os.LookupEnv("TESTKEY") + if !ok { + t.Fatal("env missing") + } +} + +func TestDirList(t *testing.T) { + f, err := os.Open(".") + if err != nil { + t.Fatal(err) + } + f.Readdirnames(-1) + f.Close() +} + +func TestExec(t *testing.T) { + // Note: not using os/exec to make sure there is no unexpected stat. + p, err := os.StartProcess("./script.sh", []string{"script"}, new(os.ProcAttr)) + if err != nil { + t.Fatal(err) + } + ps, err := p.Wait() + if err != nil { + t.Fatal(err) + } + if !ps.Success() { + t.Fatalf("script failed: %v", err) + } +} + +func TestExternalFile(t *testing.T) { + os.Open(os.Getenv("TEST_EXTERNAL_FILE")) + _, err := os.Stat(os.Getenv("TEST_EXTERNAL_FILE")) + if err != nil { + t.Fatal(err) + } +} + +func TestOSArgs(t *testing.T) { + t.Log(os.Args) +} + +func TestBenchtime(t *testing.T) { +} + +func TestCoverageCache(t *testing.T) { + result := HelloWorld("") + if result != "Hello, World!" { + t.Errorf("Expected 'Hello, World!', got '%s'", result) + } + + result = HelloWorld("Go") + if result != "Hello, Go!" { + t.Errorf("Expected 'Hello, Go!', got '%s'", result) + } +} + +-- gopath/src/mkold.go -- +package main + +import ( + "log" + "os" + "time" +) + +func main() { + d, err := time.ParseDuration(os.Args[1]) + if err != nil { + log.Fatal(err) + } + path := os.Args[2] + old := time.Now().Add(-d) + err = os.Chtimes(path, old, old) + if err != nil { + log.Fatal(err) + } +} diff --git a/src/cmd/go/testdata/script/link_matching_actionid.txt b/src/cmd/go/testdata/script/link_matching_actionid.txt deleted file mode 100644 index b8d423d027..0000000000 --- a/src/cmd/go/testdata/script/link_matching_actionid.txt +++ /dev/null @@ -1,38 +0,0 @@ -# Checks that an identical binary is built with -trimpath from the same -# source files, with GOROOT in two different locations. -# Verifies golang.org/issue/38989 - -[short] skip -[!symlink] skip - -# Symlink the compiler to a local path -env GOROOT=$WORK/goroot1 -symlink $GOROOT -> $TESTGO_GOROOT - -# Set up fresh GOCACHE -env GOCACHE=$WORK/gocache1 -mkdir $GOCACHE - -# Build a simple binary -go build -o binary1 -trimpath -x main.go - -# Now repeat the same process with the compiler at a different local path -env GOROOT=$WORK/goroot2 -symlink $GOROOT -> $TESTGO_GOROOT - -env GOCACHE=$WORK/gocache2 -mkdir $GOCACHE - -go build -o binary2 -trimpath -x main.go - -# Check that the binaries match exactly -go tool buildid binary1 -cp stdout buildid1 -go tool buildid binary2 -cp stdout buildid2 -cmp buildid1 buildid2 - - --- main.go -- -package main -func main() {} diff --git a/src/cmd/go/testdata/script/repro_build.txt b/src/cmd/go/testdata/script/repro_build.txt deleted file mode 100644 index 7c6e317cec..0000000000 --- a/src/cmd/go/testdata/script/repro_build.txt +++ /dev/null @@ -1,22 +0,0 @@ -# Check that goroutine scheduling does not affect compiler output. -# If it does, reproducible builds will not work very well. -[short] skip -[GOOS:aix] env CGO_ENABLED=0 # go.dev/issue/56896 -env GOMAXPROCS=16 -go build -a -o http16.o net/http -env GOMAXPROCS=17 -go build -a -o http17.o net/http -cmp -q http16.o http17.o -env GOMAXPROCS=18 -go build -a -o http18.o net/http -cmp -q http16.o http18.o - -# Check that goroutine scheduling does not affect linker output. -env GOMAXPROCS=16 -go build -a -o gofmt16.exe cmd/gofmt -env GOMAXPROCS=17 -go build -a -o gofmt17.exe cmd/gofmt -cmp -q gofmt16.exe gofmt17.exe -env GOMAXPROCS=18 -go build -a -o gofmt18.exe cmd/gofmt -cmp -q gofmt16.exe gofmt18.exe diff --git a/src/cmd/go/testdata/script/test_cache_inputs.txt b/src/cmd/go/testdata/script/test_cache_inputs.txt deleted file mode 100644 index 29e538c11e..0000000000 --- a/src/cmd/go/testdata/script/test_cache_inputs.txt +++ /dev/null @@ -1,354 +0,0 @@ -env GO111MODULE=off - -# Test that cached test results are invalidated in response to -# changes to the external inputs to the test. - -[short] skip -[GODEBUG:gocacheverify=1] skip - -# We're testing cache behavior, so start with a clean GOCACHE. -env GOCACHE=$WORK/cache - -# Build a helper binary to invoke os.Chtimes. -go build -o mkold$GOEXE mkold.go - -# Make test input files appear to be a minute old. -exec ./mkold$GOEXE 1m testcache/file.txt -exec ./mkold$GOEXE 1m testcache/script.sh - -# If the test reads an environment variable, changes to that variable -# should invalidate cached test results. -env TESTKEY=x -go test testcache -run=TestLookupEnv -go test testcache -run=TestLookupEnv -stdout '\(cached\)' - -# GODEBUG is always read -env GODEBUG=asdf=1 -go test testcache -run=TestLookupEnv -! stdout '\(cached\)' -go test testcache -run=TestLookupEnv -stdout '\(cached\)' -env GODEBUG= - -env TESTKEY=y -go test testcache -run=TestLookupEnv -! stdout '\(cached\)' -go test testcache -run=TestLookupEnv -stdout '\(cached\)' - -# Changes in arguments forwarded to the test should invalidate cached test -# results. -go test testcache -run=TestOSArgs -v hello -! stdout '\(cached\)' -stdout 'hello' -go test testcache -run=TestOSArgs -v goodbye -! stdout '\(cached\)' -stdout 'goodbye' - -# golang.org/issue/36134: that includes the `-timeout` argument. -go test testcache -run=TestOSArgs -timeout=20m -v -! stdout '\(cached\)' -stdout '-test\.timeout[= ]20m' -go test testcache -run=TestOSArgs -timeout=5s -v -! stdout '\(cached\)' -stdout '-test\.timeout[= ]5s' - -# If the test stats a file, changes to the file should invalidate the cache. -go test testcache -run=FileSize -go test testcache -run=FileSize -stdout '\(cached\)' - -cp 4x.txt testcache/file.txt -go test testcache -run=FileSize -! stdout '\(cached\)' -go test testcache -run=FileSize -stdout '\(cached\)' - -# Files should be tracked even if the test changes its working directory. -go test testcache -run=Chdir -go test testcache -run=Chdir -stdout '\(cached\)' -cp 6x.txt testcache/file.txt -go test testcache -run=Chdir -! stdout '\(cached\)' -go test testcache -run=Chdir -stdout '\(cached\)' - -# The content of files should affect caching, provided that the mtime also changes. -exec ./mkold$GOEXE 1m testcache/file.txt -go test testcache -run=FileContent -go test testcache -run=FileContent -stdout '\(cached\)' -cp 2y.txt testcache/file.txt -exec ./mkold$GOEXE 50s testcache/file.txt -go test testcache -run=FileContent -! stdout '\(cached\)' -go test testcache -run=FileContent -stdout '\(cached\)' - -# Directory contents read via os.ReadDirNames should affect caching. -go test testcache -run=DirList -go test testcache -run=DirList -stdout '\(cached\)' -rm testcache/file.txt -go test testcache -run=DirList -! stdout '\(cached\)' -go test testcache -run=DirList -stdout '\(cached\)' - -# Files outside GOROOT and GOPATH should not affect caching. -env TEST_EXTERNAL_FILE=$WORK/external.txt -go test testcache -run=ExternalFile -go test testcache -run=ExternalFile -stdout '\(cached\)' - -rm $WORK/external.txt -go test testcache -run=ExternalFile -stdout '\(cached\)' - -# The -benchtime flag without -bench should not affect caching. -go test testcache -run=Benchtime -benchtime=1x -go test testcache -run=Benchtime -benchtime=1x -stdout '\(cached\)' - -go test testcache -run=Benchtime -bench=Benchtime -benchtime=1x -go test testcache -run=Benchtime -bench=Benchtime -benchtime=1x -! stdout '\(cached\)' - -# golang.org/issue/47355: that includes the `-failfast` argument. -go test testcache -run=TestOSArgs -failfast -! stdout '\(cached\)' -go test testcache -run=TestOSArgs -failfast -stdout '\(cached\)' - -# golang.org/issue/64638: that includes the `-fullpath` argument. -go test testcache -run=TestOSArgs -fullpath -! stdout '\(cached\)' -go test testcache -run=TestOSArgs -fullpath -stdout '\(cached\)' - -# golang.org/issue/70692: that includes the `-skip` flag -go test testcache -run=TestOdd -skip=TestOddFile -! stdout '\(cached\)' -go test testcache -run=TestOdd -skip=TestOddFile -stdout '\(cached\)' - -# Ensure that coverage profiles are being cached. -go test testcache -run=TestCoverageCache -coverprofile=coverage.out -go test testcache -run=TestCoverageCache -coverprofile=coverage.out -stdout '\(cached\)' -exists coverage.out -grep -q 'mode: set' coverage.out -grep -q 'testcache/hello.go:' coverage.out - -# A new -coverprofile file should use the cached coverage profile contents. -go test testcache -run=TestCoverageCache -coverprofile=coverage2.out -stdout '\(cached\)' -cmp coverage.out coverage2.out - -# Explicitly setting the default covermode should still use cache. -go test testcache -run=TestCoverageCache -coverprofile=coverage_set.out -covermode=set -stdout '\(cached\)' -cmp coverage.out coverage_set.out - -# A new -covermode should not use the cached coverage profile. -go test testcache -run=TestCoverageCache -coverprofile=coverage_atomic.out -covermode=atomic -! stdout '\(cached\)' -! cmp coverage.out coverage_atomic.out -grep -q 'mode: atomic' coverage_atomic.out -grep -q 'testcache/hello.go:' coverage_atomic.out - -# A new -coverpkg should not use the cached coverage profile. -go test testcache -run=TestCoverageCache -coverprofile=coverage_pkg.out -coverpkg=all -! stdout '\(cached\)' -! cmp coverage.out coverage_pkg.out - -# Test that -v doesn't prevent caching. -go test testcache -v -run=TestCoverageCache -coverprofile=coverage_v.out -go test testcache -v -run=TestCoverageCache -coverprofile=coverage_v2.out -stdout '\(cached\)' -cmp coverage_v.out coverage_v2.out - -# Test that -count affects caching. -go test testcache -run=TestCoverageCache -coverprofile=coverage_count.out -count=2 -! stdout '\(cached\)' - -# Executables within GOROOT and GOPATH should affect caching, -# even if the test does not stat them explicitly. - -[!exec:/bin/sh] skip -chmod 0755 ./testcache/script.sh - -exec ./mkold$GOEXEC 1m testcache/script.sh -go test testcache -run=Exec -go test testcache -run=Exec -stdout '\(cached\)' - -exec ./mkold$GOEXE 50s testcache/script.sh -go test testcache -run=Exec -! stdout '\(cached\)' -go test testcache -run=Exec -stdout '\(cached\)' - --- testcache/file.txt -- -xx --- 4x.txt -- -xxxx --- 6x.txt -- -xxxxxx --- 2y.txt -- -yy --- $WORK/external.txt -- -This file is outside of GOPATH. --- testcache/script.sh -- -#!/bin/sh -exit 0 --- testcache/hello.go -- -package testcache - -import "fmt" - -func HelloWorld(name string) string { - if name == "" { - return "Hello, World!" - } - return fmt.Sprintf("Hello, %s!", name) -} - --- testcache/testcache_test.go -- -// Copyright 2017 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package testcache - -import ( - "io" - "os" - "testing" -) - -func TestChdir(t *testing.T) { - os.Chdir("..") - defer os.Chdir("testcache") - info, err := os.Stat("testcache/file.txt") - if err != nil { - t.Fatal(err) - } - if info.Size()%2 != 1 { - t.Fatal("even file") - } -} - -func TestOddFileContent(t *testing.T) { - f, err := os.Open("file.txt") - if err != nil { - t.Fatal(err) - } - data, err := io.ReadAll(f) - f.Close() - if err != nil { - t.Fatal(err) - } - if len(data)%2 != 1 { - t.Fatal("even file") - } -} - -func TestOddFileSize(t *testing.T) { - info, err := os.Stat("file.txt") - if err != nil { - t.Fatal(err) - } - if info.Size()%2 != 1 { - t.Fatal("even file") - } -} - -func TestOddGetenv(t *testing.T) { - val := os.Getenv("TESTKEY") - if len(val)%2 != 1 { - t.Fatal("even env value") - } -} - -func TestLookupEnv(t *testing.T) { - _, ok := os.LookupEnv("TESTKEY") - if !ok { - t.Fatal("env missing") - } -} - -func TestDirList(t *testing.T) { - f, err := os.Open(".") - if err != nil { - t.Fatal(err) - } - f.Readdirnames(-1) - f.Close() -} - -func TestExec(t *testing.T) { - // Note: not using os/exec to make sure there is no unexpected stat. - p, err := os.StartProcess("./script.sh", []string{"script"}, new(os.ProcAttr)) - if err != nil { - t.Fatal(err) - } - ps, err := p.Wait() - if err != nil { - t.Fatal(err) - } - if !ps.Success() { - t.Fatalf("script failed: %v", err) - } -} - -func TestExternalFile(t *testing.T) { - os.Open(os.Getenv("TEST_EXTERNAL_FILE")) - _, err := os.Stat(os.Getenv("TEST_EXTERNAL_FILE")) - if err != nil { - t.Fatal(err) - } -} - -func TestOSArgs(t *testing.T) { - t.Log(os.Args) -} - -func TestBenchtime(t *testing.T) { -} - -func TestCoverageCache(t *testing.T) { - result := HelloWorld("") - if result != "Hello, World!" { - t.Errorf("Expected 'Hello, World!', got '%s'", result) - } - - result = HelloWorld("Go") - if result != "Hello, Go!" { - t.Errorf("Expected 'Hello, Go!', got '%s'", result) - } -} - --- mkold.go -- -package main - -import ( - "log" - "os" - "time" -) - -func main() { - d, err := time.ParseDuration(os.Args[1]) - if err != nil { - log.Fatal(err) - } - path := os.Args[2] - old := time.Now().Add(-d) - err = os.Chtimes(path, old, old) - if err != nil { - log.Fatal(err) - } -} -- cgit v1.3-5-g9baa