Skip to content
Open
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
3 changes: 3 additions & 0 deletions tests/rust/wasm32-wasip3/src/bin/filesystem-mkdir-rmdir.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dirs": ["fs-tests.dir"]
}
103 changes: 103 additions & 0 deletions tests/rust/wasm32-wasip3/src/bin/filesystem-mkdir-rmdir.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
use std::process;
extern crate wit_bindgen;

wit_bindgen::generate!({
inline: r"
package test:test;

world test {
include wasi:filesystem/[email protected];
include wasi:cli/[email protected];
}
",
additional_derives: [PartialEq, Eq, Hash, Clone],
// Work around https://github.com/bytecodealliance/wasm-tools/issues/2285.
features:["clocks-timezone"],
generate_all
});

use wasi::filesystem::types::Descriptor;
use wasi::filesystem::types::ErrorCode;

async fn test_mkdir_rmdir(dir: &Descriptor) {
let mkdir = |path: &str| dir.create_directory_at(path.to_string());
let rmdir = |path: &str| dir.remove_directory_at(path.to_string());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add exploration of behavior further down the tree, where the test creates a dir and then opens it as a Descriptor and performs operations there, most interestingly the operations on .. and ../sibling?


// create-directory-at: async func(path: string) -> result<_, error-code>;
assert_eq!(dir.create_directory_at("".to_string()).await,
Err(ErrorCode::NoEntry));
assert_eq!(mkdir(".").await, Err(ErrorCode::Exist));
assert_eq!(mkdir("..").await, Err(ErrorCode::NotPermitted));
assert_eq!(mkdir("parent/foo").await, Err(ErrorCode::NotPermitted));
assert_eq!(mkdir("/").await, Err(ErrorCode::NotPermitted));
assert_eq!(
mkdir("../fs-tests.dir/q.cleanup").await,
Err(ErrorCode::NotPermitted)
);
assert_eq!(
mkdir("parent/fs-tests.dir/q.cleanup").await,
Err(ErrorCode::NotPermitted)
);
assert_eq!(mkdir("a.txt").await, Err(ErrorCode::Exist));
mkdir("q.cleanup").await.unwrap();
assert_eq!(
rmdir("../fs-tests.dir/q.cleanup").await,
Err(ErrorCode::NotPermitted)
);
assert_eq!(
rmdir("parent/fs-tests.dir/q.cleanup").await,
Err(ErrorCode::NotPermitted)
);
assert_eq!(rmdir("q.cleanup/").await, Err(ErrorCode::Invalid));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test filesystem-mkdir-rmdir failed
[exit_code] 0 == 3
STDOUT:

STDERR:

thread '' (1) panicked at src/bin/filesystem-mkdir-rmdir.rs:51:5:
assertion left == right failed
left: Err(ErrorCode { code: 0, name: "access", message: "Permission denied, similar to EACCES in POSIX." })
right: Err(ErrorCode { code: 11, name: "invalid", message: "Invalid argument, similar to EINVAL in POSIX." })
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
Error: failed to run main module tests\rust\testsuite\wasm32-wasip3\filesystem-mkdir-rmdir.wasm

assert_eq!(
rmdir("q.cleanup/../../fs-tests.dir/q.cleanup").await,
Err(ErrorCode::NotPermitted)
);
rmdir("q.cleanup").await.unwrap();
mkdir("q.cleanup/").await.unwrap();
rmdir("q.cleanup").await.unwrap();
mkdir("q.cleanup").await.unwrap();
// FIXME: https://github.com/bytecodealliance/wasmtime/issues/11524
// rmdir("q.cleanup/")
// .await.unwrap();
// mkdir("q.cleanup/////")
// .await.unwrap();
// rmdir("q.cleanup////////////")
// .await.unwrap();
// Using this instead to clean up:
rmdir("q.cleanup").await.unwrap();

// remove-directory-at: async func(path: string) -> result<_, error-code>;
assert_eq!(rmdir("").await, Err(ErrorCode::NoEntry));
assert_eq!(rmdir(".").await, Err(ErrorCode::Invalid));
assert_eq!(rmdir("..").await, Err(ErrorCode::NotPermitted));
assert_eq!(rmdir("/").await, Err(ErrorCode::NotPermitted));
assert_eq!(rmdir("a.txt").await, Err(ErrorCode::NotDirectory));
assert_eq!(rmdir("z.txt").await, Err(ErrorCode::NoEntry));
assert_eq!(rmdir("parent").await, Err(ErrorCode::NotDirectory));
assert_eq!(
rmdir("parent/fs-tests.dir").await,
Err(ErrorCode::NotPermitted)
);
}

struct Component;
export!(Component);
impl exports::wasi::cli::run::Guest for Component {
async fn run() -> Result<(), ()> {
match &wasi::filesystem::preopens::get_directories()[..] {
[(dir, dirname)] if dirname == "fs-tests.dir" => {
test_mkdir_rmdir(dir).await;
}
[..] => {
eprintln!("usage: run with one open dir named 'fs-tests.dir'");
process::exit(1)
}
};
Ok(())
}
}

fn main() {
unreachable!("main is a stub");
}
Loading