Skip to content

Commit

Permalink
fix: wrong Span length
Browse files Browse the repository at this point in the history
  • Loading branch information
nerodesu017 committed Dec 17, 2024
1 parent aa23a77 commit 1222ae9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 32 deletions.
5 changes: 5 additions & 0 deletions src/core/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ mod test {
assert_eq!(wasm_reader.move_start_to(span), Err(Error::Eof));
}

// #[test]
// fn should_not_die() {
// let my_bytes = vec![0x1]
// }

#[test]
fn remaining_bytes_1() {
let my_bytes = vec![0x11, 0x12, 0x13, 0x14, 0x15];
Expand Down
2 changes: 1 addition & 1 deletion src/validation/read_constant_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub fn read_constant_expression(
if this_global_valtype.is_some() {
stack.assert_val_types(&[this_global_valtype.unwrap()])?;
}
return Ok(Span::new(start_pc, wasm.pc - start_pc + 1));
return Ok(Span::new(start_pc, wasm.pc - start_pc));
}
I32_CONST => {
let _num = wasm.read_var_i32()?;
Expand Down
3 changes: 2 additions & 1 deletion tests/specification/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod run;
mod test_errors;

enum Filter {
#[allow(dead_code)]
Include(FnF),
Exclude(FnF),
}
Expand All @@ -30,8 +31,8 @@ impl Default for FnF {
#[test_log::test]
pub fn spec_tests() {
let filters = Filter::Exclude(FnF {
files: Some(vec!["binary-leb128.wast".to_string()]),
folders: Some(vec!["proposals".to_string()]),
..Default::default()
});

// let only_these_tests: Vec<String> = vec![];
Expand Down
58 changes: 28 additions & 30 deletions tests/specification/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ pub fn run_spec_test(filepath: &str) -> WastTestReport {

let interpeter = interpeter.as_mut().unwrap();

let err_or_panic: Result<(), Box<dyn Error>> =
let err_or_panic: Result<(), Box<dyn Error>> =
match catch_unwind(AssertUnwindSafe(|| {
execute_assert_trap(interpeter, exec, message)
})) {
Expand All @@ -205,24 +205,24 @@ pub fn run_spec_test(filepath: &str) -> WastTestReport {
Err(Box::new(PanicError::new("Unknown panic")))
}
}
Ok(original_result) => original_result
Ok(original_result) => original_result,
};

match err_or_panic {
Ok(_) => {
asserts.push_success(WastSuccess::new(
span.linecol_in(&contents).0 as u32 + 1,
get_command(&contents, span),
));
}
Err(inner) => {
asserts.push_error(WastError::new(
inner,
span.linecol_in(&contents).0 as u32 + 1,
get_command(&contents, span),
));
}
match err_or_panic {
Ok(_) => {
asserts.push_success(WastSuccess::new(
span.linecol_in(&contents).0 as u32 + 1,
get_command(&contents, span),
));
}
Err(inner) => {
asserts.push_error(WastError::new(
inner,
span.linecol_in(&contents).0 as u32 + 1,
get_command(&contents, span),
));
}
}

// match exec {
// wast::WastExecute::Invoke(invoke_info) => {
Expand Down Expand Up @@ -308,11 +308,6 @@ pub fn run_spec_test(filepath: &str) -> WastTestReport {
name: _,
module: _,
}
// | wast::WastDirective::AssertTrap {
// span,
// exec: _,
// message: _,
// }
| wast::WastDirective::AssertExhaustion {
span,
call: _,
Expand Down Expand Up @@ -403,7 +398,7 @@ fn execute_assert_return(
fn execute_assert_trap(
interpeter: &mut RuntimeInstance,
exec: wast::WastExecute,
message: &str
message: &str,
) -> Result<(), Box<dyn Error>> {
match exec {
wast::WastExecute::Invoke(invoke_info) => {
Expand All @@ -416,9 +411,7 @@ fn execute_assert_trap(
// TODO: more modules ¯\_(ツ)_/¯
let func_res = interpeter
.get_function_by_name(DEFAULT_MODULE, invoke_info.name)
.map_err(|err| {
Box::new(WasmInterpreterError(wasm::Error::RuntimeError(err)))
});
.map_err(|err| Box::new(WasmInterpreterError(wasm::Error::RuntimeError(err))));

let func: FunctionRef;
match func_res {
Expand All @@ -437,11 +430,16 @@ fn execute_assert_trap(
let expected = message;

if actual.contains(expected)
|| (expected.contains("uninitialized element 2") && actual.contains("uninitialized element")) {
Ok(())
} else {
Err(Box::new(GenericError::new(format!("'assert_trap': Expected '{expected}' - Actual: '{actual}'").as_str())))
}
|| (expected.contains("uninitialized element 2")
&& actual.contains("uninitialized element"))
{
Ok(())
} else {
Err(Box::new(GenericError::new(
format!("'assert_trap': Expected '{expected}' - Actual: '{actual}'")
.as_str(),
)))
}
}
}
}
Expand Down

0 comments on commit 1222ae9

Please sign in to comment.