]> Cypherpunks.ru repositories - gostls13.git/blob - misc/cgo/test/setgid2_linux.go
misc/cgo/test: make TestSetgidStress cheaper
[gostls13.git] / misc / cgo / test / setgid2_linux.go
1 // Copyright 2022 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 // Stress test setgid and thread creation. A thread
6 // can get a SIGSETXID signal early on at thread
7 // initialization, causing crash. See issue 53374.
8
9 package cgotest
10
11 /*
12 #include <sys/types.h>
13 #include <unistd.h>
14 */
15 import "C"
16
17 import (
18         "runtime"
19         "testing"
20 )
21
22 func testSetgidStress(t *testing.T) {
23         var N = 1000
24         if testing.Short() {
25                 N = 50
26         }
27         ch := make(chan int, N)
28         for i := 0; i < N; i++ {
29                 go func() {
30                         C.setgid(0)
31                         ch <- 1
32                         runtime.LockOSThread() // so every goroutine uses a new thread
33                 }()
34         }
35         for i := 0; i < N; i++ {
36                 <-ch
37         }
38 }