GCC Code Coverage Report


Directory: ./
File: unit_tests/tests/ignition_injection/test_staged_injection.cpp
Date: 2025-10-03 00:57:22
Coverage Exec Excl Total
Lines: 100.0% 35 0 35
Functions: 100.0% 8 0 8
Branches: 60.7% 37 0 61
Decisions: 100.0% 4 - 4

Line Branch Decision Exec Source
1 //
2 // Created by kifir on 11/18/24.
3 //
4
5 #include "pch.h"
6
7 #include "util/test_base.h"
8
9 namespace {
10 constexpr uint8_t TEST_STAGE2_FRACTION = 17;
11 constexpr float TEST_INJECTION_MASS = 12.34f;
12
13 constexpr float TEST_PRIMARY_INJECTOR_DEAD_TIME = 5.6f;
14 constexpr float TEST_PRIMARY_INJECTOR_FLOW = 239.17f;
15 constexpr float TEST_PRIMARY_INJECTOR_BASE_DURATION = TEST_INJECTION_MASS / TEST_PRIMARY_INJECTOR_FLOW * 1000;
16
17 constexpr float TEST_SECONDARY_INJECTOR_DEAD_TIME = 7.8;
18 constexpr float TEST_SECONDARY_INJECTOR_FLOW = 174.17f;
19 constexpr float TEST_SECONDARY_INJECTOR_BASE_DURATION = TEST_INJECTION_MASS / TEST_SECONDARY_INJECTOR_FLOW * 1000;
20
21 2 BattLagCorrTable generateConstantBattLagCorrCurve(const float value) {
22 BattLagCorrTable testBattLagCorrTable;
23 2 testBattLagCorrTable[0].fill(value);
24 2 testBattLagCorrTable[1].fill(value);
25 2 return testBattLagCorrTable;
26 }
27
28 const BattLagCorrTable TEST_PRIMARY_INJECTOR_BATT_LAG_CORR_CURVE = generateConstantBattLagCorrCurve(
29 TEST_PRIMARY_INJECTOR_DEAD_TIME
30 );
31 const BattLagCorrTable TEST_SECONDARY_INJECTOR_BATT_LAG_CORR_CURVE = generateConstantBattLagCorrCurve(
32 TEST_SECONDARY_INJECTOR_DEAD_TIME
33 );
34
35 const EngineConfig TEST_ENGINE_CONFIG = EngineConfig()
36 .setInjectorFlowAsMassFlow(true)
37 .setInjectorFlow(TEST_PRIMARY_INJECTOR_FLOW)
38 .setInjectorBattLagCorr(TEST_PRIMARY_INJECTOR_BATT_LAG_CORR_CURVE)
39 .setInjectorSecondaryFlow(TEST_SECONDARY_INJECTOR_FLOW)
40 .setInjectorSecondaryBattLagCorr(TEST_SECONDARY_INJECTOR_BATT_LAG_CORR_CURVE);
41
42 class StagedInjectionTest : public TestBase<> {
43 protected:
44 void SetUp() override;
45 };
46
47 2 void StagedInjectionTest::SetUp() {
48
1/1
✓ Branch 1 taken 2 times.
2 TestBase::SetUp();
49
50 2 InjectorStagingTable testInjectorStagingTable;
51
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 2 times.
2/2
✓ Decision 'true' taken 12 times.
✓ Decision 'false' taken 2 times.
14 for (int i = 0; i < INJ_STAGING_COUNT; i++) {
52
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 12 times.
2/2
✓ Decision 'true' taken 72 times.
✓ Decision 'false' taken 12 times.
84 for (int j = 0; j < INJ_STAGING_COUNT; j++) {
53 72 testInjectorStagingTable[i][j] = TEST_STAGE2_FRACTION;
54 }
55 };
56
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 getTestPersistentConfiguration().setInjectorStagingTable(testInjectorStagingTable);
57
58
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 getTestLuaScriptExecutor().setFuelAdd(TEST_INJECTION_MASS);
59 2 }
60
61 4 TEST_F(StagedInjectionTest, checkDisabledStagedInjection) {
62 1 setUpEngineConfiguration(TEST_ENGINE_CONFIG);
63
64 1 periodicFastCallback();
65
66
4/8
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✗ Branch 15 not taken.
✓ Branch 16 taken 1 time.
✗ Branch 19 not taken.
✗ Branch 24 not taken.
✗ Branch 27 not taken.
1 EXPECT_EQ(getTestEngineState().getInjectionStage2Fraction(), 0.0f);
67
4/8
✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 time.
✗ Branch 15 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
1 EXPECT_NEAR(
68 getTestEngineState().getInjectionDuration(),
69 TEST_PRIMARY_INJECTOR_BASE_DURATION + TEST_PRIMARY_INJECTOR_DEAD_TIME,
70 EPS5D
71 1 );
72
4/8
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✗ Branch 15 not taken.
✓ Branch 16 taken 1 time.
✗ Branch 19 not taken.
✗ Branch 24 not taken.
✗ Branch 27 not taken.
1 EXPECT_EQ(getTestEngineState().getInjectionDurationStage2(), 0.0f);
73 1 }
74
75 4 TEST_F(StagedInjectionTest, checkEnabledStagedInjection) {
76
3/3
✓ Branch 3 taken 1 time.
✓ Branch 9 taken 1 time.
✓ Branch 12 taken 1 time.
1 setUpEngineConfiguration(TEST_ENGINE_CONFIG.clone().setStagedInjectionEnabled(true));
77
78
1/1
✓ Branch 1 taken 1 time.
1 periodicFastCallback();
79
80
2/2
✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
1 const float injectionStage2Fraction = getTestEngineState().getInjectionStage2Fraction();
81
2/6
✓ Branch 3 taken 1 time.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 time.
✗ Branch 11 not taken.
✗ Branch 16 not taken.
✗ Branch 19 not taken.
1 EXPECT_EQ(injectionStage2Fraction, TEST_STAGE2_FRACTION * 0.01f);
82
4/8
✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 time.
✗ Branch 15 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
1 EXPECT_NEAR(
83 getTestEngineState().getInjectionDuration(),
84 TEST_PRIMARY_INJECTOR_BASE_DURATION * (1 - injectionStage2Fraction) + TEST_PRIMARY_INJECTOR_DEAD_TIME,
85 EPS5D
86 1 );
87
4/8
✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 time.
✗ Branch 15 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
1 EXPECT_NEAR(
88 getTestEngineState().getInjectionDurationStage2(),
89 TEST_SECONDARY_INJECTOR_BASE_DURATION * injectionStage2Fraction + TEST_SECONDARY_INJECTOR_DEAD_TIME,
90 EPS5D
91 1 );
92 1 }
93 }
94