xref: /third_party/rust/crates/rustix/tests/io/eventfd.rs
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/rust/crates/rustix/tests/io/
1b8a62b91Sopenharmony_ci#[cfg(any(target_os = "android", target_os = "linux"))]
2b8a62b91Sopenharmony_ci#[test]
3b8a62b91Sopenharmony_cifn test_eventfd() {
4b8a62b91Sopenharmony_ci    use rustix::io::{eventfd, read, write, EventfdFlags};
5b8a62b91Sopenharmony_ci    use std::mem::size_of;
6b8a62b91Sopenharmony_ci    use std::thread;
7b8a62b91Sopenharmony_ci
8b8a62b91Sopenharmony_ci    let efd = eventfd(0, EventfdFlags::CLOEXEC).unwrap();
9b8a62b91Sopenharmony_ci
10b8a62b91Sopenharmony_ci    let child = thread::spawn(move || {
11b8a62b91Sopenharmony_ci        for u in [1_u64, 3, 6, 11, 5000].iter() {
12b8a62b91Sopenharmony_ci            assert_eq!(write(&efd, &u.to_ne_bytes()).unwrap(), size_of::<u64>());
13b8a62b91Sopenharmony_ci        }
14b8a62b91Sopenharmony_ci        efd
15b8a62b91Sopenharmony_ci    });
16b8a62b91Sopenharmony_ci
17b8a62b91Sopenharmony_ci    let efd = child.join().unwrap();
18b8a62b91Sopenharmony_ci
19b8a62b91Sopenharmony_ci    let mut bytes = [0_u8; size_of::<u64>()];
20b8a62b91Sopenharmony_ci    let s = read(&efd, &mut bytes).unwrap();
21b8a62b91Sopenharmony_ci    assert_eq!(s, bytes.len());
22b8a62b91Sopenharmony_ci    let u = u64::from_ne_bytes(bytes);
23b8a62b91Sopenharmony_ci    assert_eq!(u, 5021);
24b8a62b91Sopenharmony_ci}
25

Indexes created Thu Nov 07 10:32:03 CST 2024