diff options
Diffstat (limited to 'src/debug')
| -rw-r--r-- | src/debug/gosym/pclntab_test.go | 48 |
1 files changed, 21 insertions, 27 deletions
diff --git a/src/debug/gosym/pclntab_test.go b/src/debug/gosym/pclntab_test.go index 53f3e952d6..8d4aa547a0 100644 --- a/src/debug/gosym/pclntab_test.go +++ b/src/debug/gosym/pclntab_test.go @@ -6,6 +6,7 @@ package gosym import ( "debug/elf" + "internal/testenv" "io/ioutil" "os" "os/exec" @@ -20,25 +21,16 @@ var ( pclinetestBinary string ) -func dotest(self bool) bool { +func dotest(t *testing.T) { + testenv.MustHaveGoBuild(t) // For now, only works on amd64 platforms. if runtime.GOARCH != "amd64" { - return false - } - // Self test reads test binary; only works on Linux. - if self && runtime.GOOS != "linux" { - return false - } - if pclinetestBinary != "" { - return true + t.Skipf("skipping on non-AMD64 system %s", runtime.GOARCH) } var err error pclineTempDir, err = ioutil.TempDir("", "pclinetest") if err != nil { - panic(err) - } - if strings.Contains(pclineTempDir, " ") { - panic("unexpected space in tempdir") + t.Fatal(err) } // This command builds pclinetest from pclinetest.asm; // the resulting binary looks like it was built from pclinetest.s, @@ -48,16 +40,15 @@ func dotest(self bool) bool { cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr if err := cmd.Run(); err != nil { - panic(err) + t.Fatal(err) } cmd = exec.Command("go", "tool", "link", "-H", "linux", "-E", "main", "-o", pclinetestBinary, pclinetestBinary+".o") cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr if err := cmd.Run(); err != nil { - panic(err) + t.Fatal(err) } - return true } func endtest() { @@ -68,6 +59,17 @@ func endtest() { } } +// skipIfNotELF skips the test if we are not running on an ELF system. +// These tests open and examine the test binary, and use elf.Open to do so. +func skipIfNotELF(t *testing.T) { + switch runtime.GOOS { + case "dragonfly", "freebsd", "linux", "netbsd", "openbsd", "solaris": + // OK. + default: + t.Skipf("skipping on non-ELF system %s", runtime.GOOS) + } +} + func getTable(t *testing.T) *Table { f, tab := crack(os.Args[0], t) f.Close() @@ -112,10 +114,7 @@ func parse(file string, f *elf.File, t *testing.T) (*elf.File, *Table) { var goarch = os.Getenv("O") func TestLineFromAline(t *testing.T) { - if !dotest(true) { - return - } - defer endtest() + skipIfNotELF(t) tab := getTable(t) if tab.go12line != nil { @@ -164,10 +163,7 @@ func TestLineFromAline(t *testing.T) { } func TestLineAline(t *testing.T) { - if !dotest(true) { - return - } - defer endtest() + skipIfNotELF(t) tab := getTable(t) if tab.go12line != nil { @@ -210,9 +206,7 @@ func TestLineAline(t *testing.T) { } func TestPCLine(t *testing.T) { - if !dotest(false) { - return - } + dotest(t) defer endtest() f, tab := crack(pclinetestBinary, t) |
