mirror of
https://github.com/go-delve/delve.git
synced 2025-11-02 04:36:29 +08:00
Rebuild binaries for every test
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package helper
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"syscall"
|
||||
@ -22,6 +23,11 @@ func GetRegisters(p *proctl.DebuggedProcess, t *testing.T) *syscall.PtraceRegs {
|
||||
|
||||
func WithTestProcess(name string, t *testing.T, fn testfunc) {
|
||||
runtime.LockOSThread()
|
||||
err := CompileTestProg(name)
|
||||
if err != nil {
|
||||
t.Fatalf("Could not compile %s due to %s", name, err)
|
||||
}
|
||||
|
||||
cmd, err := startTestProcess(name)
|
||||
if err != nil {
|
||||
t.Fatal("Starting test process:", err)
|
||||
@ -32,11 +38,18 @@ func WithTestProcess(name string, t *testing.T, fn testfunc) {
|
||||
if err != nil {
|
||||
t.Fatal("NewDebugProcess():", err)
|
||||
}
|
||||
defer cmd.Process.Kill()
|
||||
defer func() {
|
||||
cmd.Process.Kill()
|
||||
os.Remove(name)
|
||||
}()
|
||||
|
||||
fn(p)
|
||||
}
|
||||
|
||||
func CompileTestProg(source string) error {
|
||||
return exec.Command("go", "build", "-gcflags=-N -l", "-o", source, source+".go").Run()
|
||||
}
|
||||
|
||||
func startTestProcess(name string) (*exec.Cmd, error) {
|
||||
cmd := exec.Command(name)
|
||||
|
||||
|
||||
@ -13,14 +13,15 @@ import (
|
||||
)
|
||||
|
||||
func TestFindReturnAddress(t *testing.T) {
|
||||
var (
|
||||
testfile, _ = filepath.Abs("../../_fixtures/testnextprog")
|
||||
dbframe = dwarfhelper.GrabDebugFrameSection(testfile, t)
|
||||
fdes = frame.Parse(dbframe)
|
||||
gsd = dwarfhelper.GosymData(testfile, t)
|
||||
)
|
||||
var testfile, _ = filepath.Abs("../../_fixtures/testnextprog")
|
||||
|
||||
helper.WithTestProcess(testfile, t, func(p *proctl.DebuggedProcess) {
|
||||
var (
|
||||
dbframe = dwarfhelper.GrabDebugFrameSection(testfile, t)
|
||||
fdes = frame.Parse(dbframe)
|
||||
gsd = dwarfhelper.GosymData(testfile, t)
|
||||
)
|
||||
|
||||
testsourcefile := testfile + ".go"
|
||||
start, _, err := gsd.LineToPC(testsourcefile, 22)
|
||||
if err != nil {
|
||||
|
||||
@ -3,6 +3,7 @@ package line
|
||||
import (
|
||||
"debug/elf"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
@ -10,12 +11,7 @@ import (
|
||||
"github.com/davecheney/profile"
|
||||
)
|
||||
|
||||
func grabDebugLineSection(fp string, t *testing.T) []byte {
|
||||
p, err := filepath.Abs(fp)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
func grabDebugLineSection(p string, t *testing.T) []byte {
|
||||
f, err := os.Open(p)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -36,24 +32,24 @@ func grabDebugLineSection(fp string, t *testing.T) []byte {
|
||||
|
||||
func TestDebugLinePrologueParser(t *testing.T) {
|
||||
// Test against known good values, from readelf --debug-dump=rawline _fixtures/testnextprog
|
||||
var (
|
||||
data = grabDebugLineSection("../../_fixtures/testnextprog", t)
|
||||
dbl = Parse(data)
|
||||
prologue = dbl.Prologue
|
||||
)
|
||||
|
||||
if prologue.Length != uint32(60685) {
|
||||
t.Fatal("Length was not parsed correctly", prologue.Length)
|
||||
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)
|
||||
data := grabDebugLineSection(p, t)
|
||||
dbl := Parse(data)
|
||||
prologue := dbl.Prologue
|
||||
|
||||
if prologue.Version != uint16(2) {
|
||||
t.Fatal("Version not parsed correctly", prologue.Version)
|
||||
}
|
||||
|
||||
if prologue.PrologueLength != uint32(5363) {
|
||||
t.Fatal("Prologue Length not parsed correctly", prologue.PrologueLength)
|
||||
}
|
||||
|
||||
if prologue.MinInstrLength != uint8(1) {
|
||||
t.Fatal("Minimun Instruction Length not parsed correctly", prologue.MinInstrLength)
|
||||
}
|
||||
@ -85,10 +81,6 @@ func TestDebugLinePrologueParser(t *testing.T) {
|
||||
t.Fatal("Include dirs not parsed correctly")
|
||||
}
|
||||
|
||||
if len(dbl.FileNames) != 126 {
|
||||
t.Fatal("Filenames not parsed correctly", len(dbl.FileNames))
|
||||
}
|
||||
|
||||
if !strings.Contains(dbl.FileNames[0].Name, "/dbg/_fixtures/testnextprog.go") {
|
||||
t.Fatal("First entry not parsed correctly")
|
||||
}
|
||||
@ -96,7 +88,12 @@ func TestDebugLinePrologueParser(t *testing.T) {
|
||||
|
||||
func BenchmarkLineParser(b *testing.B) {
|
||||
defer profile.Start(profile.MemProfile).Stop()
|
||||
data := grabDebugLineSection("../../_fixtures/testnextprog", nil)
|
||||
p, err := filepath.Abs("../../_fixtures/testnextprog")
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
data := grabDebugLineSection(p, nil)
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package line
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
@ -14,8 +16,19 @@ func init() {
|
||||
}
|
||||
|
||||
func TestNextLocAfterPC(t *testing.T) {
|
||||
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)
|
||||
|
||||
var (
|
||||
data = grabDebugLineSection("../../_fixtures/testnextprog", t)
|
||||
data = grabDebugLineSection(p, t)
|
||||
dbl = Parse(data)
|
||||
gosym = dwarfhelper.GosymData(testfile, t)
|
||||
pc, _, _ = gosym.LineToPC(testfile+".go", 20)
|
||||
|
||||
Reference in New Issue
Block a user