foxBMS - Unit Tests  1.6.0
The foxBMS Unit Tests API Documentation
test_io.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_io.c
44  * @author foxBMS Team
45  * @date 2020-06-10 (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 io module
52  *
53  */
54 
55 /*========== Includes =======================================================*/
56 #include "unity.h"
57 #include "Mockmcu.h"
58 
59 #include "io.h"
60 #include "test_assert_helper.h"
61 
62 /*========== Unit Testing Framework Directives ==============================*/
63 TEST_SOURCE_FILE("io.c")
64 
65 TEST_INCLUDE_PATH("../../src/app/driver/io")
66 
67 /*========== Definitions and Implementations for Unit Test ==================*/
68 
69 /*========== Setup and Teardown =============================================*/
70 void setUp(void) {
71 }
72 
73 void tearDown(void) {
74 }
75 
76 /*========== Test Cases =====================================================*/
77 
79  volatile uint32_t registerValue = 1u;
82 
83  /* 0 -> 1 */
84  IO_SetPinDirectionToOutput(&registerValue, 0u);
85  TEST_ASSERT_EQUAL(1u, registerValue);
86 
87  /* 1 -> 1 */
88  IO_SetPinDirectionToOutput(&registerValue, 0u);
89  TEST_ASSERT_EQUAL(1u, registerValue);
90 }
91 
93  volatile uint32_t registerValue = 1u;
96 
97  /* 1 -> 0 */
98  IO_SetPinDirectionToInput(&registerValue, 0u);
99  TEST_ASSERT_EQUAL(0u, registerValue);
100 
101  /* 0 -> 0 */
102  IO_SetPinDirectionToInput(&registerValue, 0u);
103  TEST_ASSERT_EQUAL(0u, registerValue);
104 }
105 
106 void testIO_PinSet(void) {
107  volatile uint32_t registerValue = 0u;
110 
111  /* 0 -> 1 */
112  IO_PinSet(&registerValue, 0u);
113  TEST_ASSERT_EQUAL(1u, registerValue);
114 
115  /* 1 -> 1 */
116  IO_PinSet(&registerValue, 0u);
117  TEST_ASSERT_EQUAL(1u, registerValue);
118 }
119 
120 void testIO_PinReset(void) {
121  volatile uint32_t registerValue = 1u;
124 
125  /* 1 -> 0 */
126  IO_PinReset(&registerValue, 0u);
127  TEST_ASSERT_EQUAL(0u, registerValue);
128 
129  /* 0 -> 0 */
130  IO_PinReset(&registerValue, 0u);
131  TEST_ASSERT_EQUAL(0u, registerValue);
132 }
133 
134 void testIO_PinGet(void) {
135  volatile uint32_t registerValue = 1u;
136  /* invalid argument tests */
139 
140  TEST_ASSERT_EQUAL(STD_PIN_LOW, IO_PinGet(&registerValue, 1u));
141  TEST_ASSERT_EQUAL(STD_PIN_HIGH, IO_PinGet(&registerValue, 0u));
142 }
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:77
@ STD_PIN_LOW
Definition: fstd_types.h:89
@ STD_PIN_HIGH
Definition: fstd_types.h:90
void IO_SetPinDirectionToOutput(volatile uint32_t *pRegisterAddress, uint32_t pin)
Set pin to output by writing in pin direction register.
Definition: io.c:77
void IO_SetPinDirectionToInput(volatile uint32_t *pRegisterAddress, uint32_t pin)
Set pin to input by writing in pin direction register.
Definition: io.c:84
void IO_PinSet(volatile uint32_t *pRegisterAddress, uint32_t pin)
Set pin by writing in pin output register.
Definition: io.c:91
void IO_PinReset(volatile uint32_t *pRegisterAddress, uint32_t pin)
Reset pin by writing in pin output register.
Definition: io.c:98
STD_PIN_STATE_e IO_PinGet(const volatile uint32_t *pRegisterAddress, uint32_t pin)
Get pin state.
Definition: io.c:105
Header for the driver for the IO module.
#define MCU_LARGEST_PIN_NUMBER
largest pin number that exists in TMS570LC4357
Definition: mcu.h:69
Helper for unit tests.
#define TEST_ASSERT_FAIL_ASSERT(_code_under_test)
assert whether assert macro has failed
void testIO_PinGet(void)
Definition: test_io.c:134
void testIO_PinReset(void)
Definition: test_io.c:120
void setUp(void)
Definition: test_io.c:70
void tearDown(void)
Definition: test_io.c:73
void testIO_PinSet(void)
Definition: test_io.c:106
void testIO_SetPinDirectionToInput(void)
Definition: test_io.c:92
void testIO_SetPinDirectionToOutput(void)
Definition: test_io.c:78