60 #include "Mock_rkhassert.h"
61 #include "Mock_rkhfwk_evtpool.h"
62 #include "Mock_rkhtrc_record.h"
63 #include "Mock_rkhtrc_filter.h"
64 #include "Mock_rkhport.h"
71 static rui8_t *storage;
76 MockAssertCallback(
const char*
const file,
int line,
int cmock_num_calls)
85 Mock_rkhassert_Init();
86 Mock_rkhfwk_evtpool_Init();
87 rkh_trc_isoff__IgnoreAndReturn(
RKH_FALSE);
94 Mock_rkhassert_Verify();
95 Mock_rkhfwk_evtpool_Verify();
96 Mock_rkhassert_Destroy();
97 Mock_rkhfwk_evtpool_Destroy();
107 test_RegisterOneEventPool(
void)
109 rkh_evtPool_getPool_ExpectAndReturn(storage,
sizeof(storage), 4,
115 test_RegisterMultipleEventPool(
void)
121 rkh_evtPool_getPool_ExpectAndReturn(storage,
sizeof(storage), 4,
128 test_Fails_ExceedsNumberOfAllowedEventPools(
void)
134 rkh_evtPool_getPool_ExpectAndReturn(storage,
sizeof(storage), 4,
137 rkh_assert_Expect(
"rkhfwk_dynevt", 0);
138 rkh_assert_IgnoreArg_file();
139 rkh_assert_IgnoreArg_line();
140 rkh_assert_StubWithCallback(MockAssertCallback);
149 test_Fails_UnavailablePool(
void)
151 rkh_evtPool_getPool_ExpectAndReturn(storage,
sizeof(storage), 4,
153 rkh_assert_Expect(
"rkhfwk_dynevt", 0);
154 rkh_assert_IgnoreArg_file();
155 rkh_assert_IgnoreArg_line();
156 rkh_assert_StubWithCallback(MockAssertCallback);
162 test_Fails_TriesAllocateOneEvtWithoutAssignedPool(
void)
166 rkh_assert_Expect(
"rkhfwk_dynevt", 0);
167 rkh_assert_IgnoreArg_file();
168 rkh_assert_IgnoreArg_line();
169 rkh_assert_StubWithCallback(MockAssertCallback);
172 TEST_ASSERT_NULL(evt);
176 test_AllocateOneEvt(
void)
192 for (i = 0, epAddress = (
int *)0xdead0000, blockSize = 4;
194 ++i, (blockSize *= 2), ++epAddress)
196 rkh_evtPool_getPool_ExpectAndReturn(storage,
sizeof(storage),
198 (RKHEvtPool *)epAddress);
201 epAddress = (
int *)0xdead0000;
202 rkh_evtPool_getBlockSize_ExpectAndReturn((RKHEvtPool *)(epAddress), 4);
203 rkh_evtPool_getBlockSize_ExpectAndReturn((RKHEvtPool *)(epAddress + 1), 8);
204 rkh_evtPool_getBlockSize_ExpectAndReturn((RKHEvtPool *)(epAddress + 2),
206 rkh_evtPool_get_ExpectAndReturn((RKHEvtPool *)(epAddress + 2),
209 pEvt =
rkh_fwk_ae(9, sig, (
const void *)0xbeaf);
211 TEST_ASSERT_EQUAL_PTR(expectedEvt, pEvt);
212 TEST_ASSERT_EQUAL(sig, pEvt->
e);
213 TEST_ASSERT_EQUAL(pool, pEvt->
pool);
214 TEST_ASSERT_EQUAL(nRef, pEvt->
nref);
218 test_Fails_ExceededBlockSize(
void)
224 for (i = 0, epAddress = (
int *)0xdead0000, blockSize = 4;
226 ++i, (blockSize *= 2), ++epAddress)
228 rkh_evtPool_getPool_ExpectAndReturn(storage,
sizeof(storage),
230 (RKHEvtPool *)epAddress);
234 epAddress = (
int *)0xdead0000;
235 rkh_evtPool_getBlockSize_ExpectAndReturn((RKHEvtPool *)(epAddress + 0), 4);
236 rkh_evtPool_getBlockSize_ExpectAndReturn((RKHEvtPool *)(epAddress + 1), 8);
237 rkh_evtPool_getBlockSize_ExpectAndReturn((RKHEvtPool *)(epAddress + 2), 16);
238 rkh_evtPool_getBlockSize_ExpectAndReturn((RKHEvtPool *)(epAddress + 3), 32);
240 rkh_assert_Expect(
"rkhfwk_dynevt", 0);
241 rkh_assert_IgnoreArg_file();
242 rkh_assert_IgnoreArg_line();
243 rkh_assert_StubWithCallback(MockAssertCallback);
245 evt =
rkh_fwk_ae(33, 1, (
const void *)0xbeaf);
247 TEST_ASSERT_NULL(evt);
251 test_Fails_UnavailableBlockFromPool(
void)
257 for (i = 0, epAddress = (
int *)0xdead0000, blockSize = 4;
259 ++i, (blockSize *= 2), ++epAddress)
261 rkh_evtPool_getPool_ExpectAndReturn(storage,
sizeof(storage),
263 (RKHEvtPool *)epAddress);
266 epAddress = (
int *)0xdead0000;
267 rkh_evtPool_getBlockSize_ExpectAndReturn((RKHEvtPool *)(epAddress + 0), 4);
268 rkh_evtPool_getBlockSize_ExpectAndReturn((RKHEvtPool *)(epAddress + 1), 8);
269 rkh_evtPool_getBlockSize_ExpectAndReturn((RKHEvtPool *)(epAddress + 2), 16);
270 rkh_evtPool_get_ExpectAndReturn((RKHEvtPool *)(epAddress + 2), 0);
272 rkh_assert_Expect(
"rkhfwk_dynevt", 0);
273 rkh_assert_IgnoreArg_file();
274 rkh_assert_IgnoreArg_line();
275 rkh_assert_StubWithCallback(MockAssertCallback);
279 TEST_ASSERT_NULL(evt);
283 test_ReservesOneEvt(
void)
290 rkh_enter_critical_Expect();
291 rkh_exit_critical_Expect();
295 TEST_ASSERT_EQUAL(8, evt.
e);
296 TEST_ASSERT_EQUAL(16 + 1, evt.
nref);
297 TEST_ASSERT_EQUAL(32, evt.
pool);
301 test_TriesRecycleNotReferencedEvt(
void)
310 test_TriesRecycleMultipleReferencedEvt(
void)
315 rkh_enter_critical_Expect();
316 rkh_exit_critical_Expect();
320 TEST_ASSERT_EQUAL(3, evt.
nref);
324 test_RecycleEvt(
void)
330 rkh_evtPool_getPool_ExpectAndReturn(storage,
sizeof(storage), 4,
332 rkh_enter_critical_Expect();
333 rkh_exit_critical_Expect();
334 rkh_evtPool_put_Expect((RKHEvtPool *)1, &evt);
341 test_Fails_OnRecycleEvtNullPool(
void)
347 rkh_enter_critical_Expect();
348 rkh_assert_Expect(
"rkhfwk_dynevt", 0);
349 rkh_assert_IgnoreArg_file();
350 rkh_assert_IgnoreArg_line();
351 rkh_assert_StubWithCallback(MockAssertCallback);
357 test_Fails_OnRecycleEvtWrongPool(
void)
363 rkh_evtPool_getPool_ExpectAndReturn(storage,
sizeof(storage), 4,
365 rkh_enter_critical_Expect();
366 rkh_assert_Expect(
"rkhfwk_dynevt", 0);
367 rkh_assert_IgnoreArg_file();
368 rkh_assert_IgnoreArg_line();
369 rkh_assert_StubWithCallback(MockAssertCallback);
#define RKH_FALSE
Standard define.
void rkh_fwk_reserve(RKH_EVT_T *e)
Reserve the dynamic event to be recycled.
void rkh_dynEvt_init(void)
Initializes the dynamic event manager.
void rkh_fwk_gc(RKH_EVT_T *e, const void *const sender)
Recycle a dynamic event.
void rkh_fwk_registerEvtPool(void *sstart, rui32_t ssize, RKH_ES_T esize)
Registers a new event pool into the event pool list.
RKH_EVT_T * rkh_fwk_ae(RKH_ES_T esize, RKH_SIG_T e, const void *const sender)
Allocates an event from the previously created event pool.
#define RKH_CFG_FWK_MAX_EVT_POOL
If the dynamic event support is enabled (see RKH_CFG_FWK_DYN_EVT_EN) then the RKH_CFG_FWK_MAX_EVT_POO...
Specifies the interface of dynamic event support.
Represents events without parameters.
RKH_SIG_T e
Signal of the event instance.
rui8_t nref
Attribute of dynamic events.
rui8_t pool
Attribute of dynamic events (0 for static event).