1 use test_programs::wasi::cli::{stdin, stdout};
2 
main()3 fn main() {
4     match std::env::var("PIPED_SIDE")
5         .expect("piped tests require the PIPED_SIDE env var")
6         .as_str()
7     {
8         "PRODUCER" => producer(),
9         "CONSUMER" => consumer(),
10         side => panic!("unknown piped test side: {side}"),
11     }
12 }
13 
14 const CHUNK: &[u8] = &[b'a'; 50];
15 
producer()16 fn producer() {
17     let out = stdout::get_stdout();
18     let n = out.check_write().unwrap() as usize;
19     assert!(n > CHUNK.len());
20     out.write(CHUNK).unwrap();
21 }
22 
consumer()23 fn consumer() {
24     let stdin = stdin::get_stdin();
25     let stdin_pollable = stdin.subscribe();
26     stdin_pollable.block();
27     assert!(stdin_pollable.ready());
28     let bytes = stdin.read(CHUNK.len() as u64).unwrap();
29     assert_eq!(&bytes, CHUNK);
30 }
31