I have been debugging some race conditions involving CUDA (unit tests can fail non-deterministically). So far, I'm doing something like:
while true; do cargo test --features="gpu"; done
However, I'd prefer to have cargo test just run each test 1_000_000 times. Is there a way to do this?
Pre-emptive questions:
Why not put a for loop in the unit test itself?
Sometimes, I want to do a quick test of "is the algorithm even approximately correct" (and have it only run once). It's only after I'm pretty sure the algorithm is "basically correct" what I want to run a torture test.
I like this approach. Is there a way to have feature "torture" auto turn on feature "gpu" ? Or does rust's 'additive feature" requirement prevent this?
An alternative method is to call the test harness directly instead of using Cargo:
cargo clean # otherwise, you could end up with more than one target/test/YOUR_CRATE_NAME-* executable
cargo test --no-run --features="gpu"
while true; do `find target/debug -maxdepth 1 -name YOUR_CRATE_NAME-\* -type f -executable`; done
Good idea, although the calling find at each iteration loop itches me:
#!/bin/sh
set -eu
set -o pipefail
export NUMRUNS=1000000 # or whatever amount you want
export CRATENAME=example # set to your crate name
cargo clean
cargo test --no-run # + whatever other flags you need, e.g. --features "gpu"
export TESTBINARY=$(find target/debug -maxdepth 1 -name $CRATENAME-\* -type f -executable)
seq 1 $NUMRUNS | while read line; do $TESTBINARY; done