Skip to content

Commit

Permalink
Add lldb smoke test (#1241)
Browse files Browse the repository at this point in the history
* add lldb runner

* don't build wasmtime

* use brew's lldb

* disable for macos

* set LLDB on linux

* re-org gh actions and cfg

* address feedback
  • Loading branch information
yurydelendik authored Mar 9, 2020
1 parent e5b9f1b commit 7ce1019
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 4 deletions.
3 changes: 0 additions & 3 deletions .github/actions/define-dwarfdump-env/README.md

This file was deleted.

3 changes: 3 additions & 0 deletions .github/actions/define-llvm-env/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# define-llvm-env

Defines `DWARFDUMP` and `LLDB` path executable.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
// On OSX pointing to brew's LLVM location.
if (process.platform == 'darwin') {
console.log("::set-env name=DWARFDUMP::/usr/local/opt/llvm/bin/llvm-dwarfdump");
console.log("::set-env name=LLDB::/usr/local/opt/llvm/bin/lldb");
}

// On Linux pointing to specific version
if (process.platform == 'linux') {
console.log("::set-env name=DWARFDUMP::/usr/bin/llvm-dwarfdump-9");
console.log("::set-env name=LLDB::/usr/bin/lldb-9");
}
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ jobs:
- uses: ./.github/actions/install-rust
with:
toolchain: ${{ matrix.rust }}
- uses: ./.github/actions/define-dwarfdump-env
- uses: ./.github/actions/define-llvm-env

- name: Install libclang
# Note: libclang is pre-installed on the macOS and linux images.
Expand Down Expand Up @@ -202,6 +202,7 @@ jobs:

# Test debug (DWARF) related functionality.
- run: cargo test test_debug_dwarf_ -- --ignored --nocapture --test-threads 1
if: matrix.os == 'ubuntu-latest'
env:
RUST_BACKTRACE: 1
RUSTFLAGS: "-D warnings"
Expand Down
94 changes: 94 additions & 0 deletions tests/debug/lldb.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#![allow(dead_code)]

use anyhow::{bail, format_err, Result};
use filecheck::{CheckerBuilder, NO_VARIABLES};
use std::env;
use std::io::Write;
use std::process::Command;
use tempfile::NamedTempFile;

fn lldb_with_script(args: &[&str], script: &str) -> Result<String> {
let lldb_path = env::var("LLDB").unwrap_or("lldb".to_string());
let mut cmd = Command::new(&lldb_path);

cmd.arg("--batch");
if cfg!(target_os = "macos") {
cmd.args(&["-o", "settings set plugin.jit-loader.gdb.enable on"]);
}
let mut script_file = NamedTempFile::new()?;
script_file.write(script.as_bytes())?;
let script_path = script_file.path().to_str().unwrap();
cmd.args(&["-s", &script_path]);

let mut me = std::env::current_exe().expect("current_exe specified");
me.pop(); // chop off the file name
me.pop(); // chop off `deps`
me.push("wasmtime");
cmd.arg(me);

cmd.arg("--");
cmd.args(args);

let output = cmd.output().expect("success");
if !output.status.success() {
bail!(
"failed to execute {:?}: {}",
cmd,
String::from_utf8_lossy(&output.stderr),
);
}
Ok(String::from_utf8(output.stdout)?)
}

fn check_lldb_output(output: &str, directives: &str) -> Result<()> {
let mut builder = CheckerBuilder::new();
builder
.text(directives)
.map_err(|e| format_err!("unable to build checker: {:?}", e))?;
let checker = builder.finish();
let check = checker
.explain(output, NO_VARIABLES)
.map_err(|e| format_err!("{:?}", e))?;
assert!(check.0, "didn't pass check {}", check.1);
Ok(())
}

#[test]
#[ignore]
#[cfg(all(
any(target_os = "linux", target_os = "macos"),
target_pointer_width = "64"
))]
pub fn test_debug_dwarf_lldb() -> Result<()> {
let output = lldb_with_script(
&[
"-g",
"tests/debug/testsuite/fib-wasm.wasm",
"--invoke",
"fib",
"3",
],
r#"b fib
r
fr v
c"#,
)?;

check_lldb_output(
&output,
r#"
check: Breakpoint 1: no locations (pending)
check: Unable to resolve breakpoint to any actual locations.
check: 1 location added to breakpoint 1
check: stop reason = breakpoint 1.1
check: frame #0
sameln: JIT
sameln: fib(n=3)
check: n = 3
check: a = 0
check: resuming
check: exited with status
"#,
)?;
Ok(())
}
1 change: 1 addition & 0 deletions tests/debug/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod dump;
mod lldb;
mod obj;
mod simulate;
mod translate;

0 comments on commit 7ce1019

Please sign in to comment.