RKH
test_rkhsma_sync.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_sync.h"
60 #include "Mock_rkhqueue.h"
61 #include "Mock_rkhassert.h"
62 #include "Mock_rkhsma_prio.h"
63 
64 /* ----------------------------- Local macros ------------------------------ */
65 /* ------------------------------- Constants ------------------------------- */
66 /* ---------------------------- Local data types --------------------------- */
67 /* ---------------------------- Global variables --------------------------- */
68 /* ---------------------------- Local variables ---------------------------- */
69 static RKHROM RKH_ROM_T base = {0, 0, "ao"};
70 static RKH_SMA_T ao;
71 
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_rkhassert_Init();
85  Mock_rkhsma_prio_Init();
86  ao.sm.romrkh = &base;
87 }
88 
89 void
90 tearDown(void)
91 {
92  Mock_rkhassert_Verify();
93  Mock_rkhsma_prio_Verify();
94  Mock_rkhassert_Destroy();
95  Mock_rkhsma_prio_Destroy();
96 }
97 
104 void
105 test_BlockActiveObject(void)
106 {
107  ao.equeue.qty = 1;
108  rkh_sma_block(&ao);
109 }
110 
111 void
112 test_Fails_TriesBlockActiveObjectWithEmptyQueue(void)
113 {
114  rkh_assert_Expect("rkhsma_sync", 0);
115  rkh_assert_IgnoreArg_file();
116  rkh_assert_IgnoreArg_line();
117  rkh_assert_StubWithCallback(MockAssertCallback);
118  ao.equeue.qty = 0;
119 
120  rkh_sma_block(&ao);
121 }
122 
123 void
124 test_SetActiveObjectReady(void)
125 {
126  rkh_smaPrio_setReady_Expect(ao.sm.romrkh->prio);
127  rkh_sma_setReady(&ao);
128 }
129 
130 void
131 test_SetActiveObjectUnready(void)
132 {
133  rkh_smaPrio_setUnready_Expect(ao.sm.romrkh->prio);
134  rkh_sma_setUnready(&ao);
135 }
136 
141 /* ------------------------------ End of file ------------------------------ */
Specifies the interface of the blocking mechanism (synchro) for active object scheduling.
void rkh_sma_setUnready(RKH_SMA_T *const me)
Informs the underlying kernel that the active object's event queue is becoming empty....
void rkh_sma_block(RKH_SMA_T *const me)
Encapsulates the mechanism of blocking the native event queue.
void rkh_sma_setReady(RKH_SMA_T *const me)
Encapsulates the mechanism of signaling the thread waiting on the used native event queue....
Constant parameters of state machine.
Definition: rkhsm.h:1829
rui8_t prio
SMA (a.k.a Active Object) priority.
Definition: rkhsm.h:1837
RKHROM RKH_ROM_T * romrkh
Points to constant parameters of state machine.
Definition: rkhsm.h:1910
Describes the SMA (active object in UML).
Definition: rkhsma.h:772
RKH_SM_T sm
State machine.
Definition: rkhsma.h:777
RKH_EQ_TYPE equeue
Event queue of the SMA (a.k.a Active Object).
Definition: rkhsma.h:835