poll_oneoff test: don't try to poll same fd for read and write

This commit is contained in:
Pat Hickey
2021-04-27 17:41:07 -07:00
parent a532d0f379
commit 02581ddda0

View File

@@ -55,7 +55,10 @@ unsafe fn test_timeout() {
event.userdata, CLOCK_ID, event.userdata, CLOCK_ID,
"the event.userdata should contain clock_id specified by the user" "the event.userdata should contain clock_id specified by the user"
); );
assert!(after - before >= timeout, "poll_oneoff should sleep for the specified interval"); assert!(
after - before >= timeout,
"poll_oneoff should sleep for the specified interval"
);
} }
// Like test_timeout, but uses `CLOCKID_REALTIME`, as WASI libc's sleep // Like test_timeout, but uses `CLOCKID_REALTIME`, as WASI libc's sleep
@@ -90,20 +93,22 @@ unsafe fn test_sleep() {
event.userdata, CLOCK_ID, event.userdata, CLOCK_ID,
"the event.userdata should contain clock_id specified by the user" "the event.userdata should contain clock_id specified by the user"
); );
assert!(after - before >= timeout, "poll_oneoff should sleep for the specified interval"); assert!(
after - before >= timeout,
"poll_oneoff should sleep for the specified interval"
);
} }
unsafe fn test_fd_readwrite(fd: wasi::Fd, error_code: wasi::Errno) { unsafe fn test_fd_readwrite(readable_fd: wasi::Fd, writable_fd: wasi::Fd, error_code: wasi::Errno) {
let fd_readwrite = wasi::SubscriptionFdReadwrite {
file_descriptor: fd,
};
let r#in = [ let r#in = [
wasi::Subscription { wasi::Subscription {
userdata: 1, userdata: 1,
u: wasi::SubscriptionU { u: wasi::SubscriptionU {
tag: wasi::EVENTTYPE_FD_READ, tag: wasi::EVENTTYPE_FD_READ,
u: wasi::SubscriptionUU { u: wasi::SubscriptionUU {
fd_read: fd_readwrite, fd_read: wasi::SubscriptionFdReadwrite {
file_descriptor: readable_fd,
},
}, },
}, },
}, },
@@ -112,7 +117,9 @@ unsafe fn test_fd_readwrite(fd: wasi::Fd, error_code: wasi::Errno) {
u: wasi::SubscriptionU { u: wasi::SubscriptionU {
tag: wasi::EVENTTYPE_FD_WRITE, tag: wasi::EVENTTYPE_FD_WRITE,
u: wasi::SubscriptionUU { u: wasi::SubscriptionUU {
fd_write: fd_readwrite, fd_write: wasi::SubscriptionFdReadwrite {
file_descriptor: writable_fd,
},
}, },
}, },
}, },
@@ -143,26 +150,43 @@ unsafe fn test_fd_readwrite(fd: wasi::Fd, error_code: wasi::Errno) {
unsafe fn test_fd_readwrite_valid_fd(dir_fd: wasi::Fd) { unsafe fn test_fd_readwrite_valid_fd(dir_fd: wasi::Fd) {
// Create a file in the scratch directory. // Create a file in the scratch directory.
let file_fd = wasi::path_open( let readable_fd = wasi::path_open(
dir_fd, dir_fd,
0, 0,
"file", "readable_file",
wasi::OFLAGS_CREAT, wasi::OFLAGS_CREAT,
wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE | wasi::RIGHTS_POLL_FD_READWRITE, wasi::RIGHTS_FD_READ | wasi::RIGHTS_POLL_FD_READWRITE,
0, 0,
0, 0,
) )
.expect("opening a file"); .expect("opening a readable file");
assert_gt!( assert_gt!(
file_fd, readable_fd,
libc::STDERR_FILENO as wasi::Fd,
"file descriptor range check",
);
// Create a file in the scratch directory.
let writable_fd = wasi::path_open(
dir_fd,
0,
"writable_file",
wasi::OFLAGS_CREAT,
wasi::RIGHTS_FD_WRITE | wasi::RIGHTS_POLL_FD_READWRITE,
0,
0,
)
.expect("opening a writable file");
assert_gt!(
writable_fd,
libc::STDERR_FILENO as wasi::Fd, libc::STDERR_FILENO as wasi::Fd,
"file descriptor range check", "file descriptor range check",
); );
test_fd_readwrite(file_fd, wasi::ERRNO_SUCCESS); test_fd_readwrite(readable_fd, writable_fd, wasi::ERRNO_SUCCESS);
wasi::fd_close(file_fd).expect("closing a file"); wasi::fd_close(readable_fd).expect("closing readable_file");
wasi::path_unlink_file(dir_fd, "file").expect("removing a file"); wasi::path_unlink_file(dir_fd, "readable_file").expect("removing readable_file");
wasi::path_unlink_file(dir_fd, "writable_file").expect("removing writable_file");
} }
unsafe fn test_fd_readwrite_invalid_fd() { unsafe fn test_fd_readwrite_invalid_fd() {