Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dlv_test: fix TestChildProcessExitWhenNoDebugInfo to test stripped binary #2949

Merged

Conversation

polinasok
Copy link
Collaborator

Following up on discussion here: #2018 (comment)
The test was bailing out early before actually trying to debug a stripped binary at this check:

if !headless && !allowNonTerminalInteractive {
for _, f := range []struct {
name string
file *os.File
}{{"Stdin", os.Stdin}, {"Stdout", os.Stdout}, {"Stderr", os.Stderr}} {
if f.file == nil {
continue
}
if !isatty.IsTerminal(f.file.Fd()) {
fmt.Fprintf(os.Stderr, "%s is not a terminal, use '-r' to specify redirects for the target process or --allow-non-terminal-interactive=true if you really want to specify a redirect for Delve\n", f.name)
return 1
}

Modified the flags and added logging and more checks to make sure the session exits for the right reasons.

$ go test -run ^TestChildProcessExitWhenNoDebugInfo$ -v
=== RUN   TestChildProcessExitWhenNoDebugInfo
    dlv_test.go:272: time="2022-03-29T06:17:06Z" level=warning msg="CGO_CFLAGS already set, Cgo code could be optimized." layer=dlv
        2022-03-29T06:17:06Z info layer=debugger launching process with args: [/tmp/http_server.b8c49b54]
        could not launch process: could not open debug info
...

// Test only for dlv's prefix of the error like "could not launch process: could not open debug info"
if !strings.Contains(string(out), "could not launch process") {
t.Fatalf("Expected logged error 'could not launch process: ...'")
}

// search the running process named fix.Name
cmd := exec.Command("ps", "-aux")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this part designed to test that a process won't leak after the debug command exits?
Technically, when process leaks, the debugger leaks with it and the test will times out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember, I think it didn't hang when the process leaks on linux.

// Test only for dlv's prefix of the error like "could not launch process: could not open debug info"
if !strings.Contains(string(out), "could not launch process") {
t.Fatalf("Expected logged error 'could not launch process: ...'")
}

// search the running process named fix.Name
cmd := exec.Command("ps", "-aux")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember, I think it didn't hang when the process leaks on linux.

Copy link
Member

@derekparker derekparker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@derekparker
Copy link
Member

Re-running CI real quick.

@derekparker derekparker merged commit 65e03d6 into go-delve:master Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants