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 "trigger_central.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"
|
2021-08-31 01:38:35 -07:00
|
|
|
#include "engine.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2020-11-26 16:21:42 -08:00
|
|
|
#include <unordered_map>
|
|
|
|
|
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
|
2021-11-15 21:23:14 -08:00
|
|
|
EngineTestHelperBase(Engine * eng, engine_configuration_s * config, persistent_config_s * pers);
|
|
|
|
~EngineTestHelperBase();
|
2019-01-14 08:33:58 -08:00
|
|
|
};
|
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:
|
2021-11-15 21:23:14 -08:00
|
|
|
explicit EngineTestHelper(engine_type_e engineType);
|
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();
|
|
|
|
|
2021-06-23 03:37:32 -07:00
|
|
|
warningBuffer_t *recentWarnings();
|
2021-06-24 20:38:16 -07:00
|
|
|
int getWarningCounter();
|
2021-06-23 03:37:32 -07:00
|
|
|
|
2019-12-07 22:09:39 -08:00
|
|
|
void applyTriggerWaveform();
|
2021-11-16 01:15:29 -08:00
|
|
|
void setTriggerType(trigger_type_e trigger);
|
2020-07-20 08:16:51 -07:00
|
|
|
/**
|
|
|
|
* DEPRECATED these methods do not execute events on the queue
|
|
|
|
*/
|
2019-10-07 18:23:38 -07:00
|
|
|
void fireRise(float delayMs);
|
|
|
|
void fireFall(float delayMs);
|
2020-07-20 08:16:51 -07:00
|
|
|
void moveTimeForwardUs(int deltaTimeUs);
|
|
|
|
void fireTriggerEvents2(int count, float delayMs);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* these methods execute events while moving time forward
|
|
|
|
* todo: better naming convention?
|
|
|
|
*/
|
|
|
|
void smartFireRise(float delayMs);
|
|
|
|
void smartFireFall(float delayMs);
|
2021-03-11 21:43:48 -08:00
|
|
|
void moveTimeForwardAndInvokeEventsUs(int deltaTimeUs);
|
2021-06-23 02:00:26 -07:00
|
|
|
void setTimeAndInvokeEventsUs(int timeNowUs);
|
2021-07-07 20:55:33 -07:00
|
|
|
void executeUntil(int timeUs);
|
2021-03-11 21:43:48 -08:00
|
|
|
void moveTimeForwardAndInvokeEventsSec(int deltaTimeSeconds);
|
2021-12-07 16:59:43 -08:00
|
|
|
/**
|
|
|
|
* both Rise and Fall
|
|
|
|
*/
|
2020-07-20 08:16:51 -07:00
|
|
|
void smartFireTriggerEvents2(int count, 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);
|
2021-10-01 19:29:44 -07:00
|
|
|
/**
|
|
|
|
* todo: better method name since this method executes events in the FUTURE
|
|
|
|
* looks like such a method should be used only in some pretty narrow circumstances
|
|
|
|
* a healthy test should probably use executeActions instead?
|
|
|
|
*/
|
2018-03-04 13:38:01 -08:00
|
|
|
void clearQueue();
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2022-09-11 13:08:11 -07:00
|
|
|
scheduling_s * assertEvent5(const char *msg, int index, void *callback, efitimeus_t expectedTimestamp);
|
|
|
|
scheduling_s * assertScheduling(const char *msg, int index, scheduling_s *expected, void *callback, efitimeus_t expectedTimestamp);
|
2019-12-02 21:20:47 -08:00
|
|
|
|
2022-09-20 02:28:23 -07:00
|
|
|
AngleBasedEventBase * assertTriggerEvent(const char *msg, int index, AngleBasedEventBase *expected, void *callback, int triggerEventIndex, angle_t angleOffsetFromTriggerEvent);
|
2019-12-02 21:20:47 -08:00
|
|
|
|
2022-09-11 13:08:11 -07:00
|
|
|
void assertEvent(const char *msg, int index, void *callback, efitimeus_t momentX, InjectionEvent *event);
|
|
|
|
void assertInjectorUpEvent(const char *msg, int eventIndex, efitimeus_t momentX, long injectorIndex);
|
|
|
|
void assertInjectorDownEvent(const char *msg, int eventIndex, efitimeus_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);
|
2021-03-11 21:43:48 -08:00
|
|
|
void moveTimeForwardSec(float deltaTimeSec);
|
2022-01-11 19:40:52 -08:00
|
|
|
efitimeus_t getTimeNowUs();
|
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;
|
2020-07-20 18:50:48 -07:00
|
|
|
|
2022-03-14 12:00:02 -07:00
|
|
|
std::unique_ptr<::testing::NiceMock<MockAirmass>> mockAirmass;
|
2020-07-26 20:39:42 -07:00
|
|
|
|
2020-07-20 18:50:48 -07:00
|
|
|
private:
|
|
|
|
void writeEvents(const char *fileName);
|
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);
|
2021-06-26 13:05:43 -07:00
|
|
|
|
|
|
|
void setVerboseTrigger(bool isEnabled);
|