mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-19 00:35:59 +01:00
Merge branch 'master' into feat/renderers-cleanup
This commit is contained in:
60
EU07.cpp
60
EU07.cpp
@@ -19,9 +19,15 @@ Stele, firleju, szociu, hunter, ZiomalCl, OLI_EU and others
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "application/application.h"
|
||||
#include "simulation/simulationtest.h"
|
||||
#include "utilities/Globals.h"
|
||||
#include "utilities/Logs.h"
|
||||
#include "utilities/crashdump.h"
|
||||
#include <cstdlib>
|
||||
#include <exception>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#ifdef EU07_CPU_PREFLIGHT
|
||||
@@ -48,6 +54,55 @@ static void stop_log_service()
|
||||
it->second.join();
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
// the log is written by a thread of its own, which the closing of the application stops and waits for. on the ways
|
||||
// out that skip the closing (a failed start, an exception) what was logged last would be lost with the process
|
||||
void finish_log()
|
||||
{
|
||||
StopLogService();
|
||||
if (auto const logservice{Global.threads.find("LogService")};
|
||||
logservice != Global.threads.end() && logservice->second.joinable() && logservice->second.get_id() != std::this_thread::get_id())
|
||||
logservice->second.join();
|
||||
}
|
||||
|
||||
// ends a test run with its verdict on the standard output and in the exit code. a test the simulator didn't end
|
||||
// (a failed start, an exception) ends with the error and Reason
|
||||
[[noreturn]] void end_test_run(std::string_view const Reason)
|
||||
{
|
||||
simulation::test().conclude(simulation::test_result::error, Reason);
|
||||
finish_log();
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
// skip destructors, there are ordering errors which causes segfaults
|
||||
std::_Exit(simulation::test().exit_code());
|
||||
}
|
||||
|
||||
// a test run (--test): whatever stops it, it ends with its verdict. any other run never gets here and ends as
|
||||
// it always has
|
||||
[[noreturn]] void run_test(int argc, char *argv[])
|
||||
{
|
||||
// for what doesn't reach the catch below: an exception leaving a noexcept function, or on Linux one leaving
|
||||
// a thread (on Windows the handler is the main thread's only)
|
||||
std::set_terminate([] { end_test_run(simulation::describe_exception(std::current_exception())); });
|
||||
try
|
||||
{
|
||||
if (Application.init(argc, argv) == 0)
|
||||
{
|
||||
Application.run();
|
||||
Application.exit();
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
end_test_run(simulation::describe_exception(std::current_exception()));
|
||||
}
|
||||
end_test_run("the simulator stopped before the test ended");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
crashdump_install();
|
||||
@@ -95,6 +150,11 @@ int main(int argc, char *argv[])
|
||||
fflush(stderr);
|
||||
std::_Exit(result);
|
||||
}
|
||||
// unattended test run of a scenery, which says its result in the exit code (eu07/maszyna#541)
|
||||
else if (simulation::parse_test_command_line(std::vector<char const *>(argv, argv + argc)).enabled)
|
||||
{
|
||||
run_test(argc, argv);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user