Test harness: support multi-values

extensions
Volodymyr Shymanskyy 3 years ago
parent bd455d5701
commit f9a31c8ecd

@ -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: <Empty Stack>\n");
fprintf (stderr, "<Empty Stack>");
}
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;
}

@ -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);

@ -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 <Empty Stack>"
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 <Multiple>"
elif "expected_trap" in test:
if test.expected_trap in trapmap:
test.expected_trap = trapmap[test.expected_trap]

@ -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

Loading…
Cancel
Save