From da109c6075e135bae4b8681e0c53c725e62a354c Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Mon, 6 Nov 2017 10:47:02 -0500 Subject: [PATCH] cmd/compile: enable ssacheck for tests in ssa_test.go I thought SSA check was enabled for those tests, but in fact it was not. Enable it. So we have SSA check on for at least some tests on all architectures. Updates #22499. Change-Id: I51fcdda3af7faab5aeb33bf46c6db309285ce42c Reviewed-on: https://go-review.googlesource.com/76024 Reviewed-by: Keith Randall --- src/cmd/compile/internal/gc/ssa_test.go | 32 +++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/cmd/compile/internal/gc/ssa_test.go b/src/cmd/compile/internal/gc/ssa_test.go index 40d80e6aba..462910a986 100644 --- a/src/cmd/compile/internal/gc/ssa_test.go +++ b/src/cmd/compile/internal/gc/ssa_test.go @@ -8,6 +8,7 @@ import ( "bytes" "internal/testenv" "io/ioutil" + "os" "os/exec" "path/filepath" "runtime" @@ -27,11 +28,38 @@ func buildTest(t *testing.T, filename string) { } func doTest(t *testing.T, filename string, kind string) { testenv.MustHaveGoBuild(t) + gotool := testenv.GoToolPath(t) + tmpdir, ok := ioutil.TempDir("", "ssatest") + if ok != nil { + t.Fatalf("Failed to create temporary directory") + } + defer os.RemoveAll(tmpdir) + + // Execute compile+link+run instead of "go run" to avoid applying -gcflags=-d=ssa/check/on + // to the runtime (especially over and over and over). + // compile var stdout, stderr bytes.Buffer - cmd := exec.Command(testenv.GoToolPath(t), kind, filepath.Join("testdata", filename)) + cmd := exec.Command(gotool, "tool", "compile", "-d=ssa/check/on", "-o", filepath.Join(tmpdir, "run.a"), filepath.Join("testdata", filename)) cmd.Stdout = &stdout cmd.Stderr = &stderr - if err := cmd.Run(); err != nil { + err := cmd.Run() + if kind == "run" { + if err == nil { + // link + cmd = exec.Command(gotool, "tool", "link", "-o", filepath.Join(tmpdir, "run.exe"), filepath.Join(tmpdir, "run.a")) + cmd.Stdout = &stdout + cmd.Stderr = &stderr + err = cmd.Run() + } + if err == nil { + // run + cmd = exec.Command(filepath.Join(tmpdir, "run.exe")) + cmd.Stdout = &stdout + cmd.Stderr = &stderr + err = cmd.Run() + } + } + if err != nil { t.Fatalf("Failed: %v:\nOut: %s\nStderr: %s\n", err, &stdout, &stderr) } if s := stdout.String(); s != "" { -- 2.48.1