diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/README.md | 5 | ||||
-rw-r--r-- | test/binary/names.txt | 94 | ||||
-rw-r--r-- | test/decompile/names.txt | 116 | ||||
-rwxr-xr-x | test/run-tests.py | 6 |
4 files changed, 211 insertions, 10 deletions
diff --git a/test/README.md b/test/README.md index c93bc26a..669fd28d 100644 --- a/test/README.md +++ b/test/README.md @@ -140,7 +140,9 @@ The currently supported list of tools (see binary files), then parse via `wasm2wat` and display the result - `run-gen-wasm-interp`: parse a "gen-wasm" text file, generate a wasm file, the run `wasm-interp` on it, which runes all exported functions in an - interpreter + interpreter. +- `run-gen-wasm-decompile`: parse a "gen-wasm" text file (which can describe + invalid binary files), then parse via `wasm-decompile` and display the result. - `run-opcodecnt`: parse a wasm text file, convert it to binary, then display opcode usage counts. - `run-gen-spec-js`: parse wasm spec test text file, convert it to a JSON file @@ -149,6 +151,7 @@ The currently supported list of tools (see - `run-spec-wasm2c`: similar to `run-gen-spec-js`, but the output instead will be C source files, that are then compiled with the default C compiler (`cc`). Finally, the native executable is run. +- `run-wasm-decompile`: parse wat with `wat2wasm` then `wasm-decompile`. ## Test subdirectories diff --git a/test/binary/names.txt b/test/binary/names.txt index bc57f4a8..d5561072 100644 --- a/test/binary/names.txt +++ b/test/binary/names.txt @@ -1,26 +1,76 @@ ;;; TOOL: run-gen-wasm +;;; ARGS2: --generate-names +;; NOTE: same test as in test/decompile/names.txt magic version -section(TYPE) { count[1] function params[0] results[1] i32 } -section(FUNCTION) { count[1] type[0] } -section(CODE) { +section(TYPE) { + count[2] + function params[0] results[1] i32 + function params[0] results[0] +} +section(FUNCTION) { + count[4] + type[0] + type[1] + type[1] + type[1] +} +section(MEMORY) { count[1] + has_max[0] + initial[0] +} +section(GLOBAL) { + count[2] + ;; This has both a sym and export name, prefer sym. + type[i32] mut[0] init_expr[i32.const 0 end] + ;; This only has an export name. + type[i32] mut[0] init_expr[i32.const 0 end] +} +section(EXPORT) { + count[5] + str("F1_EXPORT") func_kind func[1] + str("F2_EXPORT") func_kind func[2] + str("F3_EXPORT") func_kind func[3] + str("G0_EXPORT") global_kind global[0] + str("G1_EXPORT") global_kind global[1] +} +section(CODE) { + count[4] + ;; Test name section. func { locals[decl_count[1] i32_count[1] i32] get_local 0 } + ;; Test naming priorities + ;; If there's a name section name, prefer that over sym/export. + func { locals[0] } + ;; If there's no name section name, prefer sym over export. + func { locals[0] } + ;; If there's only export, use that. + func { locals[0] } +} +section(DATA) { + count[2] + ;; These can only be named thru symbols. + memory_index[0] + offset[i32.const 0 end] + data[str("foo")] + memory_index[0] + offset[i32.const 10 end] + data[str("bar")] } section("name") { section(NAME_MODULE) { str("M0") } - section(NAME_FUNCTION) { - func_count[1] + func_count[2] index[0] str("F0") + index[1] + str("F1_NS") } - section(NAME_LOCALS) { func_count[1] index[0] @@ -29,10 +79,36 @@ section("name") { str("L0") } } +section("linking") { + metadata_version[2] + section(LINKING_SYMBOL_TABLE) { + num_symbols[5] + type[0] flags[1] index[1] str("F1_SYM") + type[0] flags[1] index[2] str("F2_SYM") + type[2] flags[1] index[0] str("G0_SYM") + + type[1] flags[4] str("D0_SYM") segment[0] offset[0] size[1] + type[1] flags[4] str("D1_SYM") segment[1] offset[0] size[1] + } +} (;; STDOUT ;;; (module $M0 - (type (;0;) (func (result i32))) - (func $F0 (type 0) (result i32) + (type $t0 (func (result i32))) + (type $t1 (func)) + (func $F0 (type $t0) (result i32) (local $L0 i32) - local.get $L0)) + local.get $L0) + (func $F1_NS (type $t1)) + (func $F2_SYM (type $t1)) + (func $F3_EXPORT (type $t1)) + (memory $M0 0) + (global $G0_SYM i32 (i32.const 0)) + (global $G1_EXPORT i32 (i32.const 0)) + (export "F1_EXPORT" (func $F1_NS)) + (export "F2_EXPORT" (func $F2_SYM)) + (export "F3_EXPORT" (func $F3_EXPORT)) + (export "G0_EXPORT" (global 0)) + (export "G1_EXPORT" (global 1)) + (data $D0_SYM (i32.const 0) "foo") + (data $D1_SYM (i32.const 10) "bar")) ;;; STDOUT ;;) diff --git a/test/decompile/names.txt b/test/decompile/names.txt new file mode 100644 index 00000000..f390b891 --- /dev/null +++ b/test/decompile/names.txt @@ -0,0 +1,116 @@ +;;; TOOL: run-gen-wasm-decompile +;; NOTE: same test as in test/binary/names.txt +magic +version +section(TYPE) { + count[2] + function params[0] results[1] i32 + function params[0] results[0] +} +section(FUNCTION) { + count[4] + type[0] + type[1] + type[1] + type[1] +} +section(MEMORY) { + count[1] + has_max[0] + initial[0] +} +section(GLOBAL) { + count[2] + ;; This has both a sym and export name, prefer sym. + type[i32] mut[0] init_expr[i32.const 0 end] + ;; This only has an export name. + type[i32] mut[0] init_expr[i32.const 0 end] +} +section(EXPORT) { + count[5] + str("F1_EXPORT") func_kind func[1] + str("F2_EXPORT") func_kind func[2] + str("F3_EXPORT") func_kind func[3] + str("G0_EXPORT") global_kind global[0] + str("G1_EXPORT") global_kind global[1] +} +section(CODE) { + count[4] + ;; Test name section. + func { + locals[decl_count[1] i32_count[1] i32] + get_local 0 + } + ;; Test naming priorities + ;; If there's a name section name, prefer that over sym/export. + func { locals[0] } + ;; If there's no name section name, prefer sym over export. + func { locals[0] } + ;; If there's only export, use that. + func { locals[0] } +} +section(DATA) { + count[2] + ;; These can only be named thru symbols. + memory_index[0] + offset[i32.const 0 end] + data[str("Hello, World!")] + memory_index[0] + offset[i32.const 10 end] + data[str("bar")] +} +section("name") { + section(NAME_MODULE) { + str("M0") + } + section(NAME_FUNCTION) { + func_count[2] + index[0] + str("F0") + index[1] + str("F1_NS") + } + section(NAME_LOCALS) { + func_count[1] + index[0] + local_count[1] + index[0] + str("L0") + } +} +section("linking") { + metadata_version[2] + section(LINKING_SYMBOL_TABLE) { + num_symbols[5] + type[0] flags[1] index[1] str("F1_SYM") + type[0] flags[1] index[2] str("F2_SYM") + type[2] flags[1] index[0] str("G0_SYM") + + type[1] flags[4] str("D0_SYM") segment[0] offset[0] size[1] + type[1] flags[4] str("D1_SYM") segment[1] offset[0] size[1] + } +} +(;; STDOUT ;;; +memory M_a(initial: 0, max: 0); + +global G0_SYM:int = 0; +export global G1_EXPORT:int = 0; + +data D0_SYM(offset: 0) = "Hello, World!"; +data D1_SYM(offset: 10) = "bar"; + +function F0():int { + var L0:int; + return L0; +} + +function F1_NS() { +} + +function F2_SYM() { +} + +export function F3_EXPORT() { +} + +;;; STDOUT ;;) diff --git a/test/run-tests.py b/test/run-tests.py index 0a452025..89094d9c 100755 --- a/test/run-tests.py +++ b/test/run-tests.py @@ -119,6 +119,12 @@ TOOLS = { ('RUN', '%(wasm-objdump)s -h %(temp_file)s.wasm'), ('VERBOSE-ARGS', ['--print-cmd', '-v']), ], + 'run-gen-wasm-decompile': [ + ('RUN', '%(gen_wasm_py)s %(in_file)s -o %(temp_file)s.wasm'), + ('RUN', '%(wasm-validate)s %(temp_file)s.wasm'), + ('RUN', '%(wasm-decompile)s %(temp_file)s.wasm'), + ('VERBOSE-ARGS', ['--print-cmd', '-v']), + ], 'run-opcodecnt': [ ('RUN', '%(wat2wasm)s %(in_file)s -o %(temp_file)s.wasm'), ('RUN', '%(wasm-opcodecnt)s %(temp_file)s.wasm'), |