Skip to content

Commit 1e43298

Browse files
committed
cmd/go: convert remaining non-parallel tooSlow tests to script framework
Part of converting all tests to script framework to improve test parallelism. Updates #36320 Updates #17751 Change-Id: Ib1c55a48fafb5ce040ac70707bbc2a3ee5e2ddd4 Reviewed-on: https://go-review.googlesource.com/c/go/+/214382 Reviewed-by: Bryan C. Mills <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent 9c68d85 commit 1e43298

File tree

4 files changed

+78
-107
lines changed

4 files changed

+78
-107
lines changed

src/cmd/go/go_test.go

-107
Original file line numberDiff line numberDiff line change
@@ -2357,25 +2357,6 @@ const (
23572357
okPattern = `(?m)^ok`
23582358
)
23592359

2360-
// Issue 19394
2361-
func TestWriteProfilesOnTimeout(t *testing.T) {
2362-
tooSlow(t)
2363-
tg := testgo(t)
2364-
defer tg.cleanup()
2365-
tg.tempDir("profiling")
2366-
tg.tempFile("profiling/timeouttest_test.go", `package timeouttest_test
2367-
import "testing"
2368-
import "time"
2369-
func TestSleep(t *testing.T) { time.Sleep(time.Second) }`)
2370-
tg.cd(tg.path("profiling"))
2371-
tg.runFail(
2372-
"test",
2373-
"-cpuprofile", tg.path("profiling/cpu.pprof"), "-memprofile", tg.path("profiling/mem.pprof"),
2374-
"-timeout", "1ms")
2375-
tg.mustHaveContent(tg.path("profiling/cpu.pprof"))
2376-
tg.mustHaveContent(tg.path("profiling/mem.pprof"))
2377-
}
2378-
23792360
func TestLinkXImportPathEscape(t *testing.T) {
23802361
// golang.org/issue/16710
23812362
skipIfGccgo(t, "gccgo does not support -ldflags -X")
@@ -2661,29 +2642,6 @@ func TestNeedVersion(t *testing.T) {
26612642
tg.grepStderr("compile", "does not match go tool version")
26622643
}
26632644

2664-
func TestCgoFlagContainsSpace(t *testing.T) {
2665-
tooSlow(t)
2666-
if !canCgo {
2667-
t.Skip("skipping because cgo not enabled")
2668-
}
2669-
tg := testgo(t)
2670-
defer tg.cleanup()
2671-
2672-
tg.makeTempdir()
2673-
tg.cd(tg.path("."))
2674-
tg.tempFile("main.go", `package main
2675-
// #cgo CFLAGS: -I"c flags"
2676-
// #cgo LDFLAGS: -L"ld flags"
2677-
import "C"
2678-
func main() {}
2679-
`)
2680-
tg.run("run", "-x", "main.go")
2681-
tg.grepStderr(`"-I[^"]+c flags"`, "did not find quoted c flags")
2682-
tg.grepStderrNot(`"-I[^"]+c flags".*"-I[^"]+c flags"`, "found too many quoted c flags")
2683-
tg.grepStderr(`"-L[^"]+ld flags"`, "did not find quoted ld flags")
2684-
tg.grepStderrNot(`"-L[^"]+c flags".*"-L[^"]+c flags"`, "found too many quoted ld flags")
2685-
}
2686-
26872645
// Issue 9737: verify that GOARM and GO386 affect the computed build ID.
26882646
func TestBuildIDContainsArchModeEnv(t *testing.T) {
26892647
if testing.Short() {
@@ -2783,71 +2741,6 @@ func TestBuildmodePIE(t *testing.T) {
27832741
}
27842742
}
27852743

2786-
func TestExecBuildX(t *testing.T) {
2787-
tooSlow(t)
2788-
if !canCgo {
2789-
t.Skip("skipping because cgo not enabled")
2790-
}
2791-
2792-
testenv.MustHaveExecPath(t, "/usr/bin/env")
2793-
testenv.MustHaveExecPath(t, "bash")
2794-
2795-
tg := testgo(t)
2796-
defer tg.cleanup()
2797-
2798-
tg.tempDir("cache")
2799-
tg.setenv("GOCACHE", tg.path("cache"))
2800-
2801-
// Before building our test main.go, ensure that an up-to-date copy of
2802-
// runtime/cgo is present in the cache. If it isn't, the 'go build' step below
2803-
// will fail with "can't open import". See golang.org/issue/29004.
2804-
tg.run("build", "runtime/cgo")
2805-
2806-
tg.tempFile("main.go", `package main; import "C"; func main() { print("hello") }`)
2807-
src := tg.path("main.go")
2808-
obj := tg.path("main")
2809-
tg.run("build", "-x", "-o", obj, src)
2810-
sh := tg.path("test.sh")
2811-
cmds := tg.getStderr()
2812-
err := ioutil.WriteFile(sh, []byte("set -e\n"+cmds), 0666)
2813-
if err != nil {
2814-
t.Fatal(err)
2815-
}
2816-
2817-
out, err := exec.Command(obj).CombinedOutput()
2818-
if err != nil {
2819-
t.Fatal(err)
2820-
}
2821-
if string(out) != "hello" {
2822-
t.Fatalf("got %q; want %q", out, "hello")
2823-
}
2824-
2825-
err = os.Remove(obj)
2826-
if err != nil {
2827-
t.Fatal(err)
2828-
}
2829-
2830-
out, err = exec.Command("/usr/bin/env", "bash", "-x", sh).CombinedOutput()
2831-
if err != nil {
2832-
t.Fatalf("/bin/sh %s: %v\n%s", sh, err, out)
2833-
}
2834-
t.Logf("shell output:\n%s", out)
2835-
2836-
out, err = exec.Command(obj).CombinedOutput()
2837-
if err != nil {
2838-
t.Fatal(err)
2839-
}
2840-
if string(out) != "hello" {
2841-
t.Fatalf("got %q; want %q", out, "hello")
2842-
}
2843-
2844-
matches := regexp.MustCompile(`^WORK=(.*)\n`).FindStringSubmatch(cmds)
2845-
if len(matches) == 0 {
2846-
t.Fatal("no WORK directory")
2847-
}
2848-
tg.must(robustio.RemoveAll(matches[1]))
2849-
}
2850-
28512744
func TestUpxCompression(t *testing.T) {
28522745
if runtime.GOOS != "linux" ||
28532746
(runtime.GOARCH != "amd64" && runtime.GOARCH != "386") {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
[short] skip
2+
[!cgo] skip
3+
4+
[!exec:/usr/bin/env] skip
5+
[!exec:bash] skip
6+
[!exec:cat] skip
7+
8+
mkdir $WORK/tmp/cache
9+
env GOCACHE=$WORK/tmp/cache
10+
11+
# Before building our test main.go, ensure that an up-to-date copy of
12+
# runtime/cgo is present in the cache. If it isn't, the 'go build' step below
13+
# will fail with "can't open import". See golang.org/issue/29004.
14+
#
15+
# (The fix in golang.org/issue/29004 didn't completely fix the underlying issue:
16+
# cmd/go/internal/load adds a bunch of implicit dependencies
17+
# based on various heuristics, and, due to a bug described in
18+
# https://golang.org/issue/31544#issuecomment-490607180,
19+
# those implicit dependencies are not added early enough during
20+
# loading to properly affect the import graph.)
21+
go build runtime/cgo
22+
23+
go build -x -o main main.go
24+
cp stderr commands.txt
25+
exec cat header.txt commands.txt
26+
cp stdout test.sh
27+
28+
exec ./main
29+
cmp stderr hello.txt
30+
rm ./main
31+
32+
exec /usr/bin/env bash -x test.sh
33+
exec ./main
34+
cmp stderr hello.txt
35+
36+
grep '^WORK=(.*)\n' commands.txt
37+
38+
-- main.go --
39+
package main
40+
41+
import "C"
42+
43+
func main() {
44+
print("hello\n")
45+
}
46+
-- header.txt --
47+
set -e
48+
-- hello.txt --
49+
hello
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[short] skip
2+
[!cgo] skip
3+
4+
go run -x main.go
5+
stderr '"-I[^"]+c flags"' # find quoted c flags
6+
! stderr '"-I[^"]+c flags".*"-I[^"]+c flags"' # don't find too many quoted c flags
7+
stderr '"-L[^"]+ld flags"' # find quoted ld flags
8+
! stderr '"-L[^"]+c flags".*"-L[^"]+c flags"' # don't find too many quoted ld flags
9+
10+
-- main.go --
11+
package main
12+
// #cgo CFLAGS: -I"c flags"
13+
// #cgo LDFLAGS: -L"ld flags"
14+
import "C"
15+
func main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Tests issue 19394
2+
3+
[short] skip
4+
5+
cd profiling
6+
! go test -cpuprofile cpu.pprof -memprofile mem.pprof -timeout 1ms
7+
grep . cpu.pprof
8+
grep . mem.pprof
9+
10+
-- profiling/timeout_test.go --
11+
package timeouttest_test
12+
import "testing"
13+
import "time"
14+
func TestSleep(t *testing.T) { time.Sleep(time.Second) }

0 commit comments

Comments
 (0)