Commit 25ea4e57 authored by Keith Randall's avatar Keith Randall Committed by Keith Randall

cmd/compile: move more compiler tests to new test infrastructure

Update #26469

Change-Id: I1188e49cde1bda11506afef6b6e3f34c6ff45ea5
Reviewed-on: https://go-review.googlesource.com/127115
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarDavid Chase <drchase@google.com>
parent 78ce3a03
...@@ -26,10 +26,6 @@ func runTest(t *testing.T, filename string, flags ...string) { ...@@ -26,10 +26,6 @@ func runTest(t *testing.T, filename string, flags ...string) {
t.Parallel() t.Parallel()
doTest(t, filename, "run", flags...) doTest(t, filename, "run", flags...)
} }
func buildTest(t *testing.T, filename string, flags ...string) {
t.Parallel()
doTest(t, filename, "build", flags...)
}
func doTest(t *testing.T, filename string, kind string, flags ...string) { func doTest(t *testing.T, filename string, kind string, flags ...string) {
testenv.MustHaveGoBuild(t) testenv.MustHaveGoBuild(t)
gotool := testenv.GoToolPath(t) gotool := testenv.GoToolPath(t)
...@@ -227,22 +223,6 @@ func TestCode(t *testing.T) { ...@@ -227,22 +223,6 @@ func TestCode(t *testing.T) {
} }
} }
func TestChan(t *testing.T) { runTest(t, "chan.go") }
func TestCompound(t *testing.T) { runTest(t, "compound.go") }
func TestCtl(t *testing.T) { runTest(t, "ctl.go") }
func TestLoadStore(t *testing.T) { runTest(t, "loadstore.go") }
func TestMap(t *testing.T) { runTest(t, "map.go") }
func TestRegalloc(t *testing.T) { runTest(t, "regalloc.go") }
func TestString(t *testing.T) { runTest(t, "string.go") }
func TestDeferNoReturn(t *testing.T) { buildTest(t, "deferNoReturn.go") }
// TestClosure tests closure related behavior. // TestClosure tests closure related behavior.
func TestClosure(t *testing.T) { runTest(t, "closure.go") } func TestClosure(t *testing.T) { runTest(t, "closure.go") }
......
...@@ -2,12 +2,10 @@ ...@@ -2,12 +2,10 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// chan_ssa.go tests chan operations. // chan.go tests chan operations.
package main package main
import "fmt" import "testing"
var failed = false
//go:noinline //go:noinline
func lenChan_ssa(v chan int) int { func lenChan_ssa(v chan int) int {
...@@ -19,7 +17,7 @@ func capChan_ssa(v chan int) int { ...@@ -19,7 +17,7 @@ func capChan_ssa(v chan int) int {
return cap(v) return cap(v)
} }
func testLenChan() { func testLenChan(t *testing.T) {
v := make(chan int, 10) v := make(chan int, 10)
v <- 1 v <- 1
...@@ -27,47 +25,39 @@ func testLenChan() { ...@@ -27,47 +25,39 @@ func testLenChan() {
v <- 1 v <- 1
if want, got := 3, lenChan_ssa(v); got != want { if want, got := 3, lenChan_ssa(v); got != want {
fmt.Printf("expected len(chan) = %d, got %d", want, got) t.Errorf("expected len(chan) = %d, got %d", want, got)
failed = true
} }
} }
func testLenNilChan() { func testLenNilChan(t *testing.T) {
var v chan int var v chan int
if want, got := 0, lenChan_ssa(v); got != want { if want, got := 0, lenChan_ssa(v); got != want {
fmt.Printf("expected len(nil) = %d, got %d", want, got) t.Errorf("expected len(nil) = %d, got %d", want, got)
failed = true
} }
} }
func testCapChan() { func testCapChan(t *testing.T) {
v := make(chan int, 25) v := make(chan int, 25)
if want, got := 25, capChan_ssa(v); got != want { if want, got := 25, capChan_ssa(v); got != want {
fmt.Printf("expected cap(chan) = %d, got %d", want, got) t.Errorf("expected cap(chan) = %d, got %d", want, got)
failed = true
} }
} }
func testCapNilChan() { func testCapNilChan(t *testing.T) {
var v chan int var v chan int
if want, got := 0, capChan_ssa(v); got != want { if want, got := 0, capChan_ssa(v); got != want {
fmt.Printf("expected cap(nil) = %d, got %d", want, got) t.Errorf("expected cap(nil) = %d, got %d", want, got)
failed = true
} }
} }
func main() { func TestChan(t *testing.T) {
testLenChan() testLenChan(t)
testLenNilChan() testLenNilChan(t)
testCapChan()
testCapNilChan()
if failed { testCapChan(t)
panic("failed") testCapNilChan(t)
}
} }
// run
// Copyright 2015 The Go Authors. All rights reserved. // Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
...@@ -8,7 +6,9 @@ ...@@ -8,7 +6,9 @@
package main package main
import "fmt" import (
"testing"
)
func string_ssa(a, b string, x bool) string { func string_ssa(a, b string, x bool) string {
s := "" s := ""
...@@ -20,16 +20,14 @@ func string_ssa(a, b string, x bool) string { ...@@ -20,16 +20,14 @@ func string_ssa(a, b string, x bool) string {
return s return s
} }
func testString() { func testString(t *testing.T) {
a := "foo" a := "foo"
b := "barz" b := "barz"
if want, got := a, string_ssa(a, b, true); got != want { if want, got := a, string_ssa(a, b, true); got != want {
fmt.Printf("string_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want) t.Errorf("string_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
failed = true
} }
if want, got := b, string_ssa(a, b, false); got != want { if want, got := b, string_ssa(a, b, false); got != want {
fmt.Printf("string_ssa(%v, %v, false) = %v, want %v\n", a, b, got, want) t.Errorf("string_ssa(%v, %v, false) = %v, want %v\n", a, b, got, want)
failed = true
} }
} }
...@@ -55,31 +53,27 @@ func complex128_ssa(a, b complex128, x bool) complex128 { ...@@ -55,31 +53,27 @@ func complex128_ssa(a, b complex128, x bool) complex128 {
return c return c
} }
func testComplex64() { func testComplex64(t *testing.T) {
var a complex64 = 1 + 2i var a complex64 = 1 + 2i
var b complex64 = 3 + 4i var b complex64 = 3 + 4i
if want, got := a, complex64_ssa(a, b, true); got != want { if want, got := a, complex64_ssa(a, b, true); got != want {
fmt.Printf("complex64_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want) t.Errorf("complex64_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
failed = true
} }
if want, got := b, complex64_ssa(a, b, false); got != want { if want, got := b, complex64_ssa(a, b, false); got != want {
fmt.Printf("complex64_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want) t.Errorf("complex64_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
failed = true
} }
} }
func testComplex128() { func testComplex128(t *testing.T) {
var a complex128 = 1 + 2i var a complex128 = 1 + 2i
var b complex128 = 3 + 4i var b complex128 = 3 + 4i
if want, got := a, complex128_ssa(a, b, true); got != want { if want, got := a, complex128_ssa(a, b, true); got != want {
fmt.Printf("complex128_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want) t.Errorf("complex128_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
failed = true
} }
if want, got := b, complex128_ssa(a, b, false); got != want { if want, got := b, complex128_ssa(a, b, false); got != want {
fmt.Printf("complex128_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want) t.Errorf("complex128_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
failed = true
} }
} }
...@@ -93,16 +87,14 @@ func slice_ssa(a, b []byte, x bool) []byte { ...@@ -93,16 +87,14 @@ func slice_ssa(a, b []byte, x bool) []byte {
return s return s
} }
func testSlice() { func testSlice(t *testing.T) {
a := []byte{3, 4, 5} a := []byte{3, 4, 5}
b := []byte{7, 8, 9} b := []byte{7, 8, 9}
if want, got := byte(3), slice_ssa(a, b, true)[0]; got != want { if want, got := byte(3), slice_ssa(a, b, true)[0]; got != want {
fmt.Printf("slice_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want) t.Errorf("slice_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
failed = true
} }
if want, got := byte(7), slice_ssa(a, b, false)[0]; got != want { if want, got := byte(7), slice_ssa(a, b, false)[0]; got != want {
fmt.Printf("slice_ssa(%v, %v, false) = %v, want %v\n", a, b, got, want) t.Errorf("slice_ssa(%v, %v, false) = %v, want %v\n", a, b, got, want)
failed = true
} }
} }
...@@ -116,28 +108,21 @@ func interface_ssa(a, b interface{}, x bool) interface{} { ...@@ -116,28 +108,21 @@ func interface_ssa(a, b interface{}, x bool) interface{} {
return s return s
} }
func testInterface() { func testInterface(t *testing.T) {
a := interface{}(3) a := interface{}(3)
b := interface{}(4) b := interface{}(4)
if want, got := 3, interface_ssa(a, b, true).(int); got != want { if want, got := 3, interface_ssa(a, b, true).(int); got != want {
fmt.Printf("interface_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want) t.Errorf("interface_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
failed = true
} }
if want, got := 4, interface_ssa(a, b, false).(int); got != want { if want, got := 4, interface_ssa(a, b, false).(int); got != want {
fmt.Printf("interface_ssa(%v, %v, false) = %v, want %v\n", a, b, got, want) t.Errorf("interface_ssa(%v, %v, false) = %v, want %v\n", a, b, got, want)
failed = true
} }
} }
var failed = false func TestCompound(t *testing.T) {
testString(t)
func main() { testSlice(t)
testString() testInterface(t)
testSlice() testComplex64(t)
testInterface() testComplex128(t)
testComplex64()
testComplex128()
if failed {
panic("failed")
}
} }
// run
// Copyright 2015 The Go Authors. All rights reserved. // Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
...@@ -8,6 +6,8 @@ ...@@ -8,6 +6,8 @@
package main package main
import "testing"
// nor_ssa calculates NOR(a, b). // nor_ssa calculates NOR(a, b).
// It is implemented in a way that generates // It is implemented in a way that generates
// phi control values. // phi control values.
...@@ -25,7 +25,7 @@ func nor_ssa(a, b bool) bool { ...@@ -25,7 +25,7 @@ func nor_ssa(a, b bool) bool {
return true return true
} }
func testPhiControl() { func testPhiControl(t *testing.T) {
tests := [...][3]bool{ // a, b, want tests := [...][3]bool{ // a, b, want
{false, false, true}, {false, false, true},
{true, false, false}, {true, false, false},
...@@ -37,8 +37,7 @@ func testPhiControl() { ...@@ -37,8 +37,7 @@ func testPhiControl() {
got := nor_ssa(a, b) got := nor_ssa(a, b)
want := test[2] want := test[2]
if want != got { if want != got {
print("nor(", a, ", ", b, ")=", want, " got ", got, "\n") t.Errorf("nor(%t, %t)=%t got %t", a, b, want, got)
failed = true
} }
} }
} }
...@@ -50,10 +49,9 @@ func emptyRange_ssa(b []byte) bool { ...@@ -50,10 +49,9 @@ func emptyRange_ssa(b []byte) bool {
return true return true
} }
func testEmptyRange() { func testEmptyRange(t *testing.T) {
if !emptyRange_ssa([]byte{}) { if !emptyRange_ssa([]byte{}) {
println("emptyRange_ssa([]byte{})=false, want true") t.Errorf("emptyRange_ssa([]byte{})=false, want true")
failed = true
} }
} }
...@@ -97,20 +95,18 @@ func fallthrough_ssa(a int) int { ...@@ -97,20 +95,18 @@ func fallthrough_ssa(a int) int {
} }
func testFallthrough() { func testFallthrough(t *testing.T) {
for i := 0; i < 6; i++ { for i := 0; i < 6; i++ {
if got := fallthrough_ssa(i); got != i { if got := fallthrough_ssa(i); got != i {
println("fallthrough_ssa(i) =", got, "wanted", i) t.Errorf("fallthrough_ssa(i) = %d, wanted %d", got, i)
failed = true
} }
} }
} }
func testSwitch() { func testSwitch(t *testing.T) {
for i := 0; i < 6; i++ { for i := 0; i < 6; i++ {
if got := switch_ssa(i); got != i { if got := switch_ssa(i); got != i {
println("switch_ssa(i) =", got, "wanted", i) t.Errorf("switch_ssa(i) = %d, wanted %d", got, i)
failed = true
} }
} }
} }
...@@ -135,26 +131,19 @@ func flagOverwrite_ssa(s *junk, c int) int { ...@@ -135,26 +131,19 @@ func flagOverwrite_ssa(s *junk, c int) int {
return 3 return 3
} }
func testFlagOverwrite() { func testFlagOverwrite(t *testing.T) {
j := junk{} j := junk{}
if got := flagOverwrite_ssa(&j, ' '); got != 3 { if got := flagOverwrite_ssa(&j, ' '); got != 3 {
println("flagOverwrite_ssa =", got, "wanted 3") t.Errorf("flagOverwrite_ssa = %d, wanted 3", got)
failed = true
} }
} }
var failed = false func TestCtl(t *testing.T) {
testPhiControl(t)
func main() { testEmptyRange(t)
testPhiControl()
testEmptyRange()
testSwitch() testSwitch(t)
testFallthrough() testFallthrough(t)
testFlagOverwrite() testFlagOverwrite(t)
if failed {
panic("failed")
}
} }
// compile
// Copyright 2015 The Go Authors. All rights reserved. // Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
...@@ -7,7 +5,9 @@ ...@@ -7,7 +5,9 @@
// Test that a defer in a function with no return // Test that a defer in a function with no return
// statement will compile correctly. // statement will compile correctly.
package foo package main
import "testing"
func deferNoReturn_ssa() { func deferNoReturn_ssa() {
defer func() { println("returned") }() defer func() { println("returned") }()
...@@ -15,3 +15,7 @@ func deferNoReturn_ssa() { ...@@ -15,3 +15,7 @@ func deferNoReturn_ssa() {
println("loop") println("loop")
} }
} }
func TestDeferNoReturn(t *testing.T) {
// This is a compile-time test, no runtime testing required.
}
// run
// Copyright 2015 The Go Authors. All rights reserved. // Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
...@@ -8,14 +6,13 @@ ...@@ -8,14 +6,13 @@
package main package main
import "fmt" import "testing"
// testLoadStoreOrder tests for reordering of stores/loads. // testLoadStoreOrder tests for reordering of stores/loads.
func testLoadStoreOrder() { func testLoadStoreOrder(t *testing.T) {
z := uint32(1000) z := uint32(1000)
if testLoadStoreOrder_ssa(&z, 100) == 0 { if testLoadStoreOrder_ssa(&z, 100) == 0 {
println("testLoadStoreOrder failed") t.Errorf("testLoadStoreOrder failed")
failed = true
} }
} }
...@@ -29,13 +26,12 @@ func testLoadStoreOrder_ssa(z *uint32, prec uint) int { ...@@ -29,13 +26,12 @@ func testLoadStoreOrder_ssa(z *uint32, prec uint) int {
return 0 return 0
} }
func testStoreSize() { func testStoreSize(t *testing.T) {
a := [4]uint16{11, 22, 33, 44} a := [4]uint16{11, 22, 33, 44}
testStoreSize_ssa(&a[0], &a[2], 77) testStoreSize_ssa(&a[0], &a[2], 77)
want := [4]uint16{77, 22, 33, 44} want := [4]uint16{77, 22, 33, 44}
if a != want { if a != want {
fmt.Println("testStoreSize failed. want =", want, ", got =", a) t.Errorf("testStoreSize failed. want = %d, got = %d", want, a)
failed = true
} }
} }
...@@ -55,8 +51,6 @@ func testStoreSize_ssa(p *uint16, q *uint16, v uint32) { ...@@ -55,8 +51,6 @@ func testStoreSize_ssa(p *uint16, q *uint16, v uint32) {
} }
} }
var failed = false
//go:noinline //go:noinline
func testExtStore_ssa(p *byte, b bool) int { func testExtStore_ssa(p *byte, b bool) int {
x := *p x := *p
...@@ -67,12 +61,11 @@ func testExtStore_ssa(p *byte, b bool) int { ...@@ -67,12 +61,11 @@ func testExtStore_ssa(p *byte, b bool) int {
return 0 return 0
} }
func testExtStore() { func testExtStore(t *testing.T) {
const start = 8 const start = 8
var b byte = start var b byte = start
if got := testExtStore_ssa(&b, true); got != start { if got := testExtStore_ssa(&b, true); got != start {
fmt.Println("testExtStore failed. want =", start, ", got =", got) t.Errorf("testExtStore failed. want = %d, got = %d", start, got)
failed = true
} }
} }
...@@ -95,10 +88,9 @@ func testDeadStorePanic_ssa(a int) (r int) { ...@@ -95,10 +88,9 @@ func testDeadStorePanic_ssa(a int) (r int) {
return return
} }
func testDeadStorePanic() { func testDeadStorePanic(t *testing.T) {
if want, got := 2, testDeadStorePanic_ssa(1); want != got { if want, got := 2, testDeadStorePanic_ssa(1); want != got {
fmt.Println("testDeadStorePanic failed. want =", want, ", got =", got) t.Errorf("testDeadStorePanic failed. want = %d, got = %d", want, got)
failed = true
} }
} }
...@@ -144,7 +136,7 @@ func loadHitStoreU32(x uint32, p *uint32) uint64 { ...@@ -144,7 +136,7 @@ func loadHitStoreU32(x uint32, p *uint32) uint64 {
return uint64(*p) // load and cast return uint64(*p) // load and cast
} }
func testLoadHitStore() { func testLoadHitStore(t *testing.T) {
// Test that sign/zero extensions are kept when a load-hit-store // Test that sign/zero extensions are kept when a load-hit-store
// is replaced by a register-register move. // is replaced by a register-register move.
{ {
...@@ -153,8 +145,7 @@ func testLoadHitStore() { ...@@ -153,8 +145,7 @@ func testLoadHitStore() {
got := loadHitStore8(in, &p) got := loadHitStore8(in, &p)
want := int32(in * in) want := int32(in * in)
if got != want { if got != want {
fmt.Println("testLoadHitStore (int8) failed. want =", want, ", got =", got) t.Errorf("testLoadHitStore (int8) failed. want = %d, got = %d", want, got)
failed = true
} }
} }
{ {
...@@ -163,8 +154,7 @@ func testLoadHitStore() { ...@@ -163,8 +154,7 @@ func testLoadHitStore() {
got := loadHitStoreU8(in, &p) got := loadHitStoreU8(in, &p)
want := uint32(in * in) want := uint32(in * in)
if got != want { if got != want {
fmt.Println("testLoadHitStore (uint8) failed. want =", want, ", got =", got) t.Errorf("testLoadHitStore (uint8) failed. want = %d, got = %d", want, got)
failed = true
} }
} }
{ {
...@@ -173,8 +163,7 @@ func testLoadHitStore() { ...@@ -173,8 +163,7 @@ func testLoadHitStore() {
got := loadHitStore16(in, &p) got := loadHitStore16(in, &p)
want := int32(in * in) want := int32(in * in)
if got != want { if got != want {
fmt.Println("testLoadHitStore (int16) failed. want =", want, ", got =", got) t.Errorf("testLoadHitStore (int16) failed. want = %d, got = %d", want, got)
failed = true
} }
} }
{ {
...@@ -183,8 +172,7 @@ func testLoadHitStore() { ...@@ -183,8 +172,7 @@ func testLoadHitStore() {
got := loadHitStoreU16(in, &p) got := loadHitStoreU16(in, &p)
want := uint32(in * in) want := uint32(in * in)
if got != want { if got != want {
fmt.Println("testLoadHitStore (uint16) failed. want =", want, ", got =", got) t.Errorf("testLoadHitStore (uint16) failed. want = %d, got = %d", want, got)
failed = true
} }
} }
{ {
...@@ -193,8 +181,7 @@ func testLoadHitStore() { ...@@ -193,8 +181,7 @@ func testLoadHitStore() {
got := loadHitStore32(in, &p) got := loadHitStore32(in, &p)
want := int64(in * in) want := int64(in * in)
if got != want { if got != want {
fmt.Println("testLoadHitStore (int32) failed. want =", want, ", got =", got) t.Errorf("testLoadHitStore (int32) failed. want = %d, got = %d", want, got)
failed = true
} }
} }
{ {
...@@ -203,21 +190,15 @@ func testLoadHitStore() { ...@@ -203,21 +190,15 @@ func testLoadHitStore() {
got := loadHitStoreU32(in, &p) got := loadHitStoreU32(in, &p)
want := uint64(in * in) want := uint64(in * in)
if got != want { if got != want {
fmt.Println("testLoadHitStore (uint32) failed. want =", want, ", got =", got) t.Errorf("testLoadHitStore (uint32) failed. want = %d, got = %d", want, got)
failed = true
} }
} }
} }
func main() { func TestLoadStore(t *testing.T) {
testLoadStoreOrder(t)
testLoadStoreOrder() testStoreSize(t)
testStoreSize() testExtStore(t)
testExtStore() testDeadStorePanic(t)
testDeadStorePanic() testLoadHitStore(t)
testLoadHitStore()
if failed {
panic("failed")
}
} }
...@@ -2,19 +2,17 @@ ...@@ -2,19 +2,17 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// map_ssa.go tests map operations. // map.go tests map operations.
package main package main
import "fmt" import "testing"
var failed = false
//go:noinline //go:noinline
func lenMap_ssa(v map[int]int) int { func lenMap_ssa(v map[int]int) int {
return len(v) return len(v)
} }
func testLenMap() { func testLenMap(t *testing.T) {
v := make(map[int]int) v := make(map[int]int)
v[0] = 0 v[0] = 0
...@@ -22,24 +20,18 @@ func testLenMap() { ...@@ -22,24 +20,18 @@ func testLenMap() {
v[2] = 0 v[2] = 0
if want, got := 3, lenMap_ssa(v); got != want { if want, got := 3, lenMap_ssa(v); got != want {
fmt.Printf("expected len(map) = %d, got %d", want, got) t.Errorf("expected len(map) = %d, got %d", want, got)
failed = true
} }
} }
func testLenNilMap() { func testLenNilMap(t *testing.T) {
var v map[int]int var v map[int]int
if want, got := 0, lenMap_ssa(v); got != want { if want, got := 0, lenMap_ssa(v); got != want {
fmt.Printf("expected len(nil) = %d, got %d", want, got) t.Errorf("expected len(nil) = %d, got %d", want, got)
failed = true
} }
} }
func main() { func TestMap(t *testing.T) {
testLenMap() testLenMap(t)
testLenNilMap() testLenNilMap(t)
if failed {
panic("failed")
}
} }
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// This file exists just to convince vet not to check this directory.
// (vet will not check a directory with two different packages in it.)
// TODO: remove this hack & add failing tests to the whitelist.
package foo
// run
// Copyright 2015 The Go Authors. All rights reserved. // Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
...@@ -8,6 +6,8 @@ ...@@ -8,6 +6,8 @@
package main package main
import "testing"
func phiOverwrite_ssa() int { func phiOverwrite_ssa() int {
var n int var n int
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
...@@ -19,12 +19,11 @@ func phiOverwrite_ssa() int { ...@@ -19,12 +19,11 @@ func phiOverwrite_ssa() int {
return n return n
} }
func phiOverwrite() { func phiOverwrite(t *testing.T) {
want := 5 want := 5
got := phiOverwrite_ssa() got := phiOverwrite_ssa()
if got != want { if got != want {
println("phiOverwrite_ssa()=", want, ", got", got) t.Errorf("phiOverwrite_ssa()= %d, got %d", want, got)
failed = true
} }
} }
...@@ -37,21 +36,15 @@ func phiOverwriteBig_ssa() int { ...@@ -37,21 +36,15 @@ func phiOverwriteBig_ssa() int {
return a*1 + b*2 + c*3 + d*4 + e*5 + f*6 + g*7 + h*8 + i*9 + j*10 + k*11 + l*12 + m*13 + n*14 + o*15 + p*16 + q*17 + r*18 + s*19 + t*20 + u*21 + v*22 + w*23 + x*24 + y*25 + z*26 return a*1 + b*2 + c*3 + d*4 + e*5 + f*6 + g*7 + h*8 + i*9 + j*10 + k*11 + l*12 + m*13 + n*14 + o*15 + p*16 + q*17 + r*18 + s*19 + t*20 + u*21 + v*22 + w*23 + x*24 + y*25 + z*26
} }
func phiOverwriteBig() { func phiOverwriteBig(t *testing.T) {
want := 1 want := 1
got := phiOverwriteBig_ssa() got := phiOverwriteBig_ssa()
if got != want { if got != want {
println("phiOverwriteBig_ssa()=", want, ", got", got) t.Errorf("phiOverwriteBig_ssa()= %d, got %d", want, got)
failed = true
} }
} }
var failed = false func TestRegalloc(t *testing.T) {
phiOverwrite(t)
func main() { phiOverwriteBig(t)
phiOverwrite()
phiOverwriteBig()
if failed {
panic("failed")
}
} }
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
// string_ssa.go tests string operations. // string_ssa.go tests string operations.
package main package main
var failed = false import "testing"
//go:noinline //go:noinline
func testStringSlice1_ssa(a string, i, j int) string { func testStringSlice1_ssa(a string, i, j int) string {
...@@ -22,7 +22,7 @@ func testStringSlice12_ssa(a string, i, j int) string { ...@@ -22,7 +22,7 @@ func testStringSlice12_ssa(a string, i, j int) string {
return a[i:j] return a[i:j]
} }
func testStringSlice() { func testStringSlice(t *testing.T) {
tests := [...]struct { tests := [...]struct {
fn func(string, int, int) string fn func(string, int, int) string
s string s string
...@@ -44,10 +44,9 @@ func testStringSlice() { ...@@ -44,10 +44,9 @@ func testStringSlice() {
{testStringSlice12_ssa, "", 0, 0, ""}, {testStringSlice12_ssa, "", 0, 0, ""},
} }
for i, t := range tests { for i, test := range tests {
if got := t.fn(t.s, t.low, t.high); t.want != got { if got := test.fn(test.s, test.low, test.high); test.want != got {
println("#", i, " ", t.s, "[", t.low, ":", t.high, "] = ", got, " want ", t.want) t.Errorf("#%d %s[%d,%d] = %s, want %s", i, test.s, test.low, test.high, got, test.want)
failed = true
} }
} }
} }
...@@ -61,26 +60,23 @@ func (p *prefix) slice_ssa() { ...@@ -61,26 +60,23 @@ func (p *prefix) slice_ssa() {
} }
//go:noinline //go:noinline
func testStructSlice() { func testStructSlice(t *testing.T) {
p := &prefix{"prefix"} p := &prefix{"prefix"}
p.slice_ssa() p.slice_ssa()
if "pre" != p.prefix { if "pre" != p.prefix {
println("wrong field slice: wanted %s got %s", "pre", p.prefix) t.Errorf("wrong field slice: wanted %s got %s", "pre", p.prefix)
failed = true
} }
} }
func testStringSlicePanic() { func testStringSlicePanic(t *testing.T) {
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
println("panicked as expected") //println("panicked as expected")
} }
}() }()
str := "foobar" str := "foobar"
println("got ", testStringSlice12_ssa(str, 3, 9)) t.Errorf("got %s and expected to panic, but didn't", testStringSlice12_ssa(str, 3, 9))
println("expected to panic, but didn't")
failed = true
} }
const _Accuracy_name = "BelowExactAbove" const _Accuracy_name = "BelowExactAbove"
...@@ -92,7 +88,7 @@ func testSmallIndexType_ssa(i int) string { ...@@ -92,7 +88,7 @@ func testSmallIndexType_ssa(i int) string {
return _Accuracy_name[_Accuracy_index[i]:_Accuracy_index[i+1]] return _Accuracy_name[_Accuracy_index[i]:_Accuracy_index[i+1]]
} }
func testSmallIndexType() { func testSmallIndexType(t *testing.T) {
tests := []struct { tests := []struct {
i int i int
want string want string
...@@ -102,10 +98,9 @@ func testSmallIndexType() { ...@@ -102,10 +98,9 @@ func testSmallIndexType() {
{2, "Above"}, {2, "Above"},
} }
for i, t := range tests { for i, test := range tests {
if got := testSmallIndexType_ssa(t.i); got != t.want { if got := testSmallIndexType_ssa(test.i); got != test.want {
println("#", i, "got ", got, ", wanted", t.want) t.Errorf("#%d got %s wanted %s", i, got, test.want)
failed = true
} }
} }
} }
...@@ -120,7 +115,7 @@ func testInt64Slice_ssa(s string, i, j int64) string { ...@@ -120,7 +115,7 @@ func testInt64Slice_ssa(s string, i, j int64) string {
return s[i:j] return s[i:j]
} }
func testInt64Index() { func testInt64Index(t *testing.T) {
tests := []struct { tests := []struct {
i int64 i int64
j int64 j int64
...@@ -133,42 +128,36 @@ func testInt64Index() { ...@@ -133,42 +128,36 @@ func testInt64Index() {
} }
str := "BelowExactAbove" str := "BelowExactAbove"
for i, t := range tests { for i, test := range tests {
if got := testInt64Index_ssa(str, t.i); got != t.b { if got := testInt64Index_ssa(str, test.i); got != test.b {
println("#", i, "got ", got, ", wanted", t.b) t.Errorf("#%d got %d wanted %d", i, got, test.b)
failed = true
} }
if got := testInt64Slice_ssa(str, t.i, t.j); got != t.s { if got := testInt64Slice_ssa(str, test.i, test.j); got != test.s {
println("#", i, "got ", got, ", wanted", t.s) t.Errorf("#%d got %s wanted %s", i, got, test.s)
failed = true
} }
} }
} }
func testInt64IndexPanic() { func testInt64IndexPanic(t *testing.T) {
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
println("panicked as expected") //println("panicked as expected")
} }
}() }()
str := "foobar" str := "foobar"
println("got ", testInt64Index_ssa(str, 1<<32+1)) t.Errorf("got %d and expected to panic, but didn't", testInt64Index_ssa(str, 1<<32+1))
println("expected to panic, but didn't")
failed = true
} }
func testInt64SlicePanic() { func testInt64SlicePanic(t *testing.T) {
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
println("panicked as expected") //println("panicked as expected")
} }
}() }()
str := "foobar" str := "foobar"
println("got ", testInt64Slice_ssa(str, 1<<32, 1<<32+1)) t.Errorf("got %s and expected to panic, but didn't", testInt64Slice_ssa(str, 1<<32, 1<<32+1))
println("expected to panic, but didn't")
failed = true
} }
//go:noinline //go:noinline
...@@ -176,7 +165,7 @@ func testStringElem_ssa(s string, i int) byte { ...@@ -176,7 +165,7 @@ func testStringElem_ssa(s string, i int) byte {
return s[i] return s[i]
} }
func testStringElem() { func testStringElem(t *testing.T) {
tests := []struct { tests := []struct {
s string s string
i int i int
...@@ -186,10 +175,9 @@ func testStringElem() { ...@@ -186,10 +175,9 @@ func testStringElem() {
{"foobar", 0, 102}, {"foobar", 0, 102},
{"foobar", 5, 114}, {"foobar", 5, 114},
} }
for _, t := range tests { for _, test := range tests {
if got := testStringElem_ssa(t.s, t.i); got != t.n { if got := testStringElem_ssa(test.s, test.i); got != test.n {
print("testStringElem \"", t.s, "\"[", t.i, "]=", got, ", wanted ", t.n, "\n") t.Errorf("testStringElem \"%s\"[%d] = %d, wanted %d", test.s, test.i, got, test.n)
failed = true
} }
} }
} }
...@@ -200,25 +188,20 @@ func testStringElemConst_ssa(i int) byte { ...@@ -200,25 +188,20 @@ func testStringElemConst_ssa(i int) byte {
return s[i] return s[i]
} }
func testStringElemConst() { func testStringElemConst(t *testing.T) {
if got := testStringElemConst_ssa(3); got != 98 { if got := testStringElemConst_ssa(3); got != 98 {
println("testStringElemConst=", got, ", wanted 98") t.Errorf("testStringElemConst= %d, wanted 98", got)
failed = true
} }
} }
func main() { func TestString(t *testing.T) {
testStringSlice() testStringSlice(t)
testStringSlicePanic() testStringSlicePanic(t)
testStructSlice() testStructSlice(t)
testSmallIndexType() testSmallIndexType(t)
testStringElem() testStringElem(t)
testStringElemConst() testStringElemConst(t)
testInt64Index() testInt64Index(t)
testInt64IndexPanic() testInt64IndexPanic(t)
testInt64SlicePanic() testInt64SlicePanic(t)
if failed {
panic("failed")
}
} }
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