Skip to content

Commit

Permalink
Add parsecheck
Browse files Browse the repository at this point in the history
- Test that all files in test/testsuite-generated do not crash
- This is regardless of if they're supported in zware or not
- Also includes fuzzed files
  • Loading branch information
malcolmstill committed Sep 26, 2022
1 parent 224d620 commit 73358bc
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
28 changes: 28 additions & 0 deletions test/parsecheck/build.zig
Original file line number Diff line number Diff line change
@@ -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);
}
53 changes: 53 additions & 0 deletions test/parsecheck/src/parsecheck.zig
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Binary file added test/testsuite-generated/27_1.if.50.wasm
Binary file not shown.
Binary file not shown.

0 comments on commit 73358bc

Please sign in to comment.