Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/tests/all/piped_tests.rs
1692 views
1
#![cfg(not(miri))]
2
3
use super::cli_tests::get_wasmtime_command;
4
use anyhow::Result;
5
use std::process::Stdio;
6
7
pub fn run_wasmtime_piped(component_path: &str) -> Result<()> {
8
let mut producer = get_wasmtime_command()?
9
.arg("run")
10
.arg("-Wcomponent-model")
11
.arg("--env")
12
.arg("PIPED_SIDE=PRODUCER")
13
.arg(component_path)
14
.stdout(Stdio::piped())
15
.spawn()?;
16
17
let mut consumer = get_wasmtime_command()?
18
.arg("run")
19
.arg("-Wcomponent-model")
20
.arg("--env")
21
.arg("PIPED_SIDE=CONSUMER")
22
.arg(component_path)
23
.stdin(producer.stdout.take().unwrap())
24
.spawn()?;
25
26
let producer = producer.wait()?;
27
if !producer.success() {
28
// make sure the consumer gets killed off
29
if consumer.try_wait().is_err() {
30
consumer.kill().expect("Failed to kill consumer");
31
}
32
33
panic!("Producer failed");
34
}
35
36
assert!(consumer.wait()?.success(), "Consumer failed");
37
38
Ok(())
39
}
40
41
mod test_programs {
42
use super::run_wasmtime_piped;
43
use test_programs_artifacts::*;
44
45
macro_rules! assert_test_exists {
46
($name:ident) => {
47
#[expect(unused_imports, reason = "here to assert function is here")]
48
use self::$name as _;
49
};
50
}
51
foreach_piped!(assert_test_exists);
52
53
// Below here is mechanical: there should be one test for every binary in
54
// wasi-tests.
55
#[test]
56
fn piped_simple() {
57
run_wasmtime_piped(PIPED_SIMPLE_COMPONENT).unwrap()
58
}
59
60
#[test]
61
fn piped_multiple() {
62
run_wasmtime_piped(PIPED_MULTIPLE_COMPONENT).unwrap()
63
}
64
65
#[test]
66
fn piped_polling() {
67
run_wasmtime_piped(PIPED_POLLING_COMPONENT).unwrap()
68
}
69
}
70
71