MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / run_test

Function run_test

tests/wasi.rs:152–255  ·  view source on GitHub ↗
(path: &Path, componentize: bool)

Source from the content-addressed store, hash-verified

150}
151
152fn run_test(path: &Path, componentize: bool) -> Result<()> {
153 let wasmtime = Path::new(env!("CARGO_BIN_EXE_wasmtime"));
154 let test_name = path.file_stem().unwrap().to_str().unwrap();
155 let target_dir = wasmtime.parent().unwrap().parent().unwrap();
156 let parent_dir = path.parent().ok_or(format_err!("module has no parent?"))?;
157 let spec = if let Ok(contents) = fs::read_to_string(&path.with_extension("json")) {
158 serde_json::from_str(&contents)?
159 } else {
160 Spec::default()
161 };
162
163 let mut td = TempDir::new_in(&target_dir)?;
164 td.disable_cleanup(true);
165 let path = if componentize {
166 let module = fs::read(path).expect("read wasm module");
167 let component = ComponentEncoder::default()
168 .module(module.as_slice())
169 .to_wasmtime_result()?
170 .validate(true)
171 .adapter(
172 "wasi_snapshot_preview1",
173 &fs::read(test_programs_artifacts::ADAPTER_COMMAND)?,
174 )
175 .to_wasmtime_result()?
176 .encode()
177 .to_wasmtime_result()?;
178 let stem = path.file_stem().unwrap().to_str().unwrap();
179 let component_path = td.path().join(format!("{stem}.component.wasm"));
180 fs::write(&component_path, component)?;
181 component_path
182 } else {
183 path.to_path_buf()
184 };
185
186 let Spec {
187 args,
188 dirs,
189 env,
190 exit_code: _,
191 stderr: _,
192 stdout: _,
193 } = &spec;
194 let mut cmd = wasmtime_test_util::command(wasmtime);
195 cmd.arg("run");
196 for dir in dirs {
197 cmd.arg("--dir");
198 let src = parent_dir.join(dir);
199 let dst = td.path().join(dir);
200 cp_r(&src, &dst)?;
201 cmd.arg(format!("{}::{dir}", dst.display()));
202 }
203 for (k, v) in env {
204 cmd.arg("--env");
205 cmd.arg(format!("{k}={v}"));
206 }
207 let mut should_fail = KNOWN_FAILURES.contains(&test_name);
208 if path.iter().any(|p| p == "wasm32-wasip3") {
209 cmd.arg("-Sp3,http").arg("-Wcomponent-model-async");

Callers 1

find_testsFunction · 0.70

Calls 15

read_to_stringFunction · 0.85
commandFunction · 0.85
cp_rFunction · 0.85
OkFunction · 0.85
to_strMethod · 0.80
to_wasmtime_resultMethod · 0.80
anyMethod · 0.80
outputMethod · 0.80
newFunction · 0.50
readFunction · 0.50
writeFunction · 0.50
unwrapMethod · 0.45

Tested by

no test coverage detected