mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-18 22:16:02 +01:00
fix(simulation): a test run that can't start ends with the error code and says why
- `--test` is looked for before the rest of the command line is read. An unknown option before it (e.g. `-s x.scn --test-timout 90 --test`) used to end the run with exit code 0, which a caller reads as a pass. - `--test-timeout` without a value, or with one that isn't a number of seconds, fails the run instead of leaving the default or, through atof, turning the timeout off. - These, a missing -s, a failed start and an exception caught in main() end the test through test_manager::conclude(), which writes the usual `test: error (exit code 5) ... : <reason>` line to stdout and the log. Before, `eu07 --test` alone exited with 5 and nothing anywhere: the error went to the log queue and the process ended before the log thread wrote it. In test mode main() now stops the log thread and waits for it before _Exit(). Outside the test mode nothing changes: conclude() does nothing there.
This commit is contained in:
21
EU07.cpp
21
EU07.cpp
@@ -84,6 +84,20 @@ LONG WINAPI CrashHandler(EXCEPTION_POINTERS *ExceptionInfo)
|
||||
|
||||
#endif
|
||||
|
||||
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.join();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
#ifdef WITHDUMPGEN
|
||||
@@ -153,6 +167,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
ErrorLog(std::format("Critical error: {}", Error.what()));
|
||||
// in test mode nobody is there to close the box, the exit code tells of the error
|
||||
simulation::test().conclude(simulation::test_result::error, std::format("critical error: {}", Error.what()));
|
||||
if (false == Global.test.enabled)
|
||||
{
|
||||
std::string msg = "Simulator crash occured :(\n";
|
||||
@@ -166,6 +181,12 @@ int main(int argc, char *argv[])
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
#endif
|
||||
if (Global.test.enabled)
|
||||
{
|
||||
// a run that stopped before its test ended (a failed start, an exception) says so like any other end
|
||||
simulation::test().conclude(simulation::test_result::error, "the simulator stopped before the test ended");
|
||||
finish_log();
|
||||
}
|
||||
// skip destructors, there are ordering errors which causes segfaults
|
||||
// a test run (--test) says its result in the exit code
|
||||
std::_Exit(Global.test.enabled ? simulation::test().exit_code() : 0);
|
||||
|
||||
Reference in New Issue
Block a user