提交 948f83a1 编写于 作者: D Derek Parker

Ensure we lock OS thread in test

上级 8fb5e164
...@@ -3,6 +3,7 @@ package proctl ...@@ -3,6 +3,7 @@ package proctl
import ( import (
"bytes" "bytes"
"os/exec" "os/exec"
"runtime"
"syscall" "syscall"
"testing" "testing"
) )
...@@ -29,7 +30,8 @@ func getRegisters(p *DebuggedProcess, t *testing.T) *syscall.PtraceRegs { ...@@ -29,7 +30,8 @@ func getRegisters(p *DebuggedProcess, t *testing.T) *syscall.PtraceRegs {
} }
func withTestProcess(name string, t *testing.T, fn testfunc) { func withTestProcess(name string, t *testing.T, fn testfunc) {
cmd, err := StartTestProcess(name) runtime.LockOSThread()
cmd, err := startTestProcess(name)
if err != nil { if err != nil {
t.Fatal("Starting test process:", err) t.Fatal("Starting test process:", err)
} }
...@@ -44,7 +46,7 @@ func withTestProcess(name string, t *testing.T, fn testfunc) { ...@@ -44,7 +46,7 @@ func withTestProcess(name string, t *testing.T, fn testfunc) {
fn(p) fn(p)
} }
func StartTestProcess(name string) (*exec.Cmd, error) { func startTestProcess(name string) (*exec.Cmd, error) {
cmd := exec.Command("../_fixtures/" + name) cmd := exec.Command("../_fixtures/" + name)
err := cmd.Start() err := cmd.Start()
...@@ -65,6 +67,10 @@ func TestAttachProcess(t *testing.T) { ...@@ -65,6 +67,10 @@ func TestAttachProcess(t *testing.T) {
func TestStep(t *testing.T) { func TestStep(t *testing.T) {
withTestProcess("testprog", t, func(p *DebuggedProcess) { withTestProcess("testprog", t, func(p *DebuggedProcess) {
if p.ProcessState.Exited() {
t.Fatal("Process already exited")
}
regs := getRegisters(p, t) regs := getRegisters(p, t)
rip := regs.PC() rip := regs.PC()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册