18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 20:05:23 +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:
jerrrrycho
2026-11-29 05:29:37 +01:00
parent b7f2186a19
commit d6dba363e3
27 changed files with 666 additions and 13 deletions
+52 -1
View File
@@ -43,7 +43,8 @@ std::optional<simulation::test_verdict> run(simulation::test_progress &Progress,
TEST_CASE("test mode: the exit codes keep clear of the ones of a killed or aborted process")
{
std::array const results{test_result::pass, test_result::fail, test_result::signal_passed_at_danger, test_result::timeout, test_result::standstill, test_result::error};
std::array const results{test_result::pass, test_result::fail, test_result::signal_passed_at_danger, test_result::timeout, test_result::standstill, test_result::error,
test_result::derailment};
for (auto const result : results)
{
auto const code{static_cast<int>(result)};
@@ -60,6 +61,8 @@ TEST_CASE("test mode: the exit codes keep clear of the ones of a killed or abort
CHECK(static_cast<int>(test_result::timeout) == 12);
CHECK(static_cast<int>(test_result::standstill) == 13);
CHECK(static_cast<int>(test_result::error) == 14);
CHECK(static_cast<int>(test_result::derailment) == 15);
CHECK(simulation::to_string(test_result::derailment) == "derailment");
}
TEST_CASE("test mode: seconds on the command line are a number, not negative")
@@ -266,3 +269,51 @@ TEST_CASE("test mode: what ended a run the simulator didn't end")
CHECK(simulation::describe_exception(nullptr) == "the simulator was terminated");
}
}
TEST_CASE("test mode: a derailment")
{
simulation::test_limits limits;
simulation::test_progress progress;
auto const first{"autotest_x derailed (buckle) on track tdo_n222 at 46 km/h"};
auto const second{"autotest_x_w1 derailed (pulled_off) on track tdo_n222 at 31 km/h"};
SUBCASE("off by default: a tested train derailing doesn't end the test, the verdict tells it")
{
CHECK_FALSE(limits.fail_on_derailment);
CHECK_FALSE(simulation::evaluate_derailment(progress, true, first, limits).has_value());
CHECK(progress.derailments == 1);
auto const verdict{run(progress, limits, 4000.0, frame(false))};
REQUIRE(verdict.has_value());
CHECK(verdict->result == test_result::timeout);
CHECK(simulation::verdict_reason(*verdict, progress) == "no result after 3600 s [derailed: autotest_x derailed (buckle) on track tdo_n222 at 46 km/h]");
}
SUBCASE("the verdict counts the ones after the first")
{
simulation::evaluate_derailment(progress, true, first, limits);
simulation::evaluate_derailment(progress, true, second, limits);
simulation::evaluate_derailment(progress, true, second, limits);
CHECK(simulation::verdict_reason({test_result::pass, "__test.result set to 1 and the tested trains stopped"}, progress) ==
"__test.result set to 1 and the tested trains stopped [derailed: autotest_x derailed (buckle) on track tdo_n222 at 46 km/h, and 2 more]");
}
SUBCASE("test.fail_on_derailment ends the test at once, with the derailment as the reason")
{
limits.fail_on_derailment = true;
auto const verdict{simulation::evaluate_derailment(progress, true, first, limits)};
REQUIRE(verdict.has_value());
CHECK(verdict->result == test_result::derailment);
CHECK(verdict->reason == first);
CHECK(simulation::verdict_reason(*verdict, progress) == first);
}
SUBCASE("another train doesn't count, either way")
{
CHECK_FALSE(simulation::evaluate_derailment(progress, false, first, limits).has_value());
limits.fail_on_derailment = true;
CHECK_FALSE(simulation::evaluate_derailment(progress, false, first, limits).has_value());
CHECK(progress.derailments == 0);
CHECK(simulation::verdict_reason({test_result::timeout, "no result after 60 s"}, progress) == "no result after 60 s");
}
SUBCASE("a verdict without a derailment keeps its reason")
{
CHECK(simulation::verdict_reason({test_result::fail, "__test.result set to 0"}, progress) == "__test.result set to 0");
}
}