mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-19 06:26:01 +01:00
refactor(simulation): the rules of the test mode in a file of their own, with unit tests
The command line options of the test mode and the end conditions checked after each frame are now plain functions in simulation/simulationtestrules.cpp, which needs nothing of the running simulation: parse_test_command_line() and evaluate_frame(). The file is part of the core library, so the unit tests check them (tests/unit/test_test_mode.cpp): the --test-timeout value, values of other options not taken for options, a pass that waits for the stop, the standstill, the timeout. test_manager only gathers what a frame brought and acts on the verdict. No change in behaviour.
This commit is contained in:
@@ -9,32 +9,19 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "simulation/simulationtestrules.h"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
// integration test mode (eu07 --test -s <scenery>, eu07/maszyna#541): the scenery runs unattended in a tight
|
||||
// fixed-step loop and the simulator quits with an exit code saying how the test went
|
||||
namespace simulation {
|
||||
|
||||
// exit codes of a test run; public, scripts and CI read them
|
||||
enum class test_result : int {
|
||||
pass = 0, // __test.result set to 1, then every vehicle came to rest (or test.pass_on_standstill)
|
||||
fail = 1, // __test.result set to 0
|
||||
signal_passed_at_danger = 2, // a train went past a stop signal (SetVelocity 0 0), unless test.fail_if_stop_overran no
|
||||
timeout = 3, // test.timeout seconds of simulation time went by without a result
|
||||
standstill = 4, // every vehicle stood still for test.standstill seconds without a result
|
||||
error = 5, // the run could not start (no -s, the scenery failed to load) or the simulator threw
|
||||
};
|
||||
|
||||
std::string_view to_string(test_result Result);
|
||||
|
||||
class test_manager {
|
||||
|
||||
public:
|
||||
// name of the memory cell a scenery reports its result to
|
||||
static constexpr std::string_view result_cell { "__test.result" };
|
||||
// how long everything has to stand before a requested pass is granted [s]
|
||||
static constexpr double pass_settle_time { 1.0 };
|
||||
// fixed simulation time step of one frame in test mode [s]: 3 physics steps of 10 ms
|
||||
static constexpr double frame_step { 0.03 };
|
||||
|
||||
@@ -60,9 +47,7 @@ private:
|
||||
bool m_started { false };
|
||||
bool m_finished { false };
|
||||
test_result m_result { test_result::error };
|
||||
bool m_passrequested { false };
|
||||
double m_time { 0.0 }; // simulation time since the start [s]
|
||||
double m_resttime { 0.0 }; // how long every vehicle has been standing [s]
|
||||
test_progress m_progress;
|
||||
};
|
||||
|
||||
// the test of the run
|
||||
|
||||
Reference in New Issue
Block a user