Skip to content

Commit 91f0ddb

Browse files
committed
Add basic test for pipe
1 parent 1a329d8 commit 91f0ddb

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

tests/pass-dep/libc/libc-fs-with-isolation.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use std::{fs, thread};
77

88
fn main() {
99
test_fcntl_f_dupfd();
10-
test_setfl_getfl();
10+
test_socketpair_setfl_getfl();
11+
test_pipe_setfl_getfl();
1112
test_setfl_getfl_threaded();
1213
}
1314

@@ -58,6 +59,33 @@ fn test_socketpair_setfl_getfl() {
5859
assert_eq!(res, libc::O_RDWR);
5960
}
6061

62+
63+
fn test_pipe_setfl_getfl() {
64+
65+
let mut fds = [-1, -1];
66+
let res = unsafe { libc::pipe(fds.as_mut_ptr()) };
67+
assert_eq!(res, 0);
68+
69+
// Test if both sides have O_RDWR.
70+
let res = unsafe { libc::fcntl(fds[0], libc::F_GETFL) };
71+
assert_eq!(res, libc::O_RDONLY);
72+
let res = unsafe { libc::fcntl(fds[1], libc::F_GETFL) };
73+
assert_eq!(res, libc::O_WRONLY);
74+
75+
// Add the O_NONBLOCK flag with setfl.
76+
let res = unsafe { libc::fcntl(fds[0], libc::F_SETFL, libc::O_NONBLOCK) };
77+
assert_eq!(res, 0);
78+
79+
// Test if the O_NONBLOCK flag is successfully added.
80+
let new_flag = libc::O_RDONLY | libc::O_NONBLOCK;
81+
let res = unsafe { libc::fcntl(fds[0], libc::F_GETFL) };
82+
assert_eq!(res, new_flag);
83+
84+
// THe other side remains unchanged.
85+
let res = unsafe { libc::fcntl(fds[1], libc::F_GETFL) };
86+
assert_eq!(res, libc::O_WRONLY);
87+
}
88+
6189
/// Test the behaviour of setfl/getfl when a fd is blocking.
6290
/// The expected execution is:
6391
/// 1. Main thread blocks on fds[0] `read`.

0 commit comments

Comments
 (0)