Skip to content

Commit

Permalink
Revert "test: avoid writing temporary files to GOROOT"
Browse files Browse the repository at this point in the history
This reverts CL 207352

Reason for revert: broke more builders than it fixed. 😞

Change-Id: Ic5adefe92edfa2230b9c7d750c922473a6a5ded4
Reviewed-on: https://go-review.googlesource.com/c/go/+/207477
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
  • Loading branch information
Bryan C. Mills committed Nov 15, 2019
1 parent dab1a10 commit 72f333a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 73 deletions.
14 changes: 5 additions & 9 deletions src/cmd/dist/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1358,21 +1358,17 @@ var runtest struct {

func (t *tester) testDirTest(dt *distTest, shard, shards int) error {
runtest.Do(func() {
f, err := ioutil.TempFile("", "runtest-*.exe") // named exe for Windows, but harmless elsewhere
if err != nil {
const exe = "runtest.exe" // named exe for Windows, but harmless elsewhere
cmd := t.dirCmd("test", "go", "build", "-o", exe, "run.go")
cmd.Env = append(os.Environ(), "GOOS="+gohostos, "GOARCH="+gohostarch)
runtest.exe = filepath.Join(cmd.Dir, exe)
if err := cmd.Run(); err != nil {
runtest.err = err
return
}
f.Close()

runtest.exe = f.Name()
xatexit(func() {
os.Remove(runtest.exe)
})

cmd := t.dirCmd("test", "go", "build", "-o", runtest.exe, "run.go")
cmd.Env = append(os.Environ(), "GOOS="+gohostos, "GOARCH="+gohostarch)
runtest.err = cmd.Run()
})
if runtest.err != nil {
return runtest.err
Expand Down
24 changes: 6 additions & 18 deletions test/fixedbugs/bug302.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,22 @@ package main

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
)

var tmpDir string

func main() {
fb, err := filepath.Abs("fixedbugs")
if err == nil {
tmpDir, err = ioutil.TempDir("", "bug302")
}
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer os.RemoveAll(tmpDir)

run("go", "tool", "compile", filepath.Join(fb, "bug302.dir", "p.go"))
run("go", "tool", "compile", filepath.Join("fixedbugs", "bug302.dir", "p.go"))
run("go", "tool", "pack", "grc", "pp.a", "p.o")
run("go", "tool", "compile", "-I", ".", filepath.Join(fb, "bug302.dir", "main.go"))
run("go", "tool", "compile", "-I", ".", filepath.Join("fixedbugs", "bug302.dir", "main.go"))
os.Remove("p.o")
os.Remove("pp.a")
os.Remove("main.o")
}

func run(cmd string, args ...string) {
c := exec.Command(cmd, args...)
c.Dir = tmpDir
out, err := c.CombinedOutput()
out, err := exec.Command(cmd, args...).CombinedOutput()
if err != nil {
fmt.Println(string(out))
fmt.Println(err)
Expand Down
22 changes: 9 additions & 13 deletions test/fixedbugs/bug369.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ package main

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand All @@ -21,19 +20,16 @@ func main() {
err := os.Chdir(filepath.Join(".", "fixedbugs", "bug369.dir"))
check(err)

tmpDir, err := ioutil.TempDir("", "bug369")
check(err)
defer os.RemoveAll(tmpDir)

tmp := func(name string) string {
return filepath.Join(tmpDir, name)
}
run("go", "tool", "compile", "-N", "-o", "slow.o", "pkg.go")
run("go", "tool", "compile", "-o", "fast.o", "pkg.go")
run("go", "tool", "compile", "-o", "main.o", "main.go")
run("go", "tool", "link", "-o", "a.exe", "main.o")
run("." + string(filepath.Separator) + "a.exe")

run("go", "tool", "compile", "-N", "-o", tmp("slow.o"), "pkg.go")
run("go", "tool", "compile", "-o", tmp("fast.o"), "pkg.go")
run("go", "tool", "compile", "-D", tmpDir, "-o", tmp("main.o"), "main.go")
run("go", "tool", "link", "-o", tmp("a.exe"), tmp("main.o"))
run(tmp("a.exe"))
os.Remove("slow.o")
os.Remove("fast.o")
os.Remove("main.o")
os.Remove("a.exe")
}

func run(name string, args ...string) {
Expand Down
3 changes: 2 additions & 1 deletion test/fixedbugs/issue9355.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ func main() {
err := os.Chdir(filepath.Join("fixedbugs", "issue9355.dir"))
check(err)

out := run("go", "tool", "compile", "-o", os.DevNull, "-S", "a.go")
out := run("go", "tool", "compile", "-S", "a.go")
os.Remove("a.o")

// 6g/8g print the offset as dec, but 5g/9g print the offset as hex.
patterns := []string{
Expand Down
44 changes: 17 additions & 27 deletions test/linkmain_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ package main

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
)

var tmpDir string

func cleanup() {
os.RemoveAll(tmpDir)
os.Remove("linkmain.o")
os.Remove("linkmain.a")
os.Remove("linkmain1.o")
os.Remove("linkmain1.a")
os.Remove("linkmain.exe")
}

func run(cmdline ...string) {
args := strings.Fields(strings.Join(cmdline, " "))
func run(cmdline string) {
args := strings.Fields(cmdline)
cmd := exec.Command(args[0], args[1:]...)
out, err := cmd.CombinedOutput()
if err != nil {
Expand All @@ -37,8 +37,8 @@ func run(cmdline ...string) {
}
}

func runFail(cmdline ...string) {
args := strings.Fields(strings.Join(cmdline, " "))
func runFail(cmdline string) {
args := strings.Fields(cmdline)
cmd := exec.Command(args[0], args[1:]...)
out, err := cmd.CombinedOutput()
if err == nil {
Expand All @@ -51,26 +51,16 @@ func runFail(cmdline ...string) {
}

func main() {
var err error
tmpDir, err = ioutil.TempDir("", "")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
tmp := func(name string) string {
return filepath.Join(tmpDir, name)
}

// helloworld.go is package main
run("go tool compile -o", tmp("linkmain.o"), "helloworld.go")
run("go tool compile -pack -o", tmp("linkmain.a"), "helloworld.go")
run("go tool link -o", tmp("linkmain.exe"), tmp("linkmain.o"))
run("go tool link -o", tmp("linkmain.exe"), tmp("linkmain.a"))
run("go tool compile -o linkmain.o helloworld.go")
run("go tool compile -pack -o linkmain.a helloworld.go")
run("go tool link -o linkmain.exe linkmain.o")
run("go tool link -o linkmain.exe linkmain.a")

// linkmain.go is not
run("go tool compile -o", tmp("linkmain1.o"), "linkmain.go")
run("go tool compile -pack -o", tmp("linkmain1.a"), "linkmain.go")
runFail("go tool link -o", tmp("linkmain.exe"), tmp("linkmain1.o"))
runFail("go tool link -o", tmp("linkmain.exe"), tmp("linkmain1.a"))
run("go tool compile -o linkmain1.o linkmain.go")
run("go tool compile -pack -o linkmain1.a linkmain.go")
runFail("go tool link -o linkmain.exe linkmain1.o")
runFail("go tool link -o linkmain.exe linkmain1.a")
cleanup()
}
7 changes: 2 additions & 5 deletions test/sinit_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,15 @@ import (
)

func main() {
cmd := exec.Command("go", "tool", "compile", "-o", os.DevNull, "-S", "sinit.go")
cmd := exec.Command("go", "tool", "compile", "-S", "sinit.go")
out, err := cmd.CombinedOutput()
if err != nil {
fmt.Println(string(out))
fmt.Println(err)
os.Exit(1)
}
os.Remove("sinit.o")

if len(bytes.TrimSpace(out)) == 0 {
fmt.Println("'go tool compile -S sinit.go' printed no output")
os.Exit(1)
}
if bytes.Contains(out, []byte("initdone")) {
fmt.Println("sinit generated an init function")
os.Exit(1)
Expand Down

0 comments on commit 72f333a

Please sign in to comment.