]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: skip debug call injection tests under a debugger
authorAustin Clements <austin@google.com>
Mon, 27 Aug 2018 01:30:19 +0000 (21:30 -0400)
committerAustin Clements <austin@google.com>
Wed, 3 Oct 2018 20:32:28 +0000 (20:32 +0000)
The debug call injection tests will freeze when run under a debugger
because they depend on catching SIGTRAP, which is usually swallowed by
a debugger.

Change-Id: If6b86ca279b0489182990dd513444ca3062973f1
Reviewed-on: https://go-review.googlesource.com/c/139437
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/runtime/debug_test.go

index a34f4c77f7cbedd4a95e0827c02a0ecea8f0844c..37dcafd145ea68df01634abb9a75a06aba698e8b 100644 (file)
@@ -17,6 +17,8 @@ package runtime_test
 
 import (
        "fmt"
+       "io/ioutil"
+       "regexp"
        "runtime"
        "runtime/debug"
        "sync/atomic"
@@ -25,6 +27,11 @@ import (
 )
 
 func startDebugCallWorker(t *testing.T) (g *runtime.G, after func()) {
+       // This can deadlock if run under a debugger because it
+       // depends on catching SIGTRAP, which is usually swallowed by
+       // a debugger.
+       skipUnderDebugger(t)
+
        // This can deadlock if there aren't enough threads or if a GC
        // tries to interrupt an atomic loop (see issue #10958).
        ogomaxprocs := runtime.GOMAXPROCS(2)
@@ -73,6 +80,28 @@ func debugCallTKill(tid int) error {
        return syscall.Tgkill(syscall.Getpid(), tid, syscall.SIGTRAP)
 }
 
+// skipUnderDebugger skips the current test when running under a
+// debugger (specifically if this process has a tracer). This is
+// Linux-specific.
+func skipUnderDebugger(t *testing.T) {
+       pid := syscall.Getpid()
+       status, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/status", pid))
+       if err != nil {
+               t.Logf("couldn't get proc tracer: %s", err)
+               return
+       }
+       re := regexp.MustCompile(`TracerPid:\s+([0-9]+)`)
+       sub := re.FindSubmatch(status)
+       if sub == nil {
+               t.Logf("couldn't find proc tracer PID")
+               return
+       }
+       if string(sub[1]) == "0" {
+               return
+       }
+       t.Skip("test will deadlock under a debugger")
+}
+
 func TestDebugCall(t *testing.T) {
        g, after := startDebugCallWorker(t)
        defer after()
@@ -160,6 +189,8 @@ func debugCallUnsafePointWorker(gpp **runtime.G, ready, stop *uint32) {
 }
 
 func TestDebugCallUnsafePoint(t *testing.T) {
+       skipUnderDebugger(t)
+
        // This can deadlock if there aren't enough threads or if a GC
        // tries to interrupt an atomic loop (see issue #10958).
        defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(2))
@@ -181,6 +212,8 @@ func TestDebugCallUnsafePoint(t *testing.T) {
 }
 
 func TestDebugCallPanic(t *testing.T) {
+       skipUnderDebugger(t)
+
        // This can deadlock if there aren't enough threads.
        defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(2))