diff options
author | Austin Clements <austin@google.com> | 2019-10-14 20:10:48 -0400 |
---|---|---|
committer | Austin Clements <austin@google.com> | 2019-10-26 02:52:32 +0000 |
commit | 8dc1a158e460d7fdaca3c9317405e7c0dca6e443 (patch) | |
tree | 753df3de871b49d09fe0eae8ca4f774fe178a59d /src/runtime/export_unix_test.go | |
parent | 42aab4b0af5e50071fa8901a038bdc6f1f42b2ed (diff) | |
download | go-8dc1a158e460d7fdaca3c9317405e7c0dca6e443.tar.gz go-8dc1a158e460d7fdaca3c9317405e7c0dca6e443.zip |
runtime: add test for signalM
For #10958, #24543.
Change-Id: Ib009a83fe02bc623894f4908fe8f6b266382ba95
Reviewed-on: https://go-review.googlesource.com/c/go/+/201404
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'src/runtime/export_unix_test.go')
-rw-r--r-- | src/runtime/export_unix_test.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/runtime/export_unix_test.go b/src/runtime/export_unix_test.go index eecdfb7eb2..3f8bff619d 100644 --- a/src/runtime/export_unix_test.go +++ b/src/runtime/export_unix_test.go @@ -17,3 +17,42 @@ func Sigisblocked(i int) bool { sigprocmask(_SIG_SETMASK, nil, &sigmask) return sigismember(&sigmask, i) } + +type M = m + +var waitForSigusr1 struct { + park note + mp *m +} + +// WaitForSigusr1 blocks until a SIGUSR1 is received. It calls ready +// when it is set up to receive SIGUSR1. The ready function should +// cause a SIGUSR1 to be sent. +// +// Once SIGUSR1 is received, it returns the ID of the current M and +// the ID of the M the SIGUSR1 was received on. If no SIGUSR1 is +// received for timeoutNS nanoseconds, it returns -1. +func WaitForSigusr1(ready func(mp *M), timeoutNS int64) (int64, int64) { + mp := getg().m + testSigusr1 = func(gp *g) bool { + waitForSigusr1.mp = gp.m + notewakeup(&waitForSigusr1.park) + return true + } + ready(mp) + ok := notetsleepg(&waitForSigusr1.park, timeoutNS) + noteclear(&waitForSigusr1.park) + gotM := waitForSigusr1.mp + waitForSigusr1.mp = nil + testSigusr1 = nil + + if !ok { + return -1, -1 + } + return mp.id, gotM.id +} + +// SendSigusr1 sends SIGUSR1 to mp. +func SendSigusr1(mp *M) { + signalM(mp, _SIGUSR1) +} |