GCC Code Coverage Report


Directory: ./
File: unit_tests/tests/actuators/boost/test_open_loop_multipliers.cpp
Date: 2025-10-03 00:57:22
Coverage Exec Excl Total
Lines: 100.0% 96 0 96
Functions: 100.0% 32 0 32
Branches: 51.7% 31 0 60
Decisions: 100.0% 8 - 8

Line Branch Decision Exec Source
1 //
2 // Created by kifir on 7/30/24.
3 //
4
5 #include "pch.h"
6
7 #include "boost_test_base.h"
8
9 namespace {
10 class OpenLoopMultipliersTest : public BoostTestBase {
11 protected:
12 static constexpr float TEST_BOOST_CONTROL_DUTY_CYCLE = 17.0f;
13 static constexpr float TEST_CLT_BOOST_CORR_BINS[BOOST_CURVE_SIZE] = { 5.9f, 10.8f, 20.7f, 40.6f, 80.5f };
14 static constexpr float TEST_CLT_BOOST_CORR[BOOST_CURVE_SIZE] = { 1.9f, 1.4f, 1.0f, 0.7f, 0.5f };
15 static constexpr float TEST_IAT_BOOST_CORR_BINS[BOOST_CURVE_SIZE] = { 0.1f, 5.2f, 15.3f, 35.4f, 75.5f };
16 static constexpr float TEST_IAT_BOOST_CORR[BOOST_CURVE_SIZE] = { 0.4f, 0.5f, 0.7f, 1.0f, 1.4f };
17
18 virtual void SetUp() override;
19
20 void initTestCltBoostCorr();
21 void initTestIatBoostCorr();
22 void initLuaOpenLoopAdd(const float value);
23 static std::optional<float> getTestCltBoostBin(const int index);
24 static std::optional<float> getTestIatBoostBin(const int index);
25
26 void checkOpenLoop(
27 ValueByIndexRetriever cltExtractorByIndex,
28 ValueByIndexRetriever iatExtractorByIndex,
29 std::function<float(int)> expectedOpenLoopExtractorByIndex
30 );
31
32 void checkOpenLoop(
33 const std::optional<float> clt,
34 const std::optional<float> iat,
35 const float expectedOpenLoop
36 );
37 };
38
39 8 void OpenLoopMultipliersTest::SetUp() {
40 8 BoostTestBase::SetUp();
41
42 8 setTable(config->boostTableOpenLoop, TEST_BOOST_CONTROL_DUTY_CYCLE);
43
44 8 Sensor::setMockValue(SensorType::Tps1, 42.1f);
45 8 }
46
47 5 void OpenLoopMultipliersTest::initTestCltBoostCorr() {
48 5 initTestBoostCurve(TEST_CLT_BOOST_CORR_BINS, config->cltBoostCorrBins, TEST_CLT_BOOST_CORR, config->cltBoostCorr);
49 5 }
50
51 5 void OpenLoopMultipliersTest::initTestIatBoostCorr() {
52 5 initTestBoostCurve(TEST_IAT_BOOST_CORR_BINS, config->iatBoostCorrBins, TEST_IAT_BOOST_CORR, config->iatBoostCorr);
53 5 }
54
55 1 void OpenLoopMultipliersTest::initLuaOpenLoopAdd(const float value) {
56 1 getBoostController().luaOpenLoopAdd = value;
57 1 }
58
59 25 std::optional<float> OpenLoopMultipliersTest::getTestCltBoostBin(const int index) {
60 25 return {TEST_CLT_BOOST_CORR_BINS[index] };
61 }
62
63 25 std::optional<float> OpenLoopMultipliersTest::getTestIatBoostBin(const int index) {
64 25 return {TEST_IAT_BOOST_CORR_BINS[index] };
65 }
66
67 6 void OpenLoopMultipliersTest::checkOpenLoop(
68 ValueByIndexRetriever cltExtractorByIndex,
69 ValueByIndexRetriever iatExtractorByIndex,
70 std::function<float(int)> expectedOpenLoopExtractorByIndex
71 ) {
72
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 6 times.
2/2
✓ Decision 'true' taken 30 times.
✓ Decision 'false' taken 6 times.
36 for (int i = 0; i< BOOST_CURVE_SIZE; i++) {
73 30 checkOpenLoop(cltExtractorByIndex(i), iatExtractorByIndex(i), expectedOpenLoopExtractorByIndex(i));
74 }
75 6 }
76
77 32 void OpenLoopMultipliersTest::checkOpenLoop(
78 const std::optional<float> clt,
79 const std::optional<float> iat,
80 const float expectedOpenLoop
81 ) {
82
2/2
✓ Branch 1 taken 25 times.
✓ Branch 2 taken 7 times.
2/2
✓ Decision 'true' taken 25 times.
✓ Decision 'false' taken 7 times.
32 if (clt.has_value()) {
83
2/2
✓ Branch 1 taken 25 times.
✓ Branch 4 taken 25 times.
25 Sensor::setMockValue(SensorType::Clt, clt.value());
84 }
85
2/2
✓ Branch 1 taken 25 times.
✓ Branch 2 taken 7 times.
2/2
✓ Decision 'true' taken 25 times.
✓ Decision 'false' taken 7 times.
32 if (iat.has_value()) {
86
2/2
✓ Branch 1 taken 25 times.
✓ Branch 4 taken 25 times.
25 Sensor::setMockValue(SensorType::Iat, iat.value());
87 }
88
2/2
✓ Branch 2 taken 32 times.
✓ Branch 5 taken 32 times.
32 const expected<percent_t> openLoop = getBoostController().getOpenLoop(0.0f);
89
1/10
✗ Branch 3 not taken.
✓ Branch 4 taken 32 times.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✗ Branch 16 not taken.
✗ Branch 19 not taken.
✗ Branch 25 not taken.
✗ Branch 30 not taken.
✗ Branch 34 not taken.
✗ Branch 37 not taken.
32 EXPECT_TRUE(openLoop.Valid) << "clt: " << clt.value_or(-1) << ", iat: " << iat.value_or(-1) ;
90
2/10
✓ Branch 2 taken 32 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 32 times.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✗ Branch 27 not taken.
✗ Branch 32 not taken.
✗ Branch 35 not taken.
32 EXPECT_EQ(openLoop.Value, expectedOpenLoop) << "clt: " << clt.value_or(-1) << ", iat: " << iat.value_or(-1) ;
91 32 }
92
93 4 TEST_F(OpenLoopMultipliersTest, openLoopWithDefaultCurves) {
94
2/2
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 1 time.
2/2
✓ Decision 'true' taken 5 times.
✓ Decision 'false' taken 1 time.
6 for (int i = 0; i < BOOST_CURVE_SIZE; i++) {
95
2/8
✓ Branch 4 taken 5 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 5 times.
✗ Branch 12 not taken.
✗ Branch 15 not taken.
✗ Branch 18 not taken.
✗ Branch 23 not taken.
✗ Branch 26 not taken.
5 EXPECT_EQ(config->cltBoostCorr[i], 1.0f) << "index: " << i; // check default multiplier
96
2/8
✓ Branch 4 taken 5 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 5 times.
✗ Branch 12 not taken.
✗ Branch 15 not taken.
✗ Branch 18 not taken.
✗ Branch 23 not taken.
✗ Branch 26 not taken.
5 EXPECT_EQ(config->iatBoostCorr[i], 1.0f) << "index: " << i; // check default multiplier
97 }
98
99
1/1
✓ Branch 5 taken 1 time.
1 checkOpenLoop({}, {}, TEST_BOOST_CONTROL_DUTY_CYCLE);
100 1 }
101
102 4 TEST_F(OpenLoopMultipliersTest, openLoopWithUninitializedCurves) {
103 // Emulate configuration created with old version of TunerStudio, that doesn't support CLT and IAT boost curves:
104 1 setArrayValues(config->cltBoostCorr, 0.0f);
105 1 setArrayValues(config->cltBoostCorrBins, 0.0f);
106 1 setArrayValues(config->iatBoostCorr, 0.0f);
107 1 setArrayValues(config->iatBoostCorrBins, 0.0f);
108
109
1/1
✓ Branch 5 taken 1 time.
1 checkOpenLoop({}, {}, TEST_BOOST_CONTROL_DUTY_CYCLE);
110 1 }
111
112 4 TEST_F(OpenLoopMultipliersTest, openLoopWithCltCorrection) {
113 1 initTestCltBoostCorr();
114
115
1/1
✓ Branch 8 taken 1 time.
2 checkOpenLoop(
116 OpenLoopMultipliersTest::getTestCltBoostBin,
117 OpenLoopMultipliersTest::getTestIatBoostBin,
118 1 [](const int i) -> float { return TEST_BOOST_CONTROL_DUTY_CYCLE * TEST_CLT_BOOST_CORR[i]; }
119 );
120 1 }
121
122 4 TEST_F(OpenLoopMultipliersTest, openLoopWithIatCorrection) {
123 1 initTestIatBoostCorr();
124
125
1/1
✓ Branch 8 taken 1 time.
2 checkOpenLoop(
126 OpenLoopMultipliersTest::getTestCltBoostBin,
127 OpenLoopMultipliersTest::getTestIatBoostBin,
128 1 [](const int i) -> float { return TEST_BOOST_CONTROL_DUTY_CYCLE * TEST_IAT_BOOST_CORR[i]; }
129 );
130 1 }
131
132 4 TEST_F(OpenLoopMultipliersTest, openLoopWithBothCltAndIatCorrection) {
133 1 initTestCltBoostCorr();
134 1 initTestIatBoostCorr();
135
136
1/1
✓ Branch 8 taken 1 time.
2 checkOpenLoop(
137 OpenLoopMultipliersTest::getTestCltBoostBin,
138 OpenLoopMultipliersTest::getTestIatBoostBin,
139 1 [](const int i) -> float {
140 return TEST_BOOST_CONTROL_DUTY_CYCLE * TEST_CLT_BOOST_CORR[i] * TEST_IAT_BOOST_CORR[i];
141 }
142 );
143 1 }
144
145 4 TEST_F(OpenLoopMultipliersTest, openLoopWithBothCltAndIatCorrectionWithMissedIatSensor) {
146 1 initTestCltBoostCorr();
147 1 initTestIatBoostCorr();
148
149
2/2
✓ Branch 5 taken 1 time.
✓ Branch 10 taken 1 time.
2 checkOpenLoop(
150 OpenLoopMultipliersTest::getTestCltBoostBin,
151 emptyValue,
152 1 [](const int i) -> float { return TEST_BOOST_CONTROL_DUTY_CYCLE * TEST_CLT_BOOST_CORR[i]; }
153 );
154 1 }
155
156 4 TEST_F(OpenLoopMultipliersTest, openLoopWithBothCltAndIatCorrectionWithMissedCltSensor) {
157 1 initTestCltBoostCorr();
158 1 initTestIatBoostCorr();
159
160
2/2
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
2 checkOpenLoop(
161 emptyValue,
162 OpenLoopMultipliersTest::getTestIatBoostBin,
163 1 [](const int i) -> float { return TEST_BOOST_CONTROL_DUTY_CYCLE * TEST_IAT_BOOST_CORR[i]; }
164 );
165 1 }
166
167 4 TEST_F(OpenLoopMultipliersTest, openLoopWithBothCltAndIatCorrectionAndLuaOpenLoopAdd) {
168 1 initTestCltBoostCorr();
169 1 initTestIatBoostCorr();
170
171 1 constexpr float TEST_LUA_OPEN_LOOP_ADD = 239.17;
172 1 initLuaOpenLoopAdd(TEST_LUA_OPEN_LOOP_ADD);
173
174
1/1
✓ Branch 8 taken 1 time.
2 checkOpenLoop(
175 OpenLoopMultipliersTest::getTestCltBoostBin,
176 OpenLoopMultipliersTest::getTestIatBoostBin,
177 1 [](const int i) -> float {
178 return TEST_LUA_OPEN_LOOP_ADD
179 + TEST_BOOST_CONTROL_DUTY_CYCLE * TEST_CLT_BOOST_CORR[i] * TEST_IAT_BOOST_CORR[i];
180 }
181 );
182 1 }
183 }
184