12
12
#include "power.h"
13
13
#include "network.h"
14
14
#include "checks.h"
15
+ #include "fota.h"
15
16
17
+ ZBUS_MSG_SUBSCRIBER_DEFINE (fota_subscriber );
16
18
ZBUS_MSG_SUBSCRIBER_DEFINE (location_subscriber );
17
19
ZBUS_MSG_SUBSCRIBER_DEFINE (network_subscriber );
18
20
ZBUS_MSG_SUBSCRIBER_DEFINE (power_subscriber );
21
+ ZBUS_CHAN_ADD_OBS (FOTA_CHAN , fota_subscriber , 0 );
19
22
ZBUS_CHAN_ADD_OBS (LOCATION_CHAN , location_subscriber , 0 );
20
23
ZBUS_CHAN_ADD_OBS (NETWORK_CHAN , network_subscriber , 0 );
21
24
ZBUS_CHAN_ADD_OBS (POWER_CHAN , power_subscriber , 0 );
22
25
23
26
LOG_MODULE_REGISTER (main_module_checks , 4 );
24
27
25
- void check_location_event (enum location_msg_type expected_location_type )
28
+ void expect_location_event (enum location_msg_type expected_location_type )
26
29
{
27
30
int err ;
28
31
const struct zbus_channel * chan ;
@@ -51,7 +54,7 @@ void check_location_event(enum location_msg_type expected_location_type)
51
54
TEST_ASSERT_EQUAL (expected_location_type , location_msg_type );
52
55
}
53
56
54
- void check_network_event (enum network_msg_type expected_network_type )
57
+ void expect_network_event (enum network_msg_type expected_network_type )
55
58
{
56
59
int err ;
57
60
const struct zbus_channel * chan ;
@@ -80,7 +83,7 @@ void check_network_event(enum network_msg_type expected_network_type)
80
83
TEST_ASSERT_EQUAL (expected_network_type , network_msg .type );
81
84
}
82
85
83
- void check_power_event (enum power_msg_type expected_power_type )
86
+ void expect_power_event (enum power_msg_type expected_power_type )
84
87
{
85
88
int err ;
86
89
const struct zbus_channel * chan ;
@@ -109,8 +112,36 @@ void check_power_event(enum power_msg_type expected_power_type)
109
112
TEST_ASSERT_EQUAL (expected_power_type , power_msg .type );
110
113
}
111
114
115
+ void expect_fota_event (enum fota_msg_type expected_fota_type )
116
+ {
117
+ int err ;
118
+ const struct zbus_channel * chan ;
119
+ enum fota_msg_type fota_msg_type ;
120
+
121
+ /* Allow the test thread to sleep so that the DUT's thread is allowed to run. */
122
+ k_sleep (K_MSEC (100 ));
123
+
124
+ err = zbus_sub_wait_msg (& fota_subscriber , & chan , & fota_msg_type , K_MSEC (10000 ));
125
+ if (err == - ENOMSG ) {
126
+ LOG_ERR ("No FOTA event received" );
127
+ TEST_FAIL ();
128
+ } else if (err ) {
129
+ LOG_ERR ("zbus_sub_wait, error: %d" , err );
130
+ TEST_FAIL ();
112
131
113
- static void check_no_location_events (void )
132
+ return ;
133
+ }
134
+
135
+ if (chan != & FOTA_CHAN ) {
136
+ LOG_ERR ("Received message from wrong channel, expected %s, got %s" ,
137
+ zbus_chan_name (& FOTA_CHAN ), zbus_chan_name (chan ));
138
+ TEST_FAIL ();
139
+ }
140
+
141
+ TEST_ASSERT_EQUAL (expected_fota_type , fota_msg_type );
142
+ }
143
+
144
+ static void expect_no_location_events (void )
114
145
{
115
146
int err ;
116
147
const struct zbus_channel * chan ;
@@ -130,7 +161,7 @@ static void check_no_location_events(void)
130
161
TEST_FAIL ();
131
162
}
132
163
133
- static void check_no_network_events (void )
164
+ static void expect_no_network_events (void )
134
165
{
135
166
int err ;
136
167
const struct zbus_channel * chan ;
@@ -150,7 +181,7 @@ static void check_no_network_events(void)
150
181
TEST_FAIL ();
151
182
}
152
183
153
- static void check_no_power_events (void )
184
+ static void expect_no_power_events (void )
154
185
{
155
186
int err ;
156
187
const struct zbus_channel * chan ;
@@ -170,13 +201,34 @@ static void check_no_power_events(void)
170
201
TEST_FAIL ();
171
202
}
172
203
173
- void check_no_events (uint32_t timeout_sec )
204
+ static void expect_no_fota_events (void )
205
+ {
206
+ int err ;
207
+ const struct zbus_channel * chan ;
208
+ enum fota_msg_type fota_msg_type ;
209
+
210
+ err = zbus_sub_wait_msg (& fota_subscriber , & chan , & fota_msg_type , K_MSEC (10000 ));
211
+ if (err == - ENOMSG ) {
212
+ return ;
213
+ } else if (err ) {
214
+ LOG_ERR ("zbus_sub_wait, error: %d" , err );
215
+ TEST_FAIL ();
216
+
217
+ return ;
218
+ }
219
+
220
+ LOG_ERR ("Received unexpected FOTA event: %d" , fota_msg_type );
221
+ TEST_FAIL ();
222
+ }
223
+
224
+ void expect_no_events (uint32_t timeout_sec )
174
225
{
175
226
k_sleep (K_SECONDS (timeout_sec ));
176
227
177
- check_no_location_events ();
178
- check_no_network_events ();
179
- check_no_power_events ();
228
+ expect_no_location_events ();
229
+ expect_no_network_events ();
230
+ expect_no_power_events ();
231
+ expect_no_fota_events ();
180
232
}
181
233
182
234
void purge_location_events (void )
@@ -237,11 +289,33 @@ void purge_power_events(void)
237
289
}
238
290
}
239
291
292
+ void purge_fota_events (void )
293
+ {
294
+ while (true) {
295
+ int err ;
296
+ const struct zbus_channel * chan ;
297
+ enum fota_msg_type fota_msg_type ;
298
+
299
+ err = zbus_sub_wait_msg (& fota_subscriber , & chan , & fota_msg_type , K_MSEC (100 ));
300
+ if (err == - ENOMSG ) {
301
+ break ;
302
+ } else if (err ) {
303
+ LOG_ERR ("zbus_sub_wait, error: %d" , err );
304
+ TEST_FAIL ();
305
+
306
+ return ;
307
+ }
308
+ }
309
+ }
310
+
240
311
void purge_all_events (void )
241
312
{
313
+ k_sleep (K_SECONDS (1 ));
314
+
242
315
purge_location_events ();
243
316
purge_network_events ();
244
317
purge_power_events ();
318
+ purge_fota_events ();
245
319
}
246
320
247
321
int wait_for_location_event (enum location_msg_type expected_type , uint32_t timeout_sec )
0 commit comments