18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-20 10:24:58 +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:
jerrrrycho
2026-11-07 13:17:26 +01:00
parent 6209e16558
commit 02e29f6971
16 changed files with 458 additions and 26 deletions

View File

@@ -26,6 +26,7 @@ http://mozilla.org/MPL/2.0/.
#include "world/MemCell.h"
#include "simulation/simulation.h"
#include "simulation/simulationtime.h"
#include "simulation/simulationtest.h"
#include "world/Track.h"
#include "world/station.h"
#include "input/keyboardinput.h"
@@ -767,7 +768,12 @@ void TController::TableCheck(double fDistance)
{ // aktualizacja rekordów z wyjątkiem ostatniego
if (sSpeedTable[i].iFlags & spEnabled) // jeśli pozycja istotna
{
if (sSpeedTable[i].Update())
auto const waspassed { TestFlag( sSpeedTable[ i ].iFlags, spElapsed ) };
auto const switchchanged { sSpeedTable[ i ].Update() };
if( false == waspassed ) {
CheckSignalPassedAtDanger( sSpeedTable[ i ] );
}
if (switchchanged)
{
if( Global.iWriteLogEnabled & 8 ) {
WriteLog( "Speed table for " + OwnerName() + " detected switch change at " + sSpeedTable[ i ].trTrack->name() + " (generating fresh trace)" );
@@ -816,7 +822,12 @@ void TController::TableCheck(double fDistance)
}
}
}
sSpeedTable[iLast].Update(); // aktualizacja ostatniego
// aktualizacja ostatniego; a signal at stop often is the last, the scan doesn't go past it
auto const lastwaspassed { TestFlag( sSpeedTable[ iLast ].iFlags, spElapsed ) };
sSpeedTable[iLast].Update();
if( false == lastwaspassed ) {
CheckSignalPassedAtDanger( sSpeedTable[ iLast ] );
}
// WriteLog("TableCheck: Upate last track. Dist=" + AnsiString(sSpeedTable[iLast].fDist));
if( sSpeedTable[ iLast ].fDist < fDistance ) {
TableTraceRoute( fDistance, pVehicles[ end::rear ] ); // doskanowanie dalszego odcinka
@@ -827,6 +838,20 @@ void TController::TableCheck(double fDistance)
}
};
void TController::CheckSignalPassedAtDanger( TSpeedPos const &Point ) const
{
if( false == TestFlag( Point.iFlags, spElapsed )
|| false == TestFlag( Point.iFlags, spEvent )
|| false == TestFlag( Point.iFlags, spSemaphor )
|| true == TestFlag( Point.iFlags, spStopOnSBL ) // SetVelocity 0 x on automatic block: may go on after a stop
|| Point.fVelNext != 0.0
|| Point.evEvent == nullptr
|| ( mvOccupied->CategoryFlag & 1 ) == 0 ) { // railway only
return;
}
simulation::Test.signal_passed_at_danger( OwnerName(), Point.evEvent->m_name );
}
auto const passengerstopmaxdistance { 400.0 }; // maximum allowed distance between passenger stop point and consist head
TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fNext, double &fAcc)