github.com/ice-blockchain/go/src@v0.0.0-20240403114104-1564d284e521/runtime/proc_runtime_test.go (about) 1 // Copyright 2016 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 // Proc unit tests. In runtime package so can use runtime guts. 6 7 package runtime 8 9 func RunStealOrderTest() { 10 var ord randomOrder 11 for procs := 1; procs <= 64; procs++ { 12 ord.reset(uint32(procs)) 13 if procs >= 3 && len(ord.coprimes) < 2 { 14 panic("too few coprimes") 15 } 16 for co := 0; co < len(ord.coprimes); co++ { 17 enum := ord.start(uint32(co)) 18 checked := make([]bool, procs) 19 for p := 0; p < procs; p++ { 20 x := enum.position() 21 if checked[x] { 22 println("procs:", procs, "inc:", enum.inc) 23 panic("duplicate during enumeration") 24 } 25 checked[x] = true 26 enum.next() 27 } 28 if !enum.done() { 29 panic("not done") 30 } 31 } 32 } 33 // Make sure that different arguments to ord.start don't generate the 34 // same pos+inc twice. 35 for procs := 2; procs <= 64; procs++ { 36 ord.reset(uint32(procs)) 37 checked := make([]bool, procs*procs) 38 // We want at least procs*len(ord.coprimes) different pos+inc values 39 // before we start repeating. 40 for i := 0; i < procs*len(ord.coprimes); i++ { 41 enum := ord.start(uint32(i)) 42 j := enum.pos*uint32(procs) + enum.inc 43 if checked[j] { 44 println("procs:", procs, "pos:", enum.pos, "inc:", enum.inc) 45 panic("duplicate pos+inc during enumeration") 46 } 47 checked[j] = true 48 } 49 } 50 }