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

Function run_cwasm_from_stdin

tests/all/cli_tests.rs:515–552  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

513#[cfg(unix)]
514#[test]
515fn run_cwasm_from_stdin() -> Result<()> {
516 use std::process::Stdio;
517
518 let td = TempDir::new()?;
519 let cwasm = td.path().join("foo.cwasm");
520 let stdout = run_wasmtime(&[
521 "compile",
522 "tests/all/cli_tests/simple.wat",
523 "-o",
524 cwasm.to_str().unwrap(),
525 ])?;
526 assert_eq!(stdout, "");
527
528 // If stdin is literally the file itself then that should work
529 let args: &[&str] = &["run", "--allow-precompiled", "-"];
530 let output = get_wasmtime_command()?
531 .args(args)
532 .stdin(File::open(&cwasm)?)
533 .output()?;
534 assert!(output.status.success(), "a file as stdin should work");
535
536 // If stdin is a pipe, that should also work
537 let input = std::fs::read(&cwasm)?;
538 let mut child = get_wasmtime_command()?
539 .args(args)
540 .stdin(Stdio::piped())
541 .stdout(Stdio::piped())
542 .stderr(Stdio::piped())
543 .spawn()?;
544 let mut stdin = child.stdin.take().unwrap();
545 let t = std::thread::spawn(move || {
546 let _ = stdin.write_all(&input);
547 });
548 let output = child.wait_with_output()?;
549 assert!(output.status.success());
550 t.join().unwrap();
551 Ok(())
552}
553
554#[cfg(feature = "wasi-threads")]
555#[test]

Callers

nothing calls this directly

Calls 15

run_wasmtimeFunction · 0.85
get_wasmtime_commandFunction · 0.85
spawnFunction · 0.85
OkFunction · 0.85
to_strMethod · 0.80
outputMethod · 0.80
write_allMethod · 0.80
newFunction · 0.50
readFunction · 0.50
joinMethod · 0.45
pathMethod · 0.45
unwrapMethod · 0.45

Tested by

no test coverage detected