Test: Rearrange fuzz-main for AFL additions

This commit is contained in:
Jeffrey Pfau 2015-10-05 19:22:44 -07:00
parent d490f9a013
commit a90eeea924
1 changed files with 18 additions and 11 deletions

View File

@ -68,18 +68,9 @@ int main(int argc, char** argv) {
return !parsed;
}
struct VFile* rom = VFileOpen(args.fname, O_RDONLY);
context.gba->hardCrash = false;
GBAContextLoadROMFromVFile(&context, rom, 0);
struct GBAVideoSoftwareRenderer renderer;
renderer.outputBuffer = 0;
struct VFile* savestate = 0;
struct VFile* savestateOverlay = 0;
size_t overlayOffset;
if (!fuzzOpts.noVideo) {
GBAVideoSoftwareRendererCreate(&renderer);
renderer.outputBuffer = malloc(256 * 256 * 4);
@ -87,6 +78,19 @@ int main(int argc, char** argv) {
context.renderer = &renderer.d;
}
#ifdef __AFL_HAVE_MANUAL_CONTROL
__AFL_INIT();
#endif
struct VFile* rom = VFileOpen(args.fname, O_RDONLY);
context.gba->hardCrash = false;
GBAContextLoadROMFromVFile(&context, rom, 0);
struct VFile* savestate = 0;
struct VFile* savestateOverlay = 0;
size_t overlayOffset;
GBAContextStart(&context);
if (fuzzOpts.savestate) {
@ -121,18 +125,21 @@ int main(int argc, char** argv) {
_GBAFuzzRunloop(&context, fuzzOpts.frames);
GBAContextStop(&context);
GBAContextUnloadROM(&context);
if (savestate) {
savestate->close(savestate);
}
if (savestateOverlay) {
savestateOverlay->close(savestateOverlay);
}
GBAContextStop(&context);
GBAContextDeinit(&context);
freeArguments(&args);
if (renderer.outputBuffer) {
free(renderer.outputBuffer);
}
GBAContextDeinit(&context);
return 0;
}