summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/tools/wasm-interp.c112
-rw-r--r--test/spec/binary.txt20
-rw-r--r--test/spec/imports.txt112
-rw-r--r--test/spec/linking.txt8
-rw-r--r--test/spec/memory.txt6
-rw-r--r--test/spec/start.txt2
6 files changed, 171 insertions, 89 deletions
diff --git a/src/tools/wasm-interp.c b/src/tools/wasm-interp.c
index 2180762e..aa689690 100644
--- a/src/tools/wasm-interp.c
+++ b/src/tools/wasm-interp.c
@@ -1159,11 +1159,61 @@ static WasmResult on_action_command(Context* ctx, Action* action) {
return result;
}
+static WasmBinaryErrorHandler* new_custom_error_handler(Context* ctx,
+ const char* desc) {
+ size_t header_size = ctx->source_filename.length + strlen(desc) + 100;
+ char* header = wasm_alloc(ctx->allocator, header_size, 1);
+ wasm_snprintf(header, header_size, PRIstringslice ":%d: %s passed",
+ WASM_PRINTF_STRING_SLICE_ARG(ctx->source_filename),
+ ctx->command_line_number, desc);
+
+ WasmDefaultErrorHandlerInfo* info = wasm_alloc_zero(
+ ctx->allocator, sizeof(WasmDefaultErrorHandlerInfo), WASM_DEFAULT_ALIGN);
+ info->header = header;
+ info->out_file = stdout;
+ info->print_header = WASM_PRINT_ERROR_HEADER_ONCE;
+
+ WasmBinaryErrorHandler* error_handler = wasm_alloc_zero(
+ ctx->allocator, sizeof(WasmBinaryErrorHandler), WASM_DEFAULT_ALIGN);
+ error_handler->on_error = wasm_default_binary_error_callback;
+ error_handler->user_data = info;
+ return error_handler;
+}
+
+static void destroy_custom_error_handler(
+ WasmAllocator* allocator,
+ WasmBinaryErrorHandler* error_handler) {
+ WasmDefaultErrorHandlerInfo* info = error_handler->user_data;
+ wasm_free(allocator, (void*)info->header);
+ wasm_free(allocator, info);
+ wasm_free(allocator, error_handler);
+}
+
static WasmResult on_assert_malformed_command(Context* ctx,
WasmStringSlice filename,
WasmStringSlice text) {
- /* TODO */
- return WASM_OK;
+ WasmBinaryErrorHandler* error_handler =
+ new_custom_error_handler(ctx, "assert_malformed");
+ WasmInterpreterEnvironment env;
+ WASM_ZERO_MEMORY(env);
+
+ ctx->total++;
+ char* path = create_module_path(ctx, filename);
+ WasmInterpreterModule* module;
+ WasmResult result =
+ read_module(ctx->allocator, path, &env, error_handler, &module);
+ if (WASM_FAILED(result)) {
+ ctx->passed++;
+ result = WASM_OK;
+ } else {
+ print_command_error(ctx, "expected module to be malformed: \"%s\"", path);
+ result = WASM_ERROR;
+ }
+
+ wasm_free(ctx->allocator, path);
+ wasm_destroy_interpreter_environment(ctx->allocator, &env);
+ destroy_custom_error_handler(ctx->allocator, error_handler);
+ return result;
}
static WasmResult on_register_command(Context* ctx,
@@ -1203,46 +1253,61 @@ static WasmResult on_register_command(Context* ctx,
static WasmResult on_assert_unlinkable_command(Context* ctx,
WasmStringSlice filename,
WasmStringSlice text) {
- char buffer[256];
- wasm_snprintf(buffer, sizeof(buffer),
- PRIstringslice ":%d: assert_unlinkable error",
- WASM_PRINTF_STRING_SLICE_ARG(ctx->source_filename),
- ctx->command_line_number);
-
- WasmDefaultErrorHandlerInfo info;
- info.header = buffer;
- info.out_file = stdout;
- info.print_header = WASM_PRINT_ERROR_HEADER_ONCE;
-
- WasmBinaryErrorHandler error_handler;
- error_handler.on_error = wasm_default_binary_error_callback;
- error_handler.user_data = &info;
+ WasmBinaryErrorHandler* error_handler =
+ new_custom_error_handler(ctx, "assert_unlinkable");
ctx->total++;
char* path = create_module_path(ctx, filename);
+ WasmInterpreterModule* module;
WasmInterpreterEnvironmentMark mark =
wasm_mark_interpreter_environment(&ctx->env);
- WasmResult result = read_module(ctx->allocator, path, &ctx->env,
- &error_handler, &ctx->last_module);
+ WasmResult result =
+ read_module(ctx->allocator, path, &ctx->env, error_handler, &module);
wasm_reset_interpreter_environment_to_mark(ctx->allocator, &ctx->env, mark);
if (WASM_FAILED(result)) {
ctx->passed++;
+ result = WASM_OK;
} else {
print_command_error(ctx, "expected module to be unlinkable: \"%s\"", path);
- wasm_free(ctx->allocator, path);
- return WASM_ERROR;
+ result = WASM_ERROR;
}
wasm_free(ctx->allocator, path);
- return WASM_OK;
+ destroy_custom_error_handler(ctx->allocator, error_handler);
+ return result;
}
static WasmResult on_assert_uninstantiable_command(Context* ctx,
WasmStringSlice filename,
WasmStringSlice text) {
- /* TODO */
- return WASM_OK;
+ ctx->total++;
+ char* path = create_module_path(ctx, filename);
+ WasmInterpreterModule* module;
+ WasmInterpreterEnvironmentMark mark =
+ wasm_mark_interpreter_environment(&ctx->env);
+ WasmResult result =
+ read_module(ctx->allocator, path, &ctx->env, &s_error_handler, &module);
+
+ if (WASM_SUCCEEDED(result)) {
+ WasmInterpreterResult iresult =
+ run_start_function(ctx->allocator, &ctx->thread, module);
+ if (iresult == WASM_INTERPRETER_OK) {
+ print_command_error(ctx, "expected error running start function: \"%s\"",
+ path);
+ result = WASM_ERROR;
+ } else {
+ ctx->passed++;
+ result = WASM_OK;
+ }
+ } else {
+ print_command_error(ctx, "error reading module: \"%s\"", path);
+ result = WASM_ERROR;
+ }
+
+ wasm_reset_interpreter_environment_to_mark(ctx->allocator, &ctx->env, mark);
+ wasm_free(ctx->allocator, path);
+ return result;
}
static WasmBool typed_values_are_equal(const WasmInterpreterTypedValue* tv1,
@@ -1350,7 +1415,6 @@ static WasmResult on_assert_return_nan_command(Context* ctx, Action* action) {
result = WASM_ERROR;
break;
}
-
} else {
print_command_error(ctx, "unexpected trap: %s", s_trap_strings[iresult]);
result = WASM_ERROR;
diff --git a/test/spec/binary.txt b/test/spec/binary.txt
index 789fba87..ff374033 100644
--- a/test/spec/binary.txt
+++ b/test/spec/binary.txt
@@ -37,5 +37,23 @@ assert_malformed error:
third_party/testsuite/binary.wast:15:20: error in binary module: @0x00000008: bad wasm file version: 0xe (expected 0xd)
(assert_malformed (module "\00asm\0e\00\00\00") "unknown binary version")
^^^^^^
-0/0 tests passed.
+third_party/testsuite/binary.wast:6: assert_malformed passed:
+ error: @0x00000000: unable to read uint32_t: magic
+third_party/testsuite/binary.wast:7: assert_malformed passed:
+ error: @0x00000000: unable to read uint32_t: magic
+third_party/testsuite/binary.wast:8: assert_malformed passed:
+ error: @0x00000000: unable to read uint32_t: magic
+third_party/testsuite/binary.wast:9: assert_malformed passed:
+ error: @0x00000000: unable to read uint32_t: magic
+third_party/testsuite/binary.wast:10: assert_malformed passed:
+ error: @0x00000004: bad magic value
+third_party/testsuite/binary.wast:12: assert_malformed passed:
+ error: @0x00000004: unable to read uint32_t: version
+third_party/testsuite/binary.wast:13: assert_malformed passed:
+ error: @0x00000004: unable to read uint32_t: version
+third_party/testsuite/binary.wast:14: assert_malformed passed:
+ error: @0x00000004: unable to read uint32_t: version
+third_party/testsuite/binary.wast:15: assert_malformed passed:
+ error: @0x00000008: bad wasm file version: 0xe (expected 0xd)
+9/9 tests passed.
;;; STDOUT ;;)
diff --git a/test/spec/imports.txt b/test/spec/imports.txt
index 9ba25bfa..ddddb243 100644
--- a/test/spec/imports.txt
+++ b/test/spec/imports.txt
@@ -35,172 +35,172 @@ called host spectest.print(i64:25, f64:53) =>
called host spectest.print(i64:24) =>
called host spectest.print(i64:24) =>
called host spectest.print(i64:24) =>
-third_party/testsuite/imports.wast:72: assert_unlinkable error:
+third_party/testsuite/imports.wast:72: assert_unlinkable passed:
error: unknown module field "unknown"
error: @0x0000001e: on_import callback failed
-third_party/testsuite/imports.wast:76: assert_unlinkable error:
+third_party/testsuite/imports.wast:76: assert_unlinkable passed:
error: unknown host function import "spectest.unknown"
error: @0x00000024: on_import_func callback failed
-third_party/testsuite/imports.wast:81: assert_unlinkable error:
+third_party/testsuite/imports.wast:81: assert_unlinkable passed:
error: import signature mismatch
error: @0x0000001e: on_import_func callback failed
-third_party/testsuite/imports.wast:85: assert_unlinkable error:
+third_party/testsuite/imports.wast:85: assert_unlinkable passed:
error: import signature mismatch
error: @0x0000001e: on_import_func callback failed
-third_party/testsuite/imports.wast:89: assert_unlinkable error:
+third_party/testsuite/imports.wast:89: assert_unlinkable passed:
error: import signature mismatch
error: @0x0000001f: on_import_func callback failed
-third_party/testsuite/imports.wast:93: assert_unlinkable error:
+third_party/testsuite/imports.wast:93: assert_unlinkable passed:
error: import signature mismatch
error: @0x00000021: on_import_func callback failed
-third_party/testsuite/imports.wast:97: assert_unlinkable error:
+third_party/testsuite/imports.wast:97: assert_unlinkable passed:
error: import signature mismatch
error: @0x00000022: on_import_func callback failed
-third_party/testsuite/imports.wast:101: assert_unlinkable error:
+third_party/testsuite/imports.wast:101: assert_unlinkable passed:
error: import signature mismatch
error: @0x00000022: on_import_func callback failed
-third_party/testsuite/imports.wast:105: assert_unlinkable error:
+third_party/testsuite/imports.wast:105: assert_unlinkable passed:
error: import signature mismatch
error: @0x00000022: on_import_func callback failed
-third_party/testsuite/imports.wast:109: assert_unlinkable error:
+third_party/testsuite/imports.wast:109: assert_unlinkable passed:
error: import signature mismatch
error: @0x00000023: on_import_func callback failed
-third_party/testsuite/imports.wast:113: assert_unlinkable error:
+third_party/testsuite/imports.wast:113: assert_unlinkable passed:
error: import signature mismatch
error: @0x00000022: on_import_func callback failed
-third_party/testsuite/imports.wast:117: assert_unlinkable error:
+third_party/testsuite/imports.wast:117: assert_unlinkable passed:
error: import signature mismatch
error: @0x00000023: on_import_func callback failed
-third_party/testsuite/imports.wast:121: assert_unlinkable error:
+third_party/testsuite/imports.wast:121: assert_unlinkable passed:
error: import signature mismatch
error: @0x00000023: on_import_func callback failed
-third_party/testsuite/imports.wast:125: assert_unlinkable error:
+third_party/testsuite/imports.wast:125: assert_unlinkable passed:
error: import signature mismatch
error: @0x00000023: on_import_func callback failed
-third_party/testsuite/imports.wast:129: assert_unlinkable error:
+third_party/testsuite/imports.wast:129: assert_unlinkable passed:
error: import signature mismatch
error: @0x00000024: on_import_func callback failed
-third_party/testsuite/imports.wast:133: assert_unlinkable error:
+third_party/testsuite/imports.wast:133: assert_unlinkable passed:
error: import signature mismatch
error: @0x00000026: on_import_func callback failed
-third_party/testsuite/imports.wast:137: assert_unlinkable error:
+third_party/testsuite/imports.wast:137: assert_unlinkable passed:
error: import signature mismatch
error: @0x00000027: on_import_func callback failed
-third_party/testsuite/imports.wast:141: assert_unlinkable error:
+third_party/testsuite/imports.wast:141: assert_unlinkable passed:
error: import signature mismatch
error: @0x00000027: on_import_func callback failed
-third_party/testsuite/imports.wast:146: assert_unlinkable error:
+third_party/testsuite/imports.wast:146: assert_unlinkable passed:
error: expected import "test.global-i32" to have kind func, not global
error: @0x00000024: on_import_func callback failed
-third_party/testsuite/imports.wast:150: assert_unlinkable error:
+third_party/testsuite/imports.wast:150: assert_unlinkable passed:
error: expected import "test.table-10-inf" to have kind func, not table
error: @0x00000025: on_import_func callback failed
-third_party/testsuite/imports.wast:154: assert_unlinkable error:
+third_party/testsuite/imports.wast:154: assert_unlinkable passed:
error: expected import "test.memory-2-inf" to have kind func, not memory
error: @0x00000025: on_import_func callback failed
-third_party/testsuite/imports.wast:158: assert_unlinkable error:
+third_party/testsuite/imports.wast:158: assert_unlinkable passed:
error: unknown host function import "spectest.global"
error: @0x00000023: on_import_func callback failed
-third_party/testsuite/imports.wast:162: assert_unlinkable error:
+third_party/testsuite/imports.wast:162: assert_unlinkable passed:
error: unknown host function import "spectest.table"
error: @0x00000022: on_import_func callback failed
-third_party/testsuite/imports.wast:166: assert_unlinkable error:
+third_party/testsuite/imports.wast:166: assert_unlinkable passed:
error: unknown host function import "spectest.memory"
error: @0x00000023: on_import_func callback failed
-third_party/testsuite/imports.wast:199: assert_unlinkable error:
+third_party/testsuite/imports.wast:199: assert_unlinkable passed:
error: unknown module field "unknown"
error: @0x00000018: on_import callback failed
-third_party/testsuite/imports.wast:203: assert_unlinkable error:
+third_party/testsuite/imports.wast:203: assert_unlinkable passed:
error: unknown host global import "spectest.unknown"
error: @0x0000001f: on_import_global callback failed
-third_party/testsuite/imports.wast:208: assert_unlinkable error:
+third_party/testsuite/imports.wast:208: assert_unlinkable passed:
error: expected import "test.func" to have kind global, not func
error: @0x00000018: on_import_global callback failed
-third_party/testsuite/imports.wast:212: assert_unlinkable error:
+third_party/testsuite/imports.wast:212: assert_unlinkable passed:
error: expected import "test.table-10-inf" to have kind global, not table
error: @0x00000020: on_import_global callback failed
-third_party/testsuite/imports.wast:216: assert_unlinkable error:
+third_party/testsuite/imports.wast:216: assert_unlinkable passed:
error: expected import "test.memory-2-inf" to have kind global, not memory
error: @0x00000020: on_import_global callback failed
-third_party/testsuite/imports.wast:220: assert_unlinkable error:
+third_party/testsuite/imports.wast:220: assert_unlinkable passed:
error: unknown host global import "spectest.print"
error: @0x0000001d: on_import_global callback failed
-third_party/testsuite/imports.wast:224: assert_unlinkable error:
+third_party/testsuite/imports.wast:224: assert_unlinkable passed:
error: unknown host global import "spectest.table"
error: @0x0000001d: on_import_global callback failed
-third_party/testsuite/imports.wast:228: assert_unlinkable error:
+third_party/testsuite/imports.wast:228: assert_unlinkable passed:
error: unknown host global import "spectest.memory"
error: @0x0000001e: on_import_global callback failed
-third_party/testsuite/imports.wast:295: assert_unlinkable error:
+third_party/testsuite/imports.wast:295: assert_unlinkable passed:
error: unknown module field "unknown"
error: @0x00000018: on_import callback failed
-third_party/testsuite/imports.wast:299: assert_unlinkable error:
+third_party/testsuite/imports.wast:299: assert_unlinkable passed:
error: unknown host table import "spectest.unknown"
error: @0x00000020: on_import_table callback failed
-third_party/testsuite/imports.wast:304: assert_unlinkable error:
+third_party/testsuite/imports.wast:304: assert_unlinkable passed:
error: actual size (10) smaller than declared (12)
error: @0x00000021: on_import_table callback failed
-third_party/testsuite/imports.wast:308: assert_unlinkable error:
+third_party/testsuite/imports.wast:308: assert_unlinkable passed:
error: max size (unspecified) larger than declared (20)
error: @0x00000022: on_import_table callback failed
-third_party/testsuite/imports.wast:312: assert_unlinkable error:
+third_party/testsuite/imports.wast:312: assert_unlinkable passed:
error: actual size (10) smaller than declared (12)
error: @0x0000001e: on_import_table callback failed
-third_party/testsuite/imports.wast:316: assert_unlinkable error:
+third_party/testsuite/imports.wast:316: assert_unlinkable passed:
error: max size (20) larger than declared (15)
error: @0x0000001f: on_import_table callback failed
-third_party/testsuite/imports.wast:321: assert_unlinkable error:
+third_party/testsuite/imports.wast:321: assert_unlinkable passed:
error: expected import "test.func" to have kind table, not func
error: @0x00000019: on_import_table callback failed
-third_party/testsuite/imports.wast:325: assert_unlinkable error:
+third_party/testsuite/imports.wast:325: assert_unlinkable passed:
error: expected import "test.global-i32" to have kind table, not global
error: @0x0000001f: on_import_table callback failed
-third_party/testsuite/imports.wast:329: assert_unlinkable error:
+third_party/testsuite/imports.wast:329: assert_unlinkable passed:
error: expected import "test.memory-2-inf" to have kind table, not memory
error: @0x00000021: on_import_table callback failed
-third_party/testsuite/imports.wast:333: assert_unlinkable error:
+third_party/testsuite/imports.wast:333: assert_unlinkable passed:
error: unknown host table import "spectest.print"
error: @0x0000001e: on_import_table callback failed
-third_party/testsuite/imports.wast:388: assert_unlinkable error:
+third_party/testsuite/imports.wast:388: assert_unlinkable passed:
error: unknown module field "unknown"
error: @0x00000018: on_import callback failed
-third_party/testsuite/imports.wast:392: assert_unlinkable error:
+third_party/testsuite/imports.wast:392: assert_unlinkable passed:
error: unknown host memory import "spectest.unknown"
error: @0x0000001f: on_import_memory callback failed
-third_party/testsuite/imports.wast:397: assert_unlinkable error:
+third_party/testsuite/imports.wast:397: assert_unlinkable passed:
error: actual size (2) smaller than declared (3)
error: @0x00000020: on_import_memory callback failed
-third_party/testsuite/imports.wast:401: assert_unlinkable error:
+third_party/testsuite/imports.wast:401: assert_unlinkable passed:
error: max size (unspecified) larger than declared (3)
error: @0x00000021: on_import_memory callback failed
-third_party/testsuite/imports.wast:405: assert_unlinkable error:
+third_party/testsuite/imports.wast:405: assert_unlinkable passed:
error: actual size (1) smaller than declared (2)
error: @0x0000001e: on_import_memory callback failed
-third_party/testsuite/imports.wast:409: assert_unlinkable error:
+third_party/testsuite/imports.wast:409: assert_unlinkable passed:
error: max size (2) larger than declared (1)
error: @0x0000001f: on_import_memory callback failed
-third_party/testsuite/imports.wast:414: assert_unlinkable error:
+third_party/testsuite/imports.wast:414: assert_unlinkable passed:
error: expected import "test.func-i32" to have kind memory, not func
error: @0x0000001c: on_import_memory callback failed
-third_party/testsuite/imports.wast:418: assert_unlinkable error:
+third_party/testsuite/imports.wast:418: assert_unlinkable passed:
error: expected import "test.global-i32" to have kind memory, not global
error: @0x0000001e: on_import_memory callback failed
-third_party/testsuite/imports.wast:422: assert_unlinkable error:
+third_party/testsuite/imports.wast:422: assert_unlinkable passed:
error: expected import "test.table-10-inf" to have kind memory, not table
error: @0x00000020: on_import_memory callback failed
-third_party/testsuite/imports.wast:426: assert_unlinkable error:
+third_party/testsuite/imports.wast:426: assert_unlinkable passed:
error: unknown host memory import "spectest.print"
error: @0x0000001d: on_import_memory callback failed
-third_party/testsuite/imports.wast:430: assert_unlinkable error:
+third_party/testsuite/imports.wast:430: assert_unlinkable passed:
error: unknown host memory import "spectest.global"
error: @0x0000001e: on_import_memory callback failed
-third_party/testsuite/imports.wast:434: assert_unlinkable error:
+third_party/testsuite/imports.wast:434: assert_unlinkable passed:
error: unknown host memory import "spectest.table"
error: @0x0000001d: on_import_memory callback failed
-third_party/testsuite/imports.wast:439: assert_unlinkable error:
+third_party/testsuite/imports.wast:439: assert_unlinkable passed:
error: actual size (1) smaller than declared (2)
error: @0x0000001e: on_import_memory callback failed
-third_party/testsuite/imports.wast:443: assert_unlinkable error:
+third_party/testsuite/imports.wast:443: assert_unlinkable passed:
error: max size (2) larger than declared (1)
error: @0x0000001f: on_import_memory callback failed
85/85 tests passed.
diff --git a/test/spec/linking.txt b/test/spec/linking.txt
index aaf84fac..dd7407da 100644
--- a/test/spec/linking.txt
+++ b/test/spec/linking.txt
@@ -1,16 +1,16 @@
;;; TOOL: run-interp-spec
;;; STDIN_FILE: third_party/testsuite/linking.wast
(;; STDOUT ;;;
-third_party/testsuite/linking.wast:28: assert_unlinkable error:
+third_party/testsuite/linking.wast:28: assert_unlinkable passed:
error: import signature mismatch
error: @0x00000025: on_import_func callback failed
-third_party/testsuite/linking.wast:32: assert_unlinkable error:
+third_party/testsuite/linking.wast:32: assert_unlinkable passed:
error: import signature mismatch
error: @0x00000026: on_import_func callback failed
-third_party/testsuite/linking.wast:160: assert_unlinkable error:
+third_party/testsuite/linking.wast:160: assert_unlinkable passed:
error: unknown module field "mem"
error: @0x00000038: on_import callback failed
-third_party/testsuite/linking.wast:233: assert_unlinkable error:
+third_party/testsuite/linking.wast:233: assert_unlinkable passed:
error: unknown module field "tab"
error: @0x00000033: on_import callback failed
69/69 tests passed.
diff --git a/test/spec/memory.txt b/test/spec/memory.txt
index 13bfbadb..b3f792e4 100644
--- a/test/spec/memory.txt
+++ b/test/spec/memory.txt
@@ -121,13 +121,13 @@ assert_invalid error:
third_party/testsuite/memory.wast:162:29: alignment must not be larger than natural alignment (1)
(module (memory 0) (func (i32.store8 align=2 (i32.const 0) (i32.const 0))))
^^^^^^^^^^^^^^^^^^
-third_party/testsuite/memory.wast:47: assert_unlinkable error:
+third_party/testsuite/memory.wast:47: assert_unlinkable passed:
error: data segment is out of bounds: [0, 1) >= max value 0
error: @0x00000017: on_data_segment_data callback failed
-third_party/testsuite/memory.wast:51: assert_unlinkable error:
+third_party/testsuite/memory.wast:51: assert_unlinkable passed:
error: data segment is out of bounds: [98304, 98305) >= max value 65536
error: @0x0000001f: on_data_segment_data callback failed
-third_party/testsuite/memory.wast:60: assert_unlinkable error:
+third_party/testsuite/memory.wast:60: assert_unlinkable passed:
error: data segment is out of bounds: [65536, 65537) >= max value 65536
error: @0x00000020: on_data_segment_data callback failed
30/30 tests passed.
diff --git a/test/spec/start.txt b/test/spec/start.txt
index 9d956525..41deaa98 100644
--- a/test/spec/start.txt
+++ b/test/spec/start.txt
@@ -19,5 +19,5 @@ inc() =>
inc() =>
called host spectest.print(i32:1) =>
called host spectest.print(i32:2) =>
-10/10 tests passed.
+11/11 tests passed.
;;; STDOUT ;;)