From f9a31c8ecd0181586c00cd5f780ad3e111b52519 Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Wed, 17 Mar 2021 01:53:00 +0200 Subject: [PATCH] Test harness: support multi-values --- platforms/app/main.c | 17 ++++++---- platforms/python/test/dyn_callback.c | 2 +- test/run-spec-test.py | 48 ++++++++++++++++++---------- test/wasi/simple/wasm_api.h | 5 --- 4 files changed, 42 insertions(+), 30 deletions(-) diff --git a/platforms/app/main.c b/platforms/app/main.c index f698816..b5b7a63 100644 --- a/platforms/app/main.c +++ b/platforms/app/main.c @@ -312,20 +312,23 @@ M3Result repl_invoke (const char* name, int argc, const char* argv[]) result = m3_GetResults (func, ret_count, valptrs); if (result) return result; + fprintf (stderr, "Result: "); if (ret_count <= 0) { - fprintf (stderr, "Result: \n"); + fprintf (stderr, ""); } for (int i = 0; i < ret_count; i++) { switch (m3_GetRetType(func, i)) { - case c_m3Type_i32: - case c_m3Type_f32: - fprintf (stderr, "Result: %" PRIu32 "\n", *(u32*)valptrs[i]); break; - case c_m3Type_i64: - case c_m3Type_f64: - fprintf (stderr, "Result: %" PRIu64 "\n", *(u64*)valptrs[i]); break; + case c_m3Type_i32: fprintf (stderr, "%" PRIu32 ":i32", *(u32*)valptrs[i]); break; + case c_m3Type_f32: fprintf (stderr, "%" PRIu32 ":f32", *(u32*)valptrs[i]); break; + case c_m3Type_i64: fprintf (stderr, "%" PRIu64 ":i64", *(u64*)valptrs[i]); break; + case c_m3Type_f64: fprintf (stderr, "%" PRIu64 ":f64", *(u64*)valptrs[i]); break; default: return "unknown return type"; } + if (i != ret_count-1) { + fprintf (stderr, ", "); + } } + fprintf (stderr, "\n"); return result; } diff --git a/platforms/python/test/dyn_callback.c b/platforms/python/test/dyn_callback.c index 95b856b..cd159cb 100644 --- a/platforms/python/test/dyn_callback.c +++ b/platforms/python/test/dyn_callback.c @@ -1,6 +1,6 @@ /* * Build using: - * emcc fptr.c -Os -s WASM=1 -s SIDE_MODULE=1 -o fptr.wasm + * emcc dyn_callback.c -Os -s WASM=1 -s SIDE_MODULE=1 -o dyn_callback.wasm */ typedef int (*fptr_type)(int x, int y); diff --git a/test/run-spec-test.py b/test/run-spec-test.py index 9182f60..2f9f829 100755 --- a/test/run-spec-test.py +++ b/test/run-spec-test.py @@ -295,6 +295,34 @@ class Wasm3(): self.p.wait(timeout=1.0) self.p = None +# +# Multi-value result handling +# + +def parseResults(s): + values = s.split(", ") + values = [x.split(":") for x in values] + values = [{ "type": x[1], "value": int(x[0]) } for x in values] + + return normalizeResults(values) + +def normalizeResults(values): + for x in values: + t = x["type"] + v = x["value"] + if t == "f32" or t == "f64": + if v == "nan:canonical" or v == "nan:arithmetic" or math.isnan(binaryToFloat(v, t)): + x["value"] = "nan:any" + else: + x["value"] = formatValue(v, t) + else: + x["value"] = formatValue(v, t) + return values + +def combineResults(values): + values = [x["value"]+":"+x["type"] for x in values] + return ", ".join(values) + # # Actual test # @@ -401,25 +429,11 @@ def runInvoke(test): if "expected" in test: if len(test.expected) == 0: expect = "result " - elif len(test.expected) == 1: - t = test.expected[0]['type'] - value = str(test.expected[0]['value']) - expect = "result " + value - + else: if actual_val is not None: - if (t == "f32" or t == "f64") and (value == "nan:canonical" or value == "nan:arithmetic"): - val = binaryToFloat(actual_val, t) - #warning(f"{actual_val} => {val}") - if math.isnan(val): - actual = "nan:any" - expect = "nan:any" - else: - expect = "result " + formatValue(value, t) - actual = "result " + formatValue(actual_val, t) + actual = "result " + combineResults(parseResults(actual_val)) + expect = "result " + combineResults(normalizeResults(test.expected)) - else: - warning(f"Test {test.source} specifies multiple results") - expect = "result " elif "expected_trap" in test: if test.expected_trap in trapmap: test.expected_trap = trapmap[test.expected_trap] diff --git a/test/wasi/simple/wasm_api.h b/test/wasi/simple/wasm_api.h index 8a26137..7c430ff 100644 --- a/test/wasi/simple/wasm_api.h +++ b/test/wasi/simple/wasm_api.h @@ -7,9 +7,4 @@ #define WASM_EXPORT_AS(NAME) WASM_EXPORT __attribute__((export_name(NAME))) #define WASM_IMPORT(MODULE,NAME) __attribute__((import_module(MODULE))) __attribute__((import_name(NAME))) -//__attribute__((weak)) - -WASM_IMPORT("wasm3", "raw_sum") -int64_t wasm3_raw_sum (int32_t val1, int32_t val2, int32_t val3, int32_t val4); - #endif