提交 b47d6a09 编写于 作者: A Alessandro Arzilli 提交者: Derek Parker

dwarf/line: load PE files correctly in test (#894)

Fixes #885
上级 7d2834a9
......@@ -4,6 +4,7 @@ import (
"debug/elf"
"debug/macho"
"debug/pe"
"flag"
"os"
"os/exec"
"path/filepath"
......@@ -13,6 +14,14 @@ import (
"github.com/pkg/profile"
)
var userTestFile string
func TestMain(m *testing.M) {
flag.StringVar(&userTestFile, "user", "", "runs line parsing test on one extra file")
flag.Parse()
os.Exit(m.Run())
}
func grabDebugLineSection(p string, t *testing.T) []byte {
f, err := os.Open(p)
if err != nil {
......@@ -28,7 +37,11 @@ func grabDebugLineSection(p string, t *testing.T) []byte {
pf, err := pe.NewFile(f)
if err == nil {
data, _ := pf.Section(".debug_line").Data()
sec := pf.Section(".debug_line")
data, _ := sec.Data()
if 0 < sec.VirtualSize && sec.VirtualSize < sec.Size {
return data[:sec.VirtualSize]
}
return data
}
......@@ -45,18 +58,7 @@ const (
lineRangeGo18 uint8 = 10
)
func TestDebugLinePrologueParser(t *testing.T) {
// Test against known good values, from readelf --debug-dump=rawline _fixtures/testnextprog
p, err := filepath.Abs("../../../_fixtures/testnextprog")
if err != nil {
t.Fatal(err)
}
err = exec.Command("go", "build", "-gcflags=-N -l", "-o", p, p+".go").Run()
if err != nil {
t.Fatal("Could not compile test file", p, err)
}
defer os.Remove(p)
func testDebugLinePrologueParser(p string, t *testing.T) {
data := grabDebugLineSection(p, t)
debugLines := Parse(data)
dbl := debugLines[0]
......@@ -113,6 +115,29 @@ func TestDebugLinePrologueParser(t *testing.T) {
}
}
func TestUserFile(t *testing.T) {
if userTestFile == "" {
return
}
t.Logf("testing %q", userTestFile)
testDebugLinePrologueParser(userTestFile, t)
}
func TestDebugLinePrologueParser(t *testing.T) {
// Test against known good values, from readelf --debug-dump=rawline _fixtures/testnextprog
p, err := filepath.Abs("../../../_fixtures/testnextprog")
if err != nil {
t.Fatal(err)
}
err = exec.Command("go", "build", "-gcflags=-N -l", "-o", p, p+".go").Run()
if err != nil {
t.Fatal("Could not compile test file", p, err)
}
defer os.Remove(p)
testDebugLinePrologueParser(p, t)
}
func BenchmarkLineParser(b *testing.B) {
defer profile.Start(profile.MemProfile).Stop()
p, err := filepath.Abs("../../../_fixtures/testnextprog")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册