GCC Code Coverage Report


Directory: ./
File: firmware/controllers/actuators/gppwm/gppwm_channel.cpp
Date: 2025-10-03 00:57:22
Coverage Exec Excl Total
Lines: 81.2% 39 0 48
Functions: 100.0% 5 0 5
Branches: 76.3% 29 0 38
Decisions: 77.8% 14 - 18

Line Branch Decision Exec Source
1
2 #include "pch.h"
3
4 #include "gppwm_channel.h"
5
6 #include "table_helper.h"
7 #include "gppwm_channel_reader.h"
8
9 11 float GppwmChannel::setOutput(float result) {
10 // Not init yet, nothing to do.
11
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 10 times.
2/2
✓ Decision 'true' taken 1 time.
✓ Decision 'false' taken 10 times.
11 if (!m_config) {
12 1 return result;
13 }
14
15
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 6 times.
2/2
✓ Decision 'true' taken 4 times.
✓ Decision 'false' taken 6 times.
10 if (m_usePwm) {
16
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 efiAssert(ObdCode::OBD_PCM_Processor_Fault, m_usePwm, "m_usePwm null", 0);
17 4 m_pwm->setSimplePwmDutyCycle(clampF(0, result / 100.0f, 1));
18
19 4 return result;
20 } else {
21
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 efiAssert(ObdCode::OBD_PCM_Processor_Fault, m_output, "m_output null", 0);
22
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
1/2
✗ Decision 'true' not taken.
✓ Decision 'false' taken 6 times.
6 if (m_config->offBelowDuty > m_config->onAboveDuty) {
23 firmwareError(ObdCode::CUSTOM_ERR_6122, "You can't have off below %d greater than on above %d",
24 m_config->offBelowDuty,
25 m_config->onAboveDuty);
26 }
27 // Apply hysteresis with provided values
28
4/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 2 times.
2/2
✓ Decision 'true' taken 1 time.
✓ Decision 'false' taken 5 times.
6 if (m_state && result < m_config->offBelowDuty) {
29 1 m_state = false;
30
4/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 2 times.
2/2
✓ Decision 'true' taken 1 time.
✓ Decision 'false' taken 4 times.
5 } else if (!m_state && result > m_config->onAboveDuty) {
31 1 m_state = true;
32 }
33
34 6 m_output->setValue(m_state);
35
36 // Return the actual output value with hysteresis
37
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 return m_state ? 100 : 0;
38 }
39 }
40
41 3 void GppwmChannel::init(bool usePwm, IPwm* pwm, OutputPin* outputPin, const ValueProvider3D* table, const gppwm_channel* p_config) {
42 3 m_usePwm = usePwm;
43 3 m_pwm = pwm;
44 3 m_output = outputPin;
45 3 m_table = table;
46 3 m_config = p_config;
47 3 }
48
49 2 /*PUBLIC_API_WEAK*/ expected<float> boardOverrideGppwm(size_t index) {
50 UNUSED(index);
51 2 return unexpected;
52 }
53
54 2 GppwmResult GppwmChannel::getOutput(size_t index) const {
55
1/1
✓ Branch 2 taken 2 times.
2 expected<float> xAxisValue = readGppwmChannel(m_config->rpmAxis);
56
1/1
✓ Branch 2 taken 2 times.
2 expected<float> yAxisValue = readGppwmChannel(m_config->loadAxis);
57
58 2 GppwmResult result { (float)m_config->dutyIfError, xAxisValue.value_or(0), yAxisValue.value_or(0) };
59
1/1
✓ Branch 2 taken 2 times.
2 expected<float> override = boardOverrideGppwm(index);
60
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
1/2
✗ Decision 'true' not taken.
✓ Decision 'false' taken 2 times.
2 if (override) {
61 result.Result = override.Value;
62 return result;
63 }
64
65 // If we couldn't get load axis value, fall back on error value
66
5/6
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 6 taken 1 time.
✓ Branch 7 taken 1 time.
2/2
✓ Decision 'true' taken 1 time.
✓ Decision 'false' taken 1 time.
2 if (!xAxisValue || !yAxisValue) {
67 1 return result;
68 }
69
70
1/1
✓ Branch 1 taken 1 time.
1 float resultVal = m_table->getValue(xAxisValue.Value, yAxisValue.Value);
71
72
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
1/2
✗ Decision 'true' not taken.
✓ Decision 'false' taken 1 time.
1 if (std::isnan(result.Result)) {
73 return result;
74 }
75
76 1 result.Result = resultVal;
77 1 return result;
78 }
79
80 4340 GppwmResult GppwmChannel::update(size_t index) {
81 // Without a config, nothing to do.
82
1/2
✓ Branch 0 taken 4340 times.
✗ Branch 1 not taken.
1/2
✓ Decision 'true' taken 4340 times.
✗ Decision 'false' not taken.
4340 if (!m_config) {
83 4340 return {};
84 }
85
86 auto output = getOutput(index);
87 output.Result = setOutput(output.Result);
88
89 return output;
90 }
91