60 #include "Mock_rkhassert.h"
61 #include "Mock_rkhfwk_bittbl.h"
66 #define SIZEOF_BIT_TBL RKH_TRC_MAX_EVENTS_IN_BYTES
67 #define MAX_NUM_BITS (SIZEOF_BIT_TBL * 8)
68 #define FILTER_ON_BYTE 0
69 #define FILTER_OFF_BYTE 0xff
74 static RKH_FilterTbl filStatus;
75 static rui8_t bitTbl[SIZEOF_BIT_TBL];
76 static const rui8_t maptbl[] =
78 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
82 static void setUp_toolForTest(
void);
83 static void tearDown_toolForTest(
void);
84 static void setUp_filter(
void);
85 static void tearDown_filter(
void);
89 MockAssertCallback(
const char*
const file,
int line,
int cmock_num_calls)
95 setBitTbl(rui8_t *bt, rui16_t bit, rui8_t value)
100 TEST_ASSERT_TRUE( (bt != (rui8_t *)0) ||
101 (bit < MAX_NUM_BITS) ||
104 bitPos = (rui8_t)(bit & 7);
105 ix = (rui16_t)(bit >> 3);
109 *(bt + ix) |= maptbl[bitPos];
113 *(bt + ix) &= ~maptbl[bitPos];
118 getBitTbl(rui8_t *bt, rui16_t bit)
124 TEST_ASSERT_TRUE( (bt != (rui8_t *)0) ||
125 (bit < MAX_NUM_BITS));
127 bitPos = (rui8_t)(bit & 0x07);
128 ix = (rui16_t)(bit >> 3);
130 bitVal = (*(bt + ix) & maptbl[bitPos]) != 0;
135 setAllBitTbl(rui8_t *bt, ruint value, ruint size)
137 TEST_ASSERT_TRUE(bt != (rui8_t *)0);
138 memset(bitTbl, value, size);
142 checkBitTblAreOn(rui8_t *bt, rui16_t size)
148 for (i = 0, p = bt, res =
RKH_OK; i < size; ++i, ++p)
150 if (*p != FILTER_ON_BYTE)
160 setBlockBit(rui8_t *bt, ruint value, ruint to)
164 for (bitPos = 0; bitPos < to; ++bitPos)
166 setBitTbl(bt, bitPos, value);
172 rkh_trc_filterAllOn(rui8_t *ft,
RKH_TE_ID_T ftSize)
177 for (cnt = 0, p = ft; cnt < ftSize; ++cnt, ++p)
185 rkh_trc_filter_init(
void)
187 rkh_trc_filterAllOn(filStatus.signal->tbl,
189 rkh_trc_filterAllOn(filStatus.ao->tbl,
191 rkh_trc_filterAllOn(filStatus.event,
193 rkh_trc_filterAllOn(filStatus.group,
208 tearDown_toolForTest();
214 setUp_toolForTest(
void)
219 tearDown_toolForTest(
void)
230 test_getBitIndex0(
void)
232 setAllBitTbl(bitTbl, 0, SIZEOF_BIT_TBL);
235 TEST_ASSERT_EQUAL(0, getBitTbl(bitTbl, 0));
236 TEST_ASSERT_EQUAL(1, getBitTbl(bitTbl, 1));
237 TEST_ASSERT_EQUAL(1, getBitTbl(bitTbl, 7));
241 test_getBitIndexX(
void)
243 setAllBitTbl(bitTbl, 0, SIZEOF_BIT_TBL);
248 TEST_ASSERT_EQUAL(0, getBitTbl(bitTbl, 0));
249 TEST_ASSERT_EQUAL(1, getBitTbl(bitTbl, 7));
250 TEST_ASSERT_EQUAL(1, getBitTbl(bitTbl, 8));
251 TEST_ASSERT_EQUAL(1, getBitTbl(bitTbl, 9));
252 TEST_ASSERT_EQUAL(0, getBitTbl(bitTbl, 10));
253 TEST_ASSERT_EQUAL(1, getBitTbl(bitTbl, 22));
254 TEST_ASSERT_EQUAL(1, getBitTbl(bitTbl, 23));
258 test_setBitIndex0(
void)
260 setAllBitTbl(bitTbl, 0, SIZEOF_BIT_TBL);
262 setBitTbl(bitTbl, 0, 1);
263 TEST_ASSERT_EQUAL_HEX8(0x01, bitTbl[0]);
264 TEST_ASSERT_EQUAL(1, getBitTbl(bitTbl, 0));
266 setBitTbl(bitTbl, 7, 1);
267 TEST_ASSERT_EQUAL_HEX8(0x81, bitTbl[0]);
268 TEST_ASSERT_EQUAL(1, getBitTbl(bitTbl, 7));
270 TEST_ASSERT_EQUAL_HEX8(0x00, bitTbl[1]);
271 TEST_ASSERT_EQUAL_HEX8(0x00, bitTbl[2]);
272 TEST_ASSERT_EQUAL_HEX8(0x00, bitTbl[3]);
276 test_resetBitIndex0(
void)
278 setAllBitTbl(bitTbl, 0xff, SIZEOF_BIT_TBL);
280 setBitTbl(bitTbl, 0, 0);
281 TEST_ASSERT_EQUAL_HEX8(0xfe, bitTbl[0]);
282 TEST_ASSERT_EQUAL(0, getBitTbl(bitTbl, 0));
284 setBitTbl(bitTbl, 7, 0);
285 TEST_ASSERT_EQUAL_HEX8(0x7e, bitTbl[0]);
286 TEST_ASSERT_EQUAL(0, getBitTbl(bitTbl, 7));
288 TEST_ASSERT_EQUAL_HEX8(0xff, bitTbl[1]);
289 TEST_ASSERT_EQUAL_HEX8(0xff, bitTbl[2]);
290 TEST_ASSERT_EQUAL_HEX8(0xff, bitTbl[3]);
294 test_setBitIndexX(
void)
296 setAllBitTbl(bitTbl, 0, SIZEOF_BIT_TBL);
298 setBitTbl(bitTbl, 8, 1);
299 TEST_ASSERT_EQUAL_HEX8(0x01, bitTbl[1]);
300 TEST_ASSERT_EQUAL(1, getBitTbl(bitTbl, 8));
302 setBitTbl(bitTbl, 17, 1);
303 TEST_ASSERT_EQUAL_HEX8(0x02, bitTbl[2]);
304 TEST_ASSERT_EQUAL(1, getBitTbl(bitTbl, 17));
306 TEST_ASSERT_EQUAL_HEX8(0x00, bitTbl[0]);
307 TEST_ASSERT_EQUAL_HEX8(0x00, bitTbl[3]);
311 test_resetBitIndexX(
void)
313 setAllBitTbl(bitTbl, 0xff, SIZEOF_BIT_TBL);
315 setBitTbl(bitTbl, 8, 0);
316 TEST_ASSERT_EQUAL_HEX8(0xfe, bitTbl[1]);
317 TEST_ASSERT_EQUAL(0, getBitTbl(bitTbl, 8));
319 setBitTbl(bitTbl, 17, 0);
320 TEST_ASSERT_EQUAL_HEX8(0xfd, bitTbl[2]);
321 TEST_ASSERT_EQUAL(0, getBitTbl(bitTbl, 17));
323 TEST_ASSERT_EQUAL_HEX8(0xff, bitTbl[0]);
324 TEST_ASSERT_EQUAL_HEX8(0xff, bitTbl[3]);
335 rkh_trc_filter_init();
337 Mock_rkhfwk_bittbl_Init();
341 tearDown_filter(
void)
343 Mock_rkhfwk_bittbl_Verify();
344 Mock_rkhfwk_bittbl_Destroy();
354 test_filEventsAreOnAfterInit(
void)
356 TEST_ASSERT_TRUE(checkBitTblAreOn(filStatus.signal->tbl,
357 filStatus.signal->size) ==
RKH_OK);
359 TEST_ASSERT_TRUE(checkBitTblAreOn(filStatus.ao->tbl,
360 filStatus.ao->size) ==
RKH_OK);
362 TEST_ASSERT_TRUE(checkBitTblAreOn(filStatus.event,
365 TEST_ASSERT_TRUE(checkBitTblAreOn(filStatus.group,
370 test_turnOffOneFilEvent(
void)
372 RKH_GM_OFFSET_T offset;
374 offset = RKH_SM_TTBL_OFFSET;
375 bitTbl[offset] = 0x01;
376 rkh_bittbl_getBitMask_ExpectAndReturn(GETEVT(
RKH_TE_SM_INIT) & 7, 1);
381 TEST_ASSERT_EQUAL(1, getBitTbl(&filStatus.event[offset], 0));
382 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.event,
384 TEST_ASSERT_EQUAL_HEX8(0x01,
386 TEST_ASSERT_EQUAL_HEX8(0x08, *filStatus.group);
390 test_turnOnOneFilEvent(
void)
392 bitTbl[RKH_SM_TTBL_OFFSET + 0] = 0x02;
394 rkh_bittbl_getBitMask_ExpectAndReturn(GETEVT(
RKH_TE_SM_INIT) & 7, 1);
398 rkh_bittbl_getBitMask_ExpectAndReturn(GETEVT(
RKH_TE_SM_CLRH) & 7, 2);
402 rkh_bittbl_getBitMask_ExpectAndReturn(GETEVT(
RKH_TE_SM_INIT) & 7, 1);
405 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.event,
407 TEST_ASSERT_EQUAL_HEX8(0x08, *filStatus.group);
411 test_turnOffMultipleFilEvent(
void)
413 RKH_GM_OFFSET_T offset;
415 offset = RKH_SM_TTBL_OFFSET;
416 bitTbl[offset] = 0x01;
417 bitTbl[offset + 1] = 0x01;
419 rkh_bittbl_getBitMask_ExpectAndReturn(GETEVT(
RKH_TE_SM_INIT) & 7, 1);
427 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.event,
432 test_allOffFilEvent(
void)
437 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.event,
439 TEST_ASSERT_EQUAL_HEX8(0xff, *filStatus.group);
443 test_allOnFilEvent(
void)
446 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.event,
448 TEST_ASSERT_EQUAL_HEX8(0x00, *filStatus.group);
452 test_isOnOffFilEvent(
void)
454 rkh_bittbl_getBitMask_ExpectAndReturn(GETGRP(
RKH_TE_FWK_OBJ), 0x20);
458 setBitTbl(filStatus.group,
RKH_TG_MP, FILTER_OFF);
459 rkh_bittbl_getBitMask_ExpectAndReturn(GETGRP(
RKH_TE_MP_INIT), 0x01);
460 rkh_bittbl_getBitMask_ExpectAndReturn(GETEVT(
RKH_TE_MP_INIT) & 7, 0x01);
464 rkh_bittbl_getBitMask_ExpectAndReturn(GETGRP(
RKH_TE_MP_INIT), 0x01);
465 rkh_bittbl_getBitMask_ExpectAndReturn(GETEVT(
RKH_TE_MP_INIT) & 7, 0x01);
470 test_upperAndLowerBoundsFilEvent(
void)
475 rkh_bittbl_getBitMask_ExpectAndReturn(GETGRP(
RKH_TE_MP_INIT), 0x01);
476 rkh_bittbl_getBitMask_ExpectAndReturn(GETEVT(
RKH_TE_MP_INIT) & 7, 0x01);
479 rkh_bittbl_getBitMask_ExpectAndReturn(GETGRP(RKH_TE_UT_IGNORE_ARG), 0x80);
480 rkh_bittbl_getBitMask_ExpectAndReturn(GETEVT(RKH_TE_UT_IGNORE_ARG) & 7,
484 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.event,
489 test_setAllEventsFromOneGroup(
void)
495 filterTo = RKH_SM_END;
496 offset = filStatus.grpFilMap[GETGRP(
RKH_SM_START)].offset;
497 setBlockBit(&bitTbl[offset], 1, filterTo - filterFrom);
499 for (filter = filterFrom; filter < filterTo; ++filter)
501 evt = GETEVT(filter) & 7;
502 rkh_bittbl_getBitMask_ExpectAndReturn(evt, maptbl[evt]);
503 rkh_bittbl_getBitMask_ExpectAndReturn(
RKH_TG_SM, 8);
507 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.event,
512 test_outOfBoundsProducesRuntimeError(
void)
514 rkh_assert_Expect(
"rkhtrc_filter", 0);
515 rkh_assert_IgnoreArg_file();
516 rkh_assert_IgnoreArg_line();
517 rkh_assert_StubWithCallback(MockAssertCallback);
523 test_turnOffOneGroup(
void)
527 TEST_ASSERT_EQUAL_HEX8(0x01, *filStatus.group);
531 test_turnOnOneGroup(
void)
538 TEST_ASSERT_EQUAL_HEX8(0x00, *filStatus.group);
542 test_allOnOffGroup(
void)
545 TEST_ASSERT_EQUAL_HEX8(0xff, *filStatus.group);
547 TEST_ASSERT_EQUAL_HEX8(0x00, *filStatus.group);
551 test_turnOnOffMultipleGroups(
void)
562 TEST_ASSERT_EQUAL_HEX8(0x89, *filStatus.group);
573 TEST_ASSERT_EQUAL_HEX8(0x00, *filStatus.group);
577 test_turnOffOneGroupChangedItsEventFilters(
void)
579 RKHROM RKH_GMTBL_T *pTrcMap;
583 TEST_ASSERT_EQUAL_HEX8(0x80, *filStatus.group);
585 pTrcMap = &filStatus.grpFilMap[
RKH_TG_UT];
586 memset(&bitTbl[pTrcMap->offset], FILTER_OFF_BYTE, pTrcMap->range);
588 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.event,
593 test_turnOffOneSymFil(
void)
597 rkh_bittbl_getBitMask_ExpectAndReturn(0, maptbl[0]);
600 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.ao->tbl, RKH_TRC_MAX_SMA);
604 test_turnOnOneSymFil(
void)
608 rkh_bittbl_getBitMask_ExpectAndReturn(RKH_TRC_MAX_SMA - 1,
609 maptbl[RKH_TRC_MAX_SMA - 1]);
612 rkh_bittbl_getBitMask_ExpectAndReturn(RKH_TRC_MAX_SMA - 1,
613 maptbl[RKH_TRC_MAX_SMA - 1]);
616 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.ao->tbl, RKH_TRC_MAX_SMA);
620 test_turnOnOffMultipleSymFil(
void)
624 rkh_bittbl_getBitMask_ExpectAndReturn(0, maptbl[0]);
627 rkh_bittbl_getBitMask_ExpectAndReturn(3, maptbl[3]);
630 rkh_bittbl_getBitMask_ExpectAndReturn(7, maptbl[7]);
633 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.ao->tbl, RKH_TRC_MAX_SMA);
637 test_allOffOnSymFil(
void)
639 setAllBitTbl(bitTbl, FILTER_OFF_BYTE, RKH_TRC_MAX_SMA);
641 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.ao->tbl, RKH_TRC_MAX_SMA);
643 setAllBitTbl(bitTbl, FILTER_ON_BYTE, RKH_TRC_MAX_SMA);
645 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.ao->tbl, RKH_TRC_MAX_SMA);
649 test_isOnOffSymFil(
void)
651 rkh_bittbl_getBitMask_ExpectAndReturn(0, maptbl[0]);
654 setBitTbl(filStatus.ao->tbl, 0, FILTER_OFF);
655 setBitTbl(filStatus.ao->tbl, 3, FILTER_OFF);
656 rkh_bittbl_getBitMask_ExpectAndReturn(0, maptbl[0]);
658 rkh_bittbl_getBitMask_ExpectAndReturn(3, maptbl[3]);
661 rkh_bittbl_getBitMask_ExpectAndReturn(0, maptbl[0]);
662 setBitTbl(filStatus.ao->tbl, 0, FILTER_ON);
667 test_upperAndLowerBoundsSymFil(
void)
669 setBitTbl(bitTbl, 0, FILTER_OFF);
670 setBitTbl(bitTbl, RKH_TRC_MAX_SMA * 8, FILTER_OFF);
672 rkh_bittbl_getBitMask_ExpectAndReturn(0, maptbl[0]);
675 rkh_bittbl_getBitMask_ExpectAndReturn(0, maptbl[0]);
678 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.ao->tbl, RKH_TRC_MAX_SMA);
682 test_outOfBoundsProducesRuntimeErrorSymFil(
void)
684 rkh_assert_Expect(
"rkhtrc_filter", 0);
685 rkh_assert_IgnoreArg_file();
686 rkh_assert_IgnoreArg_line();
687 rkh_assert_StubWithCallback(MockAssertCallback);
689 rkh_trc_symFil(RKHFilterSma, (filStatus.ao->size * 8) + 1, FILTER_OFF);
#define RKH_FAIL
Standard define.
#define RKH_OK
Standard define.
#define RKH_FALSE
Standard define.
#define RKH_TRUE
Standard define.
rui8_t RKH_TG_T
Group of events.
#define RKH_TE_FWK_OBJ
Entry symbol table for memory object.
#define RKH_TE_SM_TS_STATE
Destination state or pseudostate of a transition segment.
#define RKH_TG_MP
Memory Pool group (MP)
#define RKH_TRC_SET_ALL(mode_)
Emit or supress tracing for all signal/active objects.
#define RKH_SM_START
Trace event offset.
#define RKH_TE_SM_CLRH
Erase the history of a state. It can be a shallow or deep history.
#define RKH_TRC_ALL_EVENTS
Emit or suppress all trace events.
#define RKH_TG_SM
State Machine group (SM)
#define RKH_TE_SM_INIT
Inits a previously created state machine calling its initializing action.
#define RKH_TRC_MAX_EVENTS_IN_BYTES
Defines the size of trace filter table according to RKH_TOT_NUM_TRC_EVTS and RKH_TRC_MAX_EVENTS.
rui8_t RKH_TE_ID_T
Describes a trace event identification (ID).
#define RKH_TRC_ALL_GROUPS
Emit or suppress tracing for all groups and events.
#define RKH_TG_UT
Unit test harness group (UT)
#define RKH_TE_MP_INIT
Initializes the previously allocated memory pool data strcuture RKH_MEMPOOL_T.
Specifies the runtime filter operations for the trace facility.
void rkh_trc_filter_group_(rui8_t ctrl, RKH_TG_T grp, rui8_t mode)
Emit or suppress all trace events from a specific group.
void rkh_trc_filter_event_(rui8_t ctrl, RKH_TE_ID_T evt)
Emit or suppress a specific event.
rbool_t rkh_trc_symFil_isoff(RKHFilter fd, RKH_TRC_FSLOT slot)
Test the active objecto or signal filter condition.
rbool_t rkh_trc_isoff_(RKH_TE_ID_T e)
Test the group and event filter condition.
void rkh_trc_filter_get(RKH_FilterTbl *outFilterTbl)
Get a memory reference to every trace filter table.
void rkh_trc_symFil(RKHFilter fd, RKH_TRC_FSLOT slot, rui8_t mode)
Emmit or suppresse trace events related to a particular active object or event signal.