diff --git a/crates/test-programs/wasi-tests/src/bin/fd_readdir.rs b/crates/test-programs/wasi-tests/src/bin/fd_readdir.rs index 87aa112c2b04..bc4bdd2d8524 100644 --- a/crates/test-programs/wasi-tests/src/bin/fd_readdir.rs +++ b/crates/test-programs/wasi-tests/src/bin/fd_readdir.rs @@ -65,10 +65,9 @@ unsafe fn exec_fd_readdir(fd: wasi::Fd, cookie: wasi::Dircookie) -> (Vec file_fd, + "nested directory file descriptor range check", + ); + let nested_stat = wasi::fd_filestat_get(nested_fd).expect("failed filestat"); + // Execute another readdir let (mut dirs, eof) = exec_fd_readdir(dir_fd, 0); assert!(eof, "expected to read the entire directory"); - assert_eq!(dirs.len(), 3, "expected three entries"); + assert_eq!(dirs.len(), 4, "expected four entries"); // Save the data about the last entry. We need to do it before sorting. - let lastfile_cookie = dirs[1].dirent.d_next; - let lastfile_name = dirs[2].name.clone(); + let lastfile_cookie = dirs[2].dirent.d_next; + let lastfile_name = dirs[3].name.clone(); dirs.sort_by_key(|d| d.name.clone()); let mut dirs = dirs.into_iter(); @@ -136,7 +157,16 @@ unsafe fn test_fd_readdir(dir_fd: wasi::Fd) { wasi::FILETYPE_REGULAR_FILE, "type for the real file" ); - assert_eq!(dir.dirent.d_ino, stat.ino); + assert_eq!(dir.dirent.d_ino, file_stat.ino); + let dir = dirs.next().expect("fourth entry is None"); + // check the directory info + assert_eq!(dir.name, "nested", "nested directory name doesn't match"); + assert_eq!( + dir.dirent.d_type, + wasi::FILETYPE_DIRECTORY, + "type for the nested directory" + ); + assert_eq!(dir.dirent.d_ino, nested_stat.ino); // check if cookie works as expected let (dirs, eof) = exec_fd_readdir(dir_fd, lastfile_cookie); @@ -144,7 +174,12 @@ unsafe fn test_fd_readdir(dir_fd: wasi::Fd) { assert_eq!(dirs.len(), 1, "expected one entry"); assert_eq!(dirs[0].name, lastfile_name, "name of the only entry"); + // check if nested directory shows up as empty + assert_empty_dir(nested_fd); + wasi::fd_close(nested_fd).expect("closing a nested directory"); + wasi::path_unlink_file(dir_fd, "file").expect("removing a file"); + wasi::path_remove_directory(dir_fd, "nested").expect("removing a nested directory"); } unsafe fn test_fd_readdir_lots(dir_fd: wasi::Fd) {