Skip to content

Commit

Permalink
make 'transitions < logs/dump.bin' a reality
Browse files Browse the repository at this point in the history
because of the potentially trailing log data we can't safely seek to
the last frame without using a logs parser. thus the teeing logic
needs to be moved into the fuzzer.
  • Loading branch information
scheibo committed Sep 17, 2024
1 parent d4cc05e commit dd3247b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
5 changes: 1 addition & 4 deletions src/test/fuzz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {promisify} from 'util';
import {Generations} from '@pkmn/data';
import {Dex} from '@pkmn/sim';

import {LAYOUT, LE} from '../pkg/data';
import {LE} from '../pkg/data';
import * as debug from '../tools/debug';

const ROOT = path.resolve(__dirname, '..', '..');
Expand Down Expand Up @@ -51,9 +51,6 @@ export async function run(
if (e.code !== 'EEXIST') throw e;
}

const size = LAYOUT[+gen - 1].sizes.Battle + 3;
fs.writeFileSync(path.join(dir, 'dump.bin'), stdout.subarray(stdout.byteLength - size));

seed = LE ? stdout.readBigUInt64LE(0) : stdout.readBigUInt64BE(0);
const hex = `0x${seed.toString(16).toUpperCase()}`;
const file = path.join(dir, `${hex}.fuzz.html`);
Expand Down
29 changes: 22 additions & 7 deletions src/test/fuzz.zig
Original file line number Diff line number Diff line change
Expand Up @@ -223,19 +223,34 @@ fn dump() !void {
try w.writeInt(u16, 0, endian);
try w.writeAll(initial);

if (frames) |frame| {
for (frame.items) |d| {
try w.writeAll(d.log);
try w.writeAll(d.state);
try w.writeStruct(d.result);
try w.writeStruct(d.c1);
try w.writeStruct(d.c2);
if (frames) |fs| {
for (fs.items) |f| {
try w.writeAll(f.log);
try w.writeAll(f.state);
try w.writeStruct(f.result);
try w.writeStruct(f.c1);
try w.writeStruct(f.c2);
}
}
if (buf) |b| try w.writeAll(b.items);
}

try bw.flush();

if (frames) |fs| {
if (fs.items.len > 0) {
// Write the last state information to the logs/ directory if it exists
// so that it can be trivially reproduced via the transitions tool
const file = std.fs.cwd().createFile("logs/dump.bin", .{}) catch return;
defer file.close();
var fw = file.writer();
const f = fs.items[fs.items.len - 1];
try fw.writeAll(f.state);
try fw.writeStruct(f.result);
try fw.writeStruct(f.c1);
try fw.writeStruct(f.c2);
}
}
}

pub fn panic(
Expand Down

0 comments on commit dd3247b

Please sign in to comment.