mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-19 08:46:00 +01:00
feat(simulation): the pass and the standstill wait for the train under test only
Both waited for every vehicle of the scenery to stand still, so on a scenery with AI traffic a test could pass only when the traffic happened to stand too, and the standstill end hardly ever came. A test scenery names the train under test with test.vehicle <name> in its config block (once for each train, if several): the pass and the standstill wait for the consists of these vehicles as they are at the moment, so a train the tested one couples to counts with it. A name the scenery doesn't have ends the test with the error code. Without test.vehicle every vehicle counts, as before. A signal passed at danger counts for every train either way. run.py puts the case's lead vehicle into test.vehicle. test_mode_standstill_traffic has the train under test standing on track 2 of Stacja1 while AI traffic leaves track 1 on the timetable: it ends on its 100 s standstill, where counting every vehicle runs into the 300 s timeout. Physicslogs of the other trains of a case (<something>_<vehicle>) are moved out of the game dir too.
This commit is contained in:
@@ -33,6 +33,11 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
namespace {
|
||||
|
||||
bool is_moving(TDynamicObject const *Vehicle)
|
||||
{
|
||||
return std::abs(Vehicle->GetVelocity()) > 0.01;
|
||||
}
|
||||
|
||||
// [s] of real time since the start of the simulator
|
||||
double elapsed_wall_time()
|
||||
{
|
||||
@@ -117,10 +122,25 @@ void test_manager::start()
|
||||
finish(test_result::error, "the scenery has no vehicles");
|
||||
return;
|
||||
}
|
||||
for (auto const &name : Global.test.vehicles)
|
||||
{
|
||||
if (simulation::Vehicles.find(name) == nullptr)
|
||||
{
|
||||
finish(test_result::error, std::format("the scenery has no vehicle {} (test.vehicle)", name));
|
||||
return;
|
||||
}
|
||||
}
|
||||
// a pause set by the scenery or the settings would never be lifted, nobody is there to press the key
|
||||
Global.iPause = 0;
|
||||
auto tested { std::string("every vehicle") };
|
||||
if (false == Global.test.vehicles.empty())
|
||||
{
|
||||
tested = "the consists of";
|
||||
for (auto const &name : Global.test.vehicles)
|
||||
tested += " " + name;
|
||||
}
|
||||
auto const walllimit { m_walllimit.load() };
|
||||
WriteLog(std::format("test: started, timeout {:.0f} s, real time limit {}, standstill {:.0f} s{}{}{}", Global.test.timeout,
|
||||
WriteLog(std::format("test: started, testing {}, timeout {:.0f} s, real time limit {}, standstill {:.0f} s{}{}{}", tested, Global.test.timeout,
|
||||
walllimit > 0.0 ? std::format("{:.0f} s", walllimit) : std::string("none"), Global.test.standstill,
|
||||
Global.test.pass_on_standstill ? ", standstill passes" : "",
|
||||
Global.test.fail_if_stop_overran ? "" : ", signals passed at danger allowed",
|
||||
@@ -132,8 +152,7 @@ void test_manager::update(double const Deltatime)
|
||||
if (false == m_started || m_finished)
|
||||
return;
|
||||
|
||||
test_frame frame { Deltatime, std::nullopt, {},
|
||||
std::ranges::none_of(simulation::Vehicles.sequence(), [](TDynamicObject const *Vehicle) { return std::abs(Vehicle->GetVelocity()) > 0.01; }) };
|
||||
test_frame frame { Deltatime, std::nullopt, {}, tested_trains_at_rest() };
|
||||
if (auto const *cell = simulation::Memory.find(std::string(result_cell)))
|
||||
{
|
||||
frame.reported = cell->Value1();
|
||||
@@ -156,11 +175,22 @@ void test_manager::update(double const Deltatime)
|
||||
}
|
||||
if (passrequested)
|
||||
{
|
||||
WriteLog(std::format("test: pass requested at {:.1f} s{}, waiting for every vehicle to stop", m_progress.time,
|
||||
WriteLog(std::format("test: pass requested at {:.1f} s{}, waiting for the tested trains to stop", m_progress.time,
|
||||
frame.reason.empty() ? std::string() : std::format(" ({})", frame.reason)));
|
||||
}
|
||||
}
|
||||
|
||||
bool test_manager::tested_trains_at_rest() const
|
||||
{
|
||||
if (Global.test.vehicles.empty())
|
||||
return std::ranges::none_of(simulation::Vehicles.sequence(), is_moving);
|
||||
// the consists as they are now: a train the tested one couples to joins it, one it leaves behind doesn't
|
||||
return std::ranges::none_of(Global.test.vehicles, [](std::string const &Name) {
|
||||
auto *vehicle { simulation::Vehicles.find(Name) };
|
||||
return vehicle != nullptr && vehicle->find_vehicle(coupling::coupler, is_moving) != nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
void test_manager::signal_passed_at_danger(std::string_view const Vehicle, std::string_view const Signal)
|
||||
{
|
||||
auto const reason { std::format("{} passed signal {} at danger", Vehicle, Signal) };
|
||||
|
||||
@@ -52,6 +52,8 @@ public:
|
||||
private:
|
||||
// the watchdog's check, at Elapsed seconds of real time since the start of the simulator
|
||||
void check_wall_clock(double Elapsed);
|
||||
// every vehicle of the tested trains stands: the consists of test.vehicle, or every vehicle without it
|
||||
bool tested_trains_at_rest() const;
|
||||
|
||||
// the watchdog may end the test from its own thread
|
||||
mutable std::mutex m_lock;
|
||||
|
||||
@@ -138,9 +138,9 @@ std::optional<test_verdict> evaluate_frame(test_progress &Progress, test_frame c
|
||||
Progress.resttime = Frame.atrest ? Progress.resttime + Frame.deltatime : 0.0;
|
||||
|
||||
if (Progress.passrequested && Progress.resttime >= pass_settle_time)
|
||||
return test_verdict{pass, "__test.result set to 1 and every vehicle stopped"};
|
||||
return test_verdict{pass, "__test.result set to 1 and the tested trains stopped"};
|
||||
if (Limits.standstill > 0.0 && Progress.resttime >= Limits.standstill)
|
||||
return test_verdict{Limits.pass_on_standstill ? pass : standstill, std::format("every vehicle stood still for {:.0f} s", Limits.standstill)};
|
||||
return test_verdict{Limits.pass_on_standstill ? pass : standstill, std::format("the tested trains stood still for {:.0f} s", Limits.standstill)};
|
||||
if (Limits.timeout > 0.0 && Progress.time >= Limits.timeout)
|
||||
return test_verdict{timeout, std::format("no result after {:.0f} s", Limits.timeout)};
|
||||
return std::nullopt;
|
||||
|
||||
@@ -22,11 +22,11 @@ namespace simulation {
|
||||
// when it goes wrong on its own: 1 (killed with TerminateProcess, or a plain failure of most programs), 3 (abort()
|
||||
// on Windows), 126-127 (a shell that can't run the program) or 128 + a signal number (killed, on Linux)
|
||||
enum class test_result : int {
|
||||
pass = 0, // __test.result set to 1, then every vehicle came to rest (or test.pass_on_standstill)
|
||||
pass = 0, // __test.result set to 1, then the tested trains came to rest (or test.pass_on_standstill)
|
||||
fail = 10, // __test.result set to 0
|
||||
signal_passed_at_danger = 11, // a train went past a stop signal (SetVelocity 0 0), unless test.fail_if_stop_overran no
|
||||
timeout = 12, // test.timeout seconds of simulation time, or test.wall_timeout seconds of real time went by
|
||||
standstill = 13, // every vehicle stood still for test.standstill seconds without a result
|
||||
standstill = 13, // the tested trains stood still for test.standstill seconds without a result
|
||||
error = 14, // the run could not start (a bad command line, the scenery failed to load) or the simulator threw
|
||||
};
|
||||
|
||||
@@ -64,7 +64,7 @@ double wall_clock_limit(std::optional<double> Given, double Simulationtimeout);
|
||||
// the limits and switches the end conditions go by
|
||||
struct test_limits {
|
||||
double timeout{3600.0}; // [s] of simulation time; 0 = never
|
||||
double standstill{300.0}; // [s] of every vehicle standing without a result; 0 = never
|
||||
double standstill{300.0}; // [s] of the tested trains standing without a result; 0 = never
|
||||
bool pass_on_standstill{false};
|
||||
bool no_movement_before_pass{true};
|
||||
};
|
||||
@@ -74,17 +74,17 @@ struct test_frame {
|
||||
double deltatime{0.0}; // [s] of simulation time
|
||||
std::optional<double> reported; // value of the result cell, if there is one
|
||||
std::string_view reason; // text of the result cell
|
||||
bool atrest{false}; // every vehicle stands
|
||||
bool atrest{false}; // every vehicle of the tested trains stands (test.vehicle; every vehicle without it)
|
||||
};
|
||||
|
||||
// the state of a test between frames
|
||||
struct test_progress {
|
||||
double time{0.0}; // simulation time since the start [s]
|
||||
double resttime{0.0}; // how long every vehicle has been standing [s]
|
||||
bool passrequested{false}; // __test.result was set to 1, the pass waits for the vehicles to stop
|
||||
double resttime{0.0}; // how long the tested trains have been standing [s]
|
||||
bool passrequested{false}; // __test.result was set to 1, the pass waits for the tested trains to stop
|
||||
};
|
||||
|
||||
// how long everything has to stand before a requested pass is granted [s]
|
||||
// how long the tested trains have to stand before a requested pass is granted [s]
|
||||
inline constexpr double pass_settle_time{1.0};
|
||||
|
||||
// checks the end conditions after a frame and moves the progress on. returns the verdict once the test is over
|
||||
|
||||
Reference in New Issue
Block a user