Fuzz testing debug tool
Add code to run a fuzz tester, simulating (more-or-less) random keyboard mashing. There's no option to turn it on, you need to set iflags.debug_fuzzer on via a debugger or something along those lines.
This commit is contained in:
@@ -389,7 +389,7 @@ boolean resuming;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (iflags.sanity_check)
|
||||
if (iflags.sanity_check || iflags.debug_fuzzer)
|
||||
sanity_check();
|
||||
|
||||
#ifdef CLIPPING
|
||||
|
||||
32
src/cmd.c
32
src/cmd.c
@@ -298,6 +298,8 @@ pgetchar() /* courtesy of aeb@cwi.nl */
|
||||
{
|
||||
register int ch;
|
||||
|
||||
if (iflags.debug_fuzzer)
|
||||
return randomkey();
|
||||
if (!(ch = popch()))
|
||||
ch = nhgetch();
|
||||
return (char) ch;
|
||||
@@ -942,6 +944,11 @@ wiz_level_change(VOID_ARGS)
|
||||
STATIC_PTR int
|
||||
wiz_panic(VOID_ARGS)
|
||||
{
|
||||
if (iflags.debug_fuzzer) {
|
||||
u.uhp = u.uhpmax = 1000;
|
||||
u.uen = u.uenmax = 1000;
|
||||
return 0;
|
||||
}
|
||||
if (yn("Do you want to call panic() and end your game?") == 'y')
|
||||
panic("Crash test.");
|
||||
return 0;
|
||||
@@ -4354,6 +4361,29 @@ int NDECL((*cmd_func));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
char
|
||||
randomkey()
|
||||
{
|
||||
static int i = 0;
|
||||
char c;
|
||||
|
||||
switch (rn2(12)) {
|
||||
default: c = '\033'; break;
|
||||
case 0: c = '\n'; break;
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4: c = (char)(' ' + rn2((int)('~' - ' '))); break;
|
||||
case 5: c = '\t'; break;
|
||||
case 6: c = (char)('a' + rn2((int)('z' - 'a'))); break;
|
||||
case 7: c = (char)('A' + rn2((int)('Z' - 'A'))); break;
|
||||
case 8: c = extcmdlist[(i++) % SIZE(extcmdlist)].key; break;
|
||||
case 9: c = '#'; break;
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
int
|
||||
ch2spkeys(c, start, end)
|
||||
char c;
|
||||
@@ -5563,6 +5593,8 @@ readchar()
|
||||
register int sym;
|
||||
int x = u.ux, y = u.uy, mod = 0;
|
||||
|
||||
if (iflags.debug_fuzzer)
|
||||
return randomkey();
|
||||
if (*readchar_queue)
|
||||
sym = *readchar_queue++;
|
||||
else
|
||||
|
||||
2
src/do.c
2
src/do.c
@@ -1061,6 +1061,8 @@ doup()
|
||||
return 1;
|
||||
}
|
||||
if (ledger_no(&u.uz) == 1) {
|
||||
if (iflags.debug_fuzzer)
|
||||
return 0;
|
||||
if (yn("Beware, there will be no return! Still climb?") != 'y')
|
||||
return 0;
|
||||
}
|
||||
|
||||
12
src/end.c
12
src/end.c
@@ -330,6 +330,8 @@ int sig_unused UNUSED;
|
||||
int
|
||||
done2()
|
||||
{
|
||||
if (iflags.debug_fuzzer)
|
||||
return 0;
|
||||
if (!paranoid_query(ParanoidQuit, "Really quit?")) {
|
||||
#ifndef NO_SIGNAL
|
||||
(void) signal(SIGINT, (SIG_RET_TYPE) done1);
|
||||
@@ -602,7 +604,7 @@ VA_DECL(const char *, str)
|
||||
/* XXX can we move this above the prints? Then we'd be able to
|
||||
* suppress "it may be possible to rebuild" based on dosave0()
|
||||
* or say it's NOT possible to rebuild. */
|
||||
if (program_state.something_worth_saving) {
|
||||
if (program_state.something_worth_saving && !iflags.debug_fuzzer) {
|
||||
set_error_savefile();
|
||||
if (dosave0()) {
|
||||
/* os/win port specific recover instructions */
|
||||
@@ -1043,6 +1045,14 @@ int how;
|
||||
bot();
|
||||
}
|
||||
|
||||
if (iflags.debug_fuzzer) {
|
||||
if (!(program_state.panicking || how == PANICKED)) {
|
||||
savelife(how);
|
||||
killer.name[0] = 0;
|
||||
killer.format = 0;
|
||||
return;
|
||||
}
|
||||
} else
|
||||
if (how == ASCENDED || (!killer.name[0] && how == GENOCIDED))
|
||||
killer.format = NO_KILLER_PREFIX;
|
||||
/* Avoid killed by "a" burning or "a" starvation */
|
||||
|
||||
@@ -642,6 +642,8 @@ struct obj *otmp UNUSED;
|
||||
return;
|
||||
#endif /* SIMPLE_MAIL */
|
||||
#ifdef DEF_MAILREADER /* This implies that UNIX is defined */
|
||||
if (iflags.debug_fuzzer)
|
||||
return;
|
||||
display_nhwindow(WIN_MESSAGE, FALSE);
|
||||
if (!(mr = nh_getenv("MAILREADER")))
|
||||
mr = DEF_MAILREADER;
|
||||
@@ -674,6 +676,8 @@ ckmailstatus()
|
||||
{
|
||||
struct mail_info *brdcst;
|
||||
|
||||
if (iflags.debug_fuzzer)
|
||||
return;
|
||||
if (u.uswallow || !flags.biff)
|
||||
return;
|
||||
|
||||
|
||||
@@ -453,6 +453,8 @@ VA_DECL(const char *, s)
|
||||
Vsprintf(pbuf, s, VA_ARGS);
|
||||
pbuf[BUFSZ - 1] = '\0'; /* sanity */
|
||||
paniclog("impossible", pbuf);
|
||||
if (iflags.debug_fuzzer)
|
||||
panic(pbuf);
|
||||
pline("%s", VA_PASS1(pbuf));
|
||||
pline(VA_PASS1(
|
||||
"Program in disorder! (Saving and reloading may fix this problem.)"));
|
||||
|
||||
@@ -77,6 +77,8 @@ static unsigned ustuck_id = 0, usteed_id = 0;
|
||||
int
|
||||
dosave()
|
||||
{
|
||||
if (iflags.debug_fuzzer)
|
||||
return 0;
|
||||
clear_nhwindow(WIN_MESSAGE);
|
||||
if (yn("Really save?") == 'n') {
|
||||
clear_nhwindow(WIN_MESSAGE);
|
||||
|
||||
@@ -608,6 +608,8 @@ level_tele()
|
||||
char buf[BUFSZ];
|
||||
boolean force_dest = FALSE;
|
||||
|
||||
if (iflags.debug_fuzzer)
|
||||
goto random_levtport;
|
||||
if ((u.uhave.amulet || In_endgame(&u.uz) || In_sokoban(&u.uz))
|
||||
&& !wizard) {
|
||||
You_feel("very disoriented for a moment.");
|
||||
@@ -750,6 +752,8 @@ level_tele()
|
||||
|
||||
killer.name[0] = 0; /* still alive, so far... */
|
||||
|
||||
if (iflags.debug_fuzzer && newlev < 0)
|
||||
goto random_levtport;
|
||||
if (newlev < 0 && !force_dest) {
|
||||
if (*u.ushops0) {
|
||||
/* take unpaid inventory items off of shop bills */
|
||||
|
||||
Reference in New Issue
Block a user