==> tests/differential.c <==1/* The same C, compiled natively here and to wasm32 by clang (fixtures/prog.c, its bytes in
2 * fixtures/prog.h), must give the same numbers in the interpreter: integer and float arithmetic,
3 * br_table, call_indirect, recursion, data segments, linear memory. */
4#include "mesh/check.h"
5#include "wasm/interp.h"
6
7#include <stdio.h>
8
9#define PROG_PREFIX(x) native_##x
10#include "fixtures/prog.c"
11#include "fixtures/prog.h"
12
13static char err[256];
14
15int main(void) {
16 wasm_compiled *c = wasm_compile(prog_wasm, prog_wasm_len, WASM_F_INTERP, err, sizeof err);
17 if (!c) fprintf(stderr, "compile: %s\n", err);
18 CHECK(c != NULL);
19 if (!c) return mesh_check_done();
20 wasm_instance *I = wasm_instantiate(c, NULL, 0, NULL, NULL, err, sizeof err);
21 if (!I) fprintf(stderr, "instantiate: %s\n", err);
22 CHECK(I != NULL);
23 if (I) {
24 int64_t run = wasm_instance_func(I, "run", "i>i", err, sizeof err);
25 int64_t fp = wasm_instance_func(I, "fp_run", "i>i", err, sizeof err);
26 CHECK(run >= 0 && fp >= 0);
27 for (uint32_t seed = 0; seed < 40 && run >= 0 && fp >= 0; seed++) {
28 uint64_t io[1] = {seed};
29 CHECK_I(wasm_call(I, (uint32_t)run, io), WASM_NUM_OK);
30 CHECK_U((uint32_t)io[0], native_run(seed));
31 io[0] = seed * 7919;
32 CHECK_I(wasm_call(I, (uint32_t)fp, io), WASM_NUM_OK);
33 CHECK_U((uint32_t)io[0], native_fp_run(seed * 7919));
34 }
35 wasm_instance_free(I);
36 }
37 wasm_compiled_free(c);
38 return mesh_check_done();
39}