Skip to content

Commit 03d4fa4

Browse files
committed
Add a fuzzer for testing randomized operations
The fuzzer creates a random sequence of operations and tries them against a JetKV store. If an inconsistency or panic is detected, the sequence is tried to be minimized into a minimal reproducible example. The fuzzer also outputs a seed, which can be used to create the same sequence of operations again. Currently only targets the file backend, mostly because it contained more logic. With some changes, the fuzzer could also target the memory backend. No windows support because `fork()` is used, but it shouldn't be a big change to use `ChildProcess` instead.
1 parent 3e939b1 commit 03d4fa4

3 files changed

Lines changed: 510 additions & 2 deletions

File tree

build.zig

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,24 @@ pub fn build(b: *std.Build) void {
1818
.optimize = optimize,
1919
});
2020

21-
_ = b.addModule("jetkv", .{ .root_source_file = .{ .path = "src/jetkv.zig" } });
21+
const jetkv_module = b.addModule("jetkv", .{ .root_source_file = .{ .path = "src/jetkv.zig" } });
2222

2323
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
2424

2525
const test_step = b.step("test", "Run unit tests");
2626
test_step.dependOn(&run_lib_unit_tests.step);
27+
28+
if (target.result.os.tag != .windows) {
29+
const args_dep = b.dependency("args", .{ .target = target, .optimize = optimize });
30+
31+
const fuzzer = b.addExecutable(.{
32+
.name = "fuzzer",
33+
.root_source_file = .{ .path = "utils/fuzzer.zig" },
34+
.target = b.host,
35+
});
36+
fuzzer.root_module.addImport("jetkv", jetkv_module);
37+
fuzzer.root_module.addImport("args", args_dep.module("args"));
38+
39+
b.installArtifact(fuzzer);
40+
}
2741
}

build.zig.zon

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
.{
22
.name = "jetkv",
33
.version = "0.0.0",
4-
.dependencies = .{},
4+
.dependencies = .{
5+
.args = .{
6+
.url = "https://github.com/MasterQ32/zig-args/archive/adb65692a3e3e1d7ea00e4f865ef1b1718326573.tar.gz",
7+
.hash = "1220e23828fcdbf6fdcd53b7cd422e041570bc52d65d4fb97ac76cd6fad6a88dccc1",
8+
},
9+
},
510
.paths = .{
611
"",
712
},

0 commit comments

Comments
 (0)