aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2016-12-21 13:50:28 -0800
committerIan Lance Taylor <iant@golang.org>2016-12-21 22:50:41 +0000
commitd2512aff877a91e8cf8fa97602297f17e5b5d3f2 (patch)
tree6a34ca21bd6cb5326e24e5ec708e27784bbefbdd
parentd51046b37ce382bbca0de7277721567e1ee0146a (diff)
downloadgo-d2512aff877a91e8cf8fa97602297f17e5b5d3f2.tar.gz
go-d2512aff877a91e8cf8fa97602297f17e5b5d3f2.zip
misc/cgo/test: limit issue18146 attempts based on RLIMIT_NPROC
Fixes #18381. Change-Id: I0a476cd7f6182c8d4646628477c56c133d5671ee Reviewed-on: https://go-review.googlesource.com/34667 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
-rw-r--r--misc/cgo/test/issue18146.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/misc/cgo/test/issue18146.go b/misc/cgo/test/issue18146.go
index 19c52b6fd5..ffb04e9037 100644
--- a/misc/cgo/test/issue18146.go
+++ b/misc/cgo/test/issue18146.go
@@ -37,6 +37,31 @@ func test18146(t *testing.T) {
attempts = 100
}
+ // Restrict the number of attempts based on RLIMIT_NPROC.
+ // Tediously, RLIMIT_NPROC was left out of the syscall package,
+ // probably because it is not in POSIX.1, so we define it here.
+ // It is not defined on Solaris.
+ var nproc int
+ setNproc := true
+ switch runtime.GOOS {
+ default:
+ setNproc = false
+ case "linux":
+ nproc = 6
+ case "darwin", "dragonfly", "freebsd", "netbsd", "openbsd":
+ nproc = 7
+ }
+ if setNproc {
+ var rlim syscall.Rlimit
+ if syscall.Getrlimit(nproc, &rlim) == nil {
+ max := int(rlim.Cur) / (threads + 5)
+ if attempts > max {
+ t.Logf("lowering attempts from %d to %d for RLIMIT_NPROC", attempts, max)
+ attempts = max
+ }
+ }
+ }
+
if os.Getenv("test18146") == "exec" {
runtime.GOMAXPROCS(1)
for n := threads; n > 0; n-- {