authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2020-08-18 01:46:19+02:00
committergravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2020-08-18 01:47:03+02:00
log9f44284ad5ed5ae94b7a4bc1f5972c60c1739bb6
tree011e0aa8f5cbf6cfd3a2cd927789c74e51449126
parentf9963909a1cf73eaee47102f4e4dcafe5afa3898
signaturelock-open Commit is signed but in an unrecognized format.

stage2/wasm: add basic test cases


2 files changed, 43 insertions(+), 5 deletions(-)

src-self-hosted/link.zig+7-5
...@@ -100,11 +100,13 @@ pub const File = struct {...@@ -100,11 +100,13 @@ pub const File = struct {
100 }100 }
101101
102 pub fn makeExecutable(base: *File) !void {102 pub fn makeExecutable(base: *File) !void {
103 std.debug.assert(base.tag != .c);103 switch (base.tag) {
104 if (base.file) |f| {104 .c => unreachable,
105 f.close();105 .wasm => {},
106 base.file = null;106 else => if (base.file) |f| {
107107 f.close();
108 base.file = null;
109 },
108 }110 }
109 }111 }
110112
test/stage2/compare_output.zig+36
...@@ -12,6 +12,11 @@ const linux_riscv64 = std.zig.CrossTarget{...@@ -12,6 +12,11 @@ const linux_riscv64 = std.zig.CrossTarget{
12 .os_tag = .linux,12 .os_tag = .linux,
13};13};
1414
15const wasi = std.zig.CrossTarget{
16 .cpu_arch = .wasm32,
17 .os_tag = .wasi,
18};
19
15pub fn addCases(ctx: *TestContext) !void {20pub fn addCases(ctx: *TestContext) !void {
16 {21 {
17 var case = ctx.exe("hello world with updates", linux_x64);22 var case = ctx.exe("hello world with updates", linux_x64);
...@@ -539,4 +544,35 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -539,4 +544,35 @@ pub fn addCases(ctx: *TestContext) !void {
539 "",544 "",
540 );545 );
541 }546 }
547
548 {
549 var case = ctx.exe("wasm returns", wasi);
550
551 case.addCompareOutput(
552 \\export fn _start() u32 {
553 \\ return 42;
554 \\}
555 ,
556 "42\n",
557 );
558
559 case.addCompareOutput(
560 \\export fn _start() i64 {
561 \\ return 42;
562 \\}
563 ,
564 "42\n",
565 );
566
567 case.addCompareOutput(
568 \\export fn _start() f32 {
569 \\ return 42.0;
570 \\}
571 ,
572 // This is what you get when you take the bits of the IEE-754
573 // representation of 42.0 and reinterpret them as an unsigned
574 // integer. Guess that's a bug in wasmtime.
575 "1109917696\n",
576 );
577 }
542}578}