blob e30f5b36 (2206B) - Raw
1 const std = @import("std"); 2 const builtin = @import("builtin"); 3 4 pub fn build(b: *std.Build) !void { 5 const test_step = b.step("test", "Test it"); 6 b.default_step = test_step; 7 8 const optimize: std.builtin.OptimizeMode = .Debug; 9 const target = b.graph.host; 10 11 if (builtin.os.tag != .windows) return; 12 13 const echo_args = b.addExecutable(.{ 14 .name = "echo-args", 15 .root_module = b.createModule(.{ 16 .root_source_file = b.path("echo-args.zig"), 17 .optimize = optimize, 18 .target = target, 19 }), 20 }); 21 22 const test_exe = b.addExecutable(.{ 23 .name = "test", 24 .root_module = b.createModule(.{ 25 .root_source_file = b.path("test.zig"), 26 .optimize = optimize, 27 .target = target, 28 }), 29 }); 30 31 test_exe.root_module.linkSystemLibrary("advapi32", .{}); 32 33 const run = b.addRunArtifact(test_exe); 34 run.addArtifactArg(echo_args); 35 run.expectExitCode(0); 36 run.skip_foreign_checks = true; 37 38 test_step.dependOn(&run.step); 39 40 const fuzz = b.addExecutable(.{ 41 .name = "fuzz", 42 .root_module = b.createModule(.{ 43 .root_source_file = b.path("fuzz.zig"), 44 .optimize = optimize, 45 .target = target, 46 }), 47 }); 48 49 fuzz.root_module.linkSystemLibrary("advapi32", .{}); 50 51 const fuzz_max_iterations = b.option(u64, "iterations", "The max fuzz iterations (default: 100)") orelse 100; 52 const fuzz_iterations_arg = std.fmt.allocPrint(b.allocator, "{}", .{fuzz_max_iterations}) catch @panic("oom"); 53 54 const fuzz_seed = b.option(u64, "seed", "Seed to use for the PRNG (default: random)") orelse seed: { 55 var buf: [8]u8 = undefined; 56 try std.posix.getrandom(&buf); 57 break :seed std.mem.readInt(u64, &buf, builtin.cpu.arch.endian()); 58 }; 59 const fuzz_seed_arg = std.fmt.allocPrint(b.allocator, "{}", .{fuzz_seed}) catch @panic("oom"); 60 61 const fuzz_run = b.addRunArtifact(fuzz); 62 fuzz_run.addArtifactArg(echo_args); 63 fuzz_run.addArgs(&.{ fuzz_iterations_arg, fuzz_seed_arg }); 64 fuzz_run.expectExitCode(0); 65 fuzz_run.skip_foreign_checks = true; 66 67 test_step.dependOn(&fuzz_run.step); 68 }