RKH
unitrazer.h
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 
39 /* -------------------------- Development history -------------------------- */
40 /*
41  * 2015.10.24 LeFr v2.4.05 ---
42  */
43 
44 /* -------------------------------- Authors -------------------------------- */
45 /*
46  * LeFr Leandro Francucci francuccilea@gmail.com
47  */
48 
49 /* --------------------------------- Notes --------------------------------- */
50 /* --------------------------------- Module -------------------------------- */
51 
52 #ifndef __UNITRAZER_H__
53 #define __UNITRAZER_H__
54 
55 /* ----------------------------- Include files ----------------------------- */
56 
57 #include "unity_fixture.h"
58 #include "rkh.h"
59 
60 #ifdef __UNITRAZER_LIB__
61 #include "unitrzlib.h"
62 #endif
63 
64 /* ---------------------- External C language linkage ---------------------- */
65 
66 #ifdef __cplusplus
67 extern "C" {
68 #endif
69 
70 /* --------------------------------- Macros -------------------------------- */
71 /* ============================= Common macros ============================= */
72 
77 #define sm_init() unitrazer_start()
78 
83 #define sm_cleanup() unitrazer_cleanup()
84 
90 #define sm_verify() unitrazer_verify()
91 
92 /* ============================= Expect macros ============================= */
93 
94 /* RKH_TE_SM_INIT */
95 #define sm_init_expect(initState) \
96  unitrazer_sm_init_expect(__LINE__, initState)
97 
98 #define unitrazer_sm_init_expect(line, initState) \
99  unitrazer_expect_wSymArg(line, RKH_TE_SM_INIT, 1, initState)
100 
101 #define sm_init_expectAnyArgs() \
102  unitrazer_expectAnyArgs(__LINE__, RKH_TE_SM_INIT)
103 
104 /* RKH_TE_SM_CLRH */
105 #define sm_clrh_expect(historyState) \
106  unitrazer_sm_clrh_expect(__LINE__, historyState)
107 
108 #define unitrazer_sm_clrh_expect(line, historyState) \
109  unitrazer_expect_wSymArg(line, RKH_TE_SM_CLRH, 1, historyState)
110 
111 #define sm_clrh_expectAnyArgs() \
112  unitrazer_expectAnyArgs(__LINE__, RKH_TE_SM_CLRH)
113 
114 /* RKH_TE_SM_TRN */
115 #define sm_trn_expect(sourceState, targetState) \
116  unitrazer_sm_trn_expect(__LINE__, sourceState, targetState)
117 
118 #define unitrazer_sm_trn_expect(line, sourceState, targetState) \
119  unitrazer_expect_wSymArg(line, RKH_TE_SM_TRN, 2, sourceState, targetState)
120 
121 #define sm_trn_expectAnyArgs() \
122  unitrazer_expectAnyArgs(__LINE__, RKH_TE_SM_TRN)
123 
124 /* RKH_TE_SM_STATE */
125 #define sm_state_expect(nextState) \
126  unitrazer_sm_state_expect(__LINE__, nextState)
127 
128 #define unitrazer_sm_state_expect(line, nextState) \
129  unitrazer_expect_wSymArg(line, RKH_TE_SM_STATE, 1, nextState)
130 
131 #define sm_state_expectAnyArgs() \
132  unitrazer_expectAnyArgs(__LINE__, RKH_TE_SM_STATE)
133 
134 /* RKH_TE_SM_ENSTATE */
135 #define sm_enstate_expect(entryState) \
136  unitrazer_enstate_expect(__LINE__, entryState)
137 
138 #define unitrazer_enstate_expect(line, entryState) \
139  unitrazer_expect_wSymArg(line, RKH_TE_SM_ENSTATE, 1, entryState)
140 
141 #define sm_enstate_expectAnyArgs() \
142  unitrazer_expectAnyArgs(__LINE__, RKH_TE_SM_ENSTATE)
143 
144 /* RKH_TE_SM_EXSTATE */
145 #define sm_exstate_expect(exitState) \
146  unitrazer_exstate_expect(__LINE__, exitState)
147 
148 #define unitrazer_exstate_expect(line, exitState) \
149  unitrazer_expect_wSymArg(line, RKH_TE_SM_EXSTATE, 1, exitState)
150 
151 #define sm_exstate_expectAnyArgs() \
152  unitrazer_expectAnyArgs(__LINE__, RKH_TE_SM_EXSTATE)
153 
154 /* RKH_TE_SM_NENEX */
155 #define sm_nenex_expect(nEntry, nExit) \
156  unitrazer_sm_nenex_expect(__LINE__, nEntry, nExit)
157 
158 #define unitrazer_sm_nenex_expect(line, nEntry, nExit) \
159  unitrazer_expect_wNumArg(line, RKH_TE_SM_NENEX, 2, nEntry, nExit)
160 
161 #define sm_nenex_expectAnyArgs() \
162  unitrazer_expectAnyArgs(__LINE__, RKH_TE_SM_NENEX)
163 
164 /* RKH_TE_SM_NTRNACT */
165 #define sm_ntrnact_expect(nActions, nSegments) \
166  unitrazer_sm_ntrnact_expect(__LINE__, nActions, nSegments)
167 
168 #define unitrazer_sm_ntrnact_expect(line, nActions, nSegments) \
169  unitrazer_expect_wNumArg(line, RKH_TE_SM_NTRNACT, 2, nActions, nSegments)
170 
171 #define sm_ntrnact_expectAnyArgs() \
172  unitrazer_expectAnyArgs(__LINE__, RKH_TE_SM_NTRNACT)
173 
174 /* RKH_TE_SM_TS_STATE */
175 #define sm_tsState_expect(targetState) \
176  unitrazer_sm_tsState_expect(__LINE__, targetState)
177 
178 #define unitrazer_sm_tsState_expect(line, targetState) \
179  unitrazer_expect_wSymArg(line, RKH_TE_SM_TS_STATE, 1, targetState)
180 
181 #define sm_tsState_expectAnyArgs() \
182  unitrazer_expectAnyArgs(__LINE__, RKH_TE_SM_TS_STATE)
183 
184 /* RKH_TE_SM_EVT_PROC */
185 #define sm_evtProc_expect() \
186  unitrazer_sm_evtProc_expect(__LINE__)
187 
188 #define unitrazer_sm_evtProc_expect(line) \
189  unitrazer_expect_noArgs(line, RKH_TE_SM_EVT_PROC)
190 
191 /* RKH_TE_SM_EVT_NFOUND */
192 #define sm_evtNotFound_expect(signal) \
193  unitrazer_sm_evtNotFound_expect(__LINE__, signal)
194 
195 #define unitrazer_sm_evtNotFound_expect(line, signal) \
196  unitrazer_expect_wSig(line, RKH_TE_SM_EVT_NFOUND, signal)
197 
198 #define sm_evtNotFound_expectAnyArgs() \
199  unitrazer_expectAnyArgs(__LINE__, RKH_TE_SM_EVT_NFOUND)
200 
201 /* RKH_TE_SM_GRD_FALSE */
202 #define sm_grdFalse_expect() \
203  unitrazer_sm_grdFalse_expect(__LINE__)
204 
205 #define unitrazer_sm_grdFalse_expect(line) \
206  unitrazer_expect_noArgs(line, RKH_TE_SM_GRD_FALSE)
207 
208 /* RKH_TE_SM_CND_NFOUND */
209 #define sm_cndNotFound_expect() \
210  unitrazer_sm_cndNotFound_expect(__LINE__)
211 
212 #define unitrazer_sm_cndNotFound_expect(line) \
213  unitrazer_expect_noArgs(line, RKH_TE_SM_CND_NFOUND)
214 
215 /* RKH_TE_SM_UNKN_STATE */
216 #define sm_unknState_expect() \
217  unitrazer_sm_unknState_expect(__LINE__)
218 
219 #define unitrazer_sm_unknState_expect(line) \
220  unitrazer_expect_noArgs(line, RKH_TE_SM_UNKN_STATE)
221 
222 /* RKH_TE_SM_EX_HLEVEL */
223 #define sm_exHLevel_expect() \
224  unitrazer_sm_exHLevel_expect(__LINE__)
225 
226 #define unitrazer_sm_exHLevel_expect(line) \
227  unitrazer_expect_noArgs(line, RKH_TE_SM_EX_HLEVEL)
228 
229 /* RKH_TE_SM_EX_TSEG */
230 #define sm_exTSeg_expect() \
231  unitrazer_sm_exTSeg_expect(__LINE__)
232 
233 #define unitrazer_sm_exTSeg_expect(line) \
234  unitrazer_expect_noArgs(line, RKH_TE_SM_EX_TSEG)
235 
236 /* RKH_TE_SM_EXE_ACT */
237 #define sm_exeAct_expect(actType, state, action) \
238  unitrazer_sm_exeAct_expect(__LINE__, actType, state, action)
239 
240 #define sm_exeAct_expectAnyArgs() \
241  unitrazer_expectAnyArgs(__LINE__, RKH_TE_SM_EXE_ACT)
242 
243 /* RKH_TE_SM_DCH */
244 #define sm_dch_expect(signal, state) \
245  unitrazer_sm_dch_expect(__LINE__, signal, state)
246 
247 #define sm_dch_expectAnyArgs() \
248  unitrazer_expectAnyArgs(__LINE__, RKH_TE_SM_DCH)
249 
250 /* ============================= Ignore macros ============================= */
251 
252 /* RKH_TE_SM_INIT */
253 #define sm_init_ignore() \
254  unitrazer_ignore(__LINE__, RKH_TE_SM_INIT)
255 
256 /* RKH_TE_SM_CLRH */
257 #define sm_clrh_ignore() \
258  unitrazer_ignore(__LINE__, RKH_TE_SM_CLRH)
259 
260 /* RKH_TE_SM_TRN */
261 #define sm_trn_ignore() \
262  unitrazer_ignore(__LINE__, RKH_TE_SM_TRN)
263 
264 #define sm_trn_ignoreArg_sourceState() \
265  unitrazer_ignoreArg(__LINE__, RKH_TE_SM_TRN, UT_ARGNO_1)
266 
267 #define sm_trn_ignoreArg_targetState() \
268  unitrazer_ignoreArg(__LINE__, RKH_TE_SM_TRN, UT_ARGNO_2)
269 
270 /* RKH_TE_SM_STATE */
271 #define sm_state_ignore() \
272  unitrazer_ignore(__LINE__, RKH_TE_SM_STATE)
273 
274 /* RKH_TE_SM_ENSTATE */
275 #define sm_enstate_ignore() \
276  unitrazer_ignore(__LINE__, RKH_TE_SM_ENSTATE)
277 
278 /* RKH_TE_SM_EXSTATE */
279 #define sm_exstate_ignore() \
280  unitrazer_ignore(__LINE__, RKH_TE_SM_EXSTATE)
281 
282 /* RKH_TE_SM_NENEX */
283 #define sm_nenex_ignore() \
284  unitrazer_ignore(__LINE__, RKH_TE_SM_NENEX)
285 
286 #define sm_nenex_ignoreArg_nEntry() \
287  unitrazer_ignoreArg(__LINE__, RKH_TE_SM_NENEX, UT_ARGNO_1)
288 
289 #define sm_nenex_ignoreArg_nExit() \
290  unitrazer_ignoreArg(__LINE__, RKH_TE_SM_NENEX, UT_ARGNO_2)
291 
292 /* RKH_TE_SM_NTRNACT */
293 #define sm_ntrnact_ignore() \
294  unitrazer_ignore(__LINE__, RKH_TE_SM_NTRNACT)
295 
296 #define sm_ntrnact_ignoreArg_nActions() \
297  unitrazer_ignoreArg(__LINE__, RKH_TE_SM_NTRNACT, UT_ARGNO_1)
298 
299 #define sm_ntrnact_ignoreArg_nSegments() \
300  unitrazer_ignoreArg(__LINE__, RKH_TE_SM_NTRNACT, UT_ARGNO_2)
301 
302 /* RKH_TE_SM_TS_STATE */
303 #define sm_tsState_ignore() \
304  unitrazer_ignore(__LINE__, RKH_TE_SM_TS_STATE)
305 
306 /* RKH_TE_SM_EVT_PROC */
307 #define sm_evtProc_ignore() \
308  unitrazer_ignore(__LINE__, RKH_TE_SM_EVT_PROC)
309 
310 /* RKH_TE_SM_EVT_NFOUND */
311 #define sm_evtNotFound_ignore() \
312  unitrazer_ignore(__LINE__, RKH_TE_SM_EVT_NFOUND)
313 
314 /* RKH_TE_SM_GRD_FALSE */
315 #define sm_grdFalse_ignore() \
316  unitrazer_ignore(__LINE__, RKH_TE_SM_GRD_FALSE)
317 
318 /* RKH_TE_SM_CND_NFOUND */
319 #define sm_cndNotFound_ignore() \
320  unitrazer_ignore(__LINE__, RKH_TE_SM_CND_NFOUND)
321 
322 /* RKH_TE_SM_UNKN_STATE */
323 #define sm_unknState_ignore() \
324  unitrazer_ignore(__LINE__, RKH_TE_SM_UNKN_STATE)
325 
326 /* RKH_TE_SM_EX_HLEVEL */
327 #define sm_exHLevel_ignore() \
328  unitrazer_ignore(__LINE__, RKH_TE_SM_EX_HLEVEL)
329 
330 /* RKH_TE_SM_EX_TSEG */
331 #define sm_exTSeg_ignore() \
332  unitrazer_ignore(__LINE__, RKH_TE_SM_EX_TSEG)
333 
334 /* RKH_TE_SM_EXE_ACT */
335 #define sm_exeAct_ignore() \
336  unitrazer_ignore(__LINE__, RKH_TE_SM_EXE_ACT)
337 
338 #define sm_exeAct_ignoreArg_actType() \
339  unitrazer_ignoreArg(__LINE__, RKH_TE_SM_EXE_ACT, UT_ARGNO_1)
340 
341 #define sm_exeAct_ignoreArg_state() \
342  unitrazer_ignoreArg(__LINE__, RKH_TE_SM_EXE_ACT, UT_ARGNO_2)
343 
344 #define sm_exeAct_ignoreArg_action() \
345  unitrazer_ignoreArg(__LINE__, RKH_TE_SM_EXE_ACT, UT_ARGNO_3)
346 
347 /* RKH_TE_SM_DCH */
348 #define sm_dch_ignore() \
349  unitrazer_ignore(__LINE__, RKH_TE_SM_DCH)
350 
351 #define sm_dch_ignoreArg_signal() \
352  unitrazer_ignoreArg(__LINE__, RKH_TE_SM_DCH, UT_ARGNO_1)
353 
354 #define sm_dch_ignoreArg_state() \
355  unitrazer_ignoreArg(__LINE__, RKH_TE_SM_DCH, UT_ARGNO_2)
356 
357 /* -------------------------------- Ignore Groups--------------------------- */
358 
359 /* RKH_MP_GROUP */
360 #define mp_ignore() \
361  unitrazer_ignoreGroup(__LINE__, RKH_TG_MP)
362 
363 /* RKH_SMA_GROUP */
364 #define sma_ignore() \
365  unitrazer_ignoreGroup(__LINE__, RKH_TG_SMA)
366 
367 /* RKH_FWK_GROUP */
368 #define fwk_ignore() \
369  unitrazer_ignoreGroup(__LINE__, RKH_TG_FWK)
370 
371 /* RKH_SM_GROUP */
372 #define sm_ignore() \
373  unitrazer_ignoreGroup(__LINE__, RKH_TG_SM)
374 
375 /* -------------------------------- Constants ------------------------------ */
376 
377 #define UT_ARGNO_1 (rui8_t)0
378 #define UT_ARGNO_2 (rui8_t)1
379 #define UT_ARGNO_3 (rui8_t)2
380 #define UT_ARGNO_4 (rui8_t)3
381 #define UT_ARGNO_5 (rui8_t)4
382 #define UT_ARGNO_6 (rui8_t)5
383 
384 #define UT_SIZEOF_MSG 256
385 
386 /* ------------------------------- Data types ------------------------------ */
387 typedef enum
388 {
389  UT_PROC_SUCCESS, UT_PROC_FAIL, UT_PROC_BUSY, UT_PROC_INIT
390 } UT_RET_CODE;
391 
392 typedef struct UtrzProcessOut UtrzProcessOut;
393 
394 struct UtrzProcessOut
395 {
396  UT_RET_CODE status; /* result code UT_RET_CODE */
397  char msg[UT_SIZEOF_MSG]; /* String terminated in '\0' according to */
398  /* cmock's ruby scripts */
399  UNITY_LINE_TYPE line; /* Line number of expectation */
400  /* Another parameters from trazer */
401 };
402 
403 /* -------------------------- External variables --------------------------- */
404 /* -------------------------- Function prototypes -------------------------- */
405 
406 UtrzProcessOut * unitrazer_getLastOut(void);
407 void unitrazer_resetOut(void);
408 void unitrazer_log_start(void);
409 
410 
415 void unitrazer_start(void);
416 
421 void unitrazer_cleanup(void);
422 
428 void unitrazer_verify(void);
429 
430 /* ============================ Expect functions =========================== */
431 
445 void unitrazer_expect_wSymArg(UNITY_LINE_TYPE cmockLine, RKH_TE_ID_T trcEvt,
446  rui8_t nArgs, ...);
447 
461 void unitrazer_expect_wNumArg(UNITY_LINE_TYPE cmockLine, RKH_TE_ID_T trcEvt,
462  rui8_t nArgs, ...);
463 
476 void unitrazer_expect_wSig(UNITY_LINE_TYPE cmockLine,
477  RKH_TE_ID_T trcEvt, RKH_SIG_T signal);
478 
490 void unitrazer_expect_noArgs(UNITY_LINE_TYPE cmockLine,
491  RKH_TE_ID_T trcEvt);
492 
493 /* ======================== Common expect functions ======================== */
494 
507 void unitrazer_expectAnyArgs(UNITY_LINE_TYPE cmockLine, rui8_t trcEvt);
508 
522 void unitrazer_sm_exeAct_expect(UNITY_LINE_TYPE cmockLine,
523  rui8_t actType, RKH_ST_T *state, void * action);
524 
537 void unitrazer_sm_dch_expect(UNITY_LINE_TYPE cmockLine, RKH_SIG_T signal,
538  RKH_ST_T *state);
539 
551 void unitrazer_ignore(UNITY_LINE_TYPE cmockLine, rui8_t trcEvt);
552 
568 void unitrazer_ignoreArg(UNITY_LINE_TYPE cmockLine, rui8_t trcEvt,
569  rui8_t noArg);
570 
583 void unitrazer_ignoreGroup(UNITY_LINE_TYPE cmockLine, RKH_TG_T group);
584 
585 /* -------------------- External C language linkage end -------------------- */
586 
587 #ifdef __cplusplus
588 }
589 #endif
590 
591 /* ------------------------------ Module end ------------------------------- */
592 
593 #endif
594 
595 /* ------------------------------ File footer ------------------------------ */
void unitrazer_ignoreGroup(UNITY_LINE_TYPE cmockLine, RKH_TG_T group)
Force to ignore every produced trace event from a specifc trace group.
rui8_t RKH_SIG_T
Definition: rkhevt.h:98
void unitrazer_expectAnyArgs(UNITY_LINE_TYPE cmockLine, rui8_t trcEvt)
Expect a specific trace event regardless its arguments.
void unitrazer_sm_dch_expect(UNITY_LINE_TYPE cmockLine, RKH_SIG_T signal, RKH_ST_T *state)
Expect for RKH_TE_SM_DCH trace event.
void unitrazer_cleanup(void)
Return the system under test to its initial state after the test.
void unitrazer_expect_wSig(UNITY_LINE_TYPE cmockLine, RKH_TE_ID_T trcEvt, RKH_SIG_T signal)
Identifies the trace event to expect and one signal argument.
void unitrazer_ignore(UNITY_LINE_TYPE cmockLine, rui8_t trcEvt)
Ignore a specific trace event.
rui8_t RKH_TE_ID_T
Describes a trace event identification (ID).
void unitrazer_sm_exeAct_expect(UNITY_LINE_TYPE cmockLine, rui8_t actType, RKH_ST_T *state, void *action)
Expect for RKH_TE_SM_EXE_ACT trace event.
rui8_t RKH_TG_T
Group of events.
void unitrazer_ignoreArg(UNITY_LINE_TYPE cmockLine, rui8_t trcEvt, rui8_t noArg)
Adds the ability to specify specifc arguments to ignore for a produced trace event, instead of ignoring all the arguments or the entire generated trace event, as the unitrazer_ignore() function supports.
void unitrazer_verify(void)
Makes sure there are no unused expectations, if there are, this function causes the test to fail...
Describes the common properties of regular states (basic, composite, and submachine).
Definition: rkhsm.h:2062
RKH framwwork platform - independent interface.
void unitrazer_expect_noArgs(UNITY_LINE_TYPE cmockLine, RKH_TE_ID_T trcEvt)
Identifies the trace event to expect without arguments.
void unitrazer_start(void)
Establish the preconditions to the tests.
void unitrazer_expect_wSymArg(UNITY_LINE_TYPE cmockLine, RKH_TE_ID_T trcEvt, rui8_t nArgs,...)
Identifies the trace event to expect with one or more arguments.
void unitrazer_expect_wNumArg(UNITY_LINE_TYPE cmockLine, RKH_TE_ID_T trcEvt, rui8_t nArgs,...)
Identifies the trace event to expect with one or more arguments.