foxBMS - Unit Tests  1.5.1
The foxBMS Unit Tests API Documentation
test_afe_plausibility.c
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2023, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V.
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice, this
12  * list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * 3. Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  * We kindly request you to use one or more of the following phrases to refer to
34  * foxBMS in your hardware, software, documentation or advertising materials:
35  *
36  * - ″This product uses parts of foxBMS®″
37  * - ″This product includes parts of foxBMS®″
38  * - ″This product is derived from foxBMS®″
39  *
40  */
41 
42 /**
43  * @file test_afe_plausibility.c
44  * @author foxBMS Team
45  * @date 2020-07-13 (date of creation)
46  * @updated 2023-02-23 (date of last update)
47  * @version v1.5.1
48  * @ingroup UNIT_TEST_IMPLEMENTATION
49  * @prefix TEST
50  *
51  * @brief Tests for the afe_plausibility.c module
52  *
53  */
54 
55 /*========== Includes =======================================================*/
56 #include "unity.h"
57 #include "Mocktsi.h"
58 
59 #include "afe_plausibility.h"
60 #include "test_assert_helper.h"
61 
62 /*========== Definitions and Implementations for Unit Test ==================*/
63 
64 /** generic implementation of cell voltage limits */
67  .minimumPlausibleVoltage_mV = 0,
68 };
69 
70 /** generic implementation of cell voltage limits with negative limits */
73  .minimumPlausibleVoltage_mV = -5000,
74 };
75 
76 /*========== Setup and Teardown =============================================*/
77 void setUp(void) {
78 }
79 
80 void tearDown(void) {
81 }
82 
83 /*========== Test Cases =====================================================*/
84 
85 /** check sanity-check of voltage plausibility function
86  *
87  * limits may not be the same and must be ascending
88  */
90  AFE_PLAUSIBILITY_VALUES_s limitsEqualValues = {
92  .minimumPlausibleVoltage_mV = 42,
93  };
94 
95  AFE_PLAUSIBILITY_VALUES_s limitsDescendingOrder = {
96  .maximumPlausibleVoltage_mV = INT16_MIN,
97  .minimumPlausibleVoltage_mV = INT16_MAX,
98  };
99 
100  AFE_PLAUSIBILITY_VALUES_s limitsAscendingOrder = {
101  .maximumPlausibleVoltage_mV = INT16_MAX,
102  .minimumPlausibleVoltage_mV = INT16_MIN,
103  };
104 
108  TEST_ASSERT_EQUAL(STD_OK, AFE_PlausibilityCheckVoltageMeasurementRange(0, limitsAscendingOrder)));
109 }
110 
111 /** equivalence input classes for voltage check:
112  *
113  * cell voltage value:
114  * * in-range-value: e.g. 3500
115  * * out-of-upper-range-value: e.g. INT16_MAX
116  * * out-of-lower-range-value: e.g. INT16_MIN
117  * * just to be sure: 0
118  *
119  * limits:
120  * * negative values
121  * * positive values
122  * * zero
123  */
129 
130  /* test around the upper threshold with #testGenericLimits */
131  TEST_ASSERT_EQUAL(
132  STD_NOT_OK,
135  TEST_ASSERT_EQUAL(
136  STD_OK,
138  TEST_ASSERT_EQUAL(
139  STD_OK,
142 
143  /* test around the lower threshold with #testGenericLimits */
144  TEST_ASSERT_EQUAL(
145  STD_OK,
148  TEST_ASSERT_EQUAL(
149  STD_OK,
151  TEST_ASSERT_EQUAL(
152  STD_NOT_OK,
155 
156  /* test around the upper threshold with #testGenericLimitsNegative */
157  TEST_ASSERT_EQUAL(
158  STD_NOT_OK,
161  TEST_ASSERT_EQUAL(
162  STD_OK,
165  TEST_ASSERT_EQUAL(
166  STD_OK,
169 
170  /* test around the lower threshold with #testGenericLimitsNegative */
171  TEST_ASSERT_EQUAL(
172  STD_OK,
175  TEST_ASSERT_EQUAL(
176  STD_OK,
179  TEST_ASSERT_EQUAL(
180  STD_NOT_OK,
183 }
184 
185 /** check if the function handles bad input from the API as expected */
187  TSI_GetMaximumPlausibleTemperature_ExpectAndReturn(50);
188  TSI_GetMinimumPlausibleTemperature_ExpectAndReturn(51);
190 
191  TSI_GetMaximumPlausibleTemperature_ExpectAndReturn(50);
192  TSI_GetMinimumPlausibleTemperature_ExpectAndReturn(50);
194 
195  TSI_GetMaximumPlausibleTemperature_ExpectAndReturn(-50);
196  TSI_GetMinimumPlausibleTemperature_ExpectAndReturn(-51);
198 
199  TSI_GetMaximumPlausibleTemperature_ExpectAndReturn(51);
200  TSI_GetMinimumPlausibleTemperature_ExpectAndReturn(50);
202 }
203 
204 /** check if the function handles plausible and implausible input as expected
205  equivalence classes:
206  * below lower limit --> FAIL
207  * on lower limit --> PASS
208  * between lower and upper limit --> PASS
209  * on upper limit --> PASS
210  * above upper limit --> FAIL
211  */
213  const int16_t upperLimit_ddegC = 100;
214  const int16_t lowerLimit_ddegC = -10;
215  TSI_GetMaximumPlausibleTemperature_IgnoreAndReturn(upperLimit_ddegC);
216  TSI_GetMinimumPlausibleTemperature_IgnoreAndReturn(lowerLimit_ddegC);
217 
218  TEST_ASSERT_EQUAL(STD_NOT_OK, AFE_PlausibilityCheckTempMinMax(INT16_MIN));
219  TEST_ASSERT_EQUAL(STD_NOT_OK, AFE_PlausibilityCheckTempMinMax(lowerLimit_ddegC - 1));
220  TEST_ASSERT_EQUAL(STD_OK, AFE_PlausibilityCheckTempMinMax(lowerLimit_ddegC));
221  TEST_ASSERT_EQUAL(STD_OK, AFE_PlausibilityCheckTempMinMax((lowerLimit_ddegC + upperLimit_ddegC) / 2));
222  TEST_ASSERT_EQUAL(STD_OK, AFE_PlausibilityCheckTempMinMax(upperLimit_ddegC));
223  TEST_ASSERT_EQUAL(STD_NOT_OK, AFE_PlausibilityCheckTempMinMax(upperLimit_ddegC + 1));
224  TEST_ASSERT_EQUAL(STD_NOT_OK, AFE_PlausibilityCheckTempMinMax(INT16_MAX));
225 }
STD_RETURN_TYPE_e AFE_PlausibilityCheckTempMinMax(const int16_t celltemperature_ddegC)
Cell temperature plausibility check.
STD_RETURN_TYPE_e AFE_PlausibilityCheckVoltageMeasurementRange(const int16_t cellVoltage_mV, const AFE_PLAUSIBILITY_VALUES_s plausibleValues)
Cell voltage measurement range plausibility check.
plausibility checks for cell voltage and cell temperatures
@ STD_NOT_OK
Definition: fstd_types.h:84
@ STD_OK
Definition: fstd_types.h:83
struct definition for plausibility values of an AFE
const int16_t minimumPlausibleVoltage_mV
const int16_t maximumPlausibleVoltage_mV
void testAFE_PlausibilityCheckTempMinMaxVerify(void)
void testAFE_PlausibilityCheckVoltageMeasurementRangeLimitSanity(void)
void testAFE_PlausibilityCheckVoltageMeasurementRange(void)
AFE_PLAUSIBILITY_VALUES_s testGenericLimitsNegative
void setUp(void)
void testAFE_PlausibilityCheckTempMinMaxBadInputFromAPI(void)
void tearDown(void)
AFE_PLAUSIBILITY_VALUES_s testGenericLimits
Helper for unit tests.
#define TEST_ASSERT_PASS_ASSERT(_code_under_test)
assert whether assert macro has passed
#define TEST_ASSERT_FAIL_ASSERT(_code_under_test)
assert whether assert macro has failed