From 31fc3d12bdf9e34cdb27776f644ebb996c2c882a Mon Sep 17 00:00:00 2001 From: Christoph Herzog Date: Sun, 15 Sep 2024 07:28:31 +0200 Subject: [PATCH] tests: Add WasiRunner file system mounting tests --- lib/wasix/src/runners/wasi.rs | 88 ++++++++++++++++++ ...-tests--volume-static-webserver@0.1.0.webc | Bin 0 -> 4634 bytes 2 files changed, 88 insertions(+) create mode 100644 tests/integration/cli/tests/webc/wasmer-tests--volume-static-webserver@0.1.0.webc diff --git a/lib/wasix/src/runners/wasi.rs b/lib/wasix/src/runners/wasi.rs index 7713b80f6d2..9837b4a2102 100644 --- a/lib/wasix/src/runners/wasi.rs +++ b/lib/wasix/src/runners/wasi.rs @@ -448,4 +448,92 @@ mod tests { assert_send::(); assert_sync::(); } + + #[tokio::test] + async fn test_volume_mount_without_webcs() { + use std::sync::Arc; + + let root_fs = virtual_fs::RootFileSystemBuilder::new().build(); + + let tokrt = tokio::runtime::Handle::current(); + + let hostdir = virtual_fs::host_fs::FileSystem::new(tokrt.clone(), "/").unwrap(); + let hostdir_dyn: Arc = Arc::new(hostdir); + + root_fs + .mount("/host".into(), &hostdir_dyn, "/".into()) + .unwrap(); + + let envb = crate::runners::wasi::WasiRunner::new(); + + let annotations = webc::metadata::annotations::Wasi::new("test"); + + let tm = Arc::new(crate::runtime::task_manager::tokio::TokioTaskManager::new( + tokrt.clone(), + )); + let rt = crate::PluggableRuntime::new(tm); + + let envb = envb + .prepare_webc_env("test", &annotations, None, Arc::new(rt), Some(root_fs)) + .unwrap(); + + let init = envb.build_init().unwrap(); + + let fs = &init.state.fs.root_fs; + + fs.read_dir(&std::path::Path::new("/host")).unwrap(); + } + + #[tokio::test] + async fn test_volume_mount_with_webcs() { + use std::sync::Arc; + + let root_fs = virtual_fs::RootFileSystemBuilder::new().build(); + + let tokrt = tokio::runtime::Handle::current(); + + let hostdir = virtual_fs::host_fs::FileSystem::new(tokrt.clone(), "/").unwrap(); + let hostdir_dyn: Arc = Arc::new(hostdir); + + root_fs + .mount("/host".into(), &hostdir_dyn, "/".into()) + .unwrap(); + + let envb = crate::runners::wasi::WasiRunner::new(); + + let annotations = webc::metadata::annotations::Wasi::new("test"); + + let tm = Arc::new(crate::runtime::task_manager::tokio::TokioTaskManager::new( + tokrt.clone(), + )); + let mut rt = crate::PluggableRuntime::new(tm); + rt.set_package_loader(crate::runtime::package_loader::BuiltinPackageLoader::new()); + + let webc_path = std::path::PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()).join("../../tests/integration/cli/tests/webc/wasmer-tests--volume-static-webserver@0.1.0.webc"); + let webc_data = std::fs::read(webc_path).unwrap(); + let container = webc::Container::from_bytes(webc_data).unwrap(); + + let binpkg = crate::bin_factory::BinaryPackage::from_webc(&container, &rt) + .await + .unwrap(); + + let mut envb = envb + .prepare_webc_env( + "test", + &annotations, + Some(&binpkg), + Arc::new(rt), + Some(root_fs), + ) + .unwrap(); + + envb = envb.preopen_dir("/host").unwrap(); + + let init = envb.build_init().unwrap(); + + let fs = &init.state.fs.root_fs; + + fs.read_dir(&std::path::Path::new("/host")).unwrap(); + fs.read_dir(&std::path::Path::new("/settings")).unwrap(); + } } diff --git a/tests/integration/cli/tests/webc/wasmer-tests--volume-static-webserver@0.1.0.webc b/tests/integration/cli/tests/webc/wasmer-tests--volume-static-webserver@0.1.0.webc new file mode 100644 index 0000000000000000000000000000000000000000..ca28cc71e5dd45fc1ba9c7925f23eeb02fa9690d GIT binary patch literal 4634 zcmcIoZEPGz8E!s+_Gm#x6;0G89o^9;F`nDA)1;PLquNf=AneAqoune9&D`$n-q^c4 zo0-|WbCVW`1VX5gN~H>EL8Wdae$Yk;@gosR#79t(kRm{ZKM1t~eu0qqEK;ci?>oDD zK7U~&760(%zHXv@jN^+WwvhI>xMku zy5Y+Wx53?6oksJnVSy~ZQQctud-n1s3se3m>3iq&c6I5!pTGHsKm7yQ_s8D&%`IDB zPp*9E(hq+7`jy+hevUIEBfVI~rfaBT%M@1DM+2mX5I&#wec8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