github.com/euank/go@v0.0.0-20160829210321-495514729181/src/cmd/compile/internal/gc/ssa_test.go (about)

     1  // Copyright 2015 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 gc
     6  
     7  import (
     8  	"bytes"
     9  	"internal/testenv"
    10  	"os/exec"
    11  	"path/filepath"
    12  	"runtime"
    13  	"strings"
    14  	"testing"
    15  )
    16  
    17  // TODO: move all these tests elsewhere?
    18  // Perhaps teach test/run.go how to run them with a new action verb.
    19  func runTest(t *testing.T, filename string) {
    20  	doTest(t, filename, "run")
    21  }
    22  func buildTest(t *testing.T, filename string) {
    23  	doTest(t, filename, "build")
    24  }
    25  func doTest(t *testing.T, filename string, kind string) {
    26  	testenv.MustHaveGoBuild(t)
    27  	var stdout, stderr bytes.Buffer
    28  	cmd := exec.Command("go", kind, filepath.Join("testdata", filename))
    29  	cmd.Stdout = &stdout
    30  	cmd.Stderr = &stderr
    31  	if err := cmd.Run(); err != nil {
    32  		t.Fatalf("Failed: %v:\nOut: %s\nStderr: %s\n", err, &stdout, &stderr)
    33  	}
    34  	if s := stdout.String(); s != "" {
    35  		t.Errorf("Stdout = %s\nWant empty", s)
    36  	}
    37  	if s := stderr.String(); strings.Contains(s, "SSA unimplemented") {
    38  		t.Errorf("Unimplemented message found in stderr:\n%s", s)
    39  	}
    40  }
    41  
    42  // TestShortCircuit tests OANDAND and OOROR expressions and short circuiting.
    43  func TestShortCircuit(t *testing.T) { runTest(t, "short_ssa.go") }
    44  
    45  // TestBreakContinue tests that continue and break statements do what they say.
    46  func TestBreakContinue(t *testing.T) { runTest(t, "break_ssa.go") }
    47  
    48  // TestTypeAssertion tests type assertions.
    49  func TestTypeAssertion(t *testing.T) { runTest(t, "assert_ssa.go") }
    50  
    51  // TestArithmetic tests that both backends have the same result for arithmetic expressions.
    52  func TestArithmetic(t *testing.T) {
    53  	if runtime.GOARCH == "386" {
    54  		t.Skip("legacy 386 compiler can't handle this test")
    55  	}
    56  	runTest(t, "arith_ssa.go")
    57  }
    58  
    59  // TestFP tests that both backends have the same result for floating point expressions.
    60  func TestFP(t *testing.T) { runTest(t, "fp_ssa.go") }
    61  
    62  // TestArithmeticBoundary tests boundary results for arithmetic operations.
    63  func TestArithmeticBoundary(t *testing.T) { runTest(t, "arithBoundary_ssa.go") }
    64  
    65  // TestArithmeticConst tests results for arithmetic operations against constants.
    66  func TestArithmeticConst(t *testing.T) { runTest(t, "arithConst_ssa.go") }
    67  
    68  func TestChan(t *testing.T) { runTest(t, "chan_ssa.go") }
    69  
    70  func TestCompound(t *testing.T) { runTest(t, "compound_ssa.go") }
    71  
    72  func TestCtl(t *testing.T) { runTest(t, "ctl_ssa.go") }
    73  
    74  func TestLoadStore(t *testing.T) { runTest(t, "loadstore_ssa.go") }
    75  
    76  func TestMap(t *testing.T) { runTest(t, "map_ssa.go") }
    77  
    78  func TestRegalloc(t *testing.T) { runTest(t, "regalloc_ssa.go") }
    79  
    80  func TestString(t *testing.T) { runTest(t, "string_ssa.go") }
    81  
    82  func TestDeferNoReturn(t *testing.T) { buildTest(t, "deferNoReturn_ssa.go") }
    83  
    84  // TestClosure tests closure related behavior.
    85  func TestClosure(t *testing.T) { runTest(t, "closure_ssa.go") }
    86  
    87  func TestArray(t *testing.T) { runTest(t, "array_ssa.go") }
    88  
    89  func TestAppend(t *testing.T) { runTest(t, "append_ssa.go") }
    90  
    91  func TestZero(t *testing.T) { runTest(t, "zero_ssa.go") }
    92  
    93  func TestAddressed(t *testing.T) { runTest(t, "addressed_ssa.go") }
    94  
    95  func TestCopy(t *testing.T) { runTest(t, "copy_ssa.go") }
    96  
    97  func TestUnsafe(t *testing.T) { runTest(t, "unsafe_ssa.go") }
    98  
    99  func TestPhi(t *testing.T) { runTest(t, "phi_ssa.go") }
   100  
   101  func TestSlice(t *testing.T) { runTest(t, "slice.go") }
   102  
   103  func TestNamedReturn(t *testing.T) { runTest(t, "namedReturn.go") }
   104  
   105  func TestDuplicateLoad(t *testing.T) { runTest(t, "dupLoad.go") }
   106  
   107  func TestSqrt(t *testing.T) { runTest(t, "sqrt_const.go") }