dawn_node: Add -j option to run-cts

Running with too many threads can cause device initialization failures.

Bug: dawn:1143
Change-Id: Ie8010ab7a95e88f560dc14ed8b96919313218062
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/65662
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Ben Clayton 2021-10-05 16:47:45 +00:00 committed by Dawn LUCI CQ
parent 2c9fe21308
commit a12ac48f64
1 changed files with 11 additions and 7 deletions

View File

@ -69,6 +69,7 @@ func run() error {
var dawnNode, cts, node, npx string var dawnNode, cts, node, npx string
var verbose, build bool var verbose, build bool
var numRunners int
flag.StringVar(&dawnNode, "dawn-node", "", "path to dawn.node module") flag.StringVar(&dawnNode, "dawn-node", "", "path to dawn.node module")
flag.StringVar(&cts, "cts", "", "root directory of WebGPU CTS") flag.StringVar(&cts, "cts", "", "root directory of WebGPU CTS")
flag.StringVar(&node, "node", "", "path to node executable") flag.StringVar(&node, "node", "", "path to node executable")
@ -76,6 +77,7 @@ func run() error {
flag.BoolVar(&verbose, "verbose", false, "print extra information while testing") flag.BoolVar(&verbose, "verbose", false, "print extra information while testing")
flag.BoolVar(&build, "build", true, "attempt to build the CTS before running") flag.BoolVar(&build, "build", true, "attempt to build the CTS before running")
flag.BoolVar(&colors, "colors", colors, "enable / disable colors") flag.BoolVar(&colors, "colors", colors, "enable / disable colors")
flag.IntVar(&numRunners, "j", runtime.NumCPU(), "number of concurrent runners")
flag.Parse() flag.Parse()
if colors { if colors {
@ -128,11 +130,12 @@ func run() error {
} }
r := runner{ r := runner{
verbose: verbose, numRunners: numRunners,
node: node, verbose: verbose,
npx: npx, node: node,
dawnNode: dawnNode, npx: npx,
cts: cts, dawnNode: dawnNode,
cts: cts,
evalScript: `require('./src/common/tools/setup-ts-in-node.js'); evalScript: `require('./src/common/tools/setup-ts-in-node.js');
require('./src/common/runtime/cmdline.ts');`, require('./src/common/runtime/cmdline.ts');`,
} }
@ -161,6 +164,7 @@ func run() error {
} }
type runner struct { type runner struct {
numRunners int
verbose bool verbose bool
node, npx, dawnNode, cts string node, npx, dawnNode, cts string
evalScript string evalScript string
@ -206,7 +210,7 @@ func (r *runner) gatherTestCases(queries []string) error {
} }
// run() calls the CTS test runner to run each testcase in a separate process. // run() calls the CTS test runner to run each testcase in a separate process.
// Up to runtime.NumCPU() tests will be run concurrently. // Up to r.numRunners tests will be run concurrently.
func (r *runner) run() error { func (r *runner) run() error {
// Create a chan of test indices. // Create a chan of test indices.
// This will be read by the test runner goroutines. // This will be read by the test runner goroutines.
@ -223,7 +227,7 @@ func (r *runner) run() error {
// Spin up the test runner goroutines // Spin up the test runner goroutines
start := time.Now() start := time.Now()
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
for i := 0; i < runtime.NumCPU(); i++ { for i := 0; i < r.numRunners; i++ {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()