RKH
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
test_smTransition.c
Go to the documentation of this file.
1 /*
2  * --------------------------------------------------------------------------
3  *
4  * Framework RKH
5  * -------------
6  *
7  * State-machine framework for reactive embedded systems
8  *
9  * Copyright (C) 2010 Leandro Francucci.
10  * All rights reserved. Protected by international copyright laws.
11  *
12  *
13  * RKH is free software: you can redistribute it and/or modify it under the
14  * terms of the GNU General Public License as published by the Free Software
15  * Foundation, either version 3 of the License, or (at your option) any
16  * later version.
17  *
18  * RKH is distributed in the hope that it will be useful, but WITHOUT ANY
19  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
21  * more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with RKH, see copying.txt file.
25  *
26  * Contact information:
27  * RKH web site: http://sourceforge.net/projects/rkh-reactivesys/
28  * e-mail: francuccilea@gmail.com
29  * ---------------------------------------------------------------------------
30  */
31 
44 /* -------------------------- Development history -------------------------- */
45 /*
46  * 2016.12.15 LeFr v2.4.05 ---
47  */
48 
49 /* -------------------------------- Authors -------------------------------- */
50 /*
51  * LeFr Leandro Francucci francuccilea@gmail.com
52  */
53 
54 /* --------------------------------- Notes --------------------------------- */
55 /* ----------------------------- Include files ----------------------------- */
56 
57 #include "unity_fixture.h"
58 #include "unitrazer.h"
59 #include "rkh.h"
60 #include "common.h"
61 #include "smTest.h"
62 #include "smTestAct.h"
63 #include "MocksmTestAct.h"
64 
65 /* ----------------------------- Local macros ------------------------------ */
66 
67 /* ------------------------------- Constants ------------------------------- */
68 static RKH_STATIC_EVENT(evA, A);
69 static RKH_STATIC_EVENT(evB, B);
70 static RKH_STATIC_EVENT(evC, C);
71 static RKH_STATIC_EVENT(evD, D);
72 static RKH_STATIC_EVENT(evE, E);
73 static RKH_STATIC_EVENT(evF, F);
74 static RKH_STATIC_EVENT(evG, G);
75 static RKH_STATIC_EVENT(evH, H);
76 static RKH_STATIC_EVENT(evI, I);
77 static RKH_STATIC_EVENT(evCompletion, RKH_COMPLETION_EVENT);
78 static RKH_STATIC_EVENT(evTerminate, TERMINATE);
79 
80 /* ---------------------------- Local data types --------------------------- */
81 typedef struct StateMachine
82 {
83  RKH_SM_T sm;
84  int foo;
85 } StateMachine;
86 
87 typedef struct Composite
88 {
89  RKH_SMA_T ao;
90  int foo;
91  RKH_SM_T itsReactivePart;
92 } Composite;
93 
94 /* ---------------------------- Global variables --------------------------- */
95 TEST_GROUP(transition);
96 
97 /* ---------------------------- Local variables ---------------------------- */
98 /* ----------------------- Local function prototypes ----------------------- */
99 /* ---------------------------- Local functions ---------------------------- */
100 /* ---------------------------- Global functions --------------------------- */
101 TEST_SETUP(transition)
102 {
103  sm_init();
104  MocksmTestAct_Init();
105 
106  RKH_TR_FWK_AO(smTest);
107  RKH_TR_FWK_STATE(smTest, &waiting);
108  RKH_TR_FWK_STATE(smTest, &s0);
109  RKH_TR_FWK_STATE(smTest, &s1);
110  RKH_TR_FWK_STATE(smTest, &s2);
111  RKH_TR_FWK_STATE(smTest, &s21);
112  RKH_TR_FWK_STATE(smTest, &s22);
113  RKH_TR_FWK_STATE(smTest, &s221);
114  RKH_TR_FWK_STATE(smTest, &s2211);
115  RKH_TR_FWK_STATE(smTest, &s222);
116  RKH_TR_FWK_STATE(smTest, &s2221);
117  RKH_TR_FWK_STATE(smTest, &s22211);
118  RKH_TR_FWK_STATE(smTest, &s3);
119  RKH_TR_FWK_STATE(smTest, &s31);
120  RKH_TR_FWK_STATE(smTest, &s4);
121  RKH_TR_FWK_STATE(smTest, &s5);
122  RKH_TR_FWK_STATE(smTest, &s2Final);
123  RKH_TR_FWK_SIG(A);
124  RKH_TR_FWK_SIG(B);
125  RKH_TR_FWK_SIG(C);
126  RKH_TR_FWK_SIG(D);
127  RKH_TR_FWK_SIG(E);
128  RKH_TR_FWK_SIG(F);
129 
132  RKH_FILTER_OFF_SMA(smTest);
134 }
135 
136 TEST_TEAR_DOWN(transition)
137 {
138  sm_verify(); /* Makes sure there are no unused expectations, if */
139  /* there are, this function causes the test to fail. */
140  sm_cleanup();
141  MocksmTestAct_Verify();
142  MocksmTestAct_Destroy();
143 }
144 
152 TEST(transition, firstStateAfterInit)
153 {
154  UtrzProcessOut *p;
155 
156  sm_init_expect(RKH_STATE_CAST(&waiting));
157  sm_enstate_expect(RKH_STATE_CAST(&waiting));
158  smTest_init_Expect(RKH_CAST(SmTest, smTest));
159 
160  rkh_sm_init((RKH_SM_T *)smTest);
161 
162  p = unitrazer_getLastOut();
163  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
164 }
165 
166 TEST(transition, simpleToSimpleAtEqualLevel)
167 {
168  UtrzProcessOut *p;
169  const RKH_ST_T *targetStates[] =
170  {
171  RKH_STATE_CAST(&s1), RKH_STATE_CAST(0)
172  };
173  const RKH_ST_T *entryStates[] =
174  {
175  RKH_STATE_CAST(&s1), RKH_STATE_CAST(0)
176  };
177  const RKH_ST_T *exitStates[] =
178  {
179  RKH_STATE_CAST(&s0), RKH_STATE_CAST(0)
180  };
181 
182  smTest_init_Expect(RKH_CAST(SmTest, smTest));
183  smTest_xS0_Expect(RKH_CAST(SmTest, smTest));
184  smTest_tr11_Expect(RKH_CAST(SmTest, smTest), &evA);
185  smTest_nS1_Expect(RKH_CAST(SmTest, smTest));
186 
187  setProfile(smTest, RKH_STATE_CAST(&s0), RKH_STATE_CAST(&s0),
188  targetStates,
189  entryStates, exitStates, RKH_STATE_CAST(&s1), 1,
190  TRN_NOT_INTERNAL, INIT_STATE_MACHINE);
191 
192  rkh_sm_dispatch((RKH_SM_T *)smTest, &evA);
193 
194  p = unitrazer_getLastOut();
195  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
196 }
197 
198 TEST(transition, simpleToSimpleFromHighToLowLevel)
199 {
200  UtrzProcessOut *p;
201  const RKH_ST_T *targetStates[] =
202  {
203  RKH_STATE_CAST(&s21), RKH_STATE_CAST(0)
204  };
205  const RKH_ST_T *entryStates[] =
206  {
207  RKH_STATE_CAST(&s2), RKH_STATE_CAST(&s21), RKH_STATE_CAST(0)
208  };
209  const RKH_ST_T *exitStates[] =
210  {
211  RKH_STATE_CAST(&s0), RKH_STATE_CAST(0)
212  };
213 
214  smTest_xS0_Expect(RKH_CAST(SmTest, smTest));
215  smTest_tr12_Expect(RKH_CAST(SmTest, smTest), &evB);
216  smTest_nS2_Expect(RKH_CAST(SmTest, smTest));
217  smTest_nS21_Expect(RKH_CAST(SmTest, smTest));
218 
219  smTest_init_Expect(RKH_CAST(SmTest, smTest));
220  setProfile(smTest, RKH_STATE_CAST(&s0), RKH_STATE_CAST(&s0),
221  targetStates,
222  entryStates, exitStates, RKH_STATE_CAST(&s21), 1,
223  TRN_NOT_INTERNAL, INIT_STATE_MACHINE);
224 
225  rkh_sm_dispatch((RKH_SM_T *)smTest, &evB);
226 
227  p = unitrazer_getLastOut();
228  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
229 }
230 
231 TEST(transition, simpleToSimpleFromLowToHighLevel)
232 {
233  UtrzProcessOut *p;
234  const RKH_ST_T *targetStates[] =
235  {
236  RKH_STATE_CAST(&s0), RKH_STATE_CAST(0)
237  };
238  const RKH_ST_T *entryStates[] =
239  {
240  RKH_STATE_CAST(&s0), RKH_STATE_CAST(0)
241  };
242  const RKH_ST_T *exitStates[] =
243  {
244  RKH_STATE_CAST(&s21), RKH_STATE_CAST(&s2), RKH_STATE_CAST(0)
245  };
246 
247  smTest_xS21_Expect(RKH_CAST(SmTest, smTest));
248  smTest_xS2_Expect(RKH_CAST(SmTest, smTest));
249  smTest_tr13_Expect(RKH_CAST(SmTest, smTest), &evB);
250  smTest_nS0_Expect(RKH_CAST(SmTest, smTest));
251 
252  smTest_init_Expect(RKH_CAST(SmTest, smTest));
253  setProfile(smTest, RKH_STATE_CAST(&s21), RKH_STATE_CAST(&s21),
254  targetStates,
255  entryStates, exitStates, RKH_STATE_CAST(&s0), 1,
256  TRN_NOT_INTERNAL, INIT_STATE_MACHINE);
257 
258  rkh_sm_dispatch((RKH_SM_T *)smTest, &evB);
259 
260  p = unitrazer_getLastOut();
261  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
262 }
263 
264 TEST(transition, simpleToCompositeAtEqualLevel)
265 {
266  UtrzProcessOut *p;
267  const RKH_ST_T *targetStates[] =
268  {
269  RKH_STATE_CAST(&s2), RKH_STATE_CAST(0)
270  };
271  const RKH_ST_T *entryStates[] =
272  {
273  RKH_STATE_CAST(&s2), RKH_STATE_CAST(&s21), RKH_STATE_CAST(0)
274  };
275  const RKH_ST_T *exitStates[] =
276  {
277  RKH_STATE_CAST(&s0), RKH_STATE_CAST(0)
278  };
279 
280  smTest_xS0_Expect(RKH_CAST(SmTest, smTest));
281  smTest_tr21_Expect(RKH_CAST(SmTest, smTest), &evC);
282  smTest_nS2_Expect(RKH_CAST(SmTest, smTest));
283  smTest_iS2_Expect(RKH_CAST(SmTest, smTest));
284  smTest_nS21_Expect(RKH_CAST(SmTest, smTest));
285 
286  smTest_init_Expect(RKH_CAST(SmTest, smTest));
287  setProfile(smTest, RKH_STATE_CAST(&s0), RKH_STATE_CAST(&s0),
288  targetStates,
289  entryStates, exitStates, RKH_STATE_CAST(&s21), 1,
290  TRN_NOT_INTERNAL, INIT_STATE_MACHINE);
291 
292  rkh_sm_dispatch((RKH_SM_T *)smTest, &evC);
293 
294  p = unitrazer_getLastOut();
295  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
296 }
297 
298 TEST(transition, simpleToCompositeFromHighToLowLevel)
299 {
300  UtrzProcessOut *p;
301  const RKH_ST_T *targetStates[] =
302  {
303  RKH_STATE_CAST(&s22), RKH_STATE_CAST(0)
304  };
305  const RKH_ST_T *entryStates[] =
306  {
307  RKH_STATE_CAST(&s2), RKH_STATE_CAST(&s22), RKH_STATE_CAST(&s221),
308  RKH_STATE_CAST(&s2211), RKH_STATE_CAST(0)
309  };
310  const RKH_ST_T *exitStates[] =
311  {
312  RKH_STATE_CAST(&s0), RKH_STATE_CAST(0)
313  };
314 
315  smTest_xS0_Expect(RKH_CAST(SmTest, smTest));
316  smTest_tr22_Expect(RKH_CAST(SmTest, smTest), &evD);
317  smTest_nS2_Expect(RKH_CAST(SmTest, smTest));
318  smTest_nS22_Expect(RKH_CAST(SmTest, smTest));
319  smTest_iS22_Expect(RKH_CAST(SmTest, smTest));
320  smTest_nS221_Expect(RKH_CAST(SmTest, smTest));
321  smTest_iS221_Expect(RKH_CAST(SmTest, smTest));
322  smTest_nS2211_Expect(RKH_CAST(SmTest, smTest));
323 
324  smTest_init_Expect(RKH_CAST(SmTest, smTest));
325  setProfile(smTest, RKH_STATE_CAST(&s0), RKH_STATE_CAST(&s0),
326  targetStates,
327  entryStates, exitStates, RKH_STATE_CAST(&s2211), 1,
328  TRN_NOT_INTERNAL, INIT_STATE_MACHINE);
329 
330  rkh_sm_dispatch((RKH_SM_T *)smTest, &evD);
331 
332  p = unitrazer_getLastOut();
333  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
334 }
335 
336 TEST(transition, simpleToCompositeFromLowToHighLevel)
337 {
338  UtrzProcessOut *p;
339  const RKH_ST_T *targetStates[] =
340  {
341  RKH_STATE_CAST(&s2), RKH_STATE_CAST(0)
342  };
343  const RKH_ST_T *entryStates[] =
344  {
345  RKH_STATE_CAST(&s21), RKH_STATE_CAST(0)
346  };
347  const RKH_ST_T *exitStates[] =
348  {
349  RKH_STATE_CAST(&s21), RKH_STATE_CAST(0)
350  };
351 
352  smTest_xS21_Expect(RKH_CAST(SmTest, smTest));
353  smTest_tr23_Expect(RKH_CAST(SmTest, smTest), &evC);
354  smTest_iS2_Expect(RKH_CAST(SmTest, smTest));
355  smTest_nS21_Expect(RKH_CAST(SmTest, smTest));
356 
357  smTest_init_Expect(RKH_CAST(SmTest, smTest));
358  setProfile(smTest, RKH_STATE_CAST(&s21), RKH_STATE_CAST(&s21),
359  targetStates,
360  entryStates, exitStates, RKH_STATE_CAST(&s21), 1,
361  TRN_NOT_INTERNAL, INIT_STATE_MACHINE);
362 
363  rkh_sm_dispatch((RKH_SM_T *)smTest, &evC);
364 
365  p = unitrazer_getLastOut();
366  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
367 }
368 
369 TEST(transition, compositeToSimpleAtEqualLevel)
370 {
371  UtrzProcessOut *p;
372  const RKH_ST_T *targetStates[] =
373  {
374  RKH_STATE_CAST(&s0), RKH_STATE_CAST(0)
375  };
376  const RKH_ST_T *entryStates[] =
377  {
378  RKH_STATE_CAST(&s0), RKH_STATE_CAST(0)
379  };
380  const RKH_ST_T *exitStates[] =
381  {
382  RKH_STATE_CAST(&s21), RKH_STATE_CAST(&s2), RKH_STATE_CAST(0)
383  };
384 
385  smTest_xS21_Expect(RKH_CAST(SmTest, smTest));
386  smTest_xS2_Expect(RKH_CAST(SmTest, smTest));
387  smTest_tr31_Expect(RKH_CAST(SmTest, smTest), &evA);
388  smTest_nS0_Expect(RKH_CAST(SmTest, smTest));
389 
390  smTest_init_Expect(RKH_CAST(SmTest, smTest));
391  setProfile(smTest, RKH_STATE_CAST(&s21), RKH_STATE_CAST(&s2),
392  targetStates,
393  entryStates, exitStates, RKH_STATE_CAST(&s0), 1,
394  TRN_NOT_INTERNAL, INIT_STATE_MACHINE);
395 
396  rkh_sm_dispatch((RKH_SM_T *)smTest, &evA);
397 
398  p = unitrazer_getLastOut();
399  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
400 }
401 
402 TEST(transition, compositeToSimpleFromHighToLowLevel)
403 {
404  UtrzProcessOut *p;
405  const RKH_ST_T *targetStates[] =
406  {
407  RKH_STATE_CAST(&s21), RKH_STATE_CAST(0)
408  };
409  const RKH_ST_T *entryStates[] =
410  {
411  RKH_STATE_CAST(&s21), RKH_STATE_CAST(0)
412  };
413  const RKH_ST_T *exitStates[] =
414  {
415  RKH_STATE_CAST(&s21), RKH_STATE_CAST(0)
416  };
417 
418  smTest_xS21_Expect(RKH_CAST(SmTest, smTest));
419  smTest_tr32_Expect(RKH_CAST(SmTest, smTest), &evD);
420  smTest_nS21_Expect(RKH_CAST(SmTest, smTest));
421 
422  smTest_init_Expect(RKH_CAST(SmTest, smTest));
423  setProfile(smTest, RKH_STATE_CAST(&s21), RKH_STATE_CAST(&s2),
424  targetStates,
425  entryStates, exitStates, RKH_STATE_CAST(&s21), 1,
426  TRN_NOT_INTERNAL, INIT_STATE_MACHINE);
427 
428  rkh_sm_dispatch((RKH_SM_T *)smTest, &evD);
429 
430  p = unitrazer_getLastOut();
431  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
432 }
433 
434 TEST(transition, loopSimpleStateOnTop)
435 {
436  UtrzProcessOut *p;
437  const RKH_ST_T *targetStates[] =
438  {
439  RKH_STATE_CAST(&s1), RKH_STATE_CAST(0)
440  };
441  const RKH_ST_T *entryStates[] =
442  {
443  RKH_STATE_CAST(&s1), RKH_STATE_CAST(0)
444  };
445  const RKH_ST_T *exitStates[] =
446  {
447  RKH_STATE_CAST(&s1), RKH_STATE_CAST(0)
448  };
449 
450  smTest_xS1_Expect(RKH_CAST(SmTest, smTest));
451  smTest_tr53_Expect(RKH_CAST(SmTest, smTest), &evA);
452  smTest_nS1_Expect(RKH_CAST(SmTest, smTest));
453 
454  smTest_init_Expect(RKH_CAST(SmTest, smTest));
455  setProfile(smTest, RKH_STATE_CAST(&s1), RKH_STATE_CAST(&s1),
456  targetStates,
457  entryStates, exitStates, RKH_STATE_CAST(&s1), 1,
458  TRN_NOT_INTERNAL, INIT_STATE_MACHINE);
459 
460  rkh_sm_dispatch((RKH_SM_T *)smTest, &evA);
461 
462  p = unitrazer_getLastOut();
463  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
464 }
465 
466 TEST(transition, loopNestedSimpleState)
467 {
468  UtrzProcessOut *p;
469  const RKH_ST_T *targetStates[] =
470  {
471  RKH_STATE_CAST(&s31), RKH_STATE_CAST(0)
472  };
473  const RKH_ST_T *entryStates[] =
474  {
475  RKH_STATE_CAST(&s31), RKH_STATE_CAST(0)
476  };
477  const RKH_ST_T *exitStates[] =
478  {
479  RKH_STATE_CAST(&s31), RKH_STATE_CAST(0)
480  };
481 
482  smTest_xS31_Expect(RKH_CAST(SmTest, smTest));
483  smTest_tr52_Expect(RKH_CAST(SmTest, smTest), &evD);
484  smTest_nS31_Expect(RKH_CAST(SmTest, smTest));
485 
486  smTest_init_Expect(RKH_CAST(SmTest, smTest));
487  setProfile(smTest, RKH_STATE_CAST(&s31), RKH_STATE_CAST(&s31),
488  targetStates, entryStates, exitStates,
489  RKH_STATE_CAST(&s31), 1, TRN_NOT_INTERNAL, INIT_STATE_MACHINE);
490 
491  rkh_sm_dispatch((RKH_SM_T *)smTest, &evD);
492 
493  p = unitrazer_getLastOut();
494  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
495 }
496 
497 TEST(transition, loopCompositeStateOnTop)
498 {
499  UtrzProcessOut *p;
500  const RKH_ST_T *targetStates[] =
501  {
502  RKH_STATE_CAST(&s3), RKH_STATE_CAST(0)
503  };
504  const RKH_ST_T *entryStates[] =
505  {
506  RKH_STATE_CAST(&s31), RKH_STATE_CAST(0)
507  };
508  const RKH_ST_T *exitStates[] =
509  {
510  RKH_STATE_CAST(&s31), RKH_STATE_CAST(0)
511  };
512 
513  smTest_xS31_Expect(RKH_CAST(SmTest, smTest));
514  smTest_tr51_Expect(RKH_CAST(SmTest, smTest), &evA);
515  smTest_iS3_Expect(RKH_CAST(SmTest, smTest));
516  smTest_nS31_Expect(RKH_CAST(SmTest, smTest));
517 
518  smTest_init_Expect(RKH_CAST(SmTest, smTest));
519  setProfile(smTest, RKH_STATE_CAST(&s31), RKH_STATE_CAST(&s3),
520  targetStates, entryStates, exitStates,
521  RKH_STATE_CAST(&s31), 1, TRN_NOT_INTERNAL, INIT_STATE_MACHINE);
522 
523  rkh_sm_dispatch((RKH_SM_T *)smTest, &evA);
524 
525  p = unitrazer_getLastOut();
526  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
527 }
528 
529 TEST(transition, loopNestedCompositeState)
530 {
531  UtrzProcessOut *p;
532  const RKH_ST_T *targetStates[] =
533  {
534  RKH_STATE_CAST(&s22), RKH_STATE_CAST(0)
535  };
536  const RKH_ST_T *entryStates[] =
537  {
538  RKH_STATE_CAST(&s221), RKH_STATE_CAST(&s2211), RKH_STATE_CAST(0)
539  };
540  const RKH_ST_T *exitStates[] =
541  {
542  RKH_STATE_CAST(&s2211), RKH_STATE_CAST(&s221), RKH_STATE_CAST(0)
543  };
544 
545  smTest_xS221_Expect(RKH_CAST(SmTest, smTest));
546  smTest_tr54_Expect(RKH_CAST(SmTest, smTest), &evD);
547  smTest_iS22_Expect(RKH_CAST(SmTest, smTest));
548  smTest_nS221_Expect(RKH_CAST(SmTest, smTest));
549  smTest_iS221_Expect(RKH_CAST(SmTest, smTest));
550  smTest_nS2211_Expect(RKH_CAST(SmTest, smTest));
551 
552  smTest_init_Expect(RKH_CAST(SmTest, smTest));
553  setProfile(smTest, RKH_STATE_CAST(&s2211), RKH_STATE_CAST(&s22),
554  targetStates, entryStates, exitStates,
555  RKH_STATE_CAST(&s2211), 1, TRN_NOT_INTERNAL,
556  INIT_STATE_MACHINE);
557 
558  rkh_sm_dispatch((RKH_SM_T *)smTest, &evD);
559 
560  p = unitrazer_getLastOut();
561  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
562 }
563 
564 TEST(transition, compositeToSimpleFromLowToHighLevel)
565 {
566  UtrzProcessOut *p;
567  const RKH_ST_T *targetStates[] =
568  {
569  RKH_STATE_CAST(&s0), RKH_STATE_CAST(0)
570  };
571  const RKH_ST_T *entryStates[] =
572  {
573  RKH_STATE_CAST(&s0), RKH_STATE_CAST(0)
574  };
575  const RKH_ST_T *exitStates[] =
576  {
577  RKH_STATE_CAST(&s221), RKH_STATE_CAST(&s22), RKH_STATE_CAST(&s2),
578  RKH_STATE_CAST(0)
579  };
580 
581  smTest_xS221_Expect(RKH_CAST(SmTest, smTest));
582  smTest_xS22_Expect(RKH_CAST(SmTest, smTest));
583  smTest_xS2_Expect(RKH_CAST(SmTest, smTest));
584  smTest_tr33_Expect(RKH_CAST(SmTest, smTest), &evB);
585  smTest_nS0_Expect(RKH_CAST(SmTest, smTest));
586 
587  smTest_init_Expect(RKH_CAST(SmTest, smTest));
588  setProfile(smTest, RKH_STATE_CAST(&s221), RKH_STATE_CAST(&s22),
589  targetStates, entryStates, exitStates,
590  RKH_STATE_CAST(&s0), 1, TRN_NOT_INTERNAL, INIT_STATE_MACHINE);
591 
592  rkh_sm_dispatch((RKH_SM_T *)smTest, &evB);
593 
594  p = unitrazer_getLastOut();
595  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
596 }
597 
598 TEST(transition, compositeToCompositeAtEqualLevel)
599 {
600  UtrzProcessOut *p;
601  const RKH_ST_T *targetStates[] =
602  {
603  RKH_STATE_CAST(&s2), RKH_STATE_CAST(0)
604  };
605  const RKH_ST_T *entryStates[] =
606  {
607  RKH_STATE_CAST(&s2), RKH_STATE_CAST(&s21), RKH_STATE_CAST(0)
608  };
609  const RKH_ST_T *exitStates[] =
610  {
611  RKH_STATE_CAST(&s31), RKH_STATE_CAST(&s3), RKH_STATE_CAST(0)
612  };
613 
614  smTest_xS31_Expect(RKH_CAST(SmTest, smTest));
615  smTest_xS3_Expect(RKH_CAST(SmTest, smTest));
616  smTest_tr41_Expect(RKH_CAST(SmTest, smTest), &evB);
617  smTest_nS2_Expect(RKH_CAST(SmTest, smTest));
618  smTest_iS2_Expect(RKH_CAST(SmTest, smTest));
619  smTest_nS21_Expect(RKH_CAST(SmTest, smTest));
620 
621  smTest_init_Expect(RKH_CAST(SmTest, smTest));
622  setProfile(smTest, RKH_STATE_CAST(&s31), RKH_STATE_CAST(&s3),
623  targetStates, entryStates, exitStates,
624  RKH_STATE_CAST(&s21), 1, TRN_NOT_INTERNAL, INIT_STATE_MACHINE);
625 
626  rkh_sm_dispatch((RKH_SM_T *)smTest, &evB);
627 
628  p = unitrazer_getLastOut();
629  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
630 }
631 
632 TEST(transition, compositeToCompositeFromHighToLowLevel)
633 {
634  UtrzProcessOut *p;
635  const RKH_ST_T *targetStates[] =
636  {
637  RKH_STATE_CAST(&s22), RKH_STATE_CAST(0)
638  };
639  const RKH_ST_T *entryStates[] =
640  {
641  RKH_STATE_CAST(&s2), RKH_STATE_CAST(&s22), RKH_STATE_CAST(&s221),
642  RKH_STATE_CAST(&s2211), RKH_STATE_CAST(0)
643  };
644  const RKH_ST_T *exitStates[] =
645  {
646  RKH_STATE_CAST(&s31), RKH_STATE_CAST(&s3), RKH_STATE_CAST(0)
647  };
648 
649  smTest_xS31_Expect(RKH_CAST(SmTest, smTest));
650  smTest_xS3_Expect(RKH_CAST(SmTest, smTest));
651  smTest_tr42_Expect(RKH_CAST(SmTest, smTest), &evC);
652  smTest_nS2_Expect(RKH_CAST(SmTest, smTest));
653  smTest_nS22_Expect(RKH_CAST(SmTest, smTest));
654  smTest_iS22_Expect(RKH_CAST(SmTest, smTest));
655  smTest_nS221_Expect(RKH_CAST(SmTest, smTest));
656  smTest_iS221_Expect(RKH_CAST(SmTest, smTest));
657  smTest_nS2211_Expect(RKH_CAST(SmTest, smTest));
658 
659  smTest_init_Expect(RKH_CAST(SmTest, smTest));
660  setProfile(smTest, RKH_STATE_CAST(&s31), RKH_STATE_CAST(&s3),
661  targetStates, entryStates, exitStates,
662  RKH_STATE_CAST(&s2211), 1, TRN_NOT_INTERNAL, INIT_STATE_MACHINE);
663 
664  rkh_sm_dispatch((RKH_SM_T *)smTest, &evC);
665 
666  p = unitrazer_getLastOut();
667  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
668 }
669 
670 TEST(transition, compositeToCompositeFromLowToHighLevel)
671 {
672  UtrzProcessOut *p;
673  const RKH_ST_T *targetStates[] =
674  {
675  RKH_STATE_CAST(&s3), RKH_STATE_CAST(0)
676  };
677  const RKH_ST_T *entryStates[] =
678  {
679  RKH_STATE_CAST(&s3), RKH_STATE_CAST(&s31), RKH_STATE_CAST(0)
680  };
681  const RKH_ST_T *exitStates[] =
682  {
683  RKH_STATE_CAST(&s221), RKH_STATE_CAST(&s22), RKH_STATE_CAST(&s2),
684  RKH_STATE_CAST(0)
685  };
686 
687  smTest_xS221_Expect(RKH_CAST(SmTest, smTest));
688  smTest_xS22_Expect(RKH_CAST(SmTest, smTest));
689  smTest_xS2_Expect(RKH_CAST(SmTest, smTest));
690  smTest_tr43_Expect(RKH_CAST(SmTest, smTest), &evC);
691  smTest_nS3_Expect(RKH_CAST(SmTest, smTest));
692  smTest_iS3_Expect(RKH_CAST(SmTest, smTest));
693  smTest_nS31_Expect(RKH_CAST(SmTest, smTest));
694 
695  smTest_init_Expect(RKH_CAST(SmTest, smTest));
696  setProfile(smTest, RKH_STATE_CAST(&s221), RKH_STATE_CAST(&s22),
697  targetStates, entryStates, exitStates,
698  RKH_STATE_CAST(&s31), 1, TRN_NOT_INTERNAL, INIT_STATE_MACHINE);
699 
700  rkh_sm_dispatch((RKH_SM_T *)smTest, &evC);
701 
702  p = unitrazer_getLastOut();
703  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
704 }
705 
706 TEST(transition, internalInSimpleState)
707 {
708  UtrzProcessOut *p;
709  const RKH_ST_T *targetStates[] =
710  {
711  RKH_STATE_CAST(&s1), RKH_STATE_CAST(0)
712  };
713  const RKH_ST_T *entryStates[] =
714  {
715  RKH_STATE_CAST(0)
716  };
717  const RKH_ST_T *exitStates[] =
718  {
719  RKH_STATE_CAST(0)
720  };
721 
722  smTest_tr14_Expect(RKH_CAST(SmTest, smTest), &evB);
723 
724  smTest_init_Expect(RKH_CAST(SmTest, smTest));
725  setProfile(smTest, RKH_STATE_CAST(&s1), RKH_STATE_CAST(&s1),
726  targetStates, entryStates, exitStates,
727  RKH_STATE_CAST(&s1), 1, TRN_INTERNAL, INIT_STATE_MACHINE);
728 
729  rkh_sm_dispatch((RKH_SM_T *)smTest, &evB);
730 
731  p = unitrazer_getLastOut();
732  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
733 }
734 
735 TEST(transition, internalInCompositeState)
736 {
737  UtrzProcessOut *p;
738  const RKH_ST_T *targetStates[] =
739  {
740  RKH_STATE_CAST(&s3), RKH_STATE_CAST(0)
741  };
742  const RKH_ST_T *entryStates[] =
743  {
744  RKH_STATE_CAST(0)
745  };
746  const RKH_ST_T *exitStates[] =
747  {
748  RKH_STATE_CAST(0)
749  };
750 
751  smTest_init_Expect(RKH_CAST(SmTest, smTest));
752  smTest_tr15_Expect(RKH_CAST(SmTest, smTest), &evE);
753 
754  setProfile(smTest, RKH_STATE_CAST(&s31), RKH_STATE_CAST(&s3),
755  targetStates, entryStates, exitStates,
756  RKH_STATE_CAST(&s31), 1, TRN_INTERNAL, INIT_STATE_MACHINE);
757 
758  rkh_sm_dispatch((RKH_SM_T *)smTest, &evE);
759 
760  p = unitrazer_getLastOut();
761  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
762 }
763 
764 TEST(transition, fails_EventNotFound)
765 {
766  UtrzProcessOut *p;
767 
768  smTest_init_Expect(RKH_CAST(SmTest, smTest));
769 
770  sm_init_expect(RKH_STATE_CAST(&waiting));
771  sm_enstate_expect(RKH_STATE_CAST(&waiting));
772  sm_evtNotFound_expect(D);
773 
774  rkh_sm_init((RKH_SM_T *)smTest);
775  setStateForcesfully(smTest, RKH_STATE_CAST(&s1));
776  rkh_sm_dispatch((RKH_SM_T *)smTest, &evD);
777 
778  p = unitrazer_getLastOut();
779  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
780 }
781 
782 TEST(transition, fails_GuardFalse)
783 {
784  UtrzProcessOut *p;
785 
786  sm_init_expect(RKH_STATE_CAST(&waiting));
787  sm_enstate_expect(RKH_STATE_CAST(&waiting));
788  sm_grdFalse_expect();
789  sm_evtNotFound_expect(C);
790 
791  smTest_init_Expect(RKH_CAST(SmTest, smTest));
792  smTest_falseGuard_ExpectAndReturn(RKH_CAST(SmTest, smTest), &evC,
793  RKH_FALSE);
794 
795  rkh_sm_init((RKH_SM_T *)smTest);
796  setStateForcesfully(smTest, RKH_STATE_CAST(&s1));
797  rkh_sm_dispatch((RKH_SM_T *)smTest, &evC);
798 
799  p = unitrazer_getLastOut();
800  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
801 }
802 
803 TEST(transition, fails_ExceededHierarchicalLevel)
804 {
805  UtrzProcessOut *p;
806 
807  sm_init_expect(RKH_STATE_CAST(&waiting));
808  sm_enstate_expect(RKH_STATE_CAST(&waiting));
809  sm_trn_expect(RKH_STATE_CAST(&s0), RKH_STATE_CAST(&s22211));
810  sm_tsState_expect(RKH_STATE_CAST(&s22211));
811  sm_exHLevel_expect();
812 
813  smTest_init_Expect(RKH_CAST(SmTest, smTest));
814 
815  rkh_sm_init((RKH_SM_T *)smTest);
816  setStateForcesfully(smTest, RKH_STATE_CAST(&s0));
817  rkh_sm_dispatch((RKH_SM_T *)smTest, &evE);
818 
819  p = unitrazer_getLastOut();
820  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
821 }
822 
823 TEST(transition, multipleEnabledTrn_FiringFirstTrueGuard)
824 {
825  UtrzProcessOut *p;
826 
827  smTest_init_Expect(RKH_CAST(SmTest, smTest));
828  smTest_guard4a_ExpectAndReturn(RKH_CAST(SmTest, smTest), &evA, RKH_FALSE);
829  smTest_guard4b_ExpectAndReturn(RKH_CAST(SmTest, smTest), &evA, RKH_TRUE);
830 
831  sm_init_ignore();
832  sm_enstate_ignore();
833  sm_ntrnact_ignore();
834  sm_trn_ignore();
835  sm_evtProc_ignore();
836  sm_grdFalse_expect();
837 
838  rkh_sm_init((RKH_SM_T *)smTest);
839  setStateForcesfully(smTest, RKH_STATE_CAST(&s4));
840  rkh_sm_dispatch((RKH_SM_T *)smTest, &evA);
841 
842  p = unitrazer_getLastOut();
843  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
844 }
845 
846 TEST(transition, multipleEnabledTrn_FiringFirstEmptyGuard)
847 {
848  UtrzProcessOut *p;
849 
850  smTest_init_Expect(RKH_CAST(SmTest, smTest));
851  smTest_guard4a_ExpectAndReturn(RKH_CAST(SmTest, smTest), &evB, RKH_FALSE);
852  smTest_guard4b_ExpectAndReturn(RKH_CAST(SmTest, smTest), &evB, RKH_FALSE);
853 
854  sm_init_ignore();
855  sm_enstate_ignore();
856  sm_exstate_ignore();
857  sm_ntrnact_ignore();
858  sm_evtProc_ignore();
859  sm_grdFalse_expect();
860  sm_grdFalse_expect();
861  sm_trn_ignore();
862  sm_nenex_ignore();
863  sm_state_ignore();
864  sm_tsState_expect(RKH_STATE_CAST(&s4));
865 
866  rkh_sm_init((RKH_SM_T *)smTest);
867  setStateForcesfully(smTest, RKH_STATE_CAST(&s4));
868  rkh_sm_dispatch((RKH_SM_T *)smTest, &evB);
869 
870  p = unitrazer_getLastOut();
871  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
872 }
873 
874 TEST(transition, defaultTrnWithAssociatedEffect)
875 {
876  UtrzProcessOut *p;
877  const RKH_ST_T *targetStates[] =
878  {
879  RKH_STATE_CAST(&s3), RKH_STATE_CAST(0)
880  };
881  const RKH_ST_T *entryStates[] =
882  {
883  RKH_STATE_CAST(&s3), RKH_STATE_CAST(&s31), RKH_STATE_CAST(0)
884  };
885  const RKH_ST_T *exitStates[] =
886  {
887  RKH_STATE_CAST(&s0), RKH_STATE_CAST(0)
888  };
889 
890  smTest_init_Expect(RKH_CAST(SmTest, smTest));
891  smTest_xS0_Expect(RKH_CAST(SmTest, smTest));
892  smTest_tr55_Expect(RKH_CAST(SmTest, smTest), &evF);
893  smTest_nS3_Expect(RKH_CAST(SmTest, smTest));
894  smTest_iS3_Expect(RKH_CAST(SmTest, smTest));
895  smTest_nS31_Expect(RKH_CAST(SmTest, smTest));
896 
897  setProfile(smTest, RKH_STATE_CAST(&s0), RKH_STATE_CAST(&s0),
898  targetStates, entryStates, exitStates,
899  RKH_STATE_CAST(&s31), 1, TRN_NOT_INTERNAL, INIT_STATE_MACHINE);
900 
901  rkh_sm_dispatch((RKH_SM_T *)smTest, &evF);
902 
903  p = unitrazer_getLastOut();
904  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
905 }
906 
907 TEST(transition, generatedCompletionEventBySimpleState)
908 {
909  UtrzProcessOut *p;
910  RKH_ST_T *targetStates[] =
911  {
912  RKH_STATE_CAST(&s5), RKH_STATE_CAST(0)
913  };
914  RKH_ST_T *entryStates[] =
915  {
916  RKH_STATE_CAST(&s5), RKH_STATE_CAST(0)
917  };
918  RKH_ST_T *exitStates[] =
919  {
920  RKH_STATE_CAST(&s21), RKH_STATE_CAST(&s2), RKH_STATE_CAST(0)
921  };
922 
923  /* Expectations for transition to s5 */
924  smTest_init_Expect(RKH_CAST(SmTest, smTest));
925  smTest_xS21_Expect(RKH_CAST(SmTest, smTest));
926  smTest_xS2_Expect(RKH_CAST(SmTest, smTest));
927  smTest_nS5_Expect(RKH_CAST(SmTest, smTest));
928 
929  setProfile(smTest, RKH_STATE_CAST(&s21), RKH_STATE_CAST(&s2),
930  targetStates, entryStates, exitStates,
931  RKH_STATE_CAST(&s5), 0, TRN_NOT_INTERNAL, INIT_STATE_MACHINE);
932 
933  /* Expectations for completion transition */
934  targetStates[0] = RKH_STATE_CAST(&s4);
935  targetStates[1] = RKH_STATE_CAST(0);
936  entryStates[0] = RKH_STATE_CAST(&s4);
937  entryStates[1] = RKH_STATE_CAST(0);
938  exitStates[0] = RKH_STATE_CAST(&s5);
939  exitStates[1] = RKH_STATE_CAST(0);
940 
941  smTest_xS5_Expect(RKH_CAST(SmTest, smTest));
942  smTest_tr61_Expect(RKH_CAST(SmTest, smTest), &evCompletion);
943 
944  setProfile(smTest, NULL, RKH_STATE_CAST(&s5),
945  targetStates, entryStates, exitStates,
946  RKH_STATE_CAST(&s4), 1, TRN_NOT_INTERNAL,
947  NO_INIT_STATE_MACHINE);
948 
949  /* Exercices */
950  rkh_sm_dispatch((RKH_SM_T *)smTest, &evE);
951 
952  p = unitrazer_getLastOut();
953  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
954 }
955 
956 TEST(transition, generatedCompletionEventByFinalState)
957 {
958  UtrzProcessOut *p;
959  RKH_ST_T *targetStates[] =
960  {
961  RKH_STATE_CAST(&s2Final), RKH_STATE_CAST(0)
962  };
963  RKH_ST_T *entryStates[] =
964  {
965  RKH_STATE_CAST(&s2Final), RKH_STATE_CAST(0)
966  };
967  RKH_ST_T *exitStates[] =
968  {
969  RKH_STATE_CAST(&s21), RKH_STATE_CAST(0), RKH_STATE_CAST(0)
970  };
971 
972  /* Expectations for transition to S2's FinalState */
973  smTest_init_Expect(RKH_CAST(SmTest, smTest));
974  smTest_xS21_Expect(RKH_CAST(SmTest, smTest));
975 
976  setProfile(smTest, RKH_STATE_CAST(&s21), RKH_STATE_CAST(&s21),
977  targetStates, entryStates, exitStates,
978  RKH_STATE_CAST(&s2Final), 0, TRN_NOT_INTERNAL,
979  INIT_STATE_MACHINE);
980 
981  /* Expectations for completion transition */
982  targetStates[0] = RKH_STATE_CAST(&s4);
983  targetStates[1] = RKH_STATE_CAST(0);
984  entryStates[0] = RKH_STATE_CAST(&s4);
985  entryStates[1] = RKH_STATE_CAST(0);
986  exitStates[0] = RKH_STATE_CAST(&s2Final);
987  exitStates[1] = RKH_STATE_CAST(&s2);
988  exitStates[2] = RKH_STATE_CAST(0);
989 
990  smTest_xS2_Expect(RKH_CAST(SmTest, smTest));
991  smTest_guardS2_ExpectAndReturn(RKH_CAST(SmTest, smTest), &evCompletion,
992  RKH_TRUE);
993  smTest_tr60_Expect(RKH_CAST(SmTest, smTest), &evCompletion);
994 
995  setProfile(smTest, NULL, RKH_STATE_CAST(&s2),
996  targetStates, entryStates, exitStates,
997  RKH_STATE_CAST(&s4), 1, TRN_NOT_INTERNAL,
998  NO_INIT_STATE_MACHINE);
999 
1000  /* Exercices */
1001  rkh_sm_dispatch((RKH_SM_T *)smTest, &evF);
1002 
1003  p = unitrazer_getLastOut();
1004  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
1005 }
1006 
1007 TEST(transition, syncDispatchingToStateMachine)
1008 {
1009  TEST_IGNORE();
1010 }
1011 
1016 /* ------------------------------ End of file ------------------------------ */
#define RKH_COMPLETION_EVENT
This macro is used to indicate the completion event.
Definition: rkhitl.h:153
#define RKH_FILTER_OFF_GROUP_ALL_EVENTS(grp)
Emit (enable) all events in a specific group.
Definition: rkhtrc.h:179
#define sm_cleanup()
Return the system under test to its initial state after the test.
Definition: unitrazer.h:79
Describes the SMA (active object in UML).
Definition: rkhitl.h:2930
#define RKH_TR_FWK_AO(actObj_)
Entry symbol table for active object.
Definition: rkhtrc.h:2653
Interface of unit test with Trazer application.
#define RKH_FALSE
Standard define.
Definition: rkhdef.h:255
State Machine group (SM)
Definition: rkhtrc.h:3103
Assertion expression was evaluated to false.
Definition: rkhtrc.h:3389
Describes the state machine.
Definition: rkhitl.h:2806
void rkh_sm_init(RKH_SM_T *me)
Inits a previously created state machine calling its initializing action.
#define sm_init()
Establish the preconditions to the tests.
Definition: unitrazer.h:73
#define RKH_TR_FWK_STATE(actObj_, stateObj_)
Entry symbol table for state object.
Definition: rkhtrc.h:2689
#define sm_verify()
Makes sure there are no unused expectations, if there are, this function causes the test to fail...
Definition: unitrazer.h:86
ruint rkh_sm_dispatch(RKH_SM_T *me, RKH_EVT_T *e)
Executes a state machine in a run-to-completation (RTC) model.
Describes the common properties of regular states (basic, composite, and submachine).
Definition: rkhitl.h:3333
#define RKH_TRUE
Standard define.
Definition: rkhdef.h:256
RKH framwwork platform - independent interface.
#define RKH_TR_FWK_SIG(stateObj_)
Entry symbol table for event signal.
Definition: rkhtrc.h:2354
#define RKH_CAST(_type, _obj)
Perform downcast of a reference of a base class to one of its derived classes.
Definition: rkh.h:2639
#define RKH_STATIC_EVENT(ev_obj, ev_sig)
This macro declares and initializes the event structure ev_ob with ev_sig signal number and establish...
Definition: rkh.h:2480
#define RKH_FILTER_OFF_EVENT(evt)
Emit (enable) one trace event. Use the RKH_TRC_ALL_EVENTS to enable all trace events.
Definition: rkhtrc.h:158
#define RKH_FILTER_OFF_ALL_SIGNALS()
Emmit all enabled trace events related to specified event signal.
Definition: rkhtrc.h:267
#define RKH_FILTER_OFF_SMA(sma)
Emmit the enabled trace events related to a specified active object.
Definition: rkhtrc.h:211