1010/*
1111 * Flat Test Transition:
1212 *
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
1818 *
1919 */
2020
21-
2221#define TEST_OBJECT (o ) ((struct test_object *)o)
2322
24- #define SMF_RUN 3
23+ #define SMF_RUN 3
2524
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)
2928
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)
3332
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)
3736
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
4241
4342static uint32_t test_value [] = {
4443 0x00 , /* STATE_A_ENTRY */
@@ -80,11 +79,15 @@ static struct test_object {
8079
8180static void state_a_entry (void * obj )
8281{
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+
8387 struct test_object * o = TEST_OBJECT (obj );
8488
8589 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" );
8891
8992 if (o -> terminate == ENTRY ) {
9093 smf_set_terminate (obj , -1 );
@@ -96,11 +99,15 @@ static void state_a_entry(void *obj)
9699
97100static enum smf_state_result state_a_run (void * obj )
98101{
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+
99107 struct test_object * o = TEST_OBJECT (obj );
100108
101109 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" );
104111
105112 o -> transition_bits |= STATE_A_RUN_BIT ;
106113
@@ -110,33 +117,45 @@ static enum smf_state_result state_a_run(void *obj)
110117
111118static void state_a_exit (void * obj )
112119{
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+
113125 struct test_object * o = TEST_OBJECT (obj );
114126
115127 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" );
118129
119130 o -> transition_bits |= STATE_A_EXIT_BIT ;
120131}
121132
122133static void state_b_entry (void * obj )
123134{
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+
124140 struct test_object * o = TEST_OBJECT (obj );
125141
126142 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" );
129144
130145 o -> transition_bits |= STATE_B_ENTRY_BIT ;
131146}
132147
133148static enum smf_state_result state_b_run (void * obj )
134149{
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+
135155 struct test_object * o = TEST_OBJECT (obj );
136156
137157 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" );
140159
141160 if (o -> terminate == RUN ) {
142161 smf_set_terminate (obj , -1 );
@@ -151,31 +170,43 @@ static enum smf_state_result state_b_run(void *obj)
151170
152171static void state_b_exit (void * obj )
153172{
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+
154178 struct test_object * o = TEST_OBJECT (obj );
155179
156180 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" );
159182 o -> transition_bits |= STATE_B_EXIT_BIT ;
160183}
161184
162185static void state_c_entry (void * obj )
163186{
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+
164192 struct test_object * o = TEST_OBJECT (obj );
165193
166194 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" );
169196 o -> transition_bits |= STATE_C_ENTRY_BIT ;
170197}
171198
172199static enum smf_state_result state_c_run (void * obj )
173200{
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+
174206 struct test_object * o = TEST_OBJECT (obj );
175207
176208 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" );
179210 o -> transition_bits |= STATE_C_RUN_BIT ;
180211
181212 smf_set_state (SMF_CTX (obj ), & test_states [STATE_D ]);
@@ -184,11 +215,15 @@ static enum smf_state_result state_c_run(void *obj)
184215
185216static void state_c_exit (void * obj )
186217{
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+
187223 struct test_object * o = TEST_OBJECT (obj );
188224
189225 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" );
192227
193228 if (o -> terminate == EXIT ) {
194229 smf_set_terminate (obj , -1 );
@@ -237,8 +272,7 @@ ZTEST(smf_tests, test_smf_flat)
237272 }
238273 }
239274
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" );
242276 zassert_equal (test_obj .transition_bits , test_value [test_obj .tv_idx ],
243277 "Final state not reached" );
244278
0 commit comments