| 1 |
//go:build linux && go1.16 |
| 2 |
// +build linux,go1.16 |
| 3 |
|
| 4 |
package psx |
| 5 |
|
| 6 |
import ( |
| 7 |
"syscall" |
| 8 |
"testing" |
| 9 |
) |
| 10 |
|
| 11 |
// Test to confirm no regression against [Go bug 42494]. |
| 12 |
// |
| 13 |
// [Go bug 42494]: https://github.com/golang/go/issues/42494 |
| 14 |
func TestThreadChurn(t *testing.T) { |
| 15 |
const prSetKeepCaps = 8 |
| 16 |
|
| 17 |
for j := 0; j < 4; j++ { |
| 18 |
kill := (j & 1) != 0 |
| 19 |
sysc := (j & 2) != 0 |
| 20 |
t.Logf("[%d] testing kill=%v, sysc=%v", j, kill, sysc) |
| 21 |
for i := 50; i > 0; i-- { |
| 22 |
if kill { |
| 23 |
c := make(chan struct{}) |
| 24 |
go killAThread(c) |
| 25 |
close(c) |
| 26 |
} |
| 27 |
if sysc { |
| 28 |
if _, _, e := Syscall3(syscall.SYS_PRCTL, prSetKeepCaps, uintptr(i&1), 0); e != 0 { |
| 29 |
t.Fatalf("[%d] psx:prctl(SET_KEEPCAPS, %d) failed: %v", i, i&1, syscall.Errno(e)) |
| 30 |
} |
| 31 |
} |
| 32 |
} |
| 33 |
t.Logf("[%d] PASSED kill=%v, sysc=%v", j, kill, sysc) |
| 34 |
} |
| 35 |
} |