Skip to content

Commit 7ce1019

Browse files
authored
Add lldb smoke test (#1241)
* 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
1 parent e5b9f1b commit 7ce1019

7 files changed

Lines changed: 102 additions & 4 deletions

File tree

‎.github/actions/define-dwarfdump-env/README.md‎

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# define-llvm-env
2+
3+
Defines `DWARFDUMP` and `LLDB` path executable.
File renamed without changes.

.github/actions/define-dwarfdump-env/main.js renamed to .github/actions/define-llvm-env/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
// On OSX pointing to brew's LLVM location.
44
if (process.platform == 'darwin') {
55
console.log("::set-env name=DWARFDUMP::/usr/local/opt/llvm/bin/llvm-dwarfdump");
6+
console.log("::set-env name=LLDB::/usr/local/opt/llvm/bin/lldb");
67
}
78

89
// On Linux pointing to specific version
910
if (process.platform == 'linux') {
1011
console.log("::set-env name=DWARFDUMP::/usr/bin/llvm-dwarfdump-9");
12+
console.log("::set-env name=LLDB::/usr/bin/lldb-9");
1113
}

‎.github/workflows/main.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ jobs:
164164
- uses: ./.github/actions/install-rust
165165
with:
166166
toolchain: ${{ matrix.rust }}
167-
- uses: ./.github/actions/define-dwarfdump-env
167+
- uses: ./.github/actions/define-llvm-env
168168

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

203203
# Test debug (DWARF) related functionality.
204204
- run: cargo test test_debug_dwarf_ -- --ignored --nocapture --test-threads 1
205+
if: matrix.os == 'ubuntu-latest'
205206
env:
206207
RUST_BACKTRACE: 1
207208
RUSTFLAGS: "-D warnings"

‎tests/debug/lldb.rs‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#![allow(dead_code)]
2+
3+
use anyhow::{bail, format_err, Result};
4+
use filecheck::{CheckerBuilder, NO_VARIABLES};
5+
use std::env;
6+
use std::io::Write;
7+
use std::process::Command;
8+
use tempfile::NamedTempFile;
9+
10+
fn lldb_with_script(args: &[&str], script: &str) -> Result<String> {
11+
let lldb_path = env::var("LLDB").unwrap_or("lldb".to_string());
12+
let mut cmd = Command::new(&lldb_path);
13+
14+
cmd.arg("--batch");
15+
if cfg!(target_os = "macos") {
16+
cmd.args(&["-o", "settings set plugin.jit-loader.gdb.enable on"]);
17+
}
18+
let mut script_file = NamedTempFile::new()?;
19+
script_file.write(script.as_bytes())?;
20+
let script_path = script_file.path().to_str().unwrap();
21+
cmd.args(&["-s", &script_path]);
22+
23+
let mut me = std::env::current_exe().expect("current_exe specified");
24+
me.pop(); // chop off the file name
25+
me.pop(); // chop off `deps`
26+
me.push("wasmtime");
27+
cmd.arg(me);
28+
29+
cmd.arg("--");
30+
cmd.args(args);
31+
32+
let output = cmd.output().expect("success");
33+
if !output.status.success() {
34+
bail!(
35+
"failed to execute {:?}: {}",
36+
cmd,
37+
String::from_utf8_lossy(&output.stderr),
38+
);
39+
}
40+
Ok(String::from_utf8(output.stdout)?)
41+
}
42+
43+
fn check_lldb_output(output: &str, directives: &str) -> Result<()> {
44+
let mut builder = CheckerBuilder::new();
45+
builder
46+
.text(directives)
47+
.map_err(|e| format_err!("unable to build checker: {:?}", e))?;
48+
let checker = builder.finish();
49+
let check = checker
50+
.explain(output, NO_VARIABLES)
51+
.map_err(|e| format_err!("{:?}", e))?;
52+
assert!(check.0, "didn't pass check {}", check.1);
53+
Ok(())
54+
}
55+
56+
#[test]
57+
#[ignore]
58+
#[cfg(all(
59+
any(target_os = "linux", target_os = "macos"),
60+
target_pointer_width = "64"
61+
))]
62+
pub fn test_debug_dwarf_lldb() -> Result<()> {
63+
let output = lldb_with_script(
64+
&[
65+
"-g",
66+
"tests/debug/testsuite/fib-wasm.wasm",
67+
"--invoke",
68+
"fib",
69+
"3",
70+
],
71+
r#"b fib
72+
r
73+
fr v
74+
c"#,
75+
)?;
76+
77+
check_lldb_output(
78+
&output,
79+
r#"
80+
check: Breakpoint 1: no locations (pending)
81+
check: Unable to resolve breakpoint to any actual locations.
82+
check: 1 location added to breakpoint 1
83+
check: stop reason = breakpoint 1.1
84+
check: frame #0
85+
sameln: JIT
86+
sameln: fib(n=3)
87+
check: n = 3
88+
check: a = 0
89+
check: resuming
90+
check: exited with status
91+
"#,
92+
)?;
93+
Ok(())
94+
}

‎tests/debug/main.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod dump;
2+
mod lldb;
23
mod obj;
34
mod simulate;
45
mod translate;

0 commit comments

Comments
 (0)