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

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