Skip to content

Commit cfcea21

Browse files
committed
document --many-seeds; set the default range to 0..64
1 parent 4345379 commit cfcea21

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

src/tools/miri/README.md

+15-17
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,21 @@ platform. For example `cargo miri test --target s390x-unknown-linux-gnu`
151151
will run your test suite on a big-endian target, which is useful for testing
152152
endian-sensitive code.
153153

154+
### Testing multiple different executions
155+
156+
Certain parts of the execution are picked randomly by Miri, such as the exact base address
157+
allocations are stored at and the interleaving of concurrently executing threads. Sometimes, it can
158+
be useful to explore multiple different execution, e.g. to make sure that your code does not depend
159+
on incidental "super-alignment" of new allocations and to test different thread interleavings.
160+
This can be done with the `--many-seeds` flag:
161+
162+
```
163+
cargo miri test --many-seeds # tries the seeds in 0..64
164+
cargo miri test --many-seeds=0..16
165+
```
166+
167+
The default of 64 different seeds is quite slow, so you probably want to specify a smaller range.
168+
154169
### Running Miri on CI
155170

156171
When running Miri on CI, use the following snippet to install a nightly toolchain with the Miri
@@ -183,23 +198,6 @@ Here is an example job for GitHub Actions:
183198
The explicit `cargo miri setup` helps to keep the output of the actual test step
184199
clean.
185200

186-
### Testing for alignment issues
187-
188-
Miri can sometimes miss misaligned accesses since allocations can "happen to be"
189-
aligned just right. You can use `-Zmiri-symbolic-alignment-check` to definitely
190-
catch all such issues, but that flag will also cause false positives when code
191-
does manual pointer arithmetic to account for alignment. Another alternative is
192-
to call Miri with various values for `-Zmiri-seed`; that will alter the
193-
randomness that is used to determine allocation base addresses. The following
194-
snippet calls Miri in a loop with different values for the seed:
195-
196-
```
197-
for SEED in $(seq 0 255); do
198-
echo "Trying seed: $SEED"
199-
MIRIFLAGS=-Zmiri-seed=$SEED cargo miri test || { echo "Failing seed: $SEED"; break; };
200-
done
201-
```
202-
203201
### Supported targets
204202

205203
Miri does not support all targets supported by Rust. The good news, however, is

src/tools/miri/cargo-miri/src/phases.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Examples:
3434
3535
";
3636

37+
const DEFAULT_MANY_SEEDS: &str = "0..64";
38+
3739
fn show_help() {
3840
println!("{CARGO_MIRI_HELP}");
3941
}
@@ -171,7 +173,7 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
171173
ArgSplitFlagValue::from_string_iter(&mut args, "--target-dir").filter_map(Result::err)
172174
{
173175
if arg == "--many-seeds" {
174-
many_seeds = Some(format!("0..256"));
176+
many_seeds = Some(DEFAULT_MANY_SEEDS.to_owned());
175177
} else if let Some(val) = arg.strip_prefix("--many-seeds=") {
176178
many_seeds = Some(val.to_owned());
177179
} else {

src/tools/miri/miri-script/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Build miri, set up a sysroot and then run the test suite.
9898
Build miri, set up a sysroot and then run the driver with the given <flags>.
9999
(Also respects MIRIFLAGS environment variable.)
100100
If `--many-seeds` is present, Miri is run many times in parallel with different seeds.
101-
The range defaults to `0..256`.
101+
The range defaults to `0..64`.
102102
103103
./miri fmt <flags>:
104104
Format all sources and tests. <flags> are passed to `rustfmt`.
@@ -180,7 +180,7 @@ fn main() -> Result<()> {
180180
dep = true;
181181
} else if args.get_long_flag("verbose")? || args.get_short_flag('v')? {
182182
verbose = true;
183-
} else if let Some(val) = args.get_long_opt_with_default("many-seeds", "0..256")? {
183+
} else if let Some(val) = args.get_long_opt_with_default("many-seeds", "0..64")? {
184184
let (from, to) = val.split_once("..").ok_or_else(|| {
185185
anyhow!("invalid format for `--many-seeds`: expected `from..to`")
186186
})?;

0 commit comments

Comments
 (0)