CORDET Framework - C2 Implementation
CrFwOutFactoryTestCases.c
Go to the documentation of this file.
1 
19 #include <stdio.h>
20 #include <stdlib.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 "CrFwOutRegistryUserPar.h"
32 #include "BaseCmp/CrFwBaseCmp.h"
33 #include "Pckt/CrFwPckt.h"
35 #include "CrFwTime.h"
36 #include "CrFwRepErr.h"
38 /* Include configuration files */
39 #include "CrFwRepErrStub.h"
40 #include "CrFwOutFactoryUserPar.h"
41 #include "CrFwCmpData.h"
42 
43 /* ---------------------------------------------------------------------------------------------*/
45  FwSmDesc_t outFactory1, outFactory2;
46 
47  /* Instantiate the OutFactory */
48  outFactory1 = CrFwOutFactoryMake();
49  if (outFactory1 == NULL)
50  return 0;
51 
52  /* Instantiate it again and check that same component is returned */
53  outFactory2 = CrFwOutFactoryMake();
54  if (outFactory1 != outFactory2)
55  return 0;
56 
57  /* Check configuration of OutFactory */
58  if (FwSmCheckRec(outFactory1) != smSuccess)
59  return 0;
60 
61  /* Initialize and Configure OutFactory and check success */
62  CrFwCmpInit(outFactory1);
63  CrFwCmpReset(outFactory1);
64  if (!CrFwCmpIsInConfigured(outFactory1))
65  return 0;
66 
67  /* Check max number of OutComponents */
69  return 0;
70 
71  /* Check component type */
72  if (CrFwCmpGetInstanceId(outFactory1) != 0)
73  return 0;
74  if (CrFwCmpGetTypeId(outFactory1) != CR_FW_OUTFACTORY_TYPE)
75  return 0;
76 
77  return 1;
78 }
79 
80 /*--------------------------------------------------------------------------------*/
82  FwSmDesc_t outFactory, outCmp;
84  FwSmDesc_t outCmpArray[CR_FW_OUTFACTORY_MAX_NOF_OUTCMP];
85  CrFwPckt_t pckt[100]; /* it is assumed that CR_FW_MAX_NOF_PCKTS is smaller than 100 */
86 
87  /* Instantiate the OutFactory */
89  if (outFactory == NULL)
90  return 0;
91 
92  /* Initialize and configure the OutFactory */
96  return 0;
97 
98  /* attempt to retrieve an OutComponent with invalid but in-range type */
100  if (outCmp != NULL)
101  return 0;
103  return 0;
105 
106  /* attempt to retrieve an OutComponent with out-of-range type */
107  outCmp = CrFwOutFactoryMakeOutCmp(51,2,1,0);
108  if (outCmp != NULL)
109  return 0;
111  return 0;
113 
114  /* attempt to retrieve an OutComponent with invalid but in-range sub-type */
115  outCmp = CrFwOutFactoryMakeOutCmp(1,3,1,0);
116  if (outCmp != NULL)
117  return 0;
119  return 0;
121 
122  /* attempt to retrieve an OutComponent with out-of-range sub-type */
123  outCmp = CrFwOutFactoryMakeOutCmp(5,5,1,0);
124  if (outCmp != NULL)
125  return 0;
127  return 0;
129 
130  /* attempt to retrieve an OutComponent with invalid but in-range discriminant */
131  outCmp = CrFwOutFactoryMakeOutCmp(5,2,15,0);
132  if (outCmp != NULL)
133  return 0;
135  return 0;
137 
138  /* attempt to retrieve an OutComponent with out-of-range sub-type */
139  outCmp = CrFwOutFactoryMakeOutCmp(5,2,40,0);
140  if (outCmp != NULL)
141  return 0;
143  return 0;
145 
146  /* Create CR_FW_MAX_NOF_PCKTS packets and then attempt to create an OutComponent */
147  for (i=0; i<CR_FW_MAX_NOF_PCKTS; i++) {
148  pckt[i] = CrFwPcktMake(CrFwPcktGetMaxLength());
149  if (i>99)
150  return 0;
151  }
152 
153  outCmp = CrFwOutFactoryMakeOutCmp(1,1,0,0);
154  if (outCmp != NULL)
155  return 0;
157  return 0;
159 
160  /* Release all packets */
161  for (i=0; i<CR_FW_MAX_NOF_PCKTS; i++)
162  CrFwPcktRelease(pckt[i]);
163 
164  /* Create CR_FW_OUTFACTORY_MAX_NOF_OUTCMP OutComponent and then attempt to create one more */
165  for (i=0; i<CR_FW_OUTFACTORY_MAX_NOF_OUTCMP; i++) {
166  outCmpArray[i] = CrFwOutFactoryMakeOutCmp(1,1,0,0);
167  if (outCmpArray[i]==NULL)
168  return 0;
169  }
170 
171  outCmp = CrFwOutFactoryMakeOutCmp(1,1,0,0);
172  if (outCmp != NULL)
173  return 0;
175  return 0;
177 
178  /* Release all OutComponents */
179  for (i=0; i<CR_FW_OUTFACTORY_MAX_NOF_OUTCMP; i++)
180  CrFwOutFactoryReleaseOutCmp(outCmpArray[i]);
181 
182  /* Check that there are no allocated packets */
183  if (CrFwPcktGetNOfAllocated() != 0)
184  return 0;
185 
186  /* Check application errors */
187  if (CrFwGetAppErrCode() != crNoAppErr)
188  return 0;
189 
190  return 1;
191 }
192 
193 /*--------------------------------------------------------------------------------*/
195  FwSmDesc_t outFactory;
196  FwSmDesc_t outCmp1, outCmp2, outCmp3;
197  CrFwInstanceId_t id;
198 
199  /* Instantiate the OutFactory */
201  if (outFactory == NULL)
202  return 0;
203 
204  /* Initialize and Reset the OutFactory */
208  return 0;
209 
210  /* Allocate three OutComponents */
211  outCmp1 = CrFwOutFactoryMakeOutCmp(1,1,0,0);
212  id = CrFwCmpGetInstanceId(outCmp1);
213  outCmp2 = CrFwOutFactoryMakeOutCmp(1,1,0,0);
214  outCmp3 = CrFwOutFactoryMakeOutCmp(5,1,2,0);
216  return 0;
217 
218  /* Check the source attributes of the OutComponents */
219  if (CrFwOutCmpGetSrc(outCmp1) != CR_FW_HOST_APP_ID)
220  return 0;
221  if (CrFwOutCmpGetSrc(outCmp2) != CR_FW_HOST_APP_ID)
222  return 0;
223  if (CrFwOutCmpGetSrc(outCmp3) != CR_FW_HOST_APP_ID)
224  return 0;
225 
226  /* Reset the OutFactory and check that no OutComponents are allocated */
229  return 0;
231  return 0;
232 
233  /* Allocate three OutComponents */
234  outCmp1 = CrFwOutFactoryMakeOutCmp(1,1,0,0);
235  outCmp2 = CrFwOutFactoryMakeOutCmp(1,1,0,0);
236  outCmp3 = CrFwOutFactoryMakeOutCmp(5,1,2,0);
237  if (CrFwCmpGetInstanceId(outCmp1) != id)
238  return 0;
239  if (CrFwCmpGetInstanceId(outCmp2) != id+1)
240  return 0;
241  if (CrFwCmpGetInstanceId(outCmp3) != id+2)
242  return 0;
244  return 0;
245 
246  /* Shutdown the OutFactory and check that no OutComponents are allocated */
248  if (CrFwCmpIsStarted(outFactory) != 0)
249  return 0;
251  return 0;
252 
253  /* Restart OutFactory */
254  FwSmStart(outFactory);
255 
256  /* Check that there are no allocated packets */
257  if (CrFwPcktGetNOfAllocated() != 0)
258  return 0;
259 
260  /* Check application errors */
261  if (CrFwGetAppErrCode() != crNoAppErr)
262  return 0;
263 
264  return 1;
265 }
266 
267 /*--------------------------------------------------------------------------------*/
269  FwSmDesc_t outFactory;
270  FwSmDesc_t outCmp1, outCmp2, outCmp3, outCmp4;
271  CrFwInstanceId_t id, i;
272 
273  /* Instantiate the OutFactory */
275  if (outFactory == NULL)
276  return 0;
277 
278  /* Initialize and Reset the OutFactory */
282  return 0;
283 
284  /* Allocate three OutComponents */
285  outCmp1 = CrFwOutFactoryMakeOutCmp(5,1,2,0);
286  id = CrFwCmpGetInstanceId(outCmp1);
287  outCmp2 = CrFwOutFactoryMakeOutCmp(5,4,0,0);
288  outCmp3 = CrFwOutFactoryMakeOutCmp(1,1,0,70); /* packet length will be 70 */
289  outCmp4 = CrFwOutFactoryMakeOutCmp(1,1,0,0); /* default packet length will be used */
291  return 0;
292 
293  /* Check the length of the OutComponents */
294  if (CrFwOutCmpGetLength(outCmp2)!=50) /* Default length is in CR_FW_OUTCMP_INIT_KIND_DESC */
295  return 0;
296  if (CrFwOutCmpGetLength(outCmp3)!=70) /* Overridden length */
297  return 0;
298  if (CrFwOutCmpGetLength(outCmp4)!=100) /* Default length is in CR_FW_OUTCMP_INIT_KIND_DESC */
299  return 0;
300 
301  /* Release the OutComponents */
304  return 0;
307  return 0;
308 
309  /* Attempt to release an OutComponent twice */
312  return 0;
314  return 0;
316 
317  /* Release the last OutComponents */
321  return 0;
322 
323  /* Reset the OutFactory */
325 
326  /* Allocate the max number of OutComponents with distinct Instance Identifiers */
327  for (i=1; i<=CrFwOutFactoryGetNOfInstanceId(); i++) {
328  outCmp1 = CrFwOutFactoryMakeOutCmp(1,1,0,0);
330  }
331  outCmp1 = CrFwOutFactoryMakeOutCmp(1,1,0,0);
332  if (CrFwCmpGetInstanceId(outCmp1) != id)
333  return 0;
335 
336  /* Check that there are no allocated packets */
337  if (CrFwPcktGetNOfAllocated() != 0)
338  return 0;
339 
340  /* Check application errors */
341  if (CrFwGetAppErrCode() != crNoAppErr)
342  return 0;
343 
344  return 1;
345 }
346 
CrFwInstanceId_t CrFwCmpGetInstanceId(FwSmDesc_t smDesc)
Return the instance identifier of the argument component.
Definition: CrFwBaseCmp.c:150
CrFwBool_t CrFwCmpIsStarted(FwSmDesc_t smDesc)
Return true if the state machine of the argument component has been started.
Definition: CrFwBaseCmp.c:162
void CrFwCmpInit(FwSmDesc_t smDesc)
Initialize a framework component.
Definition: CrFwBaseCmp.c:112
void CrFwCmpShutdown(FwSmDesc_t smDesc)
Shutdown a framework component.
Definition: CrFwBaseCmp.c:122
CrFwBool_t CrFwCmpIsInConfigured(FwSmDesc_t smDesc)
Return true if the argument component is in state CONFIGURED.
Definition: CrFwBaseCmp.c:177
void CrFwCmpReset(FwSmDesc_t smDesc)
Reset a framework component.
Definition: CrFwBaseCmp.c:117
CrFwTypeId_t CrFwCmpGetTypeId(FwSmDesc_t smDesc)
Return the type identifier of the argument component.
Definition: CrFwBaseCmp.c:156
Definition of Base Component.
Definition of the Framework Component Data (FCD) Type.
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
#define CR_FW_OUTFACTORY_TYPE
Type identifier for the OutFactory component.
CrFwDestSrc_t CrFwOutCmpGetSrc(FwSmDesc_t smDesc)
Return the source of the OutComponent.
Definition: CrFwOutCmp.c:237
CrFwPcktLength_t CrFwOutCmpGetLength(FwSmDesc_t smDesc)
Return the length in bytes of the packet to which the OutComponent is serialized.
Definition: CrFwOutCmp.c:395
CrFwInstanceId_t CrFwOutFactoryGetNOfInstanceId()
Return the number of distinct instance identifiers supported by the OutFactory.
CrFwOutFactoryPoolIndex_t CrFwOutFactoryGetNOfAllocatedOutCmp()
Return the number of OutComponents which are currently allocated.
static FwSmDesc_t outFactory
The singleton instance of the OutFactory.
FwSmDesc_t CrFwOutFactoryMakeOutCmp(CrFwServType_t type, CrFwServSubType_t subType, CrFwDiscriminant_t discriminant, CrFwPcktLength_t length)
Make function for an OutComponent.
FwSmDesc_t CrFwOutFactoryMake()
Factory function for the singleton instance of the OutFactory.
static FwSmDesc_t outCmp[CR_FW_OUTFACTORY_MAX_NOF_OUTCMP]
The pre-allocated OutComponent instances.
void CrFwOutFactoryReleaseOutCmp(FwSmDesc_t outCmpInstance)
Release function for an OutComponent.
CrFwOutFactoryPoolIndex_t CrFwOutFactoryGetMaxNOfOutCmp()
Return the maximum number of OutComponents which may be allocated at any one time.
Definition of the OutFactory component.
CrFwBool_t CrFwOutFactoryTestCase3()
Test the Reset and Shutdown functions of the OutFactory component.
CrFwBool_t CrFwOutFactoryTestCase1()
Test the creation and configuration of the OutFactory singleton component.
CrFwBool_t CrFwOutFactoryTestCase4()
Test the OutComponent Creation and Release functions of the OutFactory component.
CrFwBool_t CrFwOutFactoryTestCase2()
Test the OutComponent creation service in non-nominal situations where the creation fails.
Declaration of the test cases for the OutFactory Component (see CrFwOutFactory.h).
User-modifiable parameters for the OutFactory component (see CrFwOutFactory.h).
#define CR_FW_OUTFACTORY_MAX_NOF_OUTCMP
The maximum number of OutComponents which may be allocated at any one time.
Definition of the OutRegistry Component.
User-modifiable parameters for the OutRegistry component (see CrFwOutRegistry.h).
Interface for creating and accessing a report or command packet.
CrFwCounterU2_t CrFwPcktGetNOfAllocated()
Return the number of packets which are currently allocated.
Definition: CrFwPckt.c:214
void CrFwPcktRelease(CrFwPckt_t pckt)
Release function for command or report packets.
Definition: CrFwPckt.c:174
CrFwPcktLength_t CrFwPcktGetMaxLength()
Return the maximum length of a packet in number of bytes.
Definition: CrFwPckt.c:219
CrFwPckt_t CrFwPcktMake(CrFwPcktLength_t pcktLength)
Make function for command or report packets.
Definition: CrFwPckt.c:147
Interface for reporting an error detected by a framework component.
The CORDET Framework defines an interface for generating error reports (see CrFwRepErr....
Interface through which framework components access the current time.
#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.
@ crNoAppErr
No application errors have been detected.
@ crOutCmpRelErr
An OutComponent release request has encountered an error (see CrFwOutFactoryReleaseOutCmp).
@ crIllOutCmpKind
A framework function was called with an illegal type/sub-type/discriminant triplet for an OutComponen...
@ crOutCmpAllocationFail
An OutComponent allocation request has failed (see CrFwOutFactoryMakeOutCmp).
#define CR_FW_HOST_APP_ID
The identifier of the host application (i.e.
unsigned short CrFwInstanceId_t
Type used for instance identifiers.
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.
P&P Software GmbH, Copyright 2012-2013, All Rights Reserved