use std::process::Command;
fn synth() -> &'static str {
env!("CARGO_BIN_EXE_synth")
}
fn fixture(name: &str) -> std::path::PathBuf {
std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../..")
.join("scripts/repro")
.join(name)
}
fn fused_count(fix: &str) -> usize {
let path = fixture(fix);
let out = Command::new(synth())
.env("SYNTH_CMP_SELECT_FUSE", "1")
.env("SYNTH_FUSE_STATS", "1")
.args([
"compile",
path.to_str().unwrap(),
"-o",
&format!("/tmp/cstm_{fix}.elf"),
"--target",
"cortex-m4",
"--all-exports",
"--relocatable",
])
.output()
.expect("run synth");
assert!(
out.status.success(),
"synth compile failed for {fix}: {}",
String::from_utf8_lossy(&out.stderr)
);
let combined = format!(
"{}{}",
String::from_utf8_lossy(&out.stdout),
String::from_utf8_lossy(&out.stderr)
);
combined
.lines()
.filter(|l| l.contains("[cmp-select-fuse]"))
.filter_map(|l| {
l.split("[cmp-select-fuse]")
.nth(1)?
.trim_start()
.split(' ')
.next()?
.parse::<usize>()
.ok()
})
.sum()
}
#[test]
fn two_move_select_arm_is_reachable_428() {
let in_place = fused_count("control_step.wasm");
assert!(
in_place >= 1,
"control_step should fuse its in-place clamps (got {in_place})"
);
let two_move = fused_count("cmp_select_two_move.wat");
assert_eq!(
two_move, 1,
"the two-move arm must now be reachable (fused {two_move}, want 1) — if 0, \
the #7 deadness fix regressed; if >1 the fixture changed"
);
}