Skip to content

Commit

Permalink
fuzz: smoke fuzz free_set
Browse files Browse the repository at this point in the history
NB: with 123 seed, we are hitting the 0 branch at

```
.release = if (random.boolean()) 0 else 500 * random.float(f64),
```

I am not going to fix this here, but perhaps long term smoke fuzzing
should run for a _range_ of seeds?
  • Loading branch information
matklad committed Jan 9, 2024
1 parent ce8c0f4 commit e47aca9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/fuzz_tests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ fn smoke() !void {
// to run them fast enough?
.lsm_cache_map,
.lsm_manifest_log,
.vsr_free_set,
=> continue,

.lsm_forest => 10000,
.lsm_forest => 10_000,
.lsm_tree => 400,
.vsr_free_set => 10_000,
.vsr_superblock => 3,

inline .ewah,
Expand Down
24 changes: 14 additions & 10 deletions src/vsr/free_set_fuzz.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ pub fn main(args: fuzz.FuzzArgs) !void {
var prng = std.rand.DefaultPrng.init(args.seed);

const blocks_count = FreeSet.shard_bits * (1 + prng.random().uintLessThan(usize, 10));
const events = try generate_events(allocator, prng.random(), blocks_count);
const events_count = @min(
args.events_max orelse @as(usize, 2_000_000),
fuzz.random_int_exponential(prng.random(), usize, blocks_count * 100),
);
const events = try generate_events(allocator, prng.random(), .{
.blocks_count = blocks_count,
.events_count = events_count,
});
defer allocator.free(events);

try run_fuzz(allocator, prng.random(), blocks_count, events);
Expand Down Expand Up @@ -112,11 +119,10 @@ const FreeSetEvent = union(enum) {
checkpoint: void,
};

fn generate_events(
allocator: std.mem.Allocator,
random: std.rand.Random,
fn generate_events(allocator: std.mem.Allocator, random: std.rand.Random, options: struct {
blocks_count: usize,
) ![]const FreeSetEvent {
events_count: usize,
}) ![]const FreeSetEvent {
const event_distribution = fuzz.Distribution(FreeSetEventType){
.reserve = 1 + random.float(f64) * 100,
.forfeit = 1,
Expand All @@ -125,16 +131,14 @@ fn generate_events(
.checkpoint = random.floatExp(f64) * 10,
};

const events = try allocator.alloc(FreeSetEvent, @min(
@as(usize, 2_000_000),
fuzz.random_int_exponential(random, usize, blocks_count * 100),
));
const events = try allocator.alloc(FreeSetEvent, options.events_count);
errdefer allocator.free(events);

log.info("event_distribution = {:.2}", .{event_distribution});
log.info("event_count = {d}", .{events.len});

const reservation_blocks_mean = 1 + random.uintLessThan(usize, @divFloor(blocks_count, 20));
const reservation_blocks_mean = 1 +
random.uintLessThan(usize, @divFloor(options.blocks_count, 20));
for (events) |*event| {
event.* = switch (fuzz.random_enum(random, FreeSetEventType, event_distribution)) {
.reserve => FreeSetEvent{ .reserve = .{
Expand Down

0 comments on commit e47aca9

Please sign in to comment.