Skip to content

Commit

Permalink
Merge #2559
Browse files Browse the repository at this point in the history
2559: Implement wasi dir path rename r=syrusakbary a=bnjjj

# Description
Related to #2557 

I also add command to wasi-test-generator to generate only for specific tests and not always for all tests.


Co-authored-by: Syrus Akbary <[email protected]>
Co-authored-by: Benjamin Coenen <[email protected]>
Co-authored-by: Coenen Benjamin <[email protected]>
  • Loading branch information
4 people authored Sep 9, 2021
2 parents f0542c1 + debf5ee commit 4b23b63
Show file tree
Hide file tree
Showing 14 changed files with 115 additions and 12 deletions.
46 changes: 44 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ wasmer-engine-dylib = { version = "2.0.0", path = "lib/engine-dylib", optional =
wasmer-engine-staticlib = { version = "2.0.0", path = "lib/engine-staticlib", optional = true }
wasmer-wasi = { version = "2.0.0", path = "lib/wasi", optional = true }
wasmer-wast = { version = "2.0.0", path = "tests/lib/wast", optional = true }
wasi-test-generator = { version = "2.0.0", path = "tests/wasi-wast", optional = true }
wasmer-cache = { version = "2.0.0", path = "lib/cache", optional = true }
wasmer-types = { version = "2.0.0", path = "lib/types" }
wasmer-middlewares = { version = "2.0.0", path = "lib/middlewares", optional = true }
Expand Down Expand Up @@ -50,6 +51,7 @@ members = [
"lib/wasi-types",
"lib/wasi-experimental-io-devices",
"lib/types",
"tests/wasi-wast",
"tests/lib/wast",
"tests/lib/compiler-test-derive",
"tests/integration/cli",
Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,9 @@ test-capi-integration-%:
test-wasi-unit:
cargo test --manifest-path lib/wasi/Cargo.toml --release

test-wasi:
cargo test --release --tests $(compiler_features) -- wasi::wasitests

test-examples:
cargo test --release $(compiler_features) --features wasi --examples

Expand All @@ -573,6 +576,10 @@ test-integration:
test-integration-ios:
cargo test -p wasmer-integration-tests-ios

generate-wasi-tests:
# Uncomment the following for installing the toolchain
# cargo run -p wasi-test-generator -- -s
cargo run -p wasi-test-generator -- -g
#####
#
# Packaging.
Expand Down
1 change: 1 addition & 0 deletions lib/vfs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub trait FileSystem: fmt::Debug + Send + Sync + 'static {
self.metadata(path)
}
fn remove_file(&self, path: &Path) -> Result<()>;

fn new_open_options(&self) -> OpenOptions;
}

Expand Down
17 changes: 14 additions & 3 deletions lib/wasi/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1990,7 +1990,7 @@ pub fn path_remove_directory(
),
}

if state.fs_remove_dir(path_str).is_err() {
if state.fs_remove_dir(host_path_to_remove).is_err() {
// reinsert to prevent FS from being in bad state
if let Kind::Dir {
ref mut entries, ..
Expand Down Expand Up @@ -2070,8 +2070,11 @@ pub fn path_rename(
unreachable!("Fatal internal logic error: parent of inode is not a directory")
}
};

let source_entry = match &mut state.fs.inodes[source_parent_inode].kind {
Kind::Dir { entries, .. } => wasi_try!(entries.remove(&source_entry_name), __WASI_EINVAL),
Kind::Dir { entries, .. } => {
wasi_try!(entries.remove(&source_entry_name), __WASI_EINVAL)
}
Kind::Root { .. } => return __WASI_ENOTCAPABLE,
Kind::Symlink { .. } | Kind::File { .. } | Kind::Buffer { .. } => {
unreachable!("Fatal internal logic error: parent of inode is not a directory")
Expand Down Expand Up @@ -2107,7 +2110,15 @@ pub fn path_rename(
}
}
}
Kind::Dir { path, .. } => unimplemented!("wasi::path_rename on Directories"),
Kind::Dir { ref path, .. } => {
let cloned_path = path.clone();
if let Err(e) = state.fs_rename(cloned_path, &host_adjusted_target_path) {
return e;
}
if let Kind::Dir { path, .. } = &mut state.fs.inodes[source_entry].kind {
*path = host_adjusted_target_path;
}
}
Kind::Buffer { .. } => {}
Kind::Symlink { .. } => {}
Kind::Root { .. } => unreachable!("The root can not be moved"),
Expand Down
2 changes: 1 addition & 1 deletion tests/compilers/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl Config {
self.add_middlewares(&mut compiler);
Box::new(compiler)
}
#[allow(dead_code)]
#[allow(unreachable_patterns)]
compiler => {
panic!(
"The {:?} Compiler is not enabled. Enable it via the features",
Expand Down
2 changes: 1 addition & 1 deletion tests/wasi-wast/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wasi-test-generator"
version = "0.17.0"
version = "2.0.0"
description = "Tests for our WASI implementation"
license = "MIT"
authors = ["Wasmer Engineering Team <[email protected]>"]
Expand Down
9 changes: 9 additions & 0 deletions tests/wasi-wast/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ In order to run the test generator properly you will need:
## Usage

```
Positional arguments:
free if you want to specify specific tests to generate
Optional arguments:
-a, --all-versions Whether or not to do operations for all versions of WASI or just the latest.
-g, --generate-wasm Whether or not the Wasm will be generated.
Expand All @@ -26,6 +29,12 @@ cargo run -- -as # set up the toolchains for all targets
cargo run -- -ag # generate the WASI tests for all targets
```

If you want to generate specific tests (it's faster when you're developing) you can use this command:

```bash
cargo run -- -g fd_rename_path # If you want to run the test in fd_rename_path.rs
```

## Updating in Wasmer

Run
Expand Down
6 changes: 5 additions & 1 deletion tests/wasi-wast/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ use gumdrop::Options;

#[derive(Debug, Options)]
pub struct TestGenOptions {
/// if you want to specify specific tests to generate
#[options(free)]
free: Vec<String>,
/// Whether or not to do operations for all versions of WASI or just the latest.
all_versions: bool,
/// Whether or not the Wasm will be generated.
Expand Down Expand Up @@ -48,6 +51,7 @@ fn main() {

// Generate the WASI Wasm files
if generate_wasm {
build(wasi_versions);
let specific_tests: Vec<&str> = opts.free.iter().map(|st| st.as_str()).collect();
build(wasi_versions, &specific_tests);
}
}
2 changes: 1 addition & 1 deletion tests/wasi-wast/src/wasi_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl WasiVersion {
pub fn get_compiler_toolchain(&self) -> &'static str {
match self {
WasiVersion::Unstable => "nightly-2019-09-13",
WasiVersion::Snapshot1 => "nightly-2019-12-18",
WasiVersion::Snapshot1 => "1.53.0",
}
}

Expand Down
13 changes: 10 additions & 3 deletions tests/wasi-wast/src/wasitests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ fn compile_wasm_for_version(
.create(true)
.open(&temp_wasi_rs_file_name)
.unwrap();
actual_file.write_all(b"#![feature(wasi_ext)]\n").unwrap();
actual_file.write_all(file_contents.as_bytes()).unwrap();
}

Expand Down Expand Up @@ -246,13 +245,21 @@ fn compile(temp_dir: &Path, file: &str, wasi_versions: &[WasiVersion]) {
}

const WASI_TEST_SRC_DIR: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/wasi/tests/*.rs");
pub fn build(wasi_versions: &[WasiVersion]) {
pub fn build(wasi_versions: &[WasiVersion], specific_tests: &[&str]) {
let temp_dir = tempfile::TempDir::new().unwrap();
for entry in glob(WASI_TEST_SRC_DIR).unwrap() {
match entry {
Ok(path) => {
let test = path.to_str().unwrap();
compile(temp_dir.path(), test, wasi_versions);
if !specific_tests.is_empty() {
if let Some(filename) = path.file_stem().map(|f| f.to_str()).flatten() {
if specific_tests.contains(&filename) {
compile(temp_dir.path(), test, wasi_versions);
}
}
} else {
compile(temp_dir.path(), test, wasi_versions);
}
}
Err(e) => println!("{:?}", e),
}
Expand Down
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/wasi-wast/wasi/snapshot1/fd_rename_path.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
;; This file was generated by https://github.com/wasmerio/wasi-tests

(wasi_test "fd_rename_path.wasm"
(preopens "test_fs")
(assert_return (i64.const 0))
)
14 changes: 14 additions & 0 deletions tests/wasi-wast/wasi/tests/fd_rename_path.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// WASI:
// dir: test_fs

use std::fs;
use std::path::PathBuf;

fn main() {
let old_path = PathBuf::from("test_fs/wasitests/dirtorename");
let new_path = PathBuf::from("test_fs/wasitests/dirrenamed");
fs::create_dir_all(&old_path).expect("cannot create the directory");

fs::rename(old_path, &new_path).expect("cannot rename the directory");
fs::remove_dir(&new_path).expect("cannot remove the directory");
}

0 comments on commit 4b23b63

Please sign in to comment.