mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-27 21:45:16 +01:00
test(scenarios): AI through a section without voltage and with interlocked line contactors (#272, #276) (#467)
* test(scenarios): AI through a section without voltage and with interlocked line contactors Scenario cases for the parts of #272 (line breaker ahead of the pantographs, PantRequiresMain) and #276 (line contactors interlocked with the vehicle's own converter, LineContactorsInterlock) that had not been run in the simulator before. They all run the AI on the timetable run of td.scn. - ep05_td_dead_section: an EP05 runs under power into a 61 m span of overhead wire that has no voltage. Its line breaker stays closed, the traction force drops to 0, and behind the span the AI takes power again and stops at Przystanek. eu07_td_dead_section is the same run with an EU07, as a reference for the old behaviour: its line breaker opens after 0.2 s and the AI closes it again. - ep05_td_neutral_section: the same span, with the track under it marked overhead 0. The AI coasts from before the dead wire. - ep05_td_section_insulator: a 1 m section insulator, run under power. The 0.2 s voltage hold keeps the traction force up past it. - et42_td_converter_interlock(_cold): an ET42 with the interlock starts up and runs its timetable. - ep05_td_interlock_dead_section_cold: both keys on one EP05, starting cold, with the dead span on its way. - ep05_td_timetable: the plain timetable run of the EP05, as a reference. The runner gets vehicle_variants, a vehicle of the case's own made from one of the game's with .fiz replacements. The game's ET42 data doesn't have the interlock key yet. The runner also gets two new checks: traction (the traction force between two distances travelled) and master_controller. The local converter switch of #276 can't be covered: only the cab can set it, and in test mode nobody sits in a cab. * test(scenarios): the ET42 interlock case that fails without the interlock The ET42 interlock cases checked only that the AI gets the train going, which a plain ET42 does too. A case with a converter that starts 60 s after it is switched on shows the interlock taking effect: the train reaches 20 km/h at 80.0 s with it and at 73.8 s without it, and the starts check gets an optional lower bound, after, to fail the early one. The runner also checks the case's expect and --watch before it writes anything into the game folder, and builds the scenery inside the try that removes the case's files, so an exit or Ctrl+C there leaves none.
This commit is contained in:
@@ -215,6 +215,7 @@ to `logs/`.
|
||||
| `fragment` | `.scn` file in `cases/` added to the scenery: trainsets after `FirstInit` (before it they derail on unlinked track), the rest before it (launchers read after it never fire). Optional when the case keeps the scenery's trainsets |
|
||||
| `vars` | values for `{{name}}` in the fragment; a list becomes one line per item |
|
||||
| `timetable` | a timetable file in `cases/` for a trainset of the fragment, for a train whose timetable no scenery of the game has: copied to the game's `scenery/` dir as `autotest_<case>.txt` for the run and removed after it; the fragment names it `{{timetable}}` |
|
||||
| `vehicle_variants` | vehicles of the case's own, made from those of the game, e.g. with a `.fiz` key the game's data doesn't have yet: a list of `{ "name": ..., "from": "<dir>/<type>", "replace": [[old, new], ...] }`. For the run the vehicle's `.fiz`, with the literal replacements (an `old` it doesn't have is an error), and its `.mmd` are copied beside it in the game's `dynamic/` dir as `autotest_<case>_<name>` and removed after it; the fragment names the type `{{variant_<name>}}`, e.g. `dynamic pkp/et42_v2 112e-014-a {{variant_a}} ...`. The copy of the `.mmd` has the name of the vehicle it is made from in place of `(p2)`, the type name the simulator hands it, which some pass on to the include that names the model |
|
||||
| `expect` | the result the test mode should end with: `pass`, `fail`, `signal_passed_at_danger`, `timeout`, `standstill` or `error`, or `wall_timeout` for the timeout of the real time watchdog (the timeout code with a verdict saying it was the real time; a case expecting `timeout` fails on it). Default `timeout` for a case with `duration`, else `pass` |
|
||||
| `duration` | seconds of simulation to record: the test timeout of the run (`--test-timeout`) |
|
||||
| `timeout` | wall-clock seconds before giving up, loading included: the simulator's `--test-wall-timeout` (default 600) |
|
||||
@@ -396,6 +397,57 @@ working it stops at 0.57 m/s², 99 m: that is `eu07_td_reinspect_brakes_legacy_i
|
||||
of the earlier releases (`ai.brakesetting.cw1 no`), which cuts no brake out, and also what a build whose
|
||||
`reinspect_brakes()` does nothing gives for the first case, which then fails. The test passes 150 s after the driver goes.
|
||||
|
||||
The `*_section*` and `*_converter_interlock*` cases are about the line breaker closed ahead of the pantographs
|
||||
(`PantRequiresMain=Yes` in `Cntrl.`, MaSzyna-EU07/maszyna#272) and the line contactors that wait for the
|
||||
converter of their own vehicle (`LineContactorsInterlock=Converter`, #276), driven by the AI on the timetable
|
||||
run of td.scn. The overhead wire of td.scn is changed with `replace`: one span of it, 61 m some 400 m from
|
||||
the start (`0.7764 5.845 1561.2417` onwards, over the way out of Stacja1, which the train runs under power at
|
||||
50-55 km/h), gets no supply and 0 V (`traction none 0`), and in `ep05_td_section_insulator` the span before
|
||||
it is split around a section insulator 1 m long (`traction * 0`, as sceneries hang insulators). The EP05 has
|
||||
`PantRequiresMain=Yes` in the game's data; the ET42 has no `LineContactorsInterlock` yet (SVN data of #276),
|
||||
so those cases run variants of the vehicles made for the run (`vehicle_variants`).
|
||||
|
||||
- `ep05_td_timetable`: the EP05 on the plain timetable run, the reference: 20 km/h after 73 s, the stop
|
||||
after 205 s and 1400 m.
|
||||
- `ep05_td_dead_section`: the EP05 runs into the span without voltage under power, nothing on the track
|
||||
telling its driver to coast. The traction force drops to nothing at once and the AI puts the master
|
||||
controller to 0; the line breaker stays closed (the log
|
||||
says the vehicle lost power for 4.05 s, which it says only while the line breaker is closed). Behind the
|
||||
section the AI takes power again (535 m, 36 kN by 595 m) and stops at Przystanek (1399 m).
|
||||
- `ep05_td_neutral_section`: the same with the track under that span, `koniec`, marked as one to coast
|
||||
through (`overhead 0`, which `track_events` adds as it adds events): the AI puts the master controller to
|
||||
0 as the locomotive runs onto it, 25 m ahead of the dead wire, and takes power again behind it.
|
||||
- `eu07_td_dead_section`: the old behaviour for reference, an EU07 (pantographs first) into the same span:
|
||||
its line breaker opens after 0.2 s (`lost power for 0.21 sec`, no longer), and behind the section the AI
|
||||
closes it again and takes power (493 m).
|
||||
- `ep05_td_section_insulator`: the EP05 runs under the insulator under power at 50 km/h. The pantograph is
|
||||
without voltage for some 0.07 s, which the vehicle bridges by holding the last voltage for 0.2 s
|
||||
(`TDynamicObject::Update`): the traction force stays between 50 and 58 kN past it and nothing is logged.
|
||||
Without the hold the undervoltage relay of a `PantRequiresMain` vehicle would open the line contactors,
|
||||
which close again only with the master controller back at its first position. With the insulator 15 m long
|
||||
instead (a trial run) the vehicle does lose power there (logged, the force drops to 0), which shows the
|
||||
pantograph runs under the piece of wire.
|
||||
- `et42_td_converter_interlock_cold`: an ET42 with `LineContactorsInterlock=Converter` in both sections
|
||||
stands cold (`td_cold_timetable.scn`) and is ordered to run the timetable: the AI starts the converters,
|
||||
leaves (20 km/h after 74 s) and stops at Przystanek (1393 m). It and `et42_td_converter_interlock`, the
|
||||
same from the timetable start, check that the AI gets such a train going; a plain ET42 passes them too.
|
||||
- `et42_td_converter_interlock_slow_converter`: the check that the interlock takes effect. The same cold ET42
|
||||
with a converter that starts 60 s after it is switched on (`ConverterStartDelay=60`): the line contactors
|
||||
wait for it, and the train reaches 20 km/h at 80.0 s; `starts` with `after: 77` fails it earlier. With the
|
||||
same converter and no interlock it gets there at 73.8 s, as fast as without the slow converter (a copy of
|
||||
the case without the key, run once, not kept).
|
||||
- `ep05_td_interlock_dead_section_cold`: #272 and #276 together, an EP05 with `LineContactorsInterlock=Converter`
|
||||
added, standing cold, with the span without voltage on its way: the pantographs can go up only through the
|
||||
closed line breaker, so the AI has to close it first, then start the converter; it leaves (20 km/h after
|
||||
77 s). Under the dead wire the converter stops with the main circuit, behind it the converter starts again
|
||||
and the AI takes power (573 m, 4 s later than the EP05 without the interlock) and stops at Przystanek
|
||||
(1393 m).
|
||||
|
||||
What these can't reach: the local converter switch of the ET42 (`converterlocal_sw:`), which the AI has to put
|
||||
back on (`LineContactorsHeldByLocalConverterSwitch()`, the part of #276 in `determine_consist_state()` and
|
||||
the `converteron` hint), is in the cab only: no command of a scenery or of the train's cables sets
|
||||
`ConverterAllowLocal`, and nobody sits in a cab in the test mode, so the switch is always on in a case.
|
||||
|
||||
### Cases on a mission of a scenery
|
||||
|
||||
The cases made from players' reports (eu07/maszyna#421, #506, #524, #525) run a whole mission
|
||||
@@ -450,7 +502,8 @@ the physicslog Velocity column, which is the wheel speed: it stays at 0 while th
|
||||
locked in a skid. The ones marked *vehicle speed* use the vehicle speed column at the end of
|
||||
the row instead, logged by builds from this branch on.
|
||||
|
||||
- `starts` `min_speed`, `within`: reaches `min_speed` within `within` seconds.
|
||||
- `starts` `min_speed`, `within` (`after`): reaches `min_speed` within `within` seconds (and not before `after` seconds,
|
||||
when given).
|
||||
- `max_speed` `limit`, `tolerance`: never goes faster than `limit + tolerance`.
|
||||
- `brakes` `min_pressure`: after moving off, brake cylinder pressure reaches `min_pressure` bar
|
||||
(physicslog pressures are in bar whatever its header says; the brake pipe runs at 5.0).
|
||||
@@ -497,6 +550,13 @@ the row instead, logged by builds from this branch on.
|
||||
cut out stops slower.
|
||||
- `moves` `vehicle`, `min_speed`, optional `direction` (`front`, or `rear`): the black box has the
|
||||
vehicle reach `min_speed` with that end leading (the physicslog speed has no direction).
|
||||
- `traction` `from_distance`, `to_distance`, and one or more of `reaches`, `at_most`, `at_least`: the
|
||||
traction force in kN (the physicslog has it in N, whatever its header says) while the vehicle runs between
|
||||
the two distances (metres travelled, as in `distance`): its highest there reaches `reaches`, e.g. the power
|
||||
taken again behind a section without voltage; it stays at or below `at_most`, e.g. none under a dead wire;
|
||||
it stays at or above `at_least`, e.g. no power lost under an insulator.
|
||||
- `master_controller` `from_distance`, `to_distance`, `at_most`: the master controller stays at or below the
|
||||
position between the two distances, e.g. at 0 where the scenery tells the driver to coast.
|
||||
|
||||
New check types go in `CHECKS` in `run.py`; each gets the physicslog rows and the check's
|
||||
parameters and returns `(passed, detail)`. Checks on the log go in `LOG_CHECKS` and get the
|
||||
|
||||
22
tests/scenarios/cases/ep05_td_dead_section.json
Normal file
22
tests/scenarios/cases/ep05_td_dead_section.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"description": "#272: an EP05 (PantRequiresMain=Yes: its line breaker closes ahead of the pantographs and holds without voltage) runs the td/rozklad timetable of td.scn with one span of the overhead wire on its way, 61 m some 400 m from the start, left without voltage, and nothing on the track to tell the driver to coast. The AI runs into it under power: the line breaker stays closed (the log keeps saying the vehicle lost power, which it says only while the line breaker is closed), the traction force drops to nothing and the AI puts the master controller to 0; behind the section the AI takes power again and stops at Przystanek.",
|
||||
"base_scenery": "td.scn",
|
||||
"time": "10:34",
|
||||
"fragment": "td_timetable.scn",
|
||||
"vars": {
|
||||
"consist": "node -1 0 {{vehicle}} dynamic pkp/ep05_v2 ep05-23 ep05 0 headdriver 0 0 enddynamic"
|
||||
},
|
||||
"replace": [
|
||||
["node -1 0 none traction pwr01 3500 4500 0.01 cu 3.0 1\r\n0.7764 5.845 1561.2417", "node -1 0 none traction none 0 4500 0.01 cu 3.0 1\r\n0.7764 5.845 1561.2417"]
|
||||
],
|
||||
"duration": 240,
|
||||
"timeout": 600,
|
||||
"checks": [
|
||||
{"type": "starts", "min_speed": 20, "within": 150},
|
||||
{"type": "max_speed", "limit": 90, "tolerance": 3},
|
||||
{"type": "traction", "from_distance": 420, "to_distance": 455, "at_most": 1},
|
||||
{"type": "traction", "from_distance": 460, "to_distance": 620, "reaches": 25},
|
||||
{"type": "log_contains", "pattern": "lost power for [3-9]\\.\\d\\d sec"},
|
||||
{"type": "stops", "moving_speed": 20, "stop_speed": 1.0, "hold": 0, "min_distance": 1380, "max_distance": 1420}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"description": "#272 with #276: an EP05 whose line breaker closes ahead of the pantographs (PantRequiresMain=Yes) and whose line contactors close only with its own converter running (LineContactorsInterlock=Converter, a variant of the .fiz made for the run) stands cold on track 1 of Stacja1 and gets the order to run the td/rozklad timetable, with the span without voltage of ep05_td_dead_section on its way. The pantographs go up only through the closed line breaker, so the AI has to close it first, then start the converter, and leave; under the dead wire the main circuit, and with it the converter, has no voltage; behind it the AI takes power again and stops at Przystanek.",
|
||||
"base_scenery": "td.scn",
|
||||
"time": "10:34",
|
||||
"fragment": "td_cold_timetable.scn",
|
||||
"vars": {
|
||||
"consist": "node -1 0 {{vehicle}} dynamic pkp/ep05_v2 ep05-23 {{variant_ep05}} 0 headdriver 0 0 enddynamic"
|
||||
},
|
||||
"vehicle_variants": [
|
||||
{"name": "ep05", "from": "pkp/ep05_v2/ep05", "replace": [["Camshaft=Yes PantRequiresMain=Yes", "Camshaft=Yes PantRequiresMain=Yes LineContactorsInterlock=Converter"]]}
|
||||
],
|
||||
"replace": [
|
||||
["node -1 0 none traction pwr01 3500 4500 0.01 cu 3.0 1\r\n0.7764 5.845 1561.2417", "node -1 0 none traction none 0 4500 0.01 cu 3.0 1\r\n0.7764 5.845 1561.2417"]
|
||||
],
|
||||
"track_events": {
|
||||
"tdo_n1734": "event0 autotest_wake"
|
||||
},
|
||||
"duration": 300,
|
||||
"timeout": 600,
|
||||
"checks": [
|
||||
{"type": "starts", "min_speed": 20, "within": 150},
|
||||
{"type": "max_speed", "limit": 90, "tolerance": 3},
|
||||
{"type": "traction", "from_distance": 420, "to_distance": 455, "at_most": 1},
|
||||
{"type": "traction", "from_distance": 460, "to_distance": 620, "reaches": 25},
|
||||
{"type": "log_contains", "pattern": "lost power for [3-9]\\.\\d\\d sec"},
|
||||
{"type": "stops", "moving_speed": 20, "stop_speed": 1.0, "hold": 0, "min_distance": 1380, "max_distance": 1420}
|
||||
]
|
||||
}
|
||||
26
tests/scenarios/cases/ep05_td_neutral_section.json
Normal file
26
tests/scenarios/cases/ep05_td_neutral_section.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"description": "#272: as ep05_td_dead_section, with the track under the span without voltage (koniec, 371-466 m) marked as a section to coast through (overhead 0), as a scenery marks a neutral section: the AI puts the master controller to zero when the locomotive runs onto that track, coasts under the dead wire with the line breaker closed, and takes power again behind it.",
|
||||
"base_scenery": "td.scn",
|
||||
"time": "10:34",
|
||||
"fragment": "td_timetable.scn",
|
||||
"vars": {
|
||||
"consist": "node -1 0 {{vehicle}} dynamic pkp/ep05_v2 ep05-23 ep05 0 headdriver 0 0 enddynamic"
|
||||
},
|
||||
"replace": [
|
||||
["node -1 0 none traction pwr01 3500 4500 0.01 cu 3.0 1\r\n0.7764 5.845 1561.2417", "node -1 0 none traction none 0 4500 0.01 cu 3.0 1\r\n0.7764 5.845 1561.2417"]
|
||||
],
|
||||
"track_events": {
|
||||
"koniec": "overhead 0"
|
||||
},
|
||||
"duration": 240,
|
||||
"timeout": 600,
|
||||
"checks": [
|
||||
{"type": "starts", "min_speed": 20, "within": 150},
|
||||
{"type": "max_speed", "limit": 90, "tolerance": 3},
|
||||
{"type": "master_controller", "from_distance": 395, "to_distance": 455, "at_most": 0},
|
||||
{"type": "traction", "from_distance": 415, "to_distance": 455, "at_most": 1},
|
||||
{"type": "traction", "from_distance": 470, "to_distance": 640, "reaches": 25},
|
||||
{"type": "log_contains", "pattern": "lost power for [3-9]\\.\\d\\d sec"},
|
||||
{"type": "stops", "moving_speed": 20, "stop_speed": 1.0, "hold": 0, "min_distance": 1380, "max_distance": 1420}
|
||||
]
|
||||
}
|
||||
21
tests/scenarios/cases/ep05_td_section_insulator.json
Normal file
21
tests/scenarios/cases/ep05_td_section_insulator.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"description": "#272: the EP05 of ep05_td_timetable runs under power under a section insulator: a piece of the overhead wire 1 m long with no supply (\"*\", 0 V), some 375 m from the start. The pantograph is without voltage for a few hundredths of a second, which the vehicle bridges by holding the last voltage for 0.2 s (TDynamicObject::Update). Without the hold the undervoltage relay would open the line contactors, which on a PantRequiresMain vehicle close again only with the master controller back at its first position: the traction force stays up all the way past the insulator.",
|
||||
"base_scenery": "td.scn",
|
||||
"time": "10:34",
|
||||
"fragment": "td_timetable.scn",
|
||||
"vars": {
|
||||
"consist": "node -1 0 {{vehicle}} dynamic pkp/ep05_v2 ep05-23 ep05 0 headdriver 0 0 enddynamic"
|
||||
},
|
||||
"replace": [
|
||||
["node -1 0 none traction pwr01 3500 4500 0.01 cu 3.0 1\r\n0.687223 5.8 1500.25\r\n0.7764 5.845 1561.2417\r\n0.687223 7.5 1500.25\r\n0.7764 7.545 1561.2417\r\n0.4 4.0 3 0.04 vis\r\nendtraction", "node -1 0 none traction pwr01 3500 4500 0.01 cu 3.0 1\r\n0.687223 5.8 1500.25\r\n0.7457 5.8295 1540.2499\r\n0.687223 7.5 1500.25\r\n0.7457 7.5295 1540.2499\r\n0.4 4.0 3 0.04 vis\r\nendtraction\r\nnode -1 0 none traction * 0 4500 0.01 cu 3.0 1\r\n0.7457 5.8295 1540.2499\r\n0.7472 5.8302 1541.2499\r\n0.7457 7.5295 1540.2499\r\n0.7472 7.5302 1541.2499\r\n0.4 4.0 3 0.04 vis\r\nendtraction\r\nnode -1 0 none traction pwr01 3500 4500 0.01 cu 3.0 1\r\n0.7472 5.8302 1541.2499\r\n0.7764 5.845 1561.2417\r\n0.7472 7.5302 1541.2499\r\n0.7764 7.545 1561.2417\r\n0.4 4.0 3 0.04 vis\r\nendtraction"]
|
||||
],
|
||||
"duration": 240,
|
||||
"timeout": 600,
|
||||
"checks": [
|
||||
{"type": "starts", "min_speed": 20, "within": 150},
|
||||
{"type": "max_speed", "limit": 90, "tolerance": 3},
|
||||
{"type": "traction", "from_distance": 345, "to_distance": 395, "at_least": 30},
|
||||
{"type": "log_lacks", "pattern": "lost power"},
|
||||
{"type": "stops", "moving_speed": 20, "stop_speed": 1.0, "hold": 0, "min_distance": 1380, "max_distance": 1420}
|
||||
]
|
||||
}
|
||||
17
tests/scenarios/cases/ep05_td_timetable.json
Normal file
17
tests/scenarios/cases/ep05_td_timetable.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"description": "EP05 (PantRequiresMain=Yes) on td.scn, AI driver on the td/rozklad timetable: starts from Stacja1, keeps to the speed limit, brakes to a stop at Przystanek. The reference run of the ep05_td_*_section cases, with the overhead wire live all the way.",
|
||||
"base_scenery": "td.scn",
|
||||
"time": "10:34",
|
||||
"fragment": "td_timetable.scn",
|
||||
"vars": {
|
||||
"consist": "node -1 0 {{vehicle}} dynamic pkp/ep05_v2 ep05-23 ep05 0 headdriver 0 0 enddynamic"
|
||||
},
|
||||
"duration": 240,
|
||||
"timeout": 600,
|
||||
"checks": [
|
||||
{"type": "starts", "min_speed": 20, "within": 150},
|
||||
{"type": "max_speed", "limit": 90, "tolerance": 3},
|
||||
{"type": "brakes", "min_pressure": 0.5},
|
||||
{"type": "stops", "moving_speed": 20, "stop_speed": 1.0, "hold": 0, "min_distance": 1380, "max_distance": 1420}
|
||||
]
|
||||
}
|
||||
24
tests/scenarios/cases/et42_td_converter_interlock.json
Normal file
24
tests/scenarios/cases/et42_td_converter_interlock.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"description": "#276: as et42_td_converter_interlock_cold, from the timetable start (trainset velocity 0.1, the locomotive ready to go).",
|
||||
"base_scenery": "td.scn",
|
||||
"time": "10:34",
|
||||
"fragment": "td_timetable.scn",
|
||||
"vars": {
|
||||
"consist": [
|
||||
"node -1 0 {{vehicle}} dynamic pkp/et42_v2 112e-014-a {{variant_a}} 0 headdriver 255 0 enddynamic",
|
||||
"node -1 0 {{vehicle}}_b dynamic pkp/et42_v2 112e-014-b {{variant_b}} 0 nobody 3 0 enddynamic"
|
||||
]
|
||||
},
|
||||
"vehicle_variants": [
|
||||
{"name": "a", "from": "pkp/et42_v2/112e-a", "replace": [["IniCDelay=0.5 SCDelay=0.1", "IniCDelay=0.5 SCDelay=0.1 LineContactorsInterlock=Converter"]]},
|
||||
{"name": "b", "from": "pkp/et42_v2/112e-b", "replace": [["IniCDelay=0.5 SCDelay=0.1", "IniCDelay=0.5 SCDelay=0.1 LineContactorsInterlock=Converter"]]}
|
||||
],
|
||||
"duration": 240,
|
||||
"timeout": 600,
|
||||
"checks": [
|
||||
{"type": "starts", "min_speed": 20, "within": 150},
|
||||
{"type": "max_speed", "limit": 90, "tolerance": 3},
|
||||
{"type": "brakes", "min_pressure": 0.5},
|
||||
{"type": "stops", "moving_speed": 20, "stop_speed": 1.0, "hold": 0, "min_distance": 1380, "max_distance": 1420}
|
||||
]
|
||||
}
|
||||
27
tests/scenarios/cases/et42_td_converter_interlock_cold.json
Normal file
27
tests/scenarios/cases/et42_td_converter_interlock_cold.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"description": "#276: an ET42 whose sections take power only with their own converter running (LineContactorsInterlock=Converter in Cntrl., the .fiz key the shipped et42_v2 doesn't have yet: a variant of both sections made for the run) stands cold on track 1 of Stacja1 on td.scn and gets the order to run the td/rozklad timetable. The AI has to start the converters before the line contactors close: it leaves, keeps to the speed limit and stops at Przystanek.",
|
||||
"base_scenery": "td.scn",
|
||||
"time": "10:34",
|
||||
"fragment": "td_cold_timetable.scn",
|
||||
"vars": {
|
||||
"consist": [
|
||||
"node -1 0 {{vehicle}} dynamic pkp/et42_v2 112e-014-a {{variant_a}} 0 headdriver 255 0 enddynamic",
|
||||
"node -1 0 {{vehicle}}_b dynamic pkp/et42_v2 112e-014-b {{variant_b}} 0 nobody 3 0 enddynamic"
|
||||
]
|
||||
},
|
||||
"vehicle_variants": [
|
||||
{"name": "a", "from": "pkp/et42_v2/112e-a", "replace": [["IniCDelay=0.5 SCDelay=0.1", "IniCDelay=0.5 SCDelay=0.1 LineContactorsInterlock=Converter"]]},
|
||||
{"name": "b", "from": "pkp/et42_v2/112e-b", "replace": [["IniCDelay=0.5 SCDelay=0.1", "IniCDelay=0.5 SCDelay=0.1 LineContactorsInterlock=Converter"]]}
|
||||
],
|
||||
"track_events": {
|
||||
"tdo_n1734": "event0 autotest_wake"
|
||||
},
|
||||
"duration": 300,
|
||||
"timeout": 600,
|
||||
"checks": [
|
||||
{"type": "starts", "min_speed": 20, "within": 150},
|
||||
{"type": "max_speed", "limit": 90, "tolerance": 3},
|
||||
{"type": "brakes", "min_pressure": 0.5},
|
||||
{"type": "stops", "moving_speed": 20, "stop_speed": 1.0, "hold": 0, "min_distance": 1380, "max_distance": 1420}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"description": "#276, the check that the interlock takes effect: the ET42 of et42_td_converter_interlock_cold, with ConverterStartDelay=60 added to both sections, so the converters need a minute to start. With LineContactorsInterlock=Converter the line contactors wait for them and the train leaves later than it does with the same converter delay and no interlock (20 km/h at 80.0 s with it, at 73.8 s without it, measured with this case and a copy without the interlock key). Then it runs the timetable to Przystanek.",
|
||||
"base_scenery": "td.scn",
|
||||
"time": "10:34",
|
||||
"fragment": "td_cold_timetable.scn",
|
||||
"vars": {
|
||||
"consist": [
|
||||
"node -1 0 {{vehicle}} dynamic pkp/et42_v2 112e-014-a {{variant_a}} 0 headdriver 255 0 enddynamic",
|
||||
"node -1 0 {{vehicle}}_b dynamic pkp/et42_v2 112e-014-b {{variant_b}} 0 nobody 3 0 enddynamic"
|
||||
]
|
||||
},
|
||||
"vehicle_variants": [
|
||||
{"name": "a", "from": "pkp/et42_v2/112e-a", "replace": [["IniCDelay=0.5 SCDelay=0.1", "IniCDelay=0.5 SCDelay=0.1 LineContactorsInterlock=Converter ConverterStartDelay=60"]]},
|
||||
{"name": "b", "from": "pkp/et42_v2/112e-b", "replace": [["IniCDelay=0.5 SCDelay=0.1", "IniCDelay=0.5 SCDelay=0.1 LineContactorsInterlock=Converter ConverterStartDelay=60"]]}
|
||||
],
|
||||
"track_events": {
|
||||
"tdo_n1734": "event0 autotest_wake"
|
||||
},
|
||||
"duration": 300,
|
||||
"timeout": 600,
|
||||
"checks": [
|
||||
{"type": "starts", "min_speed": 20, "after": 77, "within": 150},
|
||||
{"type": "max_speed", "limit": 90, "tolerance": 3},
|
||||
{"type": "brakes", "min_pressure": 0.5},
|
||||
{"type": "stops", "moving_speed": 20, "stop_speed": 1, "hold": 0, "min_distance": 1380, "max_distance": 1420}
|
||||
]
|
||||
}
|
||||
22
tests/scenarios/cases/eu07_td_dead_section.json
Normal file
22
tests/scenarios/cases/eu07_td_dead_section.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"description": "The reference of ep05_td_dead_section: an EU07, whose pantographs come first and whose line breaker opens without voltage (no PantRequiresMain), runs into the same span without voltage under power. Its line breaker opens 0.2 s into the section (the log says it lost power for 0.2x s, no longer: it says so only while the line breaker is closed), and behind it the AI closes the line breaker again, takes power and stops at Przystanek.",
|
||||
"base_scenery": "td.scn",
|
||||
"time": "10:34",
|
||||
"fragment": "td_timetable.scn",
|
||||
"vars": {
|
||||
"consist": "node -1 0 {{vehicle}} dynamic pkp/4e_v1 4e-004 4e 0 headdriver 0 0 enddynamic"
|
||||
},
|
||||
"replace": [
|
||||
["node -1 0 none traction pwr01 3500 4500 0.01 cu 3.0 1\r\n0.7764 5.845 1561.2417", "node -1 0 none traction none 0 4500 0.01 cu 3.0 1\r\n0.7764 5.845 1561.2417"]
|
||||
],
|
||||
"duration": 240,
|
||||
"timeout": 600,
|
||||
"checks": [
|
||||
{"type": "starts", "min_speed": 20, "within": 150},
|
||||
{"type": "max_speed", "limit": 90, "tolerance": 3},
|
||||
{"type": "log_contains", "pattern": "lost power for 0\\.2\\d sec"},
|
||||
{"type": "log_lacks", "pattern": "lost power for (0\\.[3-9]|[1-9])"},
|
||||
{"type": "traction", "from_distance": 460, "to_distance": 700, "reaches": 25},
|
||||
{"type": "stops", "moving_speed": 20, "stop_speed": 1.0, "hold": 0, "min_distance": 1380, "max_distance": 1420}
|
||||
]
|
||||
}
|
||||
@@ -49,7 +49,9 @@ OUT_DIR = HERE / "out"
|
||||
# Velocity is in km/h and pressures in bar, despite the header saying m/s and MPa.
|
||||
COL_TIME = 0
|
||||
COL_VELOCITY = 1 # wheel speed: stays at 0 while the wheels are locked in a skid
|
||||
COL_TRACTION_FORCE = 5 # N, despite the header saying kN
|
||||
COL_BRAKE_PRESS = 8
|
||||
COL_MASTER_CONTROLLER = 11 # the position of the master controller
|
||||
COL_COMMAND = 16 # text, read as None
|
||||
COL_WHEELSLIP = 20
|
||||
COL_VEHICLE_VELOCITY = 25 # signed vehicle speed, km/h; only in builds which log it
|
||||
@@ -155,6 +157,46 @@ def timetable_path(game_dir: Path, case_name: str) -> Path:
|
||||
return game_dir / "scenery" / f"{timetable_name(case_name)}.txt"
|
||||
|
||||
|
||||
def variant_name(case_name: str, name: str) -> str:
|
||||
"""A vehicle variant of the case as a trainset names it: {{variant_<name>}} in the fragment."""
|
||||
return f"autotest_{case_name}_{name}"
|
||||
|
||||
|
||||
def variant_paths(game_dir: Path, case_name: str, variant: dict) -> list[Path]:
|
||||
"""The .fiz and .mmd of a vehicle variant of the case, beside those of the vehicle it is made from."""
|
||||
folder = (game_dir / "dynamic" / variant["from"]).parent
|
||||
return [folder / f"{variant_name(case_name, variant['name'])}{suffix}" for suffix in (".fiz", ".mmd")]
|
||||
|
||||
|
||||
def write_vehicle_variants(case: dict, game_dir: Path, case_name: str) -> None:
|
||||
"""Writes the case's vehicle variants into the game's dynamic/ dir: a copy of a vehicle's .fiz with the
|
||||
case's replacements, e.g. a .fiz key the shipped data doesn't have yet, and a copy of its .mmd. The
|
||||
simulator hands the .mmd its type name as (p2), which some pass on to the include that names the
|
||||
model (et42_v2: `include 112e-a.mmd.inc (p2) end`, `models: (p1).t3d`), so the copy has the name of
|
||||
the vehicle it is made from in place of (p2) and looks and loads as that one does."""
|
||||
files = {}
|
||||
for variant in case.get("vehicle_variants", []):
|
||||
source = game_dir / "dynamic" / variant["from"]
|
||||
# .fiz files are cp1250 like the sceneries; latin-1 round-trips every byte
|
||||
fiz = source.with_name(source.name + ".fiz").read_bytes().decode("latin-1")
|
||||
for old, new in variant.get("replace", []):
|
||||
if old not in fiz:
|
||||
sys.exit(f"vehicle_variants: {variant['from']}.fiz has no {old!r}")
|
||||
fiz = fiz.replace(old, new)
|
||||
mmd = source.with_name(source.name + ".mmd").read_bytes().decode("latin-1").replace("(p2)", source.name)
|
||||
fiz_path, mmd_path = variant_paths(game_dir, case_name, variant)
|
||||
files[fiz_path], files[mmd_path] = fiz, mmd
|
||||
# written once every variant is made, so a case with a wrong replacement leaves nothing in the game dir
|
||||
for path, text in files.items():
|
||||
path.write_bytes(text.encode("latin-1"))
|
||||
|
||||
|
||||
def remove_vehicle_variants(case: dict, game_dir: Path, case_name: str) -> None:
|
||||
for variant in case.get("vehicle_variants", []):
|
||||
for path in variant_paths(game_dir, case_name, variant):
|
||||
path.unlink(missing_ok=True)
|
||||
|
||||
|
||||
def build_scenery(case: dict, game_dir: Path, case_name: str, vehicle: str) -> str:
|
||||
"""Writes the case scenery into the game's scenery dir and returns its file name."""
|
||||
scenery_dir = game_dir / "scenery"
|
||||
@@ -175,8 +217,9 @@ def build_scenery(case: dict, game_dir: Path, case_name: str, vehicle: str) -> s
|
||||
# a case on a mission of the base scenery may have nothing to add but its test_config
|
||||
fragment = (CASES_DIR / case["fragment"]).read_bytes().decode("latin-1") if "fragment" in case else ""
|
||||
# vars first: {{vehicle}} and {{timetable}} inside a var's value get filled in the second pass
|
||||
fragment = fill_vars(fragment, case.get("vars", {}), keep={"vehicle", "timetable"})
|
||||
fragment = fill_vars(fragment, {"vehicle": vehicle, "timetable": timetable_name(case_name)})
|
||||
variants = {f"variant_{v['name']}": variant_name(case_name, v["name"]) for v in case.get("vehicle_variants", [])}
|
||||
fragment = fill_vars(fragment, case.get("vars", {}), keep={"vehicle", "timetable", *variants})
|
||||
fragment = fill_vars(fragment, {"vehicle": vehicle, "timetable": timetable_name(case_name), **variants})
|
||||
# FirstInit binds event launchers to their events and links the tracks. so launchers and
|
||||
# events of the case go in before it (read after it they never fire), trainsets after it
|
||||
# (placed before it they stand on unlinked track and derail at once)
|
||||
@@ -192,6 +235,8 @@ def build_scenery(case: dict, game_dir: Path, case_name: str, vehicle: str) -> s
|
||||
else:
|
||||
text += header + before + "\n"
|
||||
text += header + trainsets + "\n"
|
||||
# vehicles of the case's own, made from those of the game
|
||||
write_vehicle_variants(case, game_dir, case_name)
|
||||
name = f"autotest_{case_name}.scn"
|
||||
(scenery_dir / name).write_bytes(text.encode("latin-1"))
|
||||
# a timetable of the case's own, for a train whose timetable the sceneries of the game have none like
|
||||
@@ -442,11 +487,14 @@ def run_simulator(exe: Path, game_dir: Path, scenery: str, ini: Path, physicslog
|
||||
# ---------------------------------------------------------------- checks
|
||||
|
||||
|
||||
def check_starts(rows, min_speed, within):
|
||||
def check_starts(rows, min_speed, within, after=None):
|
||||
for r in rows:
|
||||
if r[COL_TIME] > within:
|
||||
break
|
||||
if r[COL_VELOCITY] >= min_speed:
|
||||
# a case can also say the train mustn't leave before something it waits for (a converter starting)
|
||||
if after is not None and r[COL_TIME] < after:
|
||||
return False, f"reached {min_speed} km/h at t={r[COL_TIME]:.1f}s, before {after}s"
|
||||
return True, f"reached {min_speed} km/h at t={r[COL_TIME]:.1f}s"
|
||||
top = max((r[COL_VELOCITY] for r in rows if r[COL_TIME] <= within), default=0.0)
|
||||
return False, f"top speed in the first {within}s was {top:.1f} km/h, wanted {min_speed}"
|
||||
@@ -602,7 +650,51 @@ def check_slip_clears(rows, moving_speed, stop_speed, within):
|
||||
return True, f"stopped at t={rows[stop][COL_TIME]:.1f}s, no slipping after t={deadline:.1f}s"
|
||||
|
||||
|
||||
def check_traction(rows, from_distance, to_distance, reaches=None, at_most=None, at_least=None):
|
||||
"""The traction force of the vehicle in kN (the physicslog has it in N, whatever its header says) while it
|
||||
runs between two points of its way, in metres travelled as in `distance`: the highest there `reaches` a
|
||||
force, e.g. the power taken again behind a section without voltage; it stays `at_most` a force, e.g. none
|
||||
taken where there is no voltage; it stays `at_least` a force, e.g. no power lost under an insulator."""
|
||||
dist = _distances(rows)
|
||||
window = [(d, r) for d, r in zip(dist, rows) if from_distance <= d <= to_distance]
|
||||
if not window:
|
||||
return False, f"never got between {from_distance} and {to_distance} m (travelled {dist[-1] if dist else 0:.0f} m)"
|
||||
|
||||
def describe(item):
|
||||
d, r = item
|
||||
return f"{r[COL_TRACTION_FORCE] / 1000:.1f} kN at {d:.0f} m, t={r[COL_TIME]:.1f}s, v={r[COL_VELOCITY]:.1f} km/h"
|
||||
|
||||
top = max(window, key=lambda item: item[1][COL_TRACTION_FORCE])
|
||||
low = min(window, key=lambda item: item[1][COL_TRACTION_FORCE])
|
||||
detail = (f"between {from_distance} and {to_distance} m (t={window[0][1][COL_TIME]:.1f}-{window[-1][1][COL_TIME]:.1f}s) "
|
||||
f"the traction force was {describe(low)} at its lowest, {describe(top)} at its highest")
|
||||
if reaches is not None and top[1][COL_TRACTION_FORCE] / 1000 < reaches:
|
||||
return False, f"{detail}; wanted it to reach {reaches} kN"
|
||||
if at_most is not None and top[1][COL_TRACTION_FORCE] / 1000 > at_most:
|
||||
return False, f"{detail}; wanted at most {at_most} kN"
|
||||
if at_least is not None and low[1][COL_TRACTION_FORCE] / 1000 < at_least:
|
||||
return False, f"{detail}; wanted at least {at_least} kN"
|
||||
return True, detail
|
||||
|
||||
|
||||
def check_master_controller(rows, from_distance, to_distance, at_most):
|
||||
"""The master controller of the vehicle stays at or below a position while it runs between two points of its
|
||||
way (metres travelled, as in `distance`), e.g. at 0 where the scenery tells the driver to coast."""
|
||||
dist = _distances(rows)
|
||||
window = [(d, r) for d, r in zip(dist, rows) if from_distance <= d <= to_distance]
|
||||
if not window:
|
||||
return False, f"never got between {from_distance} and {to_distance} m (travelled {dist[-1] if dist else 0:.0f} m)"
|
||||
d, top = max(window, key=lambda item: item[1][COL_MASTER_CONTROLLER])
|
||||
detail = (f"between {from_distance} and {to_distance} m (t={window[0][1][COL_TIME]:.1f}-{window[-1][1][COL_TIME]:.1f}s) "
|
||||
f"the master controller was at {top[COL_MASTER_CONTROLLER]:.0f} at most, at {d:.0f} m, t={top[COL_TIME]:.1f}s")
|
||||
if top[COL_MASTER_CONTROLLER] > at_most:
|
||||
return False, f"{detail}; wanted at most {at_most}"
|
||||
return True, detail
|
||||
|
||||
|
||||
CHECKS = {
|
||||
"master_controller": check_master_controller,
|
||||
"traction": check_traction,
|
||||
"slips": check_slips,
|
||||
"slip_clears": check_slip_clears,
|
||||
"holds_still": check_holds_still,
|
||||
@@ -856,15 +948,6 @@ def _run_case(name: str, case: dict, exe: Path, game_dir: Path, timespeed: float
|
||||
if not with_physicslog and (watch or needs_physicslog):
|
||||
sys.exit(f"{name}: with physicslog off a case can have log checks only ({', '.join(LOG_CHECKS)}), "
|
||||
"and can't run with --watch")
|
||||
scenery = build_scenery(case, game_dir, name, vehicle)
|
||||
ini = out / "autotest.ini"
|
||||
# the case's own settings go last, over the common ones; then the seed of this run of the suite, if any
|
||||
settings = [*case.get("ini", []), *([f"randomseed {seed}"] if seed else [])]
|
||||
ini.write_text(TEST_INI.format(timespeed=timespeed, physicslog="yes" if with_physicslog else "no")
|
||||
+ "".join(line + "\n" for line in settings), encoding="ascii")
|
||||
physicslog = game_dir / "physicslog" / f"{vehicle}.dat"
|
||||
started = time.time() - 1
|
||||
|
||||
duration = float(case["duration"]) if "duration" in case else None
|
||||
# a case that only records `duration` seconds ends on the test timeout; one that says
|
||||
# how the test ends (a pass event, a signal passed at danger...) expects that result
|
||||
@@ -873,10 +956,24 @@ def _run_case(name: str, case: dict, exe: Path, game_dir: Path, timespeed: float
|
||||
sys.exit(f"{name}: expect must be one of {', '.join(RESULTS)}")
|
||||
if watch and duration is None:
|
||||
sys.exit(f"{name}: --watch needs a case with duration")
|
||||
result = run_simulator(exe, game_dir, scenery, ini, physicslog,
|
||||
duration, float(case.get("timeout", 600)), watch, say,
|
||||
expect_rows=with_physicslog and not own_vehicle)
|
||||
timetable_path(game_dir, name).unlink(missing_ok=True)
|
||||
|
||||
ini = out / "autotest.ini"
|
||||
# the case's own settings go last, over the common ones; then the seed of this run of the suite, if any
|
||||
settings = [*case.get("ini", []), *([f"randomseed {seed}"] if seed else [])]
|
||||
ini.write_text(TEST_INI.format(timespeed=timespeed, physicslog="yes" if with_physicslog else "no")
|
||||
+ "".join(line + "\n" for line in settings), encoding="ascii")
|
||||
physicslog = game_dir / "physicslog" / f"{vehicle}.dat"
|
||||
started = time.time() - 1
|
||||
# from here on the case has files of its own in the game dir (the vehicle variants, the timetable)
|
||||
try:
|
||||
scenery = build_scenery(case, game_dir, name, vehicle)
|
||||
result = run_simulator(exe, game_dir, scenery, ini, physicslog,
|
||||
duration, float(case.get("timeout", 600)), watch, say,
|
||||
expect_rows=with_physicslog and not own_vehicle)
|
||||
finally:
|
||||
# the case's own files go from the game dir also when the run is broken off (ctrl+c)
|
||||
timetable_path(game_dir, name).unlink(missing_ok=True)
|
||||
remove_vehicle_variants(case, game_dir, name)
|
||||
# a case that asked for no geometry cache (file.binary.terrain no) leaves none of an earlier run behind
|
||||
if any(line.split()[:2] == ["file.binary.terrain", "no"] for line in case.get("ini", [])):
|
||||
scenery_cache(game_dir, name).unlink(missing_ok=True)
|
||||
|
||||
Reference in New Issue
Block a user