File: piped_tests.rs

package info (click to toggle)
rust-wasmtime 26.0.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 48,504 kB
  • sloc: ansic: 4,003; sh: 561; javascript: 542; cpp: 254; asm: 175; ml: 96; makefile: 55
file content (69 lines) | stat: -rw-r--r-- 1,718 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#![cfg(not(miri))]

use super::cli_tests::get_wasmtime_command;
use anyhow::Result;
use std::process::Stdio;

pub fn run_wasmtime_piped(component_path: &str) -> Result<()> {
    let mut producer = get_wasmtime_command()?
        .arg("run")
        .arg("-Wcomponent-model")
        .arg("--env")
        .arg("PIPED_SIDE=PRODUCER")
        .arg(component_path)
        .stdout(Stdio::piped())
        .spawn()?;

    let mut consumer = get_wasmtime_command()?
        .arg("run")
        .arg("-Wcomponent-model")
        .arg("--env")
        .arg("PIPED_SIDE=CONSUMER")
        .arg(component_path)
        .stdin(producer.stdout.take().unwrap())
        .spawn()?;

    let producer = producer.wait()?;
    if !producer.success() {
        // make sure the consumer gets killed off
        if consumer.try_wait().is_err() {
            consumer.kill().expect("Failed to kill consumer");
        }

        panic!("Producer failed");
    }

    assert!(consumer.wait()?.success(), "Consumer failed");

    Ok(())
}

mod test_programs {
    use super::run_wasmtime_piped;
    use test_programs_artifacts::*;

    macro_rules! assert_test_exists {
        ($name:ident) => {
            #[allow(unused_imports)]
            use self::$name as _;
        };
    }
    foreach_piped!(assert_test_exists);

    // Below here is mechanical: there should be one test for every binary in
    // wasi-tests.
    #[test]
    fn piped_simple() {
        run_wasmtime_piped(PIPED_SIMPLE_COMPONENT).unwrap()
    }

    #[test]
    fn piped_multiple() {
        run_wasmtime_piped(PIPED_MULTIPLE_COMPONENT).unwrap()
    }

    #[test]
    fn piped_polling() {
        run_wasmtime_piped(PIPED_POLLING_COMPONENT).unwrap()
    }
}