From: Brad Fitzpatrick Date: Mon, 9 Apr 2012 18:19:52 +0000 (-0700) Subject: debug/gosym: in test, use temp binary name in /tmp, and clean up. X-Git-Tag: go1.1rc2~3420 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=494fe3b08fd78752497a1dc5838777dc4fb52650;p=gostls13.git debug/gosym: in test, use temp binary name in /tmp, and clean up. This fixes all.bash on shared machines. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5992078 --- diff --git a/src/pkg/debug/gosym/pclntab_test.go b/src/pkg/debug/gosym/pclntab_test.go index b2400bb3ba..ade704335d 100644 --- a/src/pkg/debug/gosym/pclntab_test.go +++ b/src/pkg/debug/gosym/pclntab_test.go @@ -7,14 +7,19 @@ package gosym import ( "debug/elf" "fmt" + "io/ioutil" "os" "os/exec" + "path/filepath" "runtime" "strings" "testing" ) -var pclinetestBinary string +var ( + pclineTempDir string + pclinetestBinary string +) func dotest() bool { // For now, only works on ELF platforms. @@ -24,10 +29,18 @@ func dotest() bool { if pclinetestBinary != "" { return true } + var err error + pclineTempDir, err = ioutil.TempDir("", "pclinetest") + if err != nil { + panic(err) + } + if strings.Contains(pclineTempDir, " ") { + panic("unexpected space in tempdir") + } // This command builds pclinetest from pclinetest.asm; // the resulting binary looks like it was built from pclinetest.s, // but we have renamed it to keep it away from the go tool. - pclinetestBinary = os.TempDir() + "/pclinetest" + pclinetestBinary = filepath.Join(pclineTempDir, "pclinetest") command := fmt.Sprintf("go tool 6a -o %s.6 pclinetest.asm && go tool 6l -E main -o %s %s.6", pclinetestBinary, pclinetestBinary, pclinetestBinary) cmd := exec.Command("sh", "-c", command) @@ -170,6 +183,7 @@ func TestPCLine(t *testing.T) { if !dotest() { return } + defer os.RemoveAll(pclineTempDir) f, tab := crack(pclinetestBinary, t) text := f.Section(".text")