foxBMS - Unit Tests  1.2.1
The foxBMS Unit Tests API Documentation
test_afe_plausibility.c
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2021, 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 2021-01-15 (date of last update)
47  * @ingroup UNIT_TEST_IMPLEMENTATION
48  * @prefix TEST
49  *
50  * @brief Tests for the afe_plausibility.c module
51  *
52  */
53 
54 /*========== Includes =======================================================*/
55 #include "unity.h"
56 #include "Mocktsi.h"
57 
58 #include "afe_plausibility.h"
59 #include "test_assert_helper.h"
60 
61 /*========== Definitions and Implementations for Unit Test ==================*/
62 
63 /** generic implementation of cell voltage limits */
66  .minimumPlausibleVoltage_mV = 0,
67 };
68 
69 /** generic implementation of cell voltage limits with negative limits */
72  .minimumPlausibleVoltage_mV = -5000,
73 };
74 
75 /*========== Setup and Teardown =============================================*/
76 void setUp(void) {
77 }
78 
79 void tearDown(void) {
80 }
81 
82 /*========== Test Cases =====================================================*/
83 
84 /** check sanity-check of voltage plausibility function
85  *
86  * limits may not be the same and must be ascending
87  */
89  AFE_PLAUSIBILITY_VALUES_s limitsEqualValues = {
91  .minimumPlausibleVoltage_mV = 42,
92  };
93 
94  AFE_PLAUSIBILITY_VALUES_s limitsDescendingOrder = {
95  .maximumPlausibleVoltage_mV = INT16_MIN,
96  .minimumPlausibleVoltage_mV = INT16_MAX,
97  };
98 
99  AFE_PLAUSIBILITY_VALUES_s limitsAscendingOrder = {
100  .maximumPlausibleVoltage_mV = INT16_MAX,
101  .minimumPlausibleVoltage_mV = INT16_MIN,
102  };
103 
107  TEST_ASSERT_EQUAL(STD_OK, AFE_PlausibilityCheckVoltageMeasurementRange(0, limitsAscendingOrder)));
108 }
109 
110 /** equivalence input classes for voltage check:
111  *
112  * cell voltage value:
113  * * in-range-value: e.g. 3500
114  * * out-of-upper-range-value: e.g. INT16_MAX
115  * * out-of-lower-range-value: e.g. INT16_MIN
116  * * just to be sure: 0
117  *
118  * limits:
119  * * negative values
120  * * positive values
121  * * zero
122  */
128 
129  /* test around the upper threshold with #testGenericLimits */
130  TEST_ASSERT_EQUAL(
131  STD_NOT_OK,
134  TEST_ASSERT_EQUAL(
135  STD_OK,
137  TEST_ASSERT_EQUAL(
138  STD_OK,
141 
142  /* test around the lower threshold with #testGenericLimits */
143  TEST_ASSERT_EQUAL(
144  STD_OK,
147  TEST_ASSERT_EQUAL(
148  STD_OK,
150  TEST_ASSERT_EQUAL(
151  STD_NOT_OK,
154 
155  /* test around the upper threshold with #testGenericLimitsNegative */
156  TEST_ASSERT_EQUAL(
157  STD_NOT_OK,
160  TEST_ASSERT_EQUAL(
161  STD_OK,
164  TEST_ASSERT_EQUAL(
165  STD_OK,
168 
169  /* test around the lower threshold with #testGenericLimitsNegative */
170  TEST_ASSERT_EQUAL(
171  STD_OK,
174  TEST_ASSERT_EQUAL(
175  STD_OK,
178  TEST_ASSERT_EQUAL(
179  STD_NOT_OK,
182 }
183 
184 /** check if the function handles bad input from the API as expected */
186  TSI_GetMaximumPlausibleTemperature_ExpectAndReturn(50);
187  TSI_GetMinimumPlausibleTemperature_ExpectAndReturn(51);
189 
190  TSI_GetMaximumPlausibleTemperature_ExpectAndReturn(50);
191  TSI_GetMinimumPlausibleTemperature_ExpectAndReturn(50);
193 
194  TSI_GetMaximumPlausibleTemperature_ExpectAndReturn(-50);
195  TSI_GetMinimumPlausibleTemperature_ExpectAndReturn(-51);
197 
198  TSI_GetMaximumPlausibleTemperature_ExpectAndReturn(51);
199  TSI_GetMinimumPlausibleTemperature_ExpectAndReturn(50);
201 }
202 
203 /** check if the function handles plausible and implausible input as expected
204  equivalence classes:
205  * below lower limit --> FAIL
206  * on lower limit --> PASS
207  * between lower and upper limit --> PASS
208  * on upper limit --> PASS
209  * above upper limit --> FAIL
210  */
212  const int16_t upperLimit_ddegC = 100;
213  const int16_t lowerLimit_ddegC = -10;
214  TSI_GetMaximumPlausibleTemperature_IgnoreAndReturn(upperLimit_ddegC);
215  TSI_GetMinimumPlausibleTemperature_IgnoreAndReturn(lowerLimit_ddegC);
216 
217  TEST_ASSERT_EQUAL(STD_NOT_OK, AFE_PlausibilityCheckTempMinMax(INT16_MIN));
218  TEST_ASSERT_EQUAL(STD_NOT_OK, AFE_PlausibilityCheckTempMinMax(lowerLimit_ddegC - 1));
219  TEST_ASSERT_EQUAL(STD_OK, AFE_PlausibilityCheckTempMinMax(lowerLimit_ddegC));
220  TEST_ASSERT_EQUAL(STD_OK, AFE_PlausibilityCheckTempMinMax((lowerLimit_ddegC + upperLimit_ddegC) / 2));
221  TEST_ASSERT_EQUAL(STD_OK, AFE_PlausibilityCheckTempMinMax(upperLimit_ddegC));
222  TEST_ASSERT_EQUAL(STD_NOT_OK, AFE_PlausibilityCheckTempMinMax(upperLimit_ddegC + 1));
223  TEST_ASSERT_EQUAL(STD_NOT_OK, AFE_PlausibilityCheckTempMinMax(INT16_MAX));
224 }
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:82
@ STD_OK
Definition: fstd_types.h:81
struct definition for plausibility values of an AFE
const int16_t maximumPlausibleVoltage_mV
const int16_t minimumPlausibleVoltage_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