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