10
10
/*
11
11
* Flat Test Transition:
12
12
*
13
- * A_ENTRY --> A_RUN --> A_EXIT --> B_ENTRY --> B_RUN --|
14
- * |
15
- * |----------------------------------------------------|
16
- * |
17
- * |--> B_EXIT --> C_ENTRY --> C_RUN --> C_EXIT
13
+ * A_ENTRY --> A_RUN --> A_EXIT --> B_ENTRY --> B_RUN --|
14
+ * |
15
+ * |----------------------------------------------------|
16
+ * |
17
+ * |--> B_EXIT --> C_ENTRY --> C_RUN --> C_EXIT --> D_ENTRY
18
18
*
19
19
*/
20
20
21
-
22
21
#define TEST_OBJECT (o ) ((struct test_object *)o)
23
22
24
- #define SMF_RUN 3
23
+ #define SMF_RUN 3
25
24
26
- #define STATE_A_ENTRY_BIT (1 << 0)
27
- #define STATE_A_RUN_BIT (1 << 1)
28
- #define STATE_A_EXIT_BIT (1 << 2)
25
+ #define STATE_A_ENTRY_BIT (1 << 0)
26
+ #define STATE_A_RUN_BIT (1 << 1)
27
+ #define STATE_A_EXIT_BIT (1 << 2)
29
28
30
- #define STATE_B_ENTRY_BIT (1 << 3)
31
- #define STATE_B_RUN_BIT (1 << 4)
32
- #define STATE_B_EXIT_BIT (1 << 5)
29
+ #define STATE_B_ENTRY_BIT (1 << 3)
30
+ #define STATE_B_RUN_BIT (1 << 4)
31
+ #define STATE_B_EXIT_BIT (1 << 5)
33
32
34
- #define STATE_C_ENTRY_BIT (1 << 6)
35
- #define STATE_C_RUN_BIT (1 << 7)
36
- #define STATE_C_EXIT_BIT (1 << 8)
33
+ #define STATE_C_ENTRY_BIT (1 << 6)
34
+ #define STATE_C_RUN_BIT (1 << 7)
35
+ #define STATE_C_EXIT_BIT (1 << 8)
37
36
38
- #define TEST_ENTRY_VALUE_NUM 0
39
- #define TEST_RUN_VALUE_NUM 4
40
- #define TEST_EXIT_VALUE_NUM 8
41
- #define TEST_VALUE_NUM 9
37
+ #define TEST_ENTRY_VALUE_NUM 0
38
+ #define TEST_RUN_VALUE_NUM 4
39
+ #define TEST_EXIT_VALUE_NUM 8
40
+ #define TEST_VALUE_NUM 9
42
41
43
42
static uint32_t test_value [] = {
44
43
0x00 , /* STATE_A_ENTRY */
@@ -80,11 +79,15 @@ static struct test_object {
80
79
81
80
static void state_a_entry (void * obj )
82
81
{
82
+ zassert_equal (smf_get_current_executing_state (SMF_CTX (obj )), & test_states [STATE_A ],
83
+ "Fail to get the currently-executing state at entry. Expected: State A" );
84
+ zassert_equal (smf_get_current_leaf_state (SMF_CTX (obj )), & test_states [STATE_A ],
85
+ "Fail to get the current leaf state at entry. Expected: State A" );
86
+
83
87
struct test_object * o = TEST_OBJECT (obj );
84
88
85
89
o -> tv_idx = 0 ;
86
- zassert_equal (o -> transition_bits , test_value [o -> tv_idx ],
87
- "Test State A entry failed" );
90
+ zassert_equal (o -> transition_bits , test_value [o -> tv_idx ], "Test State A entry failed" );
88
91
89
92
if (o -> terminate == ENTRY ) {
90
93
smf_set_terminate (obj , -1 );
@@ -96,11 +99,15 @@ static void state_a_entry(void *obj)
96
99
97
100
static enum smf_state_result state_a_run (void * obj )
98
101
{
102
+ zassert_equal (smf_get_current_executing_state (SMF_CTX (obj )), & test_states [STATE_A ],
103
+ "Fail to get the currently-executing state at run. Expected: State A" );
104
+ zassert_equal (smf_get_current_leaf_state (SMF_CTX (obj )), & test_states [STATE_A ],
105
+ "Fail to get the current leaf state at run. Expected: State A" );
106
+
99
107
struct test_object * o = TEST_OBJECT (obj );
100
108
101
109
o -> tv_idx ++ ;
102
- zassert_equal (o -> transition_bits , test_value [o -> tv_idx ],
103
- "Test State A run failed" );
110
+ zassert_equal (o -> transition_bits , test_value [o -> tv_idx ], "Test State A run failed" );
104
111
105
112
o -> transition_bits |= STATE_A_RUN_BIT ;
106
113
@@ -110,33 +117,45 @@ static enum smf_state_result state_a_run(void *obj)
110
117
111
118
static void state_a_exit (void * obj )
112
119
{
120
+ zassert_equal (smf_get_current_executing_state (SMF_CTX (obj )), & test_states [STATE_A ],
121
+ "Fail to get the currently-executing state at exit. Expected: State A" );
122
+ zassert_equal (smf_get_current_leaf_state (SMF_CTX (obj )), & test_states [STATE_A ],
123
+ "Fail to get the current leaf state at exit. Expected: State A" );
124
+
113
125
struct test_object * o = TEST_OBJECT (obj );
114
126
115
127
o -> tv_idx ++ ;
116
- zassert_equal (o -> transition_bits , test_value [o -> tv_idx ],
117
- "Test State A exit failed" );
128
+ zassert_equal (o -> transition_bits , test_value [o -> tv_idx ], "Test State A exit failed" );
118
129
119
130
o -> transition_bits |= STATE_A_EXIT_BIT ;
120
131
}
121
132
122
133
static void state_b_entry (void * obj )
123
134
{
135
+ zassert_equal (smf_get_current_executing_state (SMF_CTX (obj )), & test_states [STATE_B ],
136
+ "Fail to get the currently-executing state at entry. Expected: State B" );
137
+ zassert_equal (smf_get_current_leaf_state (SMF_CTX (obj )), & test_states [STATE_B ],
138
+ "Fail to get the current leaf state at entry. Expected: State B" );
139
+
124
140
struct test_object * o = TEST_OBJECT (obj );
125
141
126
142
o -> tv_idx ++ ;
127
- zassert_equal (o -> transition_bits , test_value [o -> tv_idx ],
128
- "Test State B entry failed" );
143
+ zassert_equal (o -> transition_bits , test_value [o -> tv_idx ], "Test State B entry failed" );
129
144
130
145
o -> transition_bits |= STATE_B_ENTRY_BIT ;
131
146
}
132
147
133
148
static enum smf_state_result state_b_run (void * obj )
134
149
{
150
+ zassert_equal (smf_get_current_executing_state (SMF_CTX (obj )), & test_states [STATE_B ],
151
+ "Fail to get the currently-executing state at run. Expected: State B" );
152
+ zassert_equal (smf_get_current_leaf_state (SMF_CTX (obj )), & test_states [STATE_B ],
153
+ "Fail to get the current leaf state at run. Expected: State B" );
154
+
135
155
struct test_object * o = TEST_OBJECT (obj );
136
156
137
157
o -> tv_idx ++ ;
138
- zassert_equal (o -> transition_bits , test_value [o -> tv_idx ],
139
- "Test State B run failed" );
158
+ zassert_equal (o -> transition_bits , test_value [o -> tv_idx ], "Test State B run failed" );
140
159
141
160
if (o -> terminate == RUN ) {
142
161
smf_set_terminate (obj , -1 );
@@ -151,31 +170,43 @@ static enum smf_state_result state_b_run(void *obj)
151
170
152
171
static void state_b_exit (void * obj )
153
172
{
173
+ zassert_equal (smf_get_current_executing_state (SMF_CTX (obj )), & test_states [STATE_B ],
174
+ "Fail to get the currently-executing state at exit. Expected: State B" );
175
+ zassert_equal (smf_get_current_leaf_state (SMF_CTX (obj )), & test_states [STATE_B ],
176
+ "Fail to get the current leaf state at exit. Expected: State B" );
177
+
154
178
struct test_object * o = TEST_OBJECT (obj );
155
179
156
180
o -> tv_idx ++ ;
157
- zassert_equal (o -> transition_bits , test_value [o -> tv_idx ],
158
- "Test State B exit failed" );
181
+ zassert_equal (o -> transition_bits , test_value [o -> tv_idx ], "Test State B exit failed" );
159
182
o -> transition_bits |= STATE_B_EXIT_BIT ;
160
183
}
161
184
162
185
static void state_c_entry (void * obj )
163
186
{
187
+ zassert_equal (smf_get_current_executing_state (SMF_CTX (obj )), & test_states [STATE_C ],
188
+ "Fail to get the currently-executing state at entry. Expected: State C" );
189
+ zassert_equal (smf_get_current_leaf_state (SMF_CTX (obj )), & test_states [STATE_C ],
190
+ "Fail to get the current leaf state at entry. Expected: State C" );
191
+
164
192
struct test_object * o = TEST_OBJECT (obj );
165
193
166
194
o -> tv_idx ++ ;
167
- zassert_equal (o -> transition_bits , test_value [o -> tv_idx ],
168
- "Test State C entry failed" );
195
+ zassert_equal (o -> transition_bits , test_value [o -> tv_idx ], "Test State C entry failed" );
169
196
o -> transition_bits |= STATE_C_ENTRY_BIT ;
170
197
}
171
198
172
199
static enum smf_state_result state_c_run (void * obj )
173
200
{
201
+ zassert_equal (smf_get_current_executing_state (SMF_CTX (obj )), & test_states [STATE_C ],
202
+ "Fail to get the currently-executing state at run. Expected: State C" );
203
+ zassert_equal (smf_get_current_leaf_state (SMF_CTX (obj )), & test_states [STATE_C ],
204
+ "Fail to get the current leaf state at run. Expected: State C" );
205
+
174
206
struct test_object * o = TEST_OBJECT (obj );
175
207
176
208
o -> tv_idx ++ ;
177
- zassert_equal (o -> transition_bits , test_value [o -> tv_idx ],
178
- "Test State C run failed" );
209
+ zassert_equal (o -> transition_bits , test_value [o -> tv_idx ], "Test State C run failed" );
179
210
o -> transition_bits |= STATE_C_RUN_BIT ;
180
211
181
212
smf_set_state (SMF_CTX (obj ), & test_states [STATE_D ]);
@@ -184,11 +215,15 @@ static enum smf_state_result state_c_run(void *obj)
184
215
185
216
static void state_c_exit (void * obj )
186
217
{
218
+ zassert_equal (smf_get_current_executing_state (SMF_CTX (obj )), & test_states [STATE_C ],
219
+ "Fail to get the currently-executing state at exit. Expected: State C" );
220
+ zassert_equal (smf_get_current_leaf_state (SMF_CTX (obj )), & test_states [STATE_C ],
221
+ "Fail to get the current leaf state at exit. Expected: State C" );
222
+
187
223
struct test_object * o = TEST_OBJECT (obj );
188
224
189
225
o -> tv_idx ++ ;
190
- zassert_equal (o -> transition_bits , test_value [o -> tv_idx ],
191
- "Test State C exit failed" );
226
+ zassert_equal (o -> transition_bits , test_value [o -> tv_idx ], "Test State C exit failed" );
192
227
193
228
if (o -> terminate == EXIT ) {
194
229
smf_set_terminate (obj , -1 );
@@ -237,8 +272,7 @@ ZTEST(smf_tests, test_smf_flat)
237
272
}
238
273
}
239
274
240
- zassert_equal (TEST_VALUE_NUM , test_obj .tv_idx ,
241
- "Incorrect test value index" );
275
+ zassert_equal (TEST_VALUE_NUM , test_obj .tv_idx , "Incorrect test value index" );
242
276
zassert_equal (test_obj .transition_bits , test_value [test_obj .tv_idx ],
243
277
"Final state not reached" );
244
278
0 commit comments