rusefi/unit_tests/engine_test_helper.h

98 lines
3.3 KiB
C
Raw 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 "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"
#include "sensor.h"
2020-07-28 11:56:39 -07:00
#include "mocks.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
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:
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();
void applyTriggerWaveform();
2019-05-10 18:29:17 -07:00
void setTriggerType(trigger_type_e trigger DECLARE_ENGINE_PARAMETER_SUFFIX);
/**
* 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);
void smartMoveTimeForwardUs(int deltaTimeUs);
void smartMoveTimeForwardSeconds(int deltaTimeSeconds);
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);
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, 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);
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: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;
2020-07-20 18:50:48 -07:00
2020-07-28 14:18:50 -07:00
::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);