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

          Line data    Source code
       1             : /*
       2             :  * @file injection_mode_transition.cpp
       3             :  *
       4             :  *  Created on: Jul 19, 2020
       5             :  * @author Andrey Belomutskiy, (c) 2012-2020
       6             :  */
       7             : 
       8             : #include "pch.h"
       9             : 
      10             : using ::testing::_;
      11             : 
      12          11 : static void doRevolution(EngineTestHelper& eth, int periodMs) {
      13          11 :         float halfToothTime = (periodMs / 6.0f) / 2;
      14             : 
      15          11 :         eth.smartFireRise(halfToothTime);
      16          11 :         eth.fireFall(halfToothTime);
      17          11 :         eth.smartFireRise(halfToothTime);
      18          11 :         eth.fireFall(halfToothTime);
      19          11 :         eth.smartFireRise(halfToothTime);
      20          11 :         eth.fireFall(halfToothTime);
      21             : 
      22             :         // now missing tooth
      23          11 :         eth.smartFireRise(halfToothTime);
      24          11 :         eth.fireFall(3 * halfToothTime);
      25             : 
      26             :         // This tooth is the sync point!
      27          11 :         eth.smartFireRise(halfToothTime);
      28          11 :         eth.fireFall(halfToothTime);
      29          11 : }
      30             : 
      31             : // https://github.com/rusefi/rusefi/issues/1592
      32           4 : TEST(fuelControl, transitionIssue1592) {
      33           1 :         EngineTestHelper eth(engine_type_e::TEST_ENGINE);
      34           1 :         engine->tdcMarkEnabled = false;
      35           1 :         setupSimpleTestEngineWithMafAndTT_ONE_trigger(&eth, IM_SEQUENTIAL);
      36             : 
      37           3 :         EXPECT_CALL(*eth.mockAirmass, getAirmass(500, _))
      38           3 :                 .WillRepeatedly(Return(AirmassResult{0.1008f, 50.0f}));
      39             : 
      40             :         // This is easiest to trip on a wheel that requires sync
      41           1 :         engineConfiguration->trigger.customTotalToothCount = 6;
      42           1 :         engineConfiguration->trigger.customSkippedToothCount = 1;
      43           1 :         eth.setTriggerType(trigger_type_e::TT_TOOTHED_WHEEL);
      44           1 :     setCamOperationMode();
      45           1 :         engineConfiguration->isFasterEngineSpinUpEnabled = true;
      46             : 
      47           1 :         setTable(config->injectionPhase, 0.0f);
      48           1 :         setArrayValues(config->crankingFuelCoef, 1.0f);
      49           1 :         setArrayValues(config->crankingCycleCoef, 1.0f);
      50             : 
      51           1 :         engineConfiguration->globalTriggerAngleOffset = 20;
      52             : 
      53             :         // Yes, this is a ton of fuel but it makes the repro easier
      54           1 :         engineConfiguration->cranking.baseFuel = 213.6;
      55           1 :         engineConfiguration->cranking.rpm = 501;
      56             : 
      57             :         // Test the transition from batch cranking to sequential running
      58           1 :         engineConfiguration->crankingInjectionMode = IM_BATCH;
      59             : 
      60             :         // First sync point will schedule cranking pulse since we're in "faster spin up" mode
      61           1 :         doRevolution(eth, 240);
      62             : 
      63             :         {
      64             :                 // Injector 2 should be scheduled to open then close
      65           1 :                 void* inj2 = reinterpret_cast<void*>(&engine->injectionEvents.elements[1]);
      66             : 
      67           1 :                 ASSERT_EQ(engine->executor.size(), 2);
      68             : 
      69             :                 // Check that the action is correct - we don't care about the timing necessarily
      70           1 :                 auto sched_open = engine->executor.getForUnitTest(0);
      71           1 :                 ASSERT_EQ(sched_open->action.getArgument(), inj2);
      72           1 :                 ASSERT_EQ(sched_open->action.getCallback(), (void(*)(void*))turnInjectionPinHigh);
      73             : 
      74           1 :                 auto sched_close = engine->executor.getForUnitTest(1);
      75             :                 // Next action should be closing the same injector
      76           1 :                 ASSERT_EQ(sched_close->action.getArgument(), inj2);
      77           1 :                 ASSERT_EQ(sched_close->action.getCallback(), (void(*)(void*))turnInjectionPinLow);
      78             :         }
      79             : 
      80             :         // Run the engine for some revs
      81          11 :         for (size_t i = 0; i < 10; i++) {
      82          10 :                 doRevolution(eth, 150);
      83             :         }
      84             : 
      85             :         // Check that no injectors are stuck open
      86             :         // Injectors 1/3 should be open
      87           1 :         EXPECT_EQ(enginePins.injectors[0].getOverlappingCounter(), 1);
      88           1 :         EXPECT_EQ(enginePins.injectors[1].getOverlappingCounter(), 0);
      89           1 :         EXPECT_EQ(enginePins.injectors[2].getOverlappingCounter(), 1);
      90           1 :         EXPECT_EQ(enginePins.injectors[3].getOverlappingCounter(), 0);
      91           1 : }

Generated by: LCOV version 1.14