repositories / smith

smith

There are many coding harnesses - but this one is fast

owned by bugabinga

build(xtask): cargo x mutants requires a scope locally; one job, nice, timeout; --all for CI; smith-bench excluded

c895253f625cf500e0aa84cf3059e9a1404f58db

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (4)

+120 / −12 text lines

Diff layout

.cargo/mutants.toml

Added
new file mode 100644

+34 / −0 text lines

1# cargo-mutants configuration.
2# Runs on demand via `cargo x mutants`; never in the blocking check chain.
3#
4# Split of concerns: this file owns TREE properties, identical on every
5# machine and in CI — bare `cargo mutants` needs no flags. Run-context
6# knobs (scratch dir, job count, baseline) live in the xtask step.
7#
8# Correctness pairing: mutation scope and test_package cover the same
9# crates — every first-party crate (exclude_globs denies plugin guests,
10# unbuilt frontends, and xtask automation, so CLI -f scoping intersects
11# instead of widening: config list values APPEND to command-line lists).
12#
13# cap_lints: the workspace runs -D warnings; mutant-generated unused
14# variables would otherwise kill every build as Unviable.
15cap_lints = true
16test_package = [
17 "smith",
18 "smith-core",
19 "smith-ai",
20 "smith-rpc",
21 "smith-harness",
22 "smith-cli",
23 "smith-alloc",
24]
25test_tool = "nextest"
26profile = "mutants"
27additional_cargo_test_args = ["--profile=mutants"]
28exclude_globs = [
29 "plugins/**/*.rs",
30 "smith-tui/src/**",
31 "smith-ui/src/**",
32 "xtask/src/**",
33 "smith-bench/**",
34]

.ci/nightly.kdl

Modified

+1 / −1 text lines

2626 run "rustup component add llvm-tools"
2727 run "V=$PWD/target/tools/valgrind; test -x $V/bin/valgrind || (mkdir -p target/tools/src && curl -sSL https://sourceware.org/pub/valgrind/valgrind-3.25.1.tar.bz2 | tar -xj -C target/tools/src && cd target/tools/src/valgrind-3.25.1 && ./configure -q --prefix=$V >/dev/null && make -s -j$(nproc) >/dev/null && make -s install >/dev/null)"
2828 run "cargo run -p xtask -- bootstrap"
29 run "cargo run -p xtask -- mutants || echo 'missed mutants recorded in the report'"
29 run "cargo run -p xtask -- mutants --all || echo 'missed mutants recorded in the report'"
3030 run "PATH=$PWD/target/tools/valgrind/bin:$PATH cargo run -p xtask -- report"
3131 publish "site" {
3232 from "target/report"

.gitignore

Modified

+1 / −0 text lines

99**/target/
1010/.cargo/*
1111!/.cargo/config.toml
12!/.cargo/mutants.toml
1213/tmp/
1314/.tmp/
1415/.tmp_audit/

xtask/src/main.rs

Modified

+84 / −11 text lines

191191 if std::fs::create_dir_all(&scratch).is_err() {
192192 return fail("cannot create target/mutants-tmp\n");
193193 }
194 let jobs = std::env::var("CARGO_MUTANTS_JOBS").unwrap_or_else(|_| "1".to_string());
195194 // `cargo x mutants -- -f x` and `cargo x mutants -f x` are equivalent,
196195 // so cargo-run habits cannot turn scope flags into stray nextest test
197196 // filters.
198197 let extra = without_separator(extra);
199 let mut command = Command::new("cargo-mutants");
200 command.env("TMPDIR", &scratch).args([
201 "mutants",
202 "--jobs",
203 &jobs,
204 "--baseline",
205 "skip",
206 "--no-shuffle",
207 ]);
198 let all = extra.iter().any(|arg| arg == "--all");
199 if !all && !mutants_scoped(extra) {
200 return fail(MUTANTS_SCOPE_HELP);
201 }
202 let passthrough: Vec<&OsString> = extra.iter().filter(|arg| *arg != "--all").collect();
203 let jobs = std::env::var("CARGO_MUTANTS_JOBS").unwrap_or_else(|_| "1".to_string());
204 // Lowest scheduling priority: a mutants run is a background chore and
205 // must never starve the shell, even with one job its nextest fans out.
206 let threads = std::env::var("NEXTEST_TEST_THREADS").unwrap_or_else(|_| {
207 std::thread::available_parallelism()
208 .map_or(2, |cores| (cores.get() / 3).max(2))
209 .to_string()
210 });
211 let mut command = Command::new("nice");
212 command
213 .args(["-n", "19", "cargo-mutants"])
214 .env("TMPDIR", &scratch)
215 // A third of the cores per mutant's test run keeps the shell alive.
216 .env("NEXTEST_TEST_THREADS", &threads)
217 .args([
218 "mutants",
219 "--output",
220 "target",
221 "--jobs",
222 &jobs,
223 "--baseline",
224 "skip",
225 "--timeout",
226 "120",
227 "--no-shuffle",
228 ]);
208229 // Passthrough args come last and override the defaults above.
209 command.args(extra);
230 command.args(passthrough);
210231 match command.status() {
211232 Ok(status) if status.success() => ExitCode::SUCCESS,
212233 Ok(status) if status.code() == Some(2) => fail(
217238 }
241const MUTANTS_SCOPE_HELP: &str = "\
242cargo x mutants needs a scope: a workspace-wide run copies the tree per job and \
243has crashed this machine before.
244 -f <glob> one file or directory, e.g. -f smith-core/src/session.rs
245 -D <patch> mutants on changed lines only (jj diff --git > /tmp/d.patch)
246 -p <crate> one crate
247 --shard k/n one of n equal shards, e.g. --shard 0/8
248 -F/-E <regex> mutant-name filters
249 --list inventory only, no build
250 --all the whole workspace; CI only
251";
253/// Whether the passthrough arguments narrow a mutants run.
254fn mutants_scoped(extra: &[OsString]) -> bool {
255 extra.iter().any(|arg| {
256 let arg = arg.to_string_lossy();
257 matches!(
258 arg.as_ref(),
259 "-f" | "--file"
260 | "-D"
261 | "--in-diff"
262 | "-p"
263 | "--package"
264 | "--shard"
265 | "-F"
266 | "--re"
267 | "-E"
268 | "--exclude-re"
269 | "--list"
270 ) || arg.starts_with("--file=")
271 || arg.starts_with("--in-diff=")
272 || arg.starts_with("--package=")
273 || arg.starts_with("--shard=")
274 || arg.starts_with("--re=")
275 || arg.starts_with("--exclude-re=")
276 })
277}
220279/// Instruction budgets: every gungraun bench's callgrind `Ir` against its
221280/// pin in `smith-bench/budgets.toml`, within ±2 % in either direction, so
222281/// a regression fails and an improvement fails until re-pinned.
14631522#[cfg(test)]
14641523mod tests {
1524 #[test]
1525 fn mutants_refuse_to_run_unscoped() {
1526 let scoped = |args: &[&str]| {
1527 let args: Vec<std::ffi::OsString> = args.iter().map(std::ffi::OsString::from).collect();
1528 super::mutants_scoped(&args)
1529 };
1530 assert!(scoped(&["-f", "smith-core/src/session.rs"]));
1531 assert!(scoped(&["--shard=0/8"]));
1532 assert!(scoped(&["-D", "/tmp/d.patch", "-j2"]));
1533 assert!(scoped(&["--list"]));
1534 assert!(!scoped(&[]));
1535 assert!(!scoped(&["-j4", "--baseline", "run"]));
1536 }
14651538 #[test]
14661539 fn junit_counts_read_the_testsuites_root() {
14671540 let xml = r#"<?xml version="1.0"?><testsuites name="nextest-run" tests="19" failures="1" errors="0"><testsuite tests="7"/></testsuites>"#;