CORDET Framework - C2 Implementation
CrFwPacketTestCases.c
Go to the documentation of this file.
1 
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include "CrFwPacketTestCases.h"
22 /* Include FW Profile Files */
23 #include "FwSmConstants.h"
24 #include "FwSmConfig.h"
25 #include "FwSmCore.h"
26 #include "FwPrConfig.h"
27 #include "FwPrCore.h"
28 #include "FwPrConstants.h"
29 /* Include Framework Files */
30 #include "Pckt/CrFwPckt.h"
31 #include "Pckt/CrFwPcktQueue.h"
32 #include "CrFwConstants.h"
33 #include "BaseCmp/CrFwBaseCmp.h"
35 
37 {
38  CrFwPckt_t pckt;
39 
40  /* Attempt to create a packet with illegal length */
42  if ((pckt != NULL) || (CrFwGetAppErrCode() != crPcktAllocationFail))
43  return 0;
44  CrFwSetAppErrCode(crNoAppErr); /* reset application error code */
45 
46  pckt = CrFwPcktMake(0);
47  if ((pckt != NULL) || (CrFwGetAppErrCode() != crPcktAllocationFail))
48  return 0;
49  CrFwSetAppErrCode(crNoAppErr); /* reset application error code */
50 
51  /* Make a new packet */
53  if (pckt == NULL)
54  return 0;
55 
56  /* Check packet length */
58  {
59  CrFwPcktRelease(pckt);
60  return 0;
61  }
62 
63  /* Check setting and getting packet attributes */
64  CrFwPcktSetSeqCnt(pckt, 1);
65  if (CrFwPcktGetSeqCnt(pckt) != 1)
66  {
67  CrFwPcktRelease(pckt);
68  return 0;
69  }
70 
71  CrFwPcktSetTimeStamp(pckt, 0xAABBCCDD);
72  if (CrFwPcktGetTimeStamp(pckt) != 0xAABBCCDD)
73  {
74  CrFwPcktRelease(pckt);
75  return 0;
76  }
77 
78  CrFwPcktSetDiscriminant(pckt, 257);
79  if (CrFwPcktGetDiscriminant(pckt) != 257)
80  {
81  CrFwPcktRelease(pckt);
82  return 0;
83  }
84 
85  CrFwPcktSetGroup(pckt, 28);
86  if (CrFwPcktGetGroup(pckt) != 28)
87  {
88  CrFwPcktRelease(pckt);
89  return 0;
90  }
91 
92  CrFwPcktSetTypeCnt(pckt, 29);
93  if (CrFwPcktGetTypeCnt(pckt) != 29)
94  {
95  CrFwPcktRelease(pckt);
96  return 0;
97  }
98 
100  if (CrFwPcktGetCmdRepType(pckt) != crCmdType)
101  {
102  CrFwPcktRelease(pckt);
103  return 0;
104  }
105 
107  if (CrFwPcktGetCmdRepType(pckt) != crRepType)
108  {
109  CrFwPcktRelease(pckt);
110  return 0;
111  }
112 
113  CrFwPcktSetServType(pckt, 10);
114  if (CrFwPcktGetServType(pckt) != 10)
115  {
116  CrFwPcktRelease(pckt);
117  return 0;
118  }
119 
120  CrFwPcktSetServSubType(pckt, 11);
121  if (CrFwPcktGetServSubType(pckt) != 11)
122  {
123  CrFwPcktRelease(pckt);
124  return 0;
125  }
126 
127  CrFwPcktSetDest(pckt, 34);
128  if (CrFwPcktGetDest(pckt) != 34)
129  {
130  CrFwPcktRelease(pckt);
131  return 0;
132  }
133 
134  CrFwPcktSetSrc(pckt, 35);
135  if (CrFwPcktGetSrc(pckt) != 35)
136  {
137  CrFwPcktRelease(pckt);
138  return 0;
139  }
140 
141  CrFwPcktSetCmdRepId(pckt, 256);
142  if (CrFwPcktGetCmdRepId(pckt) != 256)
143  {
144  CrFwPcktRelease(pckt);
145  return 0;
146  }
147 
148  CrFwPcktSetAckLevel(pckt, 1, 0, 1, 0);
149  if (CrFwPcktIsAcceptAck(pckt) != 1)
150  {
151  CrFwPcktRelease(pckt);
152  return 0;
153  }
154  if (CrFwPcktIsStartAck(pckt) != 0)
155  {
156  CrFwPcktRelease(pckt);
157  return 0;
158  }
159  if (CrFwPcktIsProgressAck(pckt) != 1)
160  {
161  CrFwPcktRelease(pckt);
162  return 0;
163  }
164  if (CrFwPcktIsTermAck(pckt) != 0)
165  {
166  CrFwPcktRelease(pckt);
167  return 0;
168  }
169 
170  CrFwPcktSetAckLevel(pckt, 0, 1, 1, 0);
171  if (CrFwPcktIsAcceptAck(pckt) != 0)
172  {
173  CrFwPcktRelease(pckt);
174  return 0;
175  }
176  if (CrFwPcktIsStartAck(pckt) != 1)
177  {
178  CrFwPcktRelease(pckt);
179  return 0;
180  }
181  if (CrFwPcktIsProgressAck(pckt) != 1)
182  {
183  CrFwPcktRelease(pckt);
184  return 0;
185  }
186  if (CrFwPcktIsTermAck(pckt) != 0)
187  {
188  CrFwPcktRelease(pckt);
189  return 0;
190  }
191 
192  /* Release the packet */
193  CrFwPcktRelease(pckt);
194 
195  /* Check that there are no allocated packets */
196  if (CrFwPcktGetNOfAllocated() != 0)
197  return 0;
198 
199  /* Check application error code */
200  if (CrFwGetAppErrCode() != crNoAppErr)
201  return 0;
202 
203  return 1;
204 }
205 
206 /*--------------------------------------------------------------------------------*/
208 {
209  CrFwPckt_t *pckt;
210  CrFwPckt_t extraPckt;
211  CrFwCounterU2_t i;
212 
213  /* Create array to hold all created packets */
214  pckt = malloc(CR_FW_MAX_NOF_PCKTS * sizeof(CrFwPckt_t *));
215 
216  /* Create max number of packets */
217  for (i = 0; i < CR_FW_MAX_NOF_PCKTS; i++)
218  {
220  if (pckt[i] == NULL)
221  return 0;
222  }
223  if (CrFwGetAppErrCode() != crNoAppErr)
224  return 0;
225 
226  /* Verify that packet availability check returns 'no packet available' */
227  if (CrFwPcktIsAvail(1) != 0)
228  return 0;
229 
230  /* Attempt to create a new packet */
231  extraPckt = CrFwPcktMake(CrFwPcktGetMaxLength());
232  if ((extraPckt != NULL) || (CrFwGetAppErrCode() != crPcktAllocationFail))
233  return 0;
234  CrFwSetAppErrCode(crNoAppErr); /* reset application error code */
235 
236  /* Release one packet and then attempt creation again */
237  if (CR_FW_MAX_NOF_PCKTS > 1)
238  {
240  if (CrFwPcktIsAvail(1) != 1)
241  return 0; /* Verify that packet availability check returns 'packet is available' */
242  pckt[CR_FW_MAX_NOF_PCKTS - 1] = NULL;
243  extraPckt = CrFwPcktMake(CrFwPcktGetMaxLength());
244  if (extraPckt == NULL)
245  return 0;
246  }
247 
248  /* Release and re-allocate all packets in the packet array
249  * (NB one packet is allocated to extraPckt */
250  for (i = 0; i < CR_FW_MAX_NOF_PCKTS; i++)
251  {
252  if (pckt[i] != NULL)
253  CrFwPcktRelease(pckt[i]);
254  }
255  for (i = 0; i < CR_FW_MAX_NOF_PCKTS - 1; i++)
256  {
258  if (pckt[i] == NULL)
259  return 0;
260  }
261 
262  /* Release all packets */
263  for (i = 0; i < CR_FW_MAX_NOF_PCKTS; i++)
264  {
265  if (pckt[i] != NULL)
266  CrFwPcktRelease(pckt[i]);
267  }
268  CrFwPcktRelease(extraPckt);
269  if (CrFwPcktGetNOfAllocated() != 0)
270  return 0;
271 
272  /* Attempt releasing a packet a second time */
273  CrFwPcktRelease(pckt[0]);
275  return 0;
276  CrFwSetAppErrCode(crNoAppErr); /* reset application error code */
277 
278  /* Verify the packet availability check with illegal packet lengths */
279  if (CrFwPcktIsAvail(0) != 0)
280  return 0;
281  if (CrFwPcktIsAvail(CrFwPcktGetMaxLength() + 1) != 0)
282  return 0;
283 
284  /* Free the memory allocated to the packet array */
285  free(pckt);
286 
287  return 1;
288 }
289 
290 /*--------------------------------------------------------------------------------*/
292 {
293  CrFwPckt_t pckt, pckt1, pckt2;
294  CrFwCounterU1_t i;
295  struct CrFwPcktQueue pcktQueue;
296 
297  /* Initialize the packet queue */
298  pcktQueue.pckt = NULL;
299 
300  /* Create the packet queue */
301  CrFwPcktQueueInit(&pcktQueue, 10);
302 
303  /* Create it again (just to ensure full coverage of packet queue module */
304  CrFwPcktQueueInit(&pcktQueue, 10);
305 
306  /* Attempt to pop an item from the packet queue */
307  pckt = CrFwPcktQueuePop(&pcktQueue);
308  if (pckt != NULL)
309  return 0;
310  if (CrFwPcktQueueGetNOfPckts(&pcktQueue) != 0)
311  return 0;
312  if (CrFwPcktQueueIsEmpty(&pcktQueue) != 1)
313  return 0;
314 
315  /* Attempt to retrieve the oldest item from the packet queue */
316  pckt = CrFwPcktQueueGetOldest(&pcktQueue);
317  if (pckt != NULL)
318  return 0;
319  if (CrFwPcktQueueGetNOfPckts(&pcktQueue) != 0)
320  return 0;
321  if (CrFwPcktQueueIsEmpty(&pcktQueue) != 1)
322  return 0;
323 
324  /* Reset the empty packet queue */
325  CrFwPcktQueueReset(&pcktQueue);
326  if (CrFwPcktQueueIsEmpty(&pcktQueue) != 1)
327  return 0;
328  if (CrFwPcktQueueGetNOfPckts(&pcktQueue) != 0)
329  return 0;
330 
331  /* Push and pop two packets and verify FIFO order */
332  pckt1 = CrFwPcktMake(4);
333  pckt2 = CrFwPcktMake(4);
334  CrFwPcktQueuePush(&pcktQueue, pckt1);
335  CrFwPcktQueuePush(&pcktQueue, pckt2);
336  if (CrFwPcktQueueGetOldest(&pcktQueue) != pckt1)
337  return 0;
338  if (CrFwPcktQueueGetNOfPckts(&pcktQueue) != 2)
339  return 0;
340  if (CrFwPcktQueuePop(&pcktQueue) != pckt1)
341  return 0;
342  if (CrFwPcktQueuePop(&pcktQueue) != pckt2)
343  return 0;
344  if (CrFwPcktQueueIsEmpty(&pcktQueue) != 1)
345  return 0;
346  if (CrFwPcktQueueGetNOfPckts(&pcktQueue) != 0)
347  return 0;
348  CrFwPcktRelease(pckt1);
349  CrFwPcktRelease(pckt2);
350 
351  /* Create a situation where oldest packet is behind next free slot in queue */
352  CrFwPcktQueueReset(&pcktQueue);
353  if (CrFwPcktQueueIsEmpty(&pcktQueue) != 1)
354  return 0;
355  if (CrFwPcktQueueGetNOfPckts(&pcktQueue) != 0)
356  return 0;
357  for (i = 0; i < CrFwPcktQueueGetSize(&pcktQueue); i++)
358  {
359  pckt = CrFwPcktMake(2);
360  CrFwPcktQueuePush(&pcktQueue, pckt);
361  } /* Packet queue is now full */
362  pckt = CrFwPcktQueuePop(&pcktQueue);
364  pckt = CrFwPcktQueuePop(&pcktQueue);
366  pckt = CrFwPcktQueuePop(&pcktQueue);
367  CrFwPcktRelease(pckt); /* The first three slots in the packet queue are now free */
368  pckt = CrFwPcktMake(2);
369  CrFwPcktQueuePush(&pcktQueue, pckt);
370  pckt = CrFwPcktMake(2);
371  CrFwPcktQueuePush(&pcktQueue, pckt); /* Only the third slot in the packet queue is free */
372  CrFwPcktQueueReset(&pcktQueue);
373 
374  /* Check that there are no allocated packets */
375  if (CrFwPcktGetNOfAllocated() != 0)
376  return 0;
377 
378  /* Release memory allocated to the packet queue */
379  free(pcktQueue.pckt);
380 
381  return 1;
382 }
Definition of Base Component.
Header file to define all invariant publicly available constants and types for the CORDET Framework.
@ crRepType
Report type.
Definition: CrFwConstants.h:45
@ crCmdType
Command type.
Definition: CrFwConstants.h:43
unsigned char * CrFwPckt_t
Type for packets (see CrFwPckt.h).
Definition: CrFwConstants.h:38
int CrFwBool_t
Type used for boolean values (1 represent "true" and 0 represents "false").
Definition: CrFwConstants.h:32
CrFwBool_t CrFwPacketTestCase2()
Test the creation and release functions for a packet.
CrFwBool_t CrFwPacketTestCase1()
Test the creation of a packet and the read and write operations on its attributes.
CrFwBool_t CrFwPacketQueueTestCase1()
Test the packet queue functions which are not covered through other tests.
Declaration of the test cases for the default packet implementation of CrFwBaseCmp....
Interface for creating and accessing a report or command packet.
CrFwBool_t CrFwPcktIsAvail(CrFwPcktLength_t pcktLength)
Check whether a packet of a specified length is available.
Definition: CrFwPckt.c:194
void CrFwPcktSetServSubType(CrFwPckt_t pckt, CrFwServSubType_t servSubType)
Set the service sub-type of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:327
void CrFwPcktSetCmdRepId(CrFwPckt_t pckt, CrFwInstanceId_t id)
Set the command or report identifier in the command or report encapsulated in a packet.
Definition: CrFwPckt.c:363
CrFwTypeCnt_t CrFwPcktGetTypeCnt(CrFwPckt_t pckt)
Return the type counter of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:253
void CrFwPcktSetSeqCnt(CrFwPckt_t pckt, CrFwSeqCnt_t seqCnt)
Set the sequence counter of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:247
CrFwSeqCnt_t CrFwPcktGetSeqCnt(CrFwPckt_t pckt)
Return the sequence counter of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:241
void CrFwPcktSetCmdRepType(CrFwPckt_t pckt, CrFwCmdRepType_t type)
Set the type of a packet (either a command packet or a report packet).
Definition: CrFwPckt.c:235
CrFwBool_t CrFwPcktIsProgressAck(CrFwPckt_t pckt)
Return the acknowledge level for command progress for the command encapsulated in the packet.
Definition: CrFwPckt.c:400
CrFwBool_t CrFwPcktIsTermAck(CrFwPckt_t pckt)
Return the acknowledge level for command termination for the command encapsulated in the packet.
Definition: CrFwPckt.c:406
CrFwCmdRepType_t CrFwPcktGetCmdRepType(CrFwPckt_t pckt)
Return the type of a packet (either a command packet or a report packet).
Definition: CrFwPckt.c:229
void CrFwPcktSetDiscriminant(CrFwPckt_t pckt, CrFwDiscriminant_t discriminant)
Set the discriminant of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:309
void CrFwPcktSetTimeStamp(CrFwPckt_t pckt, CrFwTimeStamp_t timeStamp)
Set the time stamp of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:271
void CrFwPcktSetServType(CrFwPckt_t pckt, CrFwServType_t servType)
Set the service type of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:315
CrFwCounterU2_t CrFwPcktGetNOfAllocated()
Return the number of packets which are currently allocated.
Definition: CrFwPckt.c:214
CrFwDestSrc_t CrFwPcktGetSrc(CrFwPckt_t pckt)
Return the source of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:357
CrFwServSubType_t CrFwPcktGetServSubType(CrFwPckt_t pckt)
Return the service sub-type of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:333
CrFwDestSrc_t CrFwPcktGetDest(CrFwPckt_t pckt)
Return the destination of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:345
CrFwInstanceId_t CrFwPcktGetCmdRepId(CrFwPckt_t pckt)
Return the command or report identifier of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:369
CrFwBool_t CrFwPcktIsAcceptAck(CrFwPckt_t pckt)
Return the acknowledge level for command acceptance for the command encapsulated in the packet.
Definition: CrFwPckt.c:388
CrFwTimeStamp_t CrFwPcktGetTimeStamp(CrFwPckt_t pckt)
Return the time stamp of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:265
void CrFwPcktSetAckLevel(CrFwPckt_t pckt, CrFwBool_t accept, CrFwBool_t start, CrFwBool_t progress, CrFwBool_t term)
Set the acknowledge level for the command encapsulated in a packet.
Definition: CrFwPckt.c:375
void CrFwPcktRelease(CrFwPckt_t pckt)
Release function for command or report packets.
Definition: CrFwPckt.c:174
CrFwGroup_t CrFwPcktGetGroup(CrFwPckt_t pckt)
Return the group of the command/report encapsulated in a packet.
Definition: CrFwPckt.c:428
CrFwPcktLength_t CrFwPcktGetMaxLength()
Return the maximum length of a packet in number of bytes.
Definition: CrFwPckt.c:219
CrFwPcktLength_t CrFwPcktGetLength(CrFwPckt_t pckt)
Return the length (in number of bytes) of a packet.
Definition: CrFwPckt.c:224
CrFwBool_t CrFwPcktIsStartAck(CrFwPckt_t pckt)
Return the acknowledge level for command start for the command encapsulated in the packet.
Definition: CrFwPckt.c:394
void CrFwPcktSetSrc(CrFwPckt_t pckt, CrFwDestSrc_t src)
Set the source of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:351
void CrFwPcktSetDest(CrFwPckt_t pckt, CrFwDestSrc_t dest)
Set the destination of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:339
void CrFwPcktSetGroup(CrFwPckt_t pckt, CrFwGroup_t group)
Set the group of the command/report encapsulated in a packet.
Definition: CrFwPckt.c:422
CrFwDiscriminant_t CrFwPcktGetDiscriminant(CrFwPckt_t pckt)
Return the discriminant of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:303
CrFwServType_t CrFwPcktGetServType(CrFwPckt_t pckt)
Return the service type of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:321
void CrFwPcktSetTypeCnt(CrFwPckt_t pckt, CrFwTypeCnt_t typeCnt)
Set the type counter of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:259
CrFwPckt_t CrFwPcktMake(CrFwPcktLength_t pcktLength)
Make function for command or report packets.
Definition: CrFwPckt.c:147
CrFwPckt_t CrFwPcktQueueGetOldest(CrFwPcktQueue_t pcktQueue)
Return the oldest packet from the queue without removing it from the queue.
Definition: CrFwPcktQueue.c:44
CrFwBool_t CrFwPcktQueueIsEmpty(CrFwPcktQueue_t pcktQueue)
Return 1 if the packet queue is empty and 0 otherwise.
CrFwCounterU1_t CrFwPcktQueueGetSize(CrFwPcktQueue_t pcktQueue)
Return the size of the packet queue.
CrFwPckt_t CrFwPcktQueuePop(CrFwPcktQueue_t pcktQueue)
Pop a packet from the packet queue.
Definition: CrFwPcktQueue.c:25
void CrFwPcktQueueReset(CrFwPcktQueue_t pcktQueue)
Reset the packet queue.
Definition: CrFwPcktQueue.c:73
void CrFwPcktQueueInit(CrFwPcktQueue_t pcktQueue, CrFwCounterU1_t size)
Initializes the packet queue.
Definition: CrFwPcktQueue.c:95
CrFwBool_t CrFwPcktQueuePush(CrFwPcktQueue_t pcktQueue, CrFwPckt_t pckt)
Push a packet onto the packet queue.
Definition: CrFwPcktQueue.c:52
CrFwCounterU1_t CrFwPcktQueueGetNOfPckts(CrFwPcktQueue_t pcktQueue)
Return the number of packets currently in the packet queue.
Definition and management of packet queues.
#define CR_FW_MAX_NOF_PCKTS
The maximum number of packets which can be created with the default implementation of the packet acce...
unsigned short CrFwCounterU2_t
Type used for unsigned integers with a "medium" range.
unsigned char CrFwCounterU1_t
Type used for unsigned integers with a "short" range.
unsigned short int CrFwPcktLength_t
Type for the packet length.
@ crNoAppErr
No application errors have been detected.
@ crPcktAllocationFail
A packet allocation request has failed (see CrFwPcktMake).
@ crPcktRelErr
A packet release request has encountered an error (see CrFwPcktRelease).
CrFwAppErrCode_t CrFwGetAppErrCode()
Return the value of the application error code.
void CrFwSetAppErrCode(CrFwAppErrCode_t errCode)
Set the value of the application error code (see CrFwGetAppErrCode).
Definition of the utility functions for the CORDET Framework.
Descriptor for a Packet Queue (PQ) in an OutStream or InStream.
CrFwPckt_t * pckt
The list of packets in the PQ.
P&P Software GmbH, Copyright 2012-2013, All Rights Reserved