Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fuzz: smoke fuzz free_set #1410

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/fuzz_tests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ fn main_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