Assert that `wat` contains the test expectations necessary for `funcs`.
(test: &Test, output: CompileOutput)
| 291 | |
| 292 | /// Assert that `wat` contains the test expectations necessary for `funcs`. |
| 293 | fn assert_output(test: &Test, output: CompileOutput) -> Result<()> { |
| 294 | let mut actual = String::new(); |
| 295 | match output { |
| 296 | CompileOutput::Clif(funcs) => { |
| 297 | for mut func in funcs { |
| 298 | func.dfg.resolve_all_aliases(); |
| 299 | writeln!(&mut actual, "{}", func.display()).unwrap(); |
| 300 | } |
| 301 | } |
| 302 | CompileOutput::Elf(bytes) => { |
| 303 | let mut cmd = wasmtime_test_util::command(env!("CARGO_BIN_EXE_wasmtime")); |
| 304 | cmd.arg("objdump") |
| 305 | .arg("--address-width=4") |
| 306 | .arg("--address-jumps") |
| 307 | .stdin(Stdio::piped()) |
| 308 | .stdout(Stdio::piped()) |
| 309 | .stderr(Stdio::piped()); |
| 310 | match &test.config.objdump { |
| 311 | Some(args) => { |
| 312 | cmd.args(args.to_vec()); |
| 313 | } |
| 314 | None => { |
| 315 | cmd.arg("--traps=false"); |
| 316 | } |
| 317 | } |
| 318 | if let Some(filter) = &test.config.filter { |
| 319 | cmd.arg("--filter").arg(filter); |
| 320 | } |
| 321 | |
| 322 | let mut child = cmd.spawn().context("failed to run wasmtime")?; |
| 323 | child |
| 324 | .stdin |
| 325 | .take() |
| 326 | .unwrap() |
| 327 | .write_all(&bytes) |
| 328 | .context("failed to write stdin")?; |
| 329 | let output = child |
| 330 | .wait_with_output() |
| 331 | .context("failed to wait for child")?; |
| 332 | if !output.status.success() { |
| 333 | bail!( |
| 334 | "objdump failed: {}\nstderr: {}", |
| 335 | output.status, |
| 336 | String::from_utf8_lossy(&output.stderr), |
| 337 | ); |
| 338 | } |
| 339 | actual = String::from_utf8(output.stdout).unwrap(); |
| 340 | } |
| 341 | } |
| 342 | let actual = actual.trim(); |
| 343 | assert_or_bless_output(&test.path, &test.contents, actual) |
| 344 | } |
| 345 | |
| 346 | fn assert_or_bless_output(path: &Path, wat: &str, actual: &str) -> Result<()> { |
| 347 | log::debug!("=== actual ===\n{actual}"); |
no test coverage detected