foxBMS - Unit Tests  1.6.0
The foxBMS Unit Tests API Documentation
test_can.c File Reference

Tests for the CAN driver. More...

#include "unity.h"
#include "MockHL_can.h"
#include "Mockcan_cfg.h"
#include "Mockdatabase.h"
#include "Mockdiag.h"
#include "Mockfoxmath.h"
#include "Mockftask.h"
#include "Mockimd.h"
#include "Mockio.h"
#include "Mockmcu.h"
#include "Mockos.h"
#include "Mockpex.h"
#include "Mockqueue.h"
#include "Mocktest_can_mpu_prototype_queue_create_stub.h"
#include "version_cfg.h"
#include "can.h"
#include "test_assert_helper.h"
#include <stdbool.h>
#include <stdint.h>
Include dependency graph for test_can.c:

Go to the source code of this file.

Macros

#define CANRX_NOT_PERIODIC   (0u)
 
#define TEST_CANTX_ID_DUMMY   (0x001)
 
#define TEST_CANTX_DUMMY_PERIOD_ms   (100)
 
#define TEST_CANTX_DUMMY_PHASE_ms   (0)
 
#define TEST_CANTX_DUMMY_MESSAGE
 
#define TEST_CANRX_ID_DUMMY   (0x002)
 
#define TEST_CANRX_DUMMY_MESSAGE
 

Functions

static uint32_t TEST_CANTX_DummyCallback (CAN_MESSAGE_PROPERTIES_s message, uint8_t *pCanData, uint8_t *pMuxId, const CAN_SHIM_s *const kpkCanShim)
 
static uint32_t TEST_CANRX_DummyCallback (CAN_MESSAGE_PROPERTIES_s message, const uint8_t *const kpkCanData, const CAN_SHIM_s *const kpkCanShim)
 
void setUp (void)
 
void tearDown (void)
 
void testDataSendNullPointerAsNode (void)
 
void testDataSendNullPointerAsData (void)
 
void testDataSendNoMessagePending (void)
 
void testDataSendInvalidIdentifierType (void)
 
void testDataSendMessagePending (void)
 
void testEnablePeriodic (void)
 
void testIsCurrentSensorPresent (void)
 
void testIsCurrentSensorCcPresent (void)
 
void testCAN_ValidateConfiguredTxMessagePeriod (void)
 
void testCAN_ValidateConfiguredTxMessagePhase (void)
 
void testCAN_CheckDatabaseNullPointer (void)
 
void testCAN_PeriodicTransmitQueueFull (void)
 
void testCAN_PeriodicTransmitQueueHasSpace (void)
 
void testCAN_IsMessagePeriodElapsed (void)
 
void testCAN_SendMessagesFromQueue (void)
 

Variables

const CAN_NODE_s can_node1
 
const CAN_NODE_s can_node2Isolated
 
static DATA_BLOCK_CELL_TEMPERATURE_s can_tableTemperatures = {.header.uniqueId = DATA_BLOCK_ID_CELL_TEMPERATURE}
 
static DATA_BLOCK_CELL_VOLTAGE_s can_tableCellVoltages = {.header.uniqueId = DATA_BLOCK_ID_CELL_VOLTAGE}
 
static DATA_BLOCK_CURRENT_SENSOR_s can_tableCurrentSensor = {.header.uniqueId = DATA_BLOCK_ID_CURRENT_SENSOR}
 
static DATA_BLOCK_ERROR_STATE_s can_tableErrorState = {.header.uniqueId = DATA_BLOCK_ID_ERROR_STATE}
 
static DATA_BLOCK_INSULATION_MONITORING_s can_tableInsulation
 
static DATA_BLOCK_MIN_MAX_s can_tableMinimumMaximumValues = {.header.uniqueId = DATA_BLOCK_ID_MIN_MAX}
 
static DATA_BLOCK_MOL_FLAG_s can_tableMolFlags = {.header.uniqueId = DATA_BLOCK_ID_MOL_FLAG}
 
static DATA_BLOCK_MSL_FLAG_s can_tableMslFlags = {.header.uniqueId = DATA_BLOCK_ID_MSL_FLAG}
 
static DATA_BLOCK_OPEN_WIRE_s can_tableOpenWire = {.header.uniqueId = DATA_BLOCK_ID_OPEN_WIRE_BASE}
 
static DATA_BLOCK_PACK_VALUES_s can_tablePackValues = {.header.uniqueId = DATA_BLOCK_ID_PACK_VALUES}
 
static DATA_BLOCK_RSL_FLAG_s can_tableRslFlags = {.header.uniqueId = DATA_BLOCK_ID_RSL_FLAG}
 
static DATA_BLOCK_SOC_s can_tableSoc = {.header.uniqueId = DATA_BLOCK_ID_SOC}
 
static DATA_BLOCK_SOE_s can_tableSoe = {.header.uniqueId = DATA_BLOCK_ID_SOE}
 
static DATA_BLOCK_SOH_s can_tableSoh = {.header.uniqueId = DATA_BLOCK_ID_SOH}
 
static DATA_BLOCK_STATE_REQUEST_s can_tableStateRequest = {.header.uniqueId = DATA_BLOCK_ID_STATE_REQUEST}
 
OS_QUEUE imd_canDataQueue = NULL_PTR
 
const CAN_SHIM_s can_kShim
 
const CAN_TX_MESSAGE_TYPE_s can_txMessages []
 
const CAN_RX_MESSAGE_TYPE_s can_rxMessages []
 
const uint8_t can_txMessagesLength = sizeof(can_txMessages) / sizeof(can_txMessages[0])
 
const uint8_t can_rxMessagesLength = sizeof(can_rxMessages) / sizeof(can_rxMessages[0])
 
CAN_BUFFER_ELEMENT_s dummyMessageBuffer
 
const uint16_t numberOfRepetitionsToReset = (TEST_CANTX_DUMMY_PERIOD_ms / CAN_TICK_ms) - 1
 
CAN_STATE_scanTestState = NULL_PTR
 
OS_QUEUE ftsk_dataQueue = NULL_PTR
 
OS_QUEUE ftsk_imdCanDataQueue = NULL_PTR
 
OS_QUEUE ftsk_canRxQueue = NULL_PTR
 
OS_QUEUE ftsk_canTxUnsentMessagesQueue = NULL_PTR
 
volatile bool ftsk_allQueuesCreated = false
 

Detailed Description

Tests for the CAN driver.

SPDX-License-Identifier: BSD-3-Clause

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

We kindly request you to use one or more of the following phrases to refer to foxBMS in your hardware, software, documentation or advertising materials:

  • ″This product uses parts of foxBMS®″
  • ″This product includes parts of foxBMS®″
  • ″This product is derived from foxBMS®″
Author
foxBMS Team
Date
2020-04-01 (date of creation)
Updated
2023-10-12 (date of last update)
Version
v1.6.0
Prefix
TEST

This file implements the test of the validation functions for tx message configuration with correct configuration for message period and phase. Both functions are tested to not assert an error with valid configuration. Invalid configurations are tested in test_can_1 and test_can_2.

Definition in file test_can.c.

Macro Definition Documentation

◆ CANRX_NOT_PERIODIC

#define CANRX_NOT_PERIODIC   (0u)

Definition at line 99 of file test_can.c.

◆ TEST_CANRX_DUMMY_MESSAGE

#define TEST_CANRX_DUMMY_MESSAGE
Value:
{ \
.dlc = CAN_DEFAULT_DLC, \
.endianness = CAN_LITTLE_ENDIAN, \
}, \
{ \
.period = CANRX_NOT_PERIODIC \
}
@ CAN_LITTLE_ENDIAN
Definition: can_cfg.h:157
#define CAN_DEFAULT_DLC
Definition: can_cfg.h:103
@ CAN_STANDARD_IDENTIFIER_11_BIT
Definition: can_cfg.h:163
#define CANRX_NOT_PERIODIC
Definition: test_can.c:99
#define TEST_CANRX_ID_DUMMY
Definition: test_can.c:118

Definition at line 120 of file test_can.c.

◆ TEST_CANRX_ID_DUMMY

#define TEST_CANRX_ID_DUMMY   (0x002)

Definition at line 118 of file test_can.c.

◆ TEST_CANTX_DUMMY_MESSAGE

#define TEST_CANTX_DUMMY_MESSAGE
Value:
{ \
.dlc = CAN_DEFAULT_DLC, \
.endianness = CAN_LITTLE_ENDIAN, \
}, \
{ \
}
#define TEST_CANTX_ID_DUMMY
Definition: test_can.c:102
#define TEST_CANTX_DUMMY_PERIOD_ms
Definition: test_can.c:103
#define TEST_CANTX_DUMMY_PHASE_ms
Definition: test_can.c:104

Definition at line 106 of file test_can.c.

◆ TEST_CANTX_DUMMY_PERIOD_ms

#define TEST_CANTX_DUMMY_PERIOD_ms   (100)

Definition at line 103 of file test_can.c.

◆ TEST_CANTX_DUMMY_PHASE_ms

#define TEST_CANTX_DUMMY_PHASE_ms   (0)

Definition at line 104 of file test_can.c.

◆ TEST_CANTX_ID_DUMMY

#define TEST_CANTX_ID_DUMMY   (0x001)

Definition at line 102 of file test_can.c.

Function Documentation

◆ setUp()

void setUp ( void  )

Definition at line 221 of file test_can.c.

Here is the call graph for this function:

◆ tearDown()

void tearDown ( void  )

Definition at line 232 of file test_can.c.

◆ TEST_CANRX_DummyCallback()

static uint32_t TEST_CANRX_DummyCallback ( CAN_MESSAGE_PROPERTIES_s  message,
const uint8_t *const  kpkCanData,
const CAN_SHIM_s *const  kpkCanShim 
)
static

Definition at line 186 of file test_can.c.

◆ TEST_CANTX_DummyCallback()

static uint32_t TEST_CANTX_DummyCallback ( CAN_MESSAGE_PROPERTIES_s  message,
uint8_t *  pCanData,
uint8_t *  pMuxId,
const CAN_SHIM_s *const  kpkCanShim 
)
static

Definition at line 178 of file test_can.c.

◆ testCAN_CheckDatabaseNullPointer()

void testCAN_CheckDatabaseNullPointer ( void  )

Definition at line 341 of file test_can.c.

Here is the call graph for this function:

◆ testCAN_IsMessagePeriodElapsed()

void testCAN_IsMessagePeriodElapsed ( void  )

Definition at line 410 of file test_can.c.

Here is the call graph for this function:

◆ testCAN_PeriodicTransmitQueueFull()

void testCAN_PeriodicTransmitQueueFull ( void  )

Definition at line 366 of file test_can.c.

Here is the call graph for this function:

◆ testCAN_PeriodicTransmitQueueHasSpace()

void testCAN_PeriodicTransmitQueueHasSpace ( void  )

Definition at line 388 of file test_can.c.

Here is the call graph for this function:

◆ testCAN_SendMessagesFromQueue()

void testCAN_SendMessagesFromQueue ( void  )

only test the case of failing, because the case of successful call would require actual (not mocked) call of OS_ReceiveFromQueue to write to message buffer

Definition at line 421 of file test_can.c.

Here is the call graph for this function:

◆ testCAN_ValidateConfiguredTxMessagePeriod()

void testCAN_ValidateConfiguredTxMessagePeriod ( void  )

Definition at line 333 of file test_can.c.

Here is the call graph for this function:

◆ testCAN_ValidateConfiguredTxMessagePhase()

void testCAN_ValidateConfiguredTxMessagePhase ( void  )

Definition at line 337 of file test_can.c.

Here is the call graph for this function:

◆ testDataSendInvalidIdentifierType()

void testDataSendInvalidIdentifierType ( void  )

Definition at line 263 of file test_can.c.

Here is the call graph for this function:

◆ testDataSendMessagePending()

void testDataSendMessagePending ( void  )

Definition at line 272 of file test_can.c.

Here is the call graph for this function:

◆ testDataSendNoMessagePending()

void testDataSendNoMessagePending ( void  )

Definition at line 252 of file test_can.c.

Here is the call graph for this function:

◆ testDataSendNullPointerAsData()

void testDataSendNullPointerAsData ( void  )

Definition at line 244 of file test_can.c.

Here is the call graph for this function:

◆ testDataSendNullPointerAsNode()

void testDataSendNullPointerAsNode ( void  )

Definition at line 236 of file test_can.c.

Here is the call graph for this function:

◆ testEnablePeriodic()

void testEnablePeriodic ( void  )

Definition at line 293 of file test_can.c.

Here is the call graph for this function:

◆ testIsCurrentSensorCcPresent()

void testIsCurrentSensorCcPresent ( void  )

Definition at line 319 of file test_can.c.

Here is the call graph for this function:

◆ testIsCurrentSensorPresent()

void testIsCurrentSensorPresent ( void  )

Definition at line 304 of file test_can.c.

Here is the call graph for this function:

Variable Documentation

◆ can_kShim

const CAN_SHIM_s can_kShim
Initial value:
= {
.pQueueImd = &ftsk_imdCanDataQueue,
.pTableCellTemperature = &can_tableTemperatures,
.pTableCellVoltage = &can_tableCellVoltages,
.pTableCurrentSensor = &can_tableCurrentSensor,
.pTableErrorState = &can_tableErrorState,
.pTableInsulation = &can_tableInsulation,
.pTableMol = &can_tableMolFlags,
.pTableMsl = &can_tableMslFlags,
.pTableOpenWire = &can_tableOpenWire,
.pTablePackValues = &can_tablePackValues,
.pTableRsl = &can_tableRslFlags,
.pTableSoc = &can_tableSoc,
.pTableSoe = &can_tableSoe,
.pTableSof = NULL_PTR,
.pTableSoh = &can_tableSoh,
.pTableStateRequest = &can_tableStateRequest,
}
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:77
static DATA_BLOCK_CELL_VOLTAGE_s can_tableCellVoltages
Definition: test_can.c:140
static DATA_BLOCK_MSL_FLAG_s can_tableMslFlags
Definition: test_can.c:147
OS_QUEUE ftsk_imdCanDataQueue
Definition: test_can.c:215
static DATA_BLOCK_MIN_MAX_s can_tableMinimumMaximumValues
Definition: test_can.c:145
static DATA_BLOCK_OPEN_WIRE_s can_tableOpenWire
Definition: test_can.c:148
static DATA_BLOCK_PACK_VALUES_s can_tablePackValues
Definition: test_can.c:149
static DATA_BLOCK_MOL_FLAG_s can_tableMolFlags
Definition: test_can.c:146
static DATA_BLOCK_SOH_s can_tableSoh
Definition: test_can.c:153
static DATA_BLOCK_ERROR_STATE_s can_tableErrorState
Definition: test_can.c:142
static DATA_BLOCK_CELL_TEMPERATURE_s can_tableTemperatures
Definition: test_can.c:139
static DATA_BLOCK_SOE_s can_tableSoe
Definition: test_can.c:152
static DATA_BLOCK_RSL_FLAG_s can_tableRslFlags
Definition: test_can.c:150
static DATA_BLOCK_STATE_REQUEST_s can_tableStateRequest
Definition: test_can.c:154
static DATA_BLOCK_INSULATION_MONITORING_s can_tableInsulation
Definition: test_can.c:143
static DATA_BLOCK_SOC_s can_tableSoc
Definition: test_can.c:151
static DATA_BLOCK_CURRENT_SENSOR_s can_tableCurrentSensor
Definition: test_can.c:141

variable for storing and passing on the local database table handles

Definition at line 158 of file test_can.c.

◆ can_node1

const CAN_NODE_s can_node1
Initial value:
= {
.canNodeRegister = canREG1,
}

CAN node configurations for CAN1 and CAN2 (isolated)

Definition at line 131 of file test_can.c.

◆ can_node2Isolated

const CAN_NODE_s can_node2Isolated
Initial value:
= {
.canNodeRegister = canREG2,
}

Definition at line 135 of file test_can.c.

◆ can_rxMessages

const CAN_RX_MESSAGE_TYPE_s can_rxMessages[]
Initial value:
= {
}
#define CAN_NODE_1
Definition: can_cfg.h:80
#define TEST_CANRX_DUMMY_MESSAGE
Definition: test_can.c:120
static uint32_t TEST_CANRX_DummyCallback(CAN_MESSAGE_PROPERTIES_s message, const uint8_t *const kpkCanData, const CAN_SHIM_s *const kpkCanShim)
Definition: test_can.c:186

registry of CAN RX messages

Definition at line 197 of file test_can.c.

◆ can_rxMessagesLength

const uint8_t can_rxMessagesLength = sizeof(can_rxMessages) / sizeof(can_rxMessages[0])

length of CAN message arrays

Definition at line 202 of file test_can.c.

◆ can_tableCellVoltages

DATA_BLOCK_CELL_VOLTAGE_s can_tableCellVoltages = {.header.uniqueId = DATA_BLOCK_ID_CELL_VOLTAGE}
static

Definition at line 140 of file test_can.c.

◆ can_tableCurrentSensor

DATA_BLOCK_CURRENT_SENSOR_s can_tableCurrentSensor = {.header.uniqueId = DATA_BLOCK_ID_CURRENT_SENSOR}
static

Definition at line 141 of file test_can.c.

◆ can_tableErrorState

DATA_BLOCK_ERROR_STATE_s can_tableErrorState = {.header.uniqueId = DATA_BLOCK_ID_ERROR_STATE}
static

Definition at line 142 of file test_can.c.

◆ can_tableInsulation

DATA_BLOCK_INSULATION_MONITORING_s can_tableInsulation
static
Initial value:
= {
@ DATA_BLOCK_ID_INSULATION_MONITORING
Definition: database_cfg.h:97

Definition at line 143 of file test_can.c.

◆ can_tableMinimumMaximumValues

DATA_BLOCK_MIN_MAX_s can_tableMinimumMaximumValues = {.header.uniqueId = DATA_BLOCK_ID_MIN_MAX}
static

Definition at line 145 of file test_can.c.

◆ can_tableMolFlags

DATA_BLOCK_MOL_FLAG_s can_tableMolFlags = {.header.uniqueId = DATA_BLOCK_ID_MOL_FLAG}
static

Definition at line 146 of file test_can.c.

◆ can_tableMslFlags

DATA_BLOCK_MSL_FLAG_s can_tableMslFlags = {.header.uniqueId = DATA_BLOCK_ID_MSL_FLAG}
static

Definition at line 147 of file test_can.c.

◆ can_tableOpenWire

DATA_BLOCK_OPEN_WIRE_s can_tableOpenWire = {.header.uniqueId = DATA_BLOCK_ID_OPEN_WIRE_BASE}
static

Definition at line 148 of file test_can.c.

◆ can_tablePackValues

DATA_BLOCK_PACK_VALUES_s can_tablePackValues = {.header.uniqueId = DATA_BLOCK_ID_PACK_VALUES}
static

Definition at line 149 of file test_can.c.

◆ can_tableRslFlags

DATA_BLOCK_RSL_FLAG_s can_tableRslFlags = {.header.uniqueId = DATA_BLOCK_ID_RSL_FLAG}
static

Definition at line 150 of file test_can.c.

◆ can_tableSoc

DATA_BLOCK_SOC_s can_tableSoc = {.header.uniqueId = DATA_BLOCK_ID_SOC}
static

Definition at line 151 of file test_can.c.

◆ can_tableSoe

DATA_BLOCK_SOE_s can_tableSoe = {.header.uniqueId = DATA_BLOCK_ID_SOE}
static

Definition at line 152 of file test_can.c.

◆ can_tableSoh

DATA_BLOCK_SOH_s can_tableSoh = {.header.uniqueId = DATA_BLOCK_ID_SOH}
static

Definition at line 153 of file test_can.c.

◆ can_tableStateRequest

DATA_BLOCK_STATE_REQUEST_s can_tableStateRequest = {.header.uniqueId = DATA_BLOCK_ID_STATE_REQUEST}
static

Definition at line 154 of file test_can.c.

◆ can_tableTemperatures

DATA_BLOCK_CELL_TEMPERATURE_s can_tableTemperatures = {.header.uniqueId = DATA_BLOCK_ID_CELL_TEMPERATURE}
static

Definition at line 139 of file test_can.c.

◆ can_txMessages

const CAN_TX_MESSAGE_TYPE_s can_txMessages[]
Initial value:
= {
}
static uint32_t TEST_CANTX_DummyCallback(CAN_MESSAGE_PROPERTIES_s message, uint8_t *pCanData, uint8_t *pMuxId, const CAN_SHIM_s *const kpkCanShim)
Definition: test_can.c:178
#define TEST_CANTX_DUMMY_MESSAGE
Definition: test_can.c:106

CAN RX and TX message configuration structs

registry of CAN TX messages

Definition at line 193 of file test_can.c.

◆ can_txMessagesLength

const uint8_t can_txMessagesLength = sizeof(can_txMessages) / sizeof(can_txMessages[0])

array length for transmission CAN0 message definition

length of CAN message arrays

Definition at line 201 of file test_can.c.

◆ canTestState

CAN_STATE_s* canTestState = NULL_PTR

Definition at line 212 of file test_can.c.

◆ dummyMessageBuffer

CAN_BUFFER_ELEMENT_s dummyMessageBuffer
Initial value:
= {
.canNode = CAN_NODE_1,
.data = {0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u}}

Definition at line 204 of file test_can.c.

◆ ftsk_allQueuesCreated

volatile bool ftsk_allQueuesCreated = false

indicator whether the queues have successfully been initialized to be used in other parts of the software

Definition at line 218 of file test_can.c.

◆ ftsk_canRxQueue

OS_QUEUE ftsk_canRxQueue = NULL_PTR

CAN driver data queue for RX messages

Definition at line 216 of file test_can.c.

◆ ftsk_canTxUnsentMessagesQueue

OS_QUEUE ftsk_canTxUnsentMessagesQueue = NULL_PTR

CAN driver data queue for unsent TX messages

Definition at line 217 of file test_can.c.

◆ ftsk_dataQueue

OS_QUEUE ftsk_dataQueue = NULL_PTR

Definition at line 214 of file test_can.c.

◆ ftsk_imdCanDataQueue

OS_QUEUE ftsk_imdCanDataQueue = NULL_PTR

queue for CAN based IMD devices

Definition at line 215 of file test_can.c.

◆ imd_canDataQueue

OS_QUEUE imd_canDataQueue = NULL_PTR

Definition at line 156 of file test_can.c.

◆ numberOfRepetitionsToReset

const uint16_t numberOfRepetitionsToReset = (TEST_CANTX_DUMMY_PERIOD_ms / CAN_TICK_ms) - 1

Definition at line 210 of file test_can.c.