test-programs: learn how to preopen a dir again

This commit is contained in:
Pat Hickey
2020-12-11 16:38:55 -08:00
parent 30d49d122c
commit 759455192b
4 changed files with 51 additions and 42 deletions

63
Cargo.lock generated
View File

@@ -207,12 +207,12 @@ checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
[[package]]
name = "cap-fs-ext"
version = "0.7.0"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "724c2735539ad3ab51f04a0d84bca8c23398e558e810254a6996867fd6c7db81"
checksum = "eac51b267ca1f2abe043f6193ff8ef119cdcfd46f10a1644c76d41daf55a5b73"
dependencies = [
"cap-primitives",
"cap-std",
"cap-primitives 0.8.0",
"cap-std 0.8.0",
]
[[package]]
@@ -226,7 +226,23 @@ dependencies = [
"ipnet",
"libc",
"once_cell",
"posish 0.5.2",
"posish",
"winapi",
"winx 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cap-primitives"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43639eaff5966a4904bf0441ad4b6a8169b463e58f0cb34140dc8555d387b699"
dependencies = [
"errno",
"fs-set-times",
"ipnet",
"libc",
"once_cell",
"posish",
"winapi",
"winx 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -237,7 +253,16 @@ version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0760daa4e6270daa9c5c6ad133108fb77edfe023a019c392d98dd769defa42d5"
dependencies = [
"cap-primitives",
"cap-primitives 0.7.0",
]
[[package]]
name = "cap-std"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9d28ff1a5e60755c62be712baf75794892eb63a8b5bc5c4a7911b3549333e96"
dependencies = [
"cap-primitives 0.8.0",
]
[[package]]
@@ -934,11 +959,11 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "fs-set-times"
version = "0.2.1"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a37c11eb7933093dd2a56c9c4d934a754b56e672fb8c2b46d50997dd2b4392d"
checksum = "08b6f6626f73621230f712be2ee1a9e70bf3d7f38ffbd75a80b8ed0d925d1df1"
dependencies = [
"posish 0.4.1",
"posish",
"winapi",
]
@@ -1509,19 +1534,6 @@ version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c917123afa01924fc84bb20c4c03f004d9c38e5127e3c039bbf7f4b9c76a2f6b"
[[package]]
name = "posish"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a81e5017f1c873447782cd776e6ec307af670ecad29e934042005a0dec6864dd"
dependencies = [
"bitflags",
"cfg-if 1.0.0",
"errno",
"itoa",
"libc",
]
[[package]]
name = "posish"
version = "0.5.2"
@@ -2076,7 +2088,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95457b1e5a9657ffd02a43048aeb083f20848d82176c0e1313facc1a23ba74da"
dependencies = [
"atty",
"posish 0.5.2",
"posish",
"winapi",
"winx 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -2135,6 +2147,7 @@ name = "test-programs"
version = "0.19.0"
dependencies = [
"anyhow",
"cap-std 0.8.0",
"cfg-if 1.0.0",
"os_pipe",
"pretty_env_logger",
@@ -2378,7 +2391,7 @@ version = "0.21.0"
dependencies = [
"anyhow",
"cap-fs-ext",
"cap-std",
"cap-std 0.8.0",
"cfg-if 1.0.0",
"fs-set-times",
"getrandom 0.2.0",
@@ -2394,7 +2407,7 @@ name = "wasi-c2-wasmtime"
version = "0.21.0"
dependencies = [
"anyhow",
"cap-std",
"cap-std 0.7.0",
"wasi-c2",
"wasmtime",
"wasmtime-wiggle",

View File

@@ -19,6 +19,7 @@ tempfile = "3.1.0"
os_pipe = "0.9"
anyhow = "1.0.19"
wat = "1.0.23"
cap-std = "0.8"
[features]
test_programs = []

View File

@@ -144,7 +144,11 @@ mod wasi_tests {
let workspace = if no_preopens(testsuite, stemstr) {
"None"
} else {
"Some(std::path::Path::new(&bin_name))"
writeln!(
out,
" let workspace = utils::prepare_workspace(&bin_name)?;"
)?;
"Some(workspace.path())"
};
writeln!(
out,

View File

@@ -14,22 +14,13 @@ pub fn instantiate(data: &[u8], bin_name: &str, workspace: Option<&Path>) -> any
builder.arg(bin_name)?.arg(".")?.inherit_stdio();
/*
if let Some(workspace) = workspace {
match preopen_type {
PreopenType::OS => {
let preopen_dir = wasi_common::preopen_dir(workspace)
.context(format!("error while preopening {:?}", workspace))?;
builder.preopened_dir(preopen_dir, ".");
}
PreopenType::Virtual => {
// we can ignore the workspace path for virtual preopens because virtual preopens
// don't exist in the filesystem anyway - no name conflict concerns.
builder.preopened_virt(VirtualDirEntry::empty_directory(), ".");
}
}
}
*/
if let Some(workspace) = workspace {
let dirfd =
File::open(workspace).context(format!("error while preopening {:?}", workspace))?;
let preopen_dir = unsafe { cap_std::fs::Dir::from_std_file(dirfd) };
builder.preopened_dir(Box::new(preopen_dir), ".")?;
}
/*
// The nonstandard thing we do with `WasiCtxBuilder` is to ensure that
// `stdin` is always an unreadable pipe. This is expected in the test suite