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