]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: convert TestGoTestRaceInstallsCgo to script framework
authorMichael Matloob <matloob@golang.org>
Mon, 13 Jan 2020 16:11:06 +0000 (11:11 -0500)
committerMichael Matloob <matloob@golang.org>
Thu, 27 Feb 2020 21:25:53 +0000 (21:25 +0000)
Part of converting all tests to script framework to improve
test parallelism.

Updates #36320
Updates #17751

Change-Id: I9a99aa5d37300c83a2f95fb906949cb4c1d5356f
Reviewed-on: https://go-review.googlesource.com/c/go/+/214426
Reviewed-by: Jay Conrod <jayconrod@google.com>
src/cmd/go/go_test.go
src/cmd/go/testdata/script/test_race_install_cgo.txt [new file with mode: 0644]

index d95714deb922ab33fc536ff60504f19e1b9355b3..b0cbeee8be87ffb75a01d5a6d544ba17e65e01d6 100644 (file)
@@ -2013,37 +2013,6 @@ func TestGoInstallPkgdir(t *testing.T) {
        tg.mustExist(filepath.Join(pkg, "sync/atomic.a"))
 }
 
-func TestGoTestRaceInstallCgo(t *testing.T) {
-       if !canRace {
-               t.Skip("skipping because race detector not supported")
-       }
-
-       // golang.org/issue/10500.
-       // This used to install a race-enabled cgo.
-       tg := testgo(t)
-       defer tg.cleanup()
-       tg.run("tool", "-n", "cgo")
-       cgo := strings.TrimSpace(tg.stdout.String())
-       old, err := os.Stat(cgo)
-       tg.must(err)
-
-       // For this test, we don't actually care whether 'go test -race -i' succeeds.
-       // It may fail, for example, if GOROOT was installed from source as root and
-       // is now read-only.
-       // We only care that — regardless of whether it succeeds — it does not
-       // overwrite cmd/cgo.
-       runArgs := []string{"test", "-race", "-i", "runtime/race"}
-       if status := tg.doRun(runArgs); status != nil {
-               tg.t.Logf("go %v failure ignored: %v", runArgs, status)
-       }
-
-       new, err := os.Stat(cgo)
-       tg.must(err)
-       if !new.ModTime().Equal(old.ModTime()) {
-               t.Fatalf("go test -i runtime/race reinstalled cmd/cgo")
-       }
-}
-
 func TestGoInstallShadowedGOPATH(t *testing.T) {
        // golang.org/issue/3652.
        // go get foo.io (not foo.io/subdir) was not working consistently.
diff --git a/src/cmd/go/testdata/script/test_race_install_cgo.txt b/src/cmd/go/testdata/script/test_race_install_cgo.txt
new file mode 100644 (file)
index 0000000..eac3241
--- /dev/null
@@ -0,0 +1,91 @@
+# Tests Issue #10500
+
+[!race] skip
+
+env GOBIN=$WORK/bin
+go install mtime sametime
+
+go tool -n cgo
+cp stdout cgopath.txt
+exec $GOBIN/mtime cgopath.txt # get the mtime of the file whose name is in cgopath.txt
+cp stdout cgotime_before.txt
+
+ # For this test, we don't actually care whether 'go test -race -i' succeeds.
+ # It may fail, for example, if GOROOT was installed from source as root and
+ # is now read-only.
+ # We only care that — regardless of whether it succeeds — it does not
+ # overwrite cmd/cgo.
+go test -race -i runtime/race
+
+exec $GOBIN/mtime cgopath.txt # get the mtime of the file whose name is in cgopath.txt
+cp stdout cgotime_after.txt
+exec $GOBIN/sametime cgotime_before.txt cgotime_after.txt
+
+-- mtime/mtime.go --
+package main
+
+import (
+       "io/ioutil"
+       "encoding/json"
+       "fmt"
+       "os"
+       "strings"
+)
+
+func main() {
+       b, err := ioutil.ReadFile(os.Args[1])
+       if err != nil {
+               fmt.Fprintln(os.Stderr, err)
+               os.Exit(1)
+       }
+       filename := strings.TrimSpace(string(b))
+       info, err := os.Stat(filename)
+       if err != nil {
+               fmt.Fprintln(os.Stderr, err)
+               os.Exit(1)
+       }
+       if err := json.NewEncoder(os.Stdout).Encode(info.ModTime()); err != nil {
+               fmt.Fprintln(os.Stderr, err)
+               os.Exit(1)
+       }
+}
+-- sametime/sametime.go --
+package main
+
+import (
+       "encoding/json"
+       "fmt"
+       "io/ioutil"
+       "os"
+       "time"
+)
+
+
+func main() {
+       var t1 time.Time
+       b1, err := ioutil.ReadFile(os.Args[1])
+       if err != nil {
+               fmt.Fprintln(os.Stderr, err)
+               os.Exit(1)
+       }
+       if err := json.Unmarshal(b1, &t1); err != nil  {
+               fmt.Fprintln(os.Stderr, err)
+               os.Exit(1)
+       }
+
+       var t2 time.Time
+       b2, err := ioutil.ReadFile(os.Args[2])
+       if err != nil {
+               fmt.Fprintln(os.Stderr, err)
+               os.Exit(1)
+       }
+       if err := json.Unmarshal(b2, &t2); err != nil  {
+               fmt.Fprintln(os.Stderr, err)
+               os.Exit(1)
+       }
+
+       if !t1.Equal(t2) {
+               fmt.Fprintf(os.Stderr, "time in %v (%v) is not the same as time in %v (%v)", os.Args[1], t1, os.Args[2], t2)
+               os.Exit(1)
+       }
+}
\ No newline at end of file