RKH
test_rkhsma_prio.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 site: http://vortexmakes.com/que-es/
28  * RKH GitHub: https://github.com/vortexmakes/RKH
29  * RKH Sourceforge: https://sourceforge.net/projects/rkh-reactivesys/
30  * e-mail: lf@vortexmakes.com
31  * ---------------------------------------------------------------------------
32  */
33 
46 /* -------------------------- Development history -------------------------- */
47 /*
48  * 2017.05.15 LeFr v2.4.05 ---
49  */
50 
51 /* -------------------------------- Authors -------------------------------- */
52 /*
53  * LeFr Leandro Francucci lf@vortexmakes.com
54  */
55 
56 /* --------------------------------- Notes --------------------------------- */
57 /* ----------------------------- Include files ----------------------------- */
58 #include "unity.h"
59 #include "rkhsma_prio.h"
60 #include "Mock_rkhfwk_rdygrp.h"
61 #include "Mock_rkhassert.h"
62 
63 /* ----------------------------- Local macros ------------------------------ */
64 /* ------------------------------- Constants ------------------------------- */
65 /* ---------------------------- Local data types --------------------------- */
66 /* ---------------------------- Global variables --------------------------- */
67 int GlobalExpectCount;
68 int GlobalVerifyOrder;
69 char *GlobalOrderError;
70 
71 /* ---------------------------- Local variables ---------------------------- */
72 /* ----------------------- Local function prototypes ----------------------- */
73 /* ---------------------------- Local functions ---------------------------- */
74 static void
75 MockAssertCallback(const char* const file, int line, int cmock_num_calls)
76 {
77  TEST_PASS();
78 }
79 
80 /* ---------------------------- Global functions --------------------------- */
81 void
82 setUp(void)
83 {
84  Mock_rkhfwk_rdygrp_Init();
85 }
86 
87 void
88 tearDown(void)
89 {
90  Mock_rkhfwk_rdygrp_Verify();
91  Mock_rkhfwk_rdygrp_Destroy();
92 }
93 
100 void
101 test_ClearAfterInit(void)
102 {
103  rbool_t result;
104 
105  rkh_rdygrp_init_Expect(0);
106  rkh_rdygrp_init_IgnoreArg_me();
107  rkh_rdygrp_isReady_ExpectAndReturn(0, 0);
108  rkh_rdygrp_isReady_IgnoreArg_me();
109  rkh_rdygrp_isReady_ExpectAndReturn(0, 0);
110  rkh_rdygrp_isReady_IgnoreArg_me();
111 
113  result = rkh_smaPrio_isReady();
114  TEST_ASSERT_EQUAL(0, result);
115  result = rkh_smaPrio_isNotReady();
116  TEST_ASSERT_EQUAL(1, result);
117 }
118 
119 void
120 test_SetOneActiveObjectReadyToRun(void)
121 {
122  rbool_t result;
123  rui8_t prio = 1, resultPrio;
124 
125  rkh_rdygrp_init_Expect(0);
126  rkh_rdygrp_init_IgnoreArg_me();
127  rkh_rdygrp_setReady_Expect(0, prio);
128  rkh_rdygrp_setReady_IgnoreArg_me();
129  rkh_rdygrp_isReady_ExpectAndReturn(0, 1);
130  rkh_rdygrp_isReady_IgnoreArg_me();
131  rkh_rdygrp_findHighest_ExpectAndReturn(0, prio);
132  rkh_rdygrp_findHighest_IgnoreArg_me();
133 
135  rkh_smaPrio_setReady(prio);
136  result = rkh_smaPrio_isReady();
137  TEST_ASSERT_EQUAL(1, result);
138 
139  resultPrio = rkh_smaPrio_findHighest();
140  TEST_ASSERT_EQUAL(prio, resultPrio);
141 }
142 
143 void
144 test_SetMultipleActiveObjectsReadyToRun(void)
145 {
146  rui8_t prioA = 1, prioC = 0, prioB = 15, resultPrio;
147 
148  rkh_rdygrp_init_Expect(0);
149  rkh_rdygrp_init_IgnoreArg_me();
150  rkh_rdygrp_setReady_Expect(0, prioA);
151  rkh_rdygrp_setReady_IgnoreArg_me();
152  rkh_rdygrp_setReady_Expect(0, prioB);
153  rkh_rdygrp_setReady_IgnoreArg_me();
154  rkh_rdygrp_setReady_Expect(0, prioC);
155  rkh_rdygrp_setReady_IgnoreArg_me();
156  rkh_rdygrp_findHighest_ExpectAndReturn(0, prioC);
157  rkh_rdygrp_findHighest_IgnoreArg_me();
158 
160  rkh_smaPrio_setReady(prioA);
161  rkh_smaPrio_setReady(prioB);
162  rkh_smaPrio_setReady(prioC);
163  resultPrio = rkh_smaPrio_findHighest();
164 
165  TEST_ASSERT_EQUAL(prioC, resultPrio);
166 }
167 
168 void
169 test_SetOneActiveObjectUnready(void)
170 {
171  rbool_t result;
172  rui8_t prio = 1, resultPrio;
173 
174  rkh_rdygrp_init_Expect(0);
175  rkh_rdygrp_init_IgnoreArg_me();
176  rkh_rdygrp_setReady_Expect(0, prio);
177  rkh_rdygrp_setReady_IgnoreArg_me();
178  rkh_rdygrp_findHighest_ExpectAndReturn(0, prio);
179  rkh_rdygrp_findHighest_IgnoreArg_me();
180  rkh_rdygrp_setUnready_Expect(0, prio);
181  rkh_rdygrp_setUnready_IgnoreArg_me();
182  rkh_rdygrp_isReady_ExpectAndReturn(0, 0);
183  rkh_rdygrp_isReady_IgnoreArg_me();
184 
186  rkh_smaPrio_setReady(prio);
187  resultPrio = rkh_smaPrio_findHighest();
188  TEST_ASSERT_EQUAL(prio, resultPrio);
189 
191  result = rkh_smaPrio_isReady();
192  TEST_ASSERT_EQUAL(0, result);
193 }
194 
195 void
196 test_SetMultipleActiveObjectsUnready(void)
197 {
198  rbool_t result;
199  rui8_t prioA = 1, prioC = 0, prioB = 15;
200 
201  rkh_rdygrp_init_Expect(0);
202  rkh_rdygrp_init_IgnoreArg_me();
203  rkh_rdygrp_setReady_Expect(0, prioA);
204  rkh_rdygrp_setReady_IgnoreArg_me();
205  rkh_rdygrp_setReady_Expect(0, prioB);
206  rkh_rdygrp_setReady_IgnoreArg_me();
207  rkh_rdygrp_setReady_Expect(0, prioC);
208  rkh_rdygrp_setReady_IgnoreArg_me();
209  rkh_rdygrp_setUnready_Expect(0, prioA);
210  rkh_rdygrp_setUnready_IgnoreArg_me();
211  rkh_rdygrp_setUnready_Expect(0, prioB);
212  rkh_rdygrp_setUnready_IgnoreArg_me();
213  rkh_rdygrp_setUnready_Expect(0, prioC);
214  rkh_rdygrp_setUnready_IgnoreArg_me();
215  rkh_rdygrp_isReady_ExpectAndReturn(0, 0);
216  rkh_rdygrp_isReady_IgnoreArg_me();
217 
219  rkh_smaPrio_setReady(prioA);
220  rkh_smaPrio_setReady(prioB);
221  rkh_smaPrio_setReady(prioC);
222  rkh_smaPrio_setUnready(prioA);
223  rkh_smaPrio_setUnready(prioB);
224  rkh_smaPrio_setUnready(prioC);
225  result = rkh_smaPrio_isReady();
226 
227  TEST_ASSERT_EQUAL(0, result);
228 }
229 
230 void
231 test_Fails_InvalidActiveObjectOnSet(void)
232 {
233  rui8_t prio = RKH_CFG_FWK_MAX_SMA;
234 
235  rkh_rdygrp_init_Expect(0);
236  rkh_rdygrp_init_IgnoreArg_me();
237 
238  rkh_assert_Expect("rkhsma_prio", 0);
239  rkh_assert_IgnoreArg_file();
240  rkh_assert_IgnoreArg_line();
241  rkh_assert_StubWithCallback(MockAssertCallback);
242 
244  rkh_smaPrio_setReady(prio);
245 }
246 
251 /* ------------------------------ End of file ------------------------------ */
#define RKH_CFG_FWK_MAX_SMA
Specify the maximum number of state machine applications (SMA) to be used by the application (can be ...
Definition: rkhcfg.h:88
Specifies the native priority mechanism for active object scheduling.
void rkh_smaPrio_init(void)
Initializes the native priority mechanism for active object scheduling.
void rkh_smaPrio_setUnready(rui8_t prio)
Removing an active object from the ready list.
rbool_t rkh_smaPrio_isNotReady(void)
Evaluates to true if all active objects are not ready to run.
rbool_t rkh_smaPrio_isReady(void)
Evaluates to true if any active object is ready to run.
void rkh_smaPrio_setReady(rui8_t prio)
Making an active object ready-to-run inserting it into the ready list.
rui8_t rkh_smaPrio_findHighest(void)
Finding the highest priority active object ready to run.