Issue 87 execute tests with GitHub ci (#234)
* Enable lcov coverage in unit testing via cmake. * fix pipeline build error * add compile options for unit test to silence some warnings * remove all BAC_TEST unit tests in src/bacnet/ folder. They are now in test/bacnet/ folders using ztest. * removed key.c - only used for unit test. * produce XML test result output for parsing * produce junit XML test result output * change lint workflow to quality * update readme badge for quality results Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
@@ -1251,487 +1251,3 @@ void MSTP_Init(volatile struct mstp_port_struct_t *mstp_port)
|
||||
mstp_port->TokenCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "bacnet/basic/sys/ringbuf.h"
|
||||
#include "ctest.h"
|
||||
|
||||
static uint8_t RxBuffer[MAX_MPDU];
|
||||
static uint8_t TxBuffer[MAX_MPDU];
|
||||
/* test stub functions */
|
||||
void RS485_Send_Frame(
|
||||
volatile struct mstp_port_struct_t *mstp_port, /* port specific data */
|
||||
uint8_t *buffer, /* frame to send (up to 501 bytes of data) */
|
||||
uint16_t nbytes)
|
||||
{ /* number of bytes of data (up to 501) */
|
||||
(void)mstp_port;
|
||||
(void)buffer;
|
||||
(void)nbytes;
|
||||
}
|
||||
|
||||
#define RING_BUFFER_DATA_SIZE 1
|
||||
#define RING_BUFFER_SIZE MAX_MPDU
|
||||
static RING_BUFFER Test_Buffer;
|
||||
static uint8_t Test_Buffer_Data[RING_BUFFER_DATA_SIZE * RING_BUFFER_SIZE];
|
||||
static void Load_Input_Buffer(uint8_t *buffer, size_t len)
|
||||
{
|
||||
static bool initialized = false; /* tracks our init */
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
Ringbuf_Init(&Test_Buffer, (char *)Test_Buffer_Data,
|
||||
RING_BUFFER_DATA_SIZE, RING_BUFFER_SIZE);
|
||||
}
|
||||
/* empty any the existing data */
|
||||
while (!Ringbuf_Empty(&Test_Buffer)) {
|
||||
(void)Ringbuf_Pop(&Test_Buffer, NULL);
|
||||
}
|
||||
|
||||
if (buffer) {
|
||||
while (len) {
|
||||
(void)Ringbuf_Put(&Test_Buffer, (char *)buffer);
|
||||
len--;
|
||||
buffer++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port)
|
||||
{ /* port specific data */
|
||||
char *data;
|
||||
if (!Ringbuf_Empty(&Test_Buffer) && mstp_port &&
|
||||
(mstp_port->DataAvailable == false)) {
|
||||
data = Ringbuf_Peek(&Test_Buffer);
|
||||
if (data) {
|
||||
mstp_port->DataRegister = *data;
|
||||
mstp_port->DataAvailable = true;
|
||||
}
|
||||
(void)Ringbuf_Pop(&Test_Buffer, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t MSTP_Put_Receive(volatile struct mstp_port_struct_t *mstp_port)
|
||||
{
|
||||
return mstp_port->DataLength;
|
||||
}
|
||||
|
||||
/* for the MS/TP state machine to use for getting data to send */
|
||||
/* Return: amount of PDU data */
|
||||
uint16_t MSTP_Get_Send(
|
||||
volatile struct mstp_port_struct_t *mstp_port, unsigned timeout)
|
||||
{ /* milliseconds to wait for a packet */
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t MSTP_Get_Reply(
|
||||
volatile struct mstp_port_struct_t *mstp_port, unsigned timeout)
|
||||
{ /* milliseconds to wait for a packet */
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t SilenceTime = 0;
|
||||
static uint16_t Timer_Silence(void)
|
||||
{
|
||||
return SilenceTime;
|
||||
}
|
||||
|
||||
static void Timer_Silence_Reset(void)
|
||||
{
|
||||
SilenceTime = 0;
|
||||
}
|
||||
|
||||
void testReceiveNodeFSM(Test *pTest)
|
||||
{
|
||||
volatile struct mstp_port_struct_t mstp_port; /* port data */
|
||||
unsigned EventCount = 0; /* local counter */
|
||||
uint8_t my_mac = 0x05; /* local MAC address */
|
||||
uint8_t HeaderCRC = 0; /* for local CRC calculation */
|
||||
uint8_t FrameType = 0; /* type of packet that was sent */
|
||||
unsigned len; /* used for the size of the message packet */
|
||||
size_t i; /* used to loop through the message bytes */
|
||||
uint8_t buffer[MAX_MPDU] = { 0 };
|
||||
uint8_t data[MAX_PDU] = { 0 };
|
||||
mstp_port.InputBuffer = &RxBuffer[0];
|
||||
mstp_port.InputBufferSize = sizeof(RxBuffer);
|
||||
mstp_port.OutputBuffer = &TxBuffer[0];
|
||||
mstp_port.OutputBufferSize = sizeof(TxBuffer);
|
||||
mstp_port.SilenceTimer = Timer_Silence;
|
||||
mstp_port.SilenceTimerReset = Timer_Silence_Reset;
|
||||
mstp_port.This_Station = my_mac;
|
||||
mstp_port.Nmax_info_frames = 1;
|
||||
mstp_port.Nmax_master = 127;
|
||||
MSTP_Init(&mstp_port);
|
||||
/* check the receive error during idle */
|
||||
mstp_port.receive_state = MSTP_RECEIVE_STATE_IDLE;
|
||||
mstp_port.ReceiveError = true;
|
||||
SilenceTime = 255;
|
||||
mstp_port.EventCount = 0;
|
||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||
ct_test(pTest, mstp_port.ReceiveError == false);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
||||
/* check for bad packet header */
|
||||
mstp_port.DataAvailable = true;
|
||||
mstp_port.DataRegister = 0x11;
|
||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
||||
/* check for good packet header, but timeout */
|
||||
mstp_port.DataAvailable = true;
|
||||
mstp_port.DataRegister = 0x55;
|
||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
|
||||
/* force the timeout */
|
||||
SilenceTime = Tframe_abort + 1;
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
||||
/* check for good packet header preamble, but receive error */
|
||||
mstp_port.DataAvailable = true;
|
||||
mstp_port.DataRegister = 0x55;
|
||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
|
||||
/* force the error */
|
||||
mstp_port.ReceiveError = true;
|
||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.ReceiveError == false);
|
||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
||||
/* check for good packet header preamble1, but bad preamble2 */
|
||||
mstp_port.DataAvailable = true;
|
||||
mstp_port.DataRegister = 0x55;
|
||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
/* no change of state if no data yet */
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
|
||||
/* repeated preamble1 */
|
||||
mstp_port.DataAvailable = true;
|
||||
mstp_port.DataRegister = 0x55;
|
||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
|
||||
/* repeated preamble1 */
|
||||
mstp_port.DataAvailable = true;
|
||||
mstp_port.DataRegister = 0x55;
|
||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
|
||||
/* bad data */
|
||||
mstp_port.DataAvailable = true;
|
||||
mstp_port.DataRegister = 0x11;
|
||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.ReceiveError == false);
|
||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
||||
/* check for good packet header preamble, but timeout in packet */
|
||||
mstp_port.DataAvailable = true;
|
||||
mstp_port.DataRegister = 0x55;
|
||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
/* preamble2 */
|
||||
mstp_port.DataAvailable = true;
|
||||
mstp_port.DataRegister = 0xFF;
|
||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||
ct_test(pTest, mstp_port.Index == 0);
|
||||
ct_test(pTest, mstp_port.HeaderCRC == 0xFF);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER);
|
||||
/* force the timeout */
|
||||
SilenceTime = Tframe_abort + 1;
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
||||
ct_test(pTest, mstp_port.ReceivedInvalidFrame == true);
|
||||
/* check for good packet header preamble, but error in packet */
|
||||
mstp_port.DataAvailable = true;
|
||||
mstp_port.DataRegister = 0x55;
|
||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
/* preamble2 */
|
||||
mstp_port.DataAvailable = true;
|
||||
mstp_port.DataRegister = 0xFF;
|
||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||
ct_test(pTest, mstp_port.Index == 0);
|
||||
ct_test(pTest, mstp_port.HeaderCRC == 0xFF);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER);
|
||||
/* force the error */
|
||||
mstp_port.ReceiveError = true;
|
||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.ReceiveError == false);
|
||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
||||
/* check for good packet header preamble */
|
||||
mstp_port.DataAvailable = true;
|
||||
mstp_port.DataRegister = 0x55;
|
||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
/* preamble2 */
|
||||
mstp_port.DataAvailable = true;
|
||||
mstp_port.DataRegister = 0xFF;
|
||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||
ct_test(pTest, mstp_port.Index == 0);
|
||||
ct_test(pTest, mstp_port.HeaderCRC == 0xFF);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER);
|
||||
/* no change of state if no data yet */
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER);
|
||||
/* Data is received - index is incremented */
|
||||
/* FrameType */
|
||||
mstp_port.DataAvailable = true;
|
||||
mstp_port.DataRegister = FRAME_TYPE_TOKEN;
|
||||
HeaderCRC = 0xFF;
|
||||
HeaderCRC = CRC_Calc_Header(mstp_port.DataRegister, HeaderCRC);
|
||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||
ct_test(pTest, mstp_port.Index == 1);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER);
|
||||
ct_test(pTest, FrameType == FRAME_TYPE_TOKEN);
|
||||
/* Destination */
|
||||
mstp_port.DataAvailable = true;
|
||||
mstp_port.DataRegister = 0x10;
|
||||
HeaderCRC = CRC_Calc_Header(mstp_port.DataRegister, HeaderCRC);
|
||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||
ct_test(pTest, mstp_port.Index == 2);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER);
|
||||
ct_test(pTest, mstp_port.DestinationAddress == 0x10);
|
||||
/* Source */
|
||||
mstp_port.DataAvailable = true;
|
||||
mstp_port.DataRegister = my_mac;
|
||||
HeaderCRC = CRC_Calc_Header(mstp_port.DataRegister, HeaderCRC);
|
||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||
ct_test(pTest, mstp_port.Index == 3);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER);
|
||||
ct_test(pTest, mstp_port.SourceAddress == my_mac);
|
||||
/* Length1 = length*256 */
|
||||
mstp_port.DataAvailable = true;
|
||||
mstp_port.DataRegister = 0;
|
||||
HeaderCRC = CRC_Calc_Header(mstp_port.DataRegister, HeaderCRC);
|
||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||
ct_test(pTest, mstp_port.Index == 4);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER);
|
||||
ct_test(pTest, mstp_port.DataLength == 0);
|
||||
/* Length2 */
|
||||
mstp_port.DataAvailable = true;
|
||||
mstp_port.DataRegister = 0;
|
||||
HeaderCRC = CRC_Calc_Header(mstp_port.DataRegister, HeaderCRC);
|
||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||
ct_test(pTest, mstp_port.Index == 5);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER);
|
||||
ct_test(pTest, mstp_port.DataLength == 0);
|
||||
/* HeaderCRC */
|
||||
mstp_port.DataAvailable = true;
|
||||
ct_test(pTest, HeaderCRC == 0x73); /* per Annex G example */
|
||||
mstp_port.DataRegister = ~HeaderCRC; /* one's compliment of CRC is sent */
|
||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||
ct_test(pTest, mstp_port.Index == 5);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
||||
ct_test(pTest, mstp_port.HeaderCRC == 0x55);
|
||||
/* BadCRC in header check */
|
||||
mstp_port.ReceivedInvalidFrame = false;
|
||||
mstp_port.ReceivedValidFrame = false;
|
||||
len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_TOKEN,
|
||||
0x10, /* destination */
|
||||
my_mac, /* source */
|
||||
NULL, /* data */
|
||||
0); /* data size */
|
||||
ct_test(pTest, len > 0);
|
||||
/* make the header CRC bad */
|
||||
buffer[7] = 0x00;
|
||||
Load_Input_Buffer(buffer, len);
|
||||
for (i = 0; i < len; i++) {
|
||||
RS485_Check_UART_Data(&mstp_port);
|
||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||
}
|
||||
ct_test(pTest, mstp_port.ReceivedInvalidFrame == true);
|
||||
ct_test(pTest, mstp_port.ReceivedValidFrame == false);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
||||
/* NoData for us */
|
||||
mstp_port.ReceivedInvalidFrame = false;
|
||||
mstp_port.ReceivedValidFrame = false;
|
||||
len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_TOKEN,
|
||||
my_mac, /* destination */
|
||||
my_mac, /* source */
|
||||
NULL, /* data */
|
||||
0); /* data size */
|
||||
ct_test(pTest, len > 0);
|
||||
Load_Input_Buffer(buffer, len);
|
||||
for (i = 0; i < len; i++) {
|
||||
RS485_Check_UART_Data(&mstp_port);
|
||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||
}
|
||||
ct_test(pTest, mstp_port.ReceivedInvalidFrame == false);
|
||||
ct_test(pTest, mstp_port.ReceivedValidFrame == true);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
||||
/* FrameTooLong */
|
||||
mstp_port.ReceivedInvalidFrame = false;
|
||||
mstp_port.ReceivedValidFrame = false;
|
||||
len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_TOKEN,
|
||||
my_mac, /* destination */
|
||||
my_mac, /* source */
|
||||
NULL, /* data */
|
||||
0); /* data size */
|
||||
ct_test(pTest, len > 0);
|
||||
/* make the header data length bad */
|
||||
buffer[5] = 0x02;
|
||||
Load_Input_Buffer(buffer, len);
|
||||
for (i = 0; i < len; i++) {
|
||||
RS485_Check_UART_Data(&mstp_port);
|
||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||
}
|
||||
ct_test(pTest, mstp_port.ReceivedInvalidFrame == true);
|
||||
ct_test(pTest, mstp_port.ReceivedValidFrame == false);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
||||
/* Data */
|
||||
mstp_port.ReceivedInvalidFrame = false;
|
||||
mstp_port.ReceivedValidFrame = false;
|
||||
memset(data, 0, sizeof(data));
|
||||
len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_PROPRIETARY_MIN,
|
||||
my_mac, my_mac, data, sizeof(data));
|
||||
ct_test(pTest, len > 0);
|
||||
Load_Input_Buffer(buffer, len);
|
||||
RS485_Check_UART_Data(&mstp_port);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
while (mstp_port.receive_state != MSTP_RECEIVE_STATE_IDLE) {
|
||||
RS485_Check_UART_Data(&mstp_port);
|
||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||
}
|
||||
ct_test(pTest, mstp_port.DataLength == sizeof(data));
|
||||
ct_test(pTest, mstp_port.ReceivedInvalidFrame == false);
|
||||
ct_test(pTest, mstp_port.ReceivedValidFrame == true);
|
||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
||||
return;
|
||||
}
|
||||
|
||||
void testMasterNodeFSM(Test *pTest)
|
||||
{
|
||||
volatile struct mstp_port_struct_t MSTP_Port; /* port data */
|
||||
uint8_t my_mac = 0x05; /* local MAC address */
|
||||
MSTP_Port.InputBuffer = &RxBuffer[0];
|
||||
MSTP_Port.InputBufferSize = sizeof(RxBuffer);
|
||||
MSTP_Port.OutputBuffer = &TxBuffer[0];
|
||||
MSTP_Port.OutputBufferSize = sizeof(TxBuffer);
|
||||
MSTP_Port.This_Station = my_mac;
|
||||
MSTP_Port.Nmax_info_frames = 1;
|
||||
MSTP_Port.Nmax_master = 127;
|
||||
MSTP_Port.SilenceTimer = Timer_Silence;
|
||||
MSTP_Port.SilenceTimerReset = Timer_Silence_Reset;
|
||||
MSTP_Init(&MSTP_Port);
|
||||
ct_test(pTest, MSTP_Port.master_state == MSTP_MASTER_STATE_INITIALIZE);
|
||||
/* FIXME: write a unit test for the Master Node State Machine */
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef TEST_MSTP
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
pTest = ct_create("mstp", NULL);
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, testReceiveNodeFSM);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, testMasterNodeFSM);
|
||||
assert(rc);
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
ct_destroy(pTest);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user