libfuzzer test: use proper cache dir logic

This commit is contained in:
tjog 2025-05-18 16:31:52 +02:00 committed by Alex Rønne Petersen
parent 07a5efd072
commit ad1e09eab0
2 changed files with 9 additions and 1 deletions

View file

@ -22,5 +22,6 @@ pub fn build(b: *std.Build) void {
b.default_step = run_step; b.default_step = run_step;
const run_artifact = b.addRunArtifact(exe); const run_artifact = b.addRunArtifact(exe);
run_artifact.addArg(b.cache_root.path orelse "");
run_step.dependOn(&run_artifact.step); run_step.dependOn(&run_artifact.step);
} }

View file

@ -15,7 +15,14 @@ extern fn fuzzer_init_corpus_elem(input_ptr: [*]const u8, input_len: usize) void
extern fn fuzzer_coverage_id() u64; extern fn fuzzer_coverage_id() u64;
pub fn main() !void { pub fn main() !void {
fuzzer_init(FuzzerSlice.fromSlice("")); var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
defer _ = gpa.deinit();
const args = try std.process.argsAlloc(gpa.allocator());
defer std.process.argsFree(gpa.allocator(), args);
const cache_dir = args[1];
fuzzer_init(FuzzerSlice.fromSlice(cache_dir));
fuzzer_init_corpus_elem("hello".ptr, "hello".len); fuzzer_init_corpus_elem("hello".ptr, "hello".len);
fuzzer_set_name("test".ptr, "test".len); fuzzer_set_name("test".ptr, "test".len);
_ = fuzzer_coverage_id(); _ = fuzzer_coverage_id();