From 21d7bed20e31e8892e8db1fd1d3081214be1f192 Mon Sep 17 00:00:00 2001 From: Christoph Herzog Date: Wed, 8 Mar 2023 12:26:42 +0100 Subject: [PATCH 1/2] refactor(wasi): Move capabilities into root submodule Just a small restructuring that moves the capabilities submodule from state into the root lib. Done because it is now exported in full rather than just partially from state::, and because it is a more generic module that will probably be moved out to a separate crate soon. --- lib/wasi/src/{state => }/capabilities.rs | 0 lib/wasi/src/http/client_impl.rs | 2 +- lib/wasi/src/lib.rs | 4 +++- lib/wasi/src/os/console/mod.rs | 2 +- lib/wasi/src/runners/wcgi/handler.rs | 3 ++- lib/wasi/src/state/builder.rs | 4 ++-- lib/wasi/src/state/env.rs | 3 ++- lib/wasi/src/state/mod.rs | 2 -- 8 files changed, 11 insertions(+), 9 deletions(-) rename lib/wasi/src/{state => }/capabilities.rs (100%) diff --git a/lib/wasi/src/state/capabilities.rs b/lib/wasi/src/capabilities.rs similarity index 100% rename from lib/wasi/src/state/capabilities.rs rename to lib/wasi/src/capabilities.rs diff --git a/lib/wasi/src/http/client_impl.rs b/lib/wasi/src/http/client_impl.rs index 078cdae6acd..6457c44968c 100644 --- a/lib/wasi/src/http/client_impl.rs +++ b/lib/wasi/src/http/client_impl.rs @@ -2,7 +2,7 @@ use std::string::FromUtf8Error; use std::sync::Arc; use crate::bindings::wasix_http_client_v1 as sys; -use crate::{Capabilities, WasiRuntime}; +use crate::{capabilities::Capabilities, WasiRuntime}; use crate::{ http::{DynHttpClient, HttpClientCapabilityV1}, diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index 927a0f24a6b..bb23dc35660 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -47,6 +47,8 @@ mod syscalls; mod utils; pub mod wapm; +pub mod capabilities; + /// WAI based bindings. mod bindings; @@ -106,7 +108,7 @@ pub use crate::utils::is_wasix_module; pub use crate::{ state::{ - Capabilities, WasiEnv, WasiEnvBuilder, WasiEnvInit, WasiFunctionEnv, WasiInstanceHandles, + WasiEnv, WasiEnvBuilder, WasiEnvInit, WasiFunctionEnv, WasiInstanceHandles, WasiStateCreationError, ALL_RIGHTS, }, syscalls::types, diff --git a/lib/wasi/src/os/console/mod.rs b/lib/wasi/src/os/console/mod.rs index 57fa7e7a51b..094b2d9fe83 100644 --- a/lib/wasi/src/os/console/mod.rs +++ b/lib/wasi/src/os/console/mod.rs @@ -27,8 +27,8 @@ use wasmer_wasi_types::{types::__WASI_STDIN_FILENO, wasi::BusErrno}; use super::{cconst::ConsoleConst, common::*, task::TaskJoinHandle}; use crate::{ bin_factory::{spawn_exec, BinFactory, ModuleCache}, + capabilities::Capabilities, os::task::{control_plane::WasiControlPlane, process::WasiProcess}, - state::Capabilities, VirtualBusError, VirtualTaskManagerExt, WasiEnv, WasiRuntime, }; diff --git a/lib/wasi/src/runners/wcgi/handler.rs b/lib/wasi/src/runners/wcgi/handler.rs index 06a8a5460cc..aa5bd5d47dd 100644 --- a/lib/wasi/src/runners/wcgi/handler.rs +++ b/lib/wasi/src/runners/wcgi/handler.rs @@ -20,9 +20,10 @@ use wasmer_vfs::{FileSystem, PassthruFileSystem, RootFileSystemBuilder, TmpFileS use wcgi_host::CgiDialect; use crate::{ + capabilities::Capabilities, http::HttpClientCapabilityV1, runners::wcgi::{Callbacks, MappedDirectory}, - Capabilities, Pipe, PluggableRuntimeImplementation, VirtualTaskManager, WasiEnv, + Pipe, PluggableRuntimeImplementation, VirtualTaskManager, WasiEnv, }; /// The shared object that manages the instantiaion of WASI executables and diff --git a/lib/wasi/src/state/builder.rs b/lib/wasi/src/state/builder.rs index 2a05886557a..fb86ecc7f15 100644 --- a/lib/wasi/src/state/builder.rs +++ b/lib/wasi/src/state/builder.rs @@ -13,12 +13,12 @@ use wasmer_vfs::{ArcFile, FsError, TmpFileSystem, VirtualFile}; use crate::{ bin_factory::{BinFactory, ModuleCache}, + capabilities::Capabilities, fs::{WasiFs, WasiFsRoot, WasiInodes}, os::task::control_plane::{ControlPlaneConfig, ControlPlaneError, WasiControlPlane}, state::WasiState, syscalls::types::{__WASI_STDERR_FILENO, __WASI_STDIN_FILENO, __WASI_STDOUT_FILENO}, - Capabilities, PluggableRuntimeImplementation, WasiEnv, WasiFunctionEnv, WasiRuntime, - WasiRuntimeError, + PluggableRuntimeImplementation, WasiEnv, WasiFunctionEnv, WasiRuntime, WasiRuntimeError, }; use super::env::WasiEnvInit; diff --git a/lib/wasi/src/state/env.rs b/lib/wasi/src/state/env.rs index d39873f4775..83830d55a47 100644 --- a/lib/wasi/src/state/env.rs +++ b/lib/wasi/src/state/env.rs @@ -18,6 +18,7 @@ use wasmer_wasi_types::{ use crate::{ bin_factory::{BinFactory, ModuleCache}, + capabilities::Capabilities, fs::{WasiFsRoot, WasiInodes}, import_object_for_all_wasi_versions, os::{ @@ -35,7 +36,7 @@ use crate::{ DEFAULT_STACK_SIZE, }; -use super::{Capabilities, WasiState}; +use super::WasiState; /// Various [`TypedFunction`] and [`Global`] handles for an active WASI(X) instance. /// diff --git a/lib/wasi/src/state/mod.rs b/lib/wasi/src/state/mod.rs index 0fca7b274ea..ef3316eb839 100644 --- a/lib/wasi/src/state/mod.rs +++ b/lib/wasi/src/state/mod.rs @@ -16,7 +16,6 @@ #![allow(clippy::cognitive_complexity, clippy::too_many_arguments)] mod builder; -mod capabilities; mod env; mod func_env; mod types; @@ -39,7 +38,6 @@ use wasmer_wasi_types::wasi::{Errno, Fd as WasiFd, Rights, Snapshot0Clockid}; pub use self::{ builder::*, - capabilities::Capabilities, env::{WasiEnv, WasiEnvInit, WasiInstanceHandles}, func_env::WasiFunctionEnv, types::*, From 5834d165080acb020cf5717cae1f88aa1c1e1204 Mon Sep 17 00:00:00 2001 From: Christoph Herzog Date: Mon, 13 Mar 2023 13:33:26 +0100 Subject: [PATCH 2/2] tests: Disable two flaky snapshot tests --- tests/integration/cli/tests/snapshot.rs | 34 +++++++++++++------------ 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/tests/integration/cli/tests/snapshot.rs b/tests/integration/cli/tests/snapshot.rs index a70dfab409c..e1dfa2d9faf 100644 --- a/tests/integration/cli/tests/snapshot.rs +++ b/tests/integration/cli/tests/snapshot.rs @@ -303,16 +303,17 @@ fn test_snapshot_cowsay() { // assert_json_snapshot!(snapshot); // } +// FIXME: re-enable, disabled due to flakyness // The ability to fork the current process and run a different image but retain // the existing open file handles (which is needed for stdin and stdout redirection) -#[cfg(not(target_os = "windows"))] -#[test] -fn test_snapshot_fork_and_exec() { - let snapshot = TestBuilder::new() - .use_coreutils() - .run_wasm(include_bytes!("./wasm/example-execve.wasm")); - assert_json_snapshot!(snapshot); -} +// #[cfg(not(target_os = "windows"))] +// #[test] +// fn test_snapshot_fork_and_exec() { +// let snapshot = TestBuilder::new() +// .use_coreutils() +// .run_wasm(include_bytes!("./wasm/example-execve.wasm")); +// assert_json_snapshot!(snapshot); +// } // longjmp is used by C programs that save and restore the stack at specific // points - this functionality is often used for exception handling @@ -379,15 +380,16 @@ fn test_snapshot_sleep() { assert_json_snapshot!(snapshot); } +// FIXME: re-enable, disabled due to flakyness // Uses `posix_spawn` to launch a sub-process and wait on it to exit -#[cfg(not(target_os = "windows"))] -#[test] -fn test_snapshot_process_spawn() { - let snapshot = TestBuilder::new() - .use_coreutils() - .run_wasm(include_bytes!("./wasm/example-spawn.wasm")); - assert_json_snapshot!(snapshot); -} +// #[cfg(not(target_os = "windows"))] +// #[test] +// fn test_snapshot_process_spawn() { +// let snapshot = TestBuilder::new() +// .use_coreutils() +// .run_wasm(include_bytes!("./wasm/example-spawn.wasm")); +// assert_json_snapshot!(snapshot); +// } // FIXME: re-enable - hangs on windows and macos // Connects to 8.8.8.8:53 over TCP to verify TCP clients work