Skip to content

Commit

Permalink
chore: move runtime error stringification to testsuite runner
Browse files Browse the repository at this point in the history
Signed-off-by: nerodesu017 <[email protected]>
  • Loading branch information
nerodesu017 committed Dec 17, 2024
1 parent 0857971 commit 5d776f7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
25 changes: 0 additions & 25 deletions src/core/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,6 @@ pub enum RuntimeError {
// "unreachable"
}

impl RuntimeError {
#[cfg(debug_assertions)]
pub fn to_wasm_testsuite_string(&self) -> alloc::string::String {
match self {
Self::DivideBy0 => "integer divide by zero",
Self::UnrepresentableResult => "integer overflow",
Self::FunctionNotFound => todo!(),
Self::StackSmash => todo!(),
Self::BadConversionToInteger => "invalid conversion to integer",

Self::MemoryAccessOutOfBounds => "out of bounds memory access",
Self::TableAccessOutOfBounds => "out of bounds table access",
Self::ElementAccessOutOfBounds => todo!(),

Self::UninitializedElement => "uninitialized element",
Self::SignatureMismatch => "indirect call type mismatch",
Self::ExpectedAValueOnTheStack => todo!(),

Self::UndefinedTableIndex => "undefined element",
// _ => "",
}
.to_string()
}
}

#[derive(Debug, PartialEq, Eq, Clone)]
pub enum StoreInstantiationError {
ActiveDataWriteOutOfBounds,
Expand Down
24 changes: 23 additions & 1 deletion tests/specification/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::panic::catch_unwind;
use std::panic::AssertUnwindSafe;

use wasm::function_ref::FunctionRef;
use wasm::RuntimeError;
use wasm::Value;
use wasm::DEFAULT_MODULE;
use wasm::{validate, RuntimeInstance};
Expand All @@ -13,6 +14,27 @@ use wast::WastArg;
use crate::specification::reports::*;
use crate::specification::test_errors::*;

pub fn to_wasm_testsuite_string(runtime_error: RuntimeError) -> std::string::String {
match runtime_error {
RuntimeError::DivideBy0 => "integer divide by zero",
RuntimeError::UnrepresentableResult => "integer overflow",
RuntimeError::FunctionNotFound => todo!(),
RuntimeError::StackSmash => todo!(),
RuntimeError::BadConversionToInteger => "invalid conversion to integer",

RuntimeError::MemoryAccessOutOfBounds => "out of bounds memory access",
RuntimeError::TableAccessOutOfBounds => "out of bounds table access",
RuntimeError::ElementAccessOutOfBounds => todo!(),

RuntimeError::UninitializedElement => "uninitialized element",
RuntimeError::SignatureMismatch => "indirect call type mismatch",
RuntimeError::ExpectedAValueOnTheStack => todo!(),

RuntimeError::UndefinedTableIndex => "undefined element",
}
.to_string()
}

/// Attempt to unwrap the result of an expression. If the expression is an `Err`, then `return` the
/// error.
///
Expand Down Expand Up @@ -426,7 +448,7 @@ fn execute_assert_trap(
match actual {
Ok(_) => Err(Box::new(GenericError::new("assert_trap did NOT trap"))),
Err(e) => {
let actual = e.to_wasm_testsuite_string();
let actual = to_wasm_testsuite_string(e);
let expected = message;

if actual.contains(expected)
Expand Down

0 comments on commit 5d776f7

Please sign in to comment.