fd_advise test: set size via fd_filestat_set_size and fd_allocate
use more_asserts::assert_gt;
use std::{env, process};
-use wasi_tests::open_scratch_directory;
+use wasi_tests::{open_scratch_directory, TESTCONFIG};
unsafe fn test_fd_advise(dir_fd: wasi::Fd) {
// Create a file in the scratch directory.
@@ -13,6 +13,7 @@ unsafe fn test_fd_advise(dir_fd: wasi::Fd) {
| wasi::RIGHTS_FD_WRITE
| wasi::RIGHTS_FD_ADVISE
| wasi::RIGHTS_FD_FILESTAT_GET
+ | wasi::RIGHTS_FD_FILESTAT_SET_SIZE
| wasi::RIGHTS_FD_ALLOCATE,
0,
0,
@@ -28,8 +29,8 @@ unsafe fn test_fd_advise(dir_fd: wasi::Fd) {
let stat = wasi::fd_filestat_get(file_fd).expect("failed to fdstat");
assert_eq!(stat.size, 0, "file size should be 0");
- // Allocate some size
- wasi::fd_allocate(file_fd, 0, 100).expect("allocating size");
+ // set_size it bigger
+ wasi::fd_filestat_set_size(file_fd, 100).expect("setting size");
let stat = wasi::fd_filestat_get(file_fd).expect("failed to fdstat 2");
assert_eq!(stat.size, 100, "file size should be 100");
@@ -37,6 +38,18 @@ unsafe fn test_fd_advise(dir_fd: wasi::Fd) {
// Advise the kernel
wasi::fd_advise(file_fd, 10, 50, wasi::ADVICE_NORMAL).expect("failed advise");
+ // Advise shouldnt change size
+ let stat = wasi::fd_filestat_get(file_fd).expect("failed to fdstat 3");
+ assert_eq!(stat.size, 100, "file size should be 100");
+
+ if TESTCONFIG.support_fd_allocate() {
+ // Use fd_allocate to expand size to 200:
+ wasi::fd_allocate(file_fd, 100, 100).expect("allocating size");
+
+ let stat = wasi::fd_filestat_get(file_fd).expect("failed to fdstat 3");
+ assert_eq!(stat.size, 200, "file size should be 200");
+ }
+
wasi::fd_close(file_fd).expect("failed to close");
wasi::path_unlink_file(dir_fd, "file").expect("failed to unlink");
}
