Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/compile-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ jobs:
toolchain: stable
target: wasm32-wasip1

- name: Run `cargo-fmt`
run: |
cargo fmt --manifest-path ./tests/rust/wasm32-wasip3/Cargo.toml --check
cargo fmt --manifest-path ./tests/rust/wasm32-wasip1/Cargo.toml --check

- name: Build tests
working-directory: tests/rust
run: |
Expand Down
11 changes: 6 additions & 5 deletions tests/rust/wasm32-wasip1/src/bin/fd_advise.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{env, process};
use wasi_tests::{open_scratch_directory};
use wasi_tests::open_scratch_directory;

unsafe fn test_fd_advise(dir_fd: wasi::Fd) {
const FILE_NAME: &str = "fd_advise_file.cleanup";
Expand Down Expand Up @@ -43,11 +43,12 @@ unsafe fn test_fd_advise(dir_fd: wasi::Fd) {

match wasi::fd_allocate(file_fd, 100, 100) {
Ok(()) => {
let stat =
wasi::fd_filestat_get(file_fd).expect("failed to fdstat 3");
let stat = wasi::fd_filestat_get(file_fd).expect("failed to fdstat 3");
assert_eq!(stat.size, 200, "file size should be 200");
},
Err(err) => { assert_eq!(err, wasi::ERRNO_NOTSUP, "allocating size"); }
}
Err(err) => {
assert_eq!(err, wasi::ERRNO_NOTSUP, "allocating size");
}
}

wasi::fd_close(file_fd).expect("failed to close");
Expand Down
6 changes: 4 additions & 2 deletions tests/rust/wasm32-wasip1/src/bin/file_allocate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ unsafe fn test_file_allocate(dir_fd: wasi::Fd) {
wasi::fd_allocate(file_fd, 90, 20).expect("allocating size larger than current size");
stat = wasi::fd_filestat_get(file_fd).expect("reading file stats");
assert_eq!(stat.size, 110, "file size should increase from 100 to 110");
},
Err(err) => { assert_eq!(err, wasi::ERRNO_NOTSUP, "allocating size"); }
}
Err(err) => {
assert_eq!(err, wasi::ERRNO_NOTSUP, "allocating size");
}
}
wasi::fd_close(file_fd).expect("closing a file");
wasi::path_unlink_file(dir_fd, "file").expect("removing a file");
Expand Down
29 changes: 13 additions & 16 deletions tests/rust/wasm32-wasip1/src/bin/path_filestat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,21 @@ unsafe fn test_path_filestat(dir_fd: wasi::Fd) {

// Create a file in the scratch directory.
let open_file = |fdflags| -> Result<wasi::Fd, wasi::Errno> {
let rights = wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE |
wasi::RIGHTS_PATH_FILESTAT_GET;
return wasi::path_open(dir_fd, 0, "file", wasi::OFLAGS_CREAT, rights, 0,
fdflags);
let rights = wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE | wasi::RIGHTS_PATH_FILESTAT_GET;
return wasi::path_open(dir_fd, 0, "file", wasi::OFLAGS_CREAT, rights, 0, fdflags);
};

let (file_fd, fdflags) =
match open_file(wasi::FDFLAGS_APPEND | wasi::FDFLAGS_SYNC) {
Ok(fd) => { (fd, wasi::FDFLAGS_APPEND | wasi::FDFLAGS_SYNC) }
Err(wasi::ERRNO_NOTSUP) => {
(open_file(wasi::FDFLAGS_APPEND).expect("opening file"),
wasi::FDFLAGS_APPEND)
}
Err(err) => {
eprintln!("error opening file: {}", err);
process::exit(1);
}
};
let (file_fd, fdflags) = match open_file(wasi::FDFLAGS_APPEND | wasi::FDFLAGS_SYNC) {
Ok(fd) => (fd, wasi::FDFLAGS_APPEND | wasi::FDFLAGS_SYNC),
Err(wasi::ERRNO_NOTSUP) => (
open_file(wasi::FDFLAGS_APPEND).expect("opening file"),
wasi::FDFLAGS_APPEND,
),
Err(err) => {
eprintln!("error opening file: {}", err);
process::exit(1);
}
};

assert!(
file_fd > libc::STDERR_FILENO as wasi::Fd,
Expand Down
2 changes: 1 addition & 1 deletion tests/rust/wasm32-wasip3/src/bin/filesystem-advise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ wit_bindgen::generate!({
generate_all
});

use wasi::filesystem::types::Descriptor;
use wasi::filesystem::types::Advice;
use wasi::filesystem::types::Descriptor;
use wasi::filesystem::types::{DescriptorFlags, ErrorCode, OpenFlags, PathFlags};

async fn test_advise(dir: &Descriptor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ wit_bindgen::generate!({
});

use wasi::filesystem::types::Descriptor;
use wasi::filesystem::types::{DescriptorFlags, ErrorCode, OpenFlags, PathFlags};
use wasi::filesystem::types::DescriptorType;
use wasi::filesystem::types::{DescriptorFlags, ErrorCode, OpenFlags, PathFlags};

async fn test_flags_and_type(dir: &Descriptor) {
// get-flags: async func() -> result<descriptor-flags, error-code>;
Expand Down
24 changes: 16 additions & 8 deletions tests/rust/wasm32-wasip3/src/bin/filesystem-hard-links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ async fn test_hard_links(dir: &Descriptor) {
let rmdir = |path: &str| dir.remove_directory_at(path.to_string());

// link-at: async func(old-path-flags: path-flags, old-path: string, new-descriptor: borrow<descriptor>, new-path: string) -> result<_, error-code>;
assert!(matches!(ln(".", "foo").await,
Err(ErrorCode::NotPermitted | ErrorCode::Access)));
assert!(matches!(
ln(".", "foo").await,
Err(ErrorCode::NotPermitted | ErrorCode::Access)
));

assert_eq!(ln("", "foo").await, Err(ErrorCode::NoEntry));
assert_eq!(ln("", "").await, Err(ErrorCode::NoEntry));
Expand All @@ -44,17 +46,23 @@ async fn test_hard_links(dir: &Descriptor) {
// FIXME: https://github.com/WebAssembly/WASI/issues/710
// assert_eq!(ln_follow("parent/foo", "a.txt").await,
// Err(ErrorCode::NotPermitted));
assert_eq!(ln("parent/foo", "a.txt").await,
Err(ErrorCode::NotPermitted));
assert_eq!(ln("a.txt", "parent/foo").await,
Err(ErrorCode::NotPermitted));
assert_eq!(
ln("parent/foo", "a.txt").await,
Err(ErrorCode::NotPermitted)
);
assert_eq!(
ln("a.txt", "parent/foo").await,
Err(ErrorCode::NotPermitted)
);
ln("a.txt", "c.cleanup").await.unwrap();
rm("c.cleanup").await.unwrap();
mkdir("d.cleanup").await.unwrap();
ln("a.txt", "d.cleanup/q.txt").await.unwrap();
rm("d.cleanup/q.txt").await.unwrap();
assert!(matches!(ln("d.cleanup", "e.cleanup").await,
Err(ErrorCode::NotPermitted | ErrorCode::Access)));
assert!(matches!(
ln("d.cleanup", "e.cleanup").await,
Err(ErrorCode::NotPermitted | ErrorCode::Access)
));
rmdir("d.cleanup").await.unwrap();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ wit_bindgen::generate!({
});

use wasi::filesystem::types::Descriptor;
use wasi::filesystem::types::DirectoryEntry;
use wasi::filesystem::types::DescriptorType;
use wasi::filesystem::types::DirectoryEntry;

async fn test_read_directory(dir: &Descriptor) {
// read-directory: async func() -> tuple<stream<directory-entry>, future<result<_, error-code>>>;
Expand Down
22 changes: 10 additions & 12 deletions tests/rust/wasm32-wasip3/src/bin/http-response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,18 @@ wit_bindgen::generate!({
generate_all
});

use wasi::http::types::{
Fields, HeaderError, Response
};
use wasi::http::types::{Fields, HeaderError, Response};

fn test_response_field_default_values(response: &Response) {
assert_eq!(response.get_status_code(), 200);
}

fn test_status_codes(response: &Response) {
for valid in [100, 101,
200, 201, 202, 203, 204, 205, 206,
300, 301, 302, 303, 304, 305, 306, 307, 308,
400, 401, 402, 403, 404, 405, 406, 407, 408, 409,
410, 411, 412, 413, 414, 415, 416, 417,
421, 422, 426,
500, 501, 502, 503, 504, 505] {
for valid in [
100, 101, 200, 201, 202, 203, 204, 205, 206, 300, 301, 302, 303, 304, 305, 306, 307, 308,
400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417,
421, 422, 426, 500, 501, 502, 503, 504, 505,
] {
assert_eq!(response.set_status_code(valid as u16), Ok(()));
assert_eq!(response.get_status_code(), valid);
}
Expand All @@ -38,8 +34,10 @@ fn test_status_codes(response: &Response) {
}

fn test_immutable_headers(headers: &Fields) {
assert_eq!(headers.append("Last-Modified", b"whatever"),
Err(HeaderError::Immutable));
assert_eq!(
headers.append("Last-Modified", b"whatever"),
Err(HeaderError::Immutable)
);
}

fn test_headers_same(left: &Fields, right: &Fields) {
Expand Down
Loading