mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-06 12:48:20 +00:00
This PR updates how we generate the WASI test suites to test against the `wasmer_vfs::host_fs` (the default), and `wasmer_vfs::mem_fs` (that's new).
43 lines
1.1 KiB
Rust
43 lines
1.1 KiB
Rust
use std::fs::File;
|
|
use std::io::Read;
|
|
use wasmer_wast::{WasiFileSystemKind, WasiTest};
|
|
|
|
// The generated tests (from build.rs) look like:
|
|
// #[cfg(test)]
|
|
// mod [compiler] {
|
|
// mod [spec] {
|
|
// mod [vfs] {
|
|
// #[test]
|
|
// fn [test_name]() -> anyhow::Result<()> {
|
|
// crate::run_wasi("tests/spectests/[test_name].wast", "[compiler]", WasiFileSystemKind::[vfs])
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
include!(concat!(env!("OUT_DIR"), "/generated_wasitests.rs"));
|
|
|
|
pub fn run_wasi(
|
|
config: crate::Config,
|
|
wast_path: &str,
|
|
base_dir: &str,
|
|
filesystem_kind: WasiFileSystemKind,
|
|
) -> anyhow::Result<()> {
|
|
println!("Running wasi wast `{}`", wast_path);
|
|
let store = config.store();
|
|
|
|
let source = {
|
|
let mut out = String::new();
|
|
let mut f = File::open(wast_path)?;
|
|
f.read_to_string(&mut out)?;
|
|
out
|
|
};
|
|
let tokens = WasiTest::lex_string(&source)?;
|
|
let wasi_test = WasiTest::parse_tokens(&tokens)?;
|
|
|
|
let succeeded = wasi_test.run(&store, base_dir, filesystem_kind)?;
|
|
|
|
assert!(succeeded);
|
|
|
|
Ok(())
|
|
}
|