FW Profile - C1 Implementation
FwRtTestCases.c
Go to the documentation of this file.
1 
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <time.h>
22 #include <pthread.h>
23 #include <unistd.h>
24 #include "FwRtConstants.h"
25 #include "FwRtCore.h"
26 #include "FwRtTestCases.h"
27 #include "FwRtMakeTest.h"
28 
30 static struct timespec oneMs = {0,1000000};
31 
33 static struct timespec tenMs = {0,10000000};
34 
36 static struct timespec nineMs = {0,9000000};
37 
39 static struct timespec hundredMs = {0,100000000};
40 
42 #define N_NOTIFY2 10000
43 
44 /*--------------------------------------------------------------------------*/
51 static void* TestCaseStressRun_Notify1(void* rtDesc);
52 
53 /*--------------------------------------------------------------------------*/
60 static void* TestCaseStressRun_Notify2(void* rtDesc);
61 
68 
75 
82 
89 
96 
103 
110 
117 
118 /*------------------------------------------------------------------------------------------------- */
120  struct FwRtDesc rtDesc;
121  pthread_attr_t tattr;
122  pthread_mutexattr_t mattr;
123  pthread_condattr_t cattr;
124 
125  /* Reset the container descriptor */
126  FwRtReset(&rtDesc);
127 
128  /* Set POSIX attributes and check */
129  FwRtSetPosixAttr(&rtDesc, &tattr, &mattr, &cattr);
130  if ((rtDesc.pThreadAttr != &tattr) || (FwRtGetActivThreadAttr(&rtDesc) != &tattr))
131  return rtTestCaseFailure;
132 
133  if ((rtDesc.pMutexAttr != &mattr) || (FwRtGetMutexAttr(&rtDesc) != &mattr))
134  return rtTestCaseFailure;
135 
136  if ((rtDesc.pCondAttr != &cattr) || (FwRtGetCondAttr(&rtDesc) != &cattr))
137  return rtTestCaseFailure;
138 
139  /* Check error code */
140  if (FwRtGetErrCode(&rtDesc) != 0)
141  return rtTestCaseFailure;
142 
143  /* Initialize the container */
144  FwRtInit(&rtDesc);
145  if (FwRtGetContState(&rtDesc) != rtContStopped)
146  return rtTestCaseFailure;
147 
148  /* Attempt to set POSIX attributes and check error */
149  FwRtSetPosixAttr(&rtDesc, &tattr, &mattr, &cattr);
150  if (FwRtGetContState(&rtDesc) != rtConfigErr)
151  return rtTestCaseFailure;
152 
153  /* Shutdown container and verify that the error condition has been lifted */
154  FwRtShutdown(&rtDesc);
155  if (FwRtGetContState(&rtDesc) != rtContUninitialized)
156  return rtTestCaseFailure;
157 
158  /* Reset container and verify that attribute settings have been lost */
159  FwRtReset(&rtDesc);
160 
161  if ((rtDesc.pThreadAttr != NULL) || (FwRtGetActivThreadAttr(&rtDesc) != NULL))
162  return rtTestCaseFailure;
163 
164  if ((rtDesc.pMutexAttr != NULL) || (FwRtGetMutexAttr(&rtDesc) != NULL))
165  return rtTestCaseFailure;
166 
167  if ((rtDesc.pCondAttr != NULL) || (FwRtGetCondAttr(&rtDesc) != NULL))
168  return rtTestCaseFailure;
169 
170  return rtTestCaseSuccess;
171 }
172 
173 /*------------------------------------------------------------------------------------------------- */
175  struct FwRtDesc rtDesc;
176  FwRtAction_t dummyAction;
177 
178  /* Reset the container descriptor */
179  FwRtReset(&rtDesc);
180 
181  /* Set procedure actions and check success */
183  if (rtDesc.initializeNotifPr != &InitializeNotifPr)
184  return rtTestCaseFailure;
185 
187  if (rtDesc.finalizeNotifPr != &FinalizeNotifPr)
188  return rtTestCaseFailure;
189 
192  return rtTestCaseFailure;
193 
195  if (rtDesc.initializeActivPr != &InitializeActivPr)
196  return rtTestCaseFailure;
197 
199  if (rtDesc.finalizeActivPr != &FinalizeActivPr)
200  return rtTestCaseFailure;
201 
203  if (rtDesc.setUpNotification != &SetUpNotification)
204  return rtTestCaseFailure;
205 
208  return rtTestCaseFailure;
209 
211  if (rtDesc.execFuncBehaviour != &ExecFuncBehaviour)
212  return rtTestCaseFailure;
213 
214  /* Check error code */
215  if (FwRtGetErrCode(&rtDesc) != 0)
216  return rtTestCaseFailure;
217 
218  /* Initialize the container */
219  FwRtInit(&rtDesc);
220  if (FwRtGetContState(&rtDesc) != rtContStopped)
221  return rtTestCaseFailure;
222 
223  /* Attempt to set procedure actions and check error */
225  if (FwRtGetContState(&rtDesc) != rtConfigErr)
226  return rtTestCaseFailure;
227 
229  if (FwRtGetContState(&rtDesc) != rtConfigErr)
230  return rtTestCaseFailure;
231 
233  if (FwRtGetContState(&rtDesc) != rtConfigErr)
234  return rtTestCaseFailure;
235 
237  if (FwRtGetContState(&rtDesc) != rtConfigErr)
238  return rtTestCaseFailure;
239 
241  if (FwRtGetContState(&rtDesc) != rtConfigErr)
242  return rtTestCaseFailure;
243 
245  if (FwRtGetContState(&rtDesc) != rtConfigErr)
246  return rtTestCaseFailure;
247 
249  if (FwRtGetContState(&rtDesc) != rtConfigErr)
250  return rtTestCaseFailure;
251 
253  if (FwRtGetContState(&rtDesc) != rtConfigErr)
254  return rtTestCaseFailure;
255 
256  /* Shutdown container and verify that the error condition has been lifted */
257  FwRtShutdown(&rtDesc);
258  if (FwRtGetContState(&rtDesc) != rtContUninitialized)
259  return rtTestCaseFailure;
260 
261  /* Reset container and verify that action settings have been lost */
262  FwRtReset(&rtDesc);
263 
264  dummyAction = rtDesc.initializeNotifPr;
265 
266  if (dummyAction == &InitializeNotifPr)
267  return rtTestCaseFailure;
268 
269  if (rtDesc.finalizeNotifPr != dummyAction)
270  return rtTestCaseFailure;
271 
272  if (rtDesc.implementNotifLogic != dummyAction)
273  return rtTestCaseFailure;
274 
275  if (rtDesc.initializeActivPr != dummyAction)
276  return rtTestCaseFailure;
277 
278  if (rtDesc.finalizeActivPr != dummyAction)
279  return rtTestCaseFailure;
280 
281  if (rtDesc.setUpNotification != dummyAction)
282  return rtTestCaseFailure;
283 
284  if (rtDesc.implementActivLogic != dummyAction)
285  return rtTestCaseFailure;
286 
287  if (rtDesc.execFuncBehaviour != dummyAction)
288  return rtTestCaseFailure;
289 
290  /* Initialize container twice and verify that second initialization fails */
291  FwRtInit(&rtDesc);
292  if (FwRtGetContState(&rtDesc) != rtContStopped)
293  return rtTestCaseFailure;
294 
295  FwRtInit(&rtDesc);
296  if (FwRtGetContState(&rtDesc) != rtConfigErr)
297  return rtTestCaseFailure;
298 
299  /* Shut down container */
300  FwRtShutdown(&rtDesc);
301  if (FwRtGetContState(&rtDesc) != rtContUninitialized)
302  return rtTestCaseFailure;
303 
304  return rtTestCaseSuccess;
305 }
306 
307 /*------------------------------------------------------------------------------------------------- */
309  FwRtDesc_t rtDesc;
310 
311  /* Create the RTD */
312  rtDesc = (FwRtDesc_t)malloc(sizeof(struct FwRtDesc));
313 
314  /* Reset and initialize RT Container */
315  FwRtReset(rtDesc);
316  FwRtInit(rtDesc);
317 
318  /* Check default state of RT Container and its procedures */
319  if (FwRtGetContState(rtDesc) != rtContStopped)
320  return rtTestCaseFailure;
321  if (FwRtIsActivPrStarted(rtDesc))
322  return rtTestCaseFailure;
323  if (FwRtIsNotifPrStarted(rtDesc))
324  return rtTestCaseFailure;
325  if (FwRtGetNotifCounter(rtDesc) != 0)
326  return rtTestCaseFailure;
327 
328  /* Start RT Container */
329  FwRtStart(rtDesc);
330 
331  /* Start RT Container a second time (this should have no effect) */
332  FwRtStart(rtDesc);
333 
334  /* Check state of RT Container and its procedures */
335  if (FwRtGetContState(rtDesc) != rtContStarted)
336  return rtTestCaseFailure;
337  if (!FwRtIsActivPrStarted(rtDesc))
338  return rtTestCaseFailure;
339  if (!FwRtIsNotifPrStarted(rtDesc))
340  return rtTestCaseFailure;
341  if (FwRtGetNotifCounter(rtDesc) != 0)
342  return rtTestCaseFailure;
343 
344  /* Notify RT Container and wait until Activation Thread has exited */
345  FwRtNotify(rtDesc);
346  FwRtWaitForTermination(rtDesc);
347 
348  /* Check default state of RT Container and its procedures */
349  if (FwRtGetContState(rtDesc) != rtContStopped)
350  return rtTestCaseFailure;
351  if (FwRtIsActivPrStarted(rtDesc))
352  return rtTestCaseFailure;
353  if (FwRtIsNotifPrStarted(rtDesc))
354  return rtTestCaseFailure;
355  if (FwRtGetNotifCounter(rtDesc) != 0)
356  return rtTestCaseFailure;
357 
358  /* Stop RT Container (this should have no effect) */
359  FwRtStop(rtDesc);
360 
361  /* Check default state of RT Container and its procedures */
362  if (FwRtGetContState(rtDesc) != rtContStopped)
363  return rtTestCaseFailure;
364  if (FwRtIsActivPrStarted(rtDesc))
365  return rtTestCaseFailure;
366  if (FwRtIsNotifPrStarted(rtDesc))
367  return rtTestCaseFailure;
368  if (FwRtGetNotifCounter(rtDesc) != 0)
369  return rtTestCaseFailure;
370 
371  /* Restart the RT Container */
372  FwRtStart(rtDesc);
373 
374  /* Check state of RT Container and its procedures */
375  if (FwRtGetContState(rtDesc) != rtContStarted)
376  return rtTestCaseFailure;
377  if (!FwRtIsActivPrStarted(rtDesc))
378  return rtTestCaseFailure;
379  if (!FwRtIsNotifPrStarted(rtDesc))
380  return rtTestCaseFailure;
381  if (FwRtGetNotifCounter(rtDesc) != 0)
382  return rtTestCaseFailure;
383 
384  /* Stop RT Container and wait until its activation thread has terminated */
385  FwRtStop(rtDesc);
386  FwRtWaitForTermination(rtDesc);
387 
388  /* Check default state of RT Container and its procedures */
389  if (FwRtGetContState(rtDesc) != rtContStopped)
390  return rtTestCaseFailure;
391  if (FwRtIsActivPrStarted(rtDesc))
392  return rtTestCaseFailure;
393  if (FwRtIsNotifPrStarted(rtDesc))
394  return rtTestCaseFailure;
395  if (FwRtGetNotifCounter(rtDesc) != 0)
396  return rtTestCaseFailure;
397 
398  /* Check error code */
399  if (FwRtGetErrCode(rtDesc) != 0)
400  return rtTestCaseFailure;
401 
402  /* Shutdown the RT Container */
403  FwRtShutdown(rtDesc);
404 
405  /* Release the RTD */
406  free(rtDesc);
407 
408  return rtTestCaseSuccess;
409 }
410 
411 /*------------------------------------------------------------------------------------------------- */
413  struct FwRtDesc rtDesc;
414  pthread_attr_t pThreadAttr;
415  pthread_mutexattr_t pMutexAttr;
416  pthread_condattr_t pCondAttr;
417 
418  /* Reset the container descriptor */
419  FwRtReset(&rtDesc);
420 
421  /* Load the attributes in the container */
422  FwRtSetPosixAttr(&rtDesc, &pThreadAttr, &pMutexAttr, &pCondAttr);
423 
424  /* Initialize RT Container */
425  FwRtInit(&rtDesc);
426 
427  /* Check default state of RT Container and its procedures */
428  if (FwRtGetContState(&rtDesc) != rtContStopped)
429  return rtTestCaseFailure;
430  if (FwRtIsActivPrStarted(&rtDesc))
431  return rtTestCaseFailure;
432  if (FwRtIsNotifPrStarted(&rtDesc))
433  return rtTestCaseFailure;
434  if (FwRtGetNotifCounter(&rtDesc) != 0)
435  return rtTestCaseFailure;
436 
437  /* Start RT Container */
438  FwRtStart(&rtDesc);
439 
440  /* Start RT Container a second time (this should have no effect) */
441  FwRtStart(&rtDesc);
442 
443  /* Check state of RT Container and its procedures */
444  if (FwRtGetContState(&rtDesc) != rtContStarted)
445  return rtTestCaseFailure;
446  if (!FwRtIsActivPrStarted(&rtDesc))
447  return rtTestCaseFailure;
448  if (!FwRtIsNotifPrStarted(&rtDesc))
449  return rtTestCaseFailure;
450  if (FwRtGetNotifCounter(&rtDesc) != 0)
451  return rtTestCaseFailure;
452 
453  /* Notify RT Container and wait until Activation Thread has exited */
454  FwRtNotify(&rtDesc);
455  FwRtWaitForTermination(&rtDesc);
456 
457  /* Check default state of RT Container and its procedures */
458  if (FwRtGetContState(&rtDesc) != rtContStopped)
459  return rtTestCaseFailure;
460  if (FwRtIsActivPrStarted(&rtDesc))
461  return rtTestCaseFailure;
462  if (FwRtIsNotifPrStarted(&rtDesc))
463  return rtTestCaseFailure;
464  if (FwRtGetNotifCounter(&rtDesc) != 0)
465  return rtTestCaseFailure;
466 
467  /* Stop RT Container (this should have no effect) */
468  FwRtStop(&rtDesc);
469 
470  /* Check default state of RT Container and its procedures */
471  if (FwRtGetContState(&rtDesc) != rtContStopped)
472  return rtTestCaseFailure;
473  if (FwRtIsActivPrStarted(&rtDesc))
474  return rtTestCaseFailure;
475  if (FwRtIsNotifPrStarted(&rtDesc))
476  return rtTestCaseFailure;
477  if (FwRtGetNotifCounter(&rtDesc) != 0)
478  return rtTestCaseFailure;
479 
480  /* Restart the RT Container (this should have no effect) */
481  FwRtStart(&rtDesc);
482 
483  /* Check state of RT Container and its procedures */
484  if (FwRtGetContState(&rtDesc) != rtContStarted)
485  return rtTestCaseFailure;
486  if (!FwRtIsActivPrStarted(&rtDesc))
487  return rtTestCaseFailure;
488  if (!FwRtIsNotifPrStarted(&rtDesc))
489  return rtTestCaseFailure;
490  if (FwRtGetNotifCounter(&rtDesc) != 0)
491  return rtTestCaseFailure;
492 
493  /* Stop RT Container and wait until its activation thread has terminated */
494  FwRtStop(&rtDesc);
495  FwRtWaitForTermination(&rtDesc);
496 
497  /* Check default state of RT Container and its procedures */
498  if (FwRtGetContState(&rtDesc) != rtContStopped)
499  return rtTestCaseFailure;
500  if (FwRtIsActivPrStarted(&rtDesc))
501  return rtTestCaseFailure;
502  if (FwRtIsNotifPrStarted(&rtDesc))
503  return rtTestCaseFailure;
504  if (FwRtGetNotifCounter(&rtDesc) != 0)
505  return rtTestCaseFailure;
506 
507  /* Shutdown the RT Container */
508  FwRtShutdown(&rtDesc);
509 
510  /* Check error code */
511  if (FwRtGetErrCode(&rtDesc) != 0)
512  return rtTestCaseFailure;
513 
514  return rtTestCaseSuccess;
515 }
516 
517 /*------------------------------------------------------------------------------------------------- */
519  FwRtDesc_t rtDesc;
520  struct TestRtData* rtData;
521 
522  /* Instantiate and initialize test container RT1 */
523  rtDesc = FwRtMakeTestRT1(1);
524 
525  /* Configure RT1 */
526  rtData = (struct TestRtData*)rtDesc->rtData;
527  rtData->npImplNotifLogicFlag = 0; /* skip notification */
528  rtData->apExecFuncBehaviourFlag = 0; /* do not terminate functional behaviour */
529  rtData->apImplActivLogicFlag = 1; /* execute functional behaviour */
530 
531  /* Start RT Container */
532  FwRtStart(rtDesc);
533 
534  /* Check state of RT Container and its procedures */
535  if (FwRtGetContState(rtDesc) != rtContStarted)
536  return rtTestCaseFailure;
537  if (!FwRtIsActivPrStarted(rtDesc))
538  return rtTestCaseFailure;
539  if (!FwRtIsNotifPrStarted(rtDesc))
540  return rtTestCaseFailure;
541  if (FwRtGetNotifCounter(rtDesc) != 0)
542  return rtTestCaseFailure;
543  if (rtData->npFinalCounter != 0)
544  return rtTestCaseFailure;
545  if (rtData->npImplNotifLogicCounter != 0)
546  return rtTestCaseFailure;
547  if (rtData->npInitCounter != 1)
548  return rtTestCaseFailure;
549  if (rtData->apExecFuncBehaviourCounter != 0)
550  return rtTestCaseFailure;
551  if (rtData->apFinalCounter != 0)
552  return rtTestCaseFailure;
553  if (rtData->apImplActivLogicCounter != 0)
554  return rtTestCaseFailure;
555  if (rtData->apInitCounter != 1)
556  return rtTestCaseFailure;
557  if (rtData->apSetupNotifCounter != 1)
558  return rtTestCaseFailure;
559 
560  /* Notify RT Container and give Activation Thread a chance to run*/
561  FwRtNotify(rtDesc);
562  nanosleep(&tenMs,NULL);
563 
564  /* Check state of counters */
565  if (rtData->npFinalCounter != 0)
566  return rtTestCaseFailure;
567  if (rtData->npImplNotifLogicCounter != 1)
568  return rtTestCaseFailure;
569  if (rtData->npInitCounter != 1)
570  return rtTestCaseFailure;
571  if (rtData->apExecFuncBehaviourCounter != 0)
572  return rtTestCaseFailure;
573  if (rtData->apFinalCounter != 0)
574  return rtTestCaseFailure;
575  if (rtData->apImplActivLogicCounter != 0)
576  return rtTestCaseFailure;
577  if (rtData->apInitCounter != 1)
578  return rtTestCaseFailure;
579  if (rtData->apSetupNotifCounter != 1)
580  return rtTestCaseFailure;
581 
582  /* Notify RT Container and give Activation Thread a chance to run*/
583  FwRtNotify(rtDesc);
584  nanosleep(&tenMs,NULL);
585 
586  /* Check state of counters */
587  if (rtData->npFinalCounter != 0)
588  return rtTestCaseFailure;
589  if (rtData->npImplNotifLogicCounter != 2)
590  return rtTestCaseFailure;
591  if (rtData->npInitCounter != 1)
592  return rtTestCaseFailure;
593  if (rtData->apExecFuncBehaviourCounter != 0)
594  return rtTestCaseFailure;
595  if (rtData->apFinalCounter != 0)
596  return rtTestCaseFailure;
597  if (rtData->apImplActivLogicCounter != 0)
598  return rtTestCaseFailure;
599  if (rtData->apInitCounter != 1)
600  return rtTestCaseFailure;
601  if (rtData->apSetupNotifCounter != 1)
602  return rtTestCaseFailure;
603 
604  /* Configure RT1 */
605  rtData = (struct TestRtData*)rtDesc->rtData;
606  rtData->npImplNotifLogicFlag = 1; /* do notification */
607  rtData->apExecFuncBehaviourFlag = 0; /* do not terminate functional behaviour */
608  rtData->apImplActivLogicFlag = 1; /* execute functional behaviour */
609 
610  /* Notify RT Container and give Activation Thread a chance to run*/
611  FwRtNotify(rtDesc);
612  nanosleep(&tenMs,NULL);
613 
614  /* Check state of counters */
615  if (rtData->npFinalCounter != 0)
616  return rtTestCaseFailure;
617  if (rtData->npImplNotifLogicCounter != 3)
618  return rtTestCaseFailure;
619  if (rtData->npInitCounter != 1)
620  return rtTestCaseFailure;
621  if (rtData->apExecFuncBehaviourCounter != 1)
622  return rtTestCaseFailure;
623  if (rtData->apFinalCounter != 0)
624  return rtTestCaseFailure;
625  if (rtData->apImplActivLogicCounter != 1)
626  return rtTestCaseFailure;
627  if (rtData->apInitCounter != 1)
628  return rtTestCaseFailure;
629  if (rtData->apSetupNotifCounter != 2)
630  return rtTestCaseFailure;
631 
632  /* Configure RT1 */
633  rtData = (struct TestRtData*)rtDesc->rtData;
634  rtData->npImplNotifLogicFlag = 1; /* do notification */
635  rtData->apExecFuncBehaviourFlag = 0; /* do not terminate functional behaviour */
636  rtData->apImplActivLogicFlag = 0; /* skip functional behaviour */
637 
638  /* Notify RT Container and give Activation Thread a chance to run*/
639  FwRtNotify(rtDesc);
640  nanosleep(&tenMs,NULL);
641 
642  /* Check state of counters */
643  if (rtData->npFinalCounter != 0)
644  return rtTestCaseFailure;
645  if (rtData->npImplNotifLogicCounter != 4)
646  return rtTestCaseFailure;
647  if (rtData->npInitCounter != 1)
648  return rtTestCaseFailure;
649  if (rtData->apExecFuncBehaviourCounter != 1)
650  return rtTestCaseFailure;
651  if (rtData->apFinalCounter != 0)
652  return rtTestCaseFailure;
653  if (rtData->apImplActivLogicCounter != 2)
654  return rtTestCaseFailure;
655  if (rtData->apInitCounter != 1)
656  return rtTestCaseFailure;
657  if (rtData->apSetupNotifCounter != 3)
658  return rtTestCaseFailure;
659 
660  /* Configure RT1 */
661  rtData = (struct TestRtData*)rtDesc->rtData;
662  rtData->npImplNotifLogicFlag = 1; /* do notification */
663  rtData->apExecFuncBehaviourFlag = 1; /* terminate functional behaviour */
664  rtData->apImplActivLogicFlag = 1; /* execute functional behaviour */
665 
666  /* Notify RT Container and wait until Activation Thread has terminated */
667  FwRtNotify(rtDesc);
668  FwRtWaitForTermination(rtDesc);
669 
670  /* Check state of counters */
671  if (rtData->npFinalCounter != 1)
672  return rtTestCaseFailure;
673  if (rtData->npImplNotifLogicCounter != 5)
674  return rtTestCaseFailure;
675  if (rtData->npInitCounter != 1)
676  return rtTestCaseFailure;
677  if (rtData->apExecFuncBehaviourCounter != 2)
678  return rtTestCaseFailure;
679  if (rtData->apFinalCounter != 1)
680  return rtTestCaseFailure;
681  if (rtData->apImplActivLogicCounter != 3)
682  return rtTestCaseFailure;
683  if (rtData->apInitCounter != 1)
684  return rtTestCaseFailure;
685  if (rtData->apSetupNotifCounter != 3)
686  return rtTestCaseFailure;
687 
688  /* Shutdown the RT Container */
689  FwRtShutdown(rtDesc);
690 
691  /* Check error code */
692  if (FwRtGetErrCode(rtDesc) != 0)
693  return rtTestCaseFailure;
694 
695  /* Retrieve the container again from its factory (this resets,
696  * reconfigures and re-initializes it) */
697  rtDesc = FwRtMakeTestRT1(1);
698 
699  /* Configure RT1 */
700  rtData = (struct TestRtData*)rtDesc->rtData;
701  rtData->npImplNotifLogicFlag = 0; /* skip notification */
702  rtData->apExecFuncBehaviourFlag = 0; /* do not terminate functional behaviour */
703  rtData->apImplActivLogicFlag = 1; /* execute functional behaviour */
704  rtData->apExecFuncBehaviourCounter = 0;
705  rtData->apFinalCounter = 0;
706  rtData->apImplActivLogicCounter = 0;
707  rtData->apInitCounter = 0;
708  rtData->apSetupNotifCounter = 0;
709  rtData->npFinalCounter = 0;
710  rtData->npImplNotifLogicCounter = 0;
711  rtData->npInitCounter = 0;
712 
713  /* Start RT Container */
714  FwRtStart(rtDesc);
715 
716  /* Check state of RT Container and its procedures */
717  if (FwRtGetContState(rtDesc) != rtContStarted)
718  return rtTestCaseFailure;
719  if (!FwRtIsActivPrStarted(rtDesc))
720  return rtTestCaseFailure;
721  if (!FwRtIsNotifPrStarted(rtDesc))
722  return rtTestCaseFailure;
723  if (FwRtGetNotifCounter(rtDesc) != 0)
724  return rtTestCaseFailure;
725 
726  /* Notify RT Container and give Activation Thread a chance to run*/
727  FwRtNotify(rtDesc);
728  nanosleep(&tenMs,NULL);
729 
730  /* Check state of counters */
731  if (rtData->npFinalCounter != 0)
732  return rtTestCaseFailure;
733  if (rtData->npImplNotifLogicCounter != 1)
734  return rtTestCaseFailure;
735  if (rtData->npInitCounter != 1)
736  return rtTestCaseFailure;
737  if (rtData->apExecFuncBehaviourCounter != 0)
738  return rtTestCaseFailure;
739  if (rtData->apFinalCounter != 0)
740  return rtTestCaseFailure;
741  if (rtData->apImplActivLogicCounter != 0)
742  return rtTestCaseFailure;
743  if (rtData->apInitCounter != 1)
744  return rtTestCaseFailure;
745  if (rtData->apSetupNotifCounter != 1)
746  return rtTestCaseFailure;
747 
748  /* Notify RT Container and give Activation Thread a chance to run*/
749  FwRtNotify(rtDesc);
750  nanosleep(&tenMs,NULL);
751 
752  /* Check state of counters */
753  if (rtData->npFinalCounter != 0)
754  return rtTestCaseFailure;
755  if (rtData->npImplNotifLogicCounter != 2)
756  return rtTestCaseFailure;
757  if (rtData->npInitCounter != 1)
758  return rtTestCaseFailure;
759  if (rtData->apExecFuncBehaviourCounter != 0)
760  return rtTestCaseFailure;
761  if (rtData->apFinalCounter != 0)
762  return rtTestCaseFailure;
763  if (rtData->apImplActivLogicCounter != 0)
764  return rtTestCaseFailure;
765  if (rtData->apInitCounter != 1)
766  return rtTestCaseFailure;
767  if (rtData->apSetupNotifCounter != 1)
768  return rtTestCaseFailure;
769 
770  /* Configure RT1 */
771  rtData = (struct TestRtData*)rtDesc->rtData;
772  rtData->npImplNotifLogicFlag = 1; /* do notification */
773  rtData->apExecFuncBehaviourFlag = 0; /* do not terminate functional behaviour */
774  rtData->apImplActivLogicFlag = 1; /* execute functional behaviour */
775 
776  /* Notify RT Container and give Activation Thread a chance to run*/
777  FwRtNotify(rtDesc);
778  nanosleep(&tenMs,NULL);
779 
780  /* Check state of counters */
781  if (rtData->npFinalCounter != 0)
782  return rtTestCaseFailure;
783  if (rtData->npImplNotifLogicCounter != 3)
784  return rtTestCaseFailure;
785  if (rtData->npInitCounter != 1)
786  return rtTestCaseFailure;
787  if (rtData->apExecFuncBehaviourCounter != 1)
788  return rtTestCaseFailure;
789  if (rtData->apFinalCounter != 0)
790  return rtTestCaseFailure;
791  if (rtData->apImplActivLogicCounter != 1)
792  return rtTestCaseFailure;
793  if (rtData->apInitCounter != 1)
794  return rtTestCaseFailure;
795  if (rtData->apSetupNotifCounter != 2)
796  return rtTestCaseFailure;
797 
798  /* Configure RT1 */
799  rtData = (struct TestRtData*)rtDesc->rtData;
800  rtData->npImplNotifLogicFlag = 1; /* do notification */
801  rtData->apExecFuncBehaviourFlag = 1; /* terminate functional behaviour */
802  rtData->apImplActivLogicFlag = 1; /* execute functional behaviour */
803 
804  /* Notify RT Container and wait until Activation Thread has terminated */
805  FwRtNotify(rtDesc);
806  FwRtWaitForTermination(rtDesc);
807 
808  /* Check state of counters */
809  if (rtData->npFinalCounter != 1)
810  return rtTestCaseFailure;
811  if (rtData->npImplNotifLogicCounter != 4)
812  return rtTestCaseFailure;
813  if (rtData->npInitCounter != 1)
814  return rtTestCaseFailure;
815  if (rtData->apExecFuncBehaviourCounter != 2)
816  return rtTestCaseFailure;
817  if (rtData->apFinalCounter != 1)
818  return rtTestCaseFailure;
819  if (rtData->apImplActivLogicCounter != 2)
820  return rtTestCaseFailure;
821  if (rtData->apInitCounter != 1)
822  return rtTestCaseFailure;
823  if (rtData->apSetupNotifCounter != 2)
824  return rtTestCaseFailure;
825 
826  /* Shutdown the RT Container */
827  FwRtShutdown(rtDesc);
828 
829  /* Check error code */
830  if (FwRtGetErrCode(rtDesc) != 0)
831  return rtTestCaseFailure;
832 
833  return rtTestCaseSuccess;
834 }
835 
836 /*--------------------------------------------------------------------------*/
838  FwRtDesc_t rtDesc;
839  struct TestRtData* rtData;
840 
841  /* Instantiate and initialize test container RT2 */
842  rtDesc = FwRtMakeTestRT2(1);
843 
844  /* Configure RT2 */
845  rtData = (struct TestRtData*)rtDesc->rtData;
846  rtData->npImplNotifLogicFlag = 1; /* do not skip notification */
847  rtData->apExecFuncBehaviourFlag = 0; /* do not terminate functional behaviour */
848  rtData->apImplActivLogicFlag = 1; /* execute functional behaviour */
849 
850  /* Start RT Container */
851  FwRtStart(rtDesc);
852 
853  /* Check state of RT Container and its procedures */
854  if (FwRtGetContState(rtDesc) != rtContStarted)
855  return rtTestCaseFailure;
856  if (!FwRtIsActivPrStarted(rtDesc))
857  return rtTestCaseFailure;
858  if (!FwRtIsNotifPrStarted(rtDesc))
859  return rtTestCaseFailure;
860  if (FwRtGetNotifCounter(rtDesc) != 0)
861  return rtTestCaseFailure;
862 
863  /* Notify RT Container five consecutive times */
864  FwRtNotify(rtDesc);
865  FwRtNotify(rtDesc);
866  FwRtNotify(rtDesc);
867  FwRtNotify(rtDesc);
868  FwRtNotify(rtDesc);
869 
870  /* Check state of RT Container and its procedures */
871  if ((FwRtGetNotifCounter(rtDesc) != 5) && (FwRtGetNotifCounter(rtDesc) != 4))
872  return rtTestCaseFailure;
873  if (FwRtGetContState(rtDesc) != rtContStarted)
874  return rtTestCaseFailure;
875  if (!FwRtIsActivPrStarted(rtDesc))
876  return rtTestCaseFailure;
877  if (!FwRtIsNotifPrStarted(rtDesc))
878  return rtTestCaseFailure;
879 
880  /* Wait 10 ms */
881  nanosleep(&tenMs,NULL);
882 
883  /* Check state of RT Container and its procedures */
884  if (FwRtGetContState(rtDesc) != rtContStarted)
885  return rtTestCaseFailure;
886  if (!FwRtIsActivPrStarted(rtDesc))
887  return rtTestCaseFailure;
888  if (!FwRtIsNotifPrStarted(rtDesc))
889  return rtTestCaseFailure;
890  if (FwRtGetNotifCounter(rtDesc) != 0)
891  return rtTestCaseFailure;
892 
893  /* Stop RT Container and wait until Activation Thread has terminated */
894  FwRtStop(rtDesc);
895  FwRtWaitForTermination(rtDesc);
896 
897  /* Check state of counters */
898  if (rtData->npFinalCounter != 1)
899  return rtTestCaseFailure;
900  if (rtData->npImplNotifLogicCounter != 5)
901  return rtTestCaseFailure;
902  if (rtData->npInitCounter != 1)
903  return rtTestCaseFailure;
904  if (rtData->apExecFuncBehaviourCounter != 5)
905  return rtTestCaseFailure;
906  if (rtData->apFinalCounter != 1)
907  return rtTestCaseFailure;
908  if (rtData->apImplActivLogicCounter != 5)
909  return rtTestCaseFailure;
910  if (rtData->apInitCounter != 1)
911  return rtTestCaseFailure;
912  if (rtData->apSetupNotifCounter != 6)
913  return rtTestCaseFailure;
914 
915  /* Shutdown the RT Container */
916  FwRtShutdown(rtDesc);
917 
918  /* Check error code */
919  if (FwRtGetErrCode(rtDesc) != 0)
920  return rtTestCaseFailure;
921 
922  return rtTestCaseSuccess;
923 }
924 
925 /*--------------------------------------------------------------------------*/
927  FwRtDesc_t rtDesc;
928  struct TestRtData* rtData;
929 
930  /* Instantiate and initialize test container RT2 */
931  rtDesc = FwRtMakeTestRT2(1);
932 
933  /* Configure RT2 */
934  rtData = (struct TestRtData*)rtDesc->rtData;
935  rtData->npImplNotifLogicFlag = 1; /* do not skip notification */
936  rtData->apExecFuncBehaviourFlag = 0; /* do not terminate functional behaviour */
937  rtData->apImplActivLogicFlag = 1; /* execute functional behaviour */
938 
939  /* Start RT Container */
940  FwRtStart(rtDesc);
941 
942  /* Check state of RT Container and its procedures */
943  if (FwRtGetContState(rtDesc) != rtContStarted)
944  return rtTestCaseFailure;
945  if (!FwRtIsActivPrStarted(rtDesc))
946  return rtTestCaseFailure;
947  if (!FwRtIsNotifPrStarted(rtDesc))
948  return rtTestCaseFailure;
949  if (FwRtGetNotifCounter(rtDesc) != 0)
950  return rtTestCaseFailure;
951 
952  /* Notify RT Container a few consecutive times */
953  FwRtNotify(rtDesc);
954  FwRtNotify(rtDesc);
955  FwRtNotify(rtDesc);
956  FwRtNotify(rtDesc);
957  FwRtNotify(rtDesc);
958  FwRtNotify(rtDesc);
959  FwRtNotify(rtDesc);
960  FwRtNotify(rtDesc);
961  FwRtNotify(rtDesc);
962 
963  /* Wait 3 ms (enough for some of the notification requests to be processed) */
964  nanosleep(&oneMs,NULL);
965  nanosleep(&oneMs,NULL);
966  nanosleep(&oneMs,NULL);
967 
968  /* Stop RT Container and wait until Activation Thread has terminated */
969  FwRtStop(rtDesc);
970  FwRtWaitForTermination(rtDesc);
971 
972  /* Check state of counters */
973  if (rtData->npFinalCounter != 1)
974  return rtTestCaseFailure;
975  if (rtData->npImplNotifLogicCounter != 9)
976  return rtTestCaseFailure;
977  if (rtData->npInitCounter != 1)
978  return rtTestCaseFailure;
979  if (rtData->apExecFuncBehaviourCounter == 0)
980  return rtTestCaseFailure;
981  if (rtData->apFinalCounter != 1)
982  return rtTestCaseFailure;
983  if (rtData->apImplActivLogicCounter == 0)
984  return rtTestCaseFailure;
985  if (rtData->apInitCounter != 1)
986  return rtTestCaseFailure;
987  if (rtData->apSetupNotifCounter == 0)
988  return rtTestCaseFailure;
989 
990  /* Check state of RT Container and its procedures */
991  if (FwRtGetNotifCounter(rtDesc) == 0)
992  return rtTestCaseFailure;
993  if (FwRtGetContState(rtDesc) != rtContStopped)
994  return rtTestCaseFailure;
995  if (FwRtIsActivPrStarted(rtDesc))
996  return rtTestCaseFailure;
997  if (FwRtIsNotifPrStarted(rtDesc))
998  return rtTestCaseFailure;
999 
1000  /* Shutdown the RT Container */
1001  FwRtShutdown(rtDesc);
1002 
1003  /* Check error code */
1004  if (FwRtGetErrCode(rtDesc) != 0)
1005  return rtTestCaseFailure;
1006 
1007  return rtTestCaseSuccess;
1008 }
1009 
1010 /*--------------------------------------------------------------------------*/
1012  FwRtDesc_t rtDesc;
1013  struct TestRtData* rtData;
1014  int i;
1015 
1016  /* Instantiate and initialize test container RT3 */
1017  rtDesc = FwRtMakeTestRT3(1);
1018  rtData = (struct TestRtData*)FwRtGetData(rtDesc);
1019 
1020  /* Start RT Container */
1021  FwRtStart(rtDesc);
1022 
1023  /* Check state of RT Container and its procedures */
1024  if (FwRtGetContState(rtDesc) != rtContStarted)
1025  return rtTestCaseFailure;
1026  if (!FwRtIsActivPrStarted(rtDesc))
1027  return rtTestCaseFailure;
1028  if (!FwRtIsNotifPrStarted(rtDesc))
1029  return rtTestCaseFailure;
1030  if (FwRtGetNotifCounter(rtDesc) != 0)
1031  return rtTestCaseFailure;
1032 
1033  /* Perform loop of notifications */
1034  for (i=1; i<10000; i++) {
1035  if (rand()<RAND_MAX/2)
1036  nanosleep(&oneMs,NULL);
1037  FwRtNotify(rtDesc);
1038  }
1039 
1040  /* Give Activation Thread a chance to process all pending notifications */
1041  nanosleep(&hundredMs,NULL);
1042 
1043  /* Stop RT Container and wait until Activation Thread has terminated */
1044  FwRtStop(rtDesc);
1045  FwRtWaitForTermination(rtDesc);
1046 
1047  /* Check state of counters */
1048  if (rtData->npFinalCounter != 1)
1049  return rtTestCaseFailure;
1050  if (rtData->npImplNotifLogicCounter != rtData->apImplActivLogicCounter)
1051  return rtTestCaseFailure;
1052  if (rtData->npInitCounter != 1)
1053  return rtTestCaseFailure;
1054  if (rtData->apFinalCounter != 1)
1055  return rtTestCaseFailure;
1056  if (rtData->apImplActivLogicCounter == 0)
1057  return rtTestCaseFailure;
1058  if (rtData->apInitCounter != 1)
1059  return rtTestCaseFailure;
1060  if (rtData->apSetupNotifCounter < rtData->apExecFuncBehaviourCounter)
1061  return rtTestCaseFailure;
1062 
1063  /* Check state of RT Container and its procedures */
1064  if (FwRtGetNotifCounter(rtDesc) != 0)
1065  return rtTestCaseFailure;
1066  if (FwRtGetContState(rtDesc) != rtContStopped)
1067  return rtTestCaseFailure;
1068  if (FwRtIsActivPrStarted(rtDesc))
1069  return rtTestCaseFailure;
1070  if (FwRtIsNotifPrStarted(rtDesc))
1071  return rtTestCaseFailure;
1072 
1073  /* Shutdown the RT Container */
1074  FwRtShutdown(rtDesc);
1075 
1076  /* Check error code */
1077  if (FwRtGetErrCode(rtDesc) != 0)
1078  return rtTestCaseFailure;
1079 
1080  return rtTestCaseSuccess;
1081 }
1082 
1083 /*--------------------------------------------------------------------------*/
1085  FwRtDesc_t rtDesc;
1086  struct TestRtData* rtData;
1087  int i, nStartStopCycles;
1088 
1089  /* Instantiate and initialize test container RT3 */
1090  rtDesc = FwRtMakeTestRT4(1);
1091  rtData = (struct TestRtData*)FwRtGetData(rtDesc);
1092 
1093  /* Start RT Container */
1094  FwRtStart(rtDesc);
1095 
1096  /* Check state of RT Container and its procedures */
1097  if (FwRtGetContState(rtDesc) != rtContStarted)
1098  return rtTestCaseFailure;
1099  if (!FwRtIsActivPrStarted(rtDesc))
1100  return rtTestCaseFailure;
1101  if (!FwRtIsNotifPrStarted(rtDesc))
1102  return rtTestCaseFailure;
1103  if (FwRtGetNotifCounter(rtDesc) != 0)
1104  return rtTestCaseFailure;
1105 
1106  /* Perform loop of notifications and start/stop cycles */
1107  nStartStopCycles = 0;
1108  for (i=1; i<10000; i++) {
1109  if (rand()<RAND_MAX/2)
1110  nanosleep(&oneMs,NULL);
1111  FwRtNotify(rtDesc);
1112 
1113  /* Check if Activation Procedure has terminated */
1114  if (rtData->apExecFuncBehaviourFlag != 0) {
1115  nStartStopCycles++;
1116  /* Wait until Activation Thread has terminated */
1117  FwRtWaitForTermination(rtDesc);
1118  /* Check state of counters */
1119  if (rtData->npFinalCounter != nStartStopCycles)
1120  return rtTestCaseFailure;
1121  if (rtData->npImplNotifLogicCounter < rtData->apImplActivLogicCounter)
1122  return rtTestCaseFailure;
1123  if (rtData->npInitCounter != nStartStopCycles)
1124  return rtTestCaseFailure;
1125  if (rtData->apFinalCounter != nStartStopCycles)
1126  return rtTestCaseFailure;
1128  return rtTestCaseFailure;
1129  if (rtData->apInitCounter != nStartStopCycles)
1130  return rtTestCaseFailure;
1131  if (rtData->apSetupNotifCounter < rtData->apExecFuncBehaviourCounter)
1132  return rtTestCaseFailure;
1133  /* Check state of RT Container and its procedures */
1134  if (FwRtGetContState(rtDesc) != rtContStopped)
1135  return rtTestCaseFailure;
1136  if (FwRtIsActivPrStarted(rtDesc))
1137  return rtTestCaseFailure;
1138  if (FwRtIsNotifPrStarted(rtDesc))
1139  return rtTestCaseFailure;
1140  /* Reset the flag used to determine whether functional behaviour is terminated */
1141  rtData->apExecFuncBehaviourFlag = 0;
1142  /* Re-start RT Container */
1143  FwRtStart(rtDesc);
1144  }
1145 
1146  /* Decide whether to force a stop/start on the container */
1147  if (rand()<RAND_MAX/99) {
1148  FwRtStop(rtDesc);
1149  nStartStopCycles++;
1150  /* Wait until Activation Thread has terminated */
1151  FwRtWaitForTermination(rtDesc);
1152  /* Check state of counters */
1153  if (rtData->npFinalCounter != nStartStopCycles)
1154  return rtTestCaseFailure;
1155  if (rtData->npImplNotifLogicCounter < rtData->apImplActivLogicCounter)
1156  return rtTestCaseFailure;
1157  if (rtData->npInitCounter != nStartStopCycles)
1158  return rtTestCaseFailure;
1159  if (rtData->apFinalCounter != nStartStopCycles)
1160  return rtTestCaseFailure;
1162  return rtTestCaseFailure;
1163  if (rtData->apInitCounter != nStartStopCycles)
1164  return rtTestCaseFailure;
1165  if (rtData->apSetupNotifCounter < rtData->apExecFuncBehaviourCounter)
1166  return rtTestCaseFailure;
1167  /* Check state of RT Container and its procedures */
1168  if (FwRtGetContState(rtDesc) != rtContStopped)
1169  return rtTestCaseFailure;
1170  if (FwRtIsActivPrStarted(rtDesc))
1171  return rtTestCaseFailure;
1172  if (FwRtIsNotifPrStarted(rtDesc))
1173  return rtTestCaseFailure;
1174  /* Re-start RT Container */
1175  FwRtStart(rtDesc);
1176  }
1177  }
1178 
1179  /* Stop RT Container and wait until Activation Thread has terminated */
1180  FwRtStop(rtDesc);
1181  FwRtWaitForTermination(rtDesc);
1182 
1183  /* Shutdown the RT Container */
1184  FwRtShutdown(rtDesc);
1185 
1186  /* Check error code */
1187  if (FwRtGetErrCode(rtDesc) != 0)
1188  return rtTestCaseFailure;
1189 
1190  return rtTestCaseSuccess;
1191 }
1192 
1193 /*--------------------------------------------------------------------------*/
1195  FwRtDesc_t rtDesc;
1196  struct TestRtData* rtData;
1197  int i, nStartStopCycles;
1198  pthread_t notifThread;
1199  void* status = 0;
1200 
1201  /* Instantiate and initialize test container RT4 */
1202  rtDesc = FwRtMakeTestRT4(1);
1203  rtData = (struct TestRtData*)FwRtGetData(rtDesc);
1204 
1205  /* Start RT Container */
1206  FwRtStart(rtDesc);
1207 
1208  /* Check state of RT Container and its procedures */
1209  if (FwRtGetContState(rtDesc) != rtContStarted)
1210  return rtTestCaseFailure;
1211  if (!FwRtIsActivPrStarted(rtDesc))
1212  return rtTestCaseFailure;
1213  if (!FwRtIsNotifPrStarted(rtDesc))
1214  return rtTestCaseFailure;
1215  if (FwRtGetNotifCounter(rtDesc) != 0)
1216  return rtTestCaseFailure;
1217 
1218  /* Create the thread which sends the notification requests */
1219  pthread_create( &notifThread, NULL, TestCaseStressRun_Notify1, rtDesc);
1220  nStartStopCycles = 1;
1221 
1222  for (i=0; i<10000; i++) {
1223  if (rand()<RAND_MAX/20) {
1224  /* Stop the RT Container */
1225  FwRtStop(rtDesc);
1226  /* Wait until the Activation and Notification Threads have terminated */
1227  FwRtWaitForTermination(rtDesc);
1228  pthread_join(notifThread,status);
1229  /* Check state of counters */
1230  if (rtData->npFinalCounter != nStartStopCycles)
1231  return rtTestCaseFailure;
1232  if (rtData->npImplNotifLogicCounter < rtData->apImplActivLogicCounter)
1233  return rtTestCaseFailure;
1234  if (rtData->npInitCounter != nStartStopCycles)
1235  return rtTestCaseFailure;
1236  if (rtData->apFinalCounter != nStartStopCycles)
1237  return rtTestCaseFailure;
1239  return rtTestCaseFailure;
1240  if (rtData->apInitCounter != nStartStopCycles)
1241  return rtTestCaseFailure;
1242  if (rtData->apSetupNotifCounter < rtData->apExecFuncBehaviourCounter)
1243  return rtTestCaseFailure;
1244  /* Check state of RT Container and its procedures */
1245  if (FwRtGetContState(rtDesc) != rtContStopped)
1246  return rtTestCaseFailure;
1247  if (FwRtIsActivPrStarted(rtDesc))
1248  return rtTestCaseFailure;
1249  if (FwRtIsNotifPrStarted(rtDesc))
1250  return rtTestCaseFailure;
1251  /* Restart container and notification thread */
1252  nStartStopCycles++;
1253  FwRtStart(rtDesc);
1254  pthread_create( &notifThread, NULL, TestCaseStressRun_Notify1, rtDesc);
1255  }
1256  }
1257 
1258  /* Stop RT Container and wait until Activation Thread has terminated */
1259  FwRtStop(rtDesc);
1260  FwRtWaitForTermination(rtDesc);
1261 
1262  /* Wait until notification thread has terminated */
1263  pthread_join(notifThread,status);
1264 
1265  /* Shutdown the RT Container */
1266  FwRtShutdown(rtDesc);
1267 
1268  /* Check error code */
1269  if (FwRtGetErrCode(rtDesc) != 0)
1270  return rtTestCaseFailure;
1271 
1272  return rtTestCaseSuccess;
1273 }
1274 
1275 /*--------------------------------------------------------------------------*/
1277  FwRtDesc_t rtDesc;
1278  struct TestRtData* rtData;
1279  int i, nStartStopCycles;
1280  pthread_t notifThread1, notifThread2;
1281  void* status = 0;
1282 
1283  /* Instantiate and initialize test container RT5 */
1284  rtDesc = FwRtMakeTestRT5(1);
1285  rtData = (struct TestRtData*)FwRtGetData(rtDesc);
1286 
1287  /* Configure container's actions */
1288  rtData->apImplActivLogicFlag = 1; /* Do not skip functional behaviour */
1289  rtData->npImplNotifLogicFlag = 1; /* Do not skip notification */
1290 
1291  /* Create the threads which send the notification requests */
1292  pthread_create( &notifThread1, NULL, TestCaseStressRun_Notify2, rtDesc);
1293  pthread_create( &notifThread2, NULL, TestCaseStressRun_Notify2, rtDesc);
1294  nStartStopCycles = 0;
1295 
1296  for (i=0; i<20; i++) {
1297  /* Start container */
1298  nStartStopCycles++;
1299  FwRtStart(rtDesc);
1300  /* Wait until the Activation Thread has terminated */
1301  FwRtWaitForTermination(rtDesc);
1302  /* Check state of counters */
1303  if (rtData->npFinalCounter != nStartStopCycles)
1304  return rtTestCaseFailure;
1305  if (rtData->npImplNotifLogicCounter < rtData->apImplActivLogicCounter)
1306  return rtTestCaseFailure;
1307  if (rtData->npInitCounter != nStartStopCycles)
1308  return rtTestCaseFailure;
1309  if (rtData->apFinalCounter != nStartStopCycles)
1310  return rtTestCaseFailure;
1311  if (rtData->apImplActivLogicCounter != rtData->apExecFuncBehaviourCounter)
1312  return rtTestCaseFailure;
1313  if (rtData->apInitCounter != nStartStopCycles)
1314  return rtTestCaseFailure;
1315  if (rtData->apSetupNotifCounter != rtData->apExecFuncBehaviourCounter)
1316  return rtTestCaseFailure;
1317  /* Check state of RT Container and its procedures */
1318  if (FwRtGetContState(rtDesc) != rtContStopped)
1319  return rtTestCaseFailure;
1320  if (FwRtIsActivPrStarted(rtDesc))
1321  return rtTestCaseFailure;
1322  if (FwRtIsNotifPrStarted(rtDesc))
1323  return rtTestCaseFailure;
1324  }
1325 
1326  /* Wait until notification threads have terminated */
1327  pthread_join(notifThread1,status);
1328  pthread_join(notifThread2,status);
1329 
1330  /* Shutdown the RT Container */
1331  FwRtShutdown(rtDesc);
1332 
1333  /* Check error code */
1334  if (FwRtGetErrCode(rtDesc) != 0)
1335  return rtTestCaseFailure;
1336 
1337  return rtTestCaseSuccess;
1338 }
1339 
1340 /*--------------------------------------------------------------------------*/
1342  FwRtDesc_t rtDesc;
1343  struct TestRtData* rtData;
1344  pthread_t notifThread1, notifThread2;
1345  void* status = 0;
1346 
1347  /* Instantiate and initialize test container RT1 */
1348  rtDesc = FwRtMakeTestRT1(1);
1349  rtData = (struct TestRtData*)FwRtGetData(rtDesc);
1350 
1351  /* Configure container's actions */
1352  rtData->apImplActivLogicFlag = 1; /* Do not skip functional behaviour */
1353  rtData->npImplNotifLogicFlag = 1; /* Do not skip notification */
1354  rtData->apExecFuncBehaviourFlag = 0; /* Do not terminate functional behaviour */
1355 
1356  /* Start container */
1357  FwRtStart(rtDesc);
1358 
1359  /* Create the threads which send the notification requests */
1360  pthread_create( &notifThread1, NULL, TestCaseStressRun_Notify2, rtDesc);
1361  pthread_create( &notifThread2, NULL, TestCaseStressRun_Notify2, rtDesc);
1362 
1363  /* Wait until notification threads and Activation Thread have terminated */
1364  pthread_join(notifThread1,status);
1365  pthread_join(notifThread2,status);
1366 
1367  /* Give time to the Activation Thread to process pending notifications */
1368  sleep(3);
1369 
1370  /* Check state of counters */
1371  if (rtData->npFinalCounter != 0)
1372  return rtTestCaseFailure;
1373  if (FwRtGetNotifCounter(rtDesc) != 0)
1374  return rtTestCaseFailure;
1375  if (rtData->npImplNotifLogicCounter != 2*N_NOTIFY2)
1376  return rtTestCaseFailure;
1377  if (rtData->npImplNotifLogicCounter != rtData->apImplActivLogicCounter)
1378  return rtTestCaseFailure;
1379  if (rtData->npInitCounter != 1)
1380  return rtTestCaseFailure;
1381  if (rtData->apFinalCounter != 0)
1382  return rtTestCaseFailure;
1383  if (rtData->apImplActivLogicCounter != rtData->apExecFuncBehaviourCounter)
1384  return rtTestCaseFailure;
1385  if (rtData->apInitCounter != 1)
1386  return rtTestCaseFailure;
1387  if (rtData->apSetupNotifCounter != rtData->apExecFuncBehaviourCounter + 1)
1388  return rtTestCaseFailure;
1389  /* Check state of RT Container and its procedures */
1390  if (FwRtGetContState(rtDesc) != rtContStarted)
1391  return rtTestCaseFailure;
1392  if (!FwRtIsActivPrStarted(rtDesc))
1393  return rtTestCaseFailure;
1394  if (!FwRtIsNotifPrStarted(rtDesc))
1395  return rtTestCaseFailure;
1396 
1397  /* Stop the RT Container */
1398  FwRtStop(rtDesc);
1399  if (FwRtGetContState(rtDesc) != rtContStopped)
1400  return rtTestCaseFailure;
1401  if (!FwRtIsActivPrStarted(rtDesc))
1402  return rtTestCaseFailure;
1403  if (!FwRtIsNotifPrStarted(rtDesc))
1404  return rtTestCaseFailure;
1405 
1406  /* Wait for Activation Thread termination and shutdown the RT Container */
1407  FwRtWaitForTermination(rtDesc);
1408  FwRtShutdown(rtDesc);
1409 
1410  /* Check error code */
1411  if (FwRtGetErrCode(rtDesc) != 0)
1412  return rtTestCaseFailure;
1413 
1414  return rtTestCaseSuccess;
1415 }
1416 
1417 /*--------------------------------------------------------------------------*/
1419  FwRtDesc_t rtDesc;
1420  struct TestRtData* rtData;
1421  int i, nStartStopCycles;
1422  pthread_t notifThread1, notifThread2;
1423  void* status = 0;
1424 
1425  /* Instantiate and initialize test container RT1 */
1426  rtDesc = FwRtMakeTestRT1(1);
1427  rtData = (struct TestRtData*)FwRtGetData(rtDesc);
1428 
1429  /* Configure container's actions */
1430  rtData->apImplActivLogicFlag = 1; /* Do not skip functional behaviour */
1431  rtData->npImplNotifLogicFlag = 1; /* Do not skip notification */
1432  rtData->apExecFuncBehaviourFlag = 0; /* Do not terminate functional behaviour */
1433 
1434  /* Start container */
1435  FwRtStart(rtDesc);
1436  nStartStopCycles = 1;
1437 
1438  /* Create the threads which send the notification requests */
1439  pthread_create( &notifThread1, NULL, TestCaseStressRun_Notify2, rtDesc);
1440  pthread_create( &notifThread2, NULL, TestCaseStressRun_Notify2, rtDesc);
1441 
1442  for (i=0; i<10000; i++) {
1443  if (rand()<RAND_MAX/2)
1444  nanosleep(&oneMs,NULL);
1445  if (rand()<RAND_MAX/99) {
1446  FwRtStop(rtDesc);
1447  FwRtWaitForTermination(rtDesc);
1448  if (rtData->npFinalCounter != nStartStopCycles)
1449  return rtTestCaseFailure;
1450  if (rtData->apFinalCounter != nStartStopCycles)
1451  return rtTestCaseFailure;
1452  if (rtData->npInitCounter != nStartStopCycles)
1453  return rtTestCaseFailure;
1454  if (rtData->apInitCounter != nStartStopCycles)
1455  return rtTestCaseFailure;
1456  if (FwRtGetContState(rtDesc) != rtContStopped)
1457  return rtTestCaseFailure;
1458  if (FwRtIsActivPrStarted(rtDesc))
1459  return rtTestCaseFailure;
1460  if (FwRtIsNotifPrStarted(rtDesc))
1461  return rtTestCaseFailure;
1462  /* Re-start container */
1463  FwRtStart(rtDesc);
1464  nStartStopCycles++;
1465  }
1466  }
1467 
1468  /* Stop the RT Container */
1469  FwRtStop(rtDesc);
1470 
1471  /* Wait for Notification and Activation Threads termination and shutdown the RT Container */
1472  FwRtWaitForTermination(rtDesc);
1473  pthread_join(notifThread1,status);
1474  pthread_join(notifThread2,status);
1475  FwRtShutdown(rtDesc);
1476 
1477  /* Check error code */
1478  if (FwRtGetErrCode(rtDesc) != 0)
1479  return rtTestCaseFailure;
1480 
1481  return rtTestCaseSuccess;
1482 }
1483 
1484 /*--------------------------------------------------------------------------*/
1485 void* TestCaseStressRun_Notify1(void* rtDesc) {
1486  int i;
1487  for (i=1; i<10000; i++) {
1488  if (rand()<RAND_MAX/2)
1489  nanosleep(&nineMs,NULL);
1490  FwRtNotify((FwRtDesc_t)rtDesc);
1491  if (FwRtGetContState((FwRtDesc_t)rtDesc) != rtContStarted)
1492  break;
1493  }
1494  return NULL;
1495 }
1496 
1497 /*--------------------------------------------------------------------------*/
1498 void* TestCaseStressRun_Notify2(void* rtDesc) {
1499  int i;
1500  for (i=0; i<N_NOTIFY2; i++) {
1501  if (rand()<RAND_MAX/2)
1502  nanosleep(&oneMs,NULL);
1503  FwRtNotify((FwRtDesc_t)rtDesc);
1504  }
1505  return NULL;
1506 }
1507 
1508 /*--------------------------------------------------------------------------*/
1510  return 1;
1511 }
1512 
1513 /*--------------------------------------------------------------------------*/
1515  return 1;
1516 }
1517 
1518 /*--------------------------------------------------------------------------*/
1520  return 1;
1521 }
1522 
1523 /*--------------------------------------------------------------------------*/
1525  return 1;
1526 }
1527 
1528 /*--------------------------------------------------------------------------*/
1530  return 1;
1531 }
1532 
1533 /*--------------------------------------------------------------------------*/
1535  return 1;
1536 }
1537 
1538 /*--------------------------------------------------------------------------*/
1540  return 1;
1541 }
1542 
1543 /*--------------------------------------------------------------------------*/
1545  return 1;
1546 }
1547 
1548 
void * rtData
The pointer to the RT Container data.
void FwRtSetInitializeActivPr(FwRtDesc_t rtDesc, FwRtAction_t initializeActivPr)
Define the function implementing the Initialization Action for the Activation Procedure.
Definition: FwRtConfig.c:217
Declaration of the test cases for the RT Container Module.
int apImplActivLogicCounter
Counter increment by the Implement Activation Logic Action.
Definition: FwRtMakeTest.h:53
FwRtDesc_t FwRtMakeTestRT3(unsigned int i)
This function resets the i-th instance of the Test RT Container RT3 and returns a pointer to its desc...
Definition: FwRtMakeTest.c:317
FwRtOutcome_t InitializeNotifPr(FwRtDesc_t rtDesc)
Dummy procedure action function.
FwRtTestOutcome_t FwRtTestCaseRun3()
Verify the logic to handle a container stop request while notifications are pending.
void FwRtSetPosixAttr(FwRtDesc_t rtDesc, pthread_attr_t *pThreadAttr, pthread_mutexattr_t *pMutexAttr, pthread_condattr_t *pCondAttr)
Set the pointers to the attribute objects of the POSIX thread, mutex and condition variable used by t...
Definition: FwRtConfig.c:151
Declaration of the API for a RT Container.
FwRtOutcome_t FinalizeNotifPr(FwRtDesc_t rtDesc)
Dummy procedure action function.
FwRtTestOutcome_t FwRtTestCaseSetAction1()
Verify the action setting interface of a RT Container.
Header file to define all constants and types for the RT Container Module of the FW Profile...
The RT Container is in state STOPPED.
Definition: FwRtConstants.h:64
FwRtAction_t initializeNotifPr
Pointer to the function encapsulating the initialization action for the Notification Procedure...
FwRtDesc_t FwRtMakeTestRT5(unsigned int i)
This function resets the i-th instance of the Test RT Container RT5 and returns a pointer to its desc...
Definition: FwRtMakeTest.c:401
FwRtOutcome_t apExecFuncBehaviourFlag
Flag determining the outcome of the Execute Functional Behaviour Action.
Definition: FwRtMakeTest.h:59
void FwRtNotify(FwRtDesc_t rtDesc)
Execute the Notification Procedure of a RT Container.
Definition: FwRtCore.c:137
int apSetupNotifCounter
Counter incremented by the Setup Notification Action.
Definition: FwRtMakeTest.h:51
FwRtOutcome_t ImplementActivLogic(FwRtDesc_t rtDesc)
Dummy procedure action function.
FwRtDesc_t FwRtMakeTestRT1(unsigned int i)
This function resets the i-th instance of the Test RT Container RT1 and returns a pointer to its desc...
Definition: FwRtMakeTest.c:233
void FwRtSetImplementActivLogic(FwRtDesc_t rtDesc, FwRtAction_t implementActivLogic)
Define the function implementing the activation logic for the RT Container.
Definition: FwRtConfig.c:244
Test case failure.
Definition: FwRtTestCases.h:27
void FwRtSetInitializeNotifPr(FwRtDesc_t rtDesc, FwRtAction_t initializeNotifPr)
Define the function implementing the Initialization Action for the Notification Procedure.
Definition: FwRtConfig.c:190
FwRtTestOutcome_t FwRtTestCaseRunNonNullAttr1()
Verify a nominal run of the RT Container with non-NULL values for the attributes of the POSIX objects...
FwRtAction_t implementNotifLogic
Pointer to the function encapsulating the implementation of the notification logic.
pthread_condattr_t * FwRtGetCondAttr(FwRtDesc_t rtDesc)
Get the value of the attributes of the condition variable associated to the RT Container.
Definition: FwRtConfig.c:175
void FwRtReset(FwRtDesc_t rtDesc)
Reset the RT Container descriptor (RTD).
Definition: FwRtConfig.c:31
FwRtTestOutcome_t FwRtTestCaseStressRun3()
Verify the RT Container logic in a stress test where two different threads send random sequences of n...
FwRtOutcome_t SetUpNotification(FwRtDesc_t rtDesc)
Dummy procedure action function.
FwRtAction_t finalizeActivPr
Pointer to the function encapsulating the finalization action for the Activation Procedure.
int apFinalCounter
Counter incremented by the Finalization Action of the Activation Procedure.
Definition: FwRtMakeTest.h:49
FwRtOutcome_t InitializeActivPr(FwRtDesc_t rtDesc)
Dummy procedure action function.
Test case success.
Definition: FwRtTestCases.h:25
FwRtAction_t implementActivLogic
Pointer to the function encapsulating the implementation of the activation logic. ...
FwRtTestOutcome_t FwRtTestCaseRunDefault1()
Verify a nominal run of the RT Container with default configuration.
FwRtOutcome_t(* FwRtAction_t)(FwRtDesc_t)
Type for a pointer to a container action.
Definition: FwRtConstants.h:50
FwRtTestOutcome_t FwRtTestCaseStressRun5()
Verify the RT Container logic in a stress test where two threads send random sequences of notificatio...
void FwRtSetFinalizeActivPr(FwRtDesc_t rtDesc, FwRtAction_t finalizeActivPr)
Define the function implementing the Finalization Action for the Activation Procedure.
Definition: FwRtConfig.c:226
FwRtOutcome_t FinalizeActivPr(FwRtDesc_t rtDesc)
Dummy procedure action function.
void FwRtWaitForTermination(FwRtDesc_t rtDesc)
Blocking function which returns when the Activation Thread has terminated.
Definition: FwRtCore.c:154
void FwRtStop(FwRtDesc_t rtDesc)
Stop a RT Container.
Definition: FwRtCore.c:97
void FwRtShutdown(FwRtDesc_t rtDesc)
Shutdown the RT Container.
Definition: FwRtConfig.c:105
FwRtAction_t setUpNotification
Pointer to the function encapsulating the logic to set up the notification for the RT Container...
FwRtAction_t execFuncBehaviour
Pointer to the function encapsulating the execution of the functional behaviour associated to the RT ...
int FwRtGetErrCode(FwRtDesc_t rtDesc)
Return the error code of the RT Container.
Definition: FwRtCore.c:181
void FwRtStart(FwRtDesc_t rtDesc)
Start a RT Container.
Definition: FwRtCore.c:47
The RT Container has not yet been initialized.
Definition: FwRtConstants.h:62
FwRtState_t FwRtGetContState(FwRtDesc_t rtDesc)
Return the RT Container state.
Definition: FwRtCore.c:176
FwRtTestOutcome_t FwRtTestCaseStressRun2()
Verify the RT Container logic in a stress test with a long sequences of notifications and start/stop ...
struct FwRtDesc * FwRtDesc_t
Forward declaration for the pointer to a RT Container Descriptor.
Definition: FwRtConstants.h:31
int apExecFuncBehaviourCounter
Counter incremented by the Execute Functional Behaviour Action.
Definition: FwRtMakeTest.h:57
pthread_mutexattr_t * FwRtGetMutexAttr(FwRtDesc_t rtDesc)
Get the value of the attributes of the mutex associated to the RT Container.
Definition: FwRtConfig.c:170
void FwRtSetImplementNotifLogic(FwRtDesc_t rtDesc, FwRtAction_t implementNotifLogicPr)
Define the function implementing the Notification Logic for the Notification Procedure.
Definition: FwRtConfig.c:208
Type for the data structure passed to all RT Containers made by the functions declared by this header...
Definition: FwRtMakeTest.h:37
int npInitCounter
Counter incremented by the Initialization Action of the Notification Procedure.
Definition: FwRtMakeTest.h:39
void FwRtSetSetUpNotif(FwRtDesc_t rtDesc, FwRtAction_t setUpNotification)
Define the function implementing the logic to set up a notification for the RT Container.
Definition: FwRtConfig.c:235
FwRtTestOutcome_t FwRtTestCaseRun2()
Verify the logic to handle bursts of notifications.
FwRtOutcome_t apImplActivLogicFlag
Flag determining outcome of Implement Activation Logic Action.
Definition: FwRtMakeTest.h:55
FwRtOutcome_t ExecFuncBehaviour(FwRtDesc_t rtDesc)
Dummy procedure action function.
Declaration of functions to create and configure test RT Containers.
FwRtOutcome_t ImplementNotifLogicPr(FwRtDesc_t rtDesc)
Dummy procedure action function.
pthread_attr_t * FwRtGetActivThreadAttr(FwRtDesc_t rtDesc)
Get the value of the attributes of the Activation Thread.
Definition: FwRtConfig.c:165
FwRtCounterU2_t FwRtGetNotifCounter(FwRtDesc_t rtDesc)
Return the value of the notification counter.
Definition: FwRtCore.c:186
FwRtDesc_t FwRtMakeTestRT2(unsigned int i)
This function resets the i-th instance of the Test RT Container RT2 and returns a pointer to its desc...
Definition: FwRtMakeTest.c:275
pthread_attr_t * pThreadAttr
The pointer to the Activation Thread attributes.
int apInitCounter
Counter incremented by the Initialization Action of the Activation Procedure.
Definition: FwRtMakeTest.h:47
FwRtTestOutcome_t FwRtTestCaseStressRun4()
Verify the RT Container logic in a stress test where two threads send random sequences of notificatio...
FwRtBool_t FwRtIsActivPrStarted(FwRtDesc_t rtDesc)
Check whether the Activation Procedure is started.
Definition: FwRtCore.c:171
FwRtTestOutcome_t FwRtTestCaseSetAttr1()
Verify the attribute setting interface of a RT Container.
#define N_NOTIFY2
Number of cycles in TestCaseStressRun_Notify2
Definition: FwRtTestCases.c:42
A configuration function has been called during the container&#39;s normal operation (i.e.
FwRtAction_t initializeActivPr
Pointer to the function encapsulating the initialization action for the Activation Procedure...
pthread_mutexattr_t * pMutexAttr
The pointer to the mutex attributes.
int npImplNotifLogicCounter
Counter incremented by the Implement Notification Logic Action.
Definition: FwRtMakeTest.h:43
void FwRtSetFinalizeNotifPr(FwRtDesc_t rtDesc, FwRtAction_t finalizeNotifPr)
Define the function implementing the Finalization Action for the Notification Procedure.
Definition: FwRtConfig.c:199
void FwRtInit(FwRtDesc_t rtDesc)
Initialize a RT Container.
Definition: FwRtConfig.c:52
FwRtBool_t FwRtIsNotifPrStarted(FwRtDesc_t rtDesc)
Check whether the Notification Procedure is started.
Definition: FwRtCore.c:166
FwRtDesc_t FwRtMakeTestRT4(unsigned int i)
This function resets the i-th instance of the Test RT Container RT4 and returns a pointer to its desc...
Definition: FwRtMakeTest.c:359
FwRtAction_t finalizeNotifPr
Pointer to the function encapsulating the finalization action for the Notification Procedure...
void * FwRtGetData(FwRtDesc_t rtDesc)
Get the pointer to the container data in the container descriptor.
Definition: FwRtConfig.c:185
FwRtOutcome_t npImplNotifLogicFlag
Flag determining outcome of Implement Notification Logic Action.
Definition: FwRtMakeTest.h:45
Structure representing a RT Container Descriptor.
pthread_condattr_t * pCondAttr
The pointer to the condition variable attributes.
FwRtTestOutcome_t
Outcome of a procedure test case.
Definition: FwRtTestCases.h:23
The RT Container is in state STARTED.
Definition: FwRtConstants.h:66
int FwRtOutcome_t
Type used for the outcome of a container action.
Definition: FwRtConstants.h:37
FwRtTestOutcome_t FwRtTestCaseStressRun1()
Verify the RT Container logic in a stress test with a long sequences of notifications and random outc...
FwRtTestOutcome_t FwRtTestCaseStressRun6()
Verify the RT Container logic in a stress test where two threads send random sequences of notificatio...
FwRtTestOutcome_t FwRtTestCaseRun1()
Verify the logic to skip a notification in the Notification Procedure.
void FwRtSetExecFuncBehaviour(FwRtDesc_t rtDesc, FwRtAction_t execFuncBehaviour)
Define the function which executes the functional behaviour associated to the RT Container.
Definition: FwRtConfig.c:253
int npFinalCounter
Counter incremented by the Finalization Action of the Notification Procedure.
Definition: FwRtMakeTest.h:41
P&P Software GmbH, Copyright 2011, All Rights Reserved