Move fuzzer_start, fuzzer_stop and fuzzer_log to pline.c
This commit is contained in:
+3
-3
@@ -27,10 +27,7 @@ E void NDECL(newgame);
|
|||||||
E void FDECL(welcome, (BOOLEAN_P));
|
E void FDECL(welcome, (BOOLEAN_P));
|
||||||
E time_t NDECL(get_realtime);
|
E time_t NDECL(get_realtime);
|
||||||
E int FDECL(argcheck, (int, char **, enum earlyarg));
|
E int FDECL(argcheck, (int, char **, enum earlyarg));
|
||||||
E void NDECL(fuzzer_start);
|
|
||||||
E void NDECL(fuzzer_stop);
|
|
||||||
E void NDECL(fuzzer_toggle);
|
E void NDECL(fuzzer_toggle);
|
||||||
E void VDECL(fuzzer_log, (int, const char *, ...)) PRINTF_F(2, 3);
|
|
||||||
E void NDECL(fuzzer_check);
|
E void NDECL(fuzzer_check);
|
||||||
E void NDECL(fuzzer_auto_start);
|
E void NDECL(fuzzer_auto_start);
|
||||||
E boolean FDECL(fuzzer_msg_history, (const char *));
|
E boolean FDECL(fuzzer_msg_history, (const char *));
|
||||||
@@ -1943,6 +1940,9 @@ E void VDECL(raw_printf, (const char *, ...)) PRINTF_F(1, 2);
|
|||||||
E void VDECL(impossible, (const char *, ...)) PRINTF_F(1, 2);
|
E void VDECL(impossible, (const char *, ...)) PRINTF_F(1, 2);
|
||||||
E void VDECL(config_error_add, (const char *, ...)) PRINTF_F(1, 2);
|
E void VDECL(config_error_add, (const char *, ...)) PRINTF_F(1, 2);
|
||||||
E void FDECL(nhassert_failed, (const char *, int));
|
E void FDECL(nhassert_failed, (const char *, int));
|
||||||
|
E void NDECL(fuzzer_start);
|
||||||
|
E void NDECL(fuzzer_stop);
|
||||||
|
E void VDECL(fuzzer_log, (int, const char *, ...)) PRINTF_F(2, 3);
|
||||||
|
|
||||||
/* ### polyself.c ### */
|
/* ### polyself.c ### */
|
||||||
|
|
||||||
|
|||||||
+5
-58
@@ -4,7 +4,6 @@
|
|||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* NetHack may be freely redistributed. See license for details. */
|
||||||
|
|
||||||
/* various code that was replicated in *main.c */
|
/* various code that was replicated in *main.c */
|
||||||
#define NEED_VARARGS
|
|
||||||
#include "hack.h"
|
#include "hack.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
@@ -927,38 +926,6 @@ const char *opts;
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FILE * g_fuzzer_log_file = NULL;
|
|
||||||
static int g_fuzzer_log_level = LOG_MINIMAL;
|
|
||||||
|
|
||||||
/* fuzzer_start() starts the fuzzer opening the fuzzer log file */
|
|
||||||
void
|
|
||||||
fuzzer_start()
|
|
||||||
{
|
|
||||||
if (!iflags.debug_fuzzer) {
|
|
||||||
const char * fq_replay;
|
|
||||||
|
|
||||||
iflags.debug_fuzzer = TRUE;
|
|
||||||
iflags.fuzzer_auto_start = FALSE;
|
|
||||||
|
|
||||||
nhassert(g_fuzzer_log_file == NULL);
|
|
||||||
fq_replay = fqname("fuzzer.log", SAVEPREFIX, 0);
|
|
||||||
|
|
||||||
g_fuzzer_log_file = fopen(fq_replay, "w");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* fuzzer_stop() stops the fuzzer and close the fuzzer log file */
|
|
||||||
void
|
|
||||||
fuzzer_stop()
|
|
||||||
{
|
|
||||||
if (iflags.debug_fuzzer) {
|
|
||||||
if(g_fuzzer_log_file != NULL) {
|
|
||||||
fclose(g_fuzzer_log_file);
|
|
||||||
g_fuzzer_log_file = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* fuzzer_toggle() toggles fuzzer state */
|
/* fuzzer_toggle() toggles fuzzer state */
|
||||||
void
|
void
|
||||||
fuzzer_toggle()
|
fuzzer_toggle()
|
||||||
@@ -969,29 +936,6 @@ fuzzer_toggle()
|
|||||||
fuzzer_start();
|
fuzzer_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fuzzer_log() is used to place messages in the file 'fuzzer.log'. This
|
|
||||||
* log is the primary tool for monitoring fuzzer activity and tracking down
|
|
||||||
* issues that the fuzzer is able to reproduce.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
fuzzer_log
|
|
||||||
VA_DECL2(int, level, const char *, str)
|
|
||||||
{
|
|
||||||
VA_START(str);
|
|
||||||
VA_INIT(str, char *);
|
|
||||||
|
|
||||||
if (!g_fuzzer_log_file)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (iflags.verbose_logging_start != 0 && moves >= iflags.verbose_logging_start)
|
|
||||||
g_fuzzer_log_level = LOG_VERBOSE;
|
|
||||||
|
|
||||||
if (level <= g_fuzzer_log_level)
|
|
||||||
Vfprintf(g_fuzzer_log_file, str, VA_ARGS);
|
|
||||||
|
|
||||||
VA_END();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* fuzzer_check() is called prior to rhack(0) to allow the fuzzer to
|
/* fuzzer_check() is called prior to rhack(0) to allow the fuzzer to
|
||||||
* check if it should stop and to allow it to reseed the game.
|
* check if it should stop and to allow it to reseed the game.
|
||||||
*/
|
*/
|
||||||
@@ -1000,6 +944,8 @@ fuzzer_check()
|
|||||||
{
|
{
|
||||||
if (iflags.debug_fuzzer)
|
if (iflags.debug_fuzzer)
|
||||||
{
|
{
|
||||||
|
unsigned long seed;
|
||||||
|
|
||||||
if (moves >= iflags.fuzzer_stop_and_save) {
|
if (moves >= iflags.fuzzer_stop_and_save) {
|
||||||
iflags.fuzzer_saving = TRUE;
|
iflags.fuzzer_saving = TRUE;
|
||||||
dosave0();
|
dosave0();
|
||||||
@@ -1008,7 +954,7 @@ fuzzer_check()
|
|||||||
nh_terminate(EXIT_SUCCESS);
|
nh_terminate(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long seed = rul();
|
seed = rul();
|
||||||
set_random(seed, rn2);
|
set_random(seed, rn2);
|
||||||
fuzzer_log(LOG_MINIMAL, "SEED:%ld:%lu\n", moves, seed);
|
fuzzer_log(LOG_MINIMAL, "SEED:%ld:%lu\n", moves, seed);
|
||||||
|
|
||||||
@@ -1022,9 +968,10 @@ void
|
|||||||
fuzzer_auto_start()
|
fuzzer_auto_start()
|
||||||
{
|
{
|
||||||
if (iflags.fuzzer_auto_start) {
|
if (iflags.fuzzer_auto_start) {
|
||||||
|
unsigned long seed;
|
||||||
nhassert(!iflags.debug_fuzzer);
|
nhassert(!iflags.debug_fuzzer);
|
||||||
fuzzer_start();
|
fuzzer_start();
|
||||||
unsigned long seed = rul();
|
seed = rul();
|
||||||
set_random(seed, rn2);
|
set_random(seed, rn2);
|
||||||
fuzzer_log(LOG_MINIMAL, "START:%ld:%lu\n", moves, seed);
|
fuzzer_log(LOG_MINIMAL, "START:%ld:%lu\n", moves, seed);
|
||||||
}
|
}
|
||||||
|
|||||||
+57
@@ -599,4 +599,61 @@ nhassert_failed(filepath, line)
|
|||||||
impossible("nhassert failed in file '%s' at line %d", filename, line);
|
impossible("nhassert failed in file '%s' at line %d", filename, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static FILE * g_fuzzer_log_file = NULL;
|
||||||
|
static int g_fuzzer_log_level = LOG_MINIMAL;
|
||||||
|
|
||||||
|
/* fuzzer_start() starts the fuzzer opening the fuzzer log file */
|
||||||
|
void
|
||||||
|
fuzzer_start()
|
||||||
|
{
|
||||||
|
if (!iflags.debug_fuzzer) {
|
||||||
|
const char * fq_replay;
|
||||||
|
|
||||||
|
iflags.debug_fuzzer = TRUE;
|
||||||
|
iflags.fuzzer_auto_start = FALSE;
|
||||||
|
|
||||||
|
nhassert(g_fuzzer_log_file == NULL);
|
||||||
|
fq_replay = fqname("fuzzer.log", SAVEPREFIX, 0);
|
||||||
|
|
||||||
|
g_fuzzer_log_file = fopen(fq_replay, "w");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* fuzzer_stop() stops the fuzzer and close the fuzzer log file */
|
||||||
|
void
|
||||||
|
fuzzer_stop()
|
||||||
|
{
|
||||||
|
if (iflags.debug_fuzzer) {
|
||||||
|
if(g_fuzzer_log_file != NULL) {
|
||||||
|
fclose(g_fuzzer_log_file);
|
||||||
|
g_fuzzer_log_file = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* fuzzer_log() is used to place messages in the file 'fuzzer.log'. This
|
||||||
|
* log is the primary tool for monitoring fuzzer activity and tracking down
|
||||||
|
* issues that the fuzzer is able to reproduce.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
fuzzer_log
|
||||||
|
VA_DECL2(int, lvl, const char *, str)
|
||||||
|
{
|
||||||
|
VA_START(str);
|
||||||
|
VA_INIT(str, char *);
|
||||||
|
|
||||||
|
if (!g_fuzzer_log_file)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (iflags.verbose_logging_start != 0 &&
|
||||||
|
moves >= iflags.verbose_logging_start)
|
||||||
|
g_fuzzer_log_level = LOG_VERBOSE;
|
||||||
|
|
||||||
|
if (lvl <= g_fuzzer_log_level)
|
||||||
|
Vfprintf(g_fuzzer_log_file, str, VA_ARGS);
|
||||||
|
|
||||||
|
VA_END();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*pline.c*/
|
/*pline.c*/
|
||||||
|
|||||||
Reference in New Issue
Block a user