MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / assert_output

Function assert_output

tests/disas.rs:293–344  ·  view source on GitHub ↗

Assert that `wat` contains the test expectations necessary for `funcs`.

(test: &Test, output: CompileOutput)

Source from the content-addressed store, hash-verified

291
292/// Assert that `wat` contains the test expectations necessary for `funcs`.
293fn 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
346fn assert_or_bless_output(path: &Path, wat: &str, actual: &str) -> Result<()> {
347 log::debug!("=== actual ===\n{actual}");

Callers 1

run_testFunction · 0.85

Calls 15

commandFunction · 0.85
assert_or_bless_outputFunction · 0.85
resolve_all_aliasesMethod · 0.80
write_allMethod · 0.80
newFunction · 0.50
unwrapMethod · 0.45
stderrMethod · 0.45
stdoutMethod · 0.45
stdinMethod · 0.45
argMethod · 0.45
argsMethod · 0.45
to_vecMethod · 0.45

Tested by

no test coverage detected