56 #include "unity_fixture.h"
58 #include "Mock_rkhassert.h"
59 #include "Mock_rkhfwk_bittbl.h"
63 #define SIZEOF_BIT_TBL RKH_TRC_MAX_EVENTS_IN_BYTES
64 #define MAX_NUM_BITS (SIZEOF_BIT_TBL * 8)
65 #define FILTER_ON_BYTE 0
66 #define FILTER_OFF_BYTE 0xff
70 TEST_GROUP(toolForTest);
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
84 MockAssertCallback(
const char*
const file,
int line,
int cmock_num_calls)
90 setBitTbl(rui8_t *bt, rui16_t bit, rui8_t value)
95 TEST_ASSERT_TRUE( (bt != (rui8_t *)0) ||
96 (bit < MAX_NUM_BITS) ||
99 bitPos = (rui8_t)(bit & 7);
100 ix = (rui16_t)(bit >> 3);
104 *(bt + ix) |= maptbl[bitPos];
108 *(bt + ix) &= ~maptbl[bitPos];
113 getBitTbl(rui8_t *bt, rui16_t bit)
119 TEST_ASSERT_TRUE( (bt != (rui8_t *)0) ||
120 (bit < MAX_NUM_BITS));
122 bitPos = (rui8_t)(bit & 0x07);
123 ix = (rui16_t)(bit >> 3);
125 bitVal = (*(bt + ix) & maptbl[bitPos]) != 0;
130 setAllBitTbl(rui8_t *bt, ruint value, ruint size)
132 TEST_ASSERT_TRUE(bt != (rui8_t *)0);
133 memset(bitTbl, value, size);
137 checkBitTblAreOn(rui8_t *bt, rui16_t size)
143 for (i = 0, p = bt, res =
RKH_OK; i < size; ++i, ++p)
145 if (*p != FILTER_ON_BYTE)
155 setBlockBit(rui8_t *bt, ruint value, ruint to)
159 for (bitPos = 0; bitPos < to; ++bitPos)
161 setBitTbl(bt, bitPos, value);
167 rkh_trc_filterAllOn(rui8_t *ft,
RKH_TE_ID_T ftSize)
172 for (cnt = 0, p = ft; cnt < ftSize; ++cnt, ++p)
180 rkh_trc_filter_init(
void)
182 rkh_trc_filterAllOn(filStatus.signal->tbl,
184 rkh_trc_filterAllOn(filStatus.ao->tbl,
186 rkh_trc_filterAllOn(filStatus.event,
188 rkh_trc_filterAllOn(filStatus.group,
194 TEST_SETUP(toolForTest)
198 TEST_TEAR_DOWN(toolForTest)
208 TEST(toolForTest, getBitIndex0)
210 setAllBitTbl(bitTbl, 0, SIZEOF_BIT_TBL);
213 TEST_ASSERT_EQUAL(0, getBitTbl(bitTbl, 0));
214 TEST_ASSERT_EQUAL(1, getBitTbl(bitTbl, 1));
215 TEST_ASSERT_EQUAL(1, getBitTbl(bitTbl, 7));
218 TEST(toolForTest, getBitIndexX)
220 setAllBitTbl(bitTbl, 0, SIZEOF_BIT_TBL);
225 TEST_ASSERT_EQUAL(0, getBitTbl(bitTbl, 0));
226 TEST_ASSERT_EQUAL(1, getBitTbl(bitTbl, 7));
227 TEST_ASSERT_EQUAL(1, getBitTbl(bitTbl, 8));
228 TEST_ASSERT_EQUAL(1, getBitTbl(bitTbl, 9));
229 TEST_ASSERT_EQUAL(0, getBitTbl(bitTbl, 10));
230 TEST_ASSERT_EQUAL(1, getBitTbl(bitTbl, 22));
231 TEST_ASSERT_EQUAL(1, getBitTbl(bitTbl, 23));
234 TEST(toolForTest, setBitIndex0)
236 setAllBitTbl(bitTbl, 0, SIZEOF_BIT_TBL);
238 setBitTbl(bitTbl, 0, 1);
239 TEST_ASSERT_EQUAL_HEX8(0x01, bitTbl[0]);
240 TEST_ASSERT_EQUAL(1, getBitTbl(bitTbl, 0));
242 setBitTbl(bitTbl, 7, 1);
243 TEST_ASSERT_EQUAL_HEX8(0x81, bitTbl[0]);
244 TEST_ASSERT_EQUAL(1, getBitTbl(bitTbl, 7));
246 TEST_ASSERT_EQUAL_HEX8(0x00, bitTbl[1]);
247 TEST_ASSERT_EQUAL_HEX8(0x00, bitTbl[2]);
248 TEST_ASSERT_EQUAL_HEX8(0x00, bitTbl[3]);
251 TEST(toolForTest, resetBitIndex0)
253 setAllBitTbl(bitTbl, 0xff, SIZEOF_BIT_TBL);
255 setBitTbl(bitTbl, 0, 0);
256 TEST_ASSERT_EQUAL_HEX8(0xfe, bitTbl[0]);
257 TEST_ASSERT_EQUAL(0, getBitTbl(bitTbl, 0));
259 setBitTbl(bitTbl, 7, 0);
260 TEST_ASSERT_EQUAL_HEX8(0x7e, bitTbl[0]);
261 TEST_ASSERT_EQUAL(0, getBitTbl(bitTbl, 7));
263 TEST_ASSERT_EQUAL_HEX8(0xff, bitTbl[1]);
264 TEST_ASSERT_EQUAL_HEX8(0xff, bitTbl[2]);
265 TEST_ASSERT_EQUAL_HEX8(0xff, bitTbl[3]);
268 TEST(toolForTest, setBitIndexX)
270 setAllBitTbl(bitTbl, 0, SIZEOF_BIT_TBL);
272 setBitTbl(bitTbl, 8, 1);
273 TEST_ASSERT_EQUAL_HEX8(0x01, bitTbl[1]);
274 TEST_ASSERT_EQUAL(1, getBitTbl(bitTbl, 8));
276 setBitTbl(bitTbl, 17, 1);
277 TEST_ASSERT_EQUAL_HEX8(0x02, bitTbl[2]);
278 TEST_ASSERT_EQUAL(1, getBitTbl(bitTbl, 17));
280 TEST_ASSERT_EQUAL_HEX8(0x00, bitTbl[0]);
281 TEST_ASSERT_EQUAL_HEX8(0x00, bitTbl[3]);
284 TEST(toolForTest, resetBitIndexX)
286 setAllBitTbl(bitTbl, 0xff, SIZEOF_BIT_TBL);
288 setBitTbl(bitTbl, 8, 0);
289 TEST_ASSERT_EQUAL_HEX8(0xfe, bitTbl[1]);
290 TEST_ASSERT_EQUAL(0, getBitTbl(bitTbl, 8));
292 setBitTbl(bitTbl, 17, 0);
293 TEST_ASSERT_EQUAL_HEX8(0xfd, bitTbl[2]);
294 TEST_ASSERT_EQUAL(0, getBitTbl(bitTbl, 17));
296 TEST_ASSERT_EQUAL_HEX8(0xff, bitTbl[0]);
297 TEST_ASSERT_EQUAL_HEX8(0xff, bitTbl[3]);
307 rkh_trc_filter_init();
309 Mock_rkhfwk_bittbl_Init();
312 TEST_TEAR_DOWN(filter)
314 Mock_rkhfwk_bittbl_Verify();
315 Mock_rkhfwk_bittbl_Destroy();
324 TEST(filter, filEventsAreOnAfterInit)
326 TEST_ASSERT_TRUE(checkBitTblAreOn(filStatus.signal->tbl,
327 filStatus.signal->size) ==
RKH_OK);
329 TEST_ASSERT_TRUE(checkBitTblAreOn(filStatus.ao->tbl,
330 filStatus.ao->size) ==
RKH_OK);
332 TEST_ASSERT_TRUE(checkBitTblAreOn(filStatus.event,
335 TEST_ASSERT_TRUE(checkBitTblAreOn(filStatus.group,
339 TEST(filter, turnOffOneFilEvent)
341 RKH_GM_OFFSET_T offset;
343 offset = RKH_SM_TTBL_OFFSET;
344 bitTbl[offset] = 0x01;
345 rkh_bittbl_getBitMask_ExpectAndReturn(GETEVT(
RKH_TE_SM_INIT) & 7, 1);
350 TEST_ASSERT_EQUAL(1, getBitTbl(&filStatus.event[offset], 0));
351 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.event,
353 TEST_ASSERT_EQUAL_HEX8(0x01,
355 TEST_ASSERT_EQUAL_HEX8(0x08, *filStatus.group);
358 TEST(filter, turnOnOneFilEvent)
360 bitTbl[RKH_SM_TTBL_OFFSET + 0] = 0x02;
362 rkh_bittbl_getBitMask_ExpectAndReturn(GETEVT(
RKH_TE_SM_INIT) & 7, 1);
366 rkh_bittbl_getBitMask_ExpectAndReturn(GETEVT(
RKH_TE_SM_CLRH) & 7, 2);
370 rkh_bittbl_getBitMask_ExpectAndReturn(GETEVT(
RKH_TE_SM_INIT) & 7, 1);
373 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.event,
375 TEST_ASSERT_EQUAL_HEX8(0x08, *filStatus.group);
378 TEST(filter, turnOffMultipleFilEvent)
380 RKH_GM_OFFSET_T offset;
382 offset = RKH_SM_TTBL_OFFSET;
383 bitTbl[offset] = 0x01;
384 bitTbl[offset + 1] = 0x01;
386 rkh_bittbl_getBitMask_ExpectAndReturn(GETEVT(
RKH_TE_SM_INIT) & 7, 1);
394 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.event,
398 TEST(filter, allOffFilEvent)
403 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.event,
405 TEST_ASSERT_EQUAL_HEX8(0xff, *filStatus.group);
408 TEST(filter, allOnFilEvent)
411 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.event,
413 TEST_ASSERT_EQUAL_HEX8(0x00, *filStatus.group);
416 TEST(filter, isOnOffFilEvent)
418 rkh_bittbl_getBitMask_ExpectAndReturn(GETGRP(
RKH_TE_FWK_OBJ), 0x20);
422 setBitTbl(filStatus.group,
RKH_TG_MP, FILTER_OFF);
423 rkh_bittbl_getBitMask_ExpectAndReturn(GETGRP(
RKH_TE_MP_INIT), 0x01);
424 rkh_bittbl_getBitMask_ExpectAndReturn(GETEVT(
RKH_TE_MP_INIT) & 7, 0x01);
428 rkh_bittbl_getBitMask_ExpectAndReturn(GETGRP(
RKH_TE_MP_INIT), 0x01);
429 rkh_bittbl_getBitMask_ExpectAndReturn(GETEVT(
RKH_TE_MP_INIT) & 7, 0x01);
433 TEST(filter, upperAndLowerBoundsFilEvent)
438 rkh_bittbl_getBitMask_ExpectAndReturn(GETGRP(
RKH_TE_MP_INIT), 0x01);
439 rkh_bittbl_getBitMask_ExpectAndReturn(GETEVT(
RKH_TE_MP_INIT) & 7, 0x01);
442 rkh_bittbl_getBitMask_ExpectAndReturn(GETGRP(RKH_TE_UT_IGNORE_ARG), 0x80);
443 rkh_bittbl_getBitMask_ExpectAndReturn(GETEVT(RKH_TE_UT_IGNORE_ARG) & 7,
447 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.event,
451 TEST(filter, setAllEventsFromOneGroup)
457 filterTo = RKH_SM_END;
458 offset = filStatus.grpFilMap[GETGRP(
RKH_SM_START)].offset;
459 setBlockBit(&bitTbl[offset], 1, filterTo - filterFrom);
461 for (filter = filterFrom; filter < filterTo; ++filter)
463 evt = GETEVT(filter) & 7;
464 rkh_bittbl_getBitMask_ExpectAndReturn(evt, maptbl[evt]);
465 rkh_bittbl_getBitMask_ExpectAndReturn(
RKH_TG_SM, 8);
469 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.event,
473 TEST(filter, outOfBoundsProducesRuntimeError)
475 rkh_assert_Expect(
"rkhtrc_filter", 0);
476 rkh_assert_IgnoreArg_line();
477 rkh_assert_StubWithCallback(MockAssertCallback);
482 TEST(filter, turnOffOneGroup)
486 TEST_ASSERT_EQUAL_HEX8(0x01, *filStatus.group);
489 TEST(filter, turnOnOneGroup)
496 TEST_ASSERT_EQUAL_HEX8(0x00, *filStatus.group);
499 TEST(filter, allOnOffGroup)
502 TEST_ASSERT_EQUAL_HEX8(0xff, *filStatus.group);
504 TEST_ASSERT_EQUAL_HEX8(0x00, *filStatus.group);
507 TEST(filter, turnOnOffMultipleGroups)
518 TEST_ASSERT_EQUAL_HEX8(0x89, *filStatus.group);
529 TEST_ASSERT_EQUAL_HEX8(0x00, *filStatus.group);
532 TEST(filter, turnOffOneGroupChangedItsEventFilters)
534 RKHROM RKH_GMTBL_T *pTrcMap;
538 TEST_ASSERT_EQUAL_HEX8(0x80, *filStatus.group);
540 pTrcMap = &filStatus.grpFilMap[
RKH_TG_UT];
541 memset(&bitTbl[pTrcMap->offset], FILTER_OFF_BYTE, pTrcMap->range);
543 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.event,
547 TEST(filter, turnOffOneSymFil)
551 rkh_bittbl_getBitMask_ExpectAndReturn(0, maptbl[0]);
554 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.ao->tbl, RKH_TRC_MAX_SMA);
557 TEST(filter, turnOnOneSymFil)
561 rkh_bittbl_getBitMask_ExpectAndReturn(RKH_TRC_MAX_SMA - 1,
562 maptbl[RKH_TRC_MAX_SMA - 1]);
565 rkh_bittbl_getBitMask_ExpectAndReturn(RKH_TRC_MAX_SMA - 1,
566 maptbl[RKH_TRC_MAX_SMA - 1]);
569 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.ao->tbl, RKH_TRC_MAX_SMA);
572 TEST(filter, turnOnOffMultipleSymFil)
576 rkh_bittbl_getBitMask_ExpectAndReturn(0, maptbl[0]);
579 rkh_bittbl_getBitMask_ExpectAndReturn(3, maptbl[3]);
582 rkh_bittbl_getBitMask_ExpectAndReturn(7, maptbl[7]);
585 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.ao->tbl, RKH_TRC_MAX_SMA);
588 TEST(filter, allOffOnSymFil)
590 setAllBitTbl(bitTbl, FILTER_OFF_BYTE, RKH_TRC_MAX_SMA);
592 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.ao->tbl, RKH_TRC_MAX_SMA);
594 setAllBitTbl(bitTbl, FILTER_ON_BYTE, RKH_TRC_MAX_SMA);
596 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.ao->tbl, RKH_TRC_MAX_SMA);
599 TEST(filter, isOnOffSymFil)
601 rkh_bittbl_getBitMask_ExpectAndReturn(0, maptbl[0]);
604 setBitTbl(filStatus.ao->tbl, 0, FILTER_OFF);
605 setBitTbl(filStatus.ao->tbl, 3, FILTER_OFF);
606 rkh_bittbl_getBitMask_ExpectAndReturn(0, maptbl[0]);
608 rkh_bittbl_getBitMask_ExpectAndReturn(3, maptbl[3]);
611 rkh_bittbl_getBitMask_ExpectAndReturn(0, maptbl[0]);
612 setBitTbl(filStatus.ao->tbl, 0, FILTER_ON);
616 TEST(filter, upperAndLowerBoundsSymFil)
618 setBitTbl(bitTbl, 0, FILTER_OFF);
619 setBitTbl(bitTbl, RKH_TRC_MAX_SMA * 8, FILTER_OFF);
621 rkh_bittbl_getBitMask_ExpectAndReturn(0, maptbl[0]);
624 rkh_bittbl_getBitMask_ExpectAndReturn(0, maptbl[0]);
627 TEST_ASSERT_EQUAL_MEMORY(bitTbl, filStatus.ao->tbl, RKH_TRC_MAX_SMA);
630 TEST(filter, outOfBoundsProducesRuntimeErrorSymFil)
632 rkh_assert_Expect(
"rkhtrc_filter", 0);
633 rkh_assert_IgnoreArg_line();
634 rkh_assert_StubWithCallback(MockAssertCallback);
636 rkh_trc_symFil(RKHFilterSma, (filStatus.ao->size * 8) + 1, FILTER_OFF);
#define RKH_FAIL
Standard define.
#define RKH_TE_MP_INIT
Initializes the previously allocated memory pool data strcuture RKH_MEMPOOL_T.
#define RKH_TRC_ALL_EVENTS
Emit or suppress all trace events.
#define RKH_TE_SM_TS_STATE
Destination state or pseudostate of a transition segment.
#define RKH_TG_MP
Memory Pool group (MP)
void rkh_trc_filter_get(RKH_FilterTbl *outFilterTbl)
Get a memory reference to every trace filter table.
#define RKH_SM_START
Trace event offset.
#define RKH_TG_UT
Unit test harness group (UT)
#define RKH_OK
Standard define.
#define RKH_TE_FWK_OBJ
Entry symbol table for memory object.
Specifies the runtime filter operations for the trace facility.
#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.
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.
#define RKH_FALSE
Standard define.
#define RKH_TG_SM
State Machine group (SM)
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.
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.
rui8_t RKH_TG_T
Group of events.
#define RKH_TE_SM_CLRH
Erase the history of a state. It can be a shallow or deep history.
void rkh_trc_filter_event_(rui8_t ctrl, RKH_TE_ID_T evt)
Emit or suppress a specific event.
#define RKH_TRUE
Standard define.
#define RKH_TE_SM_INIT
Inits a previously created state machine calling its initializing action.
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.
#define RKH_TRC_SET_ALL(mode_)
Emit or supress tracing for all signal/active objects.