-
Notifications
You must be signed in to change notification settings - Fork 1
/
testmain.c
2496 lines (2250 loc) · 67 KB
/
testmain.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <pwart.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#define puti32 pwart_rstack_put_i32
#define puti64 pwart_rstack_put_i64
#define putf32 pwart_rstack_put_f32
#define putf64 pwart_rstack_put_f64
#define putref pwart_rstack_put_ref
#define geti32 pwart_rstack_get_i32
#define geti64 pwart_rstack_get_i64
#define getf32 pwart_rstack_get_f32
#define getf64 pwart_rstack_get_f64
#define getref pwart_rstack_get_ref
static void test_wasmfn(void *fp) {
void *sp = fp;
uint64_t r = geti64(&sp) + geti64(&sp) + 2;
sp = fp;
puti64(&sp, r);
}
static void test_printf64(void *fp) {
void *sp = fp;
printf("testaid:%lf\n", getf64(&sp));
sp = fp;
printf("testaid:%lld\n", geti64(&sp));
}
static void test_printi64(void *fp) {
void *sp = fp;
printf("testaid:%lld\n", geti64(&sp));
}
static void do_resolve(struct pwart_symbol_resolver *_this,struct pwart_symbol_resolve_request *req) {
char *mod=req->import_module;
char *name=req->import_field;
void **val=&req->result;
if (!strcmp("testaid", mod)) {
if (!strcmp("printi64", name)) {
*val = pwart_wrap_host_function_c(test_printi64);
} else if (!strcmp("printf64", name)) {
*val = pwart_wrap_host_function_c(test_printf64);
}
}
}
struct pwart_symbol_resolver symbol_resolver={.resolve=do_resolve};
// base test
int test1() {
struct pwart_global_compile_config gcfg;
void *stackbase = pwart_allocate_stack(64 * 1024);
FILE *f = fopen("test1.wasm", "rb");
if(f==NULL){printf("open wasm file failed.\n");return 0;}
// 8MB buffer;
uint8_t *data = malloc(1024 * 1024 * 8);
int len = fread(data, 1, 1024 * 1024 * 8, f);
fclose(f);
pwart_get_global_compile_config(&gcfg);
for (int i1 = 0; i1 < 2; i1++) {
pwart_module_compiler m = pwart_new_module_compiler();
pwart_set_symbol_resolver(m, &symbol_resolver);
// different config
switch (i1) {
case 0:
printf("test config:default\n");
break;
case 1:
printf("test config:stack_flags=PWART_STACK_FLAGS_AUTO_ALIGN\n");
gcfg.stack_flags|=PWART_STACK_FLAGS_AUTO_ALIGN;
pwart_set_global_compile_config(&gcfg);
break;
}
struct pwart_inspect_result1 ctxinfo;
char *loadresult = pwart_compile(m, data, len);
if (loadresult != NULL) {
printf("error:%s\n", loadresult);
return 0;
}
pwart_module_state ctx = pwart_get_module_state(m);
pwart_inspect_module_state(ctx, &ctxinfo);
printf("runtime stack at %p\n", stackbase);
printf("context at %p\n", ctx);
pwart_wasm_function addTwo = pwart_get_export_function(ctx, "addTwo");
pwart_wasm_function test1 = pwart_get_export_function(ctx, "test1");
pwart_wasm_function test2 = pwart_get_export_function(ctx, "test2");
pwart_wasm_function test3 = pwart_get_export_function(ctx, "test3");
pwart_wasm_function fib_main = pwart_get_export_function(ctx, "fib_main");
pwart_wasm_function builtinFuncTest =
pwart_get_export_function(ctx, "builtinFuncTest");
pwart_wasm_function miscTest1 =
pwart_get_export_function(ctx, "miscTest1");
pwart_free_module_compiler(m);
void *sp;
int32_t ri32;
int32_t ri32_2;
int32_t ri32_3;
uint64_t ri64;
void *rref;
sp = stackbase;
puti64(&sp, 123);
puti64(&sp, 654);
sp = stackbase;
pwart_call_wasm_function(addTwo, sp);
ri64 = geti64(&sp);
printf("1.expect %"PRIu64", got %"PRIu64"\n", (uint64_t)777ll, ri64);
if ((uint64_t)777ll != ri64) {
return 0;
}
sp = stackbase;
puti32(&sp, 22);
puti32(&sp, 33);
sp = stackbase;
pwart_call_wasm_function(test1, sp);
ri32 = geti32(&sp);
printf("2.expect %u, got %u\n", (22 + 33) * 2, ri32);
if ((22 + 33) * 2 != ri32) {
return 0;
}
sp = stackbase;
puti32(&sp, 100);
puti32(&sp, 11);
sp = stackbase;
pwart_call_wasm_function(test1, sp);
ri32 = geti32(&sp);
printf("3.expect %u, got %u\n", 100 + 11, ri32);
if (100 + 11 != ri32) {
return 0;
}
char *memstr = (uint8_t *)ctxinfo.memory;
*(memstr + 50) = 0;
printf("4.expect HelloHello!!!!, got %s\n", memstr + 1);
if (strcmp(memstr + 1, "HelloHello!!!!") != 0) {
return 0;
}
printf("5.expect %p, got %p , %p\n", ctxinfo.table_entries[0],
ctxinfo.table_entries[1], ctxinfo.table_entries[2]);
if (ctxinfo.table_entries[0] != ctxinfo.table_entries[1]) {
return 0;
}
if (ctxinfo.table_entries[0] != ctxinfo.table_entries[2]) {
return 0;
}
sp = stackbase;
puti64(&sp, 22);
puti64(&sp, 33);
sp = stackbase;
pwart_call_wasm_function(test2, sp);
ri64 = geti64(&sp);
printf("6.expect %u, got %"PRIu64"\n", (22 + 33 + 140), ri64);
if (22 + 33 + 140 != ri64) {
return 0;
}
ctxinfo.table_entries[1] = &test_wasmfn;
sp = stackbase;
puti64(&sp, 22);
puti64(&sp, 33);
sp = stackbase;
pwart_call_wasm_function(test2, sp);
ri64 = geti64(&sp);
printf("7.expect %u, got %"PRIu64"\n", 22 + 33 + 140 + 2, ri64);
if (22 + 33 + 140 + 2 != ri64) {
return 0;
}
sp = stackbase;
// align and float add test
puti32(&sp, 3844);
putf64(&sp, 3.25);
putf64(&sp, 4.75);
sp = stackbase;
pwart_call_wasm_function(test3, sp);
ri32 = geti32(&sp);
ri64 = geti64(&sp);
printf("8.expect %d,%"PRIu64", got %d,%"PRIu64"\n", 3844, (int64_t)(3.25 + 4.75), ri32,
ri64);
if ((int64_t)(3.25 + 4.75) != ri64) {
return 0;
}
if (ri32 != 3844) {
return 0;
}
// fibnacci sequence
sp = stackbase;
puti32(&sp, 2);
puti32(&sp, 100);
*(int *)((char *)ctxinfo.memory + 100) = 0;
*(int *)((char *)ctxinfo.memory + 104) = 116;
memcpy((char *)ctxinfo.memory + 116, "30", 3);
sp = stackbase;
pwart_call_wasm_function(fib_main, sp);
ri32 = geti32(&sp);
printf("9.fib test, expect %d, got %d\n", 832040, ri32);
if (832040 != ri32) {
return 0;
}
// builtinFuncTest test
sp = stackbase;
sp = stackbase;
pwart_call_wasm_function(builtinFuncTest, sp);
ri32 = geti32(&sp);
ri32_2=geti32(&sp);
rref = getref(&sp);
ri32_3=geti32(&sp);
printf("10.builtinFuncTest test, expect %x,%x,%p,%x, got %x,%x,%p,%x\n",
pwart_get_version(),(uint32_t)sizeof(void *) ,ctx,(uint32_t)strlen(memstr+1), ri32, ri32_2,rref,ri32_3);
if (pwart_get_version() != ri32 || sizeof(void *)!=ri32_2 || ctx != rref || strlen(memstr+1)!=ri32_3) {
return 0;
}
// miscTest1 test
sp = stackbase;
sp = stackbase;
pwart_call_wasm_function(miscTest1, sp);
ri32 = geti32(&sp);
printf("11.miscTest1 test, expect %x got %x\n",
4,ri32);
if (4!=ri32) {
return 0;
}
pwart_free_module_state(ctx);
}
free(data);
pwart_free_stack(stackbase);
return 1;
}
int unary_test() {
FILE *f = fopen("unary.wasm", "rb");
if(f==NULL){printf("open wasm file failed.\n");return 0;}
// 8MB buffer;
uint8_t *data = malloc(1024 * 1024 * 8);
int len = fread(data, 1, 1024 * 1024 * 8, f);
void *stackbase = pwart_allocate_stack(64 * 1024);
fclose(f);
struct pwart_inspect_result1 ctxinfo;
char *err=NULL;
pwart_module_state ctx=pwart_load_module(data,len,&err);
if(err!=NULL){printf("load module failed:%s\n",err);return 0;};
pwart_inspect_module_state(ctx, &ctxinfo);
printf("runtime stack at %p\n", stackbase);
pwart_wasm_function fn;
void *sp;
fn = pwart_get_export_function(ctx, "i32_eqz_100");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i32_eqz_100 check...");
if (*(uint32_t *)sp != 0) {
printf("failed, expect %u, got %u\n", 0, *(uint32_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i32_eqz_0");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i32_eqz_0 check...");
if (*(uint32_t *)sp != 1) {
printf("failed, expect %u, got %u\n", 1, *(uint32_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i32_clz");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i32_clz check...");
if (*(uint32_t *)sp != 24) {
printf("failed, expect %u, got %u\n", 24, *(uint32_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i32_ctz");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i32_ctz check...");
if (*(uint32_t *)sp != 7) {
printf("failed, expect %u, got %u\n", 7, *(uint32_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i32_popcnt");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i32_popcnt check...");
if (*(uint32_t *)sp != 1) {
printf("failed, expect %u, got %u\n", 1, *(uint32_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i64_eqz_100");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i64_eqz_100 check...");
if (*(uint32_t *)sp != 0) {
printf("failed, expect %u, got %u\n", 0, *(uint32_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i64_eqz_0");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i64_eqz_0 check...");
if (*(uint32_t *)sp != 1) {
printf("failed, expect %u, got %u\n", 1, *(uint32_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i64_clz");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i64_clz check...");
if (*(uint64_t *)sp != 56) {
printf("failed, expect %"PRIu64", got %"PRIu64"\n", (uint64_t)56ll, *(uint64_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i64_ctz");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i64_ctz check...");
if (*(uint64_t *)sp != 7) {
printf("failed, expect %"PRIu64", got %"PRIu64"\n", (uint64_t)7ll, *(uint64_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i64_popcnt");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i64_popcnt check...");
if (*(uint64_t *)sp != 1) {
printf("failed, expect %"PRIu64", got %"PRIu64"\n", (uint64_t)1ll, *(uint64_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f32_neg");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f32_neg check...");
if (*(float *)sp != -100.000000) {
printf("failed, expect %f, got %f\n", -100.000000, *(float *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f32_abs");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f32_abs check...");
if (*(float *)sp != 100.000000) {
printf("failed, expect %f, got %f\n", 100.000000, *(float *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f32_sqrt_neg_is_nan");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f32_sqrt_neg_is_nan check...");
if (*(uint32_t *)sp != 1) {
printf("failed, expect %u, got %u\n", 1, *(uint32_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f32_sqrt_100");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f32_sqrt_100 check...");
if (*(float *)sp != 10.000000) {
printf("failed, expect %f, got %f\n", 10.000000, *(float *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f32_ceil");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f32_ceil check...");
if (*(float *)sp != -0.000000) {
printf("failed, expect %f, got %f\n", -0.000000, *(float *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f32_floor");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f32_floor check...");
if (*(float *)sp != -1.000000) {
printf("failed, expect %f, got %f\n", -1.000000, *(float *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f32_trunc");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f32_trunc check...");
if (*(float *)sp != -0.000000) {
printf("failed, expect %f, got %f\n", -0.000000, *(float *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f32_nearest_lo");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f32_nearest_lo check...");
if (*(float *)sp != 1.000000) {
printf("failed, expect %f, got %f\n", 1.000000, *(float *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f32_nearest_hi");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f32_nearest_hi check...");
if (*(float *)sp != 2.000000) {
printf("failed, expect %f, got %f\n", 2.000000, *(float *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f64_neg");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f64_neg check...");
if (*(double *)sp != -100.000000) {
printf("failed, expect %lf, got %lf\n", -100.000000, *(double *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f64_abs");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f64_abs check...");
if (*(double *)sp != 100.000000) {
printf("failed, expect %lf, got %lf\n", 100.000000, *(double *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f64_sqrt_neg_is_nan");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f64_sqrt_neg_is_nan check...");
if (*(uint32_t *)sp != 1) {
printf("failed, expect %u, got %u\n", 1, *(uint32_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f64_sqrt_100");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f64_sqrt_100 check...");
if (*(double *)sp != 10.000000) {
printf("failed, expect %lf, got %lf\n", 10.000000, *(double *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f64_ceil");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f64_ceil check...");
if (*(double *)sp != -0.000000) {
printf("failed, expect %lf, got %lf\n", -0.000000, *(double *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f64_floor");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f64_floor check...");
if (*(double *)sp != -1.000000) {
printf("failed, expect %lf, got %lf\n", -1.000000, *(double *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f64_trunc");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f64_trunc check...");
if (*(double *)sp != -0.000000) {
printf("failed, expect %lf, got %lf\n", -0.000000, *(double *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f64_nearest_lo");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f64_nearest_lo check...");
if (*(double *)sp != 1.000000) {
printf("failed, expect %lf, got %lf\n", 1.000000, *(double *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f64_nearest_hi");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f64_nearest_hi check...");
if (*(double *)sp != 2.000000) {
printf("failed, expect %lf, got %lf\n", 2.000000, *(double *)sp);
return 0;
}
printf("pass\n");
pwart_free_module_state(ctx);
pwart_free_stack(stackbase);
return 1;
}
int binary_test() {
FILE *f = fopen("binary.wasm", "rb");
if(f==NULL){printf("open wasm file failed.\n");return 0;}
// 8MB buffer;
uint8_t *data = malloc(1024 * 1024 * 8);
int len = fread(data, 1, 1024 * 1024 * 8, f);
void *stackbase = pwart_allocate_stack(64 * 1024);
fclose(f);
struct pwart_inspect_result1 ctxinfo;
char *err=NULL;
pwart_module_state ctx=pwart_load_module(data,len,&err);
pwart_inspect_module_state(ctx, &ctxinfo);
printf("runtime stack at %p\n", stackbase);
pwart_wasm_function fn;
void *sp;
fn = pwart_get_export_function(ctx, "i32_add");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i32_add check...");
if (*(uint32_t *)sp != 3) {
printf("failed, expect %u, got %u\n", 3, *(uint32_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i32_sub");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i32_sub check...");
if (*(uint32_t *)sp != 16) {
printf("failed, expect %u, got %u\n", 16, *(uint32_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i32_mul");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i32_mul check...");
if (*(uint32_t *)sp != 21) {
printf("failed, expect %u, got %u\n", 21, *(uint32_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i32_div_s");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i32_div_s check...");
if (*(uint32_t *)sp != 4294967294) {
printf("failed, expect %u, got %u\n", (uint32_t)4294967294,
*(uint32_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i32_div_u");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i32_div_u check...");
if (*(uint32_t *)sp != 2147483646) {
printf("failed, expect %u, got %u\n", 2147483646, *(uint32_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i32_rem_s");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i32_rem_s check...");
if (*(uint32_t *)sp != 4294967295) {
printf("failed, expect %u, got %u\n", (uint32_t)4294967295,
*(uint32_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i32_rem_u");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i32_rem_u check...");
if (*(uint32_t *)sp != 1) {
printf("failed, expect %u, got %u\n", 1, *(uint32_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i32_and");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i32_and check...");
if (*(uint32_t *)sp != 1) {
printf("failed, expect %u, got %u\n", 1, *(uint32_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i32_or");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i32_or check...");
if (*(uint32_t *)sp != 15) {
printf("failed, expect %u, got %u\n", 15, *(uint32_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i32_xor");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i32_xor check...");
if (*(uint32_t *)sp != 14) {
printf("failed, expect %u, got %u\n", 14, *(uint32_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i32_shl");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i32_shl check...");
if (*(uint32_t *)sp != 4294966496) {
printf("failed, expect %u, got %u\n", (uint32_t)4294966496,
*(uint32_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i32_shr_u");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i32_shr_u check...");
if (*(uint32_t *)sp != 536870899) {
printf("failed, expect %u, got %u\n", (uint32_t)536870899, *(uint32_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i32_shr_s");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i32_shr_s check...");
if (*(uint32_t *)sp != 4294967283) {
printf("failed, expect %u, got %u\n", (uint32_t)4294967283,
*(uint32_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i32_rotl");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i32_rotl check...");
if (*(uint32_t *)sp != 4294966503) {
printf("failed, expect %u, got %u\n", (uint32_t)4294966503,
*(uint32_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i32_rotr");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i32_rotr check...");
if (*(uint32_t *)sp != 2684354547) {
printf("failed, expect %u, got %u\n", (uint32_t)2684354547,
*(uint32_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i64_add");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i64_add check...");
if (*(uint64_t *)sp != 3L) {
printf("failed, expect %"PRIu64", got %"PRIu64"\n", (uint64_t)3ll, *(uint64_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i64_sub");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i64_sub check...");
if (*(uint64_t *)sp != (uint64_t)16ll) {
printf("failed, expect %"PRIu64", got %"PRIu64"\n", (uint64_t)16ll, *(uint64_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i64_mul");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i64_mul check...");
if (*(uint64_t *)sp != (uint64_t)21ll) {
printf("failed, expect %"PRIu64", got %"PRIu64"\n", (uint64_t)21ll, *(uint64_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i64_div_s");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i64_div_s check...");
if (*(uint64_t *)sp != (uint64_t)18446744073709551614ull) {
printf("failed, expect %"PRIu64", got %"PRIu64"\n", (uint64_t)18446744073709551614ull,
*(uint64_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i64_div_u");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i64_div_u check...");
if (*(uint64_t *)sp != (uint64_t)9223372036854775806ull) {
printf("failed, expect %"PRIu64", got %"PRIu64"\n", (uint64_t)9223372036854775806ull,
*(uint64_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i64_rem_s");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i64_rem_s check...");
if (*(uint64_t *)sp != (uint64_t)18446744073709551615ull) {
printf("failed, expect %"PRIu64", got %"PRIu64"\n", (uint64_t)18446744073709551615ull,
*(uint64_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i64_rem_u");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i64_rem_u check...");
if (*(uint64_t *)sp != 1L) {
printf("failed, expect %"PRIu64", got %"PRIu64"\n", (uint64_t)1ll, *(uint64_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i64_and");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i64_and check...");
if (*(uint64_t *)sp != 1L) {
printf("failed, expect %"PRIu64", got %"PRIu64"\n", (uint64_t)1ll, *(uint64_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i64_or");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i64_or check...");
if (*(uint64_t *)sp != 15L) {
printf("failed, expect %"PRIu64", got %"PRIu64"\n", (uint64_t)15ll, *(uint64_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i64_xor");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i64_xor check...");
if (*(uint64_t *)sp != 14L) {
printf("failed, expect %"PRIu64", got %"PRIu64"\n", (uint64_t)14ll, *(uint64_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i64_shl");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i64_shl check...");
if (*(uint64_t *)sp != (uint64_t)18446744073709550816ull) {
printf("failed, expect %"PRIu64", got %"PRIu64"\n", (uint64_t)18446744073709550816ull,
*(uint64_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i64_shr_u");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i64_shr_u check...");
if (*(uint64_t *)sp != (uint64_t)2305843009213693939ull) {
printf("failed, expect %"PRIu64", got %"PRIu64"\n", (uint64_t)2305843009213693939ull,
*(uint64_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i64_shr_s");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i64_shr_s check...");
if (*(uint64_t *)sp != (uint64_t)18446744073709551603ull) {
printf("failed, expect %"PRIu64", got %"PRIu64"\n", (uint64_t)18446744073709551603ull,
*(uint64_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i64_rotl");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i64_rotl check...");
if (*(uint64_t *)sp != (uint64_t)18446744073709550823ull) {
printf("failed, expect %"PRIu64", got %"PRIu64"\n", (uint64_t)18446744073709550823ull,
*(uint64_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "i64_rotr");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("i64_rotr check...");
if (*(uint64_t *)sp != (uint64_t)11529215046068469747ull) {
printf("failed, expect %"PRIu64", got %"PRIu64"\n", (uint64_t)11529215046068469747ull,
*(uint64_t *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f32_add");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f32_add check...");
if (*(float *)sp != 5.000000) {
printf("failed, expect %f, got %f\n", 5.000000, *(float *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f32_sub");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f32_sub check...");
if (*(float *)sp != -9995.500000) {
printf("failed, expect %f, got %f\n", -9995.500000, *(float *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f32_mul");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f32_mul check...");
if (*(float *)sp != -8487.187500) {
printf("failed, expect %f, got %f\n", -8487.187500, *(float *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f32_div");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f32_div check...");
if (*(float *)sp != -500000000.000000) {
printf("failed, expect %f, got %f\n", -500000000.000000, *(float *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f32_min");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f32_min check...");
if (*(float *)sp != 0.000000) {
printf("failed, expect %f, got %f\n", 0.000000, *(float *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f32_max");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f32_max check...");
if (*(float *)sp != 0.000000) {
printf("failed, expect %f, got %f\n", 0.000000, *(float *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f32_copysign");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f32_copysign check...");
if (*(float *)sp != 0.000000) {
printf("failed, expect %f, got %f\n", 0.000000, *(float *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f64_add");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f64_add check...");
if (*(double *)sp != 1111111110.000000) {
printf("failed, expect %lf, got %lf\n", 1111111110.000000, *(double *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f64_sub");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f64_sub check...");
if (*(double *)sp !=
123400000000000007812762268812638756607430593436581896388608.000000) {
printf("failed, expect %lf, got %lf\n",
123400000000000007812762268812638756607430593436581896388608.000000,
*(double *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f64_mul");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f64_mul check...");
if (*(double *)sp != -15179717820000.000000) {
printf("failed, expect %lf, got %lf\n", -15179717820000.000000,
*(double *)sp);
return 0;
}
printf("pass\n");
fn = pwart_get_export_function(ctx, "f64_div");
sp = stackbase;
pwart_call_wasm_function(fn, sp);
printf("f64_div check...");
if (*(double *)sp !=
999999999999999980835596172437374590573120014030318793091164810154100112203678582976298268616221151962702060266176005440567032331208403948233373515776.000000) {
printf(