RKH
test_rkhtrc_record.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 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 
46 /* -------------------------- Development history -------------------------- */
47 /*
48  * 2017.20.04 LeFr v2.4.05 ---
49  */
50 
51 /* -------------------------------- Authors -------------------------------- */
52 /*
53  * LeFr Leandro Francucci lf@vortexmakes.com
54  */
55 
56 /* --------------------------------- Notes --------------------------------- */
57 /* ----------------------------- Include files ----------------------------- */
58 #include "unity.h"
59 #include "rkhtrc_record.h"
60 #include "Mock_rkhsm.h"
61 #include "Mock_rkhsma.h"
62 #include "Mock_rkh.h"
63 #include "Mock_rkhport.h"
64 #include "Mock_rkhassert.h"
65 #include "Mock_rkhtrc_out.h"
66 #include "Mock_rkhtrc_stream.h"
67 #include "Mock_rkhtrc_filter.h"
68 
69 /* ----------------------------- Local macros ------------------------------ */
70 /* ------------------------------- Constants ------------------------------- */
71 /* ---------------------------- Local data types --------------------------- */
72 /* ---------------------------- Global variables --------------------------- */
73 /* ---------------------------- Local variables ---------------------------- */
74 static RKHROM RKH_ROM_T base = {0, 0, "receiver"};
75 static RKH_SMA_T receiver;
76 static RKH_SMA_T sender;
77 static RKH_EVT_T event;
78 static RKH_ST_T state = {{RKH_BASIC, "state"}};
79 static RKH_ST_T pseudoState = {{RKH_CHOICE, "pseudoState"}};
80 static rui8_t chk;
81 
82 /* ----------------------- Local function prototypes ----------------------- */
83 /* ---------------------------- Local functions ---------------------------- */
84 static void
85 expectU8(rui8_t expectData)
86 {
87  chk = (rui8_t)(chk + expectData);
88  if ((expectData == RKH_ESC) || (expectData == RKH_FLG))
89  {
90  rkh_trc_put_Expect(RKH_ESC);
91  rkh_trc_put_Expect((rui8_t)(expectData ^ RKH_XOR));
92  }
93  else
94  {
95  rkh_trc_put_Expect(expectData);
96  }
97 }
98 
99 static void
100 expectHeader(rui8_t evtId, rui8_t nSeq, rui32_t tStamp, int isCritical)
101 {
102  if (isCritical)
103  {
104  rkh_enter_critical_Expect();
105  }
106  expectU8(evtId);
107  expectU8(nSeq);
108  rkh_trc_getts_ExpectAndReturn(tStamp);
109  expectU8((rui8_t)tStamp);
110  expectU8((rui8_t)(tStamp >> 8));
111  expectU8((rui8_t)(tStamp >> 16));
112  expectU8((rui8_t)(tStamp >> 24));
113 }
114 
115 static void
116 expectObjectAddress(void *obj)
117 {
118  rui32_t value;
119 
120  value = (rui32_t)obj;
121  expectU8((rui8_t)value);
122  expectU8((rui8_t)(value >> 8));
123  expectU8((rui8_t)(value >> 16));
124  expectU8((rui8_t)(value >> 24));
125 }
126 
127 static void
128 expectString(const char *str)
129 {
130  const char *p;
131 
132  for (p = str; *p != '\0'; ++p)
133  {
134  expectU8((rui8_t)*p);
135  }
136  expectU8((rui8_t)'\0');
137 }
138 
139 static void
140 expectTrailer(int isCritical)
141 {
142  chk = (rui8_t)(~chk + 1);
143  expectU8(chk);
144  rkh_trc_put_Expect(RKH_FLG); /* insert record flag */
145  rkh_trc_put_IgnoreArg_b();
146  if (isCritical)
147  {
148  rkh_exit_critical_Expect();
149  }
150 }
151 
152 static void
153 expectU32(rui32_t value)
154 {
155  expectU8((rui8_t)value);
156  expectU8((rui8_t)(value >> 8));
157  expectU8((rui8_t)(value >> 16));
158  expectU8((rui8_t)(value >> 24));
159 }
160 
161 static void
162 expectU16(rui16_t value)
163 {
164  expectU8((rui8_t)value);
165  expectU8((rui8_t)(value >> 8));
166 }
167 
168 /* ---------------------------- Global functions --------------------------- */
169 void
170 setUp(void)
171 {
172  rkh_trcStream_init_Expect();
173  rkh_trc_init();
174 
175  Mock_rkhsm_Init();
176  Mock_rkhsma_Init();
177  Mock_rkh_Init();
178  Mock_rkhport_Init();
179  Mock_rkhassert_Init();
180  Mock_rkhtrc_out_Init();
181  Mock_rkhtrc_stream_Init();
182  Mock_rkhtrc_filter_Init();
183 
184  receiver.sm.romrkh = &base;
185  event.e = 3;
186  event.pool = 5;
187  event.nref = 7;
188  chk = 0;
189 }
190 
191 void
192 tearDown(void)
193 {
194  Mock_rkhsm_Verify();
195  Mock_rkhsma_Verify();
196  Mock_rkh_Verify();
197  Mock_rkhport_Verify();
198  Mock_rkhassert_Verify();
199  Mock_rkhtrc_out_Verify();
200  Mock_rkhtrc_stream_Verify();
201  Mock_rkhtrc_filter_Verify();
202  Mock_rkhsm_Destroy();
203  Mock_rkhsma_Destroy();
204  Mock_rkh_Destroy();
205  Mock_rkhport_Destroy();
206  Mock_rkhassert_Destroy();
207  Mock_rkhtrc_out_Destroy();
208  Mock_rkhtrc_stream_Destroy();
209  Mock_rkhtrc_filter_Destroy();
210 }
211 
218 void
219 test_InsertRecordHeader(void)
220 {
221  rkh_trc_put_Expect(8); /* insert the event ID */
222  rkh_trc_put_Expect(0); /* insert tne sequence number */
223  /* insert tne time-stamp */
224  rkh_trc_getts_ExpectAndReturn(0x01234567);
225  rkh_trc_put_Expect(0x67);
226  rkh_trc_put_Expect(0x45);
227  rkh_trc_put_Expect(0x23);
228  rkh_trc_put_Expect(0x01);
229 
230  rkh_trc_begin(8);
231 }
232 
233 void
234 test_InsertRecordEnd(void)
235 {
236  rui8_t checksum;
237 
238  checksum = 0;
239  checksum = (rui8_t)(~checksum + 1);
240  rkh_trc_put_Expect(checksum); /* insert checksum */
241  rkh_trc_put_Expect(RKH_FLG); /* insert record flag */
242 
243  rkh_trc_end();
244 }
245 
246 void
247 test_InsertU8Value(void)
248 {
249  rui8_t value = 8;
250 
251  rkh_trc_put_Expect(value);
252  rkh_trc_u8(value);
253 }
254 
255 void
256 test_InsertEscapedValues(void)
257 {
258  rui8_t value = RKH_FLG;
259  rkh_trc_put_Expect(RKH_ESC);
260  rkh_trc_put_Expect((rui8_t)(value ^ RKH_XOR));
261 
263 
264  value = RKH_ESC;
265  rkh_trc_put_Expect(RKH_ESC);
266  rkh_trc_put_Expect((rui8_t)(value ^ RKH_XOR));
267 
269 }
270 
271 void
272 test_InsertU16Value(void)
273 {
274  rui16_t value = 0x1234;
275 
276  rkh_trc_put_Expect(0x34);
277  rkh_trc_put_Expect(0x12);
278  rkh_trc_u16(value);
279 }
280 
281 void
282 test_InsertU32Value(void)
283 {
284  rui32_t value = 0x12345678;
285 
286  rkh_trc_put_Expect(0x78);
287  rkh_trc_put_Expect(0x56);
288  rkh_trc_put_Expect(0x34);
289  rkh_trc_put_Expect(0x12);
290 
291  rkh_trc_u32(value);
292 
293 }
294 
295 void
296 test_InsertString(void)
297 {
298  const char *expected = "Hello world!";
299  const char *p;
300 
301  for (p = expected; *p != '\0'; ++p)
302  {
303  rkh_trc_put_Expect(*p);
304  }
305  rkh_trc_put_Expect('\0');
306 
307  rkh_trc_str(expected);
308 }
309 
310 void
311 test_InsertObject(void)
312 {
313  rui8_t obj, evtId = RKH_TE_FWK_OBJ;
314  const char *objName = "obj";
315 
316  expectHeader(evtId, 0, 0x12345678, 1);
317  expectObjectAddress(&obj);
318  expectString(objName);
319  expectTrailer(1);
320  rkh_trc_flush_Expect();
321 
322  rkh_trc_obj(evtId, &obj, objName);
323 }
324 
325 void
326 test_InsertSignal(void)
327 {
328  rui8_t signalId = 8;
329  rui8_t evtId = RKH_TE_FWK_SIG;
330  const char *signalName = "buttonPressed";
331 
332  expectHeader(evtId, 0, 0x12345678, 1);
333  expectU8(signalId);
334  expectString(signalName);
335  expectTrailer(1);
336  rkh_trc_flush_Expect();
337 
338  rkh_trc_sig(signalId, signalName);
339 }
340 
341 void
342 test_InsertAO(void)
343 {
344  expectHeader(RKH_TE_FWK_AO, 0, 0x12345678, 1);
345  expectObjectAddress(&receiver);
346  expectString(receiver.sm.romrkh->name);
347  expectTrailer(1);
348  rkh_trc_flush_Expect();
349 
350  rkh_trc_ao(&receiver);
351 }
352 
353 void
354 test_InsertState(void)
355 {
356  RKH_ST_T state;
357 
358  state.base.name = "state";
359  state.base.type = RKH_BASIC;
360  expectHeader(RKH_TE_FWK_STATE, 0, 0x12345678, 1);
361  expectObjectAddress(&receiver);
362  expectObjectAddress(&state);
363  expectString("state");
364  expectTrailer(1);
365  rkh_trc_flush_Expect();
366 
367  rkh_trc_state(&receiver, (rui8_t *)&state);
368 }
369 
370 void
371 test_InsertRecord(void)
372 {
373 }
374 
375 void
376 test_InsertFwkEpoolRecord(void)
377 {
378  rui8_t poolId = 2;
379  const char *poolName = "ep0";
380 
381  expectHeader(RKH_TE_FWK_EPOOL, 0, 0x12345678, 1);
382  expectU8(poolId);
383  expectString(poolName);
384  expectTrailer(1);
385  rkh_trc_flush_Expect();
386 
387  RKH_TR_FWK_EPOOL(poolId, poolName);
388 }
389 
390 void
391 test_InsertFwkActorRecord(void)
392 {
393  rui8_t actor;
394  const char *actorName = "Actor";
395 
396  expectHeader(RKH_TE_FWK_ACTOR, 0, 0x12345678, 1);
397  expectObjectAddress(&actor);
398  expectString(actorName);
399  expectTrailer(1);
400  rkh_trc_flush_Expect();
401 
402  RKH_TR_FWK_ACTOR(&actor, actorName);
403 }
404 
405 void
406 test_InsertSmaActivateRecord(void)
407 {
408  rkh_trc_isoff__ExpectAndReturn(RKH_TE_SMA_ACT, RKH_TRUE);
409  rkh_trc_symFil_isoff_ExpectAndReturn(RKHFilterSma, RKH_GET_PRIO(&receiver),
410  RKH_TRUE);
411  expectHeader(RKH_TE_SMA_ACT, 0, 0x12345678, 1);
412  expectObjectAddress(&receiver);
413  expectU8(RKH_GET_PRIO(&receiver));
414  expectU8(16);
415  expectTrailer(1);
416 
417  RKH_TR_SMA_ACT(&receiver, RKH_GET_PRIO(&receiver), 16);
418 }
419 
420 void
421 test_InsertSmaGetRecord(void)
422 {
423  rui8_t nElem = 4, nMin = 2;
424 
425  rkh_trc_isoff__ExpectAndReturn(RKH_TE_SMA_GET, RKH_TRUE);
426  rkh_trc_symFil_isoff_ExpectAndReturn(RKHFilterSma, RKH_GET_PRIO(&receiver),
427  RKH_TRUE);
428  rkh_trc_symFil_isoff_ExpectAndReturn(RKHFilterSignal, event.e, RKH_TRUE);
429  expectHeader(RKH_TE_SMA_GET, 0, 0x12345678, 1);
430  expectObjectAddress(&receiver);
431  expectU8(event.e);
432  expectU8(event.pool);
433  expectU8(event.nref);
434  expectU8(nElem);
435  expectU8(nMin);
436  expectTrailer(1);
437 
438  RKH_TR_SMA_GET(&receiver, &event, event.pool, event.nref, nElem, nMin);
439 }
440 
441 void
442 test_InsertSmaPostFifoRecord(void)
443 {
444  rui8_t nElem = 4, nMin = 2;
445 
446  rkh_trc_isoff__ExpectAndReturn(RKH_TE_SMA_FIFO, RKH_TRUE);
447  rkh_trc_symFil_isoff_ExpectAndReturn(RKHFilterSma, RKH_GET_PRIO(&receiver),
448  RKH_TRUE);
449  rkh_trc_symFil_isoff_ExpectAndReturn(RKHFilterSignal, event.e, RKH_TRUE);
450  expectHeader(RKH_TE_SMA_FIFO, 0, 0x12345678, 0);
451  expectObjectAddress(&receiver);
452  expectU8(event.e);
453  expectObjectAddress(&sender);
454  expectU8(event.pool);
455  expectU8(event.nref);
456  expectU8(nElem);
457  expectU8(nMin);
458  expectTrailer(0);
459 
460  RKH_TR_SMA_FIFO(&receiver, &event, &sender, event.pool, event.nref, nElem,
461  nMin);
462 }
463 
464 void
465 test_InsertSmaPostLifoRecord(void)
466 {
467  rui8_t nElem = 4, nMin = 2;
468 
469  rkh_trc_isoff__ExpectAndReturn(RKH_TE_SMA_LIFO, RKH_TRUE);
470  rkh_trc_symFil_isoff_ExpectAndReturn(RKHFilterSma, RKH_GET_PRIO(&receiver),
471  RKH_TRUE);
472  rkh_trc_symFil_isoff_ExpectAndReturn(RKHFilterSignal, event.e, RKH_TRUE);
473  expectHeader(RKH_TE_SMA_LIFO, 0, 0x12345678, 0);
474  expectObjectAddress(&receiver);
475  expectU8(event.e);
476  expectObjectAddress(&sender);
477  expectU8(event.pool);
478  expectU8(event.nref);
479  expectU8(nElem);
480  expectU8(nMin);
481  expectTrailer(0);
482 
483  RKH_TR_SMA_LIFO(&receiver, &event, &sender, event.pool, event.nref, nElem,
484  nMin);
485 }
486 
487 void
488 test_InsertFwkAeRecord(void)
489 {
490  rkh_trc_isoff__ExpectAndReturn(RKH_TE_FWK_AE, RKH_TRUE);
491  expectHeader(RKH_TE_FWK_AE, 0, 0x12345678, 1);
492  expectU16(16);
493  expectU8(event.e);
494  expectU8(event.pool - 1);
495  expectU8(event.nref);
496  expectU8(5);
497  expectU8(2);
498  expectObjectAddress(&receiver);
499  expectTrailer(1);
500 
501  RKH_TR_FWK_AE(16, &event, 5, 2, &receiver);
502 }
503 
504 void
505 test_InsertFwkGcrRecord(void)
506 {
507  rkh_trc_isoff__ExpectAndReturn(RKH_TE_FWK_GCR, RKH_TRUE);
508  expectHeader(RKH_TE_FWK_GCR, 0, 0x12345678, 0);
509  expectU8(event.e);
510  expectU8(event.pool - 1);
511  expectU8(event.nref);
512  expectU8(5);
513  expectU8(2);
514  expectObjectAddress(&receiver);
515  expectTrailer(0);
516 
517  RKH_TR_FWK_GCR(&event, 5, 2, &receiver);
518 }
519 
520 void
521 test_InsertFwkEpregRecord(void)
522 {
523  rkh_trc_isoff__ExpectAndReturn(RKH_TE_FWK_EPREG, RKH_TRUE);
524  expectHeader(RKH_TE_FWK_EPREG, 0, 0x12345678, 1);
525  expectU8(1);
526  expectU32(128);
527  expectU16(32);
528  expectU8(4);
529  expectTrailer(1);
530 
531  RKH_TR_FWK_EPREG(1, 128, 32, 4);
532 }
533 
534 void
535 test_InsertFwkStateRecord(void)
536 {
537  expectHeader(RKH_TE_FWK_STATE, 0, 0x12345678, 1);
538  expectObjectAddress(&receiver);
539  expectObjectAddress(&state);
540  expectString(state.base.name);
541  expectTrailer(1);
542  rkh_trc_flush_Expect();
543 
544  RKH_TR_FWK_STATE(&receiver, &state);
545 }
546 
547 void
548 test_InsertFwkPseudoStateRecord(void)
549 {
550  expectHeader(RKH_TE_FWK_PSTATE, 0, 0x12345678, 1);
551  expectObjectAddress(&receiver);
552  expectObjectAddress(&pseudoState);
553  expectString(pseudoState.base.name);
554  expectTrailer(1);
555  rkh_trc_flush_Expect();
556 
557  RKH_TR_FWK_PSTATE(&receiver, &pseudoState);
558 }
559 
560 void
561 test_InsertDispatchRecordWithInvalidSignal(void)
562 {
563  event.e = RKH_COMPLETION_EVENT;
564 
565  rkh_trc_isoff__ExpectAndReturn(RKH_TE_SM_DCH, RKH_TRUE);
566  rkh_trc_symFil_isoff_ExpectAndReturn(RKHFilterSma, RKH_GET_PRIO(&receiver),
567  RKH_TRUE);
568  expectHeader(RKH_TE_SM_DCH, 0, 0x12345678, 1);
569  expectObjectAddress(&receiver);
570  expectU8(event.e);
571  expectObjectAddress(&state);
572  expectTrailer(1);
573 
574  RKH_TR_SM_DCH(&receiver, &event, &state);
575 }
576 
582 /* ------------------------------ End of file ------------------------------ */
#define RKH_TRUE
Standard define.
Definition: rkhdef.h:257
#define RKH_TR_SMA_ACT(actObj_, actObjPrio_, actObjQueSize_)
Initializes and activates a previously created state machine application (SMA) as known as active obj...
#define RKH_TR_SMA_FIFO(actObj_, evt_, sender_, poolID_, refCntr_, nElem_, nMin_)
Send an event to a state machine application (SMA) as known as active object through a queue using th...
#define RKH_TR_SMA_GET(actObj_, evt_, poolID_, refCntr_, nElem_, nMin_)
Get an event from the active object's queue.
#define RKH_TR_SMA_LIFO(actObj_, evt_, sender_, poolID_, refCntr_, nElem_, nMin_)
Send an event to a state machine application (SMA) as known as active object through a queue using th...
#define RKH_TR_FWK_EPREG(evtPool_, storageSize_, evtSize_, poolSize_)
Registers a new event pool into the event pool list.
#define RKH_TR_FWK_GCR(evt_, nUsed_, nMin_, sender_)
Effective recycling event.
#define RKH_TR_FWK_PSTATE(actObj_, pseudoStObj_)
Entry symbol table for pseudostate object.
#define RKH_TR_FWK_ACTOR(actorObj_, nm_)
Entry symbol table for actor object.
#define RKH_TR_FWK_EPOOL(poolId_, poolName_)
Entry symbol table for event pool object.
#define RKH_TR_FWK_AE(evtSize_, evt_, nUsed_, nMin_, sender_)
Allocates an event from the previously created event pool.
#define RKH_TR_FWK_STATE(actObj_, stateObj_)
Entry symbol table for state object.
#define RKH_TR_SM_DCH(actObj_, evt_, state_)
Executes a state machine in a run-to-completation (RTC) model.
#define RKH_COMPLETION_EVENT
This macro is used to indicate the completion event.
Definition: rkhitl.h:144
#define RKH_GET_PRIO(_ao)
Retrieves the priority number of an registered active object (SMA).
Definition: rkhsma.h:713
#define RKH_TE_SMA_LIFO
Send an event to a state machine application (SMA) as known as active object through a queue using th...
#define RKH_TE_FWK_EPOOL
Entry symbol table for event pool object.
#define RKH_FLG
#define RKH_TE_SM_DCH
Executes a state machine in a run-to-completation (RTC) model.
#define RKH_TE_FWK_ACTOR
Entry symbol table for actor object.
#define RKH_TE_FWK_OBJ
Entry symbol table for memory object.
#define RKH_TE_FWK_SIG
Entry symbol table for event signal.
#define RKH_TE_FWK_AE
Allocates an event from the previously created event pool.
#define RKH_XOR
#define RKH_ESC
#define RKH_TE_FWK_STATE
Entry symbol table for state object.
#define RKH_TE_SMA_ACT
Initializes and activates a previously created state machine application (SMA) as known as active obj...
#define RKH_TE_SMA_GET
Get an event from the active object's queue.
#define RKH_TE_FWK_EPREG
Registers a new event pool into the event pool list.
#define RKH_TE_FWK_PSTATE
Entry symbol table for pseudostate object.
#define RKH_TE_SMA_FIFO
Send an event to a state machine application (SMA) as known as active object through a queue using th...
#define RKH_TE_FWK_AO
Entry symbol table for active object.
#define RKH_TE_FWK_GCR
Effective recycling event.
Defines the trace records.
void rkh_trc_obj(RKH_TE_ID_T tre, rui8_t *obj, const char *obj_name)
Output object symbol record.
void rkh_trc_begin(RKH_TE_ID_T eid)
Store the trace record header in the stream.
void rkh_trc_ao(void *ao)
Output active object (AO) symbol record.
void rkh_trc_end(void)
Terminate the recorded trace event.
void rkh_trc_str(const char *s)
Store a string terminated in '\0' into the current trace event buffer without format information.
void rkh_trc_u8(rui8_t d)
Store a 8-bit data into the current trace event buffer without format information.
void rkh_trc_init(void)
Initializes the RKH's trace record service.
void rkh_trc_sig(RKH_SIG_T sig, const char *sig_name)
Output signal symbol record.
void rkh_trc_u16(rui16_t d)
Store a 16-bit data into the current trace event buffer without format information.
void rkh_trc_state(void *ao, rui8_t *state)
Output state symbol record.
void rkh_trc_u32(rui32_t d)
Store a 32-bit data into the current trace event buffer without format information.
ruint type
State type.
Definition: rkhsm.h:2009
const char * name
Name of state or pseudostate.
Definition: rkhsm.h:2020
Represents events without parameters.
Definition: rkhevt.h:170
RKH_SIG_T e
Signal of the event instance.
Definition: rkhevt.h:175
rui8_t nref
Attribute of dynamic events.
Definition: rkhevt.h:181
rui8_t pool
Attribute of dynamic events (0 for static event).
Definition: rkhevt.h:187
Constant parameters of state machine.
Definition: rkhsm.h:1829
const char * name
Name of State Machine Application (a.k.a Active Object).
Definition: rkhsm.h:1857
RKHROM RKH_ROM_T * romrkh
Points to constant parameters of state machine.
Definition: rkhsm.h:1910
Describes the SMA (active object in UML).
Definition: rkhsma.h:772
RKH_SM_T sm
State machine.
Definition: rkhsma.h:777
Describes the common properties of regular states (basic, composite, and submachine).
Definition: rkhsm.h:2065
RKH_BASE_T base
Maintains the basic information of state.
Definition: rkhsm.h:2070