1 use test_programs::wasi::cli::{stdin, stdout}; 2 main()3fn 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()16fn 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()23fn consumer() { 24 let stdin = stdin::get_stdin(); 25 let stdin_pollable1 = stdin.subscribe(); 26 let stdin_pollable2 = stdin.subscribe(); 27 28 // The two pollables are subscribed to the same resource, and must report the same readiness 29 stdin_pollable1.block(); 30 assert!(stdin_pollable1.ready() && stdin_pollable2.ready()); 31 32 let bytes = stdin.read(CHUNK.len() as u64).unwrap(); 33 assert_eq!(&bytes, CHUNK); 34 } 35