mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: use pipe rather than note in TestSignalM
At least on Darwin notewakeup is not async-signal-safe. Fixes #35276 Change-Id: I1d7523715e8e77dbd7f21d9b1ed131e52d46cc41 Reviewed-on: https://go-review.googlesource.com/c/go/+/206078 Reviewed-by: Austin Clements <austin@google.com>
This commit is contained in:
parent
d22b5735e7
commit
99957b6930
2 changed files with 53 additions and 12 deletions
|
|
@ -18,6 +18,7 @@ import (
|
|||
"sync"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
|
|
@ -308,20 +309,45 @@ func TestSignalDuringExec(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSignalM(t *testing.T) {
|
||||
r, w, errno := runtime.Pipe()
|
||||
if errno != 0 {
|
||||
t.Fatal(syscall.Errno(errno))
|
||||
}
|
||||
defer func() {
|
||||
runtime.Close(r)
|
||||
runtime.Close(w)
|
||||
}()
|
||||
runtime.Closeonexec(r)
|
||||
runtime.Closeonexec(w)
|
||||
|
||||
var want, got int64
|
||||
var wg sync.WaitGroup
|
||||
ready := make(chan *runtime.M)
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
runtime.LockOSThread()
|
||||
want, got = runtime.WaitForSigusr1(func(mp *runtime.M) {
|
||||
var errno int32
|
||||
want, got = runtime.WaitForSigusr1(r, w, func(mp *runtime.M) {
|
||||
ready <- mp
|
||||
}, 1e9)
|
||||
})
|
||||
if errno != 0 {
|
||||
t.Error(syscall.Errno(errno))
|
||||
}
|
||||
runtime.UnlockOSThread()
|
||||
wg.Done()
|
||||
}()
|
||||
waitingM := <-ready
|
||||
runtime.SendSigusr1(waitingM)
|
||||
|
||||
timer := time.AfterFunc(time.Second, func() {
|
||||
// Write 1 to tell WaitForSigusr1 that we timed out.
|
||||
bw := byte(1)
|
||||
if n := runtime.Write(uintptr(w), unsafe.Pointer(&bw), 1); n != 1 {
|
||||
t.Errorf("pipe write failed: %d", n)
|
||||
}
|
||||
})
|
||||
defer timer.Stop()
|
||||
|
||||
wg.Wait()
|
||||
if got == -1 {
|
||||
t.Fatal("signalM signal not received")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue