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