-
Notifications
You must be signed in to change notification settings - Fork 35
wasi:[email protected]: Add tests for mkdir/rmdir #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "dirs": ["fs-tests.dir"] | ||
| } |
| 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()); | ||
|
|
||
| // 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)); | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test filesystem-mkdir-rmdir failed STDERR: thread '' (1) panicked at src/bin/filesystem-mkdir-rmdir.rs:51:5: |
||
| 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"); | ||
| } | ||
There was a problem hiding this comment.
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?