Skip to content

Commit

Permalink
More debugging.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfishcode committed Mar 11, 2020
1 parent f6dfa00 commit 2e4535f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
11 changes: 10 additions & 1 deletion src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,11 @@ impl RunCommand {
.handle_module(&store, &module_registry)
.with_context(|| format!("failed to run main module `{}`", self.module.display()))
{
Ok(()) => (),
Ok(()) => {
eprintln!("ok!");
}
Err(e) => {
eprintln!("error: {:?}", e);
// If the program exited because of a trap, return an error code
// to the outside environment indicating a more severe problem
// than a simple failure.
Expand All @@ -139,6 +142,7 @@ impl RunCommand {
return Err(e);
}
}
eprintln!("all good");

Ok(())
}
Expand Down Expand Up @@ -227,27 +231,32 @@ impl RunCommand {
}

fn handle_module(&self, store: &Store, module_registry: &ModuleRegistry) -> Result<()> {
eprintln!("instantiating module...");
let (instance, module, data) =
Self::instantiate_module(store, module_registry, &self.module)?;

// If a function to invoke was given, invoke it.
if let Some(name) = self.invoke.as_ref() {
eprintln!("invoking {}...", name);
let data = ModuleData::new(&data)?;
self.invoke_export(instance, &data, name)?;
} else if module
.exports()
.iter()
.any(|export| export.name().is_empty())
{
eprintln!("invoking default command export...");
// Launch the default command export.
let data = ModuleData::new(&data)?;
self.invoke_export(instance, &data, "")?;
} else {
eprintln!("invoking the _start function...");
// If the module doesn't have a default command export, launch the
// _start function if one is present, as a compatibility measure.
let data = ModuleData::new(&data)?;
self.invoke_export(instance, &data, "_start")?;
}
eprintln!("success!");

Ok(())
}
Expand Down
22 changes: 17 additions & 5 deletions tests/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ fn run_wasmtime_for_output(args: &[&str]) -> Result<Output> {
me.pop(); // chop off the file name
me.pop(); // chop off `deps`
me.push("wasmtime");
Command::new(&me).args(args).output().map_err(Into::into)
Command::new(&me)
.args(args)
.env("RUST_LOG", "trace")
.output()
.map_err(Into::into)
}

// Run the wasmtime CLI with the provided args and, if it succeeds, return
Expand Down Expand Up @@ -85,21 +89,29 @@ fn run_wasmtime_simple_wat() -> Result<()> {
// Running a wat that traps.
#[test]
fn run_wasmtime_unreachable_wat() -> Result<()> {
dbg!("hi");
let wasm = build_wasm("tests/wasm/unreachable.wat")?;
dbg!("go");
let output = run_wasmtime_for_output(&[wasm.path().to_str().unwrap(), "--disable-cache"])?;

dbg!("yes");
eprintln!(
"stderr='{:?}' stdout='{:?}' status='{:?}'",
output.stderr, output.stdout, output.status
"stderr='{}' stdout='{}' status='{:?}'",
String::from_utf8_lossy(&output.stderr),
String::from_utf8_lossy(&output.stdout),
output.status
);
assert_ne!(output.stderr, b"");
assert_eq!(output.stdout, b"");
dbg!("printed");
assert_ne!(String::from_utf8_lossy(&output.stderr), "".to_owned());
assert_eq!(String::from_utf8_lossy(&output.stdout), "".to_owned());
assert!(!output.status.success());
dbg!("ok");

let code = output
.status
.code()
.expect("wasmtime process should exit normally");
dbg!("done");

// Test for the specific error code Wasmtime uses to indicate a trap return.
#[cfg(unix)]
Expand Down

0 comments on commit 2e4535f

Please sign in to comment.