Skip to content

Commit ff811c8

Browse files
committed
cmd/go: convert TestGoTestRaceInstallsCgo to script framework
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>
1 parent c40914b commit ff811c8

File tree

2 files changed

+91
-31
lines changed

2 files changed

+91
-31
lines changed

src/cmd/go/go_test.go

-31
Original file line numberDiff line numberDiff line change
@@ -2013,37 +2013,6 @@ func TestGoInstallPkgdir(t *testing.T) {
20132013
tg.mustExist(filepath.Join(pkg, "sync/atomic.a"))
20142014
}
20152015

2016-
func TestGoTestRaceInstallCgo(t *testing.T) {
2017-
if !canRace {
2018-
t.Skip("skipping because race detector not supported")
2019-
}
2020-
2021-
// golang.org/issue/10500.
2022-
// This used to install a race-enabled cgo.
2023-
tg := testgo(t)
2024-
defer tg.cleanup()
2025-
tg.run("tool", "-n", "cgo")
2026-
cgo := strings.TrimSpace(tg.stdout.String())
2027-
old, err := os.Stat(cgo)
2028-
tg.must(err)
2029-
2030-
// For this test, we don't actually care whether 'go test -race -i' succeeds.
2031-
// It may fail, for example, if GOROOT was installed from source as root and
2032-
// is now read-only.
2033-
// We only care that — regardless of whether it succeeds — it does not
2034-
// overwrite cmd/cgo.
2035-
runArgs := []string{"test", "-race", "-i", "runtime/race"}
2036-
if status := tg.doRun(runArgs); status != nil {
2037-
tg.t.Logf("go %v failure ignored: %v", runArgs, status)
2038-
}
2039-
2040-
new, err := os.Stat(cgo)
2041-
tg.must(err)
2042-
if !new.ModTime().Equal(old.ModTime()) {
2043-
t.Fatalf("go test -i runtime/race reinstalled cmd/cgo")
2044-
}
2045-
}
2046-
20472016
func TestGoInstallShadowedGOPATH(t *testing.T) {
20482017
// golang.org/issue/3652.
20492018
// go get foo.io (not foo.io/subdir) was not working consistently.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Tests Issue #10500
2+
3+
[!race] skip
4+
5+
env GOBIN=$WORK/bin
6+
go install mtime sametime
7+
8+
go tool -n cgo
9+
cp stdout cgopath.txt
10+
exec $GOBIN/mtime cgopath.txt # get the mtime of the file whose name is in cgopath.txt
11+
cp stdout cgotime_before.txt
12+
13+
# For this test, we don't actually care whether 'go test -race -i' succeeds.
14+
# It may fail, for example, if GOROOT was installed from source as root and
15+
# is now read-only.
16+
# We only care that — regardless of whether it succeeds — it does not
17+
# overwrite cmd/cgo.
18+
go test -race -i runtime/race
19+
20+
exec $GOBIN/mtime cgopath.txt # get the mtime of the file whose name is in cgopath.txt
21+
cp stdout cgotime_after.txt
22+
exec $GOBIN/sametime cgotime_before.txt cgotime_after.txt
23+
24+
-- mtime/mtime.go --
25+
package main
26+
27+
import (
28+
"io/ioutil"
29+
"encoding/json"
30+
"fmt"
31+
"os"
32+
"strings"
33+
)
34+
35+
func main() {
36+
b, err := ioutil.ReadFile(os.Args[1])
37+
if err != nil {
38+
fmt.Fprintln(os.Stderr, err)
39+
os.Exit(1)
40+
}
41+
filename := strings.TrimSpace(string(b))
42+
info, err := os.Stat(filename)
43+
if err != nil {
44+
fmt.Fprintln(os.Stderr, err)
45+
os.Exit(1)
46+
}
47+
if err := json.NewEncoder(os.Stdout).Encode(info.ModTime()); err != nil {
48+
fmt.Fprintln(os.Stderr, err)
49+
os.Exit(1)
50+
}
51+
}
52+
-- sametime/sametime.go --
53+
package main
54+
55+
import (
56+
"encoding/json"
57+
"fmt"
58+
"io/ioutil"
59+
"os"
60+
"time"
61+
)
62+
63+
64+
func main() {
65+
var t1 time.Time
66+
b1, err := ioutil.ReadFile(os.Args[1])
67+
if err != nil {
68+
fmt.Fprintln(os.Stderr, err)
69+
os.Exit(1)
70+
}
71+
if err := json.Unmarshal(b1, &t1); err != nil {
72+
fmt.Fprintln(os.Stderr, err)
73+
os.Exit(1)
74+
}
75+
76+
var t2 time.Time
77+
b2, err := ioutil.ReadFile(os.Args[2])
78+
if err != nil {
79+
fmt.Fprintln(os.Stderr, err)
80+
os.Exit(1)
81+
}
82+
if err := json.Unmarshal(b2, &t2); err != nil {
83+
fmt.Fprintln(os.Stderr, err)
84+
os.Exit(1)
85+
}
86+
87+
if !t1.Equal(t2) {
88+
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)
89+
os.Exit(1)
90+
}
91+
}

0 commit comments

Comments
 (0)