diff --git a/cranelift/docs/testing.md b/cranelift/docs/testing.md index bcbe3bdea8..92dc99f33a 100644 --- a/cranelift/docs/testing.md +++ b/cranelift/docs/testing.md @@ -74,6 +74,15 @@ run will also have the RISC-V specific flag `supports_m` disabled. The filetests are run automatically as part of `cargo test`, and they can also be run manually with the `clif-util test` command. +By default, the test runner will spawn a thread pool with as many threads as +there are logical CPUs. You can explicitly control how many threads are spawned +via the `CRANELIFT_FILETESTS_THREADS` environment variable. For example, to +limit the test runner to a single thread, use: + +``` +$ CRANELIFT_FILETESTS_THREADS=1 clif-util test path/to/file.clif +``` + ### Filecheck Many of the test commands described below use *filecheck* to verify their diff --git a/cranelift/filetests/src/concurrent.rs b/cranelift/filetests/src/concurrent.rs index 30e2c94cfe..67592ed03e 100644 --- a/cranelift/filetests/src/concurrent.rs +++ b/cranelift/filetests/src/concurrent.rs @@ -50,7 +50,16 @@ impl ConcurrentRunner { heartbeat_thread(reply_tx.clone()); - let handles = (0..num_cpus::get()) + let num_threads = std::env::var("CRANELIFT_FILETESTS_THREADS") + .ok() + .map(|s| { + use std::str::FromStr; + let n = usize::from_str(&s).unwrap(); + assert!(n > 0); + n + }) + .unwrap_or_else(|| num_cpus::get()); + let handles = (0..num_threads) .map(|num| worker_thread(num, request_mutex.clone(), reply_tx.clone())) .collect();