Skip to content

Commit 677de42

Browse files
committed
Hoist responsibilities to the fuzzer entrypoint
1 parent 6baf3a2 commit 677de42

File tree

11 files changed

+172
-132
lines changed

11 files changed

+172
-132
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: 11 additions & 40 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

@@ -44,7 +43,7 @@ pub const TrackedAccount = struct {
4443
pub const RunCmd = struct {
4544
max_slots: ?Slot,
4645

47-
pub const parser = cli.Parser(RunCmd, .{
46+
pub const cmd_info: cli.CommandInfo(RunCmd) = .{
4847
.help = .{
4948
.short = "Fuzz accountsdb.",
5049
.long = null,
@@ -59,12 +58,18 @@ pub const RunCmd = struct {
5958
.help = "The number of slots number which, when surpassed, will exit the fuzzer.",
6059
},
6160
},
62-
});
61+
};
6362
};
6463

6564
const Logger = sig.trace.Logger("accountsdb.fuzz");
6665

67-
pub fn run(seed: u64, args: *std.process.ArgIterator) !void {
66+
pub fn run(
67+
allocator: std.mem.Allocator,
68+
logger: Logger,
69+
seed: u64,
70+
fuzz_data_dir: std.fs.Dir,
71+
run_cmd: RunCmd,
72+
) !void {
6873
var prng_state: std.Random.DefaultPrng = .init(seed);
6974
const random = prng_state.random();
7075

@@ -73,41 +78,8 @@ pub fn run(seed: u64, args: *std.process.ArgIterator) !void {
7378
const N_ACCOUNTS_MAX: u64 = 100_000;
7479
const N_ACCOUNTS_PER_SLOT = 10;
7580

76-
var gpa_state: std.heap.DebugAllocator(.{
77-
.safety = true,
78-
}) = .init;
79-
defer _ = gpa_state.deinit();
80-
const allocator = gpa_state.allocator();
81-
82-
const std_logger: *ChannelPrintLogger = try .init(.{
83-
.allocator = allocator,
84-
.max_level = .debug,
85-
.max_buffer = 1 << 20,
86-
}, null);
87-
defer std_logger.deinit();
88-
const logger: Logger = std_logger.logger("accountsdb.fuzz");
89-
90-
const run_cmd: RunCmd = cmd: {
91-
var argv_list: std.ArrayListUnmanaged([]const u8) = .empty;
92-
defer argv_list.deinit(allocator);
93-
while (args.next()) |arg| try argv_list.append(allocator, arg);
94-
95-
const stderr = std.io.getStdErr();
96-
const stderr_tty = std.io.tty.detectConfig(stderr);
97-
break :cmd try RunCmd.parser.parse(
98-
allocator,
99-
"fuzz accountsdb",
100-
stderr_tty,
101-
stderr.writer(),
102-
argv_list.items,
103-
) orelse return;
104-
};
105-
10681
const maybe_max_slots = run_cmd.max_slots;
10782

108-
var fuzz_data_dir = try std.fs.cwd().makeOpenPath(sig.FUZZ_DATA_DIR, .{});
109-
defer fuzz_data_dir.close();
110-
11183
const main_dir_name = "main";
11284
var main_accountsdb_dir = try fuzz_data_dir.makeOpenPath(main_dir_name, .{});
11385
defer main_accountsdb_dir.close();
@@ -128,9 +100,6 @@ pub fn run(seed: u64, args: *std.process.ArgIterator) !void {
128100
};
129101
};
130102

131-
var last_full_snapshot_validated_slot: Slot = 0;
132-
var last_inc_snapshot_validated_slot: Slot = 0;
133-
134103
const use_disk = random.boolean();
135104
logger.info().logf("use disk: {}", .{use_disk});
136105
var accounts_db: AccountsDB = try .init(.{
@@ -191,6 +160,8 @@ pub fn run(seed: u64, args: *std.process.ArgIterator) !void {
191160
}));
192161
}
193162

163+
var last_full_snapshot_validated_slot: Slot = 0;
164+
var last_inc_snapshot_validated_slot: Slot = 0;
194165
var largest_rooted_slot: Slot = 0;
195166
var slot: Slot = 0;
196167

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)