mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-19 09:56:01 +01:00
feat(simulation): test mode, --test runs a scenery unattended and exits with the result (eu07/maszyna#541)
eu07 --test -s <scenery> [--test-timeout <s>] runs the scenery in ghostview with
the null renderer (models loaded, no textures), a hidden window, no sound,
network or python, and in fixed steps of 0.03 s of simulation time per frame
(three 10 ms physics steps) as fast as it can. Without -seed it uses a fixed
seed, so two runs give byte-identical physicslogs.
The scenery reports its result to the __test.result memory cell, which the
simulator always creates: value 1 passes once every vehicle has stood still for
1 s, value 0 fails at once. The run ends with exit code
0 pass, 1 fail,
2 a train passed a signal at stop (SetVelocity 0 0, as seen in its driver's
speed table; SetVelocity 0 x on automatic block doesn't count),
3 timeout (test.timeout, default 3600 s of simulation time),
4 standstill (every vehicle still for test.standstill s, default 300, with no
result; a pass with test.pass_on_standstill yes),
5 error (no -s, the scenery didn't load or has no vehicles, an exception).
The test.* keys go in the scenery's config block; test.fail_if_stop_overran no
only logs a signal passed at danger. Outside the test mode a signal passed at
danger is logged.
The null renderer gets a ui backend which draws nothing, hands out the null
texture and material instead of throwing, and ends the ui frame. A GL context
is still made for the hidden window, without asking for a version, as parts
of the ui create textures with gl calls of their own. No crash dialog or
message box in test mode; the window code no longer needs a monitor.
This commit is contained in:
@@ -456,6 +456,40 @@ bool global_settings::ConfigParseInput(cParser& Parser, const std::string& token
|
||||
return false;
|
||||
}
|
||||
|
||||
bool global_settings::ConfigParseTest(cParser& Parser, const std::string& token)
|
||||
{
|
||||
// integration test limits, usually given in the config block of a test scenery
|
||||
if (token == "test.timeout")
|
||||
{
|
||||
double value{ test.timeout };
|
||||
ParseOne(Parser, value);
|
||||
if (false == test.timeout_from_command_line)
|
||||
test.timeout = std::max(0.0, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (token == "test.standstill")
|
||||
{
|
||||
ParseOne(Parser, test.standstill);
|
||||
test.standstill = std::max(0.0, test.standstill);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (token == "test.pass_on_standstill")
|
||||
{
|
||||
ParseOne(Parser, test.pass_on_standstill);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (token == "test.fail_if_stop_overran")
|
||||
{
|
||||
ParseOne(Parser, test.fail_if_stop_overran);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool global_settings::ConfigParseSimulation(cParser& Parser, const std::string& token)
|
||||
{
|
||||
if (token == "async.trainThreads")
|
||||
@@ -1316,6 +1350,9 @@ void global_settings::ConfigParse(cParser& Parser)
|
||||
if (ConfigParseDebug(Parser, token))
|
||||
continue;
|
||||
|
||||
if (ConfigParseTest(Parser, token))
|
||||
continue;
|
||||
|
||||
// WriteLog(std::format("Unknown config token: {}", token), logtype::warning, false);
|
||||
|
||||
} while (true);
|
||||
|
||||
@@ -86,6 +86,15 @@ struct global_settings {
|
||||
std::string local_start_vehicle{ "EU07-424" };
|
||||
std::string editor_enter_vehicle; // vehicle placed in the editor, to be entered when the driving goes on
|
||||
bool editor_session{ false }; // scenery was opened for editing (-edit): loader keeps track of scenery layers and hands over to the editor
|
||||
// integration test mode (--test, eu07/maszyna#541); the limits can be set in the scenery's config block (test.*)
|
||||
struct test_settings {
|
||||
bool enabled{ false };
|
||||
double timeout{ 3600.0 }; // [s] of simulation time; no result by then fails the test
|
||||
double standstill{ 300.0 }; // [s] every vehicle standing still this long ends the test; 0 = never
|
||||
bool pass_on_standstill{ false }; // the standstill end passes the test instead of failing it
|
||||
bool fail_if_stop_overran{ true }; // a train passing a signal at stop ends the test as failed; with false it's only logged
|
||||
bool timeout_from_command_line{ false }; // --test-timeout given, the scenery doesn't override it
|
||||
} test;
|
||||
bool editor_tracks{ false }; // F3 track workspace: draw and pick tracks without the scenery draw-range cap
|
||||
int iConvertModels{ 0 }; // tworzenie plików binarnych
|
||||
int iConvertIndexRange{ 1000 }; // range of duplicate vertex scan
|
||||
@@ -377,6 +386,7 @@ struct global_settings {
|
||||
bool ConfigParseNetwork(cParser& Parser, const std::string& token);
|
||||
bool ConfigParseHardware(cParser& Parser, const std::string& token);
|
||||
bool ConfigParseDebug(cParser& Parser, const std::string& token);
|
||||
bool ConfigParseTest(cParser& Parser, const std::string& token);
|
||||
bool ConfigParse_gfx( cParser &parser, std::string_view const Token );
|
||||
// sends basic content of the class in legacy (text) format to provided stream
|
||||
void
|
||||
|
||||
@@ -26,6 +26,7 @@ double fRenderTime{ 0.0 };
|
||||
double fSoundTimer{ 0.0 };
|
||||
double fSinceStart{ 0.0 };
|
||||
double override_delta = -1.0f;
|
||||
double fixed_step = 0.0;
|
||||
|
||||
double GetTime()
|
||||
{
|
||||
@@ -53,6 +54,11 @@ void set_delta_override(double t)
|
||||
override_delta = t;
|
||||
}
|
||||
|
||||
void set_fixed_step(double t)
|
||||
{
|
||||
fixed_step = t;
|
||||
}
|
||||
|
||||
void ResetTimers()
|
||||
{
|
||||
UpdateTimers( Global.iPause != 0 );
|
||||
@@ -76,10 +82,15 @@ void UpdateTimers(bool pause)
|
||||
fr = 1000000000;
|
||||
#endif
|
||||
DeltaRenderTime = double(count - oldCount) / double(fr);
|
||||
if (fixed_step > 0.0)
|
||||
{
|
||||
// the frame lasts exactly as long as said, however long it took to compute; the time speed doesn't apply
|
||||
DeltaRenderTime = fixed_step;
|
||||
}
|
||||
fRenderTime += DeltaRenderTime;
|
||||
if (!pause)
|
||||
{
|
||||
DeltaTime = Global.fTimeSpeed * DeltaRenderTime;
|
||||
DeltaTime = (fixed_step > 0.0 ? 1.0 : Global.fTimeSpeed) * DeltaRenderTime;
|
||||
fSoundTimer += DeltaTime;
|
||||
if (fSoundTimer > 0.1)
|
||||
fSoundTimer = 0.0;
|
||||
|
||||
@@ -19,6 +19,9 @@ double GetDeltaRenderTime();
|
||||
|
||||
void set_delta_override(double v);
|
||||
|
||||
// every frame advances the clocks by this many seconds, whatever the real time; 0 = real time (test mode)
|
||||
void set_fixed_step(double v);
|
||||
|
||||
void ResetTimers();
|
||||
|
||||
void UpdateTimers(bool pause);
|
||||
|
||||
Reference in New Issue
Block a user