2015-07-10 12:58:53 -06:00
|
|
|
// Copyright 2015 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.
|
|
|
|
|
|
|
|
|
|
package gc
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"internal/testenv"
|
|
|
|
|
"os/exec"
|
2015-07-20 15:39:14 -07:00
|
|
|
"path/filepath"
|
2015-07-13 14:57:16 -06:00
|
|
|
"runtime"
|
2015-07-10 12:58:53 -06:00
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
2015-07-20 15:39:14 -07:00
|
|
|
// TODO: move all these tests elsewhere?
|
|
|
|
|
// Perhaps teach test/run.go how to run them with a new action verb.
|
|
|
|
|
func runTest(t *testing.T, filename string) {
|
2015-09-08 08:59:57 -07:00
|
|
|
doTest(t, filename, "run")
|
|
|
|
|
}
|
|
|
|
|
func buildTest(t *testing.T, filename string) {
|
|
|
|
|
doTest(t, filename, "build")
|
|
|
|
|
}
|
|
|
|
|
func doTest(t *testing.T, filename string, kind string) {
|
2015-07-10 12:58:53 -06:00
|
|
|
testenv.MustHaveGoBuild(t)
|
|
|
|
|
var stdout, stderr bytes.Buffer
|
2015-09-08 08:59:57 -07:00
|
|
|
cmd := exec.Command("go", kind, filepath.Join("testdata", filename))
|
2015-07-10 12:58:53 -06:00
|
|
|
cmd.Stdout = &stdout
|
|
|
|
|
cmd.Stderr = &stderr
|
|
|
|
|
if err := cmd.Run(); err != nil {
|
|
|
|
|
t.Fatalf("Failed: %v:\nOut: %s\nStderr: %s\n", err, &stdout, &stderr)
|
|
|
|
|
}
|
|
|
|
|
if s := stdout.String(); s != "" {
|
|
|
|
|
t.Errorf("Stdout = %s\nWant empty", s)
|
|
|
|
|
}
|
|
|
|
|
if s := stderr.String(); strings.Contains(s, "SSA unimplemented") {
|
|
|
|
|
t.Errorf("Unimplemented message found in stderr:\n%s", s)
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-20 15:39:14 -07:00
|
|
|
|
|
|
|
|
// TestShortCircuit tests OANDAND and OOROR expressions and short circuiting.
|
|
|
|
|
func TestShortCircuit(t *testing.T) { runTest(t, "short_ssa.go") }
|
|
|
|
|
|
|
|
|
|
// TestBreakContinue tests that continue and break statements do what they say.
|
|
|
|
|
func TestBreakContinue(t *testing.T) { runTest(t, "break_ssa.go") }
|
2015-07-25 12:53:58 -05:00
|
|
|
|
2015-09-17 10:31:16 -07:00
|
|
|
// TestTypeAssertion tests type assertions.
|
|
|
|
|
func TestTypeAssertion(t *testing.T) { runTest(t, "assert_ssa.go") }
|
|
|
|
|
|
2015-07-25 12:53:58 -05:00
|
|
|
// TestArithmetic tests that both backends have the same result for arithmetic expressions.
|
2016-05-03 17:21:36 -07:00
|
|
|
func TestArithmetic(t *testing.T) {
|
|
|
|
|
if runtime.GOARCH == "386" {
|
|
|
|
|
t.Skip("legacy 386 compiler can't handle this test")
|
|
|
|
|
}
|
|
|
|
|
runTest(t, "arith_ssa.go")
|
|
|
|
|
}
|
2015-08-12 16:38:11 -04:00
|
|
|
|
|
|
|
|
// TestFP tests that both backends have the same result for floating point expressions.
|
2016-05-05 16:51:54 -07:00
|
|
|
func TestFP(t *testing.T) { runTest(t, "fp_ssa.go") }
|
2015-08-17 17:46:06 -05:00
|
|
|
|
|
|
|
|
// TestArithmeticBoundary tests boundary results for arithmetic operations.
|
|
|
|
|
func TestArithmeticBoundary(t *testing.T) { runTest(t, "arithBoundary_ssa.go") }
|
2015-08-18 19:14:47 -05:00
|
|
|
|
|
|
|
|
// TestArithmeticConst tests results for arithmetic operations against constants.
|
|
|
|
|
func TestArithmeticConst(t *testing.T) { runTest(t, "arithConst_ssa.go") }
|
2015-09-07 19:29:26 -05:00
|
|
|
|
|
|
|
|
func TestChan(t *testing.T) { runTest(t, "chan_ssa.go") }
|
|
|
|
|
|
|
|
|
|
func TestCompound(t *testing.T) { runTest(t, "compound_ssa.go") }
|
|
|
|
|
|
|
|
|
|
func TestCtl(t *testing.T) { runTest(t, "ctl_ssa.go") }
|
|
|
|
|
|
|
|
|
|
func TestLoadStore(t *testing.T) { runTest(t, "loadstore_ssa.go") }
|
|
|
|
|
|
|
|
|
|
func TestMap(t *testing.T) { runTest(t, "map_ssa.go") }
|
|
|
|
|
|
|
|
|
|
func TestRegalloc(t *testing.T) { runTest(t, "regalloc_ssa.go") }
|
|
|
|
|
|
|
|
|
|
func TestString(t *testing.T) { runTest(t, "string_ssa.go") }
|
2015-09-08 08:59:57 -07:00
|
|
|
|
|
|
|
|
func TestDeferNoReturn(t *testing.T) { buildTest(t, "deferNoReturn_ssa.go") }
|
2015-09-07 19:07:02 -05:00
|
|
|
|
|
|
|
|
// TestClosure tests closure related behavior.
|
|
|
|
|
func TestClosure(t *testing.T) { runTest(t, "closure_ssa.go") }
|
2015-09-12 23:27:26 -07:00
|
|
|
|
|
|
|
|
func TestArray(t *testing.T) { runTest(t, "array_ssa.go") }
|
2015-09-11 11:02:57 -07:00
|
|
|
|
|
|
|
|
func TestAppend(t *testing.T) { runTest(t, "append_ssa.go") }
|
2015-09-18 18:23:34 -07:00
|
|
|
|
|
|
|
|
func TestZero(t *testing.T) { runTest(t, "zero_ssa.go") }
|
2015-09-11 16:40:05 -04:00
|
|
|
|
|
|
|
|
func TestAddressed(t *testing.T) { runTest(t, "addressed_ssa.go") }
|
2015-10-21 17:18:07 -07:00
|
|
|
|
|
|
|
|
func TestCopy(t *testing.T) { runTest(t, "copy_ssa.go") }
|
2015-11-10 15:35:36 -08:00
|
|
|
|
|
|
|
|
func TestUnsafe(t *testing.T) { runTest(t, "unsafe_ssa.go") }
|
2016-01-04 13:34:54 -08:00
|
|
|
|
|
|
|
|
func TestPhi(t *testing.T) { runTest(t, "phi_ssa.go") }
|
2016-03-21 10:22:03 -07:00
|
|
|
|
|
|
|
|
func TestSlice(t *testing.T) { runTest(t, "slice.go") }
|
2016-04-01 11:05:30 -07:00
|
|
|
|
|
|
|
|
func TestNamedReturn(t *testing.T) { runTest(t, "namedReturn.go") }
|
2016-04-11 21:23:11 -07:00
|
|
|
|
|
|
|
|
func TestDuplicateLoad(t *testing.T) { runTest(t, "dupLoad.go") }
|
2016-08-20 22:05:47 -07:00
|
|
|
|
|
|
|
|
func TestSqrt(t *testing.T) { runTest(t, "sqrt_const.go") }
|