]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: drop cgoTraceback call assumptions from CgoPprof tests
authorMichael Pratt <mpratt@google.com>
Fri, 12 Nov 2021 16:16:43 +0000 (11:16 -0500)
committerMichael Pratt <mpratt@google.com>
Fri, 12 Nov 2021 19:45:58 +0000 (19:45 +0000)
the CgoPprof tests currently assume that calls to their cgoTraceback
functions are primarily for generating pprof samples and exit early
after receiving two calls.

This is a fragile assumption, as cgoTraceback will be called for _any_
signal received, hence why the test already looks for 2 calls instead of
1.

Still, this has caused flaky failures in two cases:

* #37201, where async preemption signals add additional probability of
receiving non-profiling signals. This was resolved by disabling async
preemption.

* #49401, where some ITIMER_PROF SIGPROF signals are ignored in favor of
per-thread SIGPROF signals.

Rather than attempting to keep plugging holes, this CL drops the fragile
assumption from these tests. Now they simply unconditionally run for the
full 1s before exiting.

Fixes #49401

Change-Id: I16dc9d2f16c2fb511e9db93dd096a402121f86ac
Reviewed-on: https://go-review.googlesource.com/c/go/+/363634
Trust: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Rhys Hiltner <rhys@justin.tv>
src/runtime/crash_cgo_test.go
src/runtime/testdata/testprogcgo/pprof.go
src/runtime/testdata/testprogcgo/threadpprof.go

index 58c340f8ad3028fd2269fbba9e87ef2675e03566..9a174fa5497115d29b68048e5ddf51fdaa4f3237 100644 (file)
@@ -302,12 +302,7 @@ func testCgoPprof(t *testing.T, buildArg, runArg, top, bottom string) {
                t.Fatal(err)
        }
 
-       // pprofCgoTraceback is called whenever CGO code is executing and a signal
-       // is received. Disable signal preemption to increase the likelihood at
-       // least one SIGPROF signal fired to capture a sample. See issue #37201.
        cmd := testenv.CleanCmdEnv(exec.Command(exe, runArg))
-       cmd.Env = append(cmd.Env, "GODEBUG=asyncpreemptoff=1")
-
        got, err := cmd.CombinedOutput()
        if err != nil {
                if testenv.Builder() == "linux-amd64-alpine" {
index 3b73fa0bdd9d8a9728794e39f3daaccad3e13476..8870d0c415745186a3935b1b598e91fb82203722 100644 (file)
@@ -29,8 +29,6 @@ void cpuHog() {
 void cpuHog2() {
 }
 
-static int cpuHogCount;
-
 struct cgoTracebackArg {
        uintptr_t  context;
        uintptr_t  sigContext;
@@ -47,13 +45,6 @@ void pprofCgoTraceback(void* parg) {
        arg->buf[0] = (uintptr_t)(cpuHog) + 0x10;
        arg->buf[1] = (uintptr_t)(cpuHog2) + 0x4;
        arg->buf[2] = 0;
-       ++cpuHogCount;
-}
-
-// getCpuHogCount fetches the number of times we've seen cpuHog in the
-// traceback.
-int getCpuHogCount() {
-       return cpuHogCount;
 }
 */
 import "C"
@@ -86,7 +77,7 @@ func CgoPprof() {
        }
 
        t0 := time.Now()
-       for C.getCpuHogCount() < 2 && time.Since(t0) < time.Second {
+       for time.Since(t0) < time.Second {
                C.cpuHog()
        }
 
index feb774ba59a91c22146ef13e1298617bda524610..4bc84d16d0c607fb6f18732584bf574581a9e3f1 100644 (file)
@@ -33,8 +33,6 @@ void cpuHogThread() {
 void cpuHogThread2() {
 }
 
-static int cpuHogThreadCount;
-
 struct cgoTracebackArg {
        uintptr_t  context;
        uintptr_t  sigContext;
@@ -49,13 +47,6 @@ void pprofCgoThreadTraceback(void* parg) {
        arg->buf[0] = (uintptr_t)(cpuHogThread) + 0x10;
        arg->buf[1] = (uintptr_t)(cpuHogThread2) + 0x4;
        arg->buf[2] = 0;
-       __sync_add_and_fetch(&cpuHogThreadCount, 1);
-}
-
-// getCPUHogThreadCount fetches the number of times we've seen cpuHogThread
-// in the traceback.
-int getCPUHogThreadCount() {
-       return __sync_add_and_fetch(&cpuHogThreadCount, 0);
 }
 
 static void* cpuHogDriver(void* arg __attribute__ ((unused))) {
@@ -109,10 +100,7 @@ func pprofThread() {
 
        C.runCPUHogThread()
 
-       t0 := time.Now()
-       for C.getCPUHogThreadCount() < 2 && time.Since(t0) < time.Second {
-               time.Sleep(100 * time.Millisecond)
-       }
+       time.Sleep(1*time.Second)
 
        pprof.StopCPUProfile()