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:
Pasi Kallinen
2018-11-08 15:50:53 +02:00
parent 4f541fe216
commit 0bb6754998
14 changed files with 76 additions and 3 deletions

View File

@@ -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