Skip to content

Commit 9faaf68

Browse files
committed
tests: cloud: Adapt tests to new message types
Adapt the tests to handle CLOUD_CONNECT/_DISCONNECT instead of _READY_TO_SEND/_PAUSED. Signed-off-by: Jan Tore Guggedal <[email protected]>
1 parent 675d127 commit 9faaf68

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

tests/module/cloud/src/cloud_module_test.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ ZBUS_LISTENER_DEFINE(cloud_test_listener, cloud_chan_cb);
8080
#define FAKE_DEVICE_ID "test_device"
8181

8282
static K_SEM_DEFINE(cloud_disconnected, 0, 1);
83-
static K_SEM_DEFINE(cloud_connected_ready, 0, 1);
84-
static K_SEM_DEFINE(cloud_connected_paused, 0, 1);
83+
static K_SEM_DEFINE(cloud_connected, 0, 1);
8584
static K_SEM_DEFINE(data_sent, 0, 1);
8685

8786
static int nrf_cloud_client_id_get_custom_fake(char *buf, size_t len)
@@ -105,10 +104,8 @@ static void cloud_chan_cb(const struct zbus_channel *chan)
105104

106105
if (status == CLOUD_DISCONNECTED) {
107106
k_sem_give(&cloud_disconnected);
108-
} else if (status == CLOUD_CONNECTED_READY_TO_SEND) {
109-
k_sem_give(&cloud_connected_ready);
110-
} else if (status == CLOUD_CONNECTED_PAUSED) {
111-
k_sem_give(&cloud_connected_paused);
107+
} else if (status == CLOUD_CONNECTED) {
108+
k_sem_give(&cloud_connected);
112109
}
113110
}
114111
}
@@ -162,7 +159,7 @@ void test_connecting_backoff(void)
162159
/* Transport module needs CPU to run state machine */
163160
k_sleep(K_MSEC(10));
164161

165-
err = k_sem_take(&cloud_connected_ready, K_SECONDS(60));
162+
err = k_sem_take(&cloud_connected, K_SECONDS(60));
166163
TEST_ASSERT_EQUAL(-EAGAIN, err);
167164

168165
connect_duration_sec = k_uptime_delta(&connect_start_time) / MSEC_PER_SEC;
@@ -182,7 +179,7 @@ void test_transition_disconnected_connected_ready(void)
182179

183180
zbus_chan_pub(&NETWORK_CHAN, &status, K_NO_WAIT);
184181

185-
err = k_sem_take(&cloud_connected_ready, K_SECONDS(1));
182+
err = k_sem_take(&cloud_connected, K_SECONDS(1));
186183
TEST_ASSERT_EQUAL(0, err);
187184
}
188185

@@ -208,7 +205,7 @@ void test_sending_payload(void)
208205
TEST_ASSERT_EQUAL(false, nrf_cloud_coap_json_message_send_fake.arg2_val);
209206
}
210207

211-
void test_connected_ready_to_paused(void)
208+
void test_connected_to_disconnected(void)
212209
{
213210
int err;
214211
enum network_msg_type status = NETWORK_DISCONNECTED;
@@ -218,17 +215,17 @@ void test_connected_ready_to_paused(void)
218215
/* Transport module needs CPU to run state machine */
219216
k_sleep(K_MSEC(100));
220217

221-
err = k_sem_take(&cloud_connected_paused, K_SECONDS(1));
218+
err = k_sem_take(&cloud_disconnected, K_SECONDS(1));
222219
TEST_ASSERT_EQUAL(0, err);
223220
}
224221

225-
void test_connected_paused_to_ready_send_payload(void)
222+
void test_connected_disconnected_to_connected_send_payload(void)
226223
{
227224
int err;
228225
enum network_msg_type status = NETWORK_CONNECTED;
229226
struct cloud_msg msg = {
230227
.type = CLOUD_PAYLOAD_JSON,
231-
.payload.buffer = "{\"Another\": \"test\"}",
228+
.payload.buffer = "{\"Another\": \"1\"}",
232229
.payload.buffer_data_len = strnlen(msg.payload.buffer, sizeof(msg.payload.buffer)),
233230
};
234231

@@ -241,7 +238,7 @@ void test_connected_paused_to_ready_send_payload(void)
241238
/* Transport module needs CPU to run state machine */
242239
k_sleep(K_MSEC(100));
243240

244-
err = k_sem_take(&cloud_connected_ready, K_SECONDS(1));
241+
err = k_sem_take(&cloud_connected, K_SECONDS(1));
245242
TEST_ASSERT_EQUAL(0, err);
246243

247244
err = zbus_chan_pub(&CLOUD_CHAN, &msg, K_NO_WAIT);

tests/module/main/src/main.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ static void button_handler(uint32_t button_states, uint32_t has_changed)
123123
}
124124
}
125125

126-
static void send_cloud_connected_ready_to_send(void)
126+
static void send_cloud_connected(void)
127127
{
128128
struct cloud_msg cloud_msg = {
129-
.type = CLOUD_CONNECTED_READY_TO_SEND,
129+
.type = CLOUD_CONNECTED,
130130
};
131131

132132
int err = zbus_chan_pub(&CLOUD_CHAN, &cloud_msg, K_SECONDS(1));
@@ -202,7 +202,7 @@ static void send_network_disconnected(void)
202202
void test_init_to_triggering_state(void)
203203
{
204204
/* Transition the module into STATE_TRIGGERING */
205-
send_cloud_connected_ready_to_send();
205+
send_cloud_connected();
206206

207207
/* There's an initial transition to STATE_SAMPLE_DATA, where the entry function
208208
* sends a location search trigger.
@@ -226,7 +226,7 @@ void test_init_to_triggering_state(void)
226226
void test_button_press_on_connected(void)
227227
{
228228
/* Transition to STATE_SAMPLE_DATA */
229-
send_cloud_connected_ready_to_send();
229+
send_cloud_connected();
230230
expect_location_event(LOCATION_SEARCH_TRIGGER);
231231

232232
/* Transistion to STATE_WAIT_FOR_TRIGGER */
@@ -263,7 +263,7 @@ void test_button_press_on_disconnected(void)
263263
void test_trigger_interval_change_in_connected(void)
264264
{
265265
/* Transition to STATE_SAMPLE_DATA */
266-
send_cloud_connected_ready_to_send();
266+
send_cloud_connected();
267267
expect_location_event(LOCATION_SEARCH_TRIGGER);
268268

269269
/* As response to the shadow poll, the interval is set to 12 hours. */
@@ -303,7 +303,7 @@ void test_trigger_disconnect_and_connect_when_triggering(void)
303303
bool first_trigger_after_connect = true;
304304

305305
/* Transition to STATE_SAMPLE_DATA */
306-
send_cloud_connected_ready_to_send();
306+
send_cloud_connected();
307307

308308
/* As response to the shadow poll, the interval is set to 12 hours. */
309309
twelve_hour_interval_set();
@@ -331,7 +331,7 @@ void test_trigger_disconnect_and_connect_when_triggering(void)
331331
if (i % 2 == 0) {
332332
send_cloud_disconnected();
333333
expect_no_events(7200);
334-
send_cloud_connected_ready_to_send();
334+
send_cloud_connected();
335335

336336
first_trigger_after_connect = true;
337337
}
@@ -349,7 +349,7 @@ void test_fota_downloading(void)
349349
expect_fota_event(FOTA_DOWNLOADING_UPDATE);
350350

351351
/* A cloud ready message and button trigger should now cause no action */
352-
send_cloud_connected_ready_to_send();
352+
send_cloud_connected();
353353
expect_no_events(7200);
354354
button_handler(DK_BTN1_MSK, DK_BTN1_MSK);
355355
expect_no_events(7200);

0 commit comments

Comments
 (0)