Skip to content

Commit e7173df

Browse files
committed
test: migrate remaining tests to run.go
* bug248, bug345, bug369, and bug429 were ported from bash commands to run scripts. bug369 remains disabled. * bug395 is a test for issue 1909, which is still open. It is marked as skip now and will be usable with compile with run.go when issue 1909 is fixed. Fixes #4139 Updates #1909 Change-Id: Ibb5fbfb5cf72ddc285829245318eeacd3fb5a636 Reviewed-on: https://go-review.googlesource.com/1774 Reviewed-by: Russ Cox <rsc@golang.org>
1 parent 11779ef commit e7173df

File tree

10 files changed

+222
-239
lines changed

10 files changed

+222
-239
lines changed

test/bugs/bug395.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
// echo bug395 is broken # takes 90+ seconds to break
2-
// # $G $D/$F.go || echo bug395
1+
// skip
32

4-
// NOTE: This test is not run by 'run.go' and so not run by all.bash.
5-
// To run this test you must use the ./run shell script.
3+
// When issue 1909 is fixed, change from skip to compile.
64

75
// Copyright 2011 The Go Authors. All rights reserved.
86
// Use of this source code is governed by a BSD-style
97
// license that can be found in the LICENSE file.
108

119
// Issue 1909
1210
// Would OOM due to exponential recursion on Foo's expanded methodset in nodefmt
11+
1312
package test
1413

1514
type Foo interface {

test/fixedbugs/bug248.go

+51-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,56 @@
1-
// $G $D/$F.dir/bug0.go &&
2-
// $G $D/$F.dir/bug1.go &&
3-
// $G $D/$F.dir/bug2.go &&
4-
// errchk $G -e $D/$F.dir/bug3.go &&
5-
// $L bug2.$A &&
6-
// ./$A.out || echo BUG: failed to compile
7-
8-
// NOTE: This test is not run by 'run.go' and so not run by all.bash.
9-
// To run this test you must use the ./run shell script.
1+
// +build !nacl
2+
// run
103

114
// Copyright 2009 The Go Authors. All rights reserved.
125
// Use of this source code is governed by a BSD-style
136
// license that can be found in the LICENSE file.
147

15-
ignored
8+
package main
9+
10+
import (
11+
"fmt"
12+
"go/build"
13+
"os"
14+
"os/exec"
15+
"path/filepath"
16+
)
17+
18+
func main() {
19+
a, err := build.ArchChar(build.Default.GOARCH)
20+
check(err)
21+
22+
errchk, err := filepath.Abs("errchk")
23+
check(err)
24+
25+
err = os.Chdir(filepath.Join("fixedbugs", "bug248.dir"))
26+
check(err)
27+
28+
run("go", "tool", a+"g", "bug0.go")
29+
run("go", "tool", a+"g", "bug1.go")
30+
run("go", "tool", a+"g", "bug2.go")
31+
run(errchk, "go", "tool", a+"g", "-e", "bug3.go")
32+
run("go", "tool", a+"l", "bug2."+a)
33+
run(fmt.Sprintf(".%c%s.out", filepath.Separator, a))
34+
35+
os.Remove("bug0." + a)
36+
os.Remove("bug1." + a)
37+
os.Remove("bug2." + a)
38+
os.Remove(a + ".out")
39+
}
40+
41+
func run(name string, args ...string) {
42+
cmd := exec.Command(name, args...)
43+
out, err := cmd.CombinedOutput()
44+
if err != nil {
45+
fmt.Println(string(out))
46+
fmt.Println(err)
47+
os.Exit(1)
48+
}
49+
}
50+
51+
func check(err error) {
52+
if err != nil {
53+
fmt.Println(err)
54+
os.Exit(1)
55+
}
56+
}

test/fixedbugs/bug345.go

+43-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,48 @@
1-
// $G $D/$F.dir/io.go && errchk $G -e $D/$F.dir/main.go
2-
3-
// NOTE: This test is not run by 'run.go' and so not run by all.bash.
4-
// To run this test you must use the ./run shell script.
1+
// +build !nacl
2+
// run
53

64
// Copyright 2011 The Go Authors. All rights reserved.
75
// Use of this source code is governed by a BSD-style
86
// license that can be found in the LICENSE file.
97

10-
package ignored
8+
package main
9+
10+
import (
11+
"fmt"
12+
"go/build"
13+
"os"
14+
"os/exec"
15+
"path/filepath"
16+
)
17+
18+
func main() {
19+
a, err := build.ArchChar(build.Default.GOARCH)
20+
check(err)
21+
22+
errchk, err := filepath.Abs("errchk")
23+
check(err)
24+
25+
err = os.Chdir(filepath.Join(".", "fixedbugs", "bug345.dir"))
26+
check(err)
27+
28+
run("go", "tool", a+"g", "io.go")
29+
run(errchk, "go", "tool", a+"g", "-e", "main.go")
30+
os.Remove("io." + a)
31+
}
32+
33+
func run(name string, args ...string) {
34+
cmd := exec.Command(name, args...)
35+
out, err := cmd.CombinedOutput()
36+
if err != nil {
37+
fmt.Println(string(out))
38+
fmt.Println(err)
39+
os.Exit(1)
40+
}
41+
}
42+
43+
func check(err error) {
44+
if err != nil {
45+
fmt.Println(err)
46+
os.Exit(1)
47+
}
48+
}

test/fixedbugs/bug369.dir/main.go

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2011 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import (
8+
"flag"
9+
"os"
10+
"runtime"
11+
"testing"
12+
13+
fast "./fast"
14+
slow "./slow"
15+
)
16+
17+
var buf = make([]byte, 1048576)
18+
19+
func BenchmarkFastNonASCII(b *testing.B) {
20+
for i := 0; i < b.N; i++ {
21+
fast.NonASCII(buf, 0)
22+
}
23+
}
24+
25+
func BenchmarkSlowNonASCII(b *testing.B) {
26+
for i := 0; i < b.N; i++ {
27+
slow.NonASCII(buf, 0)
28+
}
29+
}
30+
31+
func main() {
32+
os.Args = []string{os.Args[0], "-test.benchtime=100ms"}
33+
flag.Parse()
34+
35+
rslow := testing.Benchmark(BenchmarkSlowNonASCII)
36+
rfast := testing.Benchmark(BenchmarkFastNonASCII)
37+
tslow := rslow.NsPerOp()
38+
tfast := rfast.NsPerOp()
39+
40+
// Optimization should be good for at least 2x, but be forgiving.
41+
// On the ARM simulator we see closer to 1.5x.
42+
speedup := float64(tslow) / float64(tfast)
43+
want := 1.8
44+
if runtime.GOARCH == "arm" {
45+
want = 1.3
46+
}
47+
if speedup < want {
48+
// TODO(rsc): doesn't work on linux-amd64 or darwin-amd64 builders, nor on
49+
// a Lenovo x200 (linux-amd64) laptop.
50+
// println("fast:", tfast, "slow:", tslow, "speedup:", speedup, "want:", want)
51+
// println("not fast enough")
52+
// os.Exit(1)
53+
}
54+
}

test/fixedbugs/bug369.go

+33-41
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
// $G -N -o slow.$A $D/bug369.dir/pkg.go &&
2-
// $G -o fast.$A $D/bug369.dir/pkg.go &&
1+
// +build !nacl
32
// run
43

5-
// NOTE: This test is not run by 'run.go' and so not run by all.bash.
6-
// To run this test you must use the ./run shell script.
7-
84
// Copyright 2011 The Go Authors. All rights reserved.
95
// Use of this source code is governed by a BSD-style
106
// license that can be found in the LICENSE file.
@@ -14,49 +10,45 @@
1410
package main
1511

1612
import (
17-
"flag"
13+
"fmt"
14+
"go/build"
1815
"os"
19-
"runtime"
20-
"testing"
21-
22-
fast "./fast"
23-
slow "./slow"
16+
"os/exec"
17+
"path/filepath"
2418
)
2519

26-
var buf = make([]byte, 1048576)
27-
28-
func BenchmarkFastNonASCII(b *testing.B) {
29-
for i := 0; i < b.N; i++ {
30-
fast.NonASCII(buf, 0)
31-
}
20+
func main() {
21+
a, err := build.ArchChar(build.Default.GOARCH)
22+
check(err)
23+
24+
err = os.Chdir(filepath.Join(".", "fixedbugs", "bug369.dir"))
25+
check(err)
26+
27+
run("go", "tool", a+"g", "-N", "-o", "slow."+a, "pkg.go")
28+
run("go", "tool", a+"g", "-o", "fast."+a, "pkg.go")
29+
run("go", "tool", a+"g", "-o", "main."+a, "main.go")
30+
run("go", "tool", a+"l", "-o", "a.exe", "main."+a)
31+
run("." + string(filepath.Separator) + "a.exe")
32+
33+
os.Remove("slow." + a)
34+
os.Remove("fast." + a)
35+
os.Remove("main." + a)
36+
os.Remove("a.exe")
3237
}
3338

34-
func BenchmarkSlowNonASCII(b *testing.B) {
35-
for i := 0; i < b.N; i++ {
36-
slow.NonASCII(buf, 0)
39+
func run(name string, args ...string) {
40+
cmd := exec.Command(name, args...)
41+
out, err := cmd.CombinedOutput()
42+
if err != nil {
43+
fmt.Println(string(out))
44+
fmt.Println(err)
45+
os.Exit(1)
3746
}
3847
}
3948

40-
func main() {
41-
os.Args = []string{os.Args[0], "-test.benchtime=100ms"}
42-
flag.Parse()
43-
44-
rslow := testing.Benchmark(BenchmarkSlowNonASCII)
45-
rfast := testing.Benchmark(BenchmarkFastNonASCII)
46-
tslow := rslow.NsPerOp()
47-
tfast := rfast.NsPerOp()
48-
49-
// Optimization should be good for at least 2x, but be forgiving.
50-
// On the ARM simulator we see closer to 1.5x.
51-
speedup := float64(tslow)/float64(tfast)
52-
want := 1.8
53-
if runtime.GOARCH == "arm" {
54-
want = 1.3
55-
}
56-
if speedup < want {
57-
// TODO(rsc): doesn't work on linux-amd64 or darwin-amd64 builders, nor on
58-
// a Lenovo x200 (linux-amd64) laptop.
59-
//println("fast:", tfast, "slow:", tslow, "speedup:", speedup, "want:", want)
60-
//println("not fast enough")
49+
func check(err error) {
50+
if err != nil {
51+
fmt.Println(err)
52+
os.Exit(1)
6153
}
6254
}

test/fixedbugs/bug429.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
// $G $D/$F.go && $L $F.$A && ! ./$A.out || echo BUG: bug429
2-
3-
// NOTE: This test is not run by 'run.go' and so not run by all.bash.
4-
// To run this test you must use the ./run shell script.
1+
// skip
52

63
// Copyright 2012 The Go Authors. All rights reserved.
74
// Use of this source code is governed by a BSD-style
85
// license that can be found in the LICENSE file.
96

107
// Should print deadlock message, not hang.
8+
// This test is run by bug429_run.go.
119

1210
package main
1311

test/fixedbugs/bug429_run.go

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// +build !nacl
2+
// run
3+
4+
// Copyright 2014 The Go Authors. All rights reserved.
5+
// Use of this source code is governed by a BSD-style
6+
// license that can be found in the LICENSE file.
7+
8+
// Run the bug429.go test.
9+
10+
package main
11+
12+
import (
13+
"fmt"
14+
"os"
15+
"os/exec"
16+
"path/filepath"
17+
"strings"
18+
)
19+
20+
func main() {
21+
cmd := exec.Command("go", "run", filepath.Join("fixedbugs", "bug429.go"))
22+
out, err := cmd.CombinedOutput()
23+
if err == nil {
24+
fmt.Println("expected deadlock")
25+
os.Exit(1)
26+
}
27+
28+
want := "fatal error: all goroutines are asleep - deadlock!"
29+
got := string(out)
30+
if !strings.Contains(got, want) {
31+
fmt.Printf("got:\n%q\nshould contain:\n%q\n", got, want)
32+
os.Exit(1)
33+
}
34+
}

test/golden.out

-24
This file was deleted.

0 commit comments

Comments
 (0)