Skip to content

Commit 83413fb

Browse files
committed
Hoist responsibilities to the fuzzer entrypoint
1 parent c18b976 commit 83413fb

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
@@ -220,7 +220,7 @@ jobs:
220220
at: workspace
221221
- run:
222222
name: Run Gossip Service Fuzzer
223-
command: workspace/zig-out-release/bin/fuzz gossip_service 19 10000
223+
command: workspace/zig-out-release/bin/fuzz --seed 19 gossip-service 10000
224224

225225
gossip_table_fuzz:
226226
executor: linux-executor
@@ -230,7 +230,7 @@ jobs:
230230
at: workspace
231231
- run:
232232
name: Run Gossip Table Fuzzer
233-
command: workspace/zig-out-release/bin/fuzz gossip_table 19 100000
233+
command: workspace/zig-out-release/bin/fuzz --seed 19 gossip-table 100000
234234

235235
allocators_fuzz:
236236
executor: linux-executor
@@ -240,7 +240,7 @@ jobs:
240240
at: workspace
241241
- run:
242242
name: Run Allocators Fuzzer
243-
command: workspace/zig-out-release/bin/fuzz allocators 19 10000
243+
command: workspace/zig-out-release/bin/fuzz --seed 19 allocators 10000
244244

245245
ledger_fuzz:
246246
executor: linux-executor
@@ -250,7 +250,7 @@ jobs:
250250
at: workspace
251251
- run:
252252
name: Run Ledger Fuzzer
253-
command: workspace/zig-out-release/bin/fuzz ledger 19 10000
253+
command: workspace/zig-out-release/bin/fuzz --seed 19 ledger 10000
254254

255255
solana_conformance:
256256
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/snapshot/fuzz.zig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ const SnapshotManifest = sig.accounts_db.snapshot.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)