Skip to content

Commit 700f555

Browse files
committed
feat: AssertExhaustion directive
Signed-off-by: Cem Onem <cem.oenem@dlr.de>
1 parent 60e7b85 commit 700f555

File tree

1 file changed

+56
-40
lines changed

1 file changed

+56
-40
lines changed

tests/specification/run.rs

Lines changed: 56 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub fn to_wasm_testsuite_string(runtime_error: RuntimeError) -> Result<String, B
7979
RuntimeError::DivideBy0 => Ok("integer divide by zero"),
8080
RuntimeError::UnrepresentableResult => Ok("integer overflow"),
8181
RuntimeError::FunctionNotFound => not_represented,
82-
RuntimeError::StackSmash => not_represented,
82+
RuntimeError::StackExhaustion => Ok("call stack exhausted"),
8383
RuntimeError::BadConversionToInteger => Ok("invalid conversion to integer"),
8484
RuntimeError::ReachedUnreachable => Ok("unreachable"),
8585

@@ -278,8 +278,21 @@ pub fn run_spec_test(filepath: &str) -> WastTestReport {
278278
exec,
279279
message,
280280
} => {
281-
let err_or_panic =
282-
execute_assert_trap(&arena, &visible_modules, interpreter, exec, message);
281+
let err_or_panic = execute_assert_trap(&arena, &visible_modules, interpreter, exec)
282+
.and_then(|e| {
283+
let actual = to_wasm_testsuite_string(e)?;
284+
if actual.contains(message)
285+
|| (message.contains("uninitialized element 2")
286+
&& actual.contains("uninitialized element"))
287+
{
288+
Ok(())
289+
} else {
290+
Err(GenericError::new_boxed(
291+
format!("'assert_trap': Expected '{message}' - Actual: '{actual}'")
292+
.as_str(),
293+
))
294+
}
295+
});
283296

284297
match err_or_panic {
285298
Ok(_) => {
@@ -375,10 +388,44 @@ pub fn run_spec_test(filepath: &str) -> WastTestReport {
375388
}
376389
wast::WastDirective::AssertExhaustion {
377390
span,
378-
call: _,
379-
message: _,
391+
call,
392+
message,
393+
} => {
394+
let err_or_panic = execute_assert_trap(
395+
&arena,
396+
&visible_modules,
397+
interpreter,
398+
wast::WastExecute::Invoke(call),
399+
)
400+
.and_then(|e| {
401+
let actual = to_wasm_testsuite_string(e)?;
402+
if actual.contains(message) {
403+
Ok(())
404+
} else {
405+
Err(GenericError::new_boxed(
406+
format!("'assert_trap': Expected '{message}' - Actual: '{actual}'")
407+
.as_str(),
408+
))
409+
}
410+
});
411+
412+
match err_or_panic {
413+
Ok(_) => {
414+
asserts.push_success(WastSuccess::new(
415+
get_linenum(&contents, span),
416+
get_command(&contents, span),
417+
));
418+
}
419+
Err(inner) => {
420+
asserts.push_error(WastError::new(
421+
inner,
422+
get_linenum(&contents, span),
423+
get_command(&contents, span),
424+
));
425+
}
426+
}
380427
}
381-
| wast::WastDirective::AssertException { span, exec: _ } => {
428+
wast::WastDirective::AssertException { span, exec: _ } => {
382429
asserts.push_error(WastError::new(
383430
GenericError::new_boxed("Assert directive not yet implemented"),
384431
get_linenum(&contents, span),
@@ -613,8 +660,7 @@ fn execute_assert_trap<'a>(
613660
visible_modules: &HashMap<String, usize>,
614661
interpreter: &mut RuntimeInstance<'a>,
615662
exec: wast::WastExecute,
616-
message: &str,
617-
) -> Result<(), Box<dyn Error>> {
663+
) -> Result<RuntimeError, Box<dyn Error>> {
618664
match exec {
619665
wast::WastExecute::Invoke(invoke_info) => {
620666
let args = invoke_info
@@ -666,22 +712,7 @@ fn execute_assert_trap<'a>(
666712

667713
match actual {
668714
Ok(_) => Err(GenericError::new_boxed("assert_trap did NOT trap")),
669-
Err(e) => {
670-
let actual = to_wasm_testsuite_string(e)?;
671-
let expected = message;
672-
673-
if actual.contains(expected)
674-
|| (expected.contains("uninitialized element 2")
675-
&& actual.contains("uninitialized element"))
676-
{
677-
Ok(())
678-
} else {
679-
Err(GenericError::new_boxed(
680-
format!("'assert_trap': Expected '{expected}' - Actual: '{actual}'")
681-
.as_str(),
682-
))
683-
}
684-
}
715+
Err(e) => Ok(e),
685716
}
686717
}
687718
wast::WastExecute::Get {
@@ -710,22 +741,7 @@ fn execute_assert_trap<'a>(
710741
// TODO taken from (assert_trap (invoke ...) ...) error checking
711742
match instantiation_result {
712743
Ok(_) => Err(GenericError::new_boxed("assert_trap did NOT trap")),
713-
Err(wasm::Error::RuntimeError(e)) => {
714-
let actual = to_wasm_testsuite_string(e)?;
715-
let expected = message;
716-
717-
if actual.contains(expected)
718-
|| (expected.contains("uninitialized element 2")
719-
&& actual.contains("uninitialized element"))
720-
{
721-
Ok(())
722-
} else {
723-
Err(GenericError::new_boxed(
724-
format!("'assert_trap': Expected '{expected}' - Actual: '{actual}'")
725-
.as_str(),
726-
))
727-
}
728-
}
744+
Err(wasm::Error::RuntimeError(e)) => Ok(e),
729745
_ => Err(GenericError::new_boxed(
730746
"instantiation failed for a reason other than a trap",
731747
)),

0 commit comments

Comments
 (0)