delve/pkg/proc/proc_unix_test.go
aarzilli 16d8bd647f proc/*: remove Process.Running
Implementing proc.Process.Running in a thread safe way is complicated
and nothing actually uses it besides tests, so we are better off
rewriting the tests without Running and removing it.

In particular:

* The call to d.target.Running() in service/debugger/debugger.go
  (Restart) can never return true because that line executes while
  holding processMutex and all continue operations are also executed
  while holding processMutex.
* The call to dbp.Running() pkg/proc/native/proc.go (Detach) can never
  return true, because it's only called from
  debugger.(*Debugger).detach() which is also always called while
  holding processMutex.

Since some tests are hard to write correctly without Process.Running a
simpler interface, Process.NotifyResumed, is introduced.

Fixes #830
2017-06-13 08:53:54 +02:00

49 lines
1.2 KiB
Go

// +build linux darwin
package proc_test
import (
"runtime"
"syscall"
"testing"
"time"
"github.com/derekparker/delve/pkg/proc"
protest "github.com/derekparker/delve/pkg/proc/test"
)
func TestIssue419(t *testing.T) {
if testBackend == "lldb" && runtime.GOOS == "darwin" {
// debugserver bug?
return
}
if testBackend == "rr" {
return
}
// SIGINT directed at the inferior should be passed along not swallowed by delve
withTestProcess("issue419", t, func(p proc.Process, fixture protest.Fixture) {
_, err := setFunctionBreakpoint(p, "main.main")
assertNoError(err, t, "SetBreakpoint()")
assertNoError(proc.Continue(p), t, "Continue()")
resumeChan := make(chan struct{})
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())
return
}
err := syscall.Kill(p.Pid(), syscall.SIGINT)
assertNoError(err, t, "syscall.Kill")
}()
p.ResumeNotify(resumeChan)
err = proc.Continue(p)
if _, exited := err.(proc.ProcessExitedError); !exited {
t.Fatalf("Unexpected error after Continue(): %v\n", err)
}
})
}