foxBMS-UnitTests  1.0.0
The foxBMS Unit Tests API Documentation
test_mic_plausibility.c
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2021, Fraunhofer-Gesellschaft zur Foerderung der
4  * angewandten Forschung e.V. All rights reserved.
5  *
6  * BSD 3-Clause License
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  * 1. Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  *
30  * We kindly request you to use one or more of the following phrases to refer
31  * to foxBMS in your hardware, software, documentation or advertising
32  * materials:
33  *
34  * ″This product uses parts of foxBMS®″
35  *
36  * ″This product includes parts of foxBMS®″
37  *
38  * ″This product is derived from foxBMS®″
39  *
40  */
41 
42 /**
43  * @file test_mic_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 mic_plausibility module
51  *
52  */
53 
54 /*========== Includes =======================================================*/
55 #include "unity.h"
56 #include "Mocktsi.h"
57 
58 #include "mic_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  MIC_PLAUSIBILITY_VALUES_s limitsEqualValues = {
91  .minimumPlausibleVoltage_mV = 42,
92  };
93 
94  MIC_PLAUSIBILITY_VALUES_s limitsDescendingOrder = {
95  .maximumPlausibleVoltage_mV = INT16_MIN,
96  .minimumPlausibleVoltage_mV = INT16_MAX,
97  };
98 
99  MIC_PLAUSIBILITY_VALUES_s limitsAscendingOrder = {
100  .maximumPlausibleVoltage_mV = INT16_MAX,
101  .minimumPlausibleVoltage_mV = INT16_MIN,
102  };
103 
107  TEST_ASSERT_EQUAL(STD_OK, MIC_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, MIC_PlausibilityCheckTempMinMax(INT16_MIN));
218  TEST_ASSERT_EQUAL(STD_NOT_OK, MIC_PlausibilityCheckTempMinMax(lowerLimit_ddegC - 1));
219  TEST_ASSERT_EQUAL(STD_OK, MIC_PlausibilityCheckTempMinMax(lowerLimit_ddegC));
220  TEST_ASSERT_EQUAL(STD_OK, MIC_PlausibilityCheckTempMinMax((lowerLimit_ddegC + upperLimit_ddegC) / 2));
221  TEST_ASSERT_EQUAL(STD_OK, MIC_PlausibilityCheckTempMinMax(upperLimit_ddegC));
222  TEST_ASSERT_EQUAL(STD_NOT_OK, MIC_PlausibilityCheckTempMinMax(upperLimit_ddegC + 1));
223  TEST_ASSERT_EQUAL(STD_NOT_OK, MIC_PlausibilityCheckTempMinMax(INT16_MAX));
224 }
setUp
void setUp(void)
Definition: test_mic_plausibility.c:76
testMIC_PlausibilityCheckVoltageMeasurementRange
void testMIC_PlausibilityCheckVoltageMeasurementRange(void)
Definition: test_mic_plausibility.c:123
test_assert_helper.h
Helper for unit tests.
tearDown
void tearDown(void)
Definition: test_mic_plausibility.c:79
MIC_PLAUSIBILITY_VALUES::maximumPlausibleVoltage_mV
const int16_t maximumPlausibleVoltage_mV
Definition: mic_plausibility.h:72
mic_plausibility.h
plausibility checks for cell voltage and cell temperatures
STD_OK
@ STD_OK
Definition: fstd_types.h:72
testMIC_PlausibilityCheckTempMinMaxVerify
void testMIC_PlausibilityCheckTempMinMaxVerify(void)
Definition: test_mic_plausibility.c:211
MIC_PlausibilityCheckTempMinMax
STD_RETURN_TYPE_e MIC_PlausibilityCheckTempMinMax(const int16_t celltemperature_ddegC)
Cell temperature plausibility check.
Definition: mic_plausibility.c:86
STD_NOT_OK
@ STD_NOT_OK
Definition: fstd_types.h:73
testGenericLimits
MIC_PLAUSIBILITY_VALUES_s testGenericLimits
Definition: test_mic_plausibility.c:64
MIC_PLAUSIBILITY_VALUES::minimumPlausibleVoltage_mV
const int16_t minimumPlausibleVoltage_mV
Definition: mic_plausibility.h:77
MIC_PlausibilityCheckVoltageMeasurementRange
STD_RETURN_TYPE_e MIC_PlausibilityCheckVoltageMeasurementRange(const int16_t cellvoltage_mV, const MIC_PLAUSIBILITY_VALUES_s plausibleValues)
Cell voltage measurement range plausibility check.
Definition: mic_plausibility.c:70
testMIC_PlausibilityCheckVoltageMeasurementRangeLimitSanity
void testMIC_PlausibilityCheckVoltageMeasurementRangeLimitSanity(void)
Definition: test_mic_plausibility.c:88
testMIC_PlausibilityCheckTempMinMaxBadInputFromAPI
void testMIC_PlausibilityCheckTempMinMaxBadInputFromAPI(void)
Definition: test_mic_plausibility.c:185
testGenericLimitsNegative
MIC_PLAUSIBILITY_VALUES_s testGenericLimitsNegative
Definition: test_mic_plausibility.c:70
MIC_PLAUSIBILITY_VALUES
struct definition for plausibility values of a MIC
Definition: mic_plausibility.h:67
TEST_ASSERT_FAIL_ASSERT
#define TEST_ASSERT_FAIL_ASSERT(_code_under_test)
assert whether assert macro has failed
Definition: test_assert_helper.h:70
TEST_ASSERT_PASS_ASSERT
#define TEST_ASSERT_PASS_ASSERT(_code_under_test)
assert whether assert macro has passed
Definition: test_assert_helper.h:88