Skip to content
This repository was archived by the owner on Nov 9, 2019. It is now read-only.

Commit 3793fa3

Browse files
authored
Merge wasi-misc-tests repo as a subdir (#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 #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] <support@dependabot.com> * Fix compilation error * Enable Actions and add rust.yml (#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 (#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 <maxim.vorobjov@gmail.com> * 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
1 parent 2fe3530 commit 3793fa3

40 files changed

+3525
-33
lines changed

.gitmodules

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[submodule "misc_testsuite"]
2-
path = misc_testsuite
3-
url = https://github.com/cranestation/wasi-misc-tests
41
[submodule "WASI"]
52
path = WASI
63
url = https://github.com/WebAssembly/WASI

Cargo.toml

+8-15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
[package]
22
name = "wasi-common"
33
version = "0.5.0"
4-
authors = [
5-
"Adam C. Foltzer <acfoltzer@fastly.com>",
6-
"Frank Denis <github@pureftpd.org>",
7-
"Jakub Konka <kubkon@jakubkonka.com>",
8-
"Dan Gohman <sunfish@mozilla.com>"]
4+
authors = ["The Wasmtime Project Developers"]
95
edition = "2018"
106
license = "Apache-2.0 WITH LLVM-exception"
117
description = "WASI implementation in Rust"
@@ -41,18 +37,15 @@ cpu-time = "1.0"
4137

4238

4339
[dev-dependencies]
44-
wasmtime-runtime = { git = "https://github.com/acfoltzer/wasmtime", rev = "d99e2fb" }
45-
wasmtime-environ = { git = "https://github.com/acfoltzer/wasmtime", rev = "d99e2fb" }
46-
wasmtime-jit = { git = "https://github.com/acfoltzer/wasmtime", rev = "d99e2fb" }
47-
wasmtime-wasi = { git = "https://github.com/acfoltzer/wasmtime", rev = "d99e2fb" }
48-
wasmtime-api = { git = "https://github.com/acfoltzer/wasmtime", rev = "d99e2fb" }
49-
cranelift-codegen = "0.47.0"
40+
wasmtime-runtime = { git = "https://github.com/CraneStation/wasmtime", rev = "ab3cd94" }
41+
wasmtime-environ = { git = "https://github.com/CraneStation/wasmtime", rev = "ab3cd94" }
42+
wasmtime-jit = { git = "https://github.com/CraneStation/wasmtime", rev = "ab3cd94" }
43+
wasmtime-wasi = { git = "https://github.com/CraneStation/wasmtime", rev = "ab3cd94" }
44+
wasmtime-api = { git = "https://github.com/CraneStation/wasmtime", rev = "ab3cd94" }
45+
cranelift-codegen = "0.49"
5046
target-lexicon = "0.8.1"
5147
pretty_env_logger = "0.3.0"
5248
tempfile = "3.1.0"
53-
# this is just a temp fix to make the tests build and run; I hope this to be
54-
# completely removed when we merge `wasi-common` into `wasmtime`
55-
faerie = "=0.11.0"
5649

5750
[patch."https://github.com/CraneStation/wasi-common"]
5851
wasi-common = { path = "." }
@@ -66,4 +59,4 @@ crate-type = ["rlib", "staticlib", "cdylib"]
6659

6760
[workspace]
6861
members = ["wasi-common-cbindgen"]
69-
exclude = ["winx", "misc_testsuite"]
62+
exclude = ["wasi-misc-tests", "wig", "winx", "WASI/tools/witx"]

build.rs

+7-13
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ mod wasm_tests {
2121

2222
pub(crate) fn build_and_generate_tests() {
2323
// Validate if any of test sources are present and if they changed
24-
let bin_tests = std::fs::read_dir("misc_testsuite/src/bin")
25-
.expect("wasm_tests feature requires initialized misc_testsuite: `git submodule update --init`?");
24+
// This should always work since there is no submodule to init anymore
25+
let bin_tests = std::fs::read_dir("wasi-misc-tests/src/bin").unwrap();
2626
for test in bin_tests {
2727
if let Ok(test_file) = test {
2828
let test_file_path = test_file
@@ -33,23 +33,17 @@ mod wasm_tests {
3333
println!("cargo:rerun-if-changed={}", test_file_path);
3434
}
3535
}
36-
3736
// Build tests to OUT_DIR (target/*/build/wasi-common-*/out/wasm32-wasi/release/*.wasm)
3837
let out_dir = PathBuf::from(
3938
env::var("OUT_DIR").expect("The OUT_DIR environment variable must be set"),
4039
);
41-
let mut out = File::create(out_dir.join("misc_testsuite_tests.rs"))
40+
let mut out = File::create(out_dir.join("wasi_misc_tests.rs"))
4241
.expect("error generating test source file");
43-
build_tests("misc_testsuite", &out_dir).expect("building tests");
44-
test_directory(&mut out, "misc_testsuite", &out_dir).expect("generating tests");
42+
build_tests("wasi-misc-tests", &out_dir).expect("building tests");
43+
test_directory(&mut out, "wasi-misc-tests", &out_dir).expect("generating tests");
4544
}
4645

4746
fn build_tests(testsuite: &str, out_dir: &Path) -> io::Result<()> {
48-
// if the submodule has not been checked out, the build will stall
49-
if !Path::new(&format!("{}/Cargo.toml", testsuite)).exists() {
50-
panic!("Testsuite {} not checked out", testsuite);
51-
}
52-
5347
let mut cmd = Command::new("cargo");
5448
cmd.args(&[
5549
"build",
@@ -191,7 +185,7 @@ mod wasm_tests {
191185
} else {
192186
/// Ignore tests that aren't supported yet.
193187
fn ignore(testsuite: &str, name: &str) -> bool {
194-
if testsuite == "misc_testsuite" {
188+
if testsuite == "wasi-misc-tests" {
195189
match name {
196190
"readlink_no_buffer" => true,
197191
"dangling_symlink" => true,
@@ -211,7 +205,7 @@ mod wasm_tests {
211205

212206
/// Mark tests which do not require preopens
213207
fn no_preopens(testsuite: &str, name: &str) -> bool {
214-
if testsuite == "misc_testsuite" {
208+
if testsuite == "wasi-misc-tests" {
215209
match name {
216210
"big_random_buf" => true,
217211
"clock_time_get" => true,

misc_testsuite

-1
This file was deleted.

tests/wasm_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ fn setup_log() {
1313
})
1414
}
1515

16-
include!(concat!(env!("OUT_DIR"), "/misc_testsuite_tests.rs"));
16+
include!(concat!(env!("OUT_DIR"), "/wasi_misc_tests.rs"));

wasi-misc-tests/Cargo.toml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "wasi-misc-tests"
3+
version = "0.1.0"
4+
authors = ["The Wasmtime Project Developers"]
5+
edition = "2018"
6+
publish = false
7+
8+
[dependencies]
9+
libc = "0.2.65"
10+
wasi = "0.7.0"
11+
more-asserts = "0.2.1"

wasi-misc-tests/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This is the `wasi-misc-test` crate, which contains source code for the system-level WASI tests.
2+
3+
Building these tests requires `wasm32-wasi` target installed
4+
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use wasi::wasi_unstable;
2+
3+
fn test_big_random_buf() {
4+
let mut buf = Vec::new();
5+
buf.resize(1024, 0);
6+
assert!(
7+
wasi_unstable::random_get(&mut buf).is_ok(),
8+
"calling get_random on a large buffer"
9+
);
10+
// Chances are pretty good that at least *one* byte will be non-zero in
11+
// any meaningful random function producing 1024 u8 values.
12+
assert!(buf.iter().any(|x| *x != 0), "random_get returned all zeros");
13+
}
14+
15+
fn main() {
16+
// Run the tests.
17+
test_big_random_buf()
18+
}
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use more_asserts::assert_le;
2+
use wasi::wasi_unstable;
3+
use wasi_misc_tests::wasi_wrappers::wasi_clock_time_get;
4+
5+
unsafe fn test_clock_time_get() {
6+
// Test that clock_time_get succeeds. Even in environments where it's not
7+
// desirable to expose high-precision timers, it should still succeed.
8+
// clock_res_get is where information about precision can be provided.
9+
let mut time: wasi_unstable::Timestamp = 0;
10+
let status = wasi_clock_time_get(wasi_unstable::CLOCK_MONOTONIC, 1, &mut time);
11+
assert_eq!(
12+
status,
13+
wasi_unstable::raw::__WASI_ESUCCESS,
14+
"clock_time_get with a precision of 1"
15+
);
16+
17+
let status = wasi_clock_time_get(wasi_unstable::CLOCK_MONOTONIC, 0, &mut time);
18+
assert_eq!(
19+
status,
20+
wasi_unstable::raw::__WASI_ESUCCESS,
21+
"clock_time_get with a precision of 0"
22+
);
23+
let first_time = time;
24+
25+
let status = wasi_clock_time_get(wasi_unstable::CLOCK_MONOTONIC, 0, &mut time);
26+
assert_eq!(
27+
status,
28+
wasi_unstable::raw::__WASI_ESUCCESS,
29+
"clock_time_get with a precision of 0"
30+
);
31+
assert_le!(first_time, time, "CLOCK_MONOTONIC should be monotonic");
32+
}
33+
34+
fn main() {
35+
// Run the tests.
36+
unsafe { test_clock_time_get() }
37+
}
+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
use libc;
2+
use more_asserts::assert_gt;
3+
use std::{env, mem, process};
4+
use wasi::wasi_unstable;
5+
use wasi_misc_tests::open_scratch_directory;
6+
use wasi_misc_tests::wasi_wrappers::wasi_fd_fdstat_get;
7+
8+
unsafe fn test_close_preopen(dir_fd: wasi_unstable::Fd) {
9+
let pre_fd: wasi_unstable::Fd = (libc::STDERR_FILENO + 1) as wasi_unstable::Fd;
10+
11+
assert_gt!(dir_fd, pre_fd, "dir_fd number");
12+
13+
// Try to close a preopened directory handle.
14+
assert_eq!(
15+
wasi_unstable::fd_close(pre_fd),
16+
Err(wasi_unstable::ENOTSUP),
17+
"closing a preopened file descriptor",
18+
);
19+
20+
// Try to renumber over a preopened directory handle.
21+
assert_eq!(
22+
wasi_unstable::fd_renumber(dir_fd, pre_fd),
23+
Err(wasi_unstable::ENOTSUP),
24+
"renumbering over a preopened file descriptor",
25+
);
26+
27+
// Ensure that dir_fd is still open.
28+
let mut dir_fdstat: wasi_unstable::FdStat = mem::zeroed();
29+
let mut status = wasi_fd_fdstat_get(dir_fd, &mut dir_fdstat);
30+
assert_eq!(
31+
status,
32+
wasi_unstable::raw::__WASI_ESUCCESS,
33+
"calling fd_fdstat on the scratch directory"
34+
);
35+
assert_eq!(
36+
dir_fdstat.fs_filetype,
37+
wasi_unstable::FILETYPE_DIRECTORY,
38+
"expected the scratch directory to be a directory",
39+
);
40+
41+
// Try to renumber a preopened directory handle.
42+
assert_eq!(
43+
wasi_unstable::fd_renumber(pre_fd, dir_fd),
44+
Err(wasi_unstable::ENOTSUP),
45+
"renumbering over a preopened file descriptor",
46+
);
47+
48+
// Ensure that dir_fd is still open.
49+
status = wasi_fd_fdstat_get(dir_fd, &mut dir_fdstat);
50+
assert_eq!(
51+
status,
52+
wasi_unstable::raw::__WASI_ESUCCESS,
53+
"calling fd_fdstat on the scratch directory"
54+
);
55+
assert_eq!(
56+
dir_fdstat.fs_filetype,
57+
wasi_unstable::FILETYPE_DIRECTORY,
58+
"expected the scratch directory to be a directory",
59+
);
60+
}
61+
62+
fn main() {
63+
let mut args = env::args();
64+
let prog = args.next().unwrap();
65+
let arg = if let Some(arg) = args.next() {
66+
arg
67+
} else {
68+
eprintln!("usage: {} <scratch directory>", prog);
69+
process::exit(1);
70+
};
71+
72+
// Open scratch directory
73+
let dir_fd = match open_scratch_directory(&arg) {
74+
Ok(dir_fd) => dir_fd,
75+
Err(err) => {
76+
eprintln!("{}", err);
77+
process::exit(1)
78+
}
79+
};
80+
81+
// Run the tests.
82+
unsafe { test_close_preopen(dir_fd) }
83+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
use std::{env, process};
2+
use wasi::wasi_unstable;
3+
use wasi_misc_tests::open_scratch_directory;
4+
use wasi_misc_tests::utils::cleanup_file;
5+
use wasi_misc_tests::wasi_wrappers::{wasi_path_open, wasi_path_symlink};
6+
7+
unsafe fn test_dangling_symlink(dir_fd: wasi_unstable::Fd) {
8+
// First create a dangling symlink.
9+
assert!(
10+
wasi_path_symlink("target", dir_fd, "symlink").is_ok(),
11+
"creating a symlink"
12+
);
13+
14+
// Try to open it as a directory with O_NOFOLLOW.
15+
let mut file_fd: wasi_unstable::Fd = wasi_unstable::Fd::max_value() - 1;
16+
let status = wasi_path_open(
17+
dir_fd,
18+
0,
19+
"symlink",
20+
wasi_unstable::O_DIRECTORY,
21+
0,
22+
0,
23+
0,
24+
&mut file_fd,
25+
);
26+
assert_eq!(
27+
status,
28+
wasi_unstable::raw::__WASI_ELOOP,
29+
"opening a dangling symlink as a directory",
30+
);
31+
assert_eq!(
32+
file_fd,
33+
wasi_unstable::Fd::max_value(),
34+
"failed open should set the file descriptor to -1",
35+
);
36+
37+
// Clean up.
38+
cleanup_file(dir_fd, "symlink");
39+
}
40+
41+
fn main() {
42+
let mut args = env::args();
43+
let prog = args.next().unwrap();
44+
let arg = if let Some(arg) = args.next() {
45+
arg
46+
} else {
47+
eprintln!("usage: {} <scratch directory>", prog);
48+
process::exit(1);
49+
};
50+
51+
// Open scratch directory
52+
let dir_fd = match open_scratch_directory(&arg) {
53+
Ok(dir_fd) => dir_fd,
54+
Err(err) => {
55+
eprintln!("{}", err);
56+
process::exit(1)
57+
}
58+
};
59+
60+
// Run the tests.
61+
unsafe { test_dangling_symlink(dir_fd) }
62+
}

0 commit comments

Comments
 (0)