GCC Code Coverage Report


Directory: ./
File: unit_tests/tests/shift_torque_reduction/test_shift_torque_reduction_flat_shift_condition.cpp
Date: 2025-10-03 00:57:22
Coverage Exec Excl Total
Lines: 100.0% 74 0 74
Functions: 100.0% 20 0 20
Branches: 36.2% 17 0 47
Decisions: -% 0 - 0

Line Branch Decision Exec Source
1 //
2 // Created by kifir on 10/4/24.
3 //
4
5 #include "pch.h"
6
7 #include "util/test_base.h"
8
9 namespace {
10 class ShiftTorqueReductionFlatShiftConditionTest : public TestBase<> {
11 protected:
12 static constexpr switch_input_pin_e TEST_TORQUE_REDUCTION_BUTTON_PIN = Gpio::E13;
13 static constexpr float TEST_TORQUE_REDUCTION_TIME = 123.45f;
14 static constexpr float TEST_TORQUE_REDUCTION_ARMING_RPM = 678.90f;
15 static constexpr float TEST_TORQUE_REDUCTION_ARMING_APP = 12.3f;
16 static constexpr float IMMEDIATELY = 0.0f;
17
18 void SetUp() override;
19
20 void triggerPin();
21 void satisfyRpmCondition();
22 void satisfyAppCondition();
23
24 void waitAndCheckFlatShiftCondition(float timeoutInMs, bool expectedFlatShiftCondition, const char* context);
25 };
26
27 5 void ShiftTorqueReductionFlatShiftConditionTest::SetUp() {
28 5 TestBase::SetUp();
29
1/1
✓ Branch 2 taken 5 times.
15 setUpEngineConfiguration(EngineConfig()
30
1/1
✓ Branch 6 taken 5 times.
15 .setTorqueReductionEnabled(true)
31
1/1
✓ Branch 5 taken 5 times.
20 .setTorqueReductionActivationMode(torqueReductionActivationMode_e::TORQUE_REDUCTION_BUTTON)
32
1/1
✓ Branch 4 taken 5 times.
20 .setTorqueReductionTriggerPin(TEST_TORQUE_REDUCTION_BUTTON_PIN)
33
1/1
✓ Branch 5 taken 5 times.
20 .setLimitTorqueReductionTime(true)
34
1/1
✓ Branch 4 taken 5 times.
20 .setTorqueReductionTime(TEST_TORQUE_REDUCTION_TIME)
35
1/1
✓ Branch 4 taken 5 times.
20 .setTorqueReductionArmingRpm(TEST_TORQUE_REDUCTION_ARMING_RPM)
36
1/1
✓ Branch 4 taken 5 times.
20 .setTorqueReductionArmingApp(TEST_TORQUE_REDUCTION_ARMING_APP)
37 );
38 5 }
39
40 4 void ShiftTorqueReductionFlatShiftConditionTest::triggerPin() {
41 4 setMockState(TEST_TORQUE_REDUCTION_BUTTON_PIN, true);
42 4 periodicFastCallback();
43
1/6
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
4 EXPECT_TRUE(engine->shiftTorqueReductionController.isTorqueReductionTriggerPinValid);
44
1/6
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
4 EXPECT_TRUE(engine->shiftTorqueReductionController.torqueReductionTriggerPinState);
45
1/6
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
4 EXPECT_TRUE(engine->shiftTorqueReductionController.isTimeConditionSatisfied);
46 4 }
47
48 4 void ShiftTorqueReductionFlatShiftConditionTest::satisfyRpmCondition() {
49
1/1
✓ Branch 3 taken 4 times.
4 updateRpm(TEST_TORQUE_REDUCTION_ARMING_RPM);
50
1/6
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
4 EXPECT_TRUE(engine->shiftTorqueReductionController.isRpmConditionSatisfied);
51 4 }
52
53 4 void ShiftTorqueReductionFlatShiftConditionTest::satisfyAppCondition() {
54
1/1
✓ Branch 3 taken 4 times.
4 updateApp(TEST_TORQUE_REDUCTION_ARMING_APP);
55
1/6
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
4 EXPECT_TRUE(engine->shiftTorqueReductionController.isAppConditionSatisfied);
56 4 }
57
58 10 void ShiftTorqueReductionFlatShiftConditionTest::waitAndCheckFlatShiftCondition(
59 const float timeoutInMs,
60 const bool expectedFlatShiftCondition,
61 const char* const context
62 ) {
63 10 advanceTimeUs(MS2US(timeoutInMs));
64 10 periodicFastCallback();
65
2/6
✓ Branch 3 taken 10 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 10 times.
✗ Branch 11 not taken.
✗ Branch 15 not taken.
✗ Branch 18 not taken.
10 EXPECT_EQ(engine->shiftTorqueReductionController.isFlatShiftConditionSatisfied, expectedFlatShiftCondition)
66
0/1
✗ Branch 1 not taken.
10 << context;
67 10 }
68
69 4 TEST_F(ShiftTorqueReductionFlatShiftConditionTest, checkSatisfiedFlatShiftCondition) {
70 1 triggerPin();
71 1 satisfyRpmCondition();
72 1 satisfyAppCondition();
73 1 waitAndCheckFlatShiftCondition(IMMEDIATELY, true, "App condition is satisfied");
74 1 }
75
76 4 TEST_F(ShiftTorqueReductionFlatShiftConditionTest, checkWithoutTriggeredPin) {
77 //triggerPin();
78 1 satisfyRpmCondition();
79 1 satisfyAppCondition();
80 1 waitAndCheckFlatShiftCondition(IMMEDIATELY, false, "Without triggered pin");
81 1 }
82
83 4 TEST_F(ShiftTorqueReductionFlatShiftConditionTest, checkWithoutRpmCondition) {
84 1 triggerPin();
85 //satisfyRpmCondition();
86 1 satisfyAppCondition();
87 1 waitAndCheckFlatShiftCondition(IMMEDIATELY, false, "Without rpm condition");
88 1 }
89
90 4 TEST_F(ShiftTorqueReductionFlatShiftConditionTest, checkWithoutAppCondition) {
91 1 triggerPin();
92 1 satisfyRpmCondition();
93 //satisfyAppCondition();
94 1 waitAndCheckFlatShiftCondition(IMMEDIATELY, false, "Without app condition");
95 1 }
96
97 4 TEST_F(ShiftTorqueReductionFlatShiftConditionTest, checkSatisfiedFlatShiftConditionExpiration) {
98 1 waitAndCheckFlatShiftCondition(IMMEDIATELY, false, "Default");
99
100 1 triggerPin();
101 1 waitAndCheckFlatShiftCondition(IMMEDIATELY, false, "Time condition is satisfied");
102
103 1 satisfyRpmCondition();
104 1 waitAndCheckFlatShiftCondition(IMMEDIATELY, false, "Rpm condition is satisfied");
105
106 1 satisfyAppCondition();
107 1 waitAndCheckFlatShiftCondition(IMMEDIATELY, true, "App condition is satisfied");
108
109 1 waitAndCheckFlatShiftCondition(TEST_TORQUE_REDUCTION_TIME, true, "Flat shift condition is still satisfied");
110
111 1 waitAndCheckFlatShiftCondition(EPS3D, false, "Flat shift condition is expired");
112 1 }
113 }
114