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 web site: http://sourceforge.net/projects/rkh-reactivesys/
28  * e-mail: francuccilea@gmail.com
29  * ---------------------------------------------------------------------------
30  */
31 
44 /* -------------------------- Development history -------------------------- */
45 /*
46  * 2017.05.15 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_sync.h"
58 #include "Mock_rkhqueue.h"
59 #include "Mock_rkhassert.h"
60 #include "Mock_rkhsma_prio.h"
61 
62 /* ----------------------------- Local macros ------------------------------ */
63 /* ------------------------------- Constants ------------------------------- */
64 /* ---------------------------- Local data types --------------------------- */
65 /* ---------------------------- Global variables --------------------------- */
66 TEST_GROUP(sync);
67 
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 TEST_SETUP(sync)
82 {
83  Mock_rkhassert_Init();
84  Mock_rkhsma_prio_Init();
85  ao.sm.romrkh = &base;
86 }
87 
88 TEST_TEAR_DOWN(sync)
89 {
90  Mock_rkhassert_Verify();
91  Mock_rkhsma_prio_Verify();
92  Mock_rkhassert_Destroy();
93  Mock_rkhsma_prio_Destroy();
94 }
95 
102 TEST(sync, BlockActiveObject)
103 {
104  ao.equeue.qty = 1;
105  rkh_sma_block(&ao);
106 }
107 
108 TEST(sync, Fails_TriesBlockActiveObjectWithEmptyQueue)
109 {
110  rkh_assert_Expect("rkhsma_sync", 0);
111  rkh_assert_IgnoreArg_line();
112  rkh_assert_StubWithCallback(MockAssertCallback);
113  ao.equeue.qty = 0;
114 
115  rkh_sma_block(&ao);
116 }
117 
118 TEST(sync, SetActiveObjectReady)
119 {
120  rkh_smaPrio_setReady_Expect(ao.sm.romrkh->prio);
121  rkh_sma_setReady(&ao);
122 }
123 
124 TEST(sync, SetActiveObjectUnready)
125 {
126  rkh_smaPrio_setUnready_Expect(ao.sm.romrkh->prio);
127  rkh_sma_setUnready(&ao);
128 }
129 
134 /* ------------------------------ End of file ------------------------------ */
RKHROM RKH_ROM_T * romrkh
Points to constant parameters of state machine.
Definition: rkhsm.h:1718
void rkh_sma_setUnready(RKH_SMA_T *const me)
Informs the underlying kernel that the active object's event queue is becoming empty. Thus, the active object is removed from the ready list.
Describes the SMA (active object in UML).
Definition: rkhsma.h:748
RKH_EQ_TYPE equeue
Event queue of the SMA (a.k.a Active Object).
Definition: rkhsma.h:812
RKH_SM_T sm
State machine.
Definition: rkhsma.h:754
Constant parameters of state machine.
Definition: rkhsm.h:1636
rui8_t prio
SMA (a.k.a Active Object) priority.
Definition: rkhsm.h:1645
void rkh_sma_setReady(RKH_SMA_T *const me)
Encapsulates the mechanism of signaling the thread waiting on the used native event queue...
void rkh_sma_block(RKH_SMA_T *const me)
Encapsulates the mechanism of blocking the native event queue.
Specifies the interface of the blocking mechanism (synchro) for active object scheduling.