github.com/comwrg/go/src@v0.0.0-20220319063731-c238d0440370/os/signal/signal_linux_test.go (about) 1 // Copyright 2020 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build linux 6 // +build linux 7 8 package signal 9 10 import ( 11 "os" 12 "syscall" 13 "testing" 14 "time" 15 ) 16 17 const prSetKeepCaps = 8 18 19 // This test validates that syscall.AllThreadsSyscall() can reliably 20 // reach all 'm' (threads) of the nocgo runtime even when one thread 21 // is blocked waiting to receive signals from the kernel. This monitors 22 // for a regression vs. the fix for #43149. 23 func TestAllThreadsSyscallSignals(t *testing.T) { 24 if _, _, err := syscall.AllThreadsSyscall(syscall.SYS_PRCTL, prSetKeepCaps, 0, 0); err == syscall.ENOTSUP { 25 t.Skip("AllThreadsSyscall disabled with cgo") 26 } 27 28 sig := make(chan os.Signal, 1) 29 Notify(sig, os.Interrupt) 30 31 for i := 0; i <= 100; i++ { 32 if _, _, errno := syscall.AllThreadsSyscall(syscall.SYS_PRCTL, prSetKeepCaps, uintptr(i&1), 0); errno != 0 { 33 t.Fatalf("[%d] failed to set KEEP_CAPS=%d: %v", i, i&1, errno) 34 } 35 } 36 37 select { 38 case <-time.After(10 * time.Millisecond): 39 case <-sig: 40 t.Fatal("unexpected signal") 41 } 42 Stop(sig) 43 }