Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | // | |||
2 | // Created by kifir on 10/2/24. | |||
3 | // | |||
4 | ||||
5 | #include "pch.h" | |||
6 | ||||
7 | #include "util/test_base.h" | |||
8 | ||||
9 | namespace { | |||
10 | constexpr switch_input_pin_e TEST_TORQUE_REDUCTION_BUTTON_PIN = Gpio::F13; | |||
11 | constexpr float TEST_TORQUE_REDUCTION_TIME = 239.17; | |||
12 | constexpr float IMMEDIATELY = 0.0f; | |||
13 | ||||
14 | class ShiftTorqueReductionTimeConditionTest : public TestBase<> { | |||
15 | protected: | |||
16 | void waitAndCheckTimeCondition( | |||
17 | float timeoutInMs, | |||
18 | bool expectedTriggerPinState, | |||
19 | bool expectedTimeCondition, | |||
20 | const char* context | |||
21 | ); | |||
22 | }; | |||
23 | ||||
24 | 33 | void ShiftTorqueReductionTimeConditionTest::waitAndCheckTimeCondition( | ||
25 | const float timeoutInMs, | |||
26 | const bool expectedTriggerPinState, | |||
27 | const bool expectedTimeCondition, | |||
28 | const char* const context | |||
29 | ) { | |||
30 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 17 times.
|
2/2✓ Decision 'true' taken 16 times.
✓ Decision 'false' taken 17 times.
|
33 | if (timeoutInMs > IMMEDIATELY) { |
31 | 16 | advanceTimeUs(MS2US(timeoutInMs)); | ||
32 | } | |||
33 | 33 | periodicFastCallback(); | ||
34 |
2/6✓ Branch 3 taken 33 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 33 times.
✗ Branch 11 not taken.
✗ Branch 15 not taken.
✗ Branch 18 not taken.
|
33 | EXPECT_EQ( | |
35 | engine->shiftTorqueReductionController.torqueReductionTriggerPinState, | |||
36 | expectedTriggerPinState | |||
37 |
0/1✗ Branch 1 not taken.
|
33 | ) << context; | |
38 |
2/6✓ Branch 3 taken 33 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 33 times.
✗ Branch 11 not taken.
✗ Branch 15 not taken.
✗ Branch 18 not taken.
|
33 | EXPECT_EQ( | |
39 | engine->shiftTorqueReductionController.isTimeConditionSatisfied, | |||
40 | expectedTimeCondition | |||
41 |
0/1✗ Branch 1 not taken.
|
33 | ) << context; | |
42 | 33 | } | ||
43 | ||||
44 | 4 | TEST_F(ShiftTorqueReductionTimeConditionTest, checkExpiration) { | ||
45 |
1/1✓ Branch 2 taken 1 time.
|
3 | setUpEngineConfiguration(EngineConfig() | |
46 |
1/1✓ Branch 6 taken 1 time.
|
3 | .setTorqueReductionEnabled(true) | |
47 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setTorqueReductionActivationMode(torqueReductionActivationMode_e::TORQUE_REDUCTION_BUTTON) | |
48 |
1/1✓ Branch 4 taken 1 time.
|
4 | .setTorqueReductionTriggerPin(TEST_TORQUE_REDUCTION_BUTTON_PIN) | |
49 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setLimitTorqueReductionTime(true) | |
50 |
1/1✓ Branch 4 taken 1 time.
|
4 | .setTorqueReductionTime(TEST_TORQUE_REDUCTION_TIME) | |
51 | ); | |||
52 | ||||
53 | 1 | waitAndCheckTimeCondition(IMMEDIATELY, false, false, "Initial state"); | ||
54 | ||||
55 | 1 | setMockState(TEST_TORQUE_REDUCTION_BUTTON_PIN, true); | ||
56 | 1 | waitAndCheckTimeCondition(IMMEDIATELY, true, true, "Pin has just been actvated"); | ||
57 | ||||
58 | 1 | waitAndCheckTimeCondition(TEST_TORQUE_REDUCTION_TIME, true, true, "Before timeout exriration"); | ||
59 | ||||
60 | 1 | waitAndCheckTimeCondition(EPS3D, true, false, "After timeout expiration"); | ||
61 | 1 | } | ||
62 | ||||
63 | 4 | TEST_F(ShiftTorqueReductionTimeConditionTest, checkDeactivation) { | ||
64 |
1/1✓ Branch 2 taken 1 time.
|
3 | setUpEngineConfiguration(EngineConfig() | |
65 |
1/1✓ Branch 6 taken 1 time.
|
3 | .setTorqueReductionEnabled(true) | |
66 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setTorqueReductionActivationMode(torqueReductionActivationMode_e::TORQUE_REDUCTION_BUTTON) | |
67 |
1/1✓ Branch 4 taken 1 time.
|
4 | .setTorqueReductionTriggerPin(TEST_TORQUE_REDUCTION_BUTTON_PIN) | |
68 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setLimitTorqueReductionTime(true) | |
69 |
1/1✓ Branch 4 taken 1 time.
|
4 | .setTorqueReductionTime(TEST_TORQUE_REDUCTION_TIME) | |
70 | ); | |||
71 | ||||
72 | 1 | setMockState(TEST_TORQUE_REDUCTION_BUTTON_PIN, true); | ||
73 | 1 | waitAndCheckTimeCondition(IMMEDIATELY, true, true, "Pin has just been actvated"); | ||
74 | ||||
75 | 1 | waitAndCheckTimeCondition(TEST_TORQUE_REDUCTION_TIME / 2, true, true, "Before pin deactivation"); | ||
76 | ||||
77 | 1 | setMockState(TEST_TORQUE_REDUCTION_BUTTON_PIN, false); | ||
78 | 1 | waitAndCheckTimeCondition(IMMEDIATELY, false, false, "Pin has just been deactvated"); | ||
79 | 1 | } | ||
80 | ||||
81 | 4 | TEST_F(ShiftTorqueReductionTimeConditionTest, checkReactivation) { | ||
82 |
1/1✓ Branch 2 taken 1 time.
|
3 | setUpEngineConfiguration(EngineConfig() | |
83 |
1/1✓ Branch 6 taken 1 time.
|
3 | .setTorqueReductionEnabled(true) | |
84 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setTorqueReductionActivationMode(torqueReductionActivationMode_e::TORQUE_REDUCTION_BUTTON) | |
85 |
1/1✓ Branch 4 taken 1 time.
|
4 | .setTorqueReductionTriggerPin(TEST_TORQUE_REDUCTION_BUTTON_PIN) | |
86 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setLimitTorqueReductionTime(true) | |
87 |
1/1✓ Branch 4 taken 1 time.
|
4 | .setTorqueReductionTime(TEST_TORQUE_REDUCTION_TIME) | |
88 | ); | |||
89 | ||||
90 | 1 | setMockState(TEST_TORQUE_REDUCTION_BUTTON_PIN, true); | ||
91 | 1 | waitAndCheckTimeCondition(IMMEDIATELY, true, true, "Pin has just been actvated"); | ||
92 | ||||
93 | 1 | waitAndCheckTimeCondition(TEST_TORQUE_REDUCTION_TIME / 3, true, true, "Before pin deactivation"); | ||
94 | ||||
95 | 1 | setMockState(TEST_TORQUE_REDUCTION_BUTTON_PIN, false); | ||
96 | 1 | waitAndCheckTimeCondition(IMMEDIATELY, false, false, "Pin has just been deactvated"); | ||
97 | ||||
98 | 1 | waitAndCheckTimeCondition(TEST_TORQUE_REDUCTION_TIME / 3, false, false, "Pin is still deactvated"); | ||
99 | 1 | setMockState(TEST_TORQUE_REDUCTION_BUTTON_PIN, true); | ||
100 | 1 | waitAndCheckTimeCondition(IMMEDIATELY, true, true, "Pin has just been reactivated"); | ||
101 | ||||
102 | 1 | waitAndCheckTimeCondition(TEST_TORQUE_REDUCTION_TIME, true, true, "Before timeout expiration"); | ||
103 | 1 | waitAndCheckTimeCondition(EPS3D, true, false, "After timeout expiration"); | ||
104 | 1 | } | ||
105 | ||||
106 | 4 | TEST_F(ShiftTorqueReductionTimeConditionTest, checkTimeConditionIsNeverSatisfiedWithZeroTorqueReductionTime) { | ||
107 |
1/1✓ Branch 2 taken 1 time.
|
3 | setUpEngineConfiguration(EngineConfig() | |
108 |
1/1✓ Branch 6 taken 1 time.
|
3 | .setTorqueReductionEnabled(true) | |
109 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setTorqueReductionActivationMode(torqueReductionActivationMode_e::TORQUE_REDUCTION_BUTTON) | |
110 |
1/1✓ Branch 4 taken 1 time.
|
4 | .setTorqueReductionTriggerPin(TEST_TORQUE_REDUCTION_BUTTON_PIN) | |
111 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setLimitTorqueReductionTime(true) | |
112 |
1/1✓ Branch 4 taken 1 time.
|
4 | .setTorqueReductionTime(IMMEDIATELY) | |
113 | ); | |||
114 | ||||
115 | 1 | setMockState(TEST_TORQUE_REDUCTION_BUTTON_PIN, true); | ||
116 | 1 | waitAndCheckTimeCondition(IMMEDIATELY, true, false, "Pin has just been actvated"); | ||
117 | ||||
118 | 1 | waitAndCheckTimeCondition(TEST_TORQUE_REDUCTION_TIME / 3, true, false, "Before pin deactivation"); | ||
119 | ||||
120 | 1 | setMockState(TEST_TORQUE_REDUCTION_BUTTON_PIN, false); | ||
121 | 1 | waitAndCheckTimeCondition(IMMEDIATELY, false, false, "Pin has just been deactvated"); | ||
122 | ||||
123 | 1 | waitAndCheckTimeCondition(TEST_TORQUE_REDUCTION_TIME / 3, false, false, "Pin is still deactvated"); | ||
124 | 1 | setMockState(TEST_TORQUE_REDUCTION_BUTTON_PIN, true); | ||
125 | 1 | waitAndCheckTimeCondition(IMMEDIATELY, true, false, "Pin has just been reactivated"); | ||
126 | ||||
127 | 1 | waitAndCheckTimeCondition(TEST_TORQUE_REDUCTION_TIME, true, false, "Before timeout expiration"); | ||
128 | 1 | waitAndCheckTimeCondition(EPS3D, true, false, "After timeout expiration"); | ||
129 | 1 | } | ||
130 | ||||
131 | 4 | TEST_F(ShiftTorqueReductionTimeConditionTest, checkDeactivationWithoutLimitedTorqueReductionTime) { | ||
132 |
1/1✓ Branch 2 taken 1 time.
|
3 | setUpEngineConfiguration(EngineConfig() | |
133 |
1/1✓ Branch 6 taken 1 time.
|
3 | .setTorqueReductionEnabled(true) | |
134 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setTorqueReductionActivationMode(torqueReductionActivationMode_e::TORQUE_REDUCTION_BUTTON) | |
135 |
1/1✓ Branch 4 taken 1 time.
|
4 | .setTorqueReductionTriggerPin(TEST_TORQUE_REDUCTION_BUTTON_PIN) | |
136 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setLimitTorqueReductionTime(false) | |
137 |
1/1✓ Branch 4 taken 1 time.
|
4 | .setTorqueReductionTime(TEST_TORQUE_REDUCTION_TIME) | |
138 | ); | |||
139 | ||||
140 | 1 | waitAndCheckTimeCondition(IMMEDIATELY, false, false, "Initial state"); | ||
141 | ||||
142 | 1 | setMockState(TEST_TORQUE_REDUCTION_BUTTON_PIN, true); | ||
143 | 1 | waitAndCheckTimeCondition(IMMEDIATELY, true, true, "Pin has just been actvated"); | ||
144 | ||||
145 | 1 | waitAndCheckTimeCondition(TEST_TORQUE_REDUCTION_TIME, true, true, "Before timeout exriration"); | ||
146 | ||||
147 | // Timeout expiration doesn't affect shift torque reduction because limitTorqueReductionTime is false: | |||
148 | 1 | waitAndCheckTimeCondition(EPS3D, true, true, "After timeout expiration"); | ||
149 | ||||
150 | 1 | setMockState(TEST_TORQUE_REDUCTION_BUTTON_PIN, false); | ||
151 | 1 | waitAndCheckTimeCondition(IMMEDIATELY, false, false, "Pin has just been deactvated"); | ||
152 | 1 | } | ||
153 | ||||
154 | 4 | TEST_F(ShiftTorqueReductionTimeConditionTest, checkLuaExpiration) { | ||
155 |
1/1✓ Branch 2 taken 1 time.
|
3 | setUpEngineConfiguration(EngineConfig() | |
156 |
1/1✓ Branch 6 taken 1 time.
|
3 | .setTorqueReductionEnabled(true) | |
157 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setTorqueReductionActivationMode(torqueReductionActivationMode_e::TORQUE_REDUCTION_BUTTON) | |
158 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setTorqueReductionTriggerPin(Gpio::Unassigned) | |
159 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setLimitTorqueReductionTime(true) | |
160 |
1/1✓ Branch 4 taken 1 time.
|
4 | .setTorqueReductionTime(TEST_TORQUE_REDUCTION_TIME) | |
161 | ); | |||
162 | ||||
163 | 1 | waitAndCheckTimeCondition(IMMEDIATELY, false, false, "Initial state"); | ||
164 | ||||
165 | 1 | getTestLuaScriptExecutor().setTorqueReductionState(true); | ||
166 | 1 | waitAndCheckTimeCondition(IMMEDIATELY, true, true, "Pin has just been actvated"); | ||
167 | ||||
168 | 1 | waitAndCheckTimeCondition(TEST_TORQUE_REDUCTION_TIME, true, true, "Before timeout exriration"); | ||
169 | ||||
170 | 1 | waitAndCheckTimeCondition(EPS3D, true, false, "After timeout expiration"); | ||
171 | 1 | } | ||
172 | ||||
173 | 4 | TEST_F(ShiftTorqueReductionTimeConditionTest, checkLuaDeactivation) { | ||
174 |
1/1✓ Branch 2 taken 1 time.
|
3 | setUpEngineConfiguration(EngineConfig() | |
175 |
1/1✓ Branch 6 taken 1 time.
|
3 | .setTorqueReductionEnabled(true) | |
176 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setTorqueReductionActivationMode(torqueReductionActivationMode_e::TORQUE_REDUCTION_BUTTON) | |
177 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setTorqueReductionTriggerPin(Gpio::Unassigned) | |
178 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setLimitTorqueReductionTime(true) | |
179 |
1/1✓ Branch 4 taken 1 time.
|
4 | .setTorqueReductionTime(TEST_TORQUE_REDUCTION_TIME) | |
180 | ); | |||
181 | ||||
182 | 1 | getTestLuaScriptExecutor().setTorqueReductionState(true); | ||
183 | 1 | waitAndCheckTimeCondition(IMMEDIATELY, true, true, "Pin has just been actvated"); | ||
184 | ||||
185 | 1 | waitAndCheckTimeCondition(TEST_TORQUE_REDUCTION_TIME / 2, true, true, "Before pin deactivation"); | ||
186 | ||||
187 | 1 | getTestLuaScriptExecutor().setTorqueReductionState(false); | ||
188 | 1 | waitAndCheckTimeCondition(IMMEDIATELY, false, false, "Pin has just been deactvated"); | ||
189 | 1 | } | ||
190 | } | |||
191 |