foxBMS - Unit Tests  1.2.1
The foxBMS Unit Tests API Documentation
test_database.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_database.c
44  * @author foxBMS Team
45  * @date 2020-04-01 (date of creation)
46  * @updated 2021-12-01 (date of last update)
47  * @ingroup UNIT_TEST_IMPLEMENTATION
48  * @prefix TEST
49  *
50  * @brief Tests for the database driver
51  *
52  */
53 
54 /*========== Includes =======================================================*/
55 #include "general.h"
56 
57 #include "unity.h"
58 #include "Mockfassert.h"
59 #include "Mockftask.h"
60 #include "Mockmpu_prototypes.h"
61 #include "Mockos.h"
62 
63 #include "database_cfg.h"
64 
65 #include "database.h"
66 #include "test_assert_helper.h"
67 
68 /*========== Definitions and Implementations for Unit Test ==================*/
69 /**
70  * struct for message injection in database queue in #testDATA_ExecuteDataBIST()
71  */
73  DATA_BLOCK_ACCESS_TYPE_e accesstype; /*!< read or write access type */
74  DATA_BLOCK_DUMMY_FOR_SELF_TEST_s *pDatabaseEntry[1u]; /*!< reference to table */
76 
77 QueueHandle_t ftsk_databaseQueue = NULL_PTR;
79 QueueHandle_t ftsk_canRxQueue = NULL_PTR;
80 volatile bool ftsk_allQueuesCreated = true;
81 
82 /*========== Setup and Teardown =============================================*/
83 void setUp(void) {
84 }
85 
86 void tearDown(void) {
87 }
88 
89 void testDummy(void) {
90 }
91 
92 /** callback for #testDATA_ExecuteDataBIST(); this not work for other instances */
94  OS_QUEUE xQueue,
95  const void *const pvItemToQueue,
96  uint32_t xTicksToWait,
97  int cmock_num_calls) {
98  const DATA_QUEUE_BIST_INJECTED_MESSAGE_s *const injectQueueMessage = pvItemToQueue;
99  /* inject the values into the message for a read access */
100  if (injectQueueMessage->accesstype == DATA_READ_ACCESS) {
101  injectQueueMessage->pDatabaseEntry[0u]->member1 = UINT8_MAX;
103  }
104 
105  return OS_SUCCESS;
106 }
107 
110  const uint8_t testValue = DATA_DUMMY_VALUE_UINT8_T_ALTERNATING_BIT_PATTERN;
111  dummyTable.member1 = UINT8_MAX;
112  dummyTable.member2 = testValue;
113  OS_SendToBackOfQueue_Stub(&DATA_mpuInjectValuesForExecuteBISTTestCallback);
115 }
116 
117 /*========== Test Cases =====================================================*/
void DATA_ExecuteDataBIST(void)
Executes a built-in self-test for the database module.
Definition: database.c:292
Database module header.
enum DATA_BLOCK_ACCESS_TYPE DATA_BLOCK_ACCESS_TYPE_e
data block access types (read or write)
@ DATA_READ_ACCESS
Definition: database.h:101
#define DATA_DUMMY_VALUE_UINT8_T_ALTERNATING_BIT_PATTERN
Definition: database.h:105
Database configuration header.
@ DATA_BLOCK_ID_DUMMY_FOR_SELF_TEST
Definition: database_cfg.h:105
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:75
General macros and definitions for the whole platform.
enum OS_STD_RETURN OS_STD_RETURN_e
@ OS_SUCCESS
Definition: os.h:77
DATA_BLOCK_ID_e uniqueId
Definition: database_cfg.h:111
DATA_BLOCK_HEADER_s header
Definition: database_cfg.h:575
DATA_BLOCK_DUMMY_FOR_SELF_TEST_s * pDatabaseEntry[1u]
Definition: test_database.c:74
DATA_BLOCK_ACCESS_TYPE_e accesstype
Definition: test_database.c:73
Helper for unit tests.
#define TEST_ASSERT_PASS_ASSERT(_code_under_test)
assert whether assert macro has passed
volatile bool ftsk_allQueuesCreated
Definition: test_database.c:80
QueueHandle_t ftsk_databaseQueue
Definition: test_database.c:77
void testDummy(void)
Definition: test_database.c:89
struct DATA_QUEUE_BIST_INJECTED_MESSAGE DATA_QUEUE_BIST_INJECTED_MESSAGE_s
OS_STD_RETURN_e DATA_mpuInjectValuesForExecuteBISTTestCallback(OS_QUEUE xQueue, const void *const pvItemToQueue, uint32_t xTicksToWait, int cmock_num_calls)
Definition: test_database.c:93
void setUp(void)
Definition: test_database.c:83
void tearDown(void)
Definition: test_database.c:86
void testDATA_ExecuteDataBIST(void)
QueueHandle_t ftsk_canRxQueue
Definition: test_database.c:79
QueueHandle_t ftsk_imdCanDataQueue
Definition: test_database.c:78