Skip to content

Commit a77157a

Browse files
committed
Hoist responsibilities to the fuzzer entrypoint
1 parent 2e2b3ee commit a77157a

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,
@@ -88,12 +87,18 @@ pub const RunCmd = struct {
8887
.help = "Enable the accountsdb manager during fuzzer.",
8988
},
9089
},
91-
});
90+
};
9291
};
9392

9493
const Logger = sig.trace.Logger("accountsdb.fuzz");
9594

96-
pub fn run(seed: u64, args: *std.process.ArgIterator) !void {
95+
pub fn run(
96+
allocator: std.mem.Allocator,
97+
logger: Logger,
98+
seed: u64,
99+
fuzz_data_dir: std.fs.Dir,
100+
run_cmd: RunCmd,
101+
) !void {
97102
var prng_state: std.Random.DefaultPrng = .init(seed);
98103
const random = prng_state.random();
99104

@@ -102,46 +107,13 @@ pub fn run(seed: u64, args: *std.process.ArgIterator) !void {
102107
const N_ACCOUNTS_MAX: u64 = 100_000;
103108
const N_ACCOUNTS_PER_SLOT = 10;
104109

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

142-
var fuzz_data_dir = try std.fs.cwd().makeOpenPath(sig.FUZZ_DATA_DIR, .{});
143-
defer fuzz_data_dir.close();
144-
145117
const main_dir_name = "main";
146118
var main_accountsdb_dir = try fuzz_data_dir.makeOpenPath(main_dir_name, .{});
147119
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)