mirror of
https://github.com/go-delve/delve.git
synced 2025-10-27 03:56:24 +08:00
*: fix various test problems with go1.25 (#3946)
- disable dwz test if it fails because of dwarf5 - fix TestExamineMemoryCmd, which made unwarranted assumptions about memory
This commit is contained in:
committed by
GitHub
parent
fc6a439f22
commit
486574cb65
@ -770,7 +770,7 @@ func TestRemoteDAPClientAfterContinue(t *testing.T) {
|
||||
|
||||
dlvbin := protest.GetDlvBinary(t)
|
||||
|
||||
fixture := protest.BuildFixture("loopprog", 0)
|
||||
fixture := protest.BuildFixture(t, "loopprog", 0)
|
||||
cmd := exec.Command(dlvbin, "exec", fixture.Path, "--headless", "--continue", "--accept-multiclient", "--log-output=debugger,dap", "--log", "--listen", listenAddr)
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
assertNoError(err, t, "stdout pipe")
|
||||
@ -1035,7 +1035,7 @@ func TestTracePid(t *testing.T) {
|
||||
expected := []byte("goroutine(1): main.A()\n>> goroutine(1): main.A => ()\n")
|
||||
|
||||
// make process run
|
||||
fix := protest.BuildFixture("issue2023", 0)
|
||||
fix := protest.BuildFixture(t, "issue2023", 0)
|
||||
targetCmd := exec.Command(fix.Path)
|
||||
assertNoError(targetCmd.Start(), t, "execute issue2023")
|
||||
|
||||
|
||||
@ -122,7 +122,7 @@ func testDebugLinePrologueParser(p string, t *testing.T) {
|
||||
}
|
||||
|
||||
for _, ln := range dbl.Lookup {
|
||||
if ln.Path == "<autogenerated>" || strings.HasPrefix(ln.Path, "<missing>_") || ln.Path == "_gomod_.go" {
|
||||
if ln.Path == "<autogenerated>" || ln.Path == "?" || strings.HasPrefix(ln.Path, "<missing>_") || ln.Path == "_gomod_.go" {
|
||||
continue
|
||||
}
|
||||
if _, err := os.Stat(ln.Path); err != nil {
|
||||
|
||||
@ -205,7 +205,7 @@ func withCoreFile(t *testing.T, name, args string) *proc.TargetGroup {
|
||||
if buildMode == "pie" {
|
||||
buildFlags = test.BuildModePIE
|
||||
}
|
||||
fix := test.BuildFixture(name, buildFlags)
|
||||
fix := test.BuildFixture(t, name, buildFlags)
|
||||
bashCmd := fmt.Sprintf("cd %v && ulimit -c unlimited && GOTRACEBACK=crash %v %s", tempDir, fix.Path, args)
|
||||
exec.Command("bash", "-c", bashCmd).Run()
|
||||
cores, err := filepath.Glob(path.Join(tempDir, "core*"))
|
||||
@ -464,7 +464,7 @@ func TestMinidump(t *testing.T) {
|
||||
if buildMode == "pie" {
|
||||
buildFlags = test.BuildModePIE
|
||||
}
|
||||
fix := test.BuildFixture("sleep", buildFlags)
|
||||
fix := test.BuildFixture(t, "sleep", buildFlags)
|
||||
mdmpPath := procdump(t, fix.Path)
|
||||
|
||||
grp, err := OpenCore(mdmpPath, fix.Path, []string{})
|
||||
|
||||
@ -24,7 +24,7 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
func withTestRecording(name string, t testing.TB, fn func(grp *proc.TargetGroup, fixture protest.Fixture)) {
|
||||
fixture := protest.BuildFixture(name, 0)
|
||||
fixture := protest.BuildFixture(t, name, 0)
|
||||
protest.MustHaveRecordingAllowed(t)
|
||||
if path, _ := exec.LookPath("rr"); path == "" {
|
||||
t.Skip("test skipped, rr not found")
|
||||
|
||||
@ -130,7 +130,7 @@ func assertNoError(err error, t testing.TB, s string) {
|
||||
|
||||
func TestDwarfVersion(t *testing.T) {
|
||||
// Tests that we correctly read the version of compilation units
|
||||
fixture := protest.BuildFixture("math", 0)
|
||||
fixture := protest.BuildFixture(t, "math", 0)
|
||||
bi := NewBinaryInfo(runtime.GOOS, runtime.GOARCH)
|
||||
// Use a fake entry point so LoadBinaryInfo does not error in case the binary is PIE.
|
||||
const fakeEntryPoint = 1
|
||||
@ -147,7 +147,7 @@ func TestRegabiFlagSentinel(t *testing.T) {
|
||||
if !protest.RegabiSupported() {
|
||||
t.Skip("irrelevant before Go 1.17 or on non-amd64 architectures")
|
||||
}
|
||||
fixture := protest.BuildFixture("math", 0)
|
||||
fixture := protest.BuildFixture(t, "math", 0)
|
||||
bi := NewBinaryInfo(runtime.GOOS, runtime.GOARCH)
|
||||
// Use a fake entry point so LoadBinaryInfo does not error in case the binary is PIE.
|
||||
const fakeEntryPoint = 1
|
||||
|
||||
@ -23,7 +23,7 @@ func mustHaveObjcopy(t *testing.T) {
|
||||
|
||||
func TestLoadingExternalDebugInfo(t *testing.T) {
|
||||
mustHaveObjcopy(t)
|
||||
fixture := protest.BuildFixture("locationsprog", 0)
|
||||
fixture := protest.BuildFixture(t, "locationsprog", 0)
|
||||
defer os.Remove(fixture.Path)
|
||||
stripAndCopyDebugInfo(fixture, t)
|
||||
p, err := native.Launch(append([]string{fixture.Path}, ""), "", 0, []string{filepath.Dir(fixture.Path)}, "", "", proc.OutputRedirect{}, proc.OutputRedirect{})
|
||||
@ -36,7 +36,7 @@ func TestLoadingExternalDebugInfo(t *testing.T) {
|
||||
func TestGnuDebuglink(t *testing.T) {
|
||||
mustHaveObjcopy(t)
|
||||
// build math.go and make a copy of the executable
|
||||
fixture := protest.BuildFixture("math", 0)
|
||||
fixture := protest.BuildFixture(t, "math", 0)
|
||||
buf, err := os.ReadFile(fixture.Path)
|
||||
assertNoError(err, t, "ReadFile")
|
||||
debuglinkPath := fixture.Path + "-gnu_debuglink"
|
||||
|
||||
@ -94,10 +94,11 @@ func withTestProcess(name string, t testing.TB, fn func(p *proc.Target, grp *pro
|
||||
}
|
||||
|
||||
func withTestProcessArgs(name string, t testing.TB, wd string, args []string, buildFlags protest.BuildFlags, fn func(p *proc.Target, grp *proc.TargetGroup, fixture protest.Fixture)) {
|
||||
t.Helper()
|
||||
if buildMode == "pie" {
|
||||
buildFlags |= protest.BuildModePIE
|
||||
}
|
||||
fixture := protest.BuildFixture(name, buildFlags)
|
||||
fixture := protest.BuildFixture(t, name, buildFlags)
|
||||
|
||||
grp := startTestProcessArgs(fixture, t, wd, args)
|
||||
|
||||
@ -2487,7 +2488,7 @@ func TestAttachDetach(t *testing.T) {
|
||||
if buildMode == "pie" {
|
||||
buildFlags |= protest.BuildModePIE
|
||||
}
|
||||
fixture := protest.BuildFixture("testnextnethttp", buildFlags)
|
||||
fixture := protest.BuildFixture(t, "testnextnethttp", buildFlags)
|
||||
cmd := exec.Command(fixture.Path)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
@ -4498,7 +4499,7 @@ func TestIssue2319(t *testing.T) {
|
||||
t.Skip("test contains fixture that is specific to go 1.14+")
|
||||
}
|
||||
|
||||
fixture := protest.BuildFixture("issue2319/", protest.BuildModeExternalLinker)
|
||||
fixture := protest.BuildFixture(t, "issue2319/", protest.BuildModeExternalLinker)
|
||||
|
||||
// Load up the binary and make sure there are no crashes.
|
||||
bi := proc.NewBinaryInfo("linux", "amd64")
|
||||
@ -5361,7 +5362,7 @@ func testWaitForSetup(t *testing.T, mu *sync.Mutex, started *bool) (*exec.Cmd, *
|
||||
if buildMode == "pie" {
|
||||
buildFlags |= protest.BuildModePIE
|
||||
}
|
||||
fixture := protest.BuildFixture("loopprog", buildFlags)
|
||||
fixture := protest.BuildFixture(t, "loopprog", buildFlags)
|
||||
|
||||
cmd := exec.Command(fixture.Path)
|
||||
|
||||
|
||||
@ -80,7 +80,7 @@ func TestSignalDeath(t *testing.T) {
|
||||
if buildMode == "pie" {
|
||||
buildFlags |= protest.BuildModePIE
|
||||
}
|
||||
fixture := protest.BuildFixture("loopprog", buildFlags)
|
||||
fixture := protest.BuildFixture(t, "loopprog", buildFlags)
|
||||
cmd := exec.Command(fixture.Path)
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
assertNoError(err, t, "StdoutPipe")
|
||||
|
||||
@ -96,7 +96,8 @@ func TempFile(name string) string {
|
||||
}
|
||||
|
||||
// BuildFixture will compile the fixture 'name' using the provided build flags.
|
||||
func BuildFixture(name string, flags BuildFlags) Fixture {
|
||||
func BuildFixture(t testing.TB, name string, flags BuildFlags) Fixture {
|
||||
t.Helper()
|
||||
if !runningWithFixtures {
|
||||
panic("RunTestsWithFixtures not called")
|
||||
}
|
||||
@ -189,10 +190,12 @@ func BuildFixture(name string, flags BuildFlags) Fixture {
|
||||
if flags&EnableDWZCompression != 0 {
|
||||
cmd := exec.Command("dwz", tmpfile)
|
||||
if out, err := cmd.CombinedOutput(); err != nil {
|
||||
if strings.Contains(string(out), "Unknown debugging section .debug_addr") {
|
||||
t.Skip("can not run dwz")
|
||||
return Fixture{}
|
||||
}
|
||||
if regexp.MustCompile(`dwz: Section offsets in (.*?) not monotonically increasing`).FindString(string(out)) == "" {
|
||||
fmt.Printf("Error running dwz on %s: %s\n", tmpfile, err)
|
||||
fmt.Printf("%s\n", string(out))
|
||||
os.Exit(1)
|
||||
t.Fatalf("Error running dwz on %s: %s\n%s\n", tmpfile, err, string(out))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -365,7 +368,7 @@ func WithPlugins(t *testing.T, flags BuildFlags, plugins ...string) []Fixture {
|
||||
|
||||
r := make([]Fixture, len(plugins))
|
||||
for i := range plugins {
|
||||
r[i] = BuildFixture(plugins[i], flags|BuildModePlugin)
|
||||
r[i] = BuildFixture(t, plugins[i], flags|BuildModePlugin)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
@ -132,7 +132,7 @@ func withTestTerminalBuildFlags(name string, t testing.TB, buildFlags test.Build
|
||||
}
|
||||
server := rpccommon.NewServer(&service.Config{
|
||||
Listener: listener,
|
||||
ProcessArgs: []string{test.BuildFixture(name, buildFlags).Path},
|
||||
ProcessArgs: []string{test.BuildFixture(t, name, buildFlags).Path},
|
||||
Debugger: debugger.Config{
|
||||
Backend: testBackend,
|
||||
},
|
||||
@ -1023,7 +1023,7 @@ func TestExamineMemoryCmd(t *testing.T) {
|
||||
t.Fatalf("could convert %s into int64, err %s", addressStr, err)
|
||||
}
|
||||
|
||||
res := term.MustExec("examinemem -count 52 -fmt hex " + addressStr)
|
||||
res := term.MustExec("examinemem -count 51 -fmt hex " + addressStr)
|
||||
t.Logf("the result of examining memory \n%s", res)
|
||||
// check first line
|
||||
firstLine := fmt.Sprintf("%#x: 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f 0x10 0x11", address)
|
||||
@ -1032,7 +1032,7 @@ func TestExamineMemoryCmd(t *testing.T) {
|
||||
}
|
||||
|
||||
// check last line
|
||||
lastLine := fmt.Sprintf("%#x: 0x3a 0x3b 0x3c 0x00", address+6*8)
|
||||
lastLine := fmt.Sprintf("%#x: 0x3a 0x3b 0x3c", address+6*8)
|
||||
if !strings.Contains(res, lastLine) {
|
||||
t.Fatalf("expected last line: %s", lastLine)
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ func runTest(t *testing.T, name string, test func(c *daptest.Client, f protest.F
|
||||
|
||||
// name is for _fixtures/<name>.go
|
||||
func runTestBuildFlags(t *testing.T, name string, test func(c *daptest.Client, f protest.Fixture), buildFlags protest.BuildFlags, defaultDebugInfoDirs bool) {
|
||||
fixture := protest.BuildFixture(name, buildFlags)
|
||||
fixture := protest.BuildFixture(t, name, buildFlags)
|
||||
|
||||
// Start the DAP server.
|
||||
serverStopped := make(chan struct{})
|
||||
@ -216,7 +216,7 @@ func TestStopWithTarget(t *testing.T) {
|
||||
|
||||
client.InitializeRequest()
|
||||
client.ExpectInitializeResponseAndCapabilities(t)
|
||||
fixture := protest.BuildFixture("increment", protest.AllNonOptimized)
|
||||
fixture := protest.BuildFixture(t, "increment", protest.AllNonOptimized)
|
||||
client.LaunchRequest("debug", fixture.Source, stopOnEntry)
|
||||
client.ExpectProcessEvent(t)
|
||||
client.ExpectInitializedEvent(t)
|
||||
@ -303,7 +303,7 @@ func TestSessionStop(t *testing.T) {
|
||||
time.Sleep(10 * time.Millisecond) // give time to start reading
|
||||
client.InitializeRequest()
|
||||
client.ExpectInitializeResponseAndCapabilities(t)
|
||||
fixture := protest.BuildFixture("increment", protest.AllNonOptimized)
|
||||
fixture := protest.BuildFixture(t, "increment", protest.AllNonOptimized)
|
||||
client.LaunchRequest("debug", fixture.Source, stopOnEntry)
|
||||
client.ExpectProcessEvent(t)
|
||||
client.ExpectInitializedEvent(t)
|
||||
@ -321,7 +321,7 @@ func TestForceStopWhileStopping(t *testing.T) {
|
||||
|
||||
client.InitializeRequest()
|
||||
client.ExpectInitializeResponseAndCapabilities(t)
|
||||
fixture := protest.BuildFixture("increment", protest.AllNonOptimized)
|
||||
fixture := protest.BuildFixture(t, "increment", protest.AllNonOptimized)
|
||||
client.LaunchRequest("exec", fixture.Path, stopOnEntry)
|
||||
client.ExpectProcessEvent(t)
|
||||
client.ExpectInitializedEvent(t)
|
||||
@ -6771,7 +6771,7 @@ func launchDebuggerWithTargetRunning(t *testing.T, fixture string) (*protest.Fix
|
||||
|
||||
func launchDebuggerWithTargetHalted(t *testing.T, fixture string) (*protest.Fixture, *debugger.Debugger) {
|
||||
t.Helper()
|
||||
fixbin := protest.BuildFixture(fixture, protest.AllNonOptimized)
|
||||
fixbin := protest.BuildFixture(t, fixture, protest.AllNonOptimized)
|
||||
cfg := service.Config{
|
||||
ProcessArgs: []string{fixbin.Path},
|
||||
Debugger: debugger.Config{Backend: "default"},
|
||||
@ -6785,7 +6785,7 @@ func launchDebuggerWithTargetHalted(t *testing.T, fixture string) (*protest.Fixt
|
||||
|
||||
func attachDebuggerWithTargetHalted(t *testing.T, fixture string) (*exec.Cmd, *debugger.Debugger) {
|
||||
t.Helper()
|
||||
fixbin := protest.BuildFixture(fixture, protest.AllNonOptimized)
|
||||
fixbin := protest.BuildFixture(t, fixture, protest.AllNonOptimized)
|
||||
cmd := execFixture(t, fixbin)
|
||||
cfg := service.Config{Debugger: debugger.Config{Backend: "default", AttachPid: cmd.Process.Pid}}
|
||||
dbg, err := debugger.New(&cfg.Debugger, nil) // debugger halts process on entry
|
||||
|
||||
@ -69,7 +69,7 @@ func startServer(name string, buildFlags protest.BuildFlags, t *testing.T, redir
|
||||
if buildMode == "pie" {
|
||||
buildFlags |= protest.BuildModePIE
|
||||
}
|
||||
fixture = protest.BuildFixture(name, buildFlags)
|
||||
fixture = protest.BuildFixture(t, name, buildFlags)
|
||||
for i := range redirects {
|
||||
if redirects[i] != "" {
|
||||
redirects[i] = filepath.Join(fixture.BuildDir, redirects[i])
|
||||
@ -2067,7 +2067,7 @@ func TestAcceptMulticlient(t *testing.T) {
|
||||
disconnectChan := make(chan struct{})
|
||||
server := rpccommon.NewServer(&service.Config{
|
||||
Listener: listener,
|
||||
ProcessArgs: []string{protest.BuildFixture("testvariables2", 0).Path},
|
||||
ProcessArgs: []string{protest.BuildFixture(t, "testvariables2", 0).Path},
|
||||
AcceptMulti: true,
|
||||
DisconnectChan: disconnectChan,
|
||||
Debugger: debugger.Config{
|
||||
@ -2105,7 +2105,7 @@ func TestForceStopWhileContinue(t *testing.T) {
|
||||
defer listener.Close()
|
||||
server := rpccommon.NewServer(&service.Config{
|
||||
Listener: listener,
|
||||
ProcessArgs: []string{protest.BuildFixture("http_server", protest.AllNonOptimized).Path},
|
||||
ProcessArgs: []string{protest.BuildFixture(t, "http_server", protest.AllNonOptimized).Path},
|
||||
AcceptMulti: true,
|
||||
DisconnectChan: disconnectChan,
|
||||
Debugger: debugger.Config{
|
||||
@ -2493,7 +2493,7 @@ func TestDetachLeaveRunning(t *testing.T) {
|
||||
if buildMode == "pie" {
|
||||
buildFlags |= protest.BuildModePIE
|
||||
}
|
||||
fixture := protest.BuildFixture("testnextnethttp", buildFlags)
|
||||
fixture := protest.BuildFixture(t, "testnextnethttp", buildFlags)
|
||||
|
||||
cmd := exec.Command(fixture.Path)
|
||||
cmd.Stdout = os.Stdout
|
||||
@ -2572,7 +2572,7 @@ func TestStopServerWithClosedListener(t *testing.T) {
|
||||
}
|
||||
listener, err := net.Listen("tcp", "localhost:0")
|
||||
assertNoError(err, t, "listener")
|
||||
fixture := protest.BuildFixture("math", 0)
|
||||
fixture := protest.BuildFixture(t, "math", 0)
|
||||
server := rpccommon.NewServer(&service.Config{
|
||||
Listener: listener,
|
||||
AcceptMulti: false,
|
||||
|
||||
Reference in New Issue
Block a user