Commit 776298ab authored by Keith Randall's avatar Keith Randall Committed by Keith Randall

cmd/compile: move autogenerated tests to new infrastructure

Update #26469

R=go1.12

Change-Id: Ib9a00ee5e98371769669bb9cad58320b66127374
Reviewed-on: https://go-review.googlesource.com/127095
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarDavid Chase <drchase@google.com>
parent ed21535a
...@@ -227,17 +227,8 @@ func TestCode(t *testing.T) { ...@@ -227,17 +227,8 @@ func TestCode(t *testing.T) {
} }
} }
// TestArithmeticBoundary tests boundary results for arithmetic operations.
func TestArithmeticBoundary(t *testing.T) { runTest(t, "arithBoundary.go") }
// TestArithmeticConst tests results for arithmetic operations against constants.
func TestArithmeticConst(t *testing.T) { runTest(t, "arithConst.go") }
func TestChan(t *testing.T) { runTest(t, "chan.go") } func TestChan(t *testing.T) { runTest(t, "chan.go") }
// TestComparisonsConst tests results for comparison operations against constants.
func TestComparisonsConst(t *testing.T) { runTest(t, "cmpConst.go") }
func TestCompound(t *testing.T) { runTest(t, "compound.go") } func TestCompound(t *testing.T) { runTest(t, "compound.go") }
func TestCtl(t *testing.T) { runTest(t, "ctl.go") } func TestCtl(t *testing.T) { runTest(t, "ctl.go") }
...@@ -259,12 +250,8 @@ func TestArray(t *testing.T) { runTest(t, "array.go") } ...@@ -259,12 +250,8 @@ func TestArray(t *testing.T) { runTest(t, "array.go") }
func TestAppend(t *testing.T) { runTest(t, "append.go") } func TestAppend(t *testing.T) { runTest(t, "append.go") }
func TestZero(t *testing.T) { runTest(t, "zero.go") }
func TestAddressed(t *testing.T) { runTest(t, "addressed.go") } func TestAddressed(t *testing.T) { runTest(t, "addressed.go") }
func TestCopy(t *testing.T) { runTest(t, "copy.go") }
func TestUnsafe(t *testing.T) { runTest(t, "unsafe.go") } func TestUnsafe(t *testing.T) { runTest(t, "unsafe.go") }
func TestPhi(t *testing.T) { runTest(t, "phi.go") } func TestPhi(t *testing.T) { runTest(t, "phi.go") }
......
// run
// Code generated by gen/arithConstGen.go. DO NOT EDIT. // Code generated by gen/arithConstGen.go. DO NOT EDIT.
package main package main
import "fmt" import "testing"
import "os"
//go:noinline //go:noinline
func add_uint64_0(a uint64) uint64 { return a + 0 } func add_uint64_0(a uint64) uint64 { return a + 0 }
...@@ -9506,83 +9504,67 @@ var tests_int8 = []test_int8{ ...@@ -9506,83 +9504,67 @@ var tests_int8 = []test_int8{
test_int8{fn: xor_127_int8, fnname: "xor_127_int8", in: 127, want: 0}, test_int8{fn: xor_127_int8, fnname: "xor_127_int8", in: 127, want: 0},
test_int8{fn: xor_int8_127, fnname: "xor_int8_127", in: 127, want: 0}} test_int8{fn: xor_int8_127, fnname: "xor_int8_127", in: 127, want: 0}}
var failed bool // TestArithmeticConst tests results for arithmetic operations against constants.
func TestArithmeticConst(t *testing.T) {
func main() {
for _, test := range tests_uint64 { for _, test := range tests_uint64 {
if got := test.fn(test.in); got != test.want { if got := test.fn(test.in); got != test.want {
fmt.Printf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) t.Errorf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want)
failed = true
} }
} }
for _, test := range tests_uint64mul { for _, test := range tests_uint64mul {
if got := test.fn(test.in); got != test.want { if got := test.fn(test.in); got != test.want {
fmt.Printf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) t.Errorf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want)
failed = true
} }
} }
for _, test := range tests_int64 { for _, test := range tests_int64 {
if got := test.fn(test.in); got != test.want { if got := test.fn(test.in); got != test.want {
fmt.Printf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) t.Errorf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want)
failed = true
} }
} }
for _, test := range tests_int64mul { for _, test := range tests_int64mul {
if got := test.fn(test.in); got != test.want { if got := test.fn(test.in); got != test.want {
fmt.Printf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) t.Errorf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want)
failed = true
} }
} }
for _, test := range tests_uint32 { for _, test := range tests_uint32 {
if got := test.fn(test.in); got != test.want { if got := test.fn(test.in); got != test.want {
fmt.Printf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) t.Errorf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want)
failed = true
} }
} }
for _, test := range tests_uint32mul { for _, test := range tests_uint32mul {
if got := test.fn(test.in); got != test.want { if got := test.fn(test.in); got != test.want {
fmt.Printf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) t.Errorf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want)
failed = true
} }
} }
for _, test := range tests_int32 { for _, test := range tests_int32 {
if got := test.fn(test.in); got != test.want { if got := test.fn(test.in); got != test.want {
fmt.Printf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) t.Errorf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want)
failed = true
} }
} }
for _, test := range tests_int32mul { for _, test := range tests_int32mul {
if got := test.fn(test.in); got != test.want { if got := test.fn(test.in); got != test.want {
fmt.Printf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) t.Errorf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want)
failed = true
} }
} }
for _, test := range tests_uint16 { for _, test := range tests_uint16 {
if got := test.fn(test.in); got != test.want { if got := test.fn(test.in); got != test.want {
fmt.Printf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) t.Errorf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want)
failed = true
} }
} }
for _, test := range tests_int16 { for _, test := range tests_int16 {
if got := test.fn(test.in); got != test.want { if got := test.fn(test.in); got != test.want {
fmt.Printf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) t.Errorf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want)
failed = true
} }
} }
for _, test := range tests_uint8 { for _, test := range tests_uint8 {
if got := test.fn(test.in); got != test.want { if got := test.fn(test.in); got != test.want {
fmt.Printf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) t.Errorf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want)
failed = true
} }
} }
for _, test := range tests_int8 { for _, test := range tests_int8 {
if got := test.fn(test.in); got != test.want { if got := test.fn(test.in); got != test.want {
fmt.Printf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) t.Errorf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want)
failed = true
} }
} }
if failed {
os.Exit(1)
}
} }
// run
// Code generated by gen/cmpConstGen.go. DO NOT EDIT. // Code generated by gen/cmpConstGen.go. DO NOT EDIT.
package main package main
import ( import (
"fmt"
"reflect" "reflect"
"runtime" "runtime"
"testing"
) )
// results show the expected result for the elements left of, equal to and right of the index. // results show the expected result for the elements left of, equal to and right of the index.
...@@ -2093,7 +2092,8 @@ var int8_tests = []struct { ...@@ -2093,7 +2092,8 @@ var int8_tests = []struct {
{idx: 6, exp: ne, fn: ne_127_int8}, {idx: 6, exp: ne, fn: ne_127_int8},
} }
func main() { // TestComparisonsConst tests results for comparison operations against constants.
func TestComparisonsConst(t *testing.T) {
for i, test := range uint64_tests { for i, test := range uint64_tests {
for j, x := range uint64_vals { for j, x := range uint64_vals {
want := test.exp.l want := test.exp.l
...@@ -2104,8 +2104,7 @@ func main() { ...@@ -2104,8 +2104,7 @@ func main() {
} }
if test.fn(x) != want { if test.fn(x) != want {
fn := runtime.FuncForPC(reflect.ValueOf(test.fn).Pointer()).Name() fn := runtime.FuncForPC(reflect.ValueOf(test.fn).Pointer()).Name()
msg := fmt.Sprintf("test failed: %v(%v) != %v [type=uint64 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx) t.Errorf("test failed: %v(%v) != %v [type=uint64 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx)
panic(msg)
} }
} }
} }
...@@ -2119,8 +2118,7 @@ func main() { ...@@ -2119,8 +2118,7 @@ func main() {
} }
if test.fn(x) != want { if test.fn(x) != want {
fn := runtime.FuncForPC(reflect.ValueOf(test.fn).Pointer()).Name() fn := runtime.FuncForPC(reflect.ValueOf(test.fn).Pointer()).Name()
msg := fmt.Sprintf("test failed: %v(%v) != %v [type=uint32 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx) t.Errorf("test failed: %v(%v) != %v [type=uint32 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx)
panic(msg)
} }
} }
} }
...@@ -2134,8 +2132,7 @@ func main() { ...@@ -2134,8 +2132,7 @@ func main() {
} }
if test.fn(x) != want { if test.fn(x) != want {
fn := runtime.FuncForPC(reflect.ValueOf(test.fn).Pointer()).Name() fn := runtime.FuncForPC(reflect.ValueOf(test.fn).Pointer()).Name()
msg := fmt.Sprintf("test failed: %v(%v) != %v [type=uint16 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx) t.Errorf("test failed: %v(%v) != %v [type=uint16 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx)
panic(msg)
} }
} }
} }
...@@ -2149,8 +2146,7 @@ func main() { ...@@ -2149,8 +2146,7 @@ func main() {
} }
if test.fn(x) != want { if test.fn(x) != want {
fn := runtime.FuncForPC(reflect.ValueOf(test.fn).Pointer()).Name() fn := runtime.FuncForPC(reflect.ValueOf(test.fn).Pointer()).Name()
msg := fmt.Sprintf("test failed: %v(%v) != %v [type=uint8 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx) t.Errorf("test failed: %v(%v) != %v [type=uint8 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx)
panic(msg)
} }
} }
} }
...@@ -2164,8 +2160,7 @@ func main() { ...@@ -2164,8 +2160,7 @@ func main() {
} }
if test.fn(x) != want { if test.fn(x) != want {
fn := runtime.FuncForPC(reflect.ValueOf(test.fn).Pointer()).Name() fn := runtime.FuncForPC(reflect.ValueOf(test.fn).Pointer()).Name()
msg := fmt.Sprintf("test failed: %v(%v) != %v [type=int64 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx) t.Errorf("test failed: %v(%v) != %v [type=int64 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx)
panic(msg)
} }
} }
} }
...@@ -2179,8 +2174,7 @@ func main() { ...@@ -2179,8 +2174,7 @@ func main() {
} }
if test.fn(x) != want { if test.fn(x) != want {
fn := runtime.FuncForPC(reflect.ValueOf(test.fn).Pointer()).Name() fn := runtime.FuncForPC(reflect.ValueOf(test.fn).Pointer()).Name()
msg := fmt.Sprintf("test failed: %v(%v) != %v [type=int32 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx) t.Errorf("test failed: %v(%v) != %v [type=int32 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx)
panic(msg)
} }
} }
} }
...@@ -2194,8 +2188,7 @@ func main() { ...@@ -2194,8 +2188,7 @@ func main() {
} }
if test.fn(x) != want { if test.fn(x) != want {
fn := runtime.FuncForPC(reflect.ValueOf(test.fn).Pointer()).Name() fn := runtime.FuncForPC(reflect.ValueOf(test.fn).Pointer()).Name()
msg := fmt.Sprintf("test failed: %v(%v) != %v [type=int16 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx) t.Errorf("test failed: %v(%v) != %v [type=int16 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx)
panic(msg)
} }
} }
} }
...@@ -2209,8 +2202,7 @@ func main() { ...@@ -2209,8 +2202,7 @@ func main() {
} }
if test.fn(x) != want { if test.fn(x) != want {
fn := runtime.FuncForPC(reflect.ValueOf(test.fn).Pointer()).Name() fn := runtime.FuncForPC(reflect.ValueOf(test.fn).Pointer()).Name()
msg := fmt.Sprintf("test failed: %v(%v) != %v [type=int8 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx) t.Errorf("test failed: %v(%v) != %v [type=int8 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx)
panic(msg)
} }
} }
} }
......
...@@ -91,10 +91,9 @@ var ops = []op{op{"add", "+"}, op{"sub", "-"}, op{"div", "/"}, op{"mod", "%%"}, ...@@ -91,10 +91,9 @@ var ops = []op{op{"add", "+"}, op{"sub", "-"}, op{"div", "/"}, op{"mod", "%%"},
func main() { func main() {
w := new(bytes.Buffer) w := new(bytes.Buffer)
fmt.Fprintf(w, "// run\n")
fmt.Fprintf(w, "// Code generated by gen/arithBoundaryGen.go. DO NOT EDIT.\n\n") fmt.Fprintf(w, "// Code generated by gen/arithBoundaryGen.go. DO NOT EDIT.\n\n")
fmt.Fprintf(w, "package main;\n") fmt.Fprintf(w, "package main;\n")
fmt.Fprintf(w, "import \"fmt\"\n") fmt.Fprintf(w, "import \"testing\"\n")
for _, sz := range []int{64, 32, 16, 8} { for _, sz := range []int{64, 32, 16, 8} {
fmt.Fprintf(w, "type utd%d struct {\n", sz) fmt.Fprintf(w, "type utd%d struct {\n", sz)
...@@ -160,13 +159,12 @@ func main() { ...@@ -160,13 +159,12 @@ func main() {
} }
} }
fmt.Fprintf(w, "var failed bool\n\n") fmt.Fprintf(w, "//TestArithmeticBoundary tests boundary results for arithmetic operations.\n")
fmt.Fprintf(w, "func main() {\n\n") fmt.Fprintf(w, "func TestArithmeticBoundary(t *testing.T) {\n\n")
verify, err := template.New("tst").Parse( verify, err := template.New("tst").Parse(
`if got := {{.Name}}_{{.Stype}}_ssa(v.a, v.b); got != v.{{.Name}} { `if got := {{.Name}}_{{.Stype}}_ssa(v.a, v.b); got != v.{{.Name}} {
fmt.Printf("{{.Name}}_{{.Stype}} %d{{.Symbol}}%d = %d, wanted %d\n",v.a,v.b,got,v.{{.Name}}) t.Errorf("{{.Name}}_{{.Stype}} %d{{.Symbol}}%d = %d, wanted %d\n",v.a,v.b,got,v.{{.Name}})
failed = true
} }
`) `)
...@@ -193,10 +191,6 @@ func main() { ...@@ -193,10 +191,6 @@ func main() {
fmt.Fprint(w, " }\n") fmt.Fprint(w, " }\n")
} }
fmt.Fprintf(w, `if failed {
panic("tests failed")
}
`)
fmt.Fprintf(w, "}\n") fmt.Fprintf(w, "}\n")
// gofmt result // gofmt result
...@@ -208,7 +202,7 @@ func main() { ...@@ -208,7 +202,7 @@ func main() {
} }
// write to file // write to file
err = ioutil.WriteFile("../arithBoundary.go", src, 0666) err = ioutil.WriteFile("../arithBoundary_test.go", src, 0666)
if err != nil { if err != nil {
log.Fatalf("can't write output: %v\n", err) log.Fatalf("can't write output: %v\n", err)
} }
......
...@@ -148,11 +148,9 @@ func ansS(i, j int64, t, op string) string { ...@@ -148,11 +148,9 @@ func ansS(i, j int64, t, op string) string {
func main() { func main() {
w := new(bytes.Buffer) w := new(bytes.Buffer)
fmt.Fprintf(w, "// run\n")
fmt.Fprintf(w, "// Code generated by gen/arithConstGen.go. DO NOT EDIT.\n\n") fmt.Fprintf(w, "// Code generated by gen/arithConstGen.go. DO NOT EDIT.\n\n")
fmt.Fprintf(w, "package main;\n") fmt.Fprintf(w, "package main;\n")
fmt.Fprintf(w, "import \"fmt\"\n") fmt.Fprintf(w, "import \"testing\"\n")
fmt.Fprintf(w, "import \"os\"\n")
fncCnst1 := template.Must(template.New("fnc").Parse( fncCnst1 := template.Must(template.New("fnc").Parse(
`//go:noinline `//go:noinline
...@@ -313,26 +311,22 @@ type test_%[1]s%[2]s struct { ...@@ -313,26 +311,22 @@ type test_%[1]s%[2]s struct {
} }
fmt.Fprint(w, ` fmt.Fprint(w, `
var failed bool
func main() { // TestArithmeticConst tests results for arithmetic operations against constants.
func TestArithmeticConst(t *testing.T) {
`) `)
for _, s := range szs { for _, s := range szs {
fmt.Fprintf(w, `for _, test := range tests_%s%s {`, s.name, s.oponly) fmt.Fprintf(w, `for _, test := range tests_%s%s {`, s.name, s.oponly)
// Use WriteString here to avoid a vet warning about formatting directives. // Use WriteString here to avoid a vet warning about formatting directives.
w.WriteString(`if got := test.fn(test.in); got != test.want { w.WriteString(`if got := test.fn(test.in); got != test.want {
fmt.Printf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) t.Errorf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want)
failed = true
} }
} }
`) `)
} }
fmt.Fprint(w, ` fmt.Fprint(w, `
if failed {
os.Exit(1)
}
} }
`) `)
...@@ -345,7 +339,7 @@ func main() { ...@@ -345,7 +339,7 @@ func main() {
} }
// write to file // write to file
err = ioutil.WriteFile("../arithConst.go", src, 0666) err = ioutil.WriteFile("../arithConst_test.go", src, 0666)
if err != nil { if err != nil {
log.Fatalf("can't write output: %v\n", err) log.Fatalf("can't write output: %v\n", err)
} }
......
...@@ -153,10 +153,9 @@ func main() { ...@@ -153,10 +153,9 @@ func main() {
} }
w := new(bytes.Buffer) w := new(bytes.Buffer)
fmt.Fprintf(w, "// run\n")
fmt.Fprintf(w, "// Code generated by gen/cmpConstGen.go. DO NOT EDIT.\n\n") fmt.Fprintf(w, "// Code generated by gen/cmpConstGen.go. DO NOT EDIT.\n\n")
fmt.Fprintf(w, "package main;\n") fmt.Fprintf(w, "package main;\n")
fmt.Fprintf(w, "import (\"fmt\"; \"reflect\"; \"runtime\";)\n") fmt.Fprintf(w, "import (\"testing\"; \"reflect\"; \"runtime\";)\n")
fmt.Fprintf(w, "// results show the expected result for the elements left of, equal to and right of the index.\n") fmt.Fprintf(w, "// results show the expected result for the elements left of, equal to and right of the index.\n")
fmt.Fprintf(w, "type result struct{l, e, r bool}\n") fmt.Fprintf(w, "type result struct{l, e, r bool}\n")
fmt.Fprintf(w, "var (\n") fmt.Fprintf(w, "var (\n")
...@@ -215,7 +214,8 @@ func main() { ...@@ -215,7 +214,8 @@ func main() {
} }
// emit the main function, looping over all test cases // emit the main function, looping over all test cases
fmt.Fprintf(w, "func main() {\n") fmt.Fprintf(w, "// TestComparisonsConst tests results for comparison operations against constants.\n")
fmt.Fprintf(w, "func TestComparisonsConst(t *testing.T) {\n")
for _, typ := range types { for _, typ := range types {
fmt.Fprintf(w, "for i, test := range %v_tests {\n", typ) fmt.Fprintf(w, "for i, test := range %v_tests {\n", typ)
fmt.Fprintf(w, " for j, x := range %v_vals {\n", typ) fmt.Fprintf(w, " for j, x := range %v_vals {\n", typ)
...@@ -224,8 +224,7 @@ func main() { ...@@ -224,8 +224,7 @@ func main() {
fmt.Fprintf(w, " else if j > test.idx {\nwant = test.exp.r\n}\n") fmt.Fprintf(w, " else if j > test.idx {\nwant = test.exp.r\n}\n")
fmt.Fprintf(w, " if test.fn(x) != want {\n") fmt.Fprintf(w, " if test.fn(x) != want {\n")
fmt.Fprintf(w, " fn := runtime.FuncForPC(reflect.ValueOf(test.fn).Pointer()).Name()\n") fmt.Fprintf(w, " fn := runtime.FuncForPC(reflect.ValueOf(test.fn).Pointer()).Name()\n")
fmt.Fprintf(w, " msg := fmt.Sprintf(\"test failed: %%v(%%v) != %%v [type=%v i=%%v j=%%v idx=%%v]\", fn, x, want, i, j, test.idx)\n", typ) fmt.Fprintf(w, " t.Errorf(\"test failed: %%v(%%v) != %%v [type=%v i=%%v j=%%v idx=%%v]\", fn, x, want, i, j, test.idx)\n", typ)
fmt.Fprintf(w, " panic(msg)\n")
fmt.Fprintf(w, " }\n") fmt.Fprintf(w, " }\n")
fmt.Fprintf(w, " }\n") fmt.Fprintf(w, " }\n")
fmt.Fprintf(w, "}\n") fmt.Fprintf(w, "}\n")
...@@ -241,7 +240,7 @@ func main() { ...@@ -241,7 +240,7 @@ func main() {
} }
// write to file // write to file
err = ioutil.WriteFile("../cmpConst.go", src, 0666) err = ioutil.WriteFile("../cmpConst_test.go", src, 0666)
if err != nil { if err != nil {
log.Fatalf("can't write output: %v\n", err) log.Fatalf("can't write output: %v\n", err)
} }
......
...@@ -24,10 +24,9 @@ var usizes = [...]int{2, 3, 4, 5, 6, 7} ...@@ -24,10 +24,9 @@ var usizes = [...]int{2, 3, 4, 5, 6, 7}
func main() { func main() {
w := new(bytes.Buffer) w := new(bytes.Buffer)
fmt.Fprintf(w, "// run\n")
fmt.Fprintf(w, "// Code generated by gen/copyGen.go. DO NOT EDIT.\n\n") fmt.Fprintf(w, "// Code generated by gen/copyGen.go. DO NOT EDIT.\n\n")
fmt.Fprintf(w, "package main\n") fmt.Fprintf(w, "package main\n")
fmt.Fprintf(w, "import \"fmt\"\n") fmt.Fprintf(w, "import \"testing\"\n")
for _, s := range sizes { for _, s := range sizes {
// type for test // type for test
...@@ -44,7 +43,7 @@ func main() { ...@@ -44,7 +43,7 @@ func main() {
fmt.Fprintf(w, "}\n") fmt.Fprintf(w, "}\n")
// testing harness // testing harness
fmt.Fprintf(w, "func testCopy%d() {\n", s) fmt.Fprintf(w, "func testCopy%d(t *testing.T) {\n", s)
fmt.Fprintf(w, " a := T%d{[8]byte{201, 202, 203, 204, 205, 206, 207, 208},[%d]byte{", s, s) fmt.Fprintf(w, " a := T%d{[8]byte{201, 202, 203, 204, 205, 206, 207, 208},[%d]byte{", s, s)
for i := 0; i < s; i++ { for i := 0; i < s; i++ {
fmt.Fprintf(w, "%d,", i%100) fmt.Fprintf(w, "%d,", i%100)
...@@ -62,8 +61,7 @@ func main() { ...@@ -62,8 +61,7 @@ func main() {
} }
fmt.Fprintf(w, "},[8]byte{211, 212, 213, 214, 215, 216, 217, 218}}\n") fmt.Fprintf(w, "},[8]byte{211, 212, 213, 214, 215, 216, 217, 218}}\n")
fmt.Fprintf(w, " if a != want {\n") fmt.Fprintf(w, " if a != want {\n")
fmt.Fprintf(w, " fmt.Printf(\"t%dcopy got=%%v, want %%v\\n\", a, want)\n", s) fmt.Fprintf(w, " t.Errorf(\"t%dcopy got=%%v, want %%v\\n\", a, want)\n", s)
fmt.Fprintf(w, " failed=true\n")
fmt.Fprintf(w, " }\n") fmt.Fprintf(w, " }\n")
fmt.Fprintf(w, "}\n") fmt.Fprintf(w, "}\n")
} }
...@@ -78,7 +76,7 @@ func main() { ...@@ -78,7 +76,7 @@ func main() {
fmt.Fprintf(w, "}\n") fmt.Fprintf(w, "}\n")
// testing harness // testing harness
fmt.Fprintf(w, "func testUnalignedCopy%d() {\n", s) fmt.Fprintf(w, "func testUnalignedCopy%d(t *testing.T) {\n", s)
fmt.Fprintf(w, " var a [%d]byte\n", s) fmt.Fprintf(w, " var a [%d]byte\n", s)
fmt.Fprintf(w, " t%d := [%d]byte{", s, s) fmt.Fprintf(w, " t%d := [%d]byte{", s, s)
for i := 0; i < s; i++ { for i := 0; i < s; i++ {
...@@ -92,24 +90,19 @@ func main() { ...@@ -92,24 +90,19 @@ func main() {
} }
fmt.Fprintf(w, "}\n") fmt.Fprintf(w, "}\n")
fmt.Fprintf(w, " if a != want%d {\n", s) fmt.Fprintf(w, " if a != want%d {\n", s)
fmt.Fprintf(w, " fmt.Printf(\"tu%dcopy got=%%v, want %%v\\n\", a, want%d)\n", s, s) fmt.Fprintf(w, " t.Errorf(\"tu%dcopy got=%%v, want %%v\\n\", a, want%d)\n", s, s)
fmt.Fprintf(w, " failed=true\n")
fmt.Fprintf(w, " }\n") fmt.Fprintf(w, " }\n")
fmt.Fprintf(w, "}\n") fmt.Fprintf(w, "}\n")
} }
// boilerplate at end // boilerplate at end
fmt.Fprintf(w, "var failed bool\n") fmt.Fprintf(w, "func TestCopy(t *testing.T) {\n")
fmt.Fprintf(w, "func main() {\n")
for _, s := range sizes { for _, s := range sizes {
fmt.Fprintf(w, " testCopy%d()\n", s) fmt.Fprintf(w, " testCopy%d(t)\n", s)
} }
for _, s := range usizes { for _, s := range usizes {
fmt.Fprintf(w, " testUnalignedCopy%d()\n", s) fmt.Fprintf(w, " testUnalignedCopy%d(t)\n", s)
} }
fmt.Fprintf(w, " if failed {\n")
fmt.Fprintf(w, " panic(\"failed\")\n")
fmt.Fprintf(w, " }\n")
fmt.Fprintf(w, "}\n") fmt.Fprintf(w, "}\n")
// gofmt result // gofmt result
...@@ -121,7 +114,7 @@ func main() { ...@@ -121,7 +114,7 @@ func main() {
} }
// write to file // write to file
err = ioutil.WriteFile("../copy.go", src, 0666) err = ioutil.WriteFile("../copy_test.go", src, 0666)
if err != nil { if err != nil {
log.Fatalf("can't write output: %v\n", err) log.Fatalf("can't write output: %v\n", err)
} }
......
...@@ -23,14 +23,13 @@ var usizes = [...]int{8, 16, 24, 32, 64, 256} ...@@ -23,14 +23,13 @@ var usizes = [...]int{8, 16, 24, 32, 64, 256}
func main() { func main() {
w := new(bytes.Buffer) w := new(bytes.Buffer)
fmt.Fprintf(w, "// run\n")
fmt.Fprintf(w, "// Code generated by gen/zeroGen.go. DO NOT EDIT.\n\n") fmt.Fprintf(w, "// Code generated by gen/zeroGen.go. DO NOT EDIT.\n\n")
fmt.Fprintf(w, "package main\n") fmt.Fprintf(w, "package main\n")
fmt.Fprintf(w, "import \"fmt\"\n") fmt.Fprintf(w, "import \"testing\"\n")
for _, s := range sizes { for _, s := range sizes {
// type for test // type for test
fmt.Fprintf(w, "type T%d struct {\n", s) fmt.Fprintf(w, "type Z%d struct {\n", s)
fmt.Fprintf(w, " pre [8]byte\n") fmt.Fprintf(w, " pre [8]byte\n")
fmt.Fprintf(w, " mid [%d]byte\n", s) fmt.Fprintf(w, " mid [%d]byte\n", s)
fmt.Fprintf(w, " post [8]byte\n") fmt.Fprintf(w, " post [8]byte\n")
...@@ -43,96 +42,89 @@ func main() { ...@@ -43,96 +42,89 @@ func main() {
fmt.Fprintf(w, "}\n") fmt.Fprintf(w, "}\n")
// testing harness // testing harness
fmt.Fprintf(w, "func testZero%d() {\n", s) fmt.Fprintf(w, "func testZero%d(t *testing.T) {\n", s)
fmt.Fprintf(w, " a := T%d{[8]byte{255,255,255,255,255,255,255,255},[%d]byte{", s, s) fmt.Fprintf(w, " a := Z%d{[8]byte{255,255,255,255,255,255,255,255},[%d]byte{", s, s)
for i := 0; i < s; i++ { for i := 0; i < s; i++ {
fmt.Fprintf(w, "255,") fmt.Fprintf(w, "255,")
} }
fmt.Fprintf(w, "},[8]byte{255,255,255,255,255,255,255,255}}\n") fmt.Fprintf(w, "},[8]byte{255,255,255,255,255,255,255,255}}\n")
fmt.Fprintf(w, " zero%d_ssa(&a.mid)\n", s) fmt.Fprintf(w, " zero%d_ssa(&a.mid)\n", s)
fmt.Fprintf(w, " want := T%d{[8]byte{255,255,255,255,255,255,255,255},[%d]byte{", s, s) fmt.Fprintf(w, " want := Z%d{[8]byte{255,255,255,255,255,255,255,255},[%d]byte{", s, s)
for i := 0; i < s; i++ { for i := 0; i < s; i++ {
fmt.Fprintf(w, "0,") fmt.Fprintf(w, "0,")
} }
fmt.Fprintf(w, "},[8]byte{255,255,255,255,255,255,255,255}}\n") fmt.Fprintf(w, "},[8]byte{255,255,255,255,255,255,255,255}}\n")
fmt.Fprintf(w, " if a != want {\n") fmt.Fprintf(w, " if a != want {\n")
fmt.Fprintf(w, " fmt.Printf(\"zero%d got=%%v, want %%v\\n\", a, want)\n", s) fmt.Fprintf(w, " t.Errorf(\"zero%d got=%%v, want %%v\\n\", a, want)\n", s)
fmt.Fprintf(w, " failed=true\n")
fmt.Fprintf(w, " }\n") fmt.Fprintf(w, " }\n")
fmt.Fprintf(w, "}\n") fmt.Fprintf(w, "}\n")
} }
for _, s := range usizes { for _, s := range usizes {
// type for test // type for test
fmt.Fprintf(w, "type T%du1 struct {\n", s) fmt.Fprintf(w, "type Z%du1 struct {\n", s)
fmt.Fprintf(w, " b bool\n") fmt.Fprintf(w, " b bool\n")
fmt.Fprintf(w, " val [%d]byte\n", s) fmt.Fprintf(w, " val [%d]byte\n", s)
fmt.Fprintf(w, "}\n") fmt.Fprintf(w, "}\n")
fmt.Fprintf(w, "type T%du2 struct {\n", s) fmt.Fprintf(w, "type Z%du2 struct {\n", s)
fmt.Fprintf(w, " i uint16\n") fmt.Fprintf(w, " i uint16\n")
fmt.Fprintf(w, " val [%d]byte\n", s) fmt.Fprintf(w, " val [%d]byte\n", s)
fmt.Fprintf(w, "}\n") fmt.Fprintf(w, "}\n")
// function being tested // function being tested
fmt.Fprintf(w, "//go:noinline\n") fmt.Fprintf(w, "//go:noinline\n")
fmt.Fprintf(w, "func zero%du1_ssa(t *T%du1) {\n", s, s) fmt.Fprintf(w, "func zero%du1_ssa(t *Z%du1) {\n", s, s)
fmt.Fprintf(w, " t.val = [%d]byte{}\n", s) fmt.Fprintf(w, " t.val = [%d]byte{}\n", s)
fmt.Fprintf(w, "}\n") fmt.Fprintf(w, "}\n")
// function being tested // function being tested
fmt.Fprintf(w, "//go:noinline\n") fmt.Fprintf(w, "//go:noinline\n")
fmt.Fprintf(w, "func zero%du2_ssa(t *T%du2) {\n", s, s) fmt.Fprintf(w, "func zero%du2_ssa(t *Z%du2) {\n", s, s)
fmt.Fprintf(w, " t.val = [%d]byte{}\n", s) fmt.Fprintf(w, " t.val = [%d]byte{}\n", s)
fmt.Fprintf(w, "}\n") fmt.Fprintf(w, "}\n")
// testing harness // testing harness
fmt.Fprintf(w, "func testZero%du() {\n", s) fmt.Fprintf(w, "func testZero%du(t *testing.T) {\n", s)
fmt.Fprintf(w, " a := T%du1{false, [%d]byte{", s, s) fmt.Fprintf(w, " a := Z%du1{false, [%d]byte{", s, s)
for i := 0; i < s; i++ { for i := 0; i < s; i++ {
fmt.Fprintf(w, "255,") fmt.Fprintf(w, "255,")
} }
fmt.Fprintf(w, "}}\n") fmt.Fprintf(w, "}}\n")
fmt.Fprintf(w, " zero%du1_ssa(&a)\n", s) fmt.Fprintf(w, " zero%du1_ssa(&a)\n", s)
fmt.Fprintf(w, " want := T%du1{false, [%d]byte{", s, s) fmt.Fprintf(w, " want := Z%du1{false, [%d]byte{", s, s)
for i := 0; i < s; i++ { for i := 0; i < s; i++ {
fmt.Fprintf(w, "0,") fmt.Fprintf(w, "0,")
} }
fmt.Fprintf(w, "}}\n") fmt.Fprintf(w, "}}\n")
fmt.Fprintf(w, " if a != want {\n") fmt.Fprintf(w, " if a != want {\n")
fmt.Fprintf(w, " fmt.Printf(\"zero%du2 got=%%v, want %%v\\n\", a, want)\n", s) fmt.Fprintf(w, " t.Errorf(\"zero%du2 got=%%v, want %%v\\n\", a, want)\n", s)
fmt.Fprintf(w, " failed=true\n")
fmt.Fprintf(w, " }\n") fmt.Fprintf(w, " }\n")
fmt.Fprintf(w, " b := T%du2{15, [%d]byte{", s, s) fmt.Fprintf(w, " b := Z%du2{15, [%d]byte{", s, s)
for i := 0; i < s; i++ { for i := 0; i < s; i++ {
fmt.Fprintf(w, "255,") fmt.Fprintf(w, "255,")
} }
fmt.Fprintf(w, "}}\n") fmt.Fprintf(w, "}}\n")
fmt.Fprintf(w, " zero%du2_ssa(&b)\n", s) fmt.Fprintf(w, " zero%du2_ssa(&b)\n", s)
fmt.Fprintf(w, " wantb := T%du2{15, [%d]byte{", s, s) fmt.Fprintf(w, " wantb := Z%du2{15, [%d]byte{", s, s)
for i := 0; i < s; i++ { for i := 0; i < s; i++ {
fmt.Fprintf(w, "0,") fmt.Fprintf(w, "0,")
} }
fmt.Fprintf(w, "}}\n") fmt.Fprintf(w, "}}\n")
fmt.Fprintf(w, " if b != wantb {\n") fmt.Fprintf(w, " if b != wantb {\n")
fmt.Fprintf(w, " fmt.Printf(\"zero%du2 got=%%v, want %%v\\n\", b, wantb)\n", s) fmt.Fprintf(w, " t.Errorf(\"zero%du2 got=%%v, want %%v\\n\", b, wantb)\n", s)
fmt.Fprintf(w, " failed=true\n")
fmt.Fprintf(w, " }\n") fmt.Fprintf(w, " }\n")
fmt.Fprintf(w, "}\n") fmt.Fprintf(w, "}\n")
} }
// boilerplate at end // boilerplate at end
fmt.Fprintf(w, "var failed bool\n") fmt.Fprintf(w, "func TestZero(t *testing.T) {\n")
fmt.Fprintf(w, "func main() {\n")
for _, s := range sizes { for _, s := range sizes {
fmt.Fprintf(w, " testZero%d()\n", s) fmt.Fprintf(w, " testZero%d(t)\n", s)
} }
for _, s := range usizes { for _, s := range usizes {
fmt.Fprintf(w, " testZero%du()\n", s) fmt.Fprintf(w, " testZero%du(t)\n", s)
} }
fmt.Fprintf(w, " if failed {\n")
fmt.Fprintf(w, " panic(\"failed\")\n")
fmt.Fprintf(w, " }\n")
fmt.Fprintf(w, "}\n") fmt.Fprintf(w, "}\n")
// gofmt result // gofmt result
...@@ -144,7 +136,7 @@ func main() { ...@@ -144,7 +136,7 @@ func main() {
} }
// write to file // write to file
err = ioutil.WriteFile("../zero.go", src, 0666) err = ioutil.WriteFile("../zero_test.go", src, 0666)
if err != nil { if err != nil {
log.Fatalf("can't write output: %v\n", err) log.Fatalf("can't write output: %v\n", err)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment