rusefi/unit_tests/test-framework/engine_test_helper.h

121 lines
4.1 KiB
C
Raw Permalink Normal View History

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
#include <unordered_map>
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
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:
explicit EngineTestHelper(engine_type_e engineType);
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);
EngineTestHelper(engine_type_e engineType, configuration_callback_t boardCallback, const std::unordered_map<SensorType, float>& sensorValues);
~EngineTestHelper();
// convert ms time to angle at current RPM
angle_t timeToAngle(float timeMs);
float angleToTimeUs(angle_t angle) {
return angle * engine.rpmCalculator.oneDegreeUs;
}
float angleToTimeMs(angle_t angle) {
return US2MS(angleToTimeUs(angle));
}
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
void applyTriggerWaveform();
void setTriggerType(trigger_type_e trigger);
/**
* 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);
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);
void setTimeAndInvokeEventsUs(int timeNowUs);
2021-03-11 21:43:48 -08:00
void moveTimeForwardAndInvokeEventsSec(int deltaTimeSeconds);
2021-12-07 16:59:43 -08:00
/**
* both Rise and Fall
*/
void smartFireTriggerEvents2(int count, float delayMs);
2018-07-28 16:51:41 -07:00
2019-01-21 16:15:17 -08: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
/**
* 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
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
const AngleBasedEvent* assertTriggerEvent(const char *msg, int index, AngleBasedEvent *expected, void *callback, angle_t enginePhase);
2019-12-02 21:20:47 -08:00
2024-05-01 08:29:21 -07:00
void assertEvent(const char *msg, int index, void *callback, efitimeus_t momentUs, InjectionEvent *event);
void assertInjectorUpEvent(const char *msg, int eventIndex, efitimeus_t momentUs, long injectorIndex);
void assertInjectorDownEvent(const char *msg, int eventIndex, efitimeus_t momentUs, long injectorIndex);
2019-01-21 19:34:17 -08:00
// todo: open question if this is worth a helper method or should be inlined?
void assertRpm(int expectedRpm, const char *msg = "RPM");
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);
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
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
};
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);