diff --git a/code/__DEFINES/misc.dm b/code/__DEFINES/misc.dm index ca36806c24a..b70b686f7f0 100644 --- a/code/__DEFINES/misc.dm +++ b/code/__DEFINES/misc.dm @@ -500,3 +500,10 @@ GLOBAL_LIST_INIT(ghost_others_options, list(GHOST_OTHERS_SIMPLE, GHOST_OTHERS_DE #define SUMMON_GUNS "guns" #define SUMMON_MAGIC "magic" + +//Run the world with this parameter to enable a single run though of the game setup and tear down process with unit tests in between +#define TEST_RUN_PARAMETER "test-run" +//Force the log directory to be something specific in the data/logs folder +#define OVERRIDE_LOG_DIRECTORY_PARAMETER "log-directory" +//Prevent the master controller from starting automatically, overrides TEST_RUN_PARAMETER +#define NO_INIT_PARAMETER "no-init" diff --git a/code/_compile_options.dm b/code/_compile_options.dm index ac7b6ab9f9b..ac4eedc7e02 100644 --- a/code/_compile_options.dm +++ b/code/_compile_options.dm @@ -5,7 +5,7 @@ #ifdef TESTING //#define GC_FAILURE_HARD_LOOKUP //makes paths that fail to GC call find_references before del'ing. - //implies FIND_REF_NO_CHECK_TICK + //implies FIND_REF_NO_CHECK_TICK //#define FIND_REF_NO_CHECK_TICK //Sets world.loop_checks to false and prevents find references from sleeping diff --git a/code/controllers/master.dm b/code/controllers/master.dm index 92a94bf428c..9aa7bd9b758 100644 --- a/code/controllers/master.dm +++ b/code/controllers/master.dm @@ -49,6 +49,7 @@ GLOBAL_REAL(Master, /datum/controller/master) = new var/map_loading = FALSE //Are we loading in a new map? var/current_runlevel //for scheduling different subsystems for different stages of the round + var/sleep_offline_after_initializations = TRUE var/static/restart_clear = 0 var/static/restart_timeout = 0 @@ -196,11 +197,12 @@ GLOBAL_REAL(Master, /datum/controller/master) = new // Sort subsystems by display setting for easy access. sortTim(subsystems, /proc/cmp_subsystem_display) // Set world options. - world.sleep_offline = TRUE + if(sleep_offline_after_initializations) + world.sleep_offline = TRUE world.fps = CONFIG_GET(number/fps) var/initialized_tod = REALTIMEOFDAY sleep(1) - if(CONFIG_GET(flag/resume_after_initializations)) + if(sleep_offline_after_initializations && CONFIG_GET(flag/resume_after_initializations)) world.sleep_offline = FALSE initializations_finished_with_no_players_logged_in = initialized_tod < REALTIMEOFDAY - 10 // Loop. diff --git a/code/game/world.dm b/code/game/world.dm index de236cdabf5..a4249d6b45f 100644 --- a/code/game/world.dm +++ b/code/game/world.dm @@ -39,11 +39,21 @@ GLOBAL_PROTECT(security_mode) GLOB.restart_counter = text2num(trim(file2text(RESTART_COUNTER_PATH))) fdel(RESTART_COUNTER_PATH) - if("no-init" in params) + if(NO_INIT_PARAMETER in params) return Master.Initialize(10, FALSE) + if(TEST_RUN_PARAMETER in params) + HandleTestRun() + +/world/proc/HandleTestRun() + //trigger things to run the whole process + Master.sleep_offline_after_initializations = FALSE + SSticker.start_immediately = TRUE + CONFIG_SET(number/round_end_countdown, 0) + SSticker.force_ending = TRUE + /world/proc/SetupExternalRSC() #if (PRELOAD_RSC == 0) GLOB.external_rsc_urls = world.file2list("config/external_rsc_urls.txt","\n") @@ -56,11 +66,15 @@ GLOBAL_PROTECT(security_mode) #endif /world/proc/SetupLogs() - GLOB.log_directory = "data/logs/[time2text(world.realtime, "YYYY/MM/DD")]/round-" - if(GLOB.round_id) - GLOB.log_directory += "[GLOB.round_id]" + var/override_dir = params[OVERRIDE_LOG_DIRECTORY_PARAMETER] + if(!override_dir) + GLOB.log_directory = "data/logs/[time2text(world.realtime, "YYYY/MM/DD")]/round-" + if(GLOB.round_id) + GLOB.log_directory += "[GLOB.round_id]" + else + GLOB.log_directory += "[replacetext(time_stamp(), ":", ".")]" else - GLOB.log_directory += "[replacetext(time_stamp(), ":", ".")]" + GLOB.log_directory = "data/logs/[override_dir]" GLOB.world_game_log = file("[GLOB.log_directory]/game.log") GLOB.world_attack_log = file("[GLOB.log_directory]/attack.log") GLOB.world_runtime_log = file("[GLOB.log_directory]/runtime.log") @@ -132,6 +146,23 @@ GLOBAL_PROTECT(security_mode) for(var/client/C in GLOB.clients) C.AnnouncePR(final_composed) +/world/proc/FinishTestRun() + set waitfor = FALSE + var/list/fail_reasons + if(GLOB) + if(GLOB.total_runtimes != 0) + fail_reasons = list("Total runtimes: [GLOB.total_runtimes]") + if(!GLOB.log_directory) + LAZYADD(fail_reasons, "Missing GLOB.log_directory!") + else + fail_reasons = list("Missing GLOB!") + if(!fail_reasons) + text2file("Success!", "[GLOB.log_directory]/clean_run.lk") + else + log_world("Test run failed!\n[fail_reasons.Join("\n")]") + sleep(0) //yes, 0, this'll let Reboot finish and prevent byond memes + qdel(src) //shut it down + /world/Reboot(reason = 0, fast_track = FALSE) SERVER_TOOLS_ON_REBOOT if (reason || fast_track) //special reboot, do none of the normal stuff @@ -143,6 +174,10 @@ GLOBAL_PROTECT(security_mode) to_chat(world, "Rebooting world...") Master.Shutdown() //run SS shutdowns + if(TEST_RUN_PARAMETER in params) + FinishTestRun() + return + if(SERVER_TOOLS_PRESENT) var/do_hard_reboot // check the hard reboot counter diff --git a/code/modules/error_handler/error_handler.dm b/code/modules/error_handler/error_handler.dm index f5882ca916d..3febc519390 100644 --- a/code/modules/error_handler/error_handler.dm +++ b/code/modules/error_handler/error_handler.dm @@ -116,7 +116,8 @@ GLOBAL_VAR_INIT(total_runtimes_skipped, 0) if(GLOB.error_cache) GLOB.error_cache.log_error(E, desclines) - SEND_TEXT(world.log, "\[[time_stamp()]] Runtime in [E.file],[E.line]: [E]") + var/main_line = "\[[time_stamp()]] Runtime in [E.file],[E.line]: [E]" + SEND_TEXT(world.log, main_line) for(var/line in desclines) SEND_TEXT(world.log, line) diff --git a/tools/travis/build_byond.sh b/tools/travis/build_byond.sh index 139c8c70a55..254dc614813 100755 --- a/tools/travis/build_byond.sh +++ b/tools/travis/build_byond.sh @@ -48,6 +48,7 @@ if [ "$BUILD_TOOLS" = false ]; then if [ "$BUILD_TESTING" = true ]; then tools/travis/dm.sh -DTRAVISBUILDING -DTRAVISTESTING -DALL_MAPS tgstation.dme else - tools/travis/dm.sh -DTRAVISBUILDING tgstation.dme + tools/travis/dm.sh -DTRAVISBUILDING tgstation.dme && DreamDaemon tgstation.dmb -close -trusted -params "test-run&log-directory=travis" + cat data/logs/travis/clean_run.lk fi; fi;