foxBMS-UnitTests
1.0.0
The foxBMS Unit Tests API Documentation
test_diag_cbs_interlock.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_diag_cbs_interlock.c
44
* @author foxBMS Team
45
* @date 2021-02-17 (date of creation)
46
* @updated 2021-02-17 (date of last update)
47
* @ingroup UNIT_TEST_IMPLEMENTATION
48
* @prefix TEST
49
*
50
* @brief Test of the Interlock diag handler implementation.
51
*
52
*/
53
54
/*========== Includes =======================================================*/
55
#include "unity.h"
56
#include "Mockdiag_cfg.h"
57
58
#include "
diag_cbs.h
"
59
#include "
test_assert_helper.h
"
60
61
TEST_FILE(
"diag_cbs_interlock.c"
)
62
63
/*========== Definitions and Implementations for Unit Test ==================*/
64
/** local copy of the #DATA_BLOCK_ERRORSTATE_s table */
65
static
DATA_BLOCK_ERRORSTATE_s
test_tableErrorFlags
= {.
header
.
uniqueId
=
DATA_BLOCK_ID_ERRORSTATE
};
66
67
/** local copy of the #DATA_BLOCK_MOL_FLAG_s table */
68
static
DATA_BLOCK_MOL_FLAG_s
test_tableMolFlags
= {.
header
.
uniqueId
=
DATA_BLOCK_ID_MOL_FLAG
};
69
70
/** local copy of the #DATA_BLOCK_RSL_FLAG_s table */
71
static
DATA_BLOCK_RSL_FLAG_s
test_tableRslFlags
= {.
header
.
uniqueId
=
DATA_BLOCK_ID_RSL_FLAG
};
72
73
/** local copy of the #DATA_BLOCK_MSL_FLAG_s table */
74
static
DATA_BLOCK_MSL_FLAG_s
test_tableMslFlags
= {.
header
.
uniqueId
=
DATA_BLOCK_ID_MSL_FLAG
};
75
76
const
DIAG_DATABASE_SHIM_s
diag_kpkDatabaseShim
= {
77
.
pTableError
= &
test_tableErrorFlags
,
78
.pTableMol = &
test_tableMolFlags
,
79
.pTableRsl = &
test_tableRslFlags
,
80
.pTableMsl = &
test_tableMslFlags
,
81
};
82
83
/*========== Setup and Teardown =============================================*/
84
void
setUp
(
void
) {
85
diag_kpkDatabaseShim
.
pTableError
->
interlock
= 0;
86
}
87
88
void
tearDown
(
void
) {
89
}
90
91
/*========== Test Cases =====================================================*/
92
void
testDiagInterlock
(
void
) {
93
/* reset event sets the interlock back in ok mode */
94
DIAG_ErrorInterlock
(
DIAG_ID_INTERLOCK_FEEDBACK
,
DIAG_EVENT_RESET
, &
diag_kpkDatabaseShim
, 0u);
95
TEST_ASSERT_EQUAL(0,
diag_kpkDatabaseShim
.
pTableError
->
interlock
);
96
/* ok event must not change the interlock state */
97
DIAG_ErrorInterlock
(
DIAG_ID_INTERLOCK_FEEDBACK
,
DIAG_EVENT_OK
, &
diag_kpkDatabaseShim
, 0u);
98
TEST_ASSERT_EQUAL(0,
diag_kpkDatabaseShim
.
pTableError
->
interlock
);
99
100
/* not ok event sets the interlock back in not ok mode */
101
DIAG_ErrorInterlock
(
DIAG_ID_INTERLOCK_FEEDBACK
,
DIAG_EVENT_NOT_OK
, &
diag_kpkDatabaseShim
, 0u);
102
TEST_ASSERT_EQUAL(1,
diag_kpkDatabaseShim
.
pTableError
->
interlock
);
103
/* interlock can be resetted via ok event (instead a reset is required), therefore the
104
* interlock must stay in not ok mode */
105
DIAG_ErrorInterlock
(
DIAG_ID_INTERLOCK_FEEDBACK
,
DIAG_EVENT_OK
, &
diag_kpkDatabaseShim
, 0u);
106
TEST_ASSERT_EQUAL(1,
diag_kpkDatabaseShim
.
pTableError
->
interlock
);
107
108
/* reset event sets the interlock back in ok mode */
109
DIAG_ErrorInterlock
(
DIAG_ID_INTERLOCK_FEEDBACK
,
DIAG_EVENT_RESET
, &
diag_kpkDatabaseShim
, 0u);
110
TEST_ASSERT_EQUAL(0,
diag_kpkDatabaseShim
.
pTableError
->
interlock
);
111
}
112
113
/** tests invalid input values */
114
void
testDIAG_ErrorInterlockInvalidInput
(
void
) {
115
TEST_ASSERT_FAIL_ASSERT
(
DIAG_ErrorInterlock
(
DIAG_ID_MAX
,
DIAG_EVENT_OK
, &
diag_kpkDatabaseShim
, 0u));
116
TEST_ASSERT_FAIL_ASSERT
(
DIAG_ErrorInterlock
(
DIAG_ID_INTERLOCK_FEEDBACK
, 42, &
diag_kpkDatabaseShim
, 0u));
117
TEST_ASSERT_FAIL_ASSERT
(
DIAG_ErrorInterlock
(
DIAG_ID_INTERLOCK_FEEDBACK
,
DIAG_EVENT_OK
,
NULL_PTR
, 0u));
118
}
DATA_BLOCK_MOL_FLAG
Definition:
database_cfg.h:465
DATA_BLOCK_ID_MOL_FLAG
@ DATA_BLOCK_ID_MOL_FLAG
Definition:
database_cfg.h:90
tearDown
void tearDown(void)
Definition:
test_diag_cbs_interlock.c:88
DIAG_DATABASE_SHIM
Definition:
diag_cfg.h:113
DATA_BLOCK_ID_MSL_FLAG
@ DATA_BLOCK_ID_MSL_FLAG
Definition:
database_cfg.h:88
test_tableMslFlags
static DATA_BLOCK_MSL_FLAG_s test_tableMslFlags
Definition:
test_diag_cbs_interlock.c:74
testDiagInterlock
void testDiagInterlock(void)
Definition:
test_diag_cbs_interlock.c:92
test_assert_helper.h
Helper for unit tests.
DATA_BLOCK_ID_RSL_FLAG
@ DATA_BLOCK_ID_RSL_FLAG
Definition:
database_cfg.h:89
DIAG_EVENT_OK
@ DIAG_EVENT_OK
Definition:
diag_cfg.h:201
testDIAG_ErrorInterlockInvalidInput
void testDIAG_ErrorInterlockInvalidInput(void)
Definition:
test_diag_cbs_interlock.c:114
DIAG_EVENT_RESET
@ DIAG_EVENT_RESET
Definition:
diag_cfg.h:203
DATA_BLOCK_ERRORSTATE::interlock
uint8_t interlock
Definition:
database_cfg.h:328
setUp
void setUp(void)
Definition:
test_diag_cbs_interlock.c:84
DATA_BLOCK_MOL_FLAG::header
DATA_BLOCK_HEADER_s header
Definition:
database_cfg.h:469
diag_cbs.h
Diagnosis driver header.
DATA_BLOCK_MSL_FLAG::header
DATA_BLOCK_HEADER_s header
Definition:
database_cfg.h:427
DIAG_ErrorInterlock
void DIAG_ErrorInterlock(DIAG_ID_e ch_id, DIAG_EVENT_e event, const DIAG_DATABASE_SHIM_s *const kpkDiagShim, uint32_t data)
Callback function for interlock related diagnosis events.
Definition:
diag_cbs_interlock.c:68
DIAG_EVENT_NOT_OK
@ DIAG_EVENT_NOT_OK
Definition:
diag_cfg.h:202
DIAG_ID_INTERLOCK_FEEDBACK
@ DIAG_ID_INTERLOCK_FEEDBACK
Definition:
diag_cfg.h:178
DATA_BLOCK_RSL_FLAG::header
DATA_BLOCK_HEADER_s header
Definition:
database_cfg.h:449
test_tableMolFlags
static DATA_BLOCK_MOL_FLAG_s test_tableMolFlags
Definition:
test_diag_cbs_interlock.c:68
test_tableRslFlags
static DATA_BLOCK_RSL_FLAG_s test_tableRslFlags
Definition:
test_diag_cbs_interlock.c:71
DATA_BLOCK_ERRORSTATE::header
DATA_BLOCK_HEADER_s header
Definition:
database_cfg.h:324
DATA_BLOCK_MSL_FLAG
Definition:
database_cfg.h:423
DATA_BLOCK_ID_ERRORSTATE
@ DATA_BLOCK_ID_ERRORSTATE
Definition:
database_cfg.h:83
DATA_BLOCK_ERRORSTATE
Definition:
database_cfg.h:320
DATA_BLOCK_RSL_FLAG
Definition:
database_cfg.h:445
NULL_PTR
#define NULL_PTR
Null pointer.
Definition:
fstd_types.h:66
test_tableErrorFlags
static DATA_BLOCK_ERRORSTATE_s test_tableErrorFlags
Definition:
test_diag_cbs_interlock.c:65
DIAG_DATABASE_SHIM::pTableError
DATA_BLOCK_ERRORSTATE_s * pTableError
Definition:
diag_cfg.h:114
TEST_ASSERT_FAIL_ASSERT
#define TEST_ASSERT_FAIL_ASSERT(_code_under_test)
assert whether assert macro has failed
Definition:
test_assert_helper.h:70
diag_kpkDatabaseShim
const DIAG_DATABASE_SHIM_s diag_kpkDatabaseShim
Definition:
test_diag_cbs_interlock.c:76
DIAG_ID_MAX
@ DIAG_ID_MAX
Definition:
diag_cfg.h:196
DATA_BLOCKHEADER::uniqueId
DATA_BLOCK_ID_e uniqueId
Definition:
database_cfg.h:109
tests
unit
app
engine
diag
cbs
test_diag_cbs_interlock.c
Generated by
1.8.20