Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | // | |||
2 | // Created by kifir on 11/21/24. | |||
3 | // | |||
4 | ||||
5 | #include "pch.h" | |||
6 | ||||
7 | #include "util/test_base.h" | |||
8 | ||||
9 | namespace { | |||
10 | constexpr float TEST_PRIMARY_INJECTOR_FUEL_REFERENCE_PRESSURE = 5423.1f; | |||
11 | constexpr float TEST_SECONDARY_INJECTOR_FUEL_REFERENCE_PRESSURE = 678.9f; | |||
12 | constexpr float TEST_MAP = 78.9f; | |||
13 | constexpr float TEST_BAROMETRIC_PRESSURE = 67.8f; | |||
14 | constexpr float TEST_FUEL_PRESSURE_INJECTOR = 76.5f; | |||
15 | ||||
16 | constexpr float TEST_PRIMARY_INJECTOR_FIXED_RAIL_FUEL_DIFFERENTIAL_PRESSURE | |||
17 | = TEST_PRIMARY_INJECTOR_FUEL_REFERENCE_PRESSURE + TEST_BAROMETRIC_PRESSURE - TEST_MAP; | |||
18 | constexpr float TEST_SECONDARY_INJECTOR_FIXED_RAIL_FUEL_DIFFERENTIAL_PRESSURE | |||
19 | = TEST_SECONDARY_INJECTOR_FUEL_REFERENCE_PRESSURE + TEST_BAROMETRIC_PRESSURE - TEST_MAP; | |||
20 | constexpr float TEST_SENSED_RAIL_ABSOLUTE_FUEL_DIFFERENTIAL_PRESSURE | |||
21 | = TEST_FUEL_PRESSURE_INJECTOR - TEST_MAP; | |||
22 | constexpr float TEST_SENSED_RAIL_GAUGE_FUEL_DIFFERENTIAL_PRESSURE | |||
23 | = TEST_FUEL_PRESSURE_INJECTOR + TEST_BAROMETRIC_PRESSURE - TEST_MAP; | |||
24 | ||||
25 | const EngineConfig TEST_ENGINE_CONFIG = EngineConfig() | |||
26 | .setFuelReferencePressure(TEST_PRIMARY_INJECTOR_FUEL_REFERENCE_PRESSURE) | |||
27 | .setSecondaryInjectorFuelReferencePressure(TEST_SECONDARY_INJECTOR_FUEL_REFERENCE_PRESSURE); | |||
28 | ||||
29 | class FuelDifferentialPressureTest : public TestBase<> { | |||
30 | protected: | |||
31 | void SetUp() override; | |||
32 | ||||
33 | void checkFuelDifferrentialPressure( | |||
34 | const EngineConfig& engineConfig, | |||
35 | std::optional<float> primaryInjectorFuelDifferentialPressure, | |||
36 | std::optional<float> secondaryInjectorFuelDifferentialPressure, | |||
37 | const char* context | |||
38 | ); | |||
39 | private: | |||
40 | expected<float> getPrimaryInjectorFuelDifferentialPressure(); | |||
41 | expected<float> getSecondaryInjectorFuelDifferentialPressure(); | |||
42 | }; | |||
43 | ||||
44 | 8 | void FuelDifferentialPressureTest::SetUp(){ | ||
45 | 8 | TestBase::SetUp(); | ||
46 | ||||
47 | 8 | Sensor::setMockValue(SensorType::Map, TEST_MAP); | ||
48 | 8 | Sensor::setMockValue(SensorType::BarometricPressure, TEST_BAROMETRIC_PRESSURE); | ||
49 | 8 | Sensor::setMockValue(SensorType::FuelPressureInjector, TEST_FUEL_PRESSURE_INJECTOR); | ||
50 | 8 | } | ||
51 | ||||
52 | 8 | void FuelDifferentialPressureTest::checkFuelDifferrentialPressure( | ||
53 | const EngineConfig& engineConfig, | |||
54 | const std::optional<float> expectedPrimaryInjectorFuelDifferentialPressure, | |||
55 | const std::optional<float> expectedSecondaryInjectorFuelDifferentialPressure, | |||
56 | const char* const context | |||
57 | ) { | |||
58 |
1/1✓ Branch 1 taken 8 times.
|
8 | setUpEngineConfiguration(engineConfig); | |
59 | 8 | constexpr float INVALID_PRESSURE = -1.0f; | ||
60 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 2 taken 2 times.
|
2/2✓ Decision 'true' taken 6 times.
✓ Decision 'false' taken 2 times.
|
8 | if (expectedPrimaryInjectorFuelDifferentialPressure.has_value()) { |
61 |
2/7✓ Branch 2 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
|
6 | EXPECT_NE(expectedPrimaryInjectorFuelDifferentialPressure, INVALID_PRESSURE) << context; | |
62 |
4/8✓ Branch 3 taken 6 times.
✓ Branch 7 taken 6 times.
✓ Branch 10 taken 6 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 6 times.
✗ Branch 18 not taken.
✗ Branch 22 not taken.
✗ Branch 25 not taken.
|
6 | EXPECT_NEAR( | |
63 | expectedPrimaryInjectorFuelDifferentialPressure.value(), | |||
64 | getPrimaryInjectorFuelDifferentialPressure().value_or(INVALID_PRESSURE), | |||
65 | EPS5D | |||
66 |
0/1✗ Branch 1 not taken.
|
6 | ) << context; | |
67 | } else { | |||
68 |
2/7✓ Branch 3 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 21 not taken.
✗ Branch 24 not taken.
|
2 | EXPECT_FALSE(getPrimaryInjectorFuelDifferentialPressure().Valid); | |
69 | } | |||
70 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 2 taken 2 times.
|
2/2✓ Decision 'true' taken 6 times.
✓ Decision 'false' taken 2 times.
|
8 | if (expectedSecondaryInjectorFuelDifferentialPressure.has_value()) { |
71 |
3/8✓ Branch 2 taken 6 times.
✓ Branch 5 taken 6 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6 times.
✗ Branch 12 not taken.
✗ Branch 15 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
|
6 | EXPECT_NE(expectedSecondaryInjectorFuelDifferentialPressure.value(), INVALID_PRESSURE) << context; | |
72 |
4/8✓ Branch 3 taken 6 times.
✓ Branch 7 taken 6 times.
✓ Branch 10 taken 6 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 6 times.
✗ Branch 18 not taken.
✗ Branch 22 not taken.
✗ Branch 25 not taken.
|
6 | EXPECT_NEAR( | |
73 | expectedSecondaryInjectorFuelDifferentialPressure.value(), | |||
74 | getSecondaryInjectorFuelDifferentialPressure().value_or(INVALID_PRESSURE), | |||
75 | EPS5D | |||
76 |
0/1✗ Branch 1 not taken.
|
6 | ) << context; | |
77 | } else { | |||
78 |
2/7✓ Branch 3 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 21 not taken.
✗ Branch 24 not taken.
|
2 | EXPECT_FALSE(getSecondaryInjectorFuelDifferentialPressure().Valid); | |
79 | } | |||
80 | 8 | } | ||
81 | ||||
82 | 8 | expected<float> FuelDifferentialPressureTest::getPrimaryInjectorFuelDifferentialPressure() { | ||
83 | 8 | return getModule<InjectorModelPrimary>().getFuelDifferentialPressure(); | ||
84 | } | |||
85 | ||||
86 | 8 | expected<float> FuelDifferentialPressureTest::getSecondaryInjectorFuelDifferentialPressure() { | ||
87 | 8 | return getModule<InjectorModelSecondary>().getFuelDifferentialPressure(); | ||
88 | } | |||
89 | ||||
90 | 4 | TEST_F(FuelDifferentialPressureTest, checkDefault) { | ||
91 |
1/1✓ Branch 5 taken 1 time.
|
1 | checkFuelDifferrentialPressure( | |
92 | TEST_ENGINE_CONFIG, | |||
93 | {}, | |||
94 | {}, | |||
95 | "default" | |||
96 | ); | |||
97 | 1 | } | ||
98 | ||||
99 | 4 | TEST_F(FuelDifferentialPressureTest, checkNone) { | ||
100 |
1/1✓ Branch 6 taken 1 time.
|
3 | checkFuelDifferrentialPressure( | |
101 |
1/1✓ Branch 1 taken 1 time.
|
2 | TEST_ENGINE_CONFIG.clone() | |
102 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setInjectorCompensationMode(ICM_None) | |
103 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setSecondaryInjectorCompensationMode(ICM_None), | |
104 | {}, | |||
105 | {}, | |||
106 | "primaryInjectorCompensationMode=ICM_None, " | |||
107 | "secondaryInjectorCompensationMode=ICM_None" | |||
108 | ); | |||
109 | 1 | } | ||
110 | ||||
111 | 4 | TEST_F(FuelDifferentialPressureTest, checkFixedRailPressure) { | ||
112 |
1/1✓ Branch 6 taken 1 time.
|
3 | checkFuelDifferrentialPressure( | |
113 |
1/1✓ Branch 1 taken 1 time.
|
2 | TEST_ENGINE_CONFIG.clone() | |
114 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setInjectorCompensationMode(ICM_FixedRailPressure) | |
115 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setSecondaryInjectorCompensationMode(ICM_FixedRailPressure), | |
116 | { TEST_PRIMARY_INJECTOR_FIXED_RAIL_FUEL_DIFFERENTIAL_PRESSURE }, | |||
117 | { TEST_SECONDARY_INJECTOR_FIXED_RAIL_FUEL_DIFFERENTIAL_PRESSURE }, | |||
118 | "primaryInjectorCompensationMode=ICM_FixedRailPressure, " | |||
119 | "secondaryInjectorCompensationMode=ICM_FixedRailPressure" | |||
120 | ); | |||
121 | 1 | } | ||
122 | ||||
123 | 4 | TEST_F(FuelDifferentialPressureTest, checkSensedRailPressureDefault) { | ||
124 |
1/1✓ Branch 6 taken 1 time.
|
3 | checkFuelDifferrentialPressure( | |
125 |
1/1✓ Branch 1 taken 1 time.
|
2 | TEST_ENGINE_CONFIG.clone() | |
126 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setInjectorCompensationMode(ICM_SensedRailPressure) | |
127 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setSecondaryInjectorCompensationMode(ICM_SensedRailPressure), | |
128 | { TEST_SENSED_RAIL_ABSOLUTE_FUEL_DIFFERENTIAL_PRESSURE }, | |||
129 | { TEST_SENSED_RAIL_ABSOLUTE_FUEL_DIFFERENTIAL_PRESSURE }, | |||
130 | "primaryInjectorCompensationMode=ICM_SensedRailPressure, " | |||
131 | "secondaryInjectorCompensationMode=ICM_SensedRailPressure" | |||
132 | ); | |||
133 | 1 | } | ||
134 | ||||
135 | 4 | TEST_F(FuelDifferentialPressureTest, checkSensedRailPressureAbsolute) { | ||
136 |
1/1✓ Branch 6 taken 1 time.
|
3 | checkFuelDifferrentialPressure( | |
137 |
1/1✓ Branch 1 taken 1 time.
|
2 | TEST_ENGINE_CONFIG.clone() | |
138 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setInjectorCompensationMode(ICM_SensedRailPressure) | |
139 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setSecondaryInjectorCompensationMode(ICM_SensedRailPressure) | |
140 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setFuelPressureSensorMode(FPM_Absolute), | |
141 | { TEST_SENSED_RAIL_ABSOLUTE_FUEL_DIFFERENTIAL_PRESSURE }, | |||
142 | { TEST_SENSED_RAIL_ABSOLUTE_FUEL_DIFFERENTIAL_PRESSURE }, | |||
143 | "primaryInjectorCompensationMode=ICM_SensedRailPressure, " | |||
144 | "secondaryInjectorCompensationMode=ICM_SensedRailPressure, " | |||
145 | "fuelPressureSensorMode=FPM_Absolute" | |||
146 | ); | |||
147 | 1 | } | ||
148 | ||||
149 | 4 | TEST_F(FuelDifferentialPressureTest, checkSensedRailPressureGauge) { | ||
150 |
1/1✓ Branch 6 taken 1 time.
|
3 | checkFuelDifferrentialPressure( | |
151 |
1/1✓ Branch 1 taken 1 time.
|
2 | TEST_ENGINE_CONFIG.clone() | |
152 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setInjectorCompensationMode(ICM_SensedRailPressure) | |
153 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setSecondaryInjectorCompensationMode(ICM_SensedRailPressure) | |
154 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setFuelPressureSensorMode(FPM_Gauge), | |
155 | { TEST_SENSED_RAIL_GAUGE_FUEL_DIFFERENTIAL_PRESSURE }, | |||
156 | { TEST_SENSED_RAIL_GAUGE_FUEL_DIFFERENTIAL_PRESSURE }, | |||
157 | "primaryInjectorCompensationMode=ICM_SensedRailPressure, " | |||
158 | "secondaryInjectorCompensationMode=ICM_SensedRailPressure, " | |||
159 | "fuelPressureSensorMode=FPM_Gauge" | |||
160 | ); | |||
161 | 1 | } | ||
162 | ||||
163 | 4 | TEST_F(FuelDifferentialPressureTest, checkSensedRailPressureDifferential) { | ||
164 |
1/1✓ Branch 6 taken 1 time.
|
3 | checkFuelDifferrentialPressure( | |
165 |
1/1✓ Branch 1 taken 1 time.
|
2 | TEST_ENGINE_CONFIG.clone() | |
166 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setInjectorCompensationMode(ICM_SensedRailPressure) | |
167 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setSecondaryInjectorCompensationMode(ICM_SensedRailPressure) | |
168 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setFuelPressureSensorMode(FPM_Differential), | |
169 | { TEST_FUEL_PRESSURE_INJECTOR }, | |||
170 | { TEST_FUEL_PRESSURE_INJECTOR }, | |||
171 | "primaryInjectorCompensationMode=ICM_SensedRailPressure, " | |||
172 | "secondaryInjectorCompensationMode=ICM_SensedRailPressure, " | |||
173 | "fuelPressureSensorMode=FPM_Differential" | |||
174 | ); | |||
175 | 1 | } | ||
176 | ||||
177 | 4 | TEST_F(FuelDifferentialPressureTest, checkMix) { | ||
178 |
1/1✓ Branch 6 taken 1 time.
|
3 | checkFuelDifferrentialPressure( | |
179 |
1/1✓ Branch 1 taken 1 time.
|
2 | TEST_ENGINE_CONFIG.clone() | |
180 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setInjectorCompensationMode(ICM_FixedRailPressure) | |
181 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setSecondaryInjectorCompensationMode(ICM_SensedRailPressure), | |
182 | { TEST_PRIMARY_INJECTOR_FIXED_RAIL_FUEL_DIFFERENTIAL_PRESSURE }, | |||
183 | { TEST_SENSED_RAIL_ABSOLUTE_FUEL_DIFFERENTIAL_PRESSURE }, | |||
184 | "primaryInjectorCompensationMode=ICM_FixedRailPressure, " | |||
185 | "secondaryInjectorCompensationMode=ICM_SensedRailPressure" | |||
186 | ); | |||
187 | 1 | } | ||
188 | } | |||
189 |