foxBMS - Unit Tests  1.6.0
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-10-12 (date of last update)
47  * @version v1.6.0
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 /*========== Unit Testing Framework Directives ==============================*/
63 TEST_INCLUDE_PATH("../../src/app/driver/afe/api")
64 TEST_INCLUDE_PATH("../../src/app/driver/ts/api")
65 
66 /*========== Definitions and Implementations for Unit Test ==================*/
67 
68 /** generic implementation of cell voltage limits */
71  .minimumPlausibleVoltage_mV = 0,
72 };
73 
74 /** generic implementation of cell voltage limits with negative limits */
77  .minimumPlausibleVoltage_mV = -5000,
78 };
79 
80 /*========== Setup and Teardown =============================================*/
81 void setUp(void) {
82 }
83 
84 void tearDown(void) {
85 }
86 
87 /*========== Test Cases =====================================================*/
88 
89 /** check sanity-check of voltage plausibility function
90  *
91  * limits may not be the same and must be ascending
92  */
94  AFE_PLAUSIBILITY_VALUES_s limitsEqualValues = {
96  .minimumPlausibleVoltage_mV = 42,
97  };
98 
99  AFE_PLAUSIBILITY_VALUES_s limitsDescendingOrder = {
100  .maximumPlausibleVoltage_mV = INT16_MIN,
101  .minimumPlausibleVoltage_mV = INT16_MAX,
102  };
103 
104  AFE_PLAUSIBILITY_VALUES_s limitsAscendingOrder = {
105  .maximumPlausibleVoltage_mV = INT16_MAX,
106  .minimumPlausibleVoltage_mV = INT16_MIN,
107  };
108 
112  TEST_ASSERT_EQUAL(STD_OK, AFE_PlausibilityCheckVoltageMeasurementRange(0, limitsAscendingOrder)));
113 }
114 
115 /** equivalence input classes for voltage check:
116  *
117  * cell voltage value:
118  * * in-range-value: e.g. 3500
119  * * out-of-upper-range-value: e.g. INT16_MAX
120  * * out-of-lower-range-value: e.g. INT16_MIN
121  * * just to be sure: 0
122  *
123  * limits:
124  * * negative values
125  * * positive values
126  * * zero
127  */
133 
134  /* test around the upper threshold with #testGenericLimits */
135  TEST_ASSERT_EQUAL(
136  STD_NOT_OK,
139  TEST_ASSERT_EQUAL(
140  STD_OK,
142  TEST_ASSERT_EQUAL(
143  STD_OK,
146 
147  /* test around the lower threshold with #testGenericLimits */
148  TEST_ASSERT_EQUAL(
149  STD_OK,
152  TEST_ASSERT_EQUAL(
153  STD_OK,
155  TEST_ASSERT_EQUAL(
156  STD_NOT_OK,
159 
160  /* test around the upper threshold with #testGenericLimitsNegative */
161  TEST_ASSERT_EQUAL(
162  STD_NOT_OK,
165  TEST_ASSERT_EQUAL(
166  STD_OK,
169  TEST_ASSERT_EQUAL(
170  STD_OK,
173 
174  /* test around the lower threshold with #testGenericLimitsNegative */
175  TEST_ASSERT_EQUAL(
176  STD_OK,
179  TEST_ASSERT_EQUAL(
180  STD_OK,
183  TEST_ASSERT_EQUAL(
184  STD_NOT_OK,
187 }
188 
189 /** check if the function handles bad input from the API as expected */
191  TSI_GetMaximumPlausibleTemperature_ExpectAndReturn(50);
192  TSI_GetMinimumPlausibleTemperature_ExpectAndReturn(51);
194 
195  TSI_GetMaximumPlausibleTemperature_ExpectAndReturn(50);
196  TSI_GetMinimumPlausibleTemperature_ExpectAndReturn(50);
198 
199  TSI_GetMaximumPlausibleTemperature_ExpectAndReturn(-50);
200  TSI_GetMinimumPlausibleTemperature_ExpectAndReturn(-51);
202 
203  TSI_GetMaximumPlausibleTemperature_ExpectAndReturn(51);
204  TSI_GetMinimumPlausibleTemperature_ExpectAndReturn(50);
206 }
207 
208 /** check if the function handles plausible and implausible input as expected
209  equivalence classes:
210  * below lower limit --> FAIL
211  * on lower limit --> PASS
212  * between lower and upper limit --> PASS
213  * on upper limit --> PASS
214  * above upper limit --> FAIL
215  */
217  const int16_t upperLimit_ddegC = 100;
218  const int16_t lowerLimit_ddegC = -10;
219  TSI_GetMaximumPlausibleTemperature_IgnoreAndReturn(upperLimit_ddegC);
220  TSI_GetMinimumPlausibleTemperature_IgnoreAndReturn(lowerLimit_ddegC);
221 
222  TEST_ASSERT_EQUAL(STD_NOT_OK, AFE_PlausibilityCheckTempMinMax(INT16_MIN));
223  TEST_ASSERT_EQUAL(STD_NOT_OK, AFE_PlausibilityCheckTempMinMax(lowerLimit_ddegC - 1));
224  TEST_ASSERT_EQUAL(STD_OK, AFE_PlausibilityCheckTempMinMax(lowerLimit_ddegC));
225  TEST_ASSERT_EQUAL(STD_OK, AFE_PlausibilityCheckTempMinMax((lowerLimit_ddegC + upperLimit_ddegC) / 2));
226  TEST_ASSERT_EQUAL(STD_OK, AFE_PlausibilityCheckTempMinMax(upperLimit_ddegC));
227  TEST_ASSERT_EQUAL(STD_NOT_OK, AFE_PlausibilityCheckTempMinMax(upperLimit_ddegC + 1));
228  TEST_ASSERT_EQUAL(STD_NOT_OK, AFE_PlausibilityCheckTempMinMax(INT16_MAX));
229 }
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