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

Function run

cranelift/filetests/src/runone.rs:22–99  ·  view source on GitHub ↗

Load `path` and run the test in it. If running this test causes a panic, it will propagate as normal.

(
    path: &Path,
    passes: Option<&[String]>,
    target: Option<&str>,
)

Source from the content-addressed store, hash-verified

20///
21/// If running this test causes a panic, it will propagate as normal.
22pub fn run(
23 path: &Path,
24 passes: Option<&[String]>,
25 target: Option<&str>,
26) -> anyhow::Result<time::Duration> {
27 let _tt = timing::process_file();
28 info!("---\nFile: {}", path.to_string_lossy());
29 let started = time::Instant::now();
30 let buffer =
31 fs::read_to_string(path).with_context(|| format!("failed to read {}", path.display()))?;
32
33 let options = ParseOptions {
34 target,
35 passes,
36 machine_code_cfg_info: true,
37 ..ParseOptions::default()
38 };
39
40 let testfile = match parse_test(&buffer, options) {
41 Ok(testfile) => testfile,
42 Err(e) => {
43 if e.is_warning {
44 log::warn!(
45 "skipping test {:?} (line {}): {}",
46 path,
47 e.location.line_number,
48 e.message
49 );
50 return Ok(started.elapsed());
51 }
52 return Err(e).context(format!("failed to parse {}", path.display()));
53 }
54 };
55
56 if testfile.functions.is_empty() {
57 anyhow::bail!("no functions found");
58 }
59
60 // Parse the test commands.
61 let mut tests = testfile
62 .commands
63 .iter()
64 .map(new_subtest)
65 .collect::<anyhow::Result<Vec<_>>>()?;
66
67 // Flags to use for those tests that don't need an ISA.
68 // This is the cumulative effect of all the `set` commands in the file.
69 let flags = match testfile.isa_spec {
70 IsaSpec::None(ref f) => f,
71 IsaSpec::Some(ref v) => v.last().expect("Empty ISA list").flags(),
72 };
73
74 // Sort the tests so the mutators are at the end, and those that don't need the verifier are at
75 // the front.
76 tests.sort_by_key(|st| (st.is_mutating(), st.needs_verifier()));
77
78 // Expand the tests into (test, flags, isa) tuples.
79 let tuples = test_tuples(&tests, &testfile.isa_spec, flags)?;

Callers

nothing calls this directly

Calls 15

read_to_stringFunction · 0.85
parse_testFunction · 0.85
OkFunction · 0.85
test_tuplesFunction · 0.85
verify_testfileFunction · 0.85
with_contextMethod · 0.80
sort_by_keyMethod · 0.80
newFunction · 0.50
contextMethod · 0.45
is_emptyMethod · 0.45
mapMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected