From 07b2fee4607aa6c710411a7ac404f18be4dff6f7 Mon Sep 17 00:00:00 2001 From: Lynn Boger Date: Fri, 9 Apr 2021 10:41:27 -0500 Subject: [PATCH] cmd/link: fix TestLargeText This test is not run in short mode so it was getting failures that didn't happen with default testing. See the issue for details on the failures. Fixes #45406 Change-Id: I51d97cc4c910fe3ba2bc0a12742023a57d101f44 Reviewed-on: https://go-review.googlesource.com/c/go/+/308935 Run-TryBot: Lynn Boger TryBot-Result: Go Bot Reviewed-by: Paul Murphy Reviewed-by: Cherry Zhang Trust: Lynn Boger --- src/cmd/link/linkbig_test.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/cmd/link/linkbig_test.go b/src/cmd/link/linkbig_test.go index d5d77d6c72..917bd9e8a3 100644 --- a/src/cmd/link/linkbig_test.go +++ b/src/cmd/link/linkbig_test.go @@ -14,7 +14,6 @@ import ( "fmt" "internal/testenv" "io/ioutil" - "os" "os/exec" "testing" ) @@ -29,6 +28,10 @@ func TestLargeText(t *testing.T) { const FN = 4 tmpdir := t.TempDir() + if err := ioutil.WriteFile(tmpdir+"/go.mod", []byte("module big_test\n"), 0666); err != nil { + t.Fatal(err) + } + // Generate the scenario where the total amount of text exceeds the // limit for the jmp/call instruction, on RISC architectures like ppc64le, // which is 2^26. When that happens the call requires special trampolines or @@ -80,26 +83,28 @@ func TestLargeText(t *testing.T) { } // Build and run with internal linking. - os.Chdir(tmpdir) cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", "bigtext") + cmd.Dir = tmpdir out, err := cmd.CombinedOutput() if err != nil { t.Fatalf("Build failed for big text program with internal linking: %v, output: %s", err, out) } - cmd = exec.Command(tmpdir + "/bigtext") + cmd = exec.Command("./bigtext") + cmd.Dir = tmpdir out, err = cmd.CombinedOutput() if err != nil { t.Fatalf("Program built with internal linking failed to run with err %v, output: %s", err, out) } // Build and run with external linking - os.Chdir(tmpdir) cmd = exec.Command(testenv.GoToolPath(t), "build", "-o", "bigtext", "-ldflags", "'-linkmode=external'") + cmd.Dir = tmpdir out, err = cmd.CombinedOutput() if err != nil { t.Fatalf("Build failed for big text program with external linking: %v, output: %s", err, out) } - cmd = exec.Command(tmpdir + "/bigtext") + cmd = exec.Command("./bigtext") + cmd.Dir = tmpdir out, err = cmd.CombinedOutput() if err != nil { t.Fatalf("Program built with external linking failed to run with err %v, output: %s", err, out) -- 2.48.1