RKH
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 "rkh.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);
179 
180  rkh_sm_dispatch((RKH_SM_T *)smPseudoTest, &evB);
181 
182  p = unitrazer_getLastOut();
183  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
184 }
185 
186 TEST(pseudostate, trnToLoadedShallowHistoryWithoutDefaultTrn)
187 {
188  UtrzProcessOut *p;
189  const RKH_ST_T *targetStates[] =
190  {
191  RKH_STATE_CAST(&smPT_s1Hist), RKH_STATE_CAST(&smPT_s12),
192  RKH_STATE_CAST(0)
193  };
194  const RKH_ST_T *exitStates[] =
195  {
196  RKH_STATE_CAST(&smPT_s0), RKH_STATE_CAST(0)
197  };
198  const RKH_ST_T *entryStates[] =
199  {
200  RKH_STATE_CAST(&smPT_s1), RKH_STATE_CAST(&smPT_s12),
201  RKH_STATE_CAST(&smPT_s121), RKH_STATE_CAST(0)
202  };
203 
204  setProfile(smPseudoTest, RKH_STATE_CAST(&smPT_s0),
205  RKH_STATE_CAST(&smPT_s0), targetStates,
206  entryStates, exitStates,
207  RKH_STATE_CAST(&smPT_s121), 0, TRN_NOT_INTERNAL, 1);
208 
209  setHistory(&smPT_s1Hist, RKH_STATE_CAST(&smPT_s12));
210  rkh_sm_dispatch((RKH_SM_T *)smPseudoTest, &evB);
211 
212  p = unitrazer_getLastOut();
213  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
214 }
215 
216 TEST(pseudostate, exitFromCompositeWithLoadedShallowHistory)
217 {
218  UtrzProcessOut *p;
219  const RKH_ST_T *state;
220  const RKH_ST_T *targetStates[] =
221  {
222  RKH_STATE_CAST(&smPT_s0), RKH_STATE_CAST(0)
223  };
224  const RKH_ST_T *exitStates[] =
225  {
226  RKH_STATE_CAST(&smPT_s121), RKH_STATE_CAST(&smPT_s12),
227  RKH_STATE_CAST(&smPT_s1), RKH_STATE_CAST(0)
228  };
229  const RKH_ST_T *entryStates[] =
230  {
231  RKH_STATE_CAST(&smPT_s0), RKH_STATE_CAST(0)
232  };
233 
234  setProfile(smPseudoTest, RKH_STATE_CAST(&smPT_s121),
235  RKH_STATE_CAST(&smPT_s1), targetStates,
236  entryStates, exitStates,
237  RKH_STATE_CAST(&smPT_s0), 0, TRN_NOT_INTERNAL, 1);
238 
239  rkh_sm_dispatch((RKH_SM_T *)smPseudoTest, &evA);
240  state = getHistory(&smPT_s1Hist);
241  TEST_ASSERT_EQUAL_PTR(RKH_STATE_CAST(&smPT_s12), state);
242 
243  p = unitrazer_getLastOut();
244  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
245 }
246 
247 TEST(pseudostate, trnToEmptyDeepHistoryWithoutDefaultTrn)
248 {
249  UtrzProcessOut *p;
250  const RKH_ST_T *targetStates[] =
251  {
252  RKH_STATE_CAST(&smPT_s12Hist), RKH_STATE_CAST(&smPT_s12),
253  RKH_STATE_CAST(0)
254  };
255  const RKH_ST_T *exitStates[] =
256  {
257  RKH_STATE_CAST(&smPT_s0), RKH_STATE_CAST(0)
258  };
259  const RKH_ST_T *entryStates[] =
260  {
261  RKH_STATE_CAST(&smPT_s1), RKH_STATE_CAST(&smPT_s12),
262  RKH_STATE_CAST(&smPT_s121), RKH_STATE_CAST(0)
263  };
264 
265  setProfile(smPseudoTest, RKH_STATE_CAST(&smPT_s0),
266  RKH_STATE_CAST(&smPT_s0), targetStates,
267  entryStates, exitStates,
268  RKH_STATE_CAST(&smPT_s121), 0, TRN_NOT_INTERNAL, 1);
269 
270  rkh_sm_dispatch((RKH_SM_T *)smPseudoTest, &evC);
271 
272  p = unitrazer_getLastOut();
273  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
274 }
275 
276 TEST(pseudostate, trnToLoadedDeepHistoryWithoutDefaultTrn)
277 {
278  UtrzProcessOut *p;
279  const RKH_ST_T *targetStates[] =
280  {
281  RKH_STATE_CAST(&smPT_s12Hist), RKH_STATE_CAST(&smPT_s122),
282  RKH_STATE_CAST(0)
283  };
284  const RKH_ST_T *exitStates[] =
285  {
286  RKH_STATE_CAST(&smPT_s0), RKH_STATE_CAST(0)
287  };
288  const RKH_ST_T *entryStates[] =
289  {
290  RKH_STATE_CAST(&smPT_s1), RKH_STATE_CAST(&smPT_s12),
291  RKH_STATE_CAST(&smPT_s122), RKH_STATE_CAST(0)
292  };
293 
294  setProfile(smPseudoTest, RKH_STATE_CAST(&smPT_s0),
295  RKH_STATE_CAST(&smPT_s0), targetStates,
296  entryStates, exitStates,
297  RKH_STATE_CAST(&smPT_s122), 0, TRN_NOT_INTERNAL, 1);
298 
299  setHistory(&smPT_s12Hist, RKH_STATE_CAST(&smPT_s122));
300  rkh_sm_dispatch((RKH_SM_T *)smPseudoTest, &evC);
301 
302  p = unitrazer_getLastOut();
303  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
304 }
305 
306 TEST(pseudostate, exitFromCompositeWithLoadedDeepHistory)
307 {
308  UtrzProcessOut *p;
309  const RKH_ST_T *state;
310  const RKH_ST_T *targetStates[] =
311  {
312  RKH_STATE_CAST(&smPT_s122), RKH_STATE_CAST(0)
313  };
314  const RKH_ST_T *exitStates[] =
315  {
316  RKH_STATE_CAST(&smPT_s0), RKH_STATE_CAST(0)
317  };
318  const RKH_ST_T *entryStates[] =
319  {
320  RKH_STATE_CAST(&smPT_s1), RKH_STATE_CAST(&smPT_s12),
321  RKH_STATE_CAST(&smPT_s122), RKH_STATE_CAST(0)
322  };
323 
324  setProfile(smPseudoTest, RKH_STATE_CAST(&smPT_s0),
325  RKH_STATE_CAST(&smPT_s0), targetStates,
326  entryStates, exitStates,
327  RKH_STATE_CAST(&smPT_s122), 0, TRN_NOT_INTERNAL, 1);
328 
329  rkh_sm_dispatch((RKH_SM_T *)smPseudoTest, &evD);
330  state = getHistory(&smPT_s12Hist);
331  TEST_ASSERT_EQUAL_PTR(RKH_STATE_CAST(&smPT_s122), state);
332 
333  p = unitrazer_getLastOut();
334  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
335 }
336 
337 TEST(pseudostate, trnToEmptyShallowHistoryWithDefaultTrn)
338 {
339  UtrzProcessOut *p;
340  const RKH_ST_T *targetStates[] =
341  {
342  RKH_STATE_CAST(&smPT_s2Hist), RKH_STATE_CAST(&smPT_s22),
343  RKH_STATE_CAST(0)
344  };
345  const RKH_ST_T *exitStates[] =
346  {
347  RKH_STATE_CAST(&smPT_s0), RKH_STATE_CAST(0)
348  };
349  const RKH_ST_T *entryStates[] =
350  {
351  RKH_STATE_CAST(&smPT_s2), RKH_STATE_CAST(&smPT_s22), RKH_STATE_CAST(0)
352  };
353 
354  setProfile(smPseudoTest, RKH_STATE_CAST(&smPT_s0),
355  RKH_STATE_CAST(&smPT_s0), targetStates,
356  entryStates, exitStates,
357  RKH_STATE_CAST(&smPT_s22), 1, TRN_NOT_INTERNAL, 1);
358 
359  rkh_sm_dispatch((RKH_SM_T *)smPseudoTest, &evE);
360 
361  p = unitrazer_getLastOut();
362  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
363 }
364 
365 TEST(pseudostate, trnToLoadedShallowHistoryWithDefaultTrn)
366 {
367  UtrzProcessOut *p;
368  const RKH_ST_T *targetStates[] =
369  {
370  RKH_STATE_CAST(&smPT_s2Hist), RKH_STATE_CAST(&smPT_s21),
371  RKH_STATE_CAST(0)
372  };
373  const RKH_ST_T *exitStates[] =
374  {
375  RKH_STATE_CAST(&smPT_s0), RKH_STATE_CAST(0)
376  };
377  const RKH_ST_T *entryStates[] =
378  {
379  RKH_STATE_CAST(&smPT_s2), RKH_STATE_CAST(&smPT_s21), RKH_STATE_CAST(0)
380  };
381 
382  setProfile(smPseudoTest, RKH_STATE_CAST(&smPT_s0),
383  RKH_STATE_CAST(&smPT_s0), targetStates,
384  entryStates, exitStates,
385  RKH_STATE_CAST(&smPT_s21), 0, TRN_NOT_INTERNAL, 1);
386 
387  setHistory(&smPT_s2Hist, RKH_STATE_CAST(&smPT_s21));
388  rkh_sm_dispatch((RKH_SM_T *)smPseudoTest, &evE);
389 
390  p = unitrazer_getLastOut();
391  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status);
392 }
393 
398 /* ------------------------------ 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.
Definition: rkhtrc.h:179
#define sm_cleanup()
Return the system under test to its initial state after the test.
Definition: unitrazer.h:79
#define RKH_TR_FWK_AO(actObj_)
Entry symbol table for active object.
Definition: rkhtrc.h:2653
Interface of unit test with Trazer application.
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
RKH framwwork platform - independent interface.
#define RKH_TR_FWK_SIG(stateObj_)
Entry symbol table for event signal.
Definition: rkhtrc.h:2354
#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