LCOV - code coverage report
Current view: top level - unit_tests/tests/ignition_injection - test_fuelCut.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 94 94 100.0 %
Date: 2024-04-25 02:23:43 Functions: 8 8 100.0 %

          Line data    Source code
       1             : /*
       2             :  * @file test_fuelCut.cpp
       3             :  *
       4             :  * @date Mar 22, 2018
       5             :  * @author Andrey Belomutskiy, (c) 2012-2020
       6             :  */
       7             : 
       8             : #include "pch.h"
       9             : 
      10             : #include "event_queue.h"
      11             : 
      12             : using ::testing::_;
      13             : 
      14             : // Define some helpers for not-cut and cut
      15             : #define EXPECT_NORMAL() EXPECT_FLOAT_EQ(normalInjDuration, engine->engineState.injectionDuration)
      16             : #define EXPECT_CUT() EXPECT_FLOAT_EQ(0, engine->engineState.injectionDuration)
      17             : 
      18           4 : TEST(fuelCut, coasting) {
      19           1 :         EngineTestHelper eth(engine_type_e::TEST_ENGINE);
      20           3 :         EXPECT_CALL(*eth.mockAirmass, getAirmass(_, _))
      21           3 :                 .WillRepeatedly(Return(AirmassResult{0.1008f, 50.0f}));
      22             : 
      23             :         // configure coastingFuelCut
      24           1 :         engineConfiguration->coastingFuelCutEnabled = true;
      25           1 :         engineConfiguration->coastingFuelCutRpmLow = 1300;
      26           1 :         engineConfiguration->coastingFuelCutRpmHigh = 1500;
      27           1 :         engineConfiguration->coastingFuelCutTps = 2;
      28           1 :         engineConfiguration->coastingFuelCutClt = 30;
      29           1 :         engineConfiguration->coastingFuelCutMap = 100;
      30             :         // set cranking threshold
      31           1 :         engineConfiguration->cranking.rpm = 999;
      32             : 
      33             :         // basic engine setup
      34           1 :         setupSimpleTestEngineWithMafAndTT_ONE_trigger(&eth);
      35             : 
      36           1 :         Sensor::setMockValue(SensorType::Map, 0);
      37             : 
      38             :         // mock CLT - just above threshold ('hot engine')
      39           1 :         float hotClt = engineConfiguration->coastingFuelCutClt + 1;
      40           1 :         Sensor::setMockValue(SensorType::Clt, hotClt);
      41             :         // mock TPS - throttle is opened
      42           1 :         Sensor::setMockValue(SensorType::DriverThrottleIntent, 60);
      43             :         // set 'running' RPM - just above RpmHigh threshold
      44           1 :         Sensor::setMockValue(SensorType::Rpm, engineConfiguration->coastingFuelCutRpmHigh + 1);
      45             :         // 'advance' time (amount doesn't matter)
      46           1 :         eth.moveTimeForwardUs(1000);
      47             : 
      48           1 :         const float normalInjDuration = 1.5f;
      49             :         /*
      50             :          * We need to pass through all rpm changes (high-mid-low-mid-high) because of state-machine
      51             :          */
      52             : 
      53             :         // process
      54           1 :         eth.engine.periodicFastCallback();
      55             : 
      56             :         // this is normal injection mode (the throttle is opened), no fuel cut-off
      57           1 :         EXPECT_NORMAL();
      58             : 
      59             :         // 'releasing' the throttle
      60           1 :         Sensor::setMockValue(SensorType::DriverThrottleIntent, 0);
      61           1 :         eth.engine.periodicFastCallback();
      62             : 
      63             :         // Fuel cut-off is enabled now
      64           1 :         EXPECT_CUT();
      65             : 
      66             :         // Now drop the CLT below threshold
      67           1 :         Sensor::setMockValue(SensorType::Clt, engineConfiguration->coastingFuelCutClt - 1);
      68           1 :         eth.engine.periodicFastCallback();
      69             : 
      70             :         // Fuel cut-off should be diactivated - the engine is 'cold'
      71           1 :         EXPECT_NORMAL();
      72             : 
      73             :         // restore CLT
      74           1 :         Sensor::setMockValue(SensorType::Clt, hotClt);
      75             :         // And set RPM - somewhere between RpmHigh and RpmLow threshold
      76           1 :         Sensor::setMockValue(SensorType::Rpm, (engineConfiguration->coastingFuelCutRpmHigh + engineConfiguration->coastingFuelCutRpmLow) / 2);
      77           1 :         eth.engine.periodicFastCallback();
      78             : 
      79             :         // Fuel cut-off is enabled - nothing should change
      80           1 :         EXPECT_NORMAL();
      81             : 
      82             :         // Now drop RPM just below RpmLow threshold
      83           1 :         Sensor::setMockValue(SensorType::Rpm, engineConfiguration->coastingFuelCutRpmLow - 1);
      84           1 :         eth.engine.periodicFastCallback();
      85             : 
      86             :         // Fuel cut-off is now disabled (the engine is idling)
      87           1 :         EXPECT_NORMAL();
      88             : 
      89             :         // Now change RPM just below RpmHigh threshold
      90           1 :         Sensor::setMockValue(SensorType::Rpm, engineConfiguration->coastingFuelCutRpmHigh - 1);
      91           1 :         eth.engine.periodicFastCallback();
      92             : 
      93             :         // Fuel cut-off is still disabled
      94           1 :         EXPECT_NORMAL();
      95             : 
      96             :         // Now set RPM just above RpmHigh threshold
      97           1 :         Sensor::setMockValue(SensorType::Rpm, engineConfiguration->coastingFuelCutRpmHigh + 1);
      98           1 :         eth.engine.periodicFastCallback();
      99             : 
     100             :         // Fuel cut-off is active again!
     101           1 :         EXPECT_CUT();
     102             : 
     103             :         // Configure vehicle speed thresholds
     104           1 :         engineConfiguration->coastingFuelCutVssHigh = 50;
     105           1 :         engineConfiguration->coastingFuelCutVssLow = 40;
     106             : 
     107             :         // High speed, should still be cut.
     108           1 :         Sensor::setMockValue(SensorType::VehicleSpeed, 55);
     109           1 :         eth.engine.periodicFastCallback();
     110           1 :         EXPECT_CUT();
     111             : 
     112             :         // Between thresholds, still cut.
     113           1 :         Sensor::setMockValue(SensorType::VehicleSpeed, 45);
     114           1 :         eth.engine.periodicFastCallback();
     115           1 :         EXPECT_CUT();
     116             : 
     117             :         // Below lower threshold, normal fuel resumes
     118           1 :         Sensor::setMockValue(SensorType::VehicleSpeed, 35);
     119           1 :         eth.engine.periodicFastCallback();
     120           1 :         EXPECT_NORMAL();
     121             : 
     122             :         // Between thresholds, still normal.
     123           1 :         Sensor::setMockValue(SensorType::VehicleSpeed, 45);
     124           1 :         eth.engine.periodicFastCallback();
     125           1 :         EXPECT_NORMAL();
     126             : 
     127             :         // Back above upper, cut again.
     128           1 :         Sensor::setMockValue(SensorType::VehicleSpeed, 55);
     129           1 :         eth.engine.periodicFastCallback();
     130           1 :         EXPECT_CUT();
     131           2 : }
     132             : 
     133           4 : TEST(fuelCut, delay) {
     134           1 :         EngineTestHelper eth(engine_type_e::TEST_ENGINE);
     135           3 :         EXPECT_CALL(*eth.mockAirmass, getAirmass(_, _))
     136           3 :                 .WillRepeatedly(Return(AirmassResult{0.1008f, 50.0f}));
     137             : 
     138             :         // configure coastingFuelCut
     139           1 :         engineConfiguration->coastingFuelCutEnabled = true;
     140           1 :         engineConfiguration->coastingFuelCutRpmLow = 1300;
     141           1 :         engineConfiguration->coastingFuelCutRpmHigh = 1500;
     142           1 :         engineConfiguration->coastingFuelCutTps = 2;
     143           1 :         engineConfiguration->coastingFuelCutClt = 30;
     144           1 :         engineConfiguration->coastingFuelCutMap = 100;
     145             :         // set cranking threshold
     146           1 :         engineConfiguration->cranking.rpm = 999;
     147             : 
     148             :         // delay is 1 second
     149           1 :         engineConfiguration->dfcoDelay = 1.0f;
     150             : 
     151             :         // basic engine setup
     152           1 :         setupSimpleTestEngineWithMafAndTT_ONE_trigger(&eth);
     153             : 
     154           1 :         Sensor::setMockValue(SensorType::Map, 0);
     155             : 
     156             :         // mock CLT - just above threshold ('hot engine')
     157           1 :         float hotClt = engineConfiguration->coastingFuelCutClt + 1;
     158           1 :         Sensor::setMockValue(SensorType::Clt, hotClt);
     159             :         // mock TPS - throttle is opened
     160           1 :         Sensor::setMockValue(SensorType::DriverThrottleIntent, 60);
     161             :         // set 'running' RPM - just above RpmHigh threshold
     162           1 :         Sensor::setMockValue(SensorType::Rpm, engineConfiguration->coastingFuelCutRpmHigh + 1);
     163             :         // 'advance' time (amount doesn't matter)
     164           1 :         eth.moveTimeForwardUs(1000);
     165             : 
     166           1 :         const float normalInjDuration = 1.5f;
     167             : 
     168             :         extern int timeNowUs;
     169           1 :         timeNowUs = 1e6;
     170             : 
     171             :         // process
     172           1 :         eth.engine.periodicFastCallback();
     173             : 
     174             :         // this is normal injection mode (the throttle is opened), no fuel cut-off
     175           1 :         EXPECT_NORMAL();
     176             : 
     177             :         // 'releasing' the throttle
     178           1 :         Sensor::setMockValue(SensorType::DriverThrottleIntent, 0);
     179           1 :         eth.engine.periodicFastCallback();
     180             : 
     181             :         // Shouldn't cut yet, since not enough time has elapsed
     182           1 :         EXPECT_NORMAL();
     183             : 
     184             :         // Change nothing else, but advance time and update again
     185           1 :         timeNowUs += 0.9e6;
     186           1 :         eth.engine.periodicFastCallback();
     187             : 
     188             :         // too soon, still no cut
     189           1 :         EXPECT_NORMAL();
     190             : 
     191             :         // Change nothing else, but advance time and update again
     192           1 :         timeNowUs += 0.2e6;
     193           1 :         eth.engine.periodicFastCallback();
     194             : 
     195             :         // Should now be cut!
     196           1 :         EXPECT_CUT();
     197             : 
     198             :         // Put the throtle back, and it should come back instantly
     199           1 :         Sensor::setMockValue(SensorType::DriverThrottleIntent, 30);
     200           1 :         eth.engine.periodicFastCallback();
     201           1 :         EXPECT_NORMAL();
     202           2 : }

Generated by: LCOV version 1.14