summaryrefslogtreecommitdiff
path: root/core/fuzz.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/fuzz.zig')
-rw-r--r--core/fuzz.zig29
1 files changed, 21 insertions, 8 deletions
diff --git a/core/fuzz.zig b/core/fuzz.zig
index f324a48e..0fce6f9d 100644
--- a/core/fuzz.zig
+++ b/core/fuzz.zig
@@ -711,7 +711,12 @@ fn damage(r: Random, b: []u8, n: usize) usize {
return n;
}
-fn loadSeed(whole: []const u8, seed: u64) !void {
+/// What is done with a dump once it loads: a join's is digested (the
+/// session's digest decides before anything draws it: replica.fromDump),
+/// a Restore's or an Upgrade's image is drawn.
+const Road = enum { join, restore };
+
+fn loadSeed(whole: []const u8, road: Road, seed: u64) !void {
var prng: Random.DefaultPrng = .init(seed);
const r = prng.random();
var cap: Capped = .{ .child = testing.allocator, .one = 64 << 20, .all = 512 << 20 };
@@ -728,8 +733,13 @@ fn loadSeed(whole: []const u8, seed: u64) !void {
var notes: std.ArrayList(u8) = .empty;
defer notes.deinit(gpa);
if (pardes.dump.load(gpa, .{ .cols = 80, .rows = 24 }, b[0..n], &notes)) |q| {
- _ = q.frame_arena.reset(.retain_capacity);
- _ = q.render(q.frame_arena.allocator()) catch {};
+ switch (road) {
+ .join => _ = pardes.tape.digestOf(q),
+ .restore => {
+ _ = q.frame_arena.reset(.retain_capacity);
+ _ = q.render(q.frame_arena.allocator()) catch {};
+ },
+ }
q.deinit();
} else |err| if (seed == 0) return err;
try testing.expectEqual(@as(usize, 0), cap.refused);
@@ -739,13 +749,16 @@ test "a dump and an image cut, flipped and grown: refused or loaded, never a pan
const gpa = testing.allocator;
const p = try th.withFile(gpa, "alpha beta\ngamma\n\tdelta \xe6\x97\xa5\n");
defer p.deinit();
- const bytes = try pardes.dump.dumpBytes(p);
+ // The byte dump a join streams, and the image a Dump keeps.
+ const bytes = try pardes.dump.byteDump(p);
defer gpa.free(bytes);
- const image = try pardes.dump.image(p, "fuzz");
+ const image = try pardes.dump.dumpBytes(p);
defer gpa.free(image);
- for ([_][]const u8{ bytes, image }) |whole| {
- try loadSeed(whole, 0);
- for (seeds) |seed| for (0..8) |k| try loadSeed(whole, seed *% 31 +% k);
+ // Seconds a road. The image's past 1024 seeds reach xitdb's own reader
+ // (a slot's tag past its kinds: a `switch` on it), a dependency's.
+ for ([_][]const u8{ bytes, image }, [_]Road{ .join, .restore }, [_]u64{ 4096, 1024 }) |whole, road, n| {
+ try loadSeed(whole, road, 0);
+ for (1..n + 1) |seed| try loadSeed(whole, road, seed);
}
}