summaryrefslogtreecommitdiffstats
path: root/src/runtime/proc_runtime_test.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-16 19:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-16 19:19:13 +0000
commitccd992355df7192993c666236047820244914598 (patch)
treef00fea65147227b7743083c6148396f74cd66935 /src/runtime/proc_runtime_test.go
parentInitial commit. (diff)
downloadgolang-1.21-ccd992355df7192993c666236047820244914598.tar.xz
golang-1.21-ccd992355df7192993c666236047820244914598.zip
Adding upstream version 1.21.8.upstream/1.21.8
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/runtime/proc_runtime_test.go')
-rw-r--r--src/runtime/proc_runtime_test.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/runtime/proc_runtime_test.go b/src/runtime/proc_runtime_test.go
new file mode 100644
index 0000000..90aed83
--- /dev/null
+++ b/src/runtime/proc_runtime_test.go
@@ -0,0 +1,50 @@
+// Copyright 2016 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.
+
+// Proc unit tests. In runtime package so can use runtime guts.
+
+package runtime
+
+func RunStealOrderTest() {
+ var ord randomOrder
+ for procs := 1; procs <= 64; procs++ {
+ ord.reset(uint32(procs))
+ if procs >= 3 && len(ord.coprimes) < 2 {
+ panic("too few coprimes")
+ }
+ for co := 0; co < len(ord.coprimes); co++ {
+ enum := ord.start(uint32(co))
+ checked := make([]bool, procs)
+ for p := 0; p < procs; p++ {
+ x := enum.position()
+ if checked[x] {
+ println("procs:", procs, "inc:", enum.inc)
+ panic("duplicate during enumeration")
+ }
+ checked[x] = true
+ enum.next()
+ }
+ if !enum.done() {
+ panic("not done")
+ }
+ }
+ }
+ // Make sure that different arguments to ord.start don't generate the
+ // same pos+inc twice.
+ for procs := 2; procs <= 64; procs++ {
+ ord.reset(uint32(procs))
+ checked := make([]bool, procs*procs)
+ // We want at least procs*len(ord.coprimes) different pos+inc values
+ // before we start repeating.
+ for i := 0; i < procs*len(ord.coprimes); i++ {
+ enum := ord.start(uint32(i))
+ j := enum.pos*uint32(procs) + enum.inc
+ if checked[j] {
+ println("procs:", procs, "pos:", enum.pos, "inc:", enum.inc)
+ panic("duplicate pos+inc during enumeration")
+ }
+ checked[j] = true
+ }
+ }
+}