MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / test_port_delay_assumption

Function test_port_delay_assumption

tests/event/port.rs:90–183  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

88#[cfg(feature = "fs")]
89#[test]
90fn test_port_delay_assumption() {
91 use rustix::fs;
92
93 let tmpdir = tempfile::tempdir().unwrap();
94 let fifo_path = tmpdir.path().join("fifo");
95 fs::mknodat(
96 fs::CWD,
97 &fifo_path,
98 fs::FileType::Fifo,
99 fs::Mode::RUSR
100 | fs::Mode::WUSR
101 | fs::Mode::RGRP
102 | fs::Mode::WGRP
103 | fs::Mode::ROTH
104 | fs::Mode::WOTH,
105 0,
106 )
107 .unwrap();
108
109 let fifo_path_clone = fifo_path.clone();
110 let _mutater = std::thread::Builder::new()
111 .name("mutater".to_string())
112 .spawn(|| {
113 let fifo = fs::openat(
114 fs::CWD,
115 fifo_path_clone,
116 fs::OFlags::WRONLY,
117 fs::Mode::empty(),
118 )
119 .unwrap();
120
121 for i in 0..10 {
122 let buf = [b'A' + (i % 26)];
123 match rustix::io::write(&fifo, &buf) {
124 Ok(1) => {}
125 Ok(n) => panic!("unexpected write of length {}", n),
126 Err(rustix::io::Errno::PIPE) => return,
127 Err(err) => Err(err).unwrap(),
128 }
129 std::thread::sleep(std::time::Duration::new(0, 4_000_000));
130 }
131 panic!("Loop iterated too many times without completing!");
132 })
133 .unwrap();
134
135 let fifo = fs::openat(fs::CWD, &fifo_path, fs::OFlags::RDONLY, fs::Mode::empty()).unwrap();
136
137 unsafe {
138 use rustix::fd::AsRawFd;
139 use std::ffi::c_void;
140
141 let port = libc::port_create();
142 assert_ne!(port, -1);
143
144 for i in 0..5 {
145 let r = libc::port_associate(
146 port,
147 libc::PORT_SOURCE_FD,

Callers

nothing calls this directly

Calls 10

port_createFunction · 0.85
port_associateFunction · 0.85
port_getFunction · 0.85
cloneMethod · 0.80
mknodatFunction · 0.50
openatFunction · 0.50
writeFunction · 0.50
readFunction · 0.50
pathMethod · 0.45
as_raw_fdMethod · 0.45

Tested by

no test coverage detected