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