Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Official Testsuite Runner #112

Merged
merged 4 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
run: cargo test --verbose -- --nocapture

conventional_commit_check:
name: Conventional Commits
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions src/core/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,24 @@ pub enum RuntimeError {
ExpectedAValueOnTheStack,
ModuleNotFound,
UnmetImport,
UndefinedTableIndex,
// "undefined element" <- as-call_indirect-last
// "unreachable"
}

#[derive(Debug, PartialEq, Eq, Clone)]
pub enum Proposal {
Memory64,
MultipleMemories,
Threads,
}

#[derive(Debug, PartialEq, Eq, Clone)]
pub enum StoreInstantiationError {
ActiveDataWriteOutOfBounds,
I64ValueOutOfReach(String),
MissingValueOnTheStack,
TooManyMemories(usize),
}

#[derive(Debug, PartialEq, Eq, Clone)]
Expand All @@ -44,6 +55,7 @@ pub enum Error {
InvalidVersion,
MalformedUtf8String(Utf8Error),
Eof,
InvalidSection(SectionTy, String),
InvalidSectionType(u8),
SectionOutOfOrder(SectionTy),
InvalidNumType,
Expand Down Expand Up @@ -92,6 +104,9 @@ pub enum Error {
OnlyFuncRefIsAllowed,
TypeUnificationMismatch,
InvalidSelectTypeVector,
TooManyLocals(usize),
UnsupportedProposal(Proposal),
Overflow,
}

impl Display for Error {
Expand All @@ -107,6 +122,10 @@ impl Display for Error {
Error::Eof => f.write_str(
"A value was expected in the WASM binary but the end of file was reached instead",
),
Error::InvalidSection(section, reason) => f.write_fmt(format_args!(
"Section '{:?}' invalid! Reason: {}",
section, reason
)),
Error::InvalidSectionType(ty) => f.write_fmt(format_args!(
"An invalid section type id was found in a section header: {ty}"
)),
Expand Down Expand Up @@ -238,6 +257,13 @@ impl Display for Error {
Error::InvalidSelectTypeVector => {
f.write_str("SELECT T* (0x1C) instruction must have exactly one type in the subsequent type vector")
}
Error::TooManyLocals(x) => {
f.write_fmt(format_args!("Too many locals (more than 2^32-1): {}", x))
}
Error::UnsupportedProposal(proposal) => {
f.write_fmt(format_args!("Unsupported proposal: {:?}", proposal))
}
Error::Overflow => f.write_str("Overflow"),
}
}
}
Expand All @@ -262,6 +288,9 @@ impl Display for RuntimeError {
RuntimeError::UnmetImport => {
f.write_str("There is at least one import which has no corresponding export")
}
RuntimeError::UndefinedTableIndex => {
f.write_str("Indirect call: table index out of bounds")
}
}
}
}
Expand All @@ -282,6 +311,7 @@ impl Display for StoreInstantiationError {
}
)),
MissingValueOnTheStack => f.write_str(""),
TooManyMemories(x) => f.write_fmt(format_args!("Too many memories (overflow): {}", x)),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pub mod error;
pub mod indices;
pub mod reader;
pub mod sidetable;
pub mod utils;
1 change: 1 addition & 0 deletions src/core/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ impl<'a> WasmReader<'a> {
/// more than 0 further bytes would panick. However, it can not move the [`pc`](Self::pc) any
/// further than that, instead an error is returned. For further information, refer to the
/// [field documentation of `pc`] (WasmReader::pc).
#[allow(dead_code)]
pub fn skip(&mut self, num_bytes: usize) -> Result<()> {
if num_bytes > self.full_wasm_binary.len() - self.pc {
return Err(Error::Eof);
Expand Down
11 changes: 6 additions & 5 deletions src/core/reader/types/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use crate::core::reader::{WasmReadable, WasmReader};
use crate::execution::assert_validated::UnwrapValidatedExt;
use crate::{unreachable_validated, Error, Result};

use super::TableType;
use super::global::GlobalType;
use super::{MemType, TableType};

#[derive(Debug)]
pub struct Import {
Expand Down Expand Up @@ -52,10 +53,10 @@ pub enum ImportDesc {
Table(TableType),
// TODO TableType
#[allow(dead_code)]
Mem(()),
Mem(MemType),
// TODO MemType
#[allow(dead_code)]
Global(()), // TODO GlobalType
Global(GlobalType), // TODO GlobalType
}

impl WasmReadable for ImportDesc {
Expand All @@ -64,8 +65,8 @@ impl WasmReadable for ImportDesc {
0x00 => Self::Func(wasm.read_var_u32()? as TypeIdx),
// https://webassembly.github.io/spec/core/binary/types.html#table-types
0x01 => Self::Table(TableType::read(wasm)?),
0x02 => todo!("read MemType"),
0x03 => todo!("read GlobalType"),
0x02 => Self::Mem(MemType::read(wasm)?),
0x03 => Self::Global(GlobalType::read(wasm)?),
other => return Err(Error::InvalidImportDesc(other)),
};

Expand Down
6 changes: 4 additions & 2 deletions src/core/reader/types/memarg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ pub struct MemArg {

impl WasmReadable for MemArg {
fn read(wasm: &mut WasmReader) -> crate::Result<Self> {
let align = wasm.read_var_u32()?;
let align_log2 = wasm.read_var_u32()?;
let offset = wasm.read_var_u32()?;
let align = u32::pow(2, align_log2);
Ok(Self { offset, align })
}

fn read_unvalidated(wasm: &mut WasmReader) -> Self {
let align = wasm.read_var_u32().unwrap_validated();
let align_log2 = wasm.read_var_u32().unwrap_validated();
let offset = wasm.read_var_u32().unwrap_validated();
let align = u32::pow(2, align_log2);
Self { offset, align }
}
}
184 changes: 184 additions & 0 deletions src/core/reader/types/opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,187 @@ pub mod fc_extensions {
pub const TABLE_SIZE: u8 = 0x10;
pub const TABLE_FILL: u8 = 0x11;
}

#[cfg(debug_assertions)]
pub fn opcode_byte_to_str(byte: u8) -> alloc::string::String {
use alloc::borrow::ToOwned;
match byte {
UNREACHABLE => "UNREACHABLE",
NOP => "NOP",
// BLOCK => "BLOCK",
// LOOP => "LOOP",
// IF => "IF",
// ELSE => "ELSE",
END => "END",
// BR => "BR",
// BR_IF => "BR_IF",
// BR_TABLE => "BR_TABLE",
RETURN => "RETURN",
CALL => "CALL",
// CALL_INDIRECT => "CALL_INDIRECT",
DROP => "DROP",
// SELECT => "SELECT",
LOCAL_GET => "LOCAL_GET",
LOCAL_SET => "LOCAL_SET",
LOCAL_TEE => "LOCAL_TEE",
GLOBAL_GET => "GLOBAL_GET",
GLOBAL_SET => "GLOBAL_SET",
I32_LOAD => "I32_LOAD",
I64_LOAD => "I64_LOAD",
F32_LOAD => "F32_LOAD",
F64_LOAD => "F64_LOAD",
I32_LOAD8_S => "I32_LOAD8_S",
I32_LOAD8_U => "I32_LOAD8_U",
I32_LOAD16_S => "I32_LOAD16_S",
I32_LOAD16_U => "I32_LOAD16_U",
I64_LOAD8_S => "I64_LOAD8_S",
I64_LOAD8_U => "I64_LOAD8_U",
I64_LOAD16_S => "I64_LOAD16_S",
I64_LOAD16_U => "I64_LOAD16_U",
I64_LOAD32_S => "I64_LOAD32_S",
I64_LOAD32_U => "I64_LOAD32_U",
I32_STORE => "I32_STORE",
I64_STORE => "I64_STORE",
F32_STORE => "F32_STORE",
F64_STORE => "F64_STORE",
I32_STORE8 => "I32_STORE8",
I32_STORE16 => "I32_STORE16",
I64_STORE8 => "I64_STORE8",
I64_STORE16 => "I64_STORE16",
I64_STORE32 => "I64_STORE32",
MEMORY_SIZE => "MEMORY_SIZE",
MEMORY_GROW => "MEMORY_GROW",
I32_CONST => "I32_CONST",
I64_CONST => "I64_CONST",
F32_CONST => "F32_CONST",
F64_CONST => "F64_CONST",
I32_EQZ => "I32_EQZ",
I32_EQ => "I32_EQ",
I32_NE => "I32_NE",
I32_LT_S => "I32_LT_S",
I32_LT_U => "I32_LT_U",
I32_GT_S => "I32_GT_S",
I32_GT_U => "I32_GT_U",
I32_LE_S => "I32_LE_S",
I32_LE_U => "I32_LE_U",
I32_GE_S => "I32_GE_S",
I32_GE_U => "I32_GE_U",
I64_EQZ => "I64_EQZ",
I64_EQ => "I64_EQ",
I64_NE => "I64_NE",
I64_LT_S => "I64_LT_S",
I64_LT_U => "I64_LT_U",
I64_GT_S => "I64_GT_S",
I64_GT_U => "I64_GT_U",
I64_LE_S => "I64_LE_S",
I64_LE_U => "I64_LE_U",
I64_GE_S => "I64_GE_S",
I64_GE_U => "I64_GE_U",
F32_EQ => "F32_EQ",
F32_NE => "F32_NE",
F32_LT => "F32_LT",
F32_GT => "F32_GT",
F32_LE => "F32_LE",
F32_GE => "F32_GE",
F64_EQ => "F64_EQ",
F64_NE => "F64_NE",
F64_LT => "F64_LT",
F64_GT => "F64_GT",
F64_LE => "F64_LE",
F64_GE => "F64_GE",
I32_CLZ => "I32_CLZ",
I32_CTZ => "I32_CTZ",
I32_POPCNT => "I32_POPCNT",
I32_ADD => "I32_ADD",
I32_SUB => "I32_SUB",
I32_MUL => "I32_MUL",
I32_DIV_S => "I32_DIV_S",
I32_DIV_U => "I32_DIV_U",
I32_REM_S => "I32_REM_S",
I32_REM_U => "I32_REM_U",
I32_AND => "I32_AND",
I32_OR => "I32_OR",
I32_XOR => "I32_XOR",
I32_SHL => "I32_SHL",
I32_SHR_S => "I32_SHR_S",
I32_SHR_U => "I32_SHR_U",
I32_ROTL => "I32_ROTL",
I32_ROTR => "I32_ROTR",
I64_CLZ => "I64_CLZ",
I64_CTZ => "I64_CTZ",
I64_POPCNT => "I64_POPCNT",
I64_ADD => "I64_ADD",
I64_SUB => "I64_SUB",
I64_MUL => "I64_MUL",
I64_DIV_S => "I64_DIV_S",
I64_DIV_U => "I64_DIV_U",
I64_REM_S => "I64_REM_S",
I64_REM_U => "I64_REM_U",
I64_AND => "I64_AND",
I64_OR => "I64_OR",
I64_XOR => "I64_XOR",
I64_SHL => "I64_SHL",
I64_SHR_S => "I64_SHR_S",
I64_SHR_U => "I64_SHR_U",
I64_ROTL => "I64_ROTL",
I64_ROTR => "I64_ROTR",
F32_ABS => "F32_ABS",
F32_NEG => "F32_NEG",
F32_CEIL => "F32_CEIL",
F32_FLOOR => "F32_FLOOR",
F32_TRUNC => "F32_TRUNC",
F32_NEAREST => "F32_NEAREST",
F32_SQRT => "F32_SQRT",
F32_ADD => "F32_ADD",
F32_SUB => "F32_SUB",
F32_MUL => "F32_MUL",
F32_DIV => "F32_DIV",
F32_MIN => "F32_MIN",
F32_MAX => "F32_MAX",
F32_COPYSIGN => "F32_COPYSIGN",
F64_ABS => "F64_ABS",
F64_NEG => "F64_NEG",
F64_CEIL => "F64_CEIL",
F64_FLOOR => "F64_FLOOR",
F64_TRUNC => "F64_TRUNC",
F64_NEAREST => "F64_NEAREST",
F64_SQRT => "F64_SQRT",
F64_ADD => "F64_ADD",
F64_SUB => "F64_SUB",
F64_MUL => "F64_MUL",
F64_DIV => "F64_DIV",
F64_MIN => "F64_MIN",
F64_MAX => "F64_MAX",
F64_COPYSIGN => "F64_COPYSIGN",
I32_WRAP_I64 => "I32_WRAP_I64",
I32_TRUNC_F32_S => "I32_TRUNC_F32_S",
I32_TRUNC_F32_U => "I32_TRUNC_F32_U",
I32_TRUNC_F64_S => "I32_TRUNC_F64_S",
I32_TRUNC_F64_U => "I32_TRUNC_F64_U",
I64_EXTEND_I32_S => "I64_EXTEND_I32_S",
I64_EXTEND_I32_U => "I64_EXTEND_I32_U",
I64_TRUNC_F32_S => "I64_TRUNC_F32_S",
I64_TRUNC_F32_U => "I64_TRUNC_F32_U",
I64_TRUNC_F64_S => "I64_TRUNC_F64_S",
I64_TRUNC_F64_U => "I64_TRUNC_F64_U",
F32_CONVERT_I32_S => "F32_CONVERT_I32_S",
F32_CONVERT_I32_U => "F32_CONVERT_I32_U",
F32_CONVERT_I64_S => "F32_CONVERT_I64_S",
F32_CONVERT_I64_U => "F32_CONVERT_I64_U",
F32_DEMOTE_F64 => "F32_DEMOTE_F64",
F64_CONVERT_I32_S => "F64_CONVERT_I32_S",
F64_CONVERT_I32_U => "F64_CONVERT_I32_U",
F64_CONVERT_I64_S => "F64_CONVERT_I64_S",
F64_CONVERT_I64_U => "F64_CONVERT_I64_U",
F64_PROMOTE_F32 => "F64_PROMOTE_F32",
I32_REINTERPRET_F32 => "I32_REINTERPRET_F32",
I64_REINTERPRET_F64 => "I64_REINTERPRET_F64",
F32_REINTERPRET_I32 => "F32_REINTERPRET_I32",
F64_REINTERPRET_I64 => "F64_REINTERPRET_I64",
REF_NULL => "REF_NULL",
REF_FUNC => "REF_FUNC",
FC_EXTENSIONS => "FC_EXTENSIONS",
_ => "UNKNOWN",
}
.to_owned()
}
Loading