diff --git a/crates/test-programs/wasi-tests/src/bin/poll_oneoff.rs b/crates/test-programs/wasi-tests/src/bin/poll_oneoff.rs index 6407a32f3c..3246b5e505 100644 --- a/crates/test-programs/wasi-tests/src/bin/poll_oneoff.rs +++ b/crates/test-programs/wasi-tests/src/bin/poll_oneoff.rs @@ -55,7 +55,10 @@ unsafe fn test_timeout() { event.userdata, CLOCK_ID, "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 @@ -90,20 +93,22 @@ unsafe fn test_sleep() { event.userdata, CLOCK_ID, "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) { - let fd_readwrite = wasi::SubscriptionFdReadwrite { - file_descriptor: fd, - }; +unsafe fn test_fd_readwrite(readable_fd: wasi::Fd, writable_fd: wasi::Fd, error_code: wasi::Errno) { let r#in = [ wasi::Subscription { userdata: 1, u: wasi::SubscriptionU { tag: wasi::EVENTTYPE_FD_READ, 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 { tag: wasi::EVENTTYPE_FD_WRITE, 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) { // Create a file in the scratch directory. - let file_fd = wasi::path_open( + let readable_fd = wasi::path_open( dir_fd, 0, - "file", + "readable_file", 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, ) - .expect("opening a file"); + .expect("opening a readable file"); 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, "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::path_unlink_file(dir_fd, "file").expect("removing a file"); + wasi::fd_close(readable_fd).expect("closing readable_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() {