Port test_pipes

This commit is contained in:
Johannes Altmanninger 2023-12-09 17:18:51 +01:00
parent 9430d5c542
commit 09b7f3892f
2 changed files with 19 additions and 22 deletions

View file

@ -233,3 +233,22 @@ pub fn make_fd_blocking(fd: RawFd) -> Result<(), io::Error> {
}
Ok(())
}
crate::ffi_tests::add_test!("test_pipes", || {
// Here we just test that each pipe has CLOEXEC set and is in the high range.
// Note pipe creation may fail due to fd exhaustion; don't fail in that case.
let mut pipes = vec![];
for _i in 0..10 {
if let Some(pipe) = make_autoclose_pipes() {
pipes.push(pipe);
}
}
for pipe in pipes {
for fd in [pipe.read.fd(), pipe.write.fd()] {
assert!(fd >= FIRST_HIGH_FD);
let flags = unsafe { libc::fcntl(fd, F_GETFD, 0) };
assert!(flags >= 0);
assert!(flags & FD_CLOEXEC != 0);
}
}
});

View file

@ -2035,27 +2035,6 @@ void test_dirname_basename() {
do_test(wbasename(longpath) == L"overlong");
}
// todo!("port this")
static void test_pipes() {
say(L"Testing pipes");
// Here we just test that each pipe has CLOEXEC set and is in the high range.
// Note pipe creation may fail due to fd exhaustion; don't fail in that case.
std::vector<autoclose_pipes_t> pipes;
for (int i = 0; i < 10; i++) {
if (auto pipe = make_autoclose_pipes()) {
pipes.push_back(pipe.acquire());
}
}
for (const auto &pipe : pipes) {
for (int fd : {pipe.read.fd(), pipe.write.fd()}) {
do_test(fd >= k_first_high_fd);
int flags = fcntl(fd, F_GETFD, 0);
do_test(flags >= 0);
do_test(bool(flags & FD_CLOEXEC));
}
}
}
// todo!("port this")
static void test_fd_event_signaller() {
say(L"Testing fd event signaller");
@ -2141,7 +2120,6 @@ static const test_t s_tests[]{
{TEST_GROUP("maybe"), test_maybe},
{TEST_GROUP("normalize"), test_normalize_path},
{TEST_GROUP("dirname"), test_dirname_basename},
{TEST_GROUP("pipes"), test_pipes},
{TEST_GROUP("fd_event"), test_fd_event_signaller},
{TEST_GROUP("rust_smoke"), test_rust_smoke},
{TEST_GROUP("rust_ffi"), test_rust_ffi},