RKH
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 /* ---------------------- External C language linkage ---------------------- */
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
66 /* --------------------------------- Macros -------------------------------- */
67 /* ============================= Common macros ============================= */
68 
73 #define sm_init() unitrazer_init()
74 
79 #define sm_cleanup() unitrazer_cleanup()
80 
86 #define sm_verify() unitrazer_verify()
87 
88 /* ============================= Expect macros ============================= */
89 
90 /* RKH_TE_SM_INIT */
91 #define sm_init_expect(initState) \
92  unitrazer_sm_init_expect(__LINE__, initState)
93 
94 #define unitrazer_sm_init_expect(line, initState) \
95  unitrazer_expect_wSymArg(line, RKH_TE_SM_INIT, 1, initState)
96 
97 #define sm_init_expectAnyArgs() \
98  unitrazer_expectAnyArgs(__LINE__, RKH_TE_SM_INIT)
99 
100 /* RKH_TE_SM_CLRH */
101 #define sm_clrh_expect(historyState) \
102  unitrazer_sm_clrh_expect(__LINE__, historyState)
103 
104 #define unitrazer_sm_clrh_expect(line, historyState) \
105  unitrazer_expect_wSymArg(line, RKH_TE_SM_CLRH, 1, historyState)
106 
107 #define sm_clrh_expectAnyArgs() \
108  unitrazer_expectAnyArgs(__LINE__, RKH_TE_SM_CLRH)
109 
110 /* RKH_TE_SM_TRN */
111 #define sm_trn_expect(sourceState, targetState) \
112  unitrazer_sm_trn_expect(__LINE__, sourceState, targetState)
113 
114 #define unitrazer_sm_trn_expect(line, sourceState, targetState) \
115  unitrazer_expect_wSymArg(line, RKH_TE_SM_TRN, 2, sourceState, targetState)
116 
117 #define sm_trn_expectAnyArgs() \
118  unitrazer_expectAnyArgs(__LINE__, RKH_TE_SM_TRN)
119 
120 /* RKH_TE_SM_STATE */
121 #define sm_state_expect(nextState) \
122  unitrazer_sm_state_expect(__LINE__, nextState)
123 
124 #define unitrazer_sm_state_expect(line, nextState) \
125  unitrazer_expect_wSymArg(line, RKH_TE_SM_STATE, 1, nextState)
126 
127 #define sm_state_expectAnyArgs() \
128  unitrazer_expectAnyArgs(__LINE__, RKH_TE_SM_STATE)
129 
130 /* RKH_TE_SM_ENSTATE */
131 #define sm_enstate_expect(entryState) \
132  unitrazer_enstate_expect(__LINE__, entryState)
133 
134 #define unitrazer_enstate_expect(line, entryState) \
135  unitrazer_expect_wSymArg(line, RKH_TE_SM_ENSTATE, 1, entryState)
136 
137 #define sm_enstate_expectAnyArgs() \
138  unitrazer_expectAnyArgs(__LINE__, RKH_TE_SM_ENSTATE)
139 
140 /* RKH_TE_SM_EXSTATE */
141 #define sm_exstate_expect(exitState) \
142  unitrazer_exstate_expect(__LINE__, exitState)
143 
144 #define unitrazer_exstate_expect(line, exitState) \
145  unitrazer_expect_wSymArg(line, RKH_TE_SM_EXSTATE, 1, exitState)
146 
147 #define sm_exstate_expectAnyArgs() \
148  unitrazer_expectAnyArgs(__LINE__, RKH_TE_SM_EXSTATE)
149 
150 /* RKH_TE_SM_NENEX */
151 #define sm_nenex_expect(nEntry, nExit) \
152  unitrazer_sm_nenex_expect(__LINE__, nEntry, nExit)
153 
154 #define unitrazer_sm_nenex_expect(line, nEntry, nExit) \
155  unitrazer_expect_wNumArg(line, RKH_TE_SM_NENEX, 2, nEntry, nExit)
156 
157 #define sm_nenex_expectAnyArgs() \
158  unitrazer_expectAnyArgs(__LINE__, RKH_TE_SM_NENEX)
159 
160 /* RKH_TE_SM_NTRNACT */
161 #define sm_ntrnact_expect(nActions, nSegments) \
162  unitrazer_sm_ntrnact_expect(__LINE__, nActions, nSegments)
163 
164 #define unitrazer_sm_ntrnact_expect(line, nActions, nSegments) \
165  unitrazer_expect_wNumArg(line, RKH_TE_SM_NTRNACT, 2, nActions, nSegments)
166 
167 #define sm_ntrnact_expectAnyArgs() \
168  unitrazer_expectAnyArgs(__LINE__, RKH_TE_SM_NTRNACT)
169 
170 /* RKH_TE_SM_TS_STATE */
171 #define sm_tsState_expect(targetState) \
172  unitrazer_sm_tsState_expect(__LINE__, targetState)
173 
174 #define unitrazer_sm_tsState_expect(line, targetState) \
175  unitrazer_expect_wSymArg(line, RKH_TE_SM_TS_STATE, 1, targetState)
176 
177 #define sm_tsState_expectAnyArgs() \
178  unitrazer_expectAnyArgs(__LINE__, RKH_TE_SM_TS_STATE)
179 
180 /* RKH_TE_SM_EVT_PROC */
181 #define sm_evtProc_expect() \
182  unitrazer_sm_evtProc_expect(__LINE__)
183 
184 #define unitrazer_sm_evtProc_expect(line) \
185  unitrazer_expect_noArgs(line, RKH_TE_SM_EVT_PROC)
186 
187 /* RKH_TE_SM_EVT_NFOUND */
188 #define sm_evtNotFound_expect(signal) \
189  unitrazer_sm_evtNotFound_expect(__LINE__, signal)
190 
191 #define unitrazer_sm_evtNotFound_expect(line, signal) \
192  unitrazer_expect_wSig(line, RKH_TE_SM_EVT_NFOUND, signal)
193 
194 #define sm_evtNotFound_expectAnyArgs() \
195  unitrazer_expectAnyArgs(__LINE__, RKH_TE_SM_EVT_NFOUND)
196 
197 /* RKH_TE_SM_GRD_FALSE */
198 #define sm_grdFalse_expect() \
199  unitrazer_sm_grdFalse_expect(__LINE__)
200 
201 #define unitrazer_sm_grdFalse_expect(line) \
202  unitrazer_expect_noArgs(line, RKH_TE_SM_GRD_FALSE)
203 
204 /* RKH_TE_SM_CND_NFOUND */
205 #define sm_cndNotFound_expect() \
206  unitrazer_sm_cndNotFound_expect(__LINE__)
207 
208 #define unitrazer_sm_cndNotFound_expect(line) \
209  unitrazer_expect_noArgs(line, RKH_TE_SM_CND_NFOUND)
210 
211 /* RKH_TE_SM_UNKN_STATE */
212 #define sm_unknState_expect() \
213  unitrazer_sm_unknState_expect(__LINE__)
214 
215 #define unitrazer_sm_unknState_expect(line) \
216  unitrazer_expect_noArgs(line, RKH_TE_SM_UNKN_STATE)
217 
218 /* RKH_TE_SM_EX_HLEVEL */
219 #define sm_exHLevel_expect() \
220  unitrazer_sm_exHLevel_expect(__LINE__)
221 
222 #define unitrazer_sm_exHLevel_expect(line) \
223  unitrazer_expect_noArgs(line, RKH_TE_SM_EX_HLEVEL)
224 
225 /* RKH_TE_SM_EX_TSEG */
226 #define sm_exTSeg_expect() \
227  unitrazer_sm_exTSeg_expect(__LINE__)
228 
229 #define unitrazer_sm_exTSeg_expect(line) \
230  unitrazer_expect_noArgs(line, RKH_TE_SM_EX_TSEG)
231 
232 /* RKH_TE_SM_EXE_ACT */
233 #define sm_exeAct_expect(actType, state, action) \
234  unitrazer_sm_exeAct_expect(__LINE__, actType, state, action)
235 
236 #define sm_exeAct_expectAnyArgs() \
237  unitrazer_expectAnyArgs(__LINE__, RKH_TE_SM_EXE_ACT)
238 
239 /* ============================= Ignore macros ============================= */
240 
241 /* RKH_TE_SM_INIT */
242 #define sm_init_ignore() \
243  unitrazer_ignore(__LINE__, RKH_TE_SM_INIT)
244 
245 /* RKH_TE_SM_CLRH */
246 #define sm_clrh_ignore() \
247  unitrazer_ignore(__LINE__, RKH_TE_SM_CLRH)
248 
249 /* RKH_TE_SM_TRN */
250 #define sm_trn_ignore() \
251  unitrazer_ignore(__LINE__, RKH_TE_SM_TRN)
252 
253 #define sm_trn_ignoreArg_sourceState() \
254  unitrazer_ignoreArg(__LINE__, RKH_TE_SM_TRN, UT_ARGNO_1)
255 
256 #define sm_trn_ignoreArg_targetState() \
257  unitrazer_ignoreArg(__LINE__, RKH_TE_SM_TRN, UT_ARGNO_2)
258 
259 /* RKH_TE_SM_STATE */
260 #define sm_state_ignore() \
261  unitrazer_ignore(__LINE__, RKH_TE_SM_STATE)
262 
263 /* RKH_TE_SM_ENSTATE */
264 #define sm_enstate_ignore() \
265  unitrazer_ignore(__LINE__, RKH_TE_SM_ENSTATE)
266 
267 /* RKH_TE_SM_EXSTATE */
268 #define sm_exstate_ignore() \
269  unitrazer_ignore(__LINE__, RKH_TE_SM_EXSTATE)
270 
271 /* RKH_TE_SM_NENEX */
272 #define sm_nenex_ignore() \
273  unitrazer_ignore(__LINE__, RKH_TE_SM_NENEX)
274 
275 #define sm_nenex_ignoreArg_nEntry() \
276  unitrazer_ignoreArg(__LINE__, RKH_TE_SM_NENEX, UT_ARGNO_1)
277 
278 #define sm_nenex_ignoreArg_nExit() \
279  unitrazer_ignoreArg(__LINE__, RKH_TE_SM_NENEX, UT_ARGNO_2)
280 
281 /* RKH_TE_SM_NTRNACT */
282 #define sm_ntrnact_ignore() \
283  unitrazer_ignore(__LINE__, RKH_TE_SM_NTRNACT)
284 
285 #define sm_ntrnact_ignoreArg_nActions() \
286  unitrazer_ignoreArg(__LINE__, RKH_TE_SM_NTRNACT, UT_ARGNO_1)
287 
288 #define sm_ntrnact_ignoreArg_nSegments() \
289  unitrazer_ignoreArg(__LINE__, RKH_TE_SM_NTRNACT, UT_ARGNO_2)
290 
291 /* RKH_TE_SM_TS_STATE */
292 #define sm_tsState_ignore() \
293  unitrazer_ignore(__LINE__, RKH_TE_SM_TS_STATE)
294 
295 /* RKH_TE_SM_EVT_PROC */
296 #define sm_evtProc_ignore() \
297  unitrazer_ignore(__LINE__, RKH_TE_SM_EVT_PROC)
298 
299 /* RKH_TE_SM_EVT_NFOUND */
300 #define sm_evtNotFound_ignore() \
301  unitrazer_ignore(__LINE__, RKH_TE_SM_EVT_NFOUND)
302 
303 /* RKH_TE_SM_GRD_FALSE */
304 #define sm_grdFalse_ignore() \
305  unitrazer_ignore(__LINE__, RKH_TE_SM_GRD_FALSE)
306 
307 /* RKH_TE_SM_CND_NFOUND */
308 #define sm_cndNotFound_ignore() \
309  unitrazer_ignore(__LINE__, RKH_TE_SM_CND_NFOUND)
310 
311 /* RKH_TE_SM_UNKN_STATE */
312 #define sm_unknState_ignore() \
313  unitrazer_ignore(__LINE__, RKH_TE_SM_UNKN_STATE)
314 
315 /* RKH_TE_SM_EX_HLEVEL */
316 #define sm_exHLevel_ignore() \
317  unitrazer_ignore(__LINE__, RKH_TE_SM_EX_HLEVEL)
318 
319 /* RKH_TE_SM_EX_TSEG */
320 #define sm_exTSeg_ignore() \
321  unitrazer_ignore(__LINE__, RKH_TE_SM_EX_TSEG)
322 
323 /* RKH_TE_SM_EXE_ACT */
324 #define sm_exeAct_ignore() \
325  unitrazer_ignore(__LINE__, RKH_TE_SM_EXE_ACT)
326 
327 #define sm_exeAct_ignoreArg_actType() \
328  unitrazer_ignoreArg(__LINE__, RKH_TE_SM_EXE_ACT, UT_ARGNO_1)
329 
330 #define sm_exeAct_ignoreArg_state() \
331  unitrazer_ignoreArg(__LINE__, RKH_TE_SM_EXE_ACT, UT_ARGNO_2)
332 
333 #define sm_exeAct_ignoreArg_action() \
334  unitrazer_ignoreArg(__LINE__, RKH_TE_SM_EXE_ACT, UT_ARGNO_3)
335 
336 /* -------------------------------- Ignore Groups--------------------------- */
337 
338 /* RKH_MP_GROUP */
339 #define mp_ignore() \
340  unitrazer_ignoreGroup(__LINE__, RKH_TG_MP)
341 
342 /* RKH_SMA_GROUP */
343 #define sma_ignore() \
344  unitrazer_ignoreGroup(__LINE__, RKH_TG_SMA)
345 
346 /* RKH_FWK_GROUP */
347 #define fwk_ignore() \
348  unitrazer_ignoreGroup(__LINE__, RKH_TG_FWK)
349 
350 /* RKH_SM_GROUP */
351 #define sm_ignore() \
352  unitrazer_ignoreGroup(__LINE__, RKH_TG_SM)
353 
354 /* -------------------------------- Constants ------------------------------ */
355 
356 #define UT_ARGNO_1 (rui8_t)0
357 #define UT_ARGNO_2 (rui8_t)1
358 #define UT_ARGNO_3 (rui8_t)2
359 #define UT_ARGNO_4 (rui8_t)3
360 #define UT_ARGNO_5 (rui8_t)4
361 #define UT_ARGNO_6 (rui8_t)5
362 
363 #define UT_SIZEOF_MSG 256
364 
365 /* ------------------------------- Data types ------------------------------ */
366 typedef enum
367 {
368  UT_PROC_SUCCESS, UT_PROC_FAIL, UT_PROC_BUSY, UT_PROC_INIT
369 } UT_RET_CODE;
370 
371 typedef struct UtrzProcessOut UtrzProcessOut;
372 
373 struct UtrzProcessOut
374 {
375  UT_RET_CODE status; /* result code UT_RET_CODE */
376  char msg[UT_SIZEOF_MSG]; /* String terminated in '\0' according to */
377  /* cmock's ruby scripts */
378  UNITY_LINE_TYPE line; /* Line number of expectation */
379  /* Another parameters from trazer */
380 };
381 
382 /* -------------------------- External variables --------------------------- */
383 /* -------------------------- Function prototypes -------------------------- */
384 
385 UtrzProcessOut * unitrazer_getLastOut(void);
386 void unitrazer_resetOut(void);
387 
392 void unitrazer_init(void);
393 
398 void unitrazer_cleanup(void);
399 
405 void unitrazer_verify(void);
406 
407 /* ============================ Expect functions =========================== */
408 
422 void unitrazer_expect_wSymArg(UNITY_LINE_TYPE cmockLine, RKH_TRC_EVENTS trcEvt,
423  rui8_t nArgs, ...);
424 
438 void unitrazer_expect_wNumArg(UNITY_LINE_TYPE cmockLine, RKH_TRC_EVENTS trcEvt,
439  rui8_t nArgs, ...);
440 
453 void unitrazer_expect_wSig(UNITY_LINE_TYPE cmockLine,
454  RKH_TRC_EVENTS trcEvt, RKH_SIG_T signal);
455 
467 void unitrazer_expect_noArgs(UNITY_LINE_TYPE cmockLine,
468  RKH_TRC_EVENTS trcEvt);
469 
470 /* ======================== Common expect functions ======================== */
471 
484 void unitrazer_expectAnyArgs(UNITY_LINE_TYPE cmockLine, rui8_t trcEvt);
485 
499 void unitrazer_sm_exeAct_expect(UNITY_LINE_TYPE cmockLine,
500  rui8_t actType, RKH_ST_T *state, void * action);
501 
513 void unitrazer_ignore(UNITY_LINE_TYPE cmockLine, rui8_t trcEvt);
514 
530 void unitrazer_ignoreArg(UNITY_LINE_TYPE cmockLine, rui8_t trcEvt,
531  rui8_t noArg);
532 
545 void unitrazer_ignoreGroup(UNITY_LINE_TYPE cmockLine, RKH_TRC_GROUPS group);
546 
547 /* -------------------- External C language linkage end -------------------- */
548 
549 #ifdef __cplusplus
550 }
551 #endif
552 
553 /* ------------------------------ Module end ------------------------------- */
554 
555 #endif
556 
557 /* ------------------------------ File footer ------------------------------ */
RKH_TRC_GROUPS
RKH group of trace events.
Definition: rkhtrc.h:3079
void unitrazer_expect_noArgs(UNITY_LINE_TYPE cmockLine, RKH_TRC_EVENTS trcEvt)
Identifies the trace event to expect without arguments.
rui8_t RKH_SIG_T
Definition: rkhevt.h:92
void unitrazer_expectAnyArgs(UNITY_LINE_TYPE cmockLine, rui8_t trcEvt)
Expect a specific trace event regardless its arguments.
void unitrazer_cleanup(void)
Return the system under test to its initial state after the test.
void unitrazer_init(void)
Establish the preconditions to the tests.
void unitrazer_expect_wNumArg(UNITY_LINE_TYPE cmockLine, RKH_TRC_EVENTS trcEvt, rui8_t nArgs,...)
Identifies the trace event to expect with one or more arguments.
void unitrazer_ignore(UNITY_LINE_TYPE cmockLine, rui8_t trcEvt)
Ignore a specific trace event.
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.
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...
RKH_TRC_EVENTS
RKH trace events.
Definition: rkhtrc.h:3316
Describes the common properties of regular states (basic, composite, and submachine).
Definition: rkhitl.h:3333
void unitrazer_expect_wSymArg(UNITY_LINE_TYPE cmockLine, RKH_TRC_EVENTS trcEvt, rui8_t nArgs,...)
Identifies the trace event to expect with one or more arguments.
void unitrazer_ignoreGroup(UNITY_LINE_TYPE cmockLine, RKH_TRC_GROUPS group)
Force to ignore every produced trace event from a specifc trace group.
RKH framwwork platform - independent interface.
void unitrazer_expect_wSig(UNITY_LINE_TYPE cmockLine, RKH_TRC_EVENTS trcEvt, RKH_SIG_T signal)
Identifies the trace event to expect and one signal argument.