mirror of https://github.com/mgba-emu/mgba.git
Test: Update fuzzing harness for GB support
This commit is contained in:
parent
d8c773bbf7
commit
13a68a0dac
|
@ -6,9 +6,8 @@
|
||||||
#include "core/config.h"
|
#include "core/config.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/serialize.h"
|
#include "core/serialize.h"
|
||||||
#include "gba/core.h"
|
#include "gb/core.h"
|
||||||
#include "gba/gba.h"
|
#include "gba/gba.h"
|
||||||
#include "gba/serialize.h"
|
|
||||||
|
|
||||||
#include "feature/commandline.h"
|
#include "feature/commandline.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
|
@ -35,14 +34,14 @@ struct FuzzOpts {
|
||||||
char* ssOverlay;
|
char* ssOverlay;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void _GBAFuzzRunloop(struct mCore* core, int frames);
|
static void _fuzzRunloop(struct mCore* core, int frames);
|
||||||
static void _GBAFuzzShutdown(int signal);
|
static void _fuzzShutdown(int signal);
|
||||||
static bool _parseFuzzOpts(struct mSubParser* parser, int option, const char* arg);
|
static bool _parseFuzzOpts(struct mSubParser* parser, int option, const char* arg);
|
||||||
|
|
||||||
static bool _dispatchExiting = false;
|
static bool _dispatchExiting = false;
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
signal(SIGINT, _GBAFuzzShutdown);
|
signal(SIGINT, _fuzzShutdown);
|
||||||
|
|
||||||
struct FuzzOpts fuzzOpts = { false, 0, 0, 0, 0 };
|
struct FuzzOpts fuzzOpts = { false, 0, 0, 0, 0 };
|
||||||
struct mSubParser subparser = {
|
struct mSubParser subparser = {
|
||||||
|
@ -52,11 +51,6 @@ int main(int argc, char** argv) {
|
||||||
.opts = &fuzzOpts
|
.opts = &fuzzOpts
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mCore* core = GBACoreCreate();
|
|
||||||
core->init(core);
|
|
||||||
mCoreInitConfig(core, "fuzz");
|
|
||||||
mCoreConfigSetDefaultValue(&core->config, "idleOptimization", "remove");
|
|
||||||
|
|
||||||
struct mArguments args;
|
struct mArguments args;
|
||||||
bool parsed = parseArguments(&args, argc, argv, &subparser);
|
bool parsed = parseArguments(&args, argc, argv, &subparser);
|
||||||
if (!args.fname) {
|
if (!args.fname) {
|
||||||
|
@ -64,16 +58,19 @@ int main(int argc, char** argv) {
|
||||||
}
|
}
|
||||||
if (!parsed || args.showHelp) {
|
if (!parsed || args.showHelp) {
|
||||||
usage(argv[0], FUZZ_USAGE);
|
usage(argv[0], FUZZ_USAGE);
|
||||||
core->deinit(core);
|
|
||||||
return !parsed;
|
return !parsed;
|
||||||
}
|
}
|
||||||
if (args.showVersion) {
|
if (args.showVersion) {
|
||||||
version(argv[0]);
|
version(argv[0]);
|
||||||
core->deinit(core);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
struct mCore* core = mCoreFind(args.fname);
|
||||||
|
core->init(core);
|
||||||
|
mCoreInitConfig(core, "fuzz");
|
||||||
applyArguments(&args, NULL, &core->config);
|
applyArguments(&args, NULL, &core->config);
|
||||||
|
|
||||||
|
mCoreConfigSetDefaultValue(&core->config, "idleOptimization", "remove");
|
||||||
|
|
||||||
void* outputBuffer;
|
void* outputBuffer;
|
||||||
outputBuffer = 0;
|
outputBuffer = 0;
|
||||||
|
|
||||||
|
@ -86,7 +83,11 @@ int main(int argc, char** argv) {
|
||||||
__AFL_INIT();
|
__AFL_INIT();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
((struct GBA*) core->board)->hardCrash = false;
|
#ifdef M_CORE_GBA
|
||||||
|
if (core->platform(core) == PLATFORM_GBA) {
|
||||||
|
((struct GBA*) core->board)->hardCrash = false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
mCoreLoadFile(core, args.fname);
|
mCoreLoadFile(core, args.fname);
|
||||||
|
|
||||||
struct VFile* savestate = 0;
|
struct VFile* savestate = 0;
|
||||||
|
@ -99,20 +100,24 @@ int main(int argc, char** argv) {
|
||||||
}
|
}
|
||||||
if (fuzzOpts.ssOverlay) {
|
if (fuzzOpts.ssOverlay) {
|
||||||
overlayOffset = fuzzOpts.overlayOffset;
|
overlayOffset = fuzzOpts.overlayOffset;
|
||||||
if (overlayOffset < sizeof(struct GBASerializedState)) {
|
if (overlayOffset < core->stateSize(core)) {
|
||||||
savestateOverlay = VFileOpen(fuzzOpts.ssOverlay, O_RDONLY);
|
savestateOverlay = VFileOpen(fuzzOpts.ssOverlay, O_RDONLY);
|
||||||
}
|
}
|
||||||
free(fuzzOpts.ssOverlay);
|
free(fuzzOpts.ssOverlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core->reset(core);
|
||||||
|
|
||||||
if (savestate) {
|
if (savestate) {
|
||||||
if (!savestateOverlay) {
|
if (!savestateOverlay) {
|
||||||
mCoreLoadStateNamed(core, savestate, 0);
|
mCoreLoadStateNamed(core, savestate, 0);
|
||||||
} else {
|
} else {
|
||||||
struct GBASerializedState* state = GBAAllocateState();
|
size_t size = core->stateSize(core);
|
||||||
savestate->read(savestate, state, sizeof(*state));
|
uint8_t* state = malloc(size);
|
||||||
savestateOverlay->read(savestateOverlay, (uint8_t*) state + overlayOffset, sizeof(*state) - overlayOffset);
|
savestate->read(savestate, state, size);
|
||||||
GBADeserialize(core->board, state);
|
savestateOverlay->read(savestateOverlay, state + overlayOffset, size - overlayOffset);
|
||||||
GBADeallocateState(state);
|
core->loadState(core, state);
|
||||||
|
free(state);
|
||||||
savestateOverlay->close(savestateOverlay);
|
savestateOverlay->close(savestateOverlay);
|
||||||
savestateOverlay = 0;
|
savestateOverlay = 0;
|
||||||
}
|
}
|
||||||
|
@ -123,9 +128,7 @@ int main(int argc, char** argv) {
|
||||||
blip_set_rates(core->getAudioChannel(core, 0), GBA_ARM7TDMI_FREQUENCY, 0x8000);
|
blip_set_rates(core->getAudioChannel(core, 0), GBA_ARM7TDMI_FREQUENCY, 0x8000);
|
||||||
blip_set_rates(core->getAudioChannel(core, 1), GBA_ARM7TDMI_FREQUENCY, 0x8000);
|
blip_set_rates(core->getAudioChannel(core, 1), GBA_ARM7TDMI_FREQUENCY, 0x8000);
|
||||||
|
|
||||||
core->reset(core);
|
_fuzzRunloop(core, fuzzOpts.frames);
|
||||||
|
|
||||||
_GBAFuzzRunloop(core, fuzzOpts.frames);
|
|
||||||
|
|
||||||
core->unloadROM(core);
|
core->unloadROM(core);
|
||||||
|
|
||||||
|
@ -145,7 +148,7 @@ int main(int argc, char** argv) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _GBAFuzzRunloop(struct mCore* core, int frames) {
|
static void _fuzzRunloop(struct mCore* core, int frames) {
|
||||||
do {
|
do {
|
||||||
core->runFrame(core);
|
core->runFrame(core);
|
||||||
blip_clear(core->getAudioChannel(core, 0));
|
blip_clear(core->getAudioChannel(core, 0));
|
||||||
|
@ -153,7 +156,7 @@ static void _GBAFuzzRunloop(struct mCore* core, int frames) {
|
||||||
} while (core->frameCounter(core) < frames && !_dispatchExiting);
|
} while (core->frameCounter(core) < frames && !_dispatchExiting);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _GBAFuzzShutdown(int signal) {
|
static void _fuzzShutdown(int signal) {
|
||||||
UNUSED(signal);
|
UNUSED(signal);
|
||||||
_dispatchExiting = true;
|
_dispatchExiting = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue