forked from bytecodealliance/wasmtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge wasi-misc-tests repo as a subdir (bytecodealliance#174)
* Initial checkin. * Update to rust-lang libc. * Add a .gitignore file. * Factor out functions for cleaning up files and directories. * Fix a typo in a comment. * Print a "Success!" message if all tests passed. * Factor out code for creating directories. * Add wrappers around WASI functions. These wrappers handle converting from &str to pointer+length and handle unsafe. * More refactoring. * Refactor a fd_close helper. * Move utility functions into a separate file. * cargo update * Add a basic test for random_get. * Test that directories aren't resizable. * Test clearing __WASI_RIGHT_PATH_FILESTAT_SET_SIZE. Ensure that clearing __WASI_RIGHT_PATH_FILESTAT_SET_SIZE succeeds before testing file truncation. * cargo update * Modularise tests for easier use with wasi-common crate * Add a Code of Conduct and CONTRIBUTING.md. * Fix typo * Add testcase for fd_allocate * Add positive test for fd_renumber * Assert bufused in readlink_no_buffer testcase * Add positive readlink testcase * Add testcase for fd_seek and fd_tell * Add fd_p{read, write} test * Add README * Add cases with trailing slashes to interesting_paths * Split nofollow_errors testcase into two * nofollow_errors now operators on symlinks to existing resources * dangling_symlink covers danling symlinks tests * Factor out a `create_file` helper function. * Switch from the error crate to `std::io::Error::last_os_error()`. * Use `create_file` in the readlink test too. * Add a test for fd_filestat_set_* * Minor refactoring Add missing cleanup_file calls to file_pread_pwrite and file_seek_tell. * Add testcase for unbuffered fd_write; fixes bytecodealliance#11 * Add testcase for path_rename * Use the wasi crate. Switch from depending on libc to depending on the new wasi crate to provide the low-level WASI interfaces. See also rust-lang/libc#1461. * Add a test for path_filestat_* * Add a test for fd_readdir * Use expect instead of unwrap * Add a check for ino. * Fix the build * Don't assume a specific order of dirents * Better test * Test cookie value * Fix file types * Fix the test * Fix the test * Fix the test * Cleanup * Minor formatting tidying in README.md. * Fix miscellaneous clippy warnings. * Rename the crate to wasi-misc-tests. * Update to wasi 0.7.0. This switches from using the libc wasi bindings to using the wasi crate's bindings. This eliminates a git dependency on libc, updates to the new-style bindings which use Result where possible, and treats functions that operate on raw file descriptors as unsafe. * Add various tests for trailing-slash behavior. * Sync new testcases with latest upstream * Fix path_filestat testcase * Add smoke test for fd_advise This test is a true smoke test as it only tests whether issuing an advise call to the host's kernel doesn't yield an error. The consequence of issuing such a syscall is not tested. * Check if CLOCK_MONOTONIC is actually monotonic * Refactor the inequality assertions for more debuggable errors. * Bump libc from 0.2.62 to 0.2.65 Bumps [libc](https://github.com/rust-lang/libc) from 0.2.62 to 0.2.65. - [Release notes](https://github.com/rust-lang/libc/releases) - [Commits](rust-lang/libc@0.2.62...0.2.65) Signed-off-by: dependabot-preview[bot] <[email protected]> * Fix compilation error * Enable Actions and add rust.yml (bytecodealliance#35) * Enable Actions and add rust.yml This commit enables Github Actions and adds corresponding configuration in rust.yml file. * Update rust.yml * Fix formatting * Add empty .rustfmt.toml config file * Add badge to README * Update README * Clean up Github Actions and README * Add test case for `poll_oneoff` syscall (bytecodealliance#38) * Add test case for `poll_oneoff` syscall This commit adds a test case for `poll_oneoff` syscall. In particular, it builds on the excellent test use case provided by @dunnock in their repo [poll_oneoff_tests] (thanks!), and tests: * simple timeout * stdin read with timeout * fd read and fd write polls [poll_oneoff_tests]: https://github.com/dunnock/poll_oneoff_tests * Apply suggestions and negative test for bad fd Co-authored-by: Maxim Vorobjov <[email protected]> * Add smoke test for STDOUT/ERR readwrite poll * Add comment on stdin/out/err * Add a test for `*at`-style functions returning `ENOTDIR` when `dirfd` is not a dir. * Remove misc_testsuite submodule * Add "publish=false" to Cargo.toml; remove LICENSE
- Loading branch information
Showing
40 changed files
with
3,525 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
[submodule "misc_testsuite"] | ||
path = misc_testsuite | ||
url = https://github.com/cranestation/wasi-misc-tests | ||
[submodule "WASI"] | ||
path = WASI | ||
url = https://github.com/WebAssembly/WASI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
[package] | ||
name = "wasi-common" | ||
version = "0.5.0" | ||
authors = [ | ||
"Adam C. Foltzer <[email protected]>", | ||
"Frank Denis <[email protected]>", | ||
"Jakub Konka <[email protected]>", | ||
"Dan Gohman <[email protected]>"] | ||
authors = ["The Wasmtime Project Developers"] | ||
edition = "2018" | ||
license = "Apache-2.0 WITH LLVM-exception" | ||
description = "WASI implementation in Rust" | ||
|
@@ -41,18 +37,15 @@ cpu-time = "1.0" | |
|
||
|
||
[dev-dependencies] | ||
wasmtime-runtime = { git = "https://github.com/acfoltzer/wasmtime", rev = "d99e2fb" } | ||
wasmtime-environ = { git = "https://github.com/acfoltzer/wasmtime", rev = "d99e2fb" } | ||
wasmtime-jit = { git = "https://github.com/acfoltzer/wasmtime", rev = "d99e2fb" } | ||
wasmtime-wasi = { git = "https://github.com/acfoltzer/wasmtime", rev = "d99e2fb" } | ||
wasmtime-api = { git = "https://github.com/acfoltzer/wasmtime", rev = "d99e2fb" } | ||
cranelift-codegen = "0.47.0" | ||
wasmtime-runtime = { git = "https://github.com/CraneStation/wasmtime", rev = "ab3cd94" } | ||
wasmtime-environ = { git = "https://github.com/CraneStation/wasmtime", rev = "ab3cd94" } | ||
wasmtime-jit = { git = "https://github.com/CraneStation/wasmtime", rev = "ab3cd94" } | ||
wasmtime-wasi = { git = "https://github.com/CraneStation/wasmtime", rev = "ab3cd94" } | ||
wasmtime-api = { git = "https://github.com/CraneStation/wasmtime", rev = "ab3cd94" } | ||
cranelift-codegen = "0.49" | ||
target-lexicon = "0.8.1" | ||
pretty_env_logger = "0.3.0" | ||
tempfile = "3.1.0" | ||
# this is just a temp fix to make the tests build and run; I hope this to be | ||
# completely removed when we merge `wasi-common` into `wasmtime` | ||
faerie = "=0.11.0" | ||
|
||
[patch."https://github.com/CraneStation/wasi-common"] | ||
wasi-common = { path = "." } | ||
|
@@ -66,4 +59,4 @@ crate-type = ["rlib", "staticlib", "cdylib"] | |
|
||
[workspace] | ||
members = ["wasi-common-cbindgen"] | ||
exclude = ["winx", "misc_testsuite"] | ||
exclude = ["wasi-misc-tests", "wig", "winx", "WASI/tools/witx"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule misc_testsuite
deleted from
f67722
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "wasi-misc-tests" | ||
version = "0.1.0" | ||
authors = ["The Wasmtime Project Developers"] | ||
edition = "2018" | ||
publish = false | ||
|
||
[dependencies] | ||
libc = "0.2.65" | ||
wasi = "0.7.0" | ||
more-asserts = "0.2.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
This is the `wasi-misc-test` crate, which contains source code for the system-level WASI tests. | ||
|
||
Building these tests requires `wasm32-wasi` target installed | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use wasi::wasi_unstable; | ||
|
||
fn test_big_random_buf() { | ||
let mut buf = Vec::new(); | ||
buf.resize(1024, 0); | ||
assert!( | ||
wasi_unstable::random_get(&mut buf).is_ok(), | ||
"calling get_random on a large buffer" | ||
); | ||
// Chances are pretty good that at least *one* byte will be non-zero in | ||
// any meaningful random function producing 1024 u8 values. | ||
assert!(buf.iter().any(|x| *x != 0), "random_get returned all zeros"); | ||
} | ||
|
||
fn main() { | ||
// Run the tests. | ||
test_big_random_buf() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use more_asserts::assert_le; | ||
use wasi::wasi_unstable; | ||
use wasi_misc_tests::wasi_wrappers::wasi_clock_time_get; | ||
|
||
unsafe fn test_clock_time_get() { | ||
// Test that clock_time_get succeeds. Even in environments where it's not | ||
// desirable to expose high-precision timers, it should still succeed. | ||
// clock_res_get is where information about precision can be provided. | ||
let mut time: wasi_unstable::Timestamp = 0; | ||
let status = wasi_clock_time_get(wasi_unstable::CLOCK_MONOTONIC, 1, &mut time); | ||
assert_eq!( | ||
status, | ||
wasi_unstable::raw::__WASI_ESUCCESS, | ||
"clock_time_get with a precision of 1" | ||
); | ||
|
||
let status = wasi_clock_time_get(wasi_unstable::CLOCK_MONOTONIC, 0, &mut time); | ||
assert_eq!( | ||
status, | ||
wasi_unstable::raw::__WASI_ESUCCESS, | ||
"clock_time_get with a precision of 0" | ||
); | ||
let first_time = time; | ||
|
||
let status = wasi_clock_time_get(wasi_unstable::CLOCK_MONOTONIC, 0, &mut time); | ||
assert_eq!( | ||
status, | ||
wasi_unstable::raw::__WASI_ESUCCESS, | ||
"clock_time_get with a precision of 0" | ||
); | ||
assert_le!(first_time, time, "CLOCK_MONOTONIC should be monotonic"); | ||
} | ||
|
||
fn main() { | ||
// Run the tests. | ||
unsafe { test_clock_time_get() } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use libc; | ||
use more_asserts::assert_gt; | ||
use std::{env, mem, process}; | ||
use wasi::wasi_unstable; | ||
use wasi_misc_tests::open_scratch_directory; | ||
use wasi_misc_tests::wasi_wrappers::wasi_fd_fdstat_get; | ||
|
||
unsafe fn test_close_preopen(dir_fd: wasi_unstable::Fd) { | ||
let pre_fd: wasi_unstable::Fd = (libc::STDERR_FILENO + 1) as wasi_unstable::Fd; | ||
|
||
assert_gt!(dir_fd, pre_fd, "dir_fd number"); | ||
|
||
// Try to close a preopened directory handle. | ||
assert_eq!( | ||
wasi_unstable::fd_close(pre_fd), | ||
Err(wasi_unstable::ENOTSUP), | ||
"closing a preopened file descriptor", | ||
); | ||
|
||
// Try to renumber over a preopened directory handle. | ||
assert_eq!( | ||
wasi_unstable::fd_renumber(dir_fd, pre_fd), | ||
Err(wasi_unstable::ENOTSUP), | ||
"renumbering over a preopened file descriptor", | ||
); | ||
|
||
// Ensure that dir_fd is still open. | ||
let mut dir_fdstat: wasi_unstable::FdStat = mem::zeroed(); | ||
let mut status = wasi_fd_fdstat_get(dir_fd, &mut dir_fdstat); | ||
assert_eq!( | ||
status, | ||
wasi_unstable::raw::__WASI_ESUCCESS, | ||
"calling fd_fdstat on the scratch directory" | ||
); | ||
assert_eq!( | ||
dir_fdstat.fs_filetype, | ||
wasi_unstable::FILETYPE_DIRECTORY, | ||
"expected the scratch directory to be a directory", | ||
); | ||
|
||
// Try to renumber a preopened directory handle. | ||
assert_eq!( | ||
wasi_unstable::fd_renumber(pre_fd, dir_fd), | ||
Err(wasi_unstable::ENOTSUP), | ||
"renumbering over a preopened file descriptor", | ||
); | ||
|
||
// Ensure that dir_fd is still open. | ||
status = wasi_fd_fdstat_get(dir_fd, &mut dir_fdstat); | ||
assert_eq!( | ||
status, | ||
wasi_unstable::raw::__WASI_ESUCCESS, | ||
"calling fd_fdstat on the scratch directory" | ||
); | ||
assert_eq!( | ||
dir_fdstat.fs_filetype, | ||
wasi_unstable::FILETYPE_DIRECTORY, | ||
"expected the scratch directory to be a directory", | ||
); | ||
} | ||
|
||
fn main() { | ||
let mut args = env::args(); | ||
let prog = args.next().unwrap(); | ||
let arg = if let Some(arg) = args.next() { | ||
arg | ||
} else { | ||
eprintln!("usage: {} <scratch directory>", prog); | ||
process::exit(1); | ||
}; | ||
|
||
// Open scratch directory | ||
let dir_fd = match open_scratch_directory(&arg) { | ||
Ok(dir_fd) => dir_fd, | ||
Err(err) => { | ||
eprintln!("{}", err); | ||
process::exit(1) | ||
} | ||
}; | ||
|
||
// Run the tests. | ||
unsafe { test_close_preopen(dir_fd) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use std::{env, process}; | ||
use wasi::wasi_unstable; | ||
use wasi_misc_tests::open_scratch_directory; | ||
use wasi_misc_tests::utils::cleanup_file; | ||
use wasi_misc_tests::wasi_wrappers::{wasi_path_open, wasi_path_symlink}; | ||
|
||
unsafe fn test_dangling_symlink(dir_fd: wasi_unstable::Fd) { | ||
// First create a dangling symlink. | ||
assert!( | ||
wasi_path_symlink("target", dir_fd, "symlink").is_ok(), | ||
"creating a symlink" | ||
); | ||
|
||
// Try to open it as a directory with O_NOFOLLOW. | ||
let mut file_fd: wasi_unstable::Fd = wasi_unstable::Fd::max_value() - 1; | ||
let status = wasi_path_open( | ||
dir_fd, | ||
0, | ||
"symlink", | ||
wasi_unstable::O_DIRECTORY, | ||
0, | ||
0, | ||
0, | ||
&mut file_fd, | ||
); | ||
assert_eq!( | ||
status, | ||
wasi_unstable::raw::__WASI_ELOOP, | ||
"opening a dangling symlink as a directory", | ||
); | ||
assert_eq!( | ||
file_fd, | ||
wasi_unstable::Fd::max_value(), | ||
"failed open should set the file descriptor to -1", | ||
); | ||
|
||
// Clean up. | ||
cleanup_file(dir_fd, "symlink"); | ||
} | ||
|
||
fn main() { | ||
let mut args = env::args(); | ||
let prog = args.next().unwrap(); | ||
let arg = if let Some(arg) = args.next() { | ||
arg | ||
} else { | ||
eprintln!("usage: {} <scratch directory>", prog); | ||
process::exit(1); | ||
}; | ||
|
||
// Open scratch directory | ||
let dir_fd = match open_scratch_directory(&arg) { | ||
Ok(dir_fd) => dir_fd, | ||
Err(err) => { | ||
eprintln!("{}", err); | ||
process::exit(1) | ||
} | ||
}; | ||
|
||
// Run the tests. | ||
unsafe { test_dangling_symlink(dir_fd) } | ||
} |
Oops, something went wrong.