From 486574cb65239d123df7fc391fc582570a54100d Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Thu, 13 Mar 2025 18:57:11 +0100 Subject: [PATCH] *: 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 --- cmd/dlv/dlv_test.go | 4 ++-- pkg/dwarf/line/line_parser_test.go | 2 +- pkg/proc/core/core_test.go | 4 ++-- pkg/proc/gdbserial/rr_test.go | 2 +- pkg/proc/proc_general_test.go | 4 ++-- pkg/proc/proc_linux_test.go | 4 ++-- pkg/proc/proc_test.go | 9 +++++---- pkg/proc/proc_unix_test.go | 2 +- pkg/proc/test/support.go | 13 ++++++++----- pkg/terminal/command_test.go | 6 +++--- service/dap/server_test.go | 12 ++++++------ service/test/integration2_test.go | 10 +++++----- 12 files changed, 38 insertions(+), 34 deletions(-) diff --git a/cmd/dlv/dlv_test.go b/cmd/dlv/dlv_test.go index 06e8e0b7..16b2d337 100644 --- a/cmd/dlv/dlv_test.go +++ b/cmd/dlv/dlv_test.go @@ -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") diff --git a/pkg/dwarf/line/line_parser_test.go b/pkg/dwarf/line/line_parser_test.go index 6f5bfd7b..022f3ff0 100644 --- a/pkg/dwarf/line/line_parser_test.go +++ b/pkg/dwarf/line/line_parser_test.go @@ -122,7 +122,7 @@ func testDebugLinePrologueParser(p string, t *testing.T) { } for _, ln := range dbl.Lookup { - if ln.Path == "" || strings.HasPrefix(ln.Path, "_") || ln.Path == "_gomod_.go" { + if ln.Path == "" || ln.Path == "?" || strings.HasPrefix(ln.Path, "_") || ln.Path == "_gomod_.go" { continue } if _, err := os.Stat(ln.Path); err != nil { diff --git a/pkg/proc/core/core_test.go b/pkg/proc/core/core_test.go index cebac8ac..dddc1d3e 100644 --- a/pkg/proc/core/core_test.go +++ b/pkg/proc/core/core_test.go @@ -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{}) diff --git a/pkg/proc/gdbserial/rr_test.go b/pkg/proc/gdbserial/rr_test.go index e6206652..3dc3d1e2 100644 --- a/pkg/proc/gdbserial/rr_test.go +++ b/pkg/proc/gdbserial/rr_test.go @@ -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") diff --git a/pkg/proc/proc_general_test.go b/pkg/proc/proc_general_test.go index dfa040a9..86e5b2de 100644 --- a/pkg/proc/proc_general_test.go +++ b/pkg/proc/proc_general_test.go @@ -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 diff --git a/pkg/proc/proc_linux_test.go b/pkg/proc/proc_linux_test.go index a86c7bf5..f654a334 100644 --- a/pkg/proc/proc_linux_test.go +++ b/pkg/proc/proc_linux_test.go @@ -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" diff --git a/pkg/proc/proc_test.go b/pkg/proc/proc_test.go index 9d65896b..9ecfec7e 100644 --- a/pkg/proc/proc_test.go +++ b/pkg/proc/proc_test.go @@ -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) diff --git a/pkg/proc/proc_unix_test.go b/pkg/proc/proc_unix_test.go index db3d1094..c7660d36 100644 --- a/pkg/proc/proc_unix_test.go +++ b/pkg/proc/proc_unix_test.go @@ -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") diff --git a/pkg/proc/test/support.go b/pkg/proc/test/support.go index 6312cfc6..d1f25bd4 100644 --- a/pkg/proc/test/support.go +++ b/pkg/proc/test/support.go @@ -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 } diff --git a/pkg/terminal/command_test.go b/pkg/terminal/command_test.go index 3dde9987..a426c02c 100644 --- a/pkg/terminal/command_test.go +++ b/pkg/terminal/command_test.go @@ -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) } diff --git a/service/dap/server_test.go b/service/dap/server_test.go index 079fa888..f16bf043 100644 --- a/service/dap/server_test.go +++ b/service/dap/server_test.go @@ -64,7 +64,7 @@ func runTest(t *testing.T, name string, test func(c *daptest.Client, f protest.F // name is for _fixtures/.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 diff --git a/service/test/integration2_test.go b/service/test/integration2_test.go index 2b972bf7..30ea5440 100644 --- a/service/test/integration2_test.go +++ b/service/test/integration2_test.go @@ -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,