Skip to content

Commit 664314f

Browse files
committed
[pr3] base
1 parent c229345 commit 664314f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+3797
-4
lines changed

crates/wast-util/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,14 @@ impl WastTest {
387387
}
388388
}
389389

390+
if cfg!(not(all(unix, target_arch = "x86_64"))) {
391+
// Stack switching is not implemented on platforms other than x64
392+
// unix, the corresponding tests will fail.
393+
if self.path.parent().unwrap().ends_with("stack-switching") {
394+
return true;
395+
}
396+
}
397+
390398
if config.compiler.should_fail(&self.config) {
391399
return true;
392400
}

crates/wast/src/wast.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,26 @@ where
439439
bail!("expected '{}', got '{}'", expected, actual)
440440
}
441441

442+
fn assert_suspension(&self, result: Outcome, expected: &str) -> Result<()> {
443+
let trap = match result {
444+
Outcome::Ok(values) => bail!("expected suspension, got {:?}", values),
445+
Outcome::Trap(t) => t,
446+
};
447+
let actual = format!("{trap:?}");
448+
if actual.contains(expected)
449+
|| actual.contains("unhandled tag")
450+
|| actual.contains("Calling suspend outside of a continuation")
451+
{
452+
Ok(())
453+
} else {
454+
bail!(
455+
"assert_suspension: expected '{}', got '{}'",
456+
expected,
457+
actual
458+
)
459+
}
460+
}
461+
442462
/// Run a wast script from a byte buffer.
443463
pub fn run_buffer(&mut self, filename: &str, wast: &[u8]) -> Result<()> {
444464
let wast = str::from_utf8(wast)?;
@@ -607,6 +627,14 @@ where
607627
}
608628
}
609629
AssertException { .. } => bail!("unimplemented assert_exception"),
630+
AssertSuspension {
631+
span: _,
632+
exec,
633+
message,
634+
} => {
635+
let result = self.perform_execute(exec)?;
636+
self.assert_suspension(result, message)?;
637+
}
610638

611639
Thread(thread) => {
612640
let mut core_linker = Linker::new(self.store.engine());
@@ -647,10 +675,6 @@ where
647675
.join()
648676
.unwrap()?;
649677
}
650-
651-
AssertSuspension { .. } => {
652-
bail!("unimplemented wast directive");
653-
}
654678
}
655679

656680
Ok(())

tests/all/debug/lldb.rs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,3 +478,93 @@ check: exited with status = 0
478478
Ok(())
479479
}
480480
}
481+
482+
#[cfg(all(feature = "stack-switching", unix, target_arch = "x86_64"))]
483+
mod stack_switching {
484+
use super::{check_lldb_output, lldb_with_script};
485+
use anyhow::Result;
486+
487+
/// Checks that we get backtraces including the entire continuation chain when
488+
/// using just FP walking.
489+
#[test]
490+
#[ignore]
491+
pub fn debug_info_disabled() -> Result<()> {
492+
let output = lldb_with_script(
493+
&[
494+
"-Ccache=n",
495+
"-Ddebug-info=n",
496+
"-Wstack-switching",
497+
"--invoke",
498+
"entry",
499+
"tests/all/debug/testsuite/stack_switch.wat",
500+
],
501+
r#"r
502+
bt
503+
"#,
504+
)?;
505+
506+
// We are running without debug-info enabled, so we will not get Wasm
507+
// function names in the output. Instead, we look for
508+
// wasmtime_continuation_start, the trampoline at the bottom of all
509+
// continuation stacks.
510+
//
511+
// This directive matches lines like this:
512+
// frame #12: 0x0000555558f18fc9 wasmtime`wasmtime_continuation_start + 9
513+
let check = r#"
514+
check: frame #$(=[0-9]+): 0x$(=[0-9a-f]+) wasmtime`wasmtime_continuation_start
515+
"#;
516+
517+
// Our stack_switch.wat file traps inside 3 levels of nested continuations.
518+
// Thus, we must have 3 stack frames at function `wasmtime_continuation_start`.
519+
check_lldb_output(&output, &check.repeat(3))?;
520+
521+
Ok(())
522+
}
523+
524+
/// Checks that we get backtraces including the entire continuation chain when
525+
/// using just FP walking.
526+
#[test]
527+
#[ignore]
528+
pub fn debug_info_enabled() -> Result<()> {
529+
let output = lldb_with_script(
530+
&[
531+
"-Ccache=n",
532+
"-Ddebug-info=y",
533+
"-Wstack-switching",
534+
"--invoke",
535+
"entry",
536+
"tests/all/debug/testsuite/stack_switch.wat",
537+
],
538+
r#"r
539+
bt
540+
"#,
541+
)?;
542+
543+
// We are running with debug-info enabled, so we get Wasm
544+
// function names in the backtrace.
545+
//
546+
// Creates directive matching lines like this:
547+
// frame #13: 0x00007ffff4e4a5be JIT(0x55555bc24b10)`c at <gen-0>.wasm:90
548+
// where the string is parameterised over the function name (c in the
549+
// example above).
550+
let check = |name: &str| {
551+
format!(
552+
"check: frame #$(=[0-9]+): 0x$(=[0-9a-f]+) JIT(0x$(=[0-9a-f]+))`{name} at <gen-0>.wasm"
553+
)
554+
};
555+
556+
// Our stack_switch.wat file traps inside 3 levels of nested continuations.
557+
// Let's check that our backtrace contains all the functions, even those in
558+
// parent continuations.
559+
check_lldb_output(
560+
&output,
561+
&["f", "e", "d", "c", "b", "a", "entry"]
562+
.into_iter()
563+
.map(check)
564+
.collect::<Vec<String>>()
565+
.join("\n"),
566+
)?;
567+
568+
Ok(())
569+
}
570+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
(module
2+
(type $ft (func))
3+
(type $ct (cont $ft))
4+
5+
(func $entry (export "entry")
6+
(call $a)
7+
)
8+
9+
(func $a (export "a")
10+
(resume $ct (cont.new $ct (ref.func $b)))
11+
)
12+
13+
(func $b (export "b")
14+
(call $c)
15+
)
16+
17+
(func $c (export "c")
18+
(resume $ct (cont.new $ct (ref.func $d)))
19+
)
20+
21+
(func $d (export "d")
22+
(call $e)
23+
)
24+
25+
(func $e (export "e")
26+
(resume $ct (cont.new $ct (ref.func $f)))
27+
)
28+
29+
(func $f (export "f")
30+
(unreachable)
31+
)
32+
)

tests/all/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ mod pulley;
3939
mod relocs;
4040
mod stack_creator;
4141
mod stack_overflow;
42+
#[cfg(all(feature = "stack-switching", unix, target_arch = "x86_64"))]
43+
mod stack_switching;
4244
mod store;
4345
mod structs;
4446
mod table;

0 commit comments

Comments
 (0)