1
0
mirror of https://github.com/golang/go synced 2024-11-08 19:36:22 -07:00
go/misc/cgo/test/setgid2_linux.go
Cherry Mui 4484c30f78 misc/cgo/test: make TestSetgidStress cheaper
TestSetgidStress spawns 1000 threads, which can be expensive on
some platforms or slow builders. Run with 50 threads in short
mode instead.

This makes the failure less reproducible even with buggy code. But
one can manually stress test it (e.g. when a flaky failure appear
on the builder).

Fixes #53641.

Change-Id: I33b5ea5ecaa8c7a56f59c16f9171657ee295db47
Reviewed-on: https://go-review.googlesource.com/c/go/+/415677
Reviewed-by: Austin Clements <austin@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Cherry Mui <cherryyz@google.com>
2022-07-06 14:23:50 +00:00

39 lines
715 B
Go

// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Stress test setgid and thread creation. A thread
// can get a SIGSETXID signal early on at thread
// initialization, causing crash. See issue 53374.
package cgotest
/*
#include <sys/types.h>
#include <unistd.h>
*/
import "C"
import (
"runtime"
"testing"
)
func testSetgidStress(t *testing.T) {
var N = 1000
if testing.Short() {
N = 50
}
ch := make(chan int, N)
for i := 0; i < N; i++ {
go func() {
C.setgid(0)
ch <- 1
runtime.LockOSThread() // so every goroutine uses a new thread
}()
}
for i := 0; i < N; i++ {
<-ch
}
}