Skip to content

Commit

Permalink
Move remaining *.wat tests out of cranelift-wasm/wasmtests
Browse files Browse the repository at this point in the history
Move these up to Wasmtime's misc testsuite to get translated and
instantiated by Wasmtime.

Note that the max-function-index-in-name-section test was removed here
as that's tested by the support added in bytecodealliance#3509.
  • Loading branch information
alexcrichton committed Mar 15, 2024
1 parent b0f13dc commit 7a10a3c
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 69 deletions.
60 changes: 0 additions & 60 deletions cranelift/wasm/tests/wasm_testsuite.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,7 @@
use cranelift_codegen::isa::{CallConv, TargetFrontendConfig};
use cranelift_codegen::print_errors::pretty_verifier_error;
use cranelift_codegen::settings::{self, Flags};
use cranelift_codegen::verifier;
use cranelift_wasm::{translate_module, DummyEnvironment, FuncIndex};
use std::fs;
use std::path::Path;
use target_lexicon::PointerWidth;

#[test]
fn testsuite() {
let mut paths: Vec<_> = fs::read_dir("./wasmtests")
.unwrap()
.map(|r| r.unwrap())
.filter(|p| {
// Ignore files starting with `.`, which could be editor temporary files
if let Some(stem) = p.path().file_stem() {
if let Some(stemstr) = stem.to_str() {
return !stemstr.starts_with('.');
}
}
false
})
.collect();
paths.sort_by_key(|dir| dir.path());
let flags = Flags::new(settings::builder());
for path in paths {
let path = path.path();
println!("=== {} ===", path.display());
let data = read_module(&path);
handle_module(data, &flags);
}
}

#[test]
fn use_name_section() {
let data = wat::parse_str(
Expand All @@ -56,36 +26,6 @@ fn use_name_section() {
);
}

fn read_module(path: &Path) -> Vec<u8> {
match path.extension() {
None => {
panic!("the file extension is not wasm or wat");
}
Some(ext) => match ext.to_str() {
Some("wasm") => std::fs::read(path).expect("error reading wasm file"),
Some("wat") => wat::parse_file(path)
.map_err(|e| e.to_string())
.expect("failed to parse wat"),
None | Some(&_) => panic!("the file extension for {:?} is not wasm or wat", path),
},
}
}

fn handle_module(data: Vec<u8>, flags: &Flags) {
let mut dummy_environ = DummyEnvironment::new(TargetFrontendConfig {
default_call_conv: CallConv::SystemV,
pointer_width: PointerWidth::U64,
});

translate_module(&data, &mut dummy_environ).unwrap();

for func in dummy_environ.info.function_bodies.values() {
verifier::verify_function(func, flags)
.map_err(|errors| panic!("{}", pretty_verifier_error(func, None, errors)))
.unwrap();
}
}

#[test]
fn reachability_is_correct() {
let tests = vec![
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
;; copied from a historical cranelift-wasm test and provided here as proof that
;; this still compiles on various platforms and such

(module $env
(memory (export "memory") 2 2)
(table (export "table") 8 8 funcref)
(global (export "DYNAMICTOP_PTR") i32 i32.const 0)
(global (export "STACKTOP") i32 i32.const 0)
(global (export "STACK_MAX") i32 i32.const 0)
(global (export "memoryBase") i32 i32.const 0)
(global (export "tableBase") i32 i32.const 0)
(func (export "abort") (param i32))
(func (export "enlargeMemory") (result i32) unreachable)
(func (export "getTotalMemory") (result i32) unreachable)
(func (export "abortOnCannotGrowMemory") (result i32) unreachable)
(func (export "_pthread_cleanup_pop") (param i32))
(func (export "___syscall6") (param i32 i32) (result i32) unreachable)
(func (export "_pthread_cleanup_push") (param i32 i32))
(func (export "_abort"))
(func (export "___setErrNo") (param i32))
(func (export "_emscripten_memcpy_big") (param i32 i32 i32) (result i32) unreachable)
(func (export "___syscall54") (param i32 i32) (result i32) unreachable)
(func (export "___syscall140") (param i32 i32) (result i32) unreachable)
(func (export "___syscall146") (param i32 i32) (result i32) unreachable)
)

(module
(type $0 (;0;) (func (param i32 i32 i32) (result i32)))
(type $1 (;1;) (func (param i32) (result i32)))
Expand All @@ -12,7 +38,7 @@
(type $10 (;10;) (func (param i32 i32 i32 i32 i32)))
(type $11 (;11;) (func (param f64 i32) (result f64)))
(type $12 (;12;) (func (param i32 i32 i32 i32) (result i32)))
(import "env" "memory" (memory $16 (;0;) 2048 2048))
(import "env" "memory" (memory $16 (;0;) 2 2))
(import "env" "table" (table $timport$17 (;0;) 8 8 funcref))
(import "env" "DYNAMICTOP_PTR" (global $gimport$0 (;0;) i32))
(import "env" "STACKTOP" (global $gimport$1 (;1;) i32))
Expand Down Expand Up @@ -12177,4 +12203,4 @@
(data (;17;) (i32.const 1560) "\0a\00\00\00\00\0a\00\00\00\00\09\0b\00\00\00\00\00\0b\00\00\0b")
(data (;18;) (i32.const 1606) "\0c")
(data (;19;) (i32.const 1618) "\0c\00\00\00\00\0c\00\00\00\00\09\0c\00\00\00\00\00\0c\00\00\0c\00\000123456789ABCDEF-+ 0X0x\00(null)\00-0X+0X 0X-0x+0x 0x\00inf\00INF\00nan\00NAN\00.\00T!\22\19\0d\01\02\03\11K\1c\0c\10\04\0b\1d\12\1e'hnopqb \05\06\0f\13\14\15\1a\08\16\07($\17\18\09\0a\0e\1b\1f%#\83\82}&*+<=>?CGJMXYZ[\5c]^_`acdefgijklrstyz{|\00Illegal byte sequence\00Domain error\00Result not representable\00Not a tty\00Permission denied\00Operation not permitted\00No such file or directory\00No such process\00File exists\00Value too large for data type\00No space left on device\00Out of memory\00Resource busy\00Interrupted system call\00Resource temporarily unavailable\00Invalid seek\00Cross-device link\00Read-only file system\00Directory not empty\00Connection reset by peer\00Operation timed out\00Connection refused\00Host is down\00Host is unreachable\00Address in use\00Broken pipe\00I/O error\00No such device or address\00Block device required\00No such device\00Not a directory\00Is a directory\00Text file busy\00Exec format error\00Invalid argument\00Argument list too long\00Symbolic link loop\00Filename too long\00Too many open files in system\00No file descriptors available\00Bad file descriptor\00No child process\00Bad address\00File too large\00Too many links\00No locks available\00Resource deadlock would occur\00State not recoverable\00Previous owner died\00Operation canceled\00Function not implemented\00No message of desired type\00Identifier removed\00Device not a stream\00No data available\00Device timeout\00Out of streams resources\00Link has been severed\00Protocol error\00Bad message\00File descriptor in bad state\00Not a socket\00Destination address required\00Message too large\00Protocol wrong type for socket\00Protocol not available\00Protocol not supported\00Socket type not supported\00Not supported\00Protocol family not supported\00Address family not supported by protocol\00Address not available\00Network is down\00Network unreachable\00Connection reset by network\00Connection aborted\00No buffer space available\00Socket is connected\00Socket not connected\00Cannot send after socket shutdown\00Operation already in progress\00Operation in progress\00Stale file handle\00Remote I/O error\00Quota exceeded\00No medium found\00Wrong medium type\00No error information")
)
)
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
;; copied from a historical cranelift-wasm test and provided here as proof that
;; this still compiles on various platforms and such

(module $env
(memory (export "memory") 2 2)
(table (export "table") 9 9 funcref)
(global (export "DYNAMICTOP_PTR") i32 i32.const 0)
(global (export "STACKTOP") i32 i32.const 0)
(global (export "STACK_MAX") i32 i32.const 0)
(global (export "memoryBase") i32 i32.const 0)
(global (export "tableBase") i32 i32.const 0)
(func (export "abort") (param i32))
(func (export "enlargeMemory") (result i32) unreachable)
(func (export "getTotalMemory") (result i32) unreachable)
(func (export "abortOnCannotGrowMemory") (result i32) unreachable)
(func (export "_pthread_cleanup_pop") (param i32))
(func (export "___syscall6") (param i32 i32) (result i32) unreachable)
(func (export "_pthread_cleanup_push") (param i32 i32))
(func (export "_abort"))
(func (export "___setErrNo") (param i32))
(func (export "_emscripten_memcpy_big") (param i32 i32 i32) (result i32) unreachable)
(func (export "___syscall54") (param i32 i32) (result i32) unreachable)
(func (export "___syscall140") (param i32 i32) (result i32) unreachable)
(func (export "___syscall146") (param i32 i32) (result i32) unreachable)
)

(module
(type $0 (;0;) (func (param i32 i32 i32) (result i32)))
(type $1 (;1;) (func))
Expand All @@ -12,7 +38,7 @@
(type $10 (;10;) (func (param i32 i32 i32 i32 i32)))
(type $11 (;11;) (func (param f64 i32) (result f64)))
(type $12 (;12;) (func (param i32 i32 i32 i32) (result i32)))
(import "env" "memory" (memory $16 (;0;) 2048 2048))
(import "env" "memory" (memory $16 (;0;) 2 2))
(import "env" "table" (table $timport$17 (;0;) 9 9 funcref))
(import "env" "DYNAMICTOP_PTR" (global $gimport$0 (;0;) i32))
(import "env" "STACKTOP" (global $gimport$1 (;1;) i32))
Expand Down Expand Up @@ -12053,4 +12079,4 @@
(data (;19;) (i32.const 2082) "\0a\00\00\00\00\0a\00\00\00\00\09\0b\00\00\00\00\00\0b\00\00\0b")
(data (;20;) (i32.const 2128) "\0c")
(data (;21;) (i32.const 2140) "\0c\00\00\00\00\0c\00\00\00\00\09\0c\00\00\00\00\00\0c\00\00\0c\00\000123456789ABCDEF-+ 0X0x\00(null)\00-0X+0X 0X-0x+0x 0x\00inf\00INF\00nan\00NAN\00.\00T!\22\19\0d\01\02\03\11K\1c\0c\10\04\0b\1d\12\1e'hnopqb \05\06\0f\13\14\15\1a\08\16\07($\17\18\09\0a\0e\1b\1f%#\83\82}&*+<=>?CGJMXYZ[\5c]^_`acdefgijklrstyz{|\00Illegal byte sequence\00Domain error\00Result not representable\00Not a tty\00Permission denied\00Operation not permitted\00No such file or directory\00No such process\00File exists\00Value too large for data type\00No space left on device\00Out of memory\00Resource busy\00Interrupted system call\00Resource temporarily unavailable\00Invalid seek\00Cross-device link\00Read-only file system\00Directory not empty\00Connection reset by peer\00Operation timed out\00Connection refused\00Host is down\00Host is unreachable\00Address in use\00Broken pipe\00I/O error\00No such device or address\00Block device required\00No such device\00Not a directory\00Is a directory\00Text file busy\00Exec format error\00Invalid argument\00Argument list too long\00Symbolic link loop\00Filename too long\00Too many open files in system\00No file descriptors available\00Bad file descriptor\00No child process\00Bad address\00File too large\00Too many links\00No locks available\00Resource deadlock would occur\00State not recoverable\00Previous owner died\00Operation canceled\00Function not implemented\00No message of desired type\00Identifier removed\00Device not a stream\00No data available\00Device timeout\00Out of streams resources\00Link has been severed\00Protocol error\00Bad message\00File descriptor in bad state\00Not a socket\00Destination address required\00Message too large\00Protocol wrong type for socket\00Protocol not available\00Protocol not supported\00Socket type not supported\00Not supported\00Protocol family not supported\00Address family not supported by protocol\00Address not available\00Network is down\00Network unreachable\00Connection reset by network\00Connection aborted\00No buffer space available\00Socket is connected\00Socket not connected\00Cannot send after socket shutdown\00Operation already in progress\00Operation in progress\00Stale file handle\00Remote I/O error\00Quota exceeded\00No medium found\00Wrong medium type\00No error information")
)
)
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
;; copied from a historical cranelift-wasm test and provided here as proof that
;; this still compiles on various platforms and such

(module $env
(memory (export "memory") 2 2)
(table (export "table") 8 8 funcref)
(global (export "DYNAMICTOP_PTR") i32 i32.const 0)
(global (export "STACKTOP") i32 i32.const 0)
(global (export "STACK_MAX") i32 i32.const 0)
(global (export "memoryBase") i32 i32.const 0)
(global (export "tableBase") i32 i32.const 0)
(func (export "abort") (param i32))
(func (export "enlargeMemory") (result i32) unreachable)
(func (export "getTotalMemory") (result i32) unreachable)
(func (export "abortOnCannotGrowMemory") (result i32) unreachable)
(func (export "_pthread_cleanup_pop") (param i32))
(func (export "___syscall6") (param i32 i32) (result i32) unreachable)
(func (export "_pthread_cleanup_push") (param i32 i32))
(func (export "_abort"))
(func (export "___setErrNo") (param i32))
(func (export "_emscripten_memcpy_big") (param i32 i32 i32) (result i32) unreachable)
(func (export "___syscall54") (param i32 i32) (result i32) unreachable)
(func (export "___syscall140") (param i32 i32) (result i32) unreachable)
(func (export "___syscall146") (param i32 i32) (result i32) unreachable)
)

(module
(type $0 (;0;) (func (param i32 i32 i32) (result i32)))
(type $1 (;1;) (func (param i32) (result i32)))
Expand All @@ -12,7 +38,7 @@
(type $10 (;10;) (func (param i32 i32 i32 i32 i32)))
(type $11 (;11;) (func (param f64 i32) (result f64)))
(type $12 (;12;) (func (param i32 i32 i32 i32) (result i32)))
(import "env" "memory" (memory $16 (;0;) 2048 2048))
(import "env" "memory" (memory $16 (;0;) 2 2))
(import "env" "table" (table $timport$17 (;0;) 8 8 funcref))
(import "env" "DYNAMICTOP_PTR" (global $gimport$0 (;0;) i32))
(import "env" "STACKTOP" (global $gimport$1 (;1;) i32))
Expand Down Expand Up @@ -11502,4 +11528,4 @@
(data (;17;) (i32.const 1538) "\0a\00\00\00\00\0a\00\00\00\00\09\0b\00\00\00\00\00\0b\00\00\0b")
(data (;18;) (i32.const 1584) "\0c")
(data (;19;) (i32.const 1596) "\0c\00\00\00\00\0c\00\00\00\00\09\0c\00\00\00\00\00\0c\00\00\0c\00\000123456789ABCDEF-+ 0X0x\00(null)\00-0X+0X 0X-0x+0x 0x\00inf\00INF\00nan\00NAN\00.\00T!\22\19\0d\01\02\03\11K\1c\0c\10\04\0b\1d\12\1e'hnopqb \05\06\0f\13\14\15\1a\08\16\07($\17\18\09\0a\0e\1b\1f%#\83\82}&*+<=>?CGJMXYZ[\5c]^_`acdefgijklrstyz{|\00Illegal byte sequence\00Domain error\00Result not representable\00Not a tty\00Permission denied\00Operation not permitted\00No such file or directory\00No such process\00File exists\00Value too large for data type\00No space left on device\00Out of memory\00Resource busy\00Interrupted system call\00Resource temporarily unavailable\00Invalid seek\00Cross-device link\00Read-only file system\00Directory not empty\00Connection reset by peer\00Operation timed out\00Connection refused\00Host is down\00Host is unreachable\00Address in use\00Broken pipe\00I/O error\00No such device or address\00Block device required\00No such device\00Not a directory\00Is a directory\00Text file busy\00Exec format error\00Invalid argument\00Argument list too long\00Symbolic link loop\00Filename too long\00Too many open files in system\00No file descriptors available\00Bad file descriptor\00No child process\00Bad address\00File too large\00Too many links\00No locks available\00Resource deadlock would occur\00State not recoverable\00Previous owner died\00Operation canceled\00Function not implemented\00No message of desired type\00Identifier removed\00Device not a stream\00No data available\00Device timeout\00Out of streams resources\00Link has been severed\00Protocol error\00Bad message\00File descriptor in bad state\00Not a socket\00Destination address required\00Message too large\00Protocol wrong type for socket\00Protocol not available\00Protocol not supported\00Socket type not supported\00Not supported\00Protocol family not supported\00Address family not supported by protocol\00Address not available\00Network is down\00Network unreachable\00Connection reset by network\00Connection aborted\00No buffer space available\00Socket is connected\00Socket not connected\00Cannot send after socket shutdown\00Operation already in progress\00Operation in progress\00Stale file handle\00Remote I/O error\00Quota exceeded\00No medium found\00Wrong medium type\00No error information")
)
)
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
;; copied from a historical cranelift-wasm test and provided here as proof that
;; this still compiles on various platforms and such

(module $env
(memory (export "memory") 2 2)
(table (export "table") 8 8 funcref)
(global (export "DYNAMICTOP_PTR") i32 i32.const 0)
(global (export "STACKTOP") i32 i32.const 0)
(global (export "STACK_MAX") i32 i32.const 0)
(global (export "memoryBase") i32 i32.const 0)
(global (export "tableBase") i32 i32.const 0)
(func (export "abort") (param i32))
(func (export "enlargeMemory") (result i32) unreachable)
(func (export "getTotalMemory") (result i32) unreachable)
(func (export "abortOnCannotGrowMemory") (result i32) unreachable)
(func (export "_pthread_cleanup_pop") (param i32))
(func (export "___syscall6") (param i32 i32) (result i32) unreachable)
(func (export "_pthread_cleanup_push") (param i32 i32))
(func (export "_abort"))
(func (export "___setErrNo") (param i32))
(func (export "_emscripten_memcpy_big") (param i32 i32 i32) (result i32) unreachable)
(func (export "___syscall54") (param i32 i32) (result i32) unreachable)
(func (export "___syscall140") (param i32 i32) (result i32) unreachable)
(func (export "___syscall146") (param i32 i32) (result i32) unreachable)
)

(module
(type $0 (;0;) (func (param i32 i32 i32) (result i32)))
(type $1 (;1;) (func (param i32) (result i32)))
Expand All @@ -12,7 +38,7 @@
(type $10 (;10;) (func (param i32 i32 i32 i32 i32)))
(type $11 (;11;) (func (param f64 i32) (result f64)))
(type $12 (;12;) (func (param i32 i32 i32 i32) (result i32)))
(import "env" "memory" (memory $16 (;0;) 2048 2048))
(import "env" "memory" (memory $16 (;0;) 2 2))
(import "env" "table" (table $timport$17 (;0;) 8 8 funcref))
(import "env" "DYNAMICTOP_PTR" (global $gimport$0 (;0;) i32))
(import "env" "STACKTOP" (global $gimport$1 (;1;) i32))
Expand Down Expand Up @@ -11182,4 +11208,4 @@
(data (;17;) (i32.const 1551) "\0a\00\00\00\00\0a\00\00\00\00\09\0b\00\00\00\00\00\0b\00\00\0b")
(data (;18;) (i32.const 1597) "\0c")
(data (;19;) (i32.const 1609) "\0c\00\00\00\00\0c\00\00\00\00\09\0c\00\00\00\00\00\0c\00\00\0c\00\000123456789ABCDEF-+ 0X0x\00(null)\00-0X+0X 0X-0x+0x 0x\00inf\00INF\00nan\00NAN\00.\00T!\22\19\0d\01\02\03\11K\1c\0c\10\04\0b\1d\12\1e'hnopqb \05\06\0f\13\14\15\1a\08\16\07($\17\18\09\0a\0e\1b\1f%#\83\82}&*+<=>?CGJMXYZ[\5c]^_`acdefgijklrstyz{|\00Illegal byte sequence\00Domain error\00Result not representable\00Not a tty\00Permission denied\00Operation not permitted\00No such file or directory\00No such process\00File exists\00Value too large for data type\00No space left on device\00Out of memory\00Resource busy\00Interrupted system call\00Resource temporarily unavailable\00Invalid seek\00Cross-device link\00Read-only file system\00Directory not empty\00Connection reset by peer\00Operation timed out\00Connection refused\00Host is down\00Host is unreachable\00Address in use\00Broken pipe\00I/O error\00No such device or address\00Block device required\00No such device\00Not a directory\00Is a directory\00Text file busy\00Exec format error\00Invalid argument\00Argument list too long\00Symbolic link loop\00Filename too long\00Too many open files in system\00No file descriptors available\00Bad file descriptor\00No child process\00Bad address\00File too large\00Too many links\00No locks available\00Resource deadlock would occur\00State not recoverable\00Previous owner died\00Operation canceled\00Function not implemented\00No message of desired type\00Identifier removed\00Device not a stream\00No data available\00Device timeout\00Out of streams resources\00Link has been severed\00Protocol error\00Bad message\00File descriptor in bad state\00Not a socket\00Destination address required\00Message too large\00Protocol wrong type for socket\00Protocol not available\00Protocol not supported\00Socket type not supported\00Not supported\00Protocol family not supported\00Address family not supported by protocol\00Address not available\00Network is down\00Network unreachable\00Connection reset by network\00Connection aborted\00No buffer space available\00Socket is connected\00Socket not connected\00Cannot send after socket shutdown\00Operation already in progress\00Operation in progress\00Stale file handle\00Remote I/O error\00Quota exceeded\00No medium found\00Wrong medium type\00No error information")
)
)
Loading

0 comments on commit 7a10a3c

Please sign in to comment.