RKH
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
test_rkhsma.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.04.05 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 "rkhsma.h"
58 #include "Mock_rkhport.h"
59 #include "Mockrkhtrc.h"
60 #include "Mockrkhsm.h"
61 #include "Mock_rkhqueue.h"
62 
63 /* ----------------------------- Local macros ------------------------------ */
64 /* ------------------------------- Constants ------------------------------- */
65 /* ---------------------------- Local data types --------------------------- */
66 /* ---------------------------- Global variables --------------------------- */
67 TEST_GROUP(sma);
68 
69 /* ---------------------------- Local variables ---------------------------- */
70 static RKHROM RKH_ROM_T base = {0, 0, "receiver"};
71 static RKH_SMA_T receiver;
72 const RKH_TRC_FIL_T fsma = {0, NULL}; /* Fake global variable of trace */
73  /* module (using for mocking) */
74 const RKH_TRC_FIL_T fsig = {0, NULL};
75 static RKH_EVT_T event = {0, 0, 0};
76 
77 /* ----------------------- Local function prototypes ----------------------- */
78 /* ---------------------------- Local functions ---------------------------- */
79 /* ---------------------------- Global functions --------------------------- */
80 /* ============================= SMA test group ============================ */
81 TEST_SETUP(sma)
82 {
83  receiver.sm.romrkh = &base;
84 }
85 
86 TEST_TEAR_DOWN(sma)
87 {
88 }
89 
96 TEST(sma, Register)
97 {
98  rkh_enter_critical_Expect();
99  rkh_trc_isoff__ExpectAndReturn(RKH_TE_SMA_REG, RKH_FALSE);
100  rkh_exit_critical_Expect();
101 
102  rkh_sma_register(&receiver);
103  TEST_ASSERT_EQUAL(&receiver, rkh_sptbl[receiver.sm.romrkh->prio]);
104 }
105 
106 TEST(sma, UnRegister)
107 {
108  rkh_enter_critical_Expect();
109  rkh_trc_isoff__ExpectAndReturn(RKH_TE_SMA_UNREG, RKH_FALSE);
110  rkh_exit_critical_Expect();
111 
112  rkh_sma_unregister(&receiver);
113  TEST_ASSERT_EQUAL((RKH_SMA_T *)0, rkh_sptbl[receiver.sm.romrkh->prio]);
114 }
115 
116 TEST(sma, Constructor)
117 {
118  rkh_sm_ctor_Expect(&(receiver.sm));
119 
120  rkh_sma_ctor(&receiver, (const RKHSmaVtbl *)0);
121 }
122 
123 TEST(sma, TerminateOneRegisteredAO)
124 {
125  rkh_enter_critical_Expect();
126  rkh_trc_isoff__ExpectAndReturn(RKH_TE_SMA_REG, RKH_FALSE);
127  rkh_exit_critical_Expect();
128 
129  rkh_sma_register(&receiver);
130 
131  rkh_enter_critical_Expect();
132  rkh_trc_isoff__ExpectAndReturn(RKH_TE_SMA_UNREG, RKH_FALSE);
133  rkh_exit_critical_Expect();
134  rkh_trc_isoff__ExpectAndReturn(RKH_TE_SMA_TERM, RKH_FALSE);
135 
136  rkh_sma_terminate(&receiver);
137 
138  TEST_ASSERT_EQUAL((RKH_SMA_T *)0, rkh_sptbl[receiver.sm.romrkh->prio]);
139 }
140 
141 TEST(sma, ActivateOneAO)
142 {
143  char *buff;
144 
145  rkh_queue_init_Expect(&receiver.equeue, &buff, 16, &receiver);
146 
147  rkh_enter_critical_Expect();
148  rkh_trc_isoff__ExpectAndReturn(RKH_TE_SMA_REG, RKH_FALSE);
149  rkh_exit_critical_Expect();
150 
151  rkh_sm_init_Expect((RKH_SM_T *)&receiver);
152 
153  rkh_enter_critical_Expect();
154  rkh_trc_isoff__ExpectAndReturn(RKH_TE_SMA_ACT, RKH_FALSE);
155  rkh_exit_critical_Expect();
156 
157  rkh_sma_activate(&receiver, (RKH_EVT_T **)&buff, 16, NULL, 0);
158 }
159 
160 TEST(sma, PostFifo)
161 {
162  rkh_enter_critical_Expect();
163  rkh_queue_put_fifo_Expect(&receiver.equeue, &event);
164  rkh_trc_isoff__ExpectAndReturn(RKH_TE_SMA_FIFO, RKH_FALSE);
165  rkh_exit_critical_Expect();
166 
167  rkh_sma_post_fifo(&receiver, &event, &receiver);
168 }
169 
170 TEST(sma, PostLifo)
171 {
172  rkh_enter_critical_Expect();
173  rkh_queue_put_lifo_Expect(&receiver.equeue, &event);
174  rkh_trc_isoff__ExpectAndReturn(RKH_TE_SMA_LIFO, RKH_FALSE);
175  rkh_exit_critical_Expect();
176 
177  rkh_sma_post_lifo(&receiver, &event, &receiver);
178 }
179 
180 TEST(sma, Get)
181 {
182  RKH_EVT_T *e;
183 
184  rkh_queue_get_ExpectAndReturn(&receiver.equeue, &event);
185  rkh_enter_critical_Expect();
186  rkh_trc_isoff__ExpectAndReturn(RKH_TE_SMA_GET, RKH_FALSE);
187  rkh_exit_critical_Expect();
188 
189  e = rkh_sma_get(&receiver);
190  TEST_ASSERT_EQUAL(&event, e);
191 }
192 
193 TEST(sma, Defer)
194 {
195  rkh_enter_critical_Expect();
196  rkh_queue_put_fifo_Expect(&receiver.equeue, &event);
197  rkh_trc_isoff__ExpectAndReturn(RKH_TE_SMA_DEFER, RKH_FALSE);
198  rkh_exit_critical_Expect();
199 
200  rkh_sma_defer(&receiver.equeue, &event);
201 }
202 
203 TEST(sma, Recall)
204 {
205  RKH_EVT_T *e;
206 
207  rkh_queue_get_ExpectAndReturn(&receiver.equeue, NULL);
208 
209  e = rkh_sma_recall(&receiver, &receiver.equeue);
210  TEST_ASSERT_EQUAL(NULL, e);
211 }
212 
217 /* ------------------------------ End of file ------------------------------ */
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...
RKHROM RKH_ROM_T * romrkh
Points to constant parameters of state machine.
Definition: rkhsm.h:1718
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...
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...
Describes the SMA (active object in UML).
Definition: rkhsma.h:748
Represents events without parameters.
Definition: rkhevt.h:167
RKH_SMA_T * rkh_sptbl[RKH_CFG_FWK_MAX_SMA]
Priority arranged table of registered SMA.
RKH_EQ_TYPE equeue
Event queue of the SMA (a.k.a Active Object).
Definition: rkhsma.h:812
Represents the filter of signal and active object.
void rkh_sma_defer(RKH_QUEUE_T *q, const RKH_EVT_T *e)
Defer an event to a given separate event queue.
RKH_SM_T sm
State machine.
Definition: rkhsma.h:754
#define RKH_FALSE
Standard define.
Definition: rkhdef.h:254
#define RKH_TE_SMA_UNREG
Removes the SMA as known as active object from the priority table, and thus from the framework...
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_unregister(RKH_SMA_T *me)
Removes the SMA as known as active object from the priority table, and thus from the framework...
void rkh_sma_register(RKH_SMA_T *me)
Registers a state machine application (SMA) as known as active object into the framework, which implies to store a pointer to the SMA in the priority table.
Constant parameters of state machine.
Definition: rkhsm.h:1636
#define RKH_TE_SMA_DEFER
Defer an event to a given separate event queue.
rui8_t prio
SMA (a.k.a Active Object) priority.
Definition: rkhsm.h:1645
Describes the state machine.
Definition: rkhsm.h:1712
Virtual table for the RKH_SMA_T structure.
Definition: rkhsma.h:860
RKH_EVT_T * rkh_sma_recall(RKH_SMA_T *me, RKH_QUEUE_T *q)
Recall a deferred event from a given event queue.
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_terminate(RKH_SMA_T *me)
Terminate a state machine application (SMA) as known as active object.
#define RKH_TE_SMA_REG
Registers a state machine application (SMA) as known as active object into the framework, which implies to store a pointer to the SMA in the priority table.
#define RKH_TE_SMA_LIFO
Send an event to a state machine application (SMA) as known as active object through a queue using th...
#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_TE_SMA_GET
Get an event from the active object's queue.
#define RKH_TE_SMA_TERM
Terminate a state machine application (SMA) as known as active object.
Specifies the interface of the acive object (SMA state machine applications) manager.