Commit e609bd37 authored by Ian Lance Taylor's avatar Ian Lance Taylor

cmd/link: use SeekPC in testDWARF

This makes the tests slightly faster, though the bulk of the time is
still spent building the test programs.

Also run some tests in parallel.

Updates #26470

Change-Id: Ia5ec2b99831d69c426b43dbab80613aa03e705f5
Reviewed-on: https://go-review.googlesource.com/c/153258Reviewed-by: default avatarAustin Clements <austin@google.com>
parent b97e40fc
...@@ -8,7 +8,6 @@ import ( ...@@ -8,7 +8,6 @@ import (
"cmd/internal/objfile" "cmd/internal/objfile"
"debug/dwarf" "debug/dwarf"
"internal/testenv" "internal/testenv"
"io"
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
...@@ -46,6 +45,8 @@ func testDWARF(t *testing.T, buildmode string, expectDWARF bool, env ...string) ...@@ -46,6 +45,8 @@ func testDWARF(t *testing.T, buildmode string, expectDWARF bool, env ...string)
for _, prog := range []string{"testprog", "testprogcgo"} { for _, prog := range []string{"testprog", "testprogcgo"} {
t.Run(prog, func(t *testing.T) { t.Run(prog, func(t *testing.T) {
t.Parallel()
exe := filepath.Join(tmpDir, prog+".exe") exe := filepath.Join(tmpDir, prog+".exe")
dir := "../../runtime/testdata/" + prog dir := "../../runtime/testdata/" + prog
cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", exe) cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", exe)
...@@ -109,43 +110,23 @@ func testDWARF(t *testing.T, buildmode string, expectDWARF bool, env ...string) ...@@ -109,43 +110,23 @@ func testDWARF(t *testing.T, buildmode string, expectDWARF bool, env ...string)
wantFile := path.Join(prog, "main.go") wantFile := path.Join(prog, "main.go")
wantLine := 24 wantLine := 24
r := d.Reader() r := d.Reader()
entry, err := r.SeekPC(addr)
if err != nil {
t.Fatal(err)
}
lr, err := d.LineReader(entry)
if err != nil {
t.Fatal(err)
}
var line dwarf.LineEntry var line dwarf.LineEntry
for { if err := lr.SeekPC(addr, &line); err == dwarf.ErrUnknownPC {
cu, err := r.Next() t.Fatalf("did not find file:line for %#x (main.main)", addr)
if err != nil { } else if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if cu == nil { if !strings.HasSuffix(line.File.Name, wantFile) || line.Line != wantLine {
break t.Errorf("%#x is %s:%d, want %s:%d", addr, line.File.Name, line.Line, filepath.Join("...", wantFile), wantLine)
}
if cu.Tag != dwarf.TagCompileUnit {
r.SkipChildren()
continue
}
if cu.Val(dwarf.AttrStmtList) == nil {
continue
}
lr, err := d.LineReader(cu)
if err != nil {
t.Fatal(err)
}
for {
err := lr.Next(&line)
if err == io.EOF {
break
}
if err != nil {
t.Fatal(err)
}
if line.Address == addr {
if !strings.HasSuffix(line.File.Name, wantFile) || line.Line != wantLine {
t.Errorf("%#x is %s:%d, want %s:%d", addr, line.File.Name, line.Line, filepath.Join("...", wantFile), wantLine)
}
return
}
}
} }
t.Fatalf("did not find file:line for %#x (main.main)", addr)
}) })
} }
} }
......
...@@ -39,6 +39,8 @@ func TestLargeSymName(t *testing.T) { ...@@ -39,6 +39,8 @@ func TestLargeSymName(t *testing.T) {
} }
func TestIssue21703(t *testing.T) { func TestIssue21703(t *testing.T) {
t.Parallel()
testenv.MustHaveGoBuild(t) testenv.MustHaveGoBuild(t)
const source = ` const source = `
...@@ -78,6 +80,8 @@ func main() {} ...@@ -78,6 +80,8 @@ func main() {}
// to, for example, save facts produced by a modular static analysis // to, for example, save facts produced by a modular static analysis
// such as golang.org/x/tools/go/analysis. // such as golang.org/x/tools/go/analysis.
func TestIssue28429(t *testing.T) { func TestIssue28429(t *testing.T) {
t.Parallel()
testenv.MustHaveGoBuild(t) testenv.MustHaveGoBuild(t)
tmpdir, err := ioutil.TempDir("", "issue28429-") tmpdir, err := ioutil.TempDir("", "issue28429-")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment