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

          Line data    Source code
       1             : #include "pch.h"
       2             : #include "spark_logic.h"
       3             : #include "harley.h"
       4             : #include "fuel_math.h"
       5             : #include "defaults.h"
       6             : 
       7             : using ::testing::_;
       8             : 
       9           4 : TEST(OddFireRunningMode, hd) {
      10             :   // basic engine setup
      11           1 :         EngineTestHelper eth(engine_type_e::HARLEY);
      12           1 :         engineConfiguration->cranking.rpm = 100;
      13           1 :         engineConfiguration->vvtMode[0] = VVT_SINGLE_TOOTH; // need to avoid engine phase sync requirement
      14             :         // let's pretend to have a 32 degree V odd fire engine.
      15           1 :         float cylinderOne = -19;
      16           1 :         float cylinderTwo = 13;
      17           1 :         engineConfiguration->timing_offset_cylinder[0] = cylinderOne;
      18           1 :         engineConfiguration->timing_offset_cylinder[1] = cylinderTwo;
      19           1 :         angle_t timing = 1;
      20           1 :         setTable(config->ignitionTable, timing); // run mode timing
      21             : 
      22             :   // we need some fuel duration so let's mock airmass just to have legit fuel, we do not care for amount here at all
      23           3 :         EXPECT_CALL(*eth.mockAirmass, getAirmass(/*any rpm*/_, _))
      24           3 :                 .WillRepeatedly(Return(AirmassResult{0.1008f, 50.0f}));
      25             : 
      26           1 :         engineConfiguration->crankingTimingAngle = timing;
      27           1 :         engine->tdcMarkEnabled = false; // reduce event queue noise TODO extract helper method
      28           1 :         engineConfiguration->camInputs[0] = Gpio::Unassigned;
      29           1 :         eth.setTriggerType(trigger_type_e::TT_HALF_MOON);
      30             :         // end of configuration
      31             : 
      32             :   // send fake crank signal events so that trigger handler schedules actuators
      33           1 :         eth.fireTriggerEvents2(2 /* count */ , 60 /* ms */);
      34           1 :         LimpState limitedSparkState = getLimpManager()->allowIgnition();
      35           1 :         ASSERT_TRUE(limitedSparkState.value);
      36           1 :         ASSERT_EQ(limitedSparkState.reason, ClearReason::None);
      37           1 :         ASSERT_EQ(IM_SIMULTANEOUS, getCurrentInjectionMode()); // still spinning up
      38           1 :         ASSERT_NEAR(0.027, getInjectionMass(200), EPS3D);
      39             : 
      40             : //      ASSERT_NEAR(-220.0, eth.timeToAngle(-73.333333), EPS3D);
      41             : //      ASSERT_NEAR(140, eth.timeToAngle(46.66666), EPS3D);
      42             : //      ASSERT_NEAR(-200.0, eth.timeToAngle(-66.66666), EPS3D);
      43             : //      ASSERT_NEAR(160.0, eth.timeToAngle(53.333333), EPS3D);
      44             : //      ASSERT_NEAR(-168.0, eth.timeToAngle(-56.0), EPS3D);
      45             : //      ASSERT_NEAR(32, eth.timeToAngle(10.66666666), EPS3D);
      46             : 
      47           1 :         angle_t expectedAngle3 = -180 + cylinderTwo - timing;
      48             : 
      49           1 :         ASSERT_EQ( 8,  engine->executor.size());
      50           1 :         eth.assertEvent5("spark down#3", 3, (void*)fireSparkAndPrepareNextSchedule, eth.angleToTimeUs(expectedAngle3));
      51             : 
      52           1 :         angle_t expectedAngle7 = 180 + cylinderOne - timing;
      53           1 :         eth.assertEvent5("spark down#7", 7, (void*)fireSparkAndPrepareNextSchedule, eth.angleToTimeUs(expectedAngle7));
      54             : 
      55           1 :         eth.assertRpm( 500, "spinning-RPM#1");
      56             : 
      57           1 :         engine->executor.executeAll(eth.getTimeNowUs() + MS2US(1000000));
      58             : 
      59           1 :         eth.fireTriggerEvents2(2 /* count */ , 60 /* ms */);
      60           1 :         ASSERT_EQ(IM_SEQUENTIAL, getCurrentInjectionMode());
      61           1 :         ASSERT_NEAR(0.0069257142022, getInjectionMass(200), EPS3D);
      62             : 
      63           1 :         ASSERT_EQ( 8,  engine->executor.size());
      64           1 :         eth.assertEvent5("fuel down2#1", 1, (void*)turnInjectionPinLow, eth.angleToTimeUs(180 + PORT_INJECTION_OFFSET + cylinderOne));
      65           1 :         eth.assertEvent5("spark down2#3", 3, (void*)fireSparkAndPrepareNextSchedule, eth.angleToTimeUs(-180 + cylinderTwo - timing));
      66           1 :         eth.assertEvent5("fuel down2#6", 6, (void*)turnInjectionPinLow, eth.angleToTimeUs(540 + PORT_INJECTION_OFFSET + cylinderTwo));
      67           1 :         eth.assertEvent5("spark down2#7", 7, (void*)fireSparkAndPrepareNextSchedule, eth.angleToTimeUs(180 + cylinderOne - timing));
      68           1 : }

Generated by: LCOV version 1.14