diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 0a054890..e6f2c9ce 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -23,6 +23,15 @@ jobs: - run: cp bin/testrunner testrunner - run: cp test/testsuite-generated/* ./ - run: bash test/run-generated.sh + parsecheck: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: goto-bus-stop/setup-zig@v1 + with: + version: master + - run: zig build --build-file test/parsecheck/build.zig --prefix ./ + - run: bin/parsecheck test/testsuite-generated lint: runs-on: ubuntu-latest steps: diff --git a/test/parsecheck/build.zig b/test/parsecheck/build.zig new file mode 100644 index 00000000..c0b38229 --- /dev/null +++ b/test/parsecheck/build.zig @@ -0,0 +1,28 @@ +const Builder = @import("std").build.Builder; + +pub fn build(b: *Builder) void { + // Standard target options allows the person running `zig build` to choose + // what target to build for. Here we do not override the defaults, which + // means any target is allowed, and the default is native. Other options + // for restricting supported target set are available. + const target = b.standardTargetOptions(.{}); + + // Standard release options allow the person running `zig build` to select + // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. + const mode = b.standardReleaseOptions(); + + const exe = b.addExecutable("parsecheck", "src/parsecheck.zig"); + exe.setTarget(target); + exe.setBuildMode(mode); + exe.addPackagePath("zware", "../../src/main.zig"); + exe.install(); + + const run_cmd = exe.run(); + run_cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| { + run_cmd.addArgs(args); + } + + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); +} diff --git a/test/parsecheck/src/parsecheck.zig b/test/parsecheck/src/parsecheck.zig new file mode 100644 index 00000000..14072400 --- /dev/null +++ b/test/parsecheck/src/parsecheck.zig @@ -0,0 +1,53 @@ +const std = @import("std"); +const mem = std.mem; +const fs = std.fs; +const fmt = std.fmt; +const process = std.process; +const zware = @import("zware"); +const ArrayList = std.ArrayList; +const Module = zware.Module; +const Store = zware.Store; +const Instance = zware.Instance; +const GeneralPurposeAllocator = std.heap.GeneralPurposeAllocator; +const ArenaAllocator = std.heap.ArenaAllocator; +var gpa = GeneralPurposeAllocator(.{}){}; + +pub fn main() !void { + var args = process.args(); + _ = args.skip(); + const directory = args.next() orelse return error.NoFilename; + + defer _ = gpa.deinit(); + + var wasm_files = ArrayList([]const u8).init(gpa.allocator()); + defer wasm_files.deinit(); + + var dir = try std.fs.cwd().openIterableDir(directory, .{}); + defer dir.close(); + + var it = dir.iterate(); + + var file_count: usize = 0; + while (try it.next()) |entry| { + if (entry.kind == .File) file_count += 1; + if (mem.endsWith(u8, entry.name, ".wasm")) { + std.log.info("{s}", .{entry.name}); + var arena = ArenaAllocator.init(gpa.allocator()); + defer _ = arena.deinit(); + const alloc = arena.allocator(); + + const program = try dir.dir.readFileAlloc(alloc, entry.name, 0xFFFFFFF); + if (program.len == 0) continue; + + var store: Store = Store.init(alloc); + + var module = Module.init(alloc, program); + module.decode() catch continue; + + var new_inst = Instance.init(alloc, &store, module); + const index = store.addInstance(new_inst) catch continue; + var inst = store.instance(index) catch continue; + inst.instantiate(index) catch continue; + } + } +} diff --git a/test/testsuite-generated/27_1.if.50.wasm b/test/testsuite-generated/27_1.if.50.wasm new file mode 100644 index 00000000..66f8430d Binary files /dev/null and b/test/testsuite-generated/27_1.if.50.wasm differ diff --git a/test/testsuite-generated/2966_5.left-to-right.0.wasm b/test/testsuite-generated/2966_5.left-to-right.0.wasm new file mode 100644 index 00000000..55823022 Binary files /dev/null and b/test/testsuite-generated/2966_5.left-to-right.0.wasm differ