From dfcdbfd0fe63d6641f7f9ea92368213f07d9bd15 Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Fri, 11 Dec 2020 15:50:35 -0800 Subject: [PATCH] test-programs: no longer test virtfs separately wasi-c2 does not have a virtfs yet, and when it does we'll design a better test harness also fix prestat get: i was reporting the wrong error --- crates/test-programs/build.rs | 90 ++----------------- .../test-programs/tests/wasm_tests/runtime.rs | 15 +--- crates/wasi-c2/src/snapshots/preview_1.rs | 2 +- 3 files changed, 8 insertions(+), 99 deletions(-) diff --git a/crates/test-programs/build.rs b/crates/test-programs/build.rs index 93f60ae649..8260a77aee 100644 --- a/crates/test-programs/build.rs +++ b/crates/test-programs/build.rs @@ -16,14 +16,6 @@ mod wasi_tests { use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; - #[derive(Clone, Copy, Debug)] - enum PreopenType { - /// Preopens should be satisfied with real OS files. - OS, - /// Preopens should be satisfied with virtual files. - Virtual, - } - pub(super) fn build_and_generate_tests() { // Validate if any of test sources are present and if they changed // This should always work since there is no submodule to init anymore @@ -111,7 +103,6 @@ mod wasi_tests { .replace("-", "_") )?; writeln!(out, " use super::{{runtime, utils, setup_log}};")?; - writeln!(out, " use runtime::PreopenType;")?; for dir_entry in dir_entries { let test_path = dir_entry.path(); let stemstr = test_path @@ -120,23 +111,13 @@ mod wasi_tests { .to_str() .expect("to_str"); - if no_preopens(testsuite, stemstr) { - write_testsuite_tests(out, &test_path, testsuite, PreopenType::OS)?; - } else { - write_testsuite_tests(out, &test_path, testsuite, PreopenType::OS)?; - write_testsuite_tests(out, &test_path, testsuite, PreopenType::Virtual)?; - } + write_testsuite_tests(out, &test_path, testsuite)?; } writeln!(out, "}}")?; Ok(()) } - fn write_testsuite_tests( - out: &mut File, - path: &Path, - testsuite: &str, - preopen_type: PreopenType, - ) -> io::Result<()> { + fn write_testsuite_tests(out: &mut File, path: &Path, testsuite: &str) -> io::Result<()> { let stemstr = path .file_stem() .expect("file_stem") @@ -144,15 +125,7 @@ mod wasi_tests { .expect("to_str"); writeln!(out, " #[test]")?; - let test_fn_name = format!( - "{}{}", - &stemstr.replace("-", "_"), - if let PreopenType::Virtual = preopen_type { - "_virtualfs" - } else { - "" - } - ); + let test_fn_name = stemstr.replace("-", "_"); if ignore(testsuite, &test_fn_name) { writeln!(out, " #[ignore]")?; } @@ -171,25 +144,12 @@ mod wasi_tests { let workspace = if no_preopens(testsuite, stemstr) { "None" } else { - match preopen_type { - PreopenType::OS => { - writeln!( - out, - " let workspace = utils::prepare_workspace(&bin_name)?;" - )?; - "Some(workspace.path())" - } - PreopenType::Virtual => "Some(std::path::Path::new(&bin_name))", - } + "Some(std::path::Path::new(&bin_name))" }; writeln!( out, - " runtime::instantiate(&data, &bin_name, {}, {})", + " runtime::instantiate(&data, &bin_name, {})", workspace, - match preopen_type { - PreopenType::OS => "PreopenType::OS", - PreopenType::Virtual => "PreopenType::Virtual", - } )?; writeln!(out, " }}")?; writeln!(out)?; @@ -201,27 +161,7 @@ mod wasi_tests { /// Ignore tests that aren't supported yet. fn ignore(testsuite: &str, name: &str) -> bool { if testsuite == "wasi-tests" { - match name { - // TODO: virtfs files cannot be poll_oneoff'd yet - "poll_oneoff_virtualfs" => true, - // TODO: virtfs does not support filetimes yet. - "path_filestat_virtualfs" | - "fd_filestat_set_virtualfs" => true, - // TODO: virtfs does not support symlinks yet. - "nofollow_errors_virtualfs" | - "path_link_virtualfs" | - "readlink_virtualfs" | - "readlink_no_buffer_virtualfs" | - "dangling_symlink_virtualfs" | - "symlink_loop_virtualfs" | - "path_symlink_trailing_slashes_virtualfs" => true, - // TODO: virtfs does not support rename yet. - "path_rename_trailing_slashes_virtualfs" | - "path_rename_virtualfs" => true, - // TODO: virtfs does not support truncation yet. - "file_truncation_virtualfs" => true, - _ => false, - } + false } else { unreachable!() } @@ -236,24 +176,6 @@ mod wasi_tests { "symlink_loop" => true, "truncation_rights" => true, "dangling_fd" => true, - // TODO: virtfs files cannot be poll_oneoff'd yet - "poll_oneoff_virtualfs" => true, - // TODO: virtfs does not support filetimes yet. - "path_filestat_virtualfs" | - "fd_filestat_set_virtualfs" => true, - // TODO: virtfs does not support symlinks yet. - "nofollow_errors_virtualfs" | - "path_link_virtualfs" | - "readlink_virtualfs" | - "readlink_no_buffer_virtualfs" | - "dangling_symlink_virtualfs" | - "symlink_loop_virtualfs" | - "path_symlink_trailing_slashes_virtualfs" => true, - // TODO: virtfs does not support rename yet. - "path_rename_trailing_slashes_virtualfs" | - "path_rename_virtualfs" => true, - // TODO: virtfs does not support truncation yet. - "file_truncation_virtualfs" => true, _ => false, } } else { diff --git a/crates/test-programs/tests/wasm_tests/runtime.rs b/crates/test-programs/tests/wasm_tests/runtime.rs index f1509a4f46..9082517703 100644 --- a/crates/test-programs/tests/wasm_tests/runtime.rs +++ b/crates/test-programs/tests/wasm_tests/runtime.rs @@ -5,20 +5,7 @@ use std::path::Path; use wasi_c2::WasiCtx; use wasmtime::{Linker, Module, Store}; -#[derive(Clone, Copy, Debug)] -pub enum PreopenType { - /// Preopens should be satisfied with real OS files. - OS, - /// Preopens should be satisfied with virtual files. - Virtual, -} - -pub fn instantiate( - data: &[u8], - bin_name: &str, - workspace: Option<&Path>, - preopen_type: PreopenType, -) -> anyhow::Result<()> { +pub fn instantiate(data: &[u8], bin_name: &str, workspace: Option<&Path>) -> anyhow::Result<()> { let store = Store::default(); // Create our wasi context with pretty standard arguments/inheritance/etc. diff --git a/crates/wasi-c2/src/snapshots/preview_1.rs b/crates/wasi-c2/src/snapshots/preview_1.rs index 8f53f91135..65e6c68305 100644 --- a/crates/wasi-c2/src/snapshots/preview_1.rs +++ b/crates/wasi-c2/src/snapshots/preview_1.rs @@ -395,7 +395,7 @@ impl<'a> wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx { fn fd_prestat_get(&self, fd: types::Fd) -> Result { let table = self.table(); - let dir_entry: RefMut = table.get(u32::from(fd)).map_err(|_| Error::Notdir)?; + let dir_entry: RefMut = table.get(u32::from(fd)).map_err(|_| Error::Badf)?; if let Some(ref preopen) = dir_entry.preopen_path { let path_str = preopen.to_str().ok_or(Error::Notsup)?; let pr_name_len =