60#include "smInstance.h"
61#include "smPolymorphism.h"
62#include "Mock_rkhport.h"
63#include "Mock_rkhtrc.h"
64#include "Mock_rkhtrc_record.h"
65#include "Mock_rkhtrc_filter.h"
66#include "Mock_rkhsm.h"
67#include "Mock_rkhqueue.h"
68#include "Mock_rkhassert.h"
69#include "Mock_rkhtmr.h"
78static RKHROM RKH_ROM_T base = {0, 0,
"receiver"};
87#if RKH_CFG_SMA_VFUNCT_EN == RKH_ENABLED
92 TEST_ASSERT_EQUAL_PTR(activate, me->vptr->activate);
93 TEST_ASSERT_EQUAL_PTR(task, me->vptr->task);
94 TEST_ASSERT_EQUAL_PTR(postFifo, me->vptr->post_fifo);
95 TEST_ASSERT_EQUAL_PTR(postLifo, me->vptr->post_lifo);
100 void *stkSto, rui32_t stkSize)
134setUp_polymorphism(
void)
136#if RKH_CFG_SMA_VFUNCT_EN == RKH_ENABLED
147 receiver.
sm.romrkh = &base;
148 Mock_rkhtrc_filter_Init();
154 Mock_rkhtrc_filter_Verify();
155 Mock_rkhtrc_filter_Destroy();
167 rkh_enter_critical_Expect();
169 rkh_exit_critical_Expect();
178 rkh_enter_critical_Expect();
180 rkh_exit_critical_Expect();
187test_Constructor(
void)
189 rkh_sm_ctor_Expect(&(receiver.
sm));
195test_TerminateOneRegisteredAO(
void)
197 rkh_enter_critical_Expect();
199 rkh_exit_critical_Expect();
203 rkh_enter_critical_Expect();
205 rkh_exit_critical_Expect();
214test_ActivateOneAO(
void)
218 rkh_queue_init_Expect(&receiver.
equeue, (
const void **)&buff, 16,
221 rkh_enter_critical_Expect();
223 rkh_exit_critical_Expect();
225 rkh_sm_init_Expect((
RKH_SM_T *)&receiver);
235 rkh_enter_critical_Expect();
236 rkh_queue_put_fifo_Expect(&receiver.
equeue, &event);
238 rkh_exit_critical_Expect();
246 rkh_enter_critical_Expect();
247 rkh_queue_put_lifo_Expect(&receiver.
equeue, &event);
249 rkh_exit_critical_Expect();
259 rkh_queue_get_ExpectAndReturn(&receiver.
equeue, &event);
263 TEST_ASSERT_EQUAL(&event, e);
269 rkh_enter_critical_Expect();
270 rkh_queue_put_fifo_Expect(&receiver.
equeue, &event);
272 rkh_exit_critical_Expect();
282 rkh_queue_get_ExpectAndReturn(&receiver.
equeue, NULL);
285 TEST_ASSERT_EQUAL(NULL, e);
298test_ctorOfStaticPrivateAO(
void)
303 TEST_ASSERT_EQUAL(4, Single_getFoo());
307test_staticPublicAOWithoutRuntimeCtor(
void)
309 publicSingle->foo = 8;
310 TEST_ASSERT_EQUAL_STRING(
"publicSingle",
315test_ctorOfStaticPublicAO(
void)
317 PublicSingle_ctor(8);
319 TEST_ASSERT_EQUAL_STRING(
"publicSingle",
321 TEST_ASSERT_EQUAL(8, publicSingle->foo);
325test_ctorOfStaticOpaqueAO(
void)
327 Opaque_ctor(opaque, 4);
329 TEST_ASSERT_EQUAL(4, Opaque_getFoo(opaque));
333test_ctorOfStaticMultipleAO(
void)
335 MultiplePublicSingle_ctor(single0, 8);
337 TEST_ASSERT_EQUAL_STRING(
"single0",
339 TEST_ASSERT_EQUAL(8, single0->foo);
343test_ctorOfStaticArrayOfAO(
void)
346 MultiplePublicSingle_ctor(pSingle, 8);
348 TEST_ASSERT_EQUAL_STRING(
"single2",
350 TEST_ASSERT_EQUAL(8, pSingle->foo);
354test_staticPrivateSMWithoutRuntimeCtor(
void)
356 TEST_ASSERT_EQUAL_STRING(
"stateMachine",
358 TEST_ASSERT_EQUAL_PTR(NULL, stateMachine->state);
362test_staticPublicSMWithoutRuntimeCtor(
void)
364 TEST_ASSERT_EQUAL_STRING(
"publicStateMachine",
366 TEST_ASSERT_EQUAL(8, publicSingle->foo);
370test_ctorOfStaticCompositePrivateSingletonAO(
void)
374 TEST_ASSERT_EQUAL_STRING(
"composite",
376 TEST_ASSERT_EQUAL_STRING(
"region",
378 TEST_ASSERT_EQUAL(16, Composite_getFoo());
382test_ctorOfStaticCompositePublicAO(
void)
384 PublicComposite_ctor(publicComposite, 16);
386 TEST_ASSERT_EQUAL_STRING(
"publicComposite",
388 TEST_ASSERT_EQUAL_STRING(
"publicRegion",
390 TEST_ASSERT_EQUAL(16, publicComposite->foo);
394test_ctorOfStaticCompositeAOWithDerivedPublicSM(
void)
396 PublicCompositeA_ctor(publicCompositeA, 16, 8);
398 TEST_ASSERT_EQUAL_STRING(
"publicCompositeA",
400 TEST_ASSERT_EQUAL_STRING(
"publicRegionA",
402 TEST_ASSERT_EQUAL(16, publicCompositeA->foo);
403 TEST_ASSERT_EQUAL(8, publicCompositeA->itsReactivePart.foo);
407test_ctorOfDynamicCompositeAO(
void)
409 PublicSingle *actObj;
411 actObj = PublicSingle_dynCtor(8);
412 TEST_ASSERT_NOT_NULL(actObj);
413 TEST_ASSERT_EQUAL(8, actObj->foo);
415 TEST_ASSERT_EQUAL_STRING(
"publicSingleDyn",
418 PublicSingle_dynDtor(actObj);
422test_ctorOfANonReactiveAO(
void)
426 setUp_polymorphism();
429 PerNonReactWoutST_ctor(signalMgr, 4);
431 TEST_ASSERT_EQUAL(4, PerNonReactWoutST_getBaz(signalMgr));
432 TEST_ASSERT_NULL(realSignalMgr->
sm.
state);
436test_invokeActivateOfANonReactiveAO(
void)
441 setUp_polymorphism();
443 rkh_queue_init_Ignore();
444 rkh_enter_critical_Expect();
446 rkh_exit_critical_Expect();
449 PerNonReactWoutST_ctor(signalMgr, 4);
454test_invokeDispatchOfANonReactiveAO(
void)
460 setUp_polymorphism();
463 Sensor_get_ExpectAndReturn(48);
464 Sensor_process_ExpectAndReturn(48, 4);
465 Actuator_set_Expect(4);
467 PerNonReactWoutST_ctor(signalMgr, 4);
472test_ctorOfANonReactiveAOWithSTButWoutUsingEventQueue(
void)
476 setUp_polymorphism();
478 rkh_tmr_init__Expect(NULL, NULL);
479 rkh_tmr_init__IgnoreArg_t();
480 rkh_tmr_init__IgnoreArg_e();
482 PerNonReactWithSTWoutQue_ctor(collector, 4);
484 TEST_ASSERT_EQUAL(4, PerNonReactWithSTWoutQue_getBaz(collector));
488test_invokeActivateOfANonReactiveAOWithSTButWoutUsingEventQueue(
void)
493 setUp_polymorphism();
495 rkh_tmr_init__Expect(NULL, NULL);
496 rkh_tmr_init__IgnoreArg_t();
497 rkh_tmr_init__IgnoreArg_e();
498 rkh_queue_init_Ignore();
499 rkh_enter_critical_Expect();
501 rkh_exit_critical_Expect();
503 rkh_tmr_start_Expect(NULL, realSignalMgr, 4, 4);
504 rkh_tmr_start_IgnoreArg_t();
507 PerNonReactWithSTWoutQue_ctor(collector, 4);
512test_invokeDispatchOfANonReactiveAOWithSTButWoutUsingEventQueue(
void)
518 setUp_polymorphism();
520 rkh_tmr_init__Expect(NULL, NULL);
521 rkh_tmr_init__IgnoreArg_t();
522 rkh_tmr_init__IgnoreArg_e();
523 rkh_queue_init_Ignore();
524 rkh_enter_critical_Expect();
526 rkh_exit_critical_Expect();
528 rkh_tmr_start_Expect(NULL, realSignalMgr, 4, 4);
529 rkh_tmr_start_IgnoreArg_t();
532 Sensor_get_ExpectAndReturn(1.3);
533 Sensor_process_ExpectAndReturn(1.3, 1.2);
537 rkh_sm_dispatch_IgnoreArg_e();
539 PerNonReactWithSTWoutQue_ctor(collector, 4);
554test_defaultVirtualFunctions(
void)
556 setUp_polymorphism();
557#if RKH_CFG_SMA_VFUNCT_EN == RKH_ENABLED
562 TEST_ASSERT_EQUAL_PTR(&
rkhSmaVtbl, singleton->vptr);
567test_callVirtualFunction(
void)
569 setUp_polymorphism();
570#if RKH_CFG_SMA_VFUNCT_EN == RKH_ENABLED
573 rkh_queue_init_Ignore();
574 rkh_enter_critical_Expect();
576 rkh_exit_critical_Expect();
577 rkh_sm_init_Ignore();
580 rkh_enter_critical_Expect();
581 rkh_queue_put_fifo_Ignore();
583 rkh_exit_critical_Expect();
585 rkh_enter_critical_Expect();
586 rkh_queue_put_lifo_Ignore();
588 rkh_exit_critical_Expect();
597test_setVirtualTable(
void)
599 setUp_polymorphism();
600#if RKH_CFG_SMA_VFUNCT_EN == RKH_ENABLED
604 testActivate, testTask, testPostFifo, testPostLifo
607 vptr = singleton->vptr = &vtbl;
610 testActivate, testTask, testPostFifo, testPostLifo);
615test_runtimeSingletonAOCtor(
void)
617 setUp_polymorphism();
618#if RKH_CFG_SMA_VFUNCT_EN == RKH_ENABLED
619 rkh_sm_ctor_Expect(&singleton->sm);
622 TEST_ASSERT_EQUAL(8, Singleton_getFoo());
625 TEST_ASSERT_EQUAL(0, Singleton_getFoo());
630test_runtimeMultipleAOCtorWithVtblForObj(
void)
632 setUp_polymorphism();
633#if RKH_CFG_SMA_VFUNCT_EN == RKH_ENABLED
634 rkh_sm_ctor_Ignore();
635 rkh_sm_ctor_Ignore();
637 Multiple_ctor(multA, 2, Multiple_postFifoA);
638 Multiple_ctor(multB, 4, Multiple_postFifoB);
644 TEST_ASSERT_EQUAL(2, Multiple_getFoobar(multA));
645 TEST_ASSERT_EQUAL(4, Multiple_getFoobar(multB));
650 TEST_ASSERT_EQUAL(0, Multiple_getFoobar(multA));
651 TEST_ASSERT_EQUAL(8, Multiple_getFoobar(multB));
656test_runtimeMultipleAOCtorWithVtblForType(
void)
658 setUp_polymorphism();
659#if RKH_CFG_SMA_VFUNCT_EN == RKH_ENABLED
660 rkh_sm_ctor_Expect((
RKH_SM_T *)cmdSignal);
661 rkh_sm_ctor_Expect((
RKH_SM_T *)cmdRegister);
663 Command_ctor(cmdSignal, 128);
664 Command_ctor(cmdRegister, 64);
668 Command_postFifo, Command_postLifo);
672 Command_postFifo, Command_postLifo);
677test_runtimeSubObjectCtorOfSMAAndSM(
void)
679 setUp_polymorphism();
680#if RKH_CFG_SMA_VFUNCT_EN == RKH_ENABLED
681 rkh_sm_ctor_Expect((
RKH_SM_T *)theCallControl);
682 CallControl_ctorA(16);
684 TEST_ASSERT_EQUAL(16, CallControl_getFoo());
686 CallControl_activate, CallControl_task,
692test_runtimeSubObjectCtorOfSMAAndSMWithDefaultVtbl(
void)
694 setUp_polymorphism();
695#if RKH_CFG_SMA_VFUNCT_EN == RKH_ENABLED
696 rkh_sm_ctor_Expect((
RKH_SM_T *)theCallControl);
697 CallControl_ctorB(8);
699 TEST_ASSERT_EQUAL(8, CallControl_getFoo());
void rkh_sma_dispatch(RKH_SMA_T *me, void *arg)
For cooperative scheduling policy, this function is used to dispatch the event to the active object b...
#define RKH_SMA_POST_LIFO(me_, e_, sender_)
Invoke the direct event posting facility rkh_sma_post_lifo(). If RKH_CFG_SMA_VFUNCT_EN is set RKH_ENA...
#define RKH_SMA_POST_FIFO(me_, e_, sender_)
Invoke the direct event posting facility rkh_sma_post_fifo(). If RKH_CFG_SMA_VFUNCT_EN is set RKH_ENA...
#define RKH_SMA_DISPATCH(me_, arg_)
For cooperative scheduling policy, this function is used to dispatch the event to the active object b...
#define RKH_UPCAST(BaseType_, me_)
Convert a pointer to a base-class.
#define RKH_SMA_ACTIVATE(me_, qSto_, qStoSize, stkSto_, stkSize_)
Invoke the active object activation function rkh_sma_activate(). If RKH_CFG_SMA_VFUNCT_EN is set RKH_...
#define RKH_FALSE
Standard define.
#define RKH_STATIC_EVENT(ev_obj, ev_sig)
This macro declares and initializes the event structure ev_ob with ev_sig signal number and establish...
void rkh_sma_post_lifo(RKH_SMA_T *me, const RKH_EVT_T *e, const void *const sender)
Send an event to a state machine application (SMA) as known as active object through a queue using th...
void rkh_sma_terminate(RKH_SMA_T *me)
Terminate a state machine application (SMA) as known as active object.
void rkh_sma_post_fifo(RKH_SMA_T *me, const RKH_EVT_T *e, const void *const sender)
Send an event to a state machine application (SMA) as known as active object through a queue using th...
void rkh_sma_activate(RKH_SMA_T *me, const RKH_EVT_T **qSto, RKH_QUENE_T qSize, void *stkSto, rui32_t stkSize)
Initializes and activates a previously created state machine application (SMA) as known as active obj...
RKH_EVT_T * rkh_sma_get(RKH_SMA_T *me)
Get an event from the event queue of an state machine application (SMA) as known as active object....
RKH_SMA_T * rkh_sptbl[RKH_CFG_FWK_MAX_SMA]
Priority arranged table of registered SMA.
rui8_t RKH_QUENE_T
This data type defines the maximum number of elements that any queue can contain.
Specifies the interface of the acive object (SMA state machine applications) manager.
void rkh_sma_register(RKH_SMA_T *me)
Registers a state machine application (SMA) as known as active object into the framework,...
void(* RKHTask)(RKH_SMA_T *me, void *arg)
void rkh_sma_defer(RKH_QUEUE_T *q, const RKH_EVT_T *e)
Defer an event to a given separate event queue.
const RKHSmaVtbl rkhSmaVtbl
RKH_EVT_T * rkh_sma_recall(RKH_SMA_T *me, RKH_QUEUE_T *q)
Recall a deferred event from a given event queue.
#define RKH_ARRAY_SMA(_arr, _ix)
Retrieves the pointer to active object from a SMA's array.
void(* RKHActivate)(RKH_SMA_T *me, const RKH_EVT_T **qSto, RKH_QUENE_T qSize, void *stkSto, rui32_t stkSize)
void rkh_sma_unregister(RKH_SMA_T *me)
Removes the SMA as known as active object from the priority table, and thus from the framework,...
void(* RKHPostLifo)(RKH_SMA_T *me, const RKH_EVT_T *e, const void *const sender)
void(* RKHPostFifo)(RKH_SMA_T *me, const RKH_EVT_T *e, const void *const sender)
#define RKH_SMA_ACCESS_CONST(me_, member_)
Macro for accessing to members of state machine structure.
void rkh_sma_ctor(RKH_SMA_T *me, const RKHSmaVtbl *vtbl)
Initializes the virtual table of the active object instance and calls the constructor operation of it...
Represents events without parameters.
Describes the state machine.
rui8_t prio
SMA (a.k.a Active Object) priority.
RKHROM RKH_ST_T * state
Pointer to an event that will be passed to state machine application when it starts....
Describes the SMA (active object in UML).
RKH_SM_T sm
State machine.
RKH_EQ_TYPE equeue
Virtual pointer.
Represents the filter of signal and active object.
Virtual table for the RKH_SMA_T structure.