2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file engine_test_helper.cpp
|
|
|
|
*
|
|
|
|
* @date Jun 26, 2014
|
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2014
|
|
|
|
*/
|
|
|
|
|
2021-07-25 22:05:17 -07:00
|
|
|
#include "pch.h"
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "trigger_decoder.h"
|
|
|
|
#include "speed_density.h"
|
|
|
|
#include "fuel_math.h"
|
2016-03-11 08:03:18 -08:00
|
|
|
#include "accel_enrichment.h"
|
2016-08-26 15:02:39 -07:00
|
|
|
#include "advance_map.h"
|
2020-07-19 21:36:10 -07:00
|
|
|
#include "tooth_logger.h"
|
|
|
|
#include "logicdata.h"
|
2021-07-14 23:12:57 -07:00
|
|
|
#include "hardware.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-04-04 19:41:38 -07:00
|
|
|
#if EFI_ENGINE_SNIFFER
|
|
|
|
#include "engine_sniffer.h"
|
|
|
|
extern WaveChart waveChart;
|
|
|
|
#endif /* EFI_ENGINE_SNIFFER */
|
|
|
|
|
|
|
|
|
2018-03-04 13:30:03 -08:00
|
|
|
extern int timeNowUs;
|
2019-01-12 05:34:38 -08:00
|
|
|
extern WarningCodeState unitTestWarningCodeState;
|
2019-10-31 13:06:34 -07:00
|
|
|
extern engine_configuration_s & activeConfiguration;
|
2020-07-19 12:47:21 -07:00
|
|
|
extern bool printTriggerDebug;
|
2021-06-26 13:05:43 -07:00
|
|
|
extern bool printTriggerTrace;
|
2020-07-19 12:47:21 -07:00
|
|
|
extern bool printFuelDebug;
|
2021-06-02 02:02:52 -07:00
|
|
|
extern int minCrankingRpm;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2022-03-13 17:03:49 -07:00
|
|
|
EngineTestHelperBase::EngineTestHelperBase(Engine * eng, engine_configuration_s * econfig, persistent_config_s * pers) {
|
2019-01-14 08:33:58 -08:00
|
|
|
// todo: make this not a global variable, we need currentTimeProvider interface on engine
|
|
|
|
timeNowUs = 0;
|
2021-06-02 02:02:52 -07:00
|
|
|
minCrankingRpm = 0;
|
2020-07-19 21:36:10 -07:00
|
|
|
EnableToothLogger();
|
2021-11-15 21:23:14 -08:00
|
|
|
if (engine || engineConfiguration || config) {
|
|
|
|
firmwareError(OBD_PCM_Processor_Fault,
|
|
|
|
"Engine configuration not cleaned up by previous test");
|
|
|
|
}
|
|
|
|
engine = eng;
|
|
|
|
engineConfiguration = econfig;
|
|
|
|
config = pers;
|
|
|
|
}
|
|
|
|
|
|
|
|
EngineTestHelperBase::~EngineTestHelperBase() {
|
|
|
|
engine = nullptr;
|
|
|
|
engineConfiguration = nullptr;
|
|
|
|
config = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
EngineTestHelper::EngineTestHelper(engine_type_e engineType)
|
|
|
|
: EngineTestHelper(engineType, &emptyCallbackWithConfiguration) {
|
2019-01-14 08:33:58 -08:00
|
|
|
}
|
|
|
|
|
2020-09-21 05:57:56 -07:00
|
|
|
EngineTestHelper::EngineTestHelper(engine_type_e engineType, configuration_callback_t configurationCallback)
|
|
|
|
: EngineTestHelper(engineType, configurationCallback, {}) {
|
2020-05-23 07:46:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EngineTestHelper::EngineTestHelper(engine_type_e engineType, const std::unordered_map<SensorType, float>& sensorValues)
|
|
|
|
: EngineTestHelper(engineType, &emptyCallbackWithConfiguration, sensorValues) {
|
|
|
|
}
|
|
|
|
|
2021-06-23 03:37:32 -07:00
|
|
|
warningBuffer_t *EngineTestHelper::recentWarnings() {
|
|
|
|
return &unitTestWarningCodeState.recentWarnings;
|
|
|
|
}
|
|
|
|
|
2021-06-24 20:38:16 -07:00
|
|
|
int EngineTestHelper::getWarningCounter() {
|
|
|
|
return unitTestWarningCodeState.warningCounter;
|
|
|
|
}
|
2021-06-23 03:37:32 -07:00
|
|
|
|
2021-11-15 21:23:14 -08:00
|
|
|
EngineTestHelper::EngineTestHelper(engine_type_e engineType, configuration_callback_t configurationCallback, const std::unordered_map<SensorType, float>& sensorValues) :
|
|
|
|
EngineTestHelperBase(&engine, &persistentConfig.engineConfiguration, &persistentConfig)
|
|
|
|
{
|
|
|
|
memset(&persistentConfig, 0, sizeof(persistentConfig));
|
2021-11-05 07:34:12 -07:00
|
|
|
|
2020-05-23 07:46:28 -07:00
|
|
|
Sensor::setMockValue(SensorType::Clt, 70);
|
|
|
|
Sensor::setMockValue(SensorType::Iat, 30);
|
|
|
|
|
2020-12-11 07:33:00 -08:00
|
|
|
for (const auto& [s, v] : sensorValues) {
|
2020-05-23 07:46:28 -07:00
|
|
|
Sensor::setMockValue(s, v);
|
|
|
|
}
|
|
|
|
|
2019-01-12 05:34:38 -08:00
|
|
|
unitTestWarningCodeState.clear();
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2018-03-04 18:10:00 -08:00
|
|
|
memset(&activeConfiguration, 0, sizeof(activeConfiguration));
|
2018-03-04 17:14:47 -08:00
|
|
|
|
2016-11-01 06:02:29 -07:00
|
|
|
enginePins.reset();
|
2021-07-09 14:02:25 -07:00
|
|
|
enginePins.unregisterPins();
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-04-04 19:41:38 -07:00
|
|
|
waveChart.init();
|
|
|
|
|
2017-06-11 12:12:41 -07:00
|
|
|
setCurveValue(config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE, -40, 1.5);
|
|
|
|
setCurveValue(config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE, -30, 1.5);
|
|
|
|
setCurveValue(config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE, -20, 1.42);
|
|
|
|
setCurveValue(config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE, -10, 1.36);
|
|
|
|
setCurveValue(config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE, 0, 1.28);
|
|
|
|
setCurveValue(config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE, 10, 1.19);
|
|
|
|
setCurveValue(config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE, 20, 1.12);
|
|
|
|
setCurveValue(config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE, 30, 1.10);
|
|
|
|
setCurveValue(config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE, 40, 1.06);
|
|
|
|
setCurveValue(config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE, 50, 1.06);
|
|
|
|
setCurveValue(config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE, 60, 1.03);
|
|
|
|
setCurveValue(config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE, 70, 1.01);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
initDataStructures();
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
resetConfigurationExt(configurationCallback, engineType);
|
2019-12-23 20:25:08 -08:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
validateConfig();
|
2021-08-16 06:11:30 -07:00
|
|
|
|
2021-07-09 14:02:25 -07:00
|
|
|
enginePins.startPins();
|
2020-11-18 19:42:41 -08:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
commonInitEngineController();
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2016-08-26 14:02:37 -07:00
|
|
|
// this is needed to have valid CLT and IAT.
|
2021-11-16 01:15:29 -08:00
|
|
|
//todo: reuse initPeriodicEvents() method
|
|
|
|
engine.periodicSlowCallback();
|
2020-07-26 20:39:42 -07:00
|
|
|
|
2022-03-14 12:00:02 -07:00
|
|
|
extern bool hasInitGtest;
|
|
|
|
if (hasInitGtest) {
|
|
|
|
// Setup running in mock airmass mode if running actual tests
|
|
|
|
engineConfiguration->fuelAlgorithm = LM_MOCK;
|
|
|
|
|
|
|
|
mockAirmass = std::make_unique<::testing::NiceMock<MockAirmass>>();
|
|
|
|
engine.mockAirmassModel = mockAirmass.get();
|
|
|
|
}
|
2020-09-10 19:16:20 -07:00
|
|
|
|
|
|
|
memset(mockPinStates, 0, sizeof(mockPinStates));
|
2021-07-14 23:12:57 -07:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
initHardware();
|
|
|
|
rememberCurrentConfiguration();
|
2019-08-08 18:27:57 -07:00
|
|
|
}
|
|
|
|
|
2020-04-05 06:10:08 -07:00
|
|
|
EngineTestHelper::~EngineTestHelper() {
|
2020-07-20 13:12:21 -07:00
|
|
|
// Write history to file
|
2022-03-14 19:15:21 -07:00
|
|
|
extern bool hasInitGtest;
|
|
|
|
if (hasInitGtest) {
|
|
|
|
std::stringstream filePath;
|
|
|
|
filePath << "unittest_" << ::testing::UnitTest::GetInstance()->current_test_info()->name() << ".logicdata";
|
|
|
|
writeEvents(filePath.str().c_str());
|
|
|
|
}
|
2020-07-20 13:12:21 -07:00
|
|
|
|
|
|
|
// Cleanup
|
2020-12-18 14:18:12 -08:00
|
|
|
enginePins.reset();
|
2021-07-09 14:02:25 -07:00
|
|
|
enginePins.unregisterPins();
|
2020-04-05 06:10:08 -07:00
|
|
|
Sensor::resetRegistry();
|
2020-09-10 19:16:20 -07:00
|
|
|
memset(mockPinStates, 0, sizeof(mockPinStates));
|
2020-04-05 06:10:08 -07:00
|
|
|
}
|
|
|
|
|
2020-07-19 21:36:10 -07:00
|
|
|
void EngineTestHelper::writeEvents(const char *fileName) {
|
2022-07-04 13:57:17 -07:00
|
|
|
const auto& events = getCompositeEvents();
|
|
|
|
if (events.size() < 2) {
|
2020-07-19 21:36:10 -07:00
|
|
|
printf("Not enough data for %s\n", fileName);
|
|
|
|
return;
|
|
|
|
}
|
2022-07-04 13:57:17 -07:00
|
|
|
printf("Writing %d records to %s\n", events.size(), fileName);
|
|
|
|
writeFile(fileName, events);
|
2020-07-19 21:36:10 -07:00
|
|
|
}
|
|
|
|
|
2019-01-14 09:59:57 -08:00
|
|
|
/**
|
|
|
|
* mock a change of time and fire single RISE front event
|
2020-07-20 08:16:51 -07:00
|
|
|
* DEPRECATED many usages should be migrated to
|
2019-01-14 09:59:57 -08:00
|
|
|
*/
|
2019-10-07 18:23:38 -07:00
|
|
|
void EngineTestHelper::fireRise(float delayMs) {
|
2019-01-10 18:26:02 -08:00
|
|
|
moveTimeForwardUs(MS2US(delayMs));
|
2018-07-28 16:51:41 -07:00
|
|
|
firePrimaryTriggerRise();
|
|
|
|
}
|
|
|
|
|
2020-07-20 08:16:51 -07:00
|
|
|
void EngineTestHelper::smartFireRise(float delayMs) {
|
2021-03-11 21:43:48 -08:00
|
|
|
moveTimeForwardAndInvokeEventsUs(MS2US(delayMs));
|
2020-07-20 08:16:51 -07:00
|
|
|
firePrimaryTriggerRise();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EngineTestHelper::fireFall(float delayMs) {
|
|
|
|
moveTimeForwardUs(MS2US(delayMs));
|
|
|
|
firePrimaryTriggerFall();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EngineTestHelper::smartFireFall(float delayMs) {
|
2021-03-11 21:43:48 -08:00
|
|
|
moveTimeForwardAndInvokeEventsUs(MS2US(delayMs));
|
2020-07-20 08:16:51 -07:00
|
|
|
firePrimaryTriggerFall();
|
|
|
|
}
|
|
|
|
|
2019-01-14 09:59:57 -08:00
|
|
|
/**
|
|
|
|
* fire single RISE front event
|
|
|
|
*/
|
2016-08-27 16:02:43 -07:00
|
|
|
void EngineTestHelper::firePrimaryTriggerRise() {
|
2020-07-19 21:36:10 -07:00
|
|
|
efitick_t nowNt = getTimeNowNt();
|
|
|
|
Engine *engine = &this->engine;
|
2021-11-16 01:15:29 -08:00
|
|
|
LogTriggerTooth(SHAFT_PRIMARY_RISING, nowNt);
|
|
|
|
handleShaftSignal(0, true, nowNt);
|
2016-08-27 16:02:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void EngineTestHelper::firePrimaryTriggerFall() {
|
2020-07-19 21:36:10 -07:00
|
|
|
efitick_t nowNt = getTimeNowNt();
|
|
|
|
Engine *engine = &this->engine;
|
2021-11-16 01:15:29 -08:00
|
|
|
LogTriggerTooth(SHAFT_PRIMARY_FALLING, nowNt);
|
|
|
|
handleShaftSignal(0, false, nowNt);
|
2016-08-27 16:02:43 -07:00
|
|
|
}
|
|
|
|
|
2019-10-07 18:23:38 -07:00
|
|
|
void EngineTestHelper::fireTriggerEventsWithDuration(float durationMs) {
|
2019-01-10 20:33:50 -08:00
|
|
|
fireTriggerEvents2(/*count*/1, durationMs);
|
2018-07-28 16:35:50 -07:00
|
|
|
}
|
|
|
|
|
2018-03-04 13:34:23 -08:00
|
|
|
/**
|
|
|
|
* Sends specified number of rise/fall trigger events, with specified amount of time between those.
|
|
|
|
*
|
|
|
|
* This is helpful for TT_ONE trigger wheel decoder and probably other decoders as well.
|
|
|
|
*/
|
2019-10-07 18:23:38 -07:00
|
|
|
void EngineTestHelper::fireTriggerEvents2(int count, float durationMs) {
|
2016-01-24 22:02:55 -08:00
|
|
|
for (int i = 0; i < count; i++) {
|
2018-07-28 16:51:41 -07:00
|
|
|
fireRise(durationMs);
|
2018-07-28 17:02:01 -07:00
|
|
|
fireFall(durationMs);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-20 08:16:51 -07:00
|
|
|
void EngineTestHelper::smartFireTriggerEvents2(int count, float durationMs) {
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
smartFireRise(durationMs);
|
|
|
|
smartFireFall(durationMs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-04 13:38:01 -08:00
|
|
|
void EngineTestHelper::clearQueue() {
|
2019-01-09 16:57:12 -08:00
|
|
|
engine.executor.executeAll(99999999); // this is needed to clear 'isScheduled' flag
|
2019-09-25 05:40:33 -07:00
|
|
|
ASSERT_EQ( 0, engine.executor.size()) << "Failed to clearQueue";
|
2018-03-04 13:38:01 -08:00
|
|
|
}
|
|
|
|
|
2019-01-10 18:26:02 -08:00
|
|
|
int EngineTestHelper::executeActions() {
|
|
|
|
return engine.executor.executeAll(timeNowUs);
|
2019-01-10 18:19:46 -08:00
|
|
|
}
|
|
|
|
|
2019-01-21 19:34:17 -08:00
|
|
|
void EngineTestHelper::moveTimeForwardMs(float deltaTimeMs) {
|
|
|
|
moveTimeForwardUs(MS2US(deltaTimeMs));
|
|
|
|
}
|
|
|
|
|
2021-03-11 21:43:48 -08:00
|
|
|
void EngineTestHelper::moveTimeForwardSec(float deltaTimeSec) {
|
|
|
|
moveTimeForwardUs(MS2US(1000 * deltaTimeSec));
|
|
|
|
}
|
|
|
|
|
2019-01-10 18:19:46 -08:00
|
|
|
void EngineTestHelper::moveTimeForwardUs(int deltaTimeUs) {
|
2020-07-19 12:47:21 -07:00
|
|
|
if (printTriggerDebug || printFuelDebug) {
|
|
|
|
printf("moveTimeForwardUs %.1fms\r\n", deltaTimeUs / 1000.0);
|
|
|
|
}
|
2019-01-10 18:19:46 -08:00
|
|
|
timeNowUs += deltaTimeUs;
|
|
|
|
}
|
|
|
|
|
2021-03-11 21:43:48 -08:00
|
|
|
void EngineTestHelper::moveTimeForwardAndInvokeEventsSec(int deltaTimeSeconds) {
|
|
|
|
moveTimeForwardAndInvokeEventsUs(MS2US(1000 * deltaTimeSeconds));
|
2020-11-18 18:22:01 -08:00
|
|
|
}
|
|
|
|
|
2020-07-20 09:45:26 -07:00
|
|
|
/**
|
2021-03-11 21:43:48 -08:00
|
|
|
* this method executes all pending events while moving time forward
|
2020-07-20 09:45:26 -07:00
|
|
|
*/
|
2021-03-11 21:43:48 -08:00
|
|
|
void EngineTestHelper::moveTimeForwardAndInvokeEventsUs(int deltaTimeUs) {
|
2020-07-20 08:16:51 -07:00
|
|
|
if (printTriggerDebug || printFuelDebug) {
|
2021-03-11 21:43:48 -08:00
|
|
|
printf("moveTimeForwardAndInvokeEventsUs %.1fms\r\n", deltaTimeUs / 1000.0);
|
2020-07-20 08:16:51 -07:00
|
|
|
}
|
2021-06-23 02:00:26 -07:00
|
|
|
setTimeAndInvokeEventsUs(timeNowUs + deltaTimeUs);
|
|
|
|
}
|
2020-07-20 09:45:26 -07:00
|
|
|
|
2021-06-23 02:00:26 -07:00
|
|
|
void EngineTestHelper::setTimeAndInvokeEventsUs(int targetTime) {
|
2020-07-20 09:45:26 -07:00
|
|
|
while (true) {
|
|
|
|
scheduling_s* nextScheduledEvent = engine.executor.getHead();
|
|
|
|
if (nextScheduledEvent == nullptr) {
|
|
|
|
// nothing pending - we are done here
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
int nextEventTime = nextScheduledEvent->momentX;
|
|
|
|
if (nextEventTime > targetTime) {
|
|
|
|
// next event is too far in the future
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
timeNowUs = nextEventTime;
|
|
|
|
engine.executor.executeAll(timeNowUs);
|
|
|
|
}
|
|
|
|
|
|
|
|
timeNowUs = targetTime;
|
2020-07-20 08:16:51 -07:00
|
|
|
}
|
|
|
|
|
2022-01-11 19:40:52 -08:00
|
|
|
efitimeus_t EngineTestHelper::getTimeNowUs() {
|
2019-01-10 18:50:13 -08:00
|
|
|
return timeNowUs;
|
|
|
|
}
|
|
|
|
|
2016-08-26 15:02:39 -07:00
|
|
|
void EngineTestHelper::fireTriggerEvents(int count) {
|
2018-07-28 16:35:50 -07:00
|
|
|
fireTriggerEvents2(count, 5); // 5ms
|
2016-08-26 15:02:39 -07:00
|
|
|
}
|
|
|
|
|
2022-09-11 13:08:11 -07:00
|
|
|
void EngineTestHelper::assertInjectorUpEvent(const char *msg, int eventIndex, efitimeus_t momentX, long injectorIndex) {
|
2019-10-07 23:56:19 -07:00
|
|
|
InjectionEvent *event = &engine.injectionEvents.elements[injectorIndex];
|
2020-01-10 20:17:58 -08:00
|
|
|
assertEvent(msg, eventIndex, (void*)turnInjectionPinHigh, momentX, event);
|
2019-01-10 18:50:13 -08:00
|
|
|
}
|
|
|
|
|
2022-09-11 13:08:11 -07:00
|
|
|
void EngineTestHelper::assertInjectorDownEvent(const char *msg, int eventIndex, efitimeus_t momentX, long injectorIndex) {
|
2019-10-07 23:56:19 -07:00
|
|
|
InjectionEvent *event = &engine.injectionEvents.elements[injectorIndex];
|
2020-01-10 20:17:58 -08:00
|
|
|
assertEvent(msg, eventIndex, (void*)turnInjectionPinLow, momentX, event);
|
2019-01-10 18:50:13 -08:00
|
|
|
}
|
|
|
|
|
2022-09-11 13:08:11 -07:00
|
|
|
scheduling_s * EngineTestHelper::assertEvent5(const char *msg, int index, void *callback, efitimeus_t expectedTimestamp) {
|
2019-10-07 18:54:03 -07:00
|
|
|
TestExecutor *executor = &engine.executor;
|
2019-11-23 19:55:21 -08:00
|
|
|
EXPECT_TRUE(executor->size() > index) << msg << " valid index";
|
2019-01-10 20:09:56 -08:00
|
|
|
scheduling_s *event = executor->getForUnitTest(index);
|
2019-11-23 19:55:21 -08:00
|
|
|
assertEqualsM4(msg, " callback up/down", (void*)event->action.getCallback() == (void*) callback, 1);
|
2022-09-11 13:08:11 -07:00
|
|
|
efitimeus_t start = getTimeNowUs();
|
2019-11-23 19:55:21 -08:00
|
|
|
assertEqualsM4(msg, " timestamp", expectedTimestamp, event->momentX - start);
|
2019-01-10 20:09:56 -08:00
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2022-09-20 02:28:23 -07:00
|
|
|
AngleBasedEventBase * EngineTestHelper::assertTriggerEvent(const char *msg,
|
|
|
|
int index, AngleBasedEventBase *expected,
|
2019-12-02 21:20:47 -08:00
|
|
|
void *callback,
|
|
|
|
int triggerEventIndex, angle_t angleOffsetFromTriggerEvent) {
|
2022-09-20 02:28:23 -07:00
|
|
|
AngleBasedEventBase * event2 =
|
2021-11-18 11:27:21 -08:00
|
|
|
engine.module<TriggerScheduler>()->getElementAtIndexForUnitTest(index);
|
2019-12-02 21:20:47 -08:00
|
|
|
|
2022-09-20 02:28:23 -07:00
|
|
|
auto event = event2->asOld();
|
|
|
|
|
2019-12-02 21:20:47 -08:00
|
|
|
assertEqualsM4(msg, " callback up/down", (void*)event->action.getCallback() == (void*) callback, 1);
|
|
|
|
|
|
|
|
assertEqualsM4(msg, " trigger", triggerEventIndex, event->position.triggerEventIndex);
|
|
|
|
assertEqualsM4(msg, " angle", angleOffsetFromTriggerEvent, event->position.angleOffsetFromTriggerEvent);
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2022-09-11 13:08:11 -07:00
|
|
|
scheduling_s * EngineTestHelper::assertScheduling(const char *msg, int index, scheduling_s *expected, void *callback, efitimeus_t expectedTimestamp) {
|
2019-11-23 19:55:21 -08:00
|
|
|
scheduling_s * actual = assertEvent5(msg, index, callback, expectedTimestamp);
|
2019-12-02 07:18:13 -08:00
|
|
|
return actual;
|
2019-11-23 19:55:21 -08:00
|
|
|
}
|
|
|
|
|
2022-09-11 13:08:11 -07:00
|
|
|
void EngineTestHelper::assertEvent(const char *msg, int index, void *callback, efitimeus_t momentX, InjectionEvent *expectedEvent) {
|
2019-10-07 20:02:47 -07:00
|
|
|
scheduling_s *event = assertEvent5(msg, index, callback, momentX);
|
2019-01-10 20:09:56 -08:00
|
|
|
|
2019-11-23 17:36:40 -08:00
|
|
|
InjectionEvent *actualEvent = (InjectionEvent *)event->action.getArgument();
|
2019-01-10 20:09:56 -08:00
|
|
|
|
2021-11-19 21:23:27 -08:00
|
|
|
assertEqualsLM(msg, (uintptr_t)expectedEvent->outputs[0], (uintptr_t)actualEvent->outputs[0]);
|
2019-01-10 20:09:56 -08:00
|
|
|
// but this would not work assertEqualsLM(msg, expectedPair, (long)eventPair);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-07 22:09:39 -08:00
|
|
|
void EngineTestHelper::applyTriggerWaveform() {
|
2022-04-02 16:27:18 -07:00
|
|
|
engine.updateTriggerWaveform();
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
incrementGlobalConfigurationVersion();
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
2019-01-15 18:36:13 -08:00
|
|
|
|
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 EngineTestHelper::assertRpm(int expectedRpm, const char *msg) {
|
|
|
|
Engine *engine = &this->engine;
|
2021-11-16 01:15:29 -08:00
|
|
|
|
2022-01-20 20:32:59 -08:00
|
|
|
EXPECT_EQ(expectedRpm, Sensor::getOrZero(SensorType::Rpm)) << msg;
|
2019-01-15 18:36:13 -08:00
|
|
|
}
|
|
|
|
|
2019-01-20 19:21:12 -08:00
|
|
|
void setupSimpleTestEngineWithMaf(EngineTestHelper *eth, injection_mode_e injectionMode,
|
|
|
|
trigger_type_e trigger) {
|
2019-01-15 18:36:13 -08:00
|
|
|
Engine *engine = ð->engine;
|
|
|
|
|
|
|
|
engineConfiguration->isIgnitionEnabled = false; // let's focus on injection
|
|
|
|
engineConfiguration->specs.cylindersCount = 4;
|
|
|
|
// a bit of flexibility - the mode may be changed by some tests
|
2019-01-20 19:21:12 -08:00
|
|
|
engineConfiguration->injectionMode = injectionMode;
|
2019-01-15 18:36:13 -08:00
|
|
|
// set cranking mode (it's used by getCurrentInjectionMode())
|
|
|
|
engineConfiguration->crankingInjectionMode = IM_SIMULTANEOUS;
|
|
|
|
|
2019-11-22 20:27:24 -08:00
|
|
|
setArrayValues(config->cltFuelCorrBins, 1.0f);
|
|
|
|
setArrayValues(engineConfiguration->injector.battLagCorr, 0.0f);
|
2019-01-15 18:36:13 -08:00
|
|
|
// this is needed to update injectorLag
|
2021-11-16 01:15:29 -08:00
|
|
|
engine->updateSlowSensors();
|
2019-01-15 18:36:13 -08:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
ASSERT_EQ( 0, engine->triggerCentral.isTriggerConfigChanged()) << "trigger #1";
|
|
|
|
eth->setTriggerType(trigger);
|
2019-05-10 18:29:17 -07:00
|
|
|
}
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void EngineTestHelper::setTriggerType(trigger_type_e trigger) {
|
2019-01-21 12:34:39 -08:00
|
|
|
engineConfiguration->trigger.type = trigger;
|
2021-11-16 01:15:29 -08:00
|
|
|
incrementGlobalConfigurationVersion();
|
|
|
|
ASSERT_EQ( 1, engine.triggerCentral.isTriggerConfigChanged()) << "trigger #2";
|
2019-12-07 22:09:39 -08:00
|
|
|
applyTriggerWaveform();
|
2019-01-15 18:36:13 -08:00
|
|
|
}
|
2019-01-20 19:21:12 -08:00
|
|
|
|
2021-07-07 20:55:33 -07:00
|
|
|
void EngineTestHelper::executeUntil(int timeUs) {
|
|
|
|
scheduling_s *head;
|
|
|
|
while ((head = engine.executor.getHead()) != nullptr) {
|
|
|
|
if (head->momentX > timeUs) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
setTimeAndInvokeEventsUs(head->momentX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-20 19:21:12 -08:00
|
|
|
void setupSimpleTestEngineWithMafAndTT_ONE_trigger(EngineTestHelper *eth, injection_mode_e injectionMode) {
|
2022-04-03 03:58:25 -07:00
|
|
|
setCamOperationMode();
|
2022-05-29 10:49:00 -07:00
|
|
|
setupSimpleTestEngineWithMaf(eth, injectionMode, TT_ONE);
|
2019-01-20 19:21:12 -08:00
|
|
|
}
|
2021-06-26 13:05:43 -07:00
|
|
|
|
|
|
|
void setVerboseTrigger(bool isEnabled) {
|
|
|
|
printTriggerDebug = isEnabled;
|
|
|
|
printTriggerTrace = isEnabled;
|
|
|
|
}
|