1 #[cfg(not(any(target_os = "redox", target_os = "solaris")))]
2 #[test]
test_flock()3 fn test_flock() {
4 use rustix::fs::{cwd, flock, openat, FlockOperation, Mode, OFlags};
5
6 let f = openat(cwd(), "Cargo.toml", OFlags::RDONLY, Mode::empty()).unwrap();
7 flock(&f, FlockOperation::LockExclusive).unwrap();
8 flock(&f, FlockOperation::Unlock).unwrap();
9 let g = openat(cwd(), "Cargo.toml", OFlags::RDONLY, Mode::empty()).unwrap();
10 flock(&g, FlockOperation::LockExclusive).unwrap();
11 flock(&g, FlockOperation::Unlock).unwrap();
12 drop(f);
13 drop(g);
14
15 let f = openat(cwd(), "Cargo.toml", OFlags::RDONLY, Mode::empty()).unwrap();
16 flock(&f, FlockOperation::LockShared).unwrap();
17 let g = openat(cwd(), "Cargo.toml", OFlags::RDONLY, Mode::empty()).unwrap();
18 flock(&g, FlockOperation::LockShared).unwrap();
19 flock(&f, FlockOperation::Unlock).unwrap();
20 flock(&g, FlockOperation::Unlock).unwrap();
21 drop(f);
22 drop(g);
23
24 let f = openat(cwd(), "Cargo.toml", OFlags::RDONLY, Mode::empty()).unwrap();
25 flock(&f, FlockOperation::LockShared).unwrap();
26 flock(&f, FlockOperation::LockExclusive).unwrap();
27 flock(&f, FlockOperation::Unlock).unwrap();
28 let g = openat(cwd(), "Cargo.toml", OFlags::RDONLY, Mode::empty()).unwrap();
29 flock(&g, FlockOperation::LockShared).unwrap();
30 flock(&g, FlockOperation::LockExclusive).unwrap();
31 flock(&g, FlockOperation::Unlock).unwrap();
32 drop(f);
33 drop(g);
34 }
35