Skip to content

Commit 375f561

Browse files
committed
Hoist responsibilities to the fuzzer entrypoint
1 parent d768015 commit 375f561

File tree

11 files changed

+170
-129
lines changed

11 files changed

+170
-129
lines changed

.circleci/config.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ jobs:
221221
at: workspace
222222
- run:
223223
name: Run Gossip Service Fuzzer
224-
command: workspace/zig-out-release/bin/fuzz gossip_service 19 10000
224+
command: workspace/zig-out-release/bin/fuzz --seed 19 gossip-service 10000
225225

226226
gossip_table_fuzz:
227227
executor: linux-executor
@@ -231,7 +231,7 @@ jobs:
231231
at: workspace
232232
- run:
233233
name: Run Gossip Table Fuzzer
234-
command: workspace/zig-out-release/bin/fuzz gossip_table 19 100000
234+
command: workspace/zig-out-release/bin/fuzz --seed 19 gossip-table 100000
235235

236236
allocators_fuzz:
237237
executor: linux-executor
@@ -241,7 +241,7 @@ jobs:
241241
at: workspace
242242
- run:
243243
name: Run Allocators Fuzzer
244-
command: workspace/zig-out-release/bin/fuzz allocators 19 10000
244+
command: workspace/zig-out-release/bin/fuzz --seed 19 allocators 10000
245245

246246
ledger_fuzz:
247247
executor: linux-executor
@@ -251,7 +251,7 @@ jobs:
251251
at: workspace
252252
- run:
253253
name: Run Ledger Fuzzer
254-
command: workspace/zig-out-release/bin/fuzz ledger 19 10000
254+
command: workspace/zig-out-release/bin/fuzz --seed 19 ledger 10000
255255

256256
solana_conformance:
257257
executor: linux-executor

scripts/kcov_fuzz_allocators.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ kcov \
2323
--include-pattern=src/utils/allocators.zig \
2424
--exclude-pattern=$HOME/.cache \
2525
kcov-output/ \
26-
./zig-out/bin/fuzz allocators 19 50_000
26+
./zig-out/bin/fuzz --seed 19 allocators 50_000
2727

2828
# open report
2929
echo "=> Opening kcov-output/index.html"

scripts/kcov_fuzz_gossip.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ kcov \
2323
--include-pattern=src/gossip/ \
2424
--exclude-pattern=$HOME/.cache \
2525
kcov-output/ \
26-
./zig-out/bin/fuzz gossip_service 19 50_000
26+
./zig-out/bin/fuzz --seed 19 gossip-service 50_000
2727

2828
# open report
2929
echo "=> Opening kcov-output/index.html"

scripts/kcov_fuzz_gossip_table.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ kcov \
2323
--include-pattern=src/gossip/ \
2424
--exclude-pattern=$HOME/.cache \
2525
kcov-output/ \
26-
./zig-out/bin/fuzz gossip_table 19 50_000
26+
./zig-out/bin/fuzz --seed 19 gossip-table 50_000
2727

2828
# open report
2929
echo "=> Opening kcov-output/index.html"

src/accountsdb/fuzz.zig

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const sig = @import("../sig.zig");
33
const cli = @import("cli");
44

55
const Account = sig.runtime.AccountSharedData;
6-
const ChannelPrintLogger = sig.trace.ChannelPrintLogger;
76
const Pubkey = sig.core.pubkey.Pubkey;
87
const Slot = sig.core.time.Slot;
98

@@ -49,7 +48,7 @@ pub const RunCmd = struct {
4948

5049
pub const IndexAllocation = enum { ram, disk };
5150

52-
pub const parser = cli.Parser(RunCmd, .{
51+
pub const cmd_info: cli.CommandInfo(RunCmd) = .{
5352
.help = .{
5453
.short = "Fuzz accountsdb.",
5554
.long = null,
@@ -91,12 +90,18 @@ pub const RunCmd = struct {
9190
.help = "Enable the accountsdb manager during fuzzer.",
9291
},
9392
},
94-
});
93+
};
9594
};
9695

9796
const Logger = sig.trace.Logger("accountsdb.fuzz");
9897

99-
pub fn run(seed: u64, args: *std.process.ArgIterator) !void {
98+
pub fn run(
99+
allocator: std.mem.Allocator,
100+
logger: Logger,
101+
seed: u64,
102+
fuzz_data_dir: std.fs.Dir,
103+
run_cmd: RunCmd,
104+
) !void {
100105
var prng_state: std.Random.DefaultPrng = .init(seed);
101106
const random = prng_state.random();
102107

@@ -105,46 +110,13 @@ pub fn run(seed: u64, args: *std.process.ArgIterator) !void {
105110
const N_ACCOUNTS_MAX: u64 = 100_000;
106111
const N_ACCOUNTS_PER_SLOT = 10;
107112

108-
var gpa_state: std.heap.DebugAllocator(.{
109-
.safety = true,
110-
}) = .init;
111-
defer _ = gpa_state.deinit();
112-
const allocator = gpa_state.allocator();
113-
114-
const std_logger: *ChannelPrintLogger = try .init(.{
115-
.allocator = allocator,
116-
.max_level = .debug,
117-
.max_buffer = 1 << 20,
118-
}, null);
119-
defer std_logger.deinit();
120-
const logger: Logger = std_logger.logger("accountsdb.fuzz");
121-
122-
const run_cmd: RunCmd = cmd: {
123-
var argv_list: std.ArrayListUnmanaged([]const u8) = .empty;
124-
defer argv_list.deinit(allocator);
125-
while (args.next()) |arg| try argv_list.append(allocator, arg);
126-
127-
const stderr = std.io.getStdErr();
128-
const stderr_tty = std.io.tty.detectConfig(stderr);
129-
break :cmd try RunCmd.parser.parse(
130-
allocator,
131-
"fuzz accountsdb",
132-
stderr_tty,
133-
stderr.writer(),
134-
argv_list.items,
135-
) orelse return;
136-
};
137-
138113
const maybe_max_slots = run_cmd.max_slots;
139114
const non_sequential_slots = run_cmd.non_sequential_slots;
140115
const enable_manager = run_cmd.enable_manager;
141116
const index_allocation =
142117
run_cmd.index_allocation orelse
143118
random.enumValue(RunCmd.IndexAllocation);
144119

145-
var fuzz_data_dir = try std.fs.cwd().makeOpenPath(sig.FUZZ_DATA_DIR, .{});
146-
defer fuzz_data_dir.close();
147-
148120
const main_dir_name = "main";
149121
var main_accountsdb_dir = try fuzz_data_dir.makeOpenPath(main_dir_name, .{});
150122
defer main_accountsdb_dir.close();

src/accountsdb/fuzz_snapshot.zig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ const SnapshotManifest = sig.accounts_db.Manifest;
1515

1616
const MAX_FUZZ_TIME_NS = std.time.ns_per_s * 100_000;
1717

18-
pub fn run(args: *std.process.ArgIterator) !void {
19-
_ = args;
18+
pub fn run() !void {
2019
const seed = std.crypto.random.int(u64);
2120

2221
var gpa: std.heap.DebugAllocator(.{}) = .init;

0 commit comments

Comments
 (0)