LCOV - code coverage report
Current view: top level - unit_tests/tests - test_idle_controller.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 276 276 100.0 %
Date: 2024-05-02 03:16:58 Functions: 82 82 100.0 %

          Line data    Source code
       1             : /*
       2             :  * @file test_idle_controller.cpp
       3             :  *
       4             :  * @date Oct 17, 2013
       5             :  * @author Andrey Belomutskiy, (c) 2012-2020
       6             :  */
       7             : 
       8             : #include "pch.h"
       9             : 
      10             : #include "advance_map.h"
      11             : #include "efi_pid.h"
      12             : #include "idle_thread.h"
      13             : #include "electronic_throttle.h"
      14             : 
      15             : using ::testing::StrictMock;
      16             : using ::testing::_;
      17             : 
      18             : using ICP = IIdleController::Phase;
      19             : 
      20           4 : TEST(idle_v2, timingPid) {
      21           1 :         EngineTestHelper eth(engine_type_e::TEST_ENGINE);
      22           1 :         IdleController dut;
      23             : 
      24           1 :         engineConfiguration->useIdleTimingPidControl = true;
      25             : 
      26           1 :         engineConfiguration->idleTimingPid.pFactor = 0.1;
      27           1 :         engineConfiguration->idleTimingPid.minValue = -10;
      28           1 :         engineConfiguration->idleTimingPid.maxValue = 10;
      29           1 :         engineConfiguration->idleTimingSoftEntryTime = 0.0f;
      30           1 :         dut.init();
      31             : 
      32             :         // Check that out of idle mode it doesn't do anything
      33           1 :         EXPECT_EQ(0, dut.getIdleTimingAdjustment(1050, 1000, ICP::Cranking));
      34           1 :         EXPECT_EQ(0, dut.getIdleTimingAdjustment(1050, 1000, ICP::Coasting));
      35           1 :         EXPECT_EQ(0, dut.getIdleTimingAdjustment(1050, 1000, ICP::Running));
      36             : 
      37             :         // Check that it works in idle mode
      38           1 :         EXPECT_FLOAT_EQ(-5, dut.getIdleTimingAdjustment(1050, 1000, ICP::Idling));
      39             : 
      40             :         // ...but not when disabled
      41           1 :         engineConfiguration->useIdleTimingPidControl = false;
      42           1 :         EXPECT_EQ(0, dut.getIdleTimingAdjustment(1050, 1000, ICP::Idling));
      43             : 
      44           1 :         engineConfiguration->useIdleTimingPidControl = true;
      45             : 
      46           1 :         EXPECT_FLOAT_EQ(5,    dut.getIdleTimingAdjustment(950,  1000, ICP::Idling));
      47           1 :         EXPECT_FLOAT_EQ(2.5,  dut.getIdleTimingAdjustment(975,  1000, ICP::Idling));
      48           1 :         EXPECT_FLOAT_EQ(0,    dut.getIdleTimingAdjustment(1000, 1000, ICP::Idling));
      49           1 :         EXPECT_FLOAT_EQ(-2.5, dut.getIdleTimingAdjustment(1025, 1000, ICP::Idling));
      50           1 :         EXPECT_FLOAT_EQ(-5,   dut.getIdleTimingAdjustment(1050, 1000, ICP::Idling));
      51           2 : }
      52             : 
      53           4 : TEST(idle_v2, testTargetRpm) {
      54           1 :         EngineTestHelper eth(engine_type_e::TEST_ENGINE);
      55           1 :         IdleController dut;
      56             : 
      57          17 :         for (size_t i = 0; i < efi::size(config->cltIdleRpmBins); i++) {
      58          16 :                 config->cltIdleRpmBins[i] = i * 10;
      59          16 :                 config->cltIdleRpm[i] = i * 100;
      60             :         }
      61             : 
      62           1 :         EXPECT_FLOAT_EQ(100, dut.getTargetRpm(10));
      63           1 :         EXPECT_FLOAT_EQ(500, dut.getTargetRpm(50));
      64           2 : }
      65             : 
      66           4 : TEST(idle_v2, testDeterminePhase) {
      67           1 :         EngineTestHelper eth(engine_type_e::TEST_ENGINE);
      68           1 :         IdleController dut;
      69             : 
      70             :         // TPS threshold 5% for easy test
      71           1 :         engineConfiguration->idlePidDeactivationTpsThreshold = 5;
      72             :         // RPM window is 100 RPM above target
      73           1 :         engineConfiguration->idlePidRpmUpperLimit = 100;
      74             :         // Max VSS for idle is 10kph
      75           1 :         engineConfiguration->maxIdleVss = 10;
      76             : 
      77             :         // First test stopped engine
      78           1 :         engine->rpmCalculator.setRpmValue(0);
      79           1 :         EXPECT_EQ(ICP::Cranking, dut.determinePhase(0, 1000, unexpected, 0, 10));
      80             : 
      81             :         // Now engine is running!
      82             :         // Controller doesn't need this other than for isCranking()
      83           1 :         engine->rpmCalculator.setRpmValue(1000);
      84             : 
      85             :         // Test invalid TPS, but inside the idle window
      86           1 :         EXPECT_EQ(ICP::Running, dut.determinePhase(1000, 1000, unexpected, 0, 10));
      87             : 
      88             :         // Valid TPS should now be inside the zone
      89           1 :         EXPECT_EQ(ICP::Idling, dut.determinePhase(1000, 1000, 0, 0, 10));
      90             : 
      91             :         // Inside the zone, but vehicle speed too fast
      92           1 :         EXPECT_EQ(ICP::Running, dut.determinePhase(1000, 1000, 0, 25, 10));
      93             : 
      94             :         // Check that shortly after cranking, the cranking taper inhibits closed loop idle
      95           1 :         EXPECT_EQ(ICP::CrankToIdleTaper, dut.determinePhase(1000, 1000, 0, 0, 0.5f));
      96             : 
      97             :         // Above TPS threshold should be outside the zone
      98           1 :         EXPECT_EQ(ICP::Running, dut.determinePhase(1000, 1000, 10, 0, 10));
      99             : 
     100             :         // Above target, below (target + upperLimit) should be in idle zone
     101           1 :         EXPECT_EQ(ICP::Idling, dut.determinePhase(1099, 1000, 0, 0, 10));
     102             : 
     103             :         // above upper limit and on throttle should be out of idle zone
     104           1 :         EXPECT_EQ(ICP::Running, dut.determinePhase(1101, 1000, 10, 0, 10));
     105             : 
     106             :         // Below TPS but above RPM should be outside the zone
     107           1 :         EXPECT_EQ(ICP::Coasting, dut.determinePhase(1101, 1000, 0, 0, 10));
     108           1 :         EXPECT_EQ(ICP::Coasting, dut.determinePhase(5000, 1000, 0, 0, 10));
     109           2 : }
     110             : 
     111           4 : TEST(idle_v2, crankingOpenLoop) {
     112           1 :         EngineTestHelper eth(engine_type_e::TEST_ENGINE);
     113           1 :         IdleController dut;
     114             : 
     115           1 :         engineConfiguration->crankingIACposition = 50;
     116             : 
     117           9 :         for (size_t i = 0; i < efi::size(config->cltCrankingCorrBins); i++) {
     118           8 :                 config->cltCrankingCorrBins[i] = i * 10;
     119           8 :                 config->cltCrankingCorr[i] = i * 0.1f;
     120             : 
     121             :                 // different values in running so we can tell which one is used
     122           8 :                 config->cltIdleCorrBins[i] = i * 10;
     123           8 :                 config->cltIdleCorr[i] = i * 0.2f;
     124             :         }
     125             : 
     126             :         // First test without override (ie, normal running CLT corr table)
     127           1 :         EXPECT_FLOAT_EQ(10, dut.getCrankingOpenLoop(10));
     128           1 :         EXPECT_FLOAT_EQ(50, dut.getCrankingOpenLoop(50));
     129             : 
     130             :         // Test with override (use separate table)
     131           1 :         engineConfiguration->overrideCrankingIacSetting = true;
     132           1 :         EXPECT_FLOAT_EQ(5, dut.getCrankingOpenLoop(10));
     133           1 :         EXPECT_FLOAT_EQ(25, dut.getCrankingOpenLoop(50));
     134           2 : }
     135             : 
     136           4 : TEST(idle_v2, runningOpenLoopBasic) {
     137           1 :         EngineTestHelper eth(engine_type_e::TEST_ENGINE);
     138           1 :         IdleController dut;
     139             : 
     140           1 :         engineConfiguration->manIdlePosition = 50;
     141             : 
     142          17 :         for (size_t i = 0; i < efi::size(config->cltIdleCorrBins); i++) {
     143          16 :                 config->cltIdleCorrBins[i] = i * 10;
     144          16 :                 config->cltIdleCorr[i] = i * 0.1f;
     145             :         }
     146             : 
     147           1 :         EXPECT_FLOAT_EQ(5, dut.getRunningOpenLoop(IIdleController::Phase::Cranking, 0, 10, 0));
     148           1 :         EXPECT_FLOAT_EQ(25, dut.getRunningOpenLoop(IIdleController::Phase::Cranking, 0, 50, 0));
     149           2 : }
     150             : 
     151           4 : TEST(idle_v2, runningFanAcBump) {
     152           1 :         EngineTestHelper eth(engine_type_e::TEST_ENGINE);
     153           1 :         IdleController dut;
     154             : 
     155           1 :         engineConfiguration->manIdlePosition = 50;
     156           1 :         engineConfiguration->acIdleExtraOffset = 9;
     157           1 :         engineConfiguration->fan1ExtraIdle = 7;
     158           1 :         engineConfiguration->fan2ExtraIdle = 3;
     159             : 
     160           1 :         setArrayValues(config->cltIdleCorr, 1.0f);
     161             : 
     162             :         // Start with fan off
     163           1 :         enginePins.fanRelay.setValue(0);
     164             : 
     165             :         // Should be base position
     166           1 :         EXPECT_FLOAT_EQ(50, dut.getRunningOpenLoop(IIdleController::Phase::Cranking, 0, 10, 0));
     167             : 
     168             :         // Turn on AC!
     169           1 :         engine->module<AcController>()->acButtonState = true;
     170           1 :         EXPECT_FLOAT_EQ(50 + 9, dut.getRunningOpenLoop(IIdleController::Phase::Cranking, 0, 10, 0));
     171           1 :         engine->module<AcController>()->acButtonState = false;
     172             : 
     173             :         // Turn the fan on!
     174           1 :         enginePins.fanRelay.setValue(1);
     175           1 :         EXPECT_FLOAT_EQ(50 + 7, dut.getRunningOpenLoop(IIdleController::Phase::Cranking, 0, 10, 0));
     176           1 :         enginePins.fanRelay.setValue(0);
     177             : 
     178             :         // Turn on the other fan!
     179           1 :         enginePins.fanRelay2.setValue(1);
     180           1 :         EXPECT_FLOAT_EQ(50 + 3, dut.getRunningOpenLoop(IIdleController::Phase::Cranking, 0, 10, 0));
     181             : 
     182             :         // Turn on everything!
     183           1 :         engine->module<AcController>()->acButtonState = true;
     184           1 :         enginePins.fanRelay.setValue(1);
     185           1 :         enginePins.fanRelay2.setValue(1);
     186           1 :         EXPECT_FLOAT_EQ(50 + 9 + 7 + 3, dut.getRunningOpenLoop(IIdleController::Phase::Cranking, 0, 10, 0));
     187           2 : }
     188             : 
     189           4 : TEST(idle_v2, runningOpenLoopTpsTaper) {
     190           1 :         EngineTestHelper eth(engine_type_e::TEST_ENGINE);
     191           1 :         IdleController dut;
     192             : 
     193             :         // Zero out base tempco table
     194           1 :         setArrayValues(config->cltIdleCorr, 0.0f);
     195             : 
     196             :         // Add 50% idle position
     197           1 :         engineConfiguration->iacByTpsTaper = 50;
     198             :         // At 10% TPS
     199           1 :         engineConfiguration->idlePidDeactivationTpsThreshold = 10;
     200             : 
     201             :         // Check in-bounds points
     202           1 :         EXPECT_FLOAT_EQ(0, dut.getRunningOpenLoop(IIdleController::Phase::Cranking, 0, 0, 0));
     203           1 :         EXPECT_FLOAT_EQ(25, dut.getRunningOpenLoop(IIdleController::Phase::Cranking, 0, 0, 5));
     204           1 :         EXPECT_FLOAT_EQ(50, dut.getRunningOpenLoop(IIdleController::Phase::Cranking, 0, 0, 10));
     205             : 
     206             :         // Check out of bounds - shouldn't leave the interval [0, 10]
     207           1 :         EXPECT_FLOAT_EQ(0, dut.getRunningOpenLoop(IIdleController::Phase::Cranking, 0, 0, -5));
     208           1 :         EXPECT_FLOAT_EQ(50, dut.getRunningOpenLoop(IIdleController::Phase::Cranking, 0, 0, 20));
     209           2 : }
     210             : 
     211           4 : TEST(idle_v2, runningOpenLoopTpsTaperWithDashpot) {
     212           1 :         EngineTestHelper eth(engine_type_e::TEST_ENGINE);
     213           1 :         IdleController dut;
     214             : 
     215             :         // Zero out base tempco table
     216           1 :         setArrayValues(config->cltIdleCorr, 0.0f);
     217             : 
     218             :         // Add 50% idle position
     219           1 :         engineConfiguration->iacByTpsTaper = 50;
     220             :         // At 10% TPS
     221           1 :         engineConfiguration->idlePidDeactivationTpsThreshold = 10;
     222             : 
     223             :         // set hold and decay time
     224           1 :         engineConfiguration->iacByTpsHoldTime = 10;  // 10 secs
     225           1 :         engineConfiguration->iacByTpsDecayTime = 10; // 10 secs
     226             : 
     227             :         // save the lastTimeRunningUs time - let it be the start of the hold phase
     228           1 :         advanceTimeUs(5'000'000);
     229             :         // full throttle = max.iac
     230           1 :         EXPECT_FLOAT_EQ(50, dut.getRunningOpenLoop(ICP::Running, 0, 0, 100));
     231             : 
     232             :         // jump to the end of the 'hold' phase of dashpot
     233           1 :         advanceTimeUs(10'000'000);
     234             : 
     235             :         // change the state to idle (release the pedal) - but still 100% max.iac!
     236           1 :     EXPECT_FLOAT_EQ(50, dut.getRunningOpenLoop(ICP::Idling, 0, 0, 0));
     237             :     // now we're in the middle of decay
     238           1 :     advanceTimeUs(5'000'000);
     239             :     // 50% decay (50% of 50 is 25)
     240           1 :     EXPECT_FLOAT_EQ(25, dut.getRunningOpenLoop(ICP::Idling, 0, 0, 0));
     241             :     // now the decay is finished
     242           1 :     advanceTimeUs(5'000'000);
     243             :     // no correction
     244           1 :     EXPECT_FLOAT_EQ(0, dut.getRunningOpenLoop(ICP::Idling, 0, 0, 0));
     245             :     // still react to the pedal
     246           1 :     EXPECT_FLOAT_EQ(50, dut.getRunningOpenLoop(ICP::Idling, 0, 0, 10));
     247           2 : }
     248             : 
     249             : struct MockOpenLoopIdler : public IdleController {
     250          11 :         MOCK_METHOD(float, getCrankingOpenLoop, (float clt), (const, override));
     251          10 :         MOCK_METHOD(float, getRunningOpenLoop, (IIdleController::Phase phase, float rpm, float clt, SensorResult tps), (override));
     252             : };
     253             : 
     254           4 : TEST(idle_v2, testOpenLoopCranking) {
     255           1 :         EngineTestHelper eth(engine_type_e::TEST_ENGINE);
     256           1 :         StrictMock<MockOpenLoopIdler> dut;
     257             : 
     258           1 :         engineConfiguration->overrideCrankingIacSetting = true;
     259             : 
     260           1 :         EXPECT_CALL(dut, getCrankingOpenLoop(30)).WillOnce(Return(44));
     261             : 
     262             :         // Should return the value from getCrankingOpenLoop, and ignore running numbers
     263           1 :         EXPECT_FLOAT_EQ(44, dut.getOpenLoop(ICP::Cranking, 0, 30, 0, 0));
     264           2 : }
     265             : 
     266           4 : TEST(idle_v2, openLoopRunningTaper) {
     267           1 :         EngineTestHelper eth(engine_type_e::TEST_ENGINE);
     268           1 :         StrictMock<MockOpenLoopIdler> dut;
     269             : 
     270           1 :         EXPECT_CALL(dut, getRunningOpenLoop(ICP::CrankToIdleTaper, 0, 30, SensorResult(0))).WillRepeatedly(Return(25));
     271           1 :         EXPECT_CALL(dut, getRunningOpenLoop(ICP::Running, 0, 30, SensorResult(0))).WillRepeatedly(Return(25));
     272           1 :         EXPECT_CALL(dut, getCrankingOpenLoop(30)).WillRepeatedly(Return(75));
     273             : 
     274             :         // 0 cycles - no taper yet, pure cranking value
     275           1 :         EXPECT_FLOAT_EQ(75, dut.getOpenLoop(ICP::Running, 0, 30, 0, 0));
     276           1 :         EXPECT_FLOAT_EQ(75, dut.getOpenLoop(ICP::CrankToIdleTaper, 0, 30, 0, 0));
     277             : 
     278             :         // 1/2 taper - half way, 50% each value -> outputs 50
     279           1 :         EXPECT_FLOAT_EQ(50, dut.getOpenLoop(ICP::Running, 0, 30, 0, 0.5f));
     280           1 :         EXPECT_FLOAT_EQ(50, dut.getOpenLoop(ICP::CrankToIdleTaper, 0, 30, 0, 0.5f));
     281             : 
     282             :         // 1x taper - fully tapered, should be running value
     283           1 :         EXPECT_FLOAT_EQ(25, dut.getOpenLoop(ICP::Running, 0, 30, 0, 1.0f));
     284           1 :         EXPECT_FLOAT_EQ(25, dut.getOpenLoop(ICP::CrankToIdleTaper, 0, 30, 0, 1.0f));
     285             : 
     286             :         // 2x taper - still fully tapered, should be running value
     287           1 :         EXPECT_FLOAT_EQ(25, dut.getOpenLoop(ICP::Running, 0, 30, 0, 2.0f));
     288           1 :         EXPECT_FLOAT_EQ(25, dut.getOpenLoop(ICP::CrankToIdleTaper, 0, 30, 0, 2.0f));
     289           2 : }
     290             : 
     291           4 : TEST(idle_v2, getCrankingTaperFraction) {
     292           1 :         EngineTestHelper eth(engine_type_e::TEST_ENGINE);
     293           1 :         StrictMock<MockOpenLoopIdler> dut;
     294             : 
     295           1 :         engineConfiguration->afterCrankingIACtaperDuration = 500;
     296             : 
     297             :         // 0 cycles - no taper yet, pure cranking value
     298           1 :         EXPECT_FLOAT_EQ(0, dut.getCrankingTaperFraction());
     299             : 
     300             :         // 250 cycles - half way, 50% each value -> outputs 50
     301         251 :         for (size_t i = 0; i < 250; i++) {
     302         250 :                 engine->rpmCalculator.onNewEngineCycle();
     303             :         }
     304           1 :         EXPECT_FLOAT_EQ(0.5f, dut.getCrankingTaperFraction());
     305             : 
     306             :         // 500 cycles - fully tapered, should be running value
     307         251 :         for (size_t i = 0; i < 250; i++) {
     308         250 :                 engine->rpmCalculator.onNewEngineCycle();
     309             :         }
     310           1 :         EXPECT_FLOAT_EQ(1, dut.getCrankingTaperFraction());
     311             : 
     312             :         // 1000 cycles - still fully tapered, should be running value
     313         501 :         for (size_t i = 0; i < 500; i++) {
     314         500 :                 engine->rpmCalculator.onNewEngineCycle();
     315             :         }
     316           1 :         EXPECT_FLOAT_EQ(2, dut.getCrankingTaperFraction());
     317           2 : }
     318             : 
     319           4 : TEST(idle_v2, openLoopCoastingTable) {
     320           1 :         EngineTestHelper eth(engine_type_e::TEST_ENGINE);
     321           1 :         IdleController dut;
     322             : 
     323             :         // enable & configure feature
     324           1 :         engineConfiguration->useIacTableForCoasting = true;
     325          17 :         for (size_t i = 0; i < CLT_CURVE_SIZE; i++) {
     326          16 :                 config->iacCoastingRpmBins[i] = 100 * i;
     327          16 :                 config->iacCoasting[i] = 5 * i;
     328             :         }
     329             : 
     330           1 :         EXPECT_FLOAT_EQ(40, dut.getOpenLoop(ICP::Coasting, 800, 0, 0, 2));
     331           1 :         EXPECT_FLOAT_EQ(75, dut.getOpenLoop(ICP::Coasting, 1500, 0, 0, 2));
     332           2 : }
     333             : 
     334           4 : TEST(idle_v2, closedLoopBasic) {
     335           1 :         EngineTestHelper eth(engine_type_e::TEST_ENGINE);
     336           1 :         IdleController dut;
     337           1 :         dut.init();
     338             : 
     339             :         // Not testing PID here, so we can set very simple PID gains
     340           1 :         engineConfiguration->idleRpmPid.pFactor = 0.5;       // 0.5 output per 1 RPM error = 50% per 100 rpm
     341           1 :         engineConfiguration->idleRpmPid.iFactor = 0;
     342           1 :         engineConfiguration->idleRpmPid.dFactor = 0;
     343           1 :         engineConfiguration->idleRpmPid.iFactor = 0;
     344           1 :         engineConfiguration->idleRpmPid.periodMs = 0;
     345           1 :         engineConfiguration->idleRpmPid.minValue = -50;
     346           1 :         engineConfiguration->idleRpmPid.maxValue = 50;
     347             : 
     348           1 :         engineConfiguration->idlePidRpmDeadZone = 0;
     349             : 
     350             :         // burn one update then advance time 5 seconds to avoid difficulty from wasResetPid
     351           1 :         dut.getClosedLoop(ICP::Idling, 0, 900, 900);
     352           1 :         advanceTimeUs(5'000'000);
     353             : 
     354             :         // Test above target, should return negative
     355           1 :         EXPECT_FLOAT_EQ(-25, dut.getClosedLoop(ICP::Idling, 0, /*rpm*/ 950, /*tgt*/ 900));
     356             : 
     357             :         // Below target, should return positive
     358           1 :         EXPECT_FLOAT_EQ(25, dut.getClosedLoop(ICP::Idling, 0, /*rpm*/ 850, /*tgt*/ 900));
     359           2 : }
     360             : 
     361           4 : TEST(idle_v2, closedLoopDeadzone) {
     362           1 :         EngineTestHelper eth(engine_type_e::TEST_ENGINE);
     363           1 :         IdleController dut;
     364           1 :         dut.init();
     365             : 
     366             : 
     367             :         // Not testing PID here, so we can set very simple PID gains
     368           1 :         engineConfiguration->idleRpmPid.pFactor = 0.5;       // 0.5 output per 1 RPM error = 50% per 100 rpm
     369           1 :         engineConfiguration->idleRpmPid.iFactor = 0;
     370           1 :         engineConfiguration->idleRpmPid.dFactor = 0;
     371           1 :         engineConfiguration->idleRpmPid.iFactor = 0;
     372           1 :         engineConfiguration->idleRpmPid.periodMs = 0;
     373           1 :         engineConfiguration->idleRpmPid.minValue = -50;
     374           1 :         engineConfiguration->idleRpmPid.maxValue = 50;
     375             : 
     376           1 :         engineConfiguration->idlePidRpmDeadZone = 25;
     377             : 
     378             :         // burn one then advance time 5 seconds to avoid difficulty from wasResetPid
     379           1 :         dut.getClosedLoop(ICP::Idling, 0, 900, 900);
     380           1 :         advanceTimeUs(5'000'000);
     381             : 
     382             :         // Test above target, should return negative
     383           1 :         EXPECT_FLOAT_EQ(-25, dut.getClosedLoop(ICP::Idling, 0, /*rpm*/ 950, /*tgt*/ 900));
     384             : 
     385             :         // Inside deadzone, should return same as last time
     386           1 :         EXPECT_FLOAT_EQ(-25, dut.getClosedLoop(ICP::Idling, 0, /*rpm*/ 900, /*tgt*/ 900));
     387           2 : }
     388             : 
     389             : struct IntegrationIdleMock : public IdleController {
     390           6 :         MOCK_METHOD(int, getTargetRpm, (float clt), (override));
     391           6 :         MOCK_METHOD(ICP, determinePhase, (int rpm, int targetRpm, SensorResult tps, float vss, float crankingTaperFraction), (override));
     392           6 :         MOCK_METHOD(float, getOpenLoop, (ICP phase, float rpm, float clt, SensorResult tps, float crankingTaperFraction), (override));
     393           4 :         MOCK_METHOD(float, getClosedLoop, (ICP phase, float tps, int rpm, int target), (override));
     394           6 :         MOCK_METHOD(float, getCrankingTaperFraction, (), (const, override));
     395             : };
     396             : 
     397           4 : TEST(idle_v2, IntegrationManual) {
     398           1 :         EngineTestHelper eth(engine_type_e::TEST_ENGINE);
     399           1 :         StrictMock<IntegrationIdleMock> dut;
     400             : 
     401           1 :         SensorResult expectedTps = 1;
     402           1 :         float expectedClt = 37;
     403           1 :         Sensor::setMockValue(SensorType::DriverThrottleIntent, expectedTps.Value);
     404           1 :         Sensor::setMockValue(SensorType::Clt, expectedClt);
     405           1 :         Sensor::setMockValue(SensorType::VehicleSpeed, 15.0);
     406             : 
     407             :         // Target of 1000 rpm
     408           3 :         EXPECT_CALL(dut, getTargetRpm(expectedClt))
     409           3 :                 .WillOnce(Return(1000));
     410             : 
     411             :         // 30% of the way through cranking taper
     412           3 :         EXPECT_CALL(dut, getCrankingTaperFraction())
     413           3 :                 .WillOnce(Return(0.3f));
     414             : 
     415             :         // Determine phase will claim we're idling
     416           3 :         EXPECT_CALL(dut, determinePhase(950, 1000, expectedTps, 15, 0.3f))
     417           3 :                 .WillOnce(Return(ICP::Idling));
     418             : 
     419             :         // Open loop should be asked for an open loop position
     420           3 :         EXPECT_CALL(dut, getOpenLoop(ICP::Idling, 950, expectedClt, expectedTps, 0.3f))
     421           3 :                 .WillOnce(Return(13));
     422             : 
     423             :         // getClosedLoop() should not be called!
     424             : 
     425           1 :         EXPECT_EQ(13, dut.getIdlePosition(950));
     426           2 : }
     427             : 
     428           4 : TEST(idle_v2, IntegrationAutomatic) {
     429           1 :         EngineTestHelper eth(engine_type_e::TEST_ENGINE);
     430           1 :         StrictMock<IntegrationIdleMock> dut;
     431             : 
     432           1 :         engineConfiguration->idleMode = IM_AUTO;
     433             : 
     434           1 :         SensorResult expectedTps = 1;
     435           1 :         float expectedClt = 37;
     436           1 :         Sensor::setMockValue(SensorType::DriverThrottleIntent, expectedTps.Value);
     437           1 :         Sensor::setMockValue(SensorType::Clt, expectedClt);
     438           1 :         Sensor::setMockValue(SensorType::VehicleSpeed, 15.0);
     439             : 
     440             :         // Target of 1000 rpm
     441           3 :         EXPECT_CALL(dut, getTargetRpm(expectedClt))
     442           3 :                 .WillOnce(Return(1000));
     443             : 
     444             :         // 40% of the way through cranking taper
     445           3 :         EXPECT_CALL(dut, getCrankingTaperFraction())
     446           3 :                 .WillOnce(Return(0.4f));
     447             : 
     448             :         // Determine phase will claim we're idling
     449           3 :         EXPECT_CALL(dut, determinePhase(950, 1000, expectedTps, 15, 0.4f))
     450           3 :                 .WillOnce(Return(ICP::Idling));
     451             : 
     452             :         // Open loop should be asked for an open loop position
     453           3 :         EXPECT_CALL(dut, getOpenLoop(ICP::Idling, 950, expectedClt, expectedTps, 0.4f))
     454           3 :                 .WillOnce(Return(13));
     455             : 
     456             :         // Closed loop should get called
     457           3 :         EXPECT_CALL(dut, getClosedLoop(ICP::Idling, expectedTps.Value, 950, 1000))
     458           3 :                 .WillOnce(Return(7));
     459             : 
     460             :         // Result should be open + closed
     461           1 :         EXPECT_EQ(13 + 7, dut.getIdlePosition(950));
     462           2 : }
     463             : 
     464           4 : TEST(idle_v2, IntegrationClamping) {
     465           1 :         EngineTestHelper eth(engine_type_e::TEST_ENGINE);
     466           1 :         StrictMock<IntegrationIdleMock> dut;
     467             : 
     468           1 :         engineConfiguration->idleMode = IM_AUTO;
     469             : 
     470           1 :         SensorResult expectedTps = 1;
     471           1 :         float expectedClt = 37;
     472           1 :         Sensor::setMockValue(SensorType::DriverThrottleIntent, expectedTps.Value);
     473           1 :         Sensor::setMockValue(SensorType::Clt, expectedClt);
     474           1 :         Sensor::setMockValue(SensorType::VehicleSpeed, 15.0);
     475             : 
     476             :         // Target of 1000 rpm
     477           3 :         EXPECT_CALL(dut, getTargetRpm(expectedClt))
     478           3 :                 .WillOnce(Return(1000));
     479             : 
     480             :         // 50% of the way through cranking taper
     481           3 :         EXPECT_CALL(dut, getCrankingTaperFraction())
     482           3 :                 .WillOnce(Return(0.5f));
     483             : 
     484             :         // Determine phase will claim we're idling
     485           3 :         EXPECT_CALL(dut, determinePhase(950, 1000, expectedTps, 15, 0.5f))
     486           3 :                 .WillOnce(Return(ICP::Idling));
     487             : 
     488             :         // Open loop should be asked for an open loop position
     489           3 :         EXPECT_CALL(dut, getOpenLoop(ICP::Idling, 950, expectedClt, expectedTps, 0.5f))
     490           3 :                 .WillOnce(Return(75));
     491             : 
     492             :         // Closed loop should get called
     493           3 :         EXPECT_CALL(dut, getClosedLoop(ICP::Idling, expectedTps.Value, 950, 1000))
     494           3 :                 .WillOnce(Return(75));
     495             : 
     496             :         // Result would be 75 + 75 = 150, but it should clamp to 100
     497           1 :         EXPECT_EQ(100, dut.getIdlePosition(950));
     498           2 : }

Generated by: LCOV version 1.14