Skip to content

Commit 8952288

Browse files
committed
Rework fd_allocate test to allow for ENOTSUP at run time
The TESTCONFIG machinery is not used by the test runner: there is no facility to pass --env arguments to the adapters.
1 parent 9315be9 commit 8952288

File tree

3 files changed

+23
-27
lines changed

3 files changed

+23
-27
lines changed

tests/rust/src/bin/fd_advise.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::{env, process};
2-
use wasi_tests::{open_scratch_directory, TESTCONFIG};
2+
use wasi_tests::{open_scratch_directory};
33

44
unsafe fn test_fd_advise(dir_fd: wasi::Fd) {
55
const FILE_NAME: &str = "fd_advise_file.cleanup";
@@ -41,12 +41,13 @@ unsafe fn test_fd_advise(dir_fd: wasi::Fd) {
4141
let stat = wasi::fd_filestat_get(file_fd).expect("failed to fdstat 3");
4242
assert_eq!(stat.size, 100, "file size should be 100");
4343

44-
if TESTCONFIG.support_fd_allocate() {
45-
// Use fd_allocate to expand size to 200:
46-
wasi::fd_allocate(file_fd, 100, 100).expect("allocating size");
47-
48-
let stat = wasi::fd_filestat_get(file_fd).expect("failed to fdstat 3");
49-
assert_eq!(stat.size, 200, "file size should be 200");
44+
match wasi::fd_allocate(file_fd, 100, 100) {
45+
Ok(()) => {
46+
let stat =
47+
wasi::fd_filestat_get(file_fd).expect("failed to fdstat 3");
48+
assert_eq!(stat.size, 200, "file size should be 200");
49+
},
50+
Err(err) => { assert_eq!(err, wasi::ERRNO_NOTSUP, "allocating size"); }
5051
}
5152

5253
wasi::fd_close(file_fd).expect("failed to close");

tests/rust/src/bin/file_allocate.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::{env, process};
2-
use wasi_tests::{create_tmp_dir, open_scratch_directory, TESTCONFIG};
2+
use wasi_tests::{create_tmp_dir, open_scratch_directory};
33

44
unsafe fn test_file_allocate(dir_fd: wasi::Fd) {
55
// Create a file in the scratch directory.
@@ -25,21 +25,22 @@ unsafe fn test_file_allocate(dir_fd: wasi::Fd) {
2525
let mut stat = wasi::fd_filestat_get(file_fd).expect("reading file stats");
2626
assert_eq!(stat.size, 0, "file size should be 0");
2727

28-
if TESTCONFIG.support_fd_allocate() {
29-
// Allocate some size
30-
wasi::fd_allocate(file_fd, 0, 100).expect("allocating size");
31-
stat = wasi::fd_filestat_get(file_fd).expect("reading file stats");
32-
assert_eq!(stat.size, 100, "file size should be 100");
28+
match wasi::fd_allocate(file_fd, 0, 100) {
29+
Ok(()) => {
30+
stat = wasi::fd_filestat_get(file_fd).expect("reading file stats");
31+
assert_eq!(stat.size, 100, "file size should be 100");
3332

34-
// Allocate should not modify if less than current size
35-
wasi::fd_allocate(file_fd, 10, 10).expect("allocating size less than current size");
36-
stat = wasi::fd_filestat_get(file_fd).expect("reading file stats");
37-
assert_eq!(stat.size, 100, "file size should remain unchanged at 100");
33+
// Allocate should not modify if less than current size
34+
wasi::fd_allocate(file_fd, 10, 10).expect("allocating size less than current size");
35+
stat = wasi::fd_filestat_get(file_fd).expect("reading file stats");
36+
assert_eq!(stat.size, 100, "file size should remain unchanged at 100");
3837

39-
// Allocate should modify if offset+len > current_len
40-
wasi::fd_allocate(file_fd, 90, 20).expect("allocating size larger than current size");
41-
stat = wasi::fd_filestat_get(file_fd).expect("reading file stats");
42-
assert_eq!(stat.size, 110, "file size should increase from 100 to 110");
38+
// Allocate should modify if offset+len > current_len
39+
wasi::fd_allocate(file_fd, 90, 20).expect("allocating size larger than current size");
40+
stat = wasi::fd_filestat_get(file_fd).expect("reading file stats");
41+
assert_eq!(stat.size, 110, "file size should increase from 100 to 110");
42+
},
43+
Err(err) => { assert_eq!(err, wasi::ERRNO_NOTSUP, "allocating size"); }
4344
}
4445
wasi::fd_close(file_fd).expect("closing a file");
4546
wasi::path_unlink_file(dir_fd, "file").expect("removing a file");

tests/rust/src/config.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
pub struct TestConfig {
22
errno_mode: ErrnoMode,
33
no_dangling_filesystem: bool,
4-
no_fd_allocate: bool,
54
no_rename_dir_to_empty_dir: bool,
65
no_fdflags_sync_support: bool,
76
}
@@ -25,14 +24,12 @@ impl TestConfig {
2524
ErrnoMode::Permissive
2625
};
2726
let no_dangling_filesystem = std::env::var("NO_DANGLING_FILESYSTEM").is_ok();
28-
let no_fd_allocate = std::env::var("NO_FD_ALLOCATE").is_ok();
2927
let no_rename_dir_to_empty_dir = std::env::var("NO_RENAME_DIR_TO_EMPTY_DIR").is_ok();
3028
let no_fdflags_sync_support = std::env::var("NO_FDFLAGS_SYNC_SUPPORT").is_ok();
3129

3230
TestConfig {
3331
errno_mode,
3432
no_dangling_filesystem,
35-
no_fd_allocate,
3633
no_rename_dir_to_empty_dir,
3734
no_fdflags_sync_support,
3835
}
@@ -58,9 +55,6 @@ impl TestConfig {
5855
pub fn support_dangling_filesystem(&self) -> bool {
5956
!self.no_dangling_filesystem
6057
}
61-
pub fn support_fd_allocate(&self) -> bool {
62-
!self.no_fd_allocate
63-
}
6458
pub fn support_rename_dir_to_empty_dir(&self) -> bool {
6559
!self.no_rename_dir_to_empty_dir
6660
}

0 commit comments

Comments
 (0)