mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 03:37:09 +01:00
feat(derailment): a derailment is told to the scenery, the black box and the test mode
Every way a vehicle leaves the rails records what derailed it and its speed in the mover (DerailedBy, DerailVelocity), by any physics.derailment model and the collisions. After all vehicles moved, TDynamicObject::new_derailment() notices each derailment once, and state_manager::report_derailment() tells: - the log: "derailment: <vehicle> derailed (<cause>) on track <track> at <speed> km/h"; - a scenery that asked for it: its memory cell __simulation.derailment gets "<vehicle> <cause> <track>", the speed and the code of the cause, then its events __simulation.derailment and <vehicle>:derailed run with the vehicle as activator. Nothing is made at the start, so a scenery without them runs as before (no draw of the random numbers for a new node); - the black box: a derailment record with the new phase 2, for any model, and every derailment record gets the finer cause and the track at its end; - the test mode: test.fail_on_derailment yes (default no) ends the run of a tested train that derailed with the new result derailment, exit code 15; otherwise the verdict line ends with " [derailed: ...]". run.py knows exit code 15 and shows the derailment of the train under test in the summary. New cases eu07_td_buckle_derails_ends_test and eu07_td_off_track_end_scenery_told; the other 83 end as before and their physics logs are byte-identical to staging.
This commit is contained in:
@@ -11,6 +11,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "simulation/simulationtest.h"
|
||||
|
||||
#include "application/application.h"
|
||||
#include "McZapkie/derailment.h"
|
||||
#include "scene/scene.h"
|
||||
#include "simulation/simulation.h"
|
||||
#include "utilities/Globals.h"
|
||||
@@ -49,6 +50,16 @@ double elapsed_wall_time()
|
||||
|
||||
namespace simulation {
|
||||
|
||||
namespace {
|
||||
|
||||
// the limits of the settings, as they are now: the scenery may change them
|
||||
test_limits current_limits()
|
||||
{
|
||||
return test_limits { Global.test.timeout, Global.test.standstill, Global.test.pass_on_standstill, Global.test.no_movement_before_pass, Global.test.fail_on_derailment };
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
test_manager &test()
|
||||
{
|
||||
static test_manager instance;
|
||||
@@ -141,11 +152,12 @@ void test_manager::start()
|
||||
tested += " " + name;
|
||||
}
|
||||
auto const walllimit { m_walllimit.load() };
|
||||
WriteLog(std::format("test: started, testing {}, timeout {:.0f} s, real time limit {}, standstill {:.0f} s{}{}{}", tested, 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",
|
||||
Global.test.no_movement_before_pass ? "" : ", pass without waiting for a stop"));
|
||||
Global.test.no_movement_before_pass ? "" : ", pass without waiting for a stop",
|
||||
Global.test.fail_on_derailment ? ", a derailment fails" : ""));
|
||||
}
|
||||
|
||||
void test_manager::update(double const Deltatime)
|
||||
@@ -160,7 +172,7 @@ void test_manager::update(double const Deltatime)
|
||||
frame.reason = cell->Text();
|
||||
}
|
||||
|
||||
auto const limits { test_limits { Global.test.timeout, Global.test.standstill, Global.test.pass_on_standstill, Global.test.no_movement_before_pass } };
|
||||
auto const limits { current_limits() };
|
||||
std::optional<test_verdict> verdict;
|
||||
auto passrequested { false };
|
||||
{
|
||||
@@ -192,6 +204,38 @@ bool test_manager::tested_trains_at_rest() const
|
||||
});
|
||||
}
|
||||
|
||||
bool test_manager::tested(TDynamicObject const &Vehicle) const
|
||||
{
|
||||
if (Global.test.vehicles.empty())
|
||||
return true;
|
||||
return std::ranges::any_of(Global.test.vehicles, [&Vehicle](std::string const &Name) {
|
||||
auto *vehicle { simulation::Vehicles.find(Name) };
|
||||
return vehicle != nullptr && vehicle->find_vehicle(coupling::coupler, [&Vehicle](TDynamicObject const *Other) { return Other == &Vehicle; }) != nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
void test_manager::vehicle_derailed(TDynamicObject const &Vehicle, derailment::notice const &Notice)
|
||||
{
|
||||
if (false == Global.test.enabled || false == m_started || m_finished)
|
||||
return;
|
||||
auto const istested { tested(Vehicle) };
|
||||
auto const description { derailment::describe(Notice) };
|
||||
std::optional<test_verdict> verdict;
|
||||
double time { 0.0 };
|
||||
{
|
||||
std::scoped_lock lock { m_lock };
|
||||
verdict = evaluate_derailment(m_progress, istested, description, current_limits());
|
||||
time = m_progress.time;
|
||||
}
|
||||
if (verdict.has_value())
|
||||
{
|
||||
finish(verdict->result, verdict->reason);
|
||||
return;
|
||||
}
|
||||
if (istested)
|
||||
WriteLog(std::format("test: {} at {:.1f} s, allowed by test.fail_on_derailment", description, time));
|
||||
}
|
||||
|
||||
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) };
|
||||
@@ -222,7 +266,8 @@ bool test_manager::conclude(test_result const Result, std::string_view const Rea
|
||||
m_result = Result;
|
||||
m_finished = true;
|
||||
|
||||
auto const line { std::format("test: {} (exit code {}) after {:.1f} s of simulation time: {}", to_string(Result), static_cast<int>(Result), m_progress.time, Reason) };
|
||||
auto const line { std::format("test: {} (exit code {}) after {:.1f} s of simulation time: {}", to_string(Result), static_cast<int>(Result), m_progress.time,
|
||||
verdict_reason(test_verdict { Result, std::string(Reason) }, m_progress)) };
|
||||
if (Result == test_result::pass)
|
||||
WriteLog(line);
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user