Skip to content

Commit 2121568

Browse files
committed
[pr3] base
1 parent b35a323 commit 2121568

Some content is hidden

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

52 files changed

+3810
-5
lines changed

crates/test-util/src/wasmtime_wast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub fn apply_test_config(config: &mut Config, test_config: &wast::TestConfig) {
7474
// To avoid needing to enable all of them at once implicitly enable
7575
// downstream proposals once the end proposal is enabled (e.g. when enabling
7676
// gc that also enables function-references and reference-types).
77-
let function_references = gc || function_references.unwrap_or(false);
77+
let function_references = stack_switching || gc || function_references.unwrap_or(false);
7878
let reference_types = function_references || reference_types.unwrap_or(false);
7979
let simd = relaxed_simd || simd.unwrap_or(false);
8080

crates/test-util/src/wast.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,14 @@ impl WastTest {
430430
}
431431
}
432432

433+
if cfg!(not(all(unix, target_arch = "x86_64"))) {
434+
// Stack switching is not implemented on platforms other than x64
435+
// unix, the corresponding tests will fail.
436+
if self.path.parent().unwrap().ends_with("stack-switching") {
437+
return true;
438+
}
439+
}
440+
433441
if config.compiler.should_fail(&self.config) {
434442
return true;
435443
}

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
@@ -551,3 +551,93 @@ check: exited with status = 0
551551
Ok(())
552552
}
553553
}
554+
555+
#[cfg(all(feature = "stack-switching", unix, target_arch = "x86_64"))]
556+
mod stack_switching {
557+
use super::{check_lldb_output, lldb_with_script};
558+
use anyhow::Result;
559+
560+
/// Checks that we get backtraces including the entire continuation chain when
561+
/// using just FP walking.
562+
#[test]
563+
#[ignore]
564+
pub fn debug_info_disabled() -> Result<()> {
565+
let output = lldb_with_script(
566+
&[
567+
"-Ccache=n",
568+
"-Ddebug-info=n",
569+
"-Wstack-switching",
570+
"--invoke",
571+
"entry",
572+
"tests/all/debug/testsuite/stack_switch.wat",
573+
],
574+
r#"r
575+
bt
576+
"#,
577+
)?;
578+
579+
// We are running without debug-info enabled, so we will not get Wasm
580+
// function names in the output. Instead, we look for
581+
// wasmtime_continuation_start, the trampoline at the bottom of all
582+
// continuation stacks.
583+
//
584+
// This directive matches lines like this:
585+
// frame #12: 0x0000555558f18fc9 wasmtime`wasmtime_continuation_start + 9
586+
let check = r#"
587+
check: frame #$(=[0-9]+): 0x$(=[0-9a-f]+) wasmtime`wasmtime_continuation_start
588+
"#;
589+
590+
// Our stack_switch.wat file traps inside 3 levels of nested continuations.
591+
// Thus, we must have 3 stack frames at function `wasmtime_continuation_start`.
592+
check_lldb_output(&output, &check.repeat(3))?;
593+
594+
Ok(())
595+
}
596+
597+
/// Checks that we get backtraces including the entire continuation chain when
598+
/// using just FP walking.
599+
#[test]
600+
#[ignore]
601+
pub fn debug_info_enabled() -> Result<()> {
602+
let output = lldb_with_script(
603+
&[
604+
"-Ccache=n",
605+
"-Ddebug-info=y",
606+
"-Wstack-switching",
607+
"--invoke",
608+
"entry",
609+
"tests/all/debug/testsuite/stack_switch.wat",
610+
],
611+
r#"r
612+
bt
613+
"#,
614+
)?;
615+
616+
// We are running with debug-info enabled, so we get Wasm
617+
// function names in the backtrace.
618+
//
619+
// Creates directive matching lines like this:
620+
// frame #13: 0x00007ffff4e4a5be JIT(0x55555bc24b10)`c at <gen-0>.wasm:90
621+
// where the string is parameterised over the function name (c in the
622+
// example above).
623+
let check = |name: &str| {
624+
format!(
625+
"check: frame #$(=[0-9]+): 0x$(=[0-9a-f]+) JIT(0x$(=[0-9a-f]+))`{name} at <gen-0>.wasm"
626+
)
627+
};
628+
629+
// Our stack_switch.wat file traps inside 3 levels of nested continuations.
630+
// Let's check that our backtrace contains all the functions, even those in
631+
// parent continuations.
632+
check_lldb_output(
633+
&output,
634+
&["f", "e", "d", "c", "b", "a", "entry"]
635+
.into_iter()
636+
.map(check)
637+
.collect::<Vec<String>>()
638+
.join("\n"),
639+
)?;
640+
641+
Ok(())
642+
}
643+
}
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
@@ -41,6 +41,8 @@ mod pulley;
4141
mod relocs;
4242
mod stack_creator;
4343
mod stack_overflow;
44+
#[cfg(all(feature = "stack-switching", unix, target_arch = "x86_64"))]
45+
mod stack_switching;
4446
mod store;
4547
mod structs;
4648
mod table;

0 commit comments

Comments
 (0)