RKH
test_smPseudostate.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 "rkhfwk_dynevt.h"
60 #include "common.h"
61 #include "smPseudoTest.h"
62 #include "smPseudoTestAct.h"
63 
64 /* ----------------------------- Local macros ------------------------------ */
65 /* ------------------------------- Constants ------------------------------- */
66 static RKH_STATIC_EVENT(evA, A);
67 static RKH_STATIC_EVENT(evB, B);
68 static RKH_STATIC_EVENT(evC, C);
69 static RKH_STATIC_EVENT(evD, D);
70 static RKH_STATIC_EVENT(evE, E);
71 static RKH_STATIC_EVENT(evF, F);
72 static RKH_STATIC_EVENT(evG, G);
73 static RKH_STATIC_EVENT(evH, H);
74 static RKH_STATIC_EVENT(evI, I);
75 static RKH_STATIC_EVENT(evTerminate, TERMINATE);
76 
77 /* ---------------------------- Local data types --------------------------- */
78 /* ---------------------------- Global variables --------------------------- */
79 TEST_GROUP(pseudostate);
80 
81 /* ---------------------------- Local variables ---------------------------- */
82 /* ----------------------- Local function prototypes ----------------------- */
83 /* ---------------------------- Local functions ---------------------------- */
84 static
85 void
86 loadStateMachineSymbols(void)
87 {
88  RKH_TR_FWK_AO(smPseudoTest);
89  RKH_TR_FWK_STATE(smPseudoTest, &smPT_waiting);
90  RKH_TR_FWK_STATE(smPseudoTest, &smPT_s0);
91  RKH_TR_FWK_STATE(smPseudoTest, &smPT_s1);
92  RKH_TR_FWK_STATE(smPseudoTest, &smPT_s11);
93  RKH_TR_FWK_STATE(smPseudoTest, &smPT_s12);
94  RKH_TR_FWK_STATE(smPseudoTest, &smPT_s1Hist);
95  RKH_TR_FWK_STATE(smPseudoTest, &smPT_s121);
96  RKH_TR_FWK_STATE(smPseudoTest, &smPT_s122);
97  RKH_TR_FWK_STATE(smPseudoTest, &smPT_s12Hist);
98  RKH_TR_FWK_STATE(smPseudoTest, &smPT_s2);
99  RKH_TR_FWK_STATE(smPseudoTest, &smPT_s21);
100  RKH_TR_FWK_STATE(smPseudoTest, &smPT_s22);
101  RKH_TR_FWK_STATE(smPseudoTest, &smPT_s2Hist);
102  RKH_TR_FWK_SIG(A);
103  RKH_TR_FWK_SIG(B);
104  RKH_TR_FWK_SIG(C);
105  RKH_TR_FWK_SIG(D);
106  RKH_TR_FWK_SIG(E);
107 }
108 
109 static
110 void
111 setRKHTraceFilters(void)
112 {
115  RKH_FILTER_OFF_SMA(smPseudoTest);
117 }
118 
119 /* ---------------------------- Global functions --------------------------- */
120 TEST_SETUP(pseudostate)
121 {
122  sm_init();
123  rkh_sm_clear_history(&smPT_s1Hist);
124  rkh_sm_clear_history(&smPT_s12Hist);
125  rkh_sm_clear_history(&smPT_s2Hist);
126 
127  loadStateMachineSymbols();
128  setRKHTraceFilters();
129 }
130 
131 TEST_TEAR_DOWN(pseudostate)
132 {
133  sm_verify(); /* Makes sure there are no unused expectations, if */
134  /* there are, this function causes the test to fail. */
135  sm_cleanup();
136 }
137 
145 TEST(pseudostate, firstStateAfterInit)
146 {
147  UtrzProcessOut *p;
148 
149  sm_init_expect(RKH_STATE_CAST(&smPT_waiting));
150  sm_enstate_expect(RKH_STATE_CAST(&smPT_waiting));
151 
152  rkh_sm_init((RKH_SM_T *)smPseudoTest);
153 
154  p = unitrazer_getLastOut();
155  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
156 }
157 
158 TEST(pseudostate, trnToEmptyShallowHistoryWithoutDefaultTrn)
159 {
160  UtrzProcessOut *p;
161  const RKH_ST_T *targetStates[] =
162  {
163  RKH_STATE_CAST(&smPT_s1Hist), RKH_STATE_CAST(&smPT_s1),
164  RKH_STATE_CAST(0)
165  };
166  const RKH_ST_T *exitStates[] =
167  {
168  RKH_STATE_CAST(&smPT_s0), RKH_STATE_CAST(0)
169  };
170  const RKH_ST_T *entryStates[] =
171  {
172  RKH_STATE_CAST(&smPT_s1), RKH_STATE_CAST(&smPT_s11), RKH_STATE_CAST(0)
173  };
174 
175  setProfile(smPseudoTest, RKH_STATE_CAST(&smPT_s0),
176  RKH_STATE_CAST(&smPT_s0), targetStates,
177  entryStates, exitStates,
178  RKH_STATE_CAST(&smPT_s11), 0, TRN_NOT_INTERNAL, 1, &evB,
179  RKH_STATE_CAST(&smPT_s0));
180 
181  rkh_sm_dispatch((RKH_SM_T *)smPseudoTest, &evB);
182 
183  p = unitrazer_getLastOut();
184  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
185 }
186 
187 TEST(pseudostate, trnToLoadedShallowHistoryWithoutDefaultTrn)
188 {
189  UtrzProcessOut *p;
190  const RKH_ST_T *targetStates[] =
191  {
192  RKH_STATE_CAST(&smPT_s1Hist), RKH_STATE_CAST(&smPT_s12),
193  RKH_STATE_CAST(0)
194  };
195  const RKH_ST_T *exitStates[] =
196  {
197  RKH_STATE_CAST(&smPT_s0), RKH_STATE_CAST(0)
198  };
199  const RKH_ST_T *entryStates[] =
200  {
201  RKH_STATE_CAST(&smPT_s1), RKH_STATE_CAST(&smPT_s12),
202  RKH_STATE_CAST(&smPT_s121), RKH_STATE_CAST(0)
203  };
204 
205  setProfile(smPseudoTest, RKH_STATE_CAST(&smPT_s0),
206  RKH_STATE_CAST(&smPT_s0), targetStates,
207  entryStates, exitStates,
208  RKH_STATE_CAST(&smPT_s121), 0, TRN_NOT_INTERNAL, 1, &evB,
209  RKH_STATE_CAST(&smPT_s0));
210 
211  setHistory(&smPT_s1Hist, RKH_STATE_CAST(&smPT_s12));
212  rkh_sm_dispatch((RKH_SM_T *)smPseudoTest, &evB);
213 
214  p = unitrazer_getLastOut();
215  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
216 }
217 
218 TEST(pseudostate, exitFromCompositeWithLoadedShallowHistory)
219 {
220  UtrzProcessOut *p;
221  const RKH_ST_T *state;
222  const RKH_ST_T *targetStates[] =
223  {
224  RKH_STATE_CAST(&smPT_s0), RKH_STATE_CAST(0)
225  };
226  const RKH_ST_T *exitStates[] =
227  {
228  RKH_STATE_CAST(&smPT_s121), RKH_STATE_CAST(&smPT_s12),
229  RKH_STATE_CAST(&smPT_s1), RKH_STATE_CAST(0)
230  };
231  const RKH_ST_T *entryStates[] =
232  {
233  RKH_STATE_CAST(&smPT_s0), RKH_STATE_CAST(0)
234  };
235 
236  setProfile(smPseudoTest, RKH_STATE_CAST(&smPT_s121),
237  RKH_STATE_CAST(&smPT_s1), targetStates,
238  entryStates, exitStates,
239  RKH_STATE_CAST(&smPT_s0), 0, TRN_NOT_INTERNAL, 1, &evA,
240  RKH_STATE_CAST(&smPT_s121));
241 
242  rkh_sm_dispatch((RKH_SM_T *)smPseudoTest, &evA);
243  state = getHistory(&smPT_s1Hist);
244  TEST_ASSERT_EQUAL_PTR(RKH_STATE_CAST(&smPT_s12), state);
245 
246  p = unitrazer_getLastOut();
247  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
248 }
249 
250 TEST(pseudostate, trnToEmptyDeepHistoryWithoutDefaultTrn)
251 {
252  UtrzProcessOut *p;
253  const RKH_ST_T *targetStates[] =
254  {
255  RKH_STATE_CAST(&smPT_s12Hist), RKH_STATE_CAST(&smPT_s12),
256  RKH_STATE_CAST(0)
257  };
258  const RKH_ST_T *exitStates[] =
259  {
260  RKH_STATE_CAST(&smPT_s0), RKH_STATE_CAST(0)
261  };
262  const RKH_ST_T *entryStates[] =
263  {
264  RKH_STATE_CAST(&smPT_s1), RKH_STATE_CAST(&smPT_s12),
265  RKH_STATE_CAST(&smPT_s121), RKH_STATE_CAST(0)
266  };
267 
268  setProfile(smPseudoTest, RKH_STATE_CAST(&smPT_s0),
269  RKH_STATE_CAST(&smPT_s0), targetStates,
270  entryStates, exitStates,
271  RKH_STATE_CAST(&smPT_s121), 0, TRN_NOT_INTERNAL, 1, &evC,
272  RKH_STATE_CAST(&smPT_s0));
273 
274  rkh_sm_dispatch((RKH_SM_T *)smPseudoTest, &evC);
275 
276  p = unitrazer_getLastOut();
277  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
278 }
279 
280 TEST(pseudostate, trnToLoadedDeepHistoryWithoutDefaultTrn)
281 {
282  UtrzProcessOut *p;
283  const RKH_ST_T *targetStates[] =
284  {
285  RKH_STATE_CAST(&smPT_s12Hist), RKH_STATE_CAST(&smPT_s122),
286  RKH_STATE_CAST(0)
287  };
288  const RKH_ST_T *exitStates[] =
289  {
290  RKH_STATE_CAST(&smPT_s0), RKH_STATE_CAST(0)
291  };
292  const RKH_ST_T *entryStates[] =
293  {
294  RKH_STATE_CAST(&smPT_s1), RKH_STATE_CAST(&smPT_s12),
295  RKH_STATE_CAST(&smPT_s122), RKH_STATE_CAST(0)
296  };
297 
298  setProfile(smPseudoTest, RKH_STATE_CAST(&smPT_s0),
299  RKH_STATE_CAST(&smPT_s0), targetStates,
300  entryStates, exitStates,
301  RKH_STATE_CAST(&smPT_s122), 0, TRN_NOT_INTERNAL, 1, &evC,
302  RKH_STATE_CAST(&smPT_s0));
303 
304  setHistory(&smPT_s12Hist, RKH_STATE_CAST(&smPT_s122));
305  rkh_sm_dispatch((RKH_SM_T *)smPseudoTest, &evC);
306 
307  p = unitrazer_getLastOut();
308  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
309 }
310 
311 TEST(pseudostate, exitFromCompositeWithLoadedDeepHistory)
312 {
313  UtrzProcessOut *p;
314  const RKH_ST_T *state;
315  const RKH_ST_T *targetStates[] =
316  {
317  RKH_STATE_CAST(&smPT_s122), RKH_STATE_CAST(0)
318  };
319  const RKH_ST_T *exitStates[] =
320  {
321  RKH_STATE_CAST(&smPT_s0), RKH_STATE_CAST(0)
322  };
323  const RKH_ST_T *entryStates[] =
324  {
325  RKH_STATE_CAST(&smPT_s1), RKH_STATE_CAST(&smPT_s12),
326  RKH_STATE_CAST(&smPT_s122), RKH_STATE_CAST(0)
327  };
328 
329  setProfile(smPseudoTest, RKH_STATE_CAST(&smPT_s0),
330  RKH_STATE_CAST(&smPT_s0), targetStates,
331  entryStates, exitStates,
332  RKH_STATE_CAST(&smPT_s122), 0, TRN_NOT_INTERNAL, 1, &evD,
333  RKH_STATE_CAST(&smPT_s0));
334 
335  rkh_sm_dispatch((RKH_SM_T *)smPseudoTest, &evD);
336  state = getHistory(&smPT_s12Hist);
337  TEST_ASSERT_EQUAL_PTR(RKH_STATE_CAST(&smPT_s122), state);
338 
339  p = unitrazer_getLastOut();
340  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
341 }
342 
343 TEST(pseudostate, trnToEmptyShallowHistoryWithDefaultTrn)
344 {
345  UtrzProcessOut *p;
346  const RKH_ST_T *targetStates[] =
347  {
348  RKH_STATE_CAST(&smPT_s2Hist), RKH_STATE_CAST(&smPT_s22),
349  RKH_STATE_CAST(0)
350  };
351  const RKH_ST_T *exitStates[] =
352  {
353  RKH_STATE_CAST(&smPT_s0), RKH_STATE_CAST(0)
354  };
355  const RKH_ST_T *entryStates[] =
356  {
357  RKH_STATE_CAST(&smPT_s2), RKH_STATE_CAST(&smPT_s22), RKH_STATE_CAST(0)
358  };
359 
360  setProfile(smPseudoTest, RKH_STATE_CAST(&smPT_s0),
361  RKH_STATE_CAST(&smPT_s0), targetStates,
362  entryStates, exitStates,
363  RKH_STATE_CAST(&smPT_s22), 1, TRN_NOT_INTERNAL, 1, &evE,
364  RKH_STATE_CAST(&smPT_s0));
365 
366  rkh_sm_dispatch((RKH_SM_T *)smPseudoTest, &evE);
367 
368  p = unitrazer_getLastOut();
369  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
370 }
371 
372 TEST(pseudostate, trnToLoadedShallowHistoryWithDefaultTrn)
373 {
374  UtrzProcessOut *p;
375  const RKH_ST_T *targetStates[] =
376  {
377  RKH_STATE_CAST(&smPT_s2Hist), RKH_STATE_CAST(&smPT_s21),
378  RKH_STATE_CAST(0)
379  };
380  const RKH_ST_T *exitStates[] =
381  {
382  RKH_STATE_CAST(&smPT_s0), RKH_STATE_CAST(0)
383  };
384  const RKH_ST_T *entryStates[] =
385  {
386  RKH_STATE_CAST(&smPT_s2), RKH_STATE_CAST(&smPT_s21), RKH_STATE_CAST(0)
387  };
388 
389  setProfile(smPseudoTest, RKH_STATE_CAST(&smPT_s0),
390  RKH_STATE_CAST(&smPT_s0), targetStates,
391  entryStates, exitStates,
392  RKH_STATE_CAST(&smPT_s21), 0, TRN_NOT_INTERNAL, 1, &evE,
393  RKH_STATE_CAST(&smPT_s0));
394 
395  setHistory(&smPT_s2Hist, RKH_STATE_CAST(&smPT_s21));
396  rkh_sm_dispatch((RKH_SM_T *)smPseudoTest, &evE);
397 
398  p = unitrazer_getLastOut();
399  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
400 }
401 
406 /* ------------------------------ End of file ------------------------------ */
void rkh_sm_clear_history(RKHROM RKH_SHIST_T *h)
Erase the history of a state. It can be a shallow or deep history.
#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
#define RKH_TR_FWK_AO(actObj_)
Entry symbol table for active object.
Interface of unit test with Trazer application.
#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_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.