• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
7package signal
8
9import (
10	"os"
11	"syscall"
12	"testing"
13	"time"
14)
15
16const prSetKeepCaps = 8
17
18// This test validates that syscall.AllThreadsSyscall() can reliably
19// reach all 'm' (threads) of the nocgo runtime even when one thread
20// is blocked waiting to receive signals from the kernel. This monitors
21// for a regression vs. the fix for #43149.
22func TestAllThreadsSyscallSignals(t *testing.T) {
23	if _, _, err := syscall.AllThreadsSyscall(syscall.SYS_PRCTL, prSetKeepCaps, 0, 0); err == syscall.ENOTSUP {
24		t.Skip("AllThreadsSyscall disabled with cgo")
25	}
26
27	sig := make(chan os.Signal, 1)
28	Notify(sig, os.Interrupt)
29
30	for i := 0; i <= 100; i++ {
31		if _, _, errno := syscall.AllThreadsSyscall(syscall.SYS_PRCTL, prSetKeepCaps, uintptr(i&1), 0); errno != 0 {
32			t.Fatalf("[%d] failed to set KEEP_CAPS=%d: %v", i, i&1, errno)
33		}
34	}
35
36	select {
37	case <-time.After(10 * time.Millisecond):
38	case <-sig:
39		t.Fatal("unexpected signal")
40	}
41	Stop(sig)
42}
43