2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file engine_test_helper.h
|
|
|
|
*
|
|
|
|
* @date Jun 26, 2014
|
2020-01-07 21:02:40 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
2019-12-02 21:20:47 -08:00
|
|
|
|
|
|
|
#pragma once
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
#include "engine.h"
|
|
|
|
#include "trigger_central.h"
|
|
|
|
#include "rpm_calculator.h"
|
2016-08-26 17:03:06 -07:00
|
|
|
#include "main_trigger_callback.h"
|
2018-03-04 20:08:32 -08:00
|
|
|
#include "unit_test_framework.h"
|
2020-04-15 06:48:17 -07:00
|
|
|
#include "sensor.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2020-03-26 05:03:55 -07:00
|
|
|
extern EnginePins enginePins;
|
|
|
|
|
2019-01-14 08:33:58 -08:00
|
|
|
class EngineTestHelperBase
|
|
|
|
{
|
|
|
|
public:
|
2019-01-14 08:36:46 -08:00
|
|
|
// we have the base method and base constructor in order to better control order if initialization
|
|
|
|
// base constructor contains things which need to be executed first
|
2019-01-14 08:33:58 -08:00
|
|
|
EngineTestHelperBase();
|
|
|
|
};
|
2019-01-08 19:10:54 -08:00
|
|
|
|
2018-07-28 12:31:01 -07:00
|
|
|
/**
|
|
|
|
* Mock engine with trigger signal simulation infrastructure
|
|
|
|
*/
|
2019-01-14 08:33:58 -08:00
|
|
|
class EngineTestHelper : public EngineTestHelperBase {
|
2015-07-10 06:01:56 -07:00
|
|
|
public:
|
2020-04-15 13:20:45 -07:00
|
|
|
EngineTestHelper(engine_type_e engineType, const std::unordered_map<SensorType, float>& sensorValues);
|
2019-08-08 19:12:51 -07:00
|
|
|
EngineTestHelper(engine_type_e engineType, configuration_callback_t boardCallback);
|
2020-05-23 07:46:28 -07:00
|
|
|
EngineTestHelper(engine_type_e engineType, configuration_callback_t boardCallback, const std::unordered_map<SensorType, float>& sensorValues);
|
2020-04-05 06:10:08 -07:00
|
|
|
~EngineTestHelper();
|
|
|
|
|
2019-12-07 22:09:39 -08:00
|
|
|
void applyTriggerWaveform();
|
2019-05-10 18:29:17 -07:00
|
|
|
void setTriggerType(trigger_type_e trigger DECLARE_ENGINE_PARAMETER_SUFFIX);
|
2019-10-07 18:23:38 -07:00
|
|
|
void fireRise(float delayMs);
|
|
|
|
void fireFall(float delayMs);
|
2018-07-28 16:51:41 -07:00
|
|
|
|
2019-01-21 16:15:17 -08:00
|
|
|
/**
|
2019-05-10 18:56:33 -07:00
|
|
|
* See also #fireRise() which would also move time forward
|
2019-01-21 16:15:17 -08:00
|
|
|
*/
|
2016-08-27 16:02:43 -07:00
|
|
|
void firePrimaryTriggerRise();
|
2019-01-21 16:15:17 -08:00
|
|
|
/**
|
2019-05-10 18:56:33 -07:00
|
|
|
* See also #fireFall() which would also move time forward
|
2019-01-21 16:15:17 -08:00
|
|
|
*/
|
2016-08-27 16:02:43 -07:00
|
|
|
void firePrimaryTriggerFall();
|
2016-01-24 22:02:55 -08:00
|
|
|
void fireTriggerEvents(int count);
|
2019-10-07 18:23:38 -07:00
|
|
|
void fireTriggerEventsWithDuration(float delayMs);
|
|
|
|
void fireTriggerEvents2(int count, float delayMs);
|
2018-03-04 13:38:01 -08:00
|
|
|
void clearQueue();
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-10-07 20:02:47 -07:00
|
|
|
scheduling_s * assertEvent5(const char *msg, int index, void *callback, efitime_t expectedTimestamp);
|
2019-11-23 19:55:21 -08:00
|
|
|
scheduling_s * assertScheduling(const char *msg, int index, scheduling_s *expected, void *callback, efitime_t expectedTimestamp);
|
2019-12-02 21:20:47 -08:00
|
|
|
|
|
|
|
AngleBasedEvent * assertTriggerEvent(const char *msg, int index, AngleBasedEvent *expected, void *callback, int triggerEventIndex, angle_t angleOffsetFromTriggerEvent);
|
|
|
|
|
2019-10-07 23:56:19 -07:00
|
|
|
void assertEvent(const char *msg, int index, void *callback, efitime_t momentX, InjectionEvent *event);
|
2019-01-10 18:50:13 -08:00
|
|
|
void assertInjectorUpEvent(const char *msg, int eventIndex, efitime_t momentX, long injectorIndex);
|
|
|
|
void assertInjectorDownEvent(const char *msg, int eventIndex, efitime_t momentX, long injectorIndex);
|
2019-01-21 19:34:17 -08:00
|
|
|
// todo: open question if this is worth a helper method or should be inlined?
|
2019-01-21 19:32:30 -08:00
|
|
|
void assertRpm(int expectedRpm, const char *msg);
|
2019-01-10 18:50:13 -08:00
|
|
|
|
2019-01-10 18:26:02 -08:00
|
|
|
int executeActions();
|
2019-01-21 19:34:17 -08:00
|
|
|
void moveTimeForwardMs(float deltaTimeMs);
|
2019-01-10 18:19:46 -08:00
|
|
|
void moveTimeForwardUs(int deltaTimeUs);
|
2019-01-10 18:50:13 -08:00
|
|
|
efitimeus_t getTimeNowUs(void);
|
2019-01-10 18:19:46 -08:00
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
Engine engine;
|
2018-07-28 12:31:01 -07:00
|
|
|
persistent_config_s persistentConfig;
|
2015-07-10 06:01:56 -07:00
|
|
|
};
|
|
|
|
|
2019-01-15 18:36:13 -08:00
|
|
|
void setupSimpleTestEngineWithMafAndTT_ONE_trigger(EngineTestHelper *eth, injection_mode_e injMode = IM_BATCH);
|
2019-12-02 21:20:47 -08:00
|
|
|
void setupSimpleTestEngineWithMaf(EngineTestHelper *eth, injection_mode_e injectionMode, trigger_type_e trigger);
|