mirror of
https://github.com/go-delve/delve.git
synced 2025-10-28 04:35:19 +08:00
Fix various issues detected by megacheck (#880)
* Fix various issues detected by megacheck I've ran honnef.co/go/tools/cmd/megacheck and fixed a few of the things that came up there. * Cleanup using Gogland
This commit is contained in:
committed by
Derek Parker
parent
a19bca2298
commit
32a005de2b
@ -3,6 +3,7 @@
|
||||
package proc_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"syscall"
|
||||
"testing"
|
||||
@ -12,6 +13,15 @@ import (
|
||||
protest "github.com/derekparker/delve/pkg/proc/test"
|
||||
)
|
||||
|
||||
type errIssue419 struct {
|
||||
pid int
|
||||
err error
|
||||
}
|
||||
|
||||
func (npe errIssue419) Error() string {
|
||||
return fmt.Sprintf("Pid is zero or negative: %d", npe.pid)
|
||||
}
|
||||
|
||||
func TestIssue419(t *testing.T) {
|
||||
if testBackend == "lldb" && runtime.GOOS == "darwin" {
|
||||
// debugserver bug?
|
||||
@ -20,29 +30,43 @@ func TestIssue419(t *testing.T) {
|
||||
if testBackend == "rr" {
|
||||
return
|
||||
}
|
||||
|
||||
errChan := make(chan error, 2)
|
||||
|
||||
// SIGINT directed at the inferior should be passed along not swallowed by delve
|
||||
withTestProcess("issue419", t, func(p proc.Process, fixture protest.Fixture) {
|
||||
defer close(errChan)
|
||||
_, err := setFunctionBreakpoint(p, "main.main")
|
||||
assertNoError(err, t, "SetBreakpoint()")
|
||||
assertNoError(proc.Continue(p), t, "Continue()")
|
||||
resumeChan := make(chan struct{})
|
||||
resumeChan := make(chan struct{}, 1)
|
||||
go func() {
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
<-resumeChan
|
||||
if p.Pid() <= 0 {
|
||||
// if we don't stop the inferior the test will never finish
|
||||
p.RequestManualStop()
|
||||
p.Kill()
|
||||
t.Fatalf("Pid is zero or negative: %d", p.Pid())
|
||||
err := p.Kill()
|
||||
errChan <- errIssue419{pid: p.Pid(), err: err}
|
||||
return
|
||||
}
|
||||
err := syscall.Kill(p.Pid(), syscall.SIGINT)
|
||||
assertNoError(err, t, "syscall.Kill")
|
||||
errChan <- errIssue419{pid: p.Pid(), err: err}
|
||||
}()
|
||||
p.ResumeNotify(resumeChan)
|
||||
err = proc.Continue(p)
|
||||
errChan <- proc.Continue(p)
|
||||
})
|
||||
|
||||
for i :=0; i<2; i++ {
|
||||
err := <-errChan
|
||||
|
||||
if v, ok := err.(errIssue419); ok {
|
||||
assertNoError(v.err, t, "syscall.Kill")
|
||||
continue
|
||||
}
|
||||
|
||||
if _, exited := err.(proc.ProcessExitedError); !exited {
|
||||
t.Fatalf("Unexpected error after Continue(): %v\n", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user