diff options
| author | Luuk de Gram <Luukdegram@users.noreply.github.com> | 2021-01-16 14:47:06 +0100 |
|---|---|---|
| committer | Luuk de Gram <Luukdegram@users.noreply.github.com> | 2021-01-16 14:58:04 +0100 |
| commit | 6c19aeddca7f1f2c25c7d34dd9f6011b495670a9 (patch) | |
| tree | 5aa3c281df8ec09cb13acadf60c905e84eb36702 /test | |
| parent | 4b2538f72c9190b12c11c45a6d18cdc831b41015 (diff) | |
| download | zig-6c19aeddca7f1f2c25c7d34dd9f6011b495670a9.tar.gz zig-6c19aeddca7f1f2c25c7d34dd9f6011b495670a9.zip | |
Add tests and move tests to wasm's own file
Diffstat (limited to 'test')
| -rw-r--r-- | test/stage2/test.zig | 62 | ||||
| -rw-r--r-- | test/stage2/wasm.zig | 125 |
2 files changed, 126 insertions, 61 deletions
diff --git a/test/stage2/test.zig b/test/stage2/test.zig index f25f07adbf..afe006574f 100644 --- a/test/stage2/test.zig +++ b/test/stage2/test.zig @@ -21,17 +21,13 @@ const linux_riscv64 = std.zig.CrossTarget{ .os_tag = .linux, }; -const wasi = std.zig.CrossTarget{ - .cpu_arch = .wasm32, - .os_tag = .wasi, -}; - pub fn addCases(ctx: *TestContext) !void { try @import("cbe.zig").addCases(ctx); try @import("spu-ii.zig").addCases(ctx); try @import("arm.zig").addCases(ctx); try @import("aarch64.zig").addCases(ctx); try @import("llvm.zig").addCases(ctx); + try @import("wasm.zig").addCases(ctx); { var case = ctx.exe("hello world with updates", linux_x64); @@ -1158,62 +1154,6 @@ pub fn addCases(ctx: *TestContext) !void { }); } - { - var case = ctx.exe("wasm function calls", wasi); - - case.addCompareOutput( - \\export fn _start() u32 { - \\ foo(); - \\ bar(); - \\ return 42; - \\} - \\fn foo() void { - \\ bar(); - \\ bar(); - \\} - \\fn bar() void {} - , - "42\n", - ); - - case.addCompareOutput( - \\export fn _start() i64 { - \\ bar(); - \\ foo(); - \\ foo(); - \\ bar(); - \\ foo(); - \\ bar(); - \\ return 42; - \\} - \\fn foo() void { - \\ bar(); - \\} - \\fn bar() void {} - , - "42\n", - ); - - case.addCompareOutput( - \\export fn _start() f32 { - \\ bar(); - \\ foo(); - \\ return 42.0; - \\} - \\fn foo() void { - \\ bar(); - \\ bar(); - \\ bar(); - \\} - \\fn bar() void {} - , - // This is what you get when you take the bits of the IEE-754 - // representation of 42.0 and reinterpret them as an unsigned - // integer. Guess that's a bug in wasmtime. - "1109917696\n", - ); - } - ctx.compileError("function redefinition", linux_x64, \\fn entry() void {} \\fn entry() void {} diff --git a/test/stage2/wasm.zig b/test/stage2/wasm.zig new file mode 100644 index 0000000000..f522db8809 --- /dev/null +++ b/test/stage2/wasm.zig @@ -0,0 +1,125 @@ +const std = @import("std"); +const TestContext = @import("../../src/test.zig").TestContext; + +const wasi = std.zig.CrossTarget{ + .cpu_arch = .wasm32, + .os_tag = .wasi, +}; + +pub fn addCases(ctx: *TestContext) !void { + { + var case = ctx.exe("wasm function calls", wasi); + + case.addCompareOutput( + \\export fn _start() u32 { + \\ foo(); + \\ bar(); + \\ return 42; + \\} + \\fn foo() void { + \\ bar(); + \\ bar(); + \\} + \\fn bar() void {} + , + "42\n", + ); + + case.addCompareOutput( + \\export fn _start() i64 { + \\ bar(); + \\ foo(); + \\ foo(); + \\ bar(); + \\ foo(); + \\ bar(); + \\ return 42; + \\} + \\fn foo() void { + \\ bar(); + \\} + \\fn bar() void {} + , + "42\n", + ); + + case.addCompareOutput( + \\export fn _start() f32 { + \\ bar(); + \\ foo(); + \\ return 42.0; + \\} + \\fn foo() void { + \\ bar(); + \\ bar(); + \\ bar(); + \\} + \\fn bar() void {} + , + // This is what you get when you take the bits of the IEE-754 + // representation of 42.0 and reinterpret them as an unsigned + // integer. Guess that's a bug in wasmtime. + "1109917696\n", + ); + + case.addCompareOutput( + \\export fn _start() u32 { + \\ foo(10, 20); + \\ return 5; + \\} + \\fn foo(x: u32, y: u32) void {} + , "5\n"); + } + + { + var case = ctx.exe("wasm locals", wasi); + + case.addCompareOutput( + \\export fn _start() u32 { + \\ var i: u32 = 5; + \\ var y: f32 = 42.0; + \\ var x: u32 = 10; + \\ return i; + \\} + , "5\n"); + + case.addCompareOutput( + \\export fn _start() u32 { + \\ var i: u32 = 5; + \\ var y: f32 = 42.0; + \\ var x: u32 = 10; + \\ foo(i, x); + \\ i = x; + \\ return i; + \\} + \\fn foo(x: u32, y: u32) void { + \\ var i: u32 = 10; + \\ i = x; + \\} + , "10\n"); + } + + { + var case = ctx.exe("wasm binary operands", wasi); + + case.addCompareOutput( + \\export fn _start() u32 { + \\ var i: u32 = 5; + \\ i += 20; + \\ return i; + \\} + , "25\n"); + + case.addCompareOutput( + \\export fn _start() u32 { + \\ var i: u32 = 5; + \\ i += 20; + \\ var result: u32 = foo(i, 10); + \\ return result; + \\} + \\fn foo(x: u32, y: u32) u32 { + \\ return x + y; + \\} + , "35\n"); + } +} |
