Small improvements to fuzzer for NetHackW.

Can toggle fuzzer on/off using "Pause" key if attached to debugger.
Extended command selected randomly.
This commit is contained in:
Bart House
2018-12-15 14:49:59 -08:00
parent 1be3ad0ddc
commit 266b5e3891
7 changed files with 125 additions and 70 deletions

View File

@@ -22,5 +22,6 @@ struct ext_func_tab {
};
extern struct ext_func_tab extcmdlist[];
extern int extcmdlist_length;
#endif /* FUNC_TAB_H */

View File

@@ -3406,6 +3406,8 @@ struct ext_func_tab extcmdlist[] = {
{ '\0', (char *) 0, (char *) 0, donull, 0, (char *) 0 } /* sentinel */
};
int extcmdlist_length = SIZE(extcmdlist) - 1;
const char *
key2extcmddesc(key)
uchar key;

View File

@@ -167,6 +167,15 @@ INT_PTR CALLBACK ExtCmdDlgProc(HWND, UINT, WPARAM, LPARAM);
int
mswin_ext_cmd_window(int *selection)
{
if (iflags.debug_fuzzer) {
*selection = rn2(extcmdlist_length + 1) - 1;
if (*selection != -1)
return IDOK;
else
return IDCANCEL;
}
INT_PTR ret;
struct extcmd_data data;

View File

@@ -195,7 +195,7 @@ static const char scanmap[] = {
LRESULT CALLBACK
MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PNHMainWindow data;
PNHMainWindow data = (PNHMainWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
switch (message) {
case WM_CREATE:
@@ -225,7 +225,6 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
break;
case WM_KEYDOWN: {
data = (PNHMainWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
/* translate arrow keys into nethack commands */
switch (wParam) {
@@ -332,6 +331,15 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
NHEVENT_KBD(KEYTABLE(KEY_PLUS));
return 0;
#if defined(DEBUG) && defined(_MSC_VER)
case VK_PAUSE:
if (IsDebuggerPresent()) {
iflags.debug_fuzzer = !iflags.debug_fuzzer;
return 0;
}
break;
#endif
case VK_CLEAR: /* This is the '5' key */
NHEVENT_KBD(KEYTABLE(KEY_GOINTERESTING));
return 0;
@@ -530,9 +538,10 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
child = GetNHApp()->windowlist[msg_param->wid].win;
} break;
case MSNH_MSG_RANDOM_INPUT:
nhassert(0); // unexpected
break;
case MSNH_MSG_RANDOM_INPUT: {
nhassert(iflags.debug_fuzzer);
NHEVENT_KBD(randomkey());
} break;
}
}

View File

@@ -689,14 +689,8 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
} break;
case MSNH_MSG_RANDOM_INPUT: {
char c = randomkey();
if (c == '\n')
PostMessage(hWnd, WM_COMMAND, MAKELONG(IDOK, 0), 0);
else if (c == '\033')
PostMessage(hWnd, WM_COMMAND, MAKELONG(IDCANCEL, 0), 0);
else
PostMessage(GetDlgItem(hWnd, IDC_TEXT_CONTROL), WM_CHAR, c, 0);
PostMessage(GetMenuControl(hWnd),
WM_MSNH_COMMAND, MSNH_MSG_RANDOM_INPUT, 0);
} break;
}
@@ -1601,6 +1595,7 @@ reset_menu_count(HWND hwndList, PNHMenuWindow data)
LRESULT CALLBACK
NHMenuListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND hWndParent = GetParent(hWnd);
BOOL bUpdateFocusItem;
/* we will redraw focused item whenever horizontal scrolling occurs
@@ -1632,6 +1627,20 @@ NHMenuListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
SetFocus(GetNHApp()->hMainWnd);
}
return FALSE;
case WM_MSNH_COMMAND:
if (wParam == MSNH_MSG_RANDOM_INPUT) {
char c = randomkey();
if (c == '\n')
PostMessage(hWndParent, WM_COMMAND, MAKELONG(IDOK, 0), 0);
else if (c == '\033')
PostMessage(hWndParent, WM_COMMAND, MAKELONG(IDCANCEL, 0), 0);
else
PostMessage(hWnd, WM_CHAR, c, 0);
return 0;
}
break;
}
/* update focused item */
@@ -1659,6 +1668,7 @@ NHMenuListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK
NHMenuTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND hWndParent = GetParent(hWnd);
HDC hDC;
RECT rc;
@@ -1686,8 +1696,7 @@ NHMenuTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
&& (si.nPos + (int) si.nPage) <= (si.nMax - si.nMin))
SendMessage(hWnd, EM_SCROLL, SB_PAGEDOWN, 0);
else
PostMessage(GetParent(hWnd), WM_COMMAND, MAKELONG(IDOK, 0),
0);
PostMessage(hWndParent, WM_COMMAND, MAKELONG(IDOK, 0), 0);
return 0;
}
case VK_NEXT:
@@ -1726,6 +1735,20 @@ NHMenuTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case WM_SETFOCUS:
HideCaret(hWnd);
return 0;
case WM_MSNH_COMMAND:
if (wParam == MSNH_MSG_RANDOM_INPUT) {
char c = randomkey();
if (c == '\n')
PostMessage(hWndParent, WM_COMMAND, MAKELONG(IDOK, 0), 0);
else if (c == '\033')
PostMessage(hWndParent, WM_COMMAND, MAKELONG(IDCANCEL, 0), 0);
else
PostMessage(hWnd, WM_CHAR, c, 0);
return 0;
}
break;
}
if (editControlWndProc)

View File

@@ -27,7 +27,6 @@ HWND
mswin_init_text_window()
{
HWND ret;
PNHTextWindow data;
RECT rt;
/* get window position */
@@ -52,13 +51,6 @@ mswin_init_text_window()
/* Set window caption */
SetWindowText(ret, "Text");
/* create and set window data */
data = (PNHTextWindow) malloc(sizeof(NHTextWindow));
if (!data)
panic("out of memory");
ZeroMemory(data, sizeof(NHTextWindow));
SetWindowLongPtr(ret, GWLP_USERDATA, (LONG_PTR) data);
mswin_apply_window_style(ret);
return ret;
@@ -88,6 +80,12 @@ NHTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
switch (message) {
case WM_INITDIALOG: {
data = (PNHTextWindow)malloc(sizeof(NHTextWindow));
if (!data)
panic("out of memory");
ZeroMemory(data, sizeof(NHTextWindow));
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)data);
HWND control = GetDlgItem(hWnd, IDC_TEXT_CONTROL);
HDC hdc = GetDC(control);
cached_font * font = mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE);
@@ -177,7 +175,10 @@ NHTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) 0);
}
break;
}
return FALSE;
}
@@ -214,14 +215,8 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
}
case MSNH_MSG_RANDOM_INPUT: {
char c = randomkey();
if (c == '\n')
PostMessage(hWnd, WM_COMMAND, MAKELONG(IDOK, 0), 0);
else if (c == '\033')
PostMessage(hWnd, WM_COMMAND, MAKELONG(IDCANCEL, 0), 0);
else
PostMessage(GetDlgItem(hWnd, IDC_TEXT_CONTROL), WM_CHAR, c, 0);
PostMessage(GetDlgItem(hWnd, IDC_TEXT_CONTROL),
WM_MSNH_COMMAND, MSNH_MSG_RANDOM_INPUT, 0);
}
break;
@@ -278,6 +273,7 @@ LayoutText(HWND hWnd)
LRESULT CALLBACK
NHEditHookWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND hWndParent = GetParent(hWnd);
HDC hDC;
RECT rc;
@@ -305,8 +301,7 @@ NHEditHookWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
&& (si.nPos + (int) si.nPage) <= (si.nMax - si.nMin))
SendMessage(hWnd, EM_SCROLL, SB_PAGEDOWN, 0);
else
PostMessage(GetParent(hWnd), WM_COMMAND, MAKELONG(IDOK, 0),
0);
PostMessage(hWndParent, WM_COMMAND, MAKELONG(IDOK, 0), 0);
return 0;
}
case VK_NEXT:
@@ -346,6 +341,20 @@ NHEditHookWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case WM_SETFOCUS:
HideCaret(hWnd);
return 0;
case WM_MSNH_COMMAND:
if (wParam == MSNH_MSG_RANDOM_INPUT) {
char c = randomkey();
if (c == '\n')
PostMessage(hWndParent, WM_COMMAND, MAKELONG(IDOK, 0), 0);
else if (c == '\033')
PostMessage(hWndParent, WM_COMMAND, MAKELONG(IDCANCEL, 0), 0);
else
PostMessage(hWnd, WM_CHAR, c, 0);
return 0;
}
break;
}
if (editControlWndProc)

View File

@@ -2102,24 +2102,25 @@ mswin_main_loop()
{
MSG msg;
while (!mswin_have_input()) {
if (!iflags.debug_fuzzer || PeekMessage(&msg, NULL, 0, 0, FALSE)) {
if(GetMessage(&msg, NULL, 0, 0) != 0) {
if (GetNHApp()->regNetHackMode
|| !TranslateAccelerator(msg.hwnd, GetNHApp()->hAccelTable,
&msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
} else {
/* WM_QUIT */
break;
}
} else {
nhassert(iflags.debug_fuzzer);
NHEVENT_KBD(randomkey());
}
}
while (!mswin_have_input()) {
if (!iflags.debug_fuzzer || PeekMessage(&msg, NULL, 0, 0, FALSE)) {
if(GetMessage(&msg, NULL, 0, 0) != 0) {
if (GetNHApp()->regNetHackMode
|| !TranslateAccelerator(msg.hwnd, GetNHApp()->hAccelTable,
&msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
} else {
/* WM_QUIT */
break;
}
} else {
nhassert(iflags.debug_fuzzer);
PostMessage(GetNHApp()->hMainWnd, WM_MSNH_COMMAND,
MSNH_MSG_RANDOM_INPUT, 0);
}
}
}
/* clean up and quit */
@@ -2232,25 +2233,26 @@ mswin_popup_display(HWND hWnd, int *done_indicator)
SetFocus(hWnd);
/* go into message loop */
while (IsWindow(hWnd) && (done_indicator == NULL || !*done_indicator)) {
if (!iflags.debug_fuzzer || PeekMessage(&msg, NULL, 0, 0, FALSE)) {
if(GetMessage(&msg, NULL, 0, 0) != 0) {
if (!IsDialogMessage(hWnd, &msg)) {
if (!TranslateAccelerator(msg.hwnd, GetNHApp()->hAccelTable,
&msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
} else {
/* WM_QUIT */
break;
}
} else {
nhassert(iflags.debug_fuzzer);
PostMessage(hWnd, WM_MSNH_COMMAND, MSNH_MSG_RANDOM_INPUT, 0);
}
}
while (IsWindow(hWnd) && (done_indicator == NULL || !*done_indicator)) {
if (!iflags.debug_fuzzer || PeekMessage(&msg, NULL, 0, 0, FALSE)) {
if(GetMessage(&msg, NULL, 0, 0) != 0) {
if (msg.message == WM_MSNH_COMMAND ||
!IsDialogMessage(hWnd, &msg)) {
if (!TranslateAccelerator(msg.hwnd,
GetNHApp()->hAccelTable, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
} else {
/* WM_QUIT */
break;
}
} else {
nhassert(iflags.debug_fuzzer);
PostMessage(hWnd, WM_MSNH_COMMAND, MSNH_MSG_RANDOM_INPUT, 0);
}
}
}
void