Skip to content

Commit 0ccaa5d

Browse files
Andrew Boienashif
authored andcommitted
tests: mqtt_packet: run in user mode
Various globals for the test cases have been moved to the ztest memory domain data section via ZTEST_DMEM tags so that user mode can access them. Some anonymous arrays whose address was being placed in the msg_subackX structs have been split out so they are in ztest memory domain. Signed-off-by: Andrew Boie <[email protected]>
1 parent 7e3a34f commit 0ccaa5d

File tree

1 file changed

+63
-60
lines changed

1 file changed

+63
-60
lines changed

tests/net/lib/mqtt_packet/src/mqtt_packet.c

Lines changed: 63 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -24,44 +24,44 @@
2424

2525
#define BUFFER_SIZE 128
2626

27-
static u8_t rx_buffer[BUFFER_SIZE];
28-
static u8_t tx_buffer[BUFFER_SIZE];
29-
static struct mqtt_client client;
27+
static ZTEST_DMEM u8_t rx_buffer[BUFFER_SIZE];
28+
static ZTEST_DMEM u8_t tx_buffer[BUFFER_SIZE];
29+
static ZTEST_DMEM struct mqtt_client client;
3030

31-
static struct mqtt_topic topic_qos_0 = {
31+
static ZTEST_DMEM struct mqtt_topic topic_qos_0 = {
3232
.qos = 0,
3333
.topic.utf8 = TOPIC,
3434
.topic.size = TOPIC_LEN
3535
};
36-
static struct mqtt_topic topic_qos_1 = {
36+
static ZTEST_DMEM struct mqtt_topic topic_qos_1 = {
3737
.qos = 1,
3838
.topic.utf8 = TOPIC,
3939
.topic.size = TOPIC_LEN
4040
};
41-
static struct mqtt_topic topic_qos_2 = {
41+
static ZTEST_DMEM struct mqtt_topic topic_qos_2 = {
4242
.qos = 2,
4343
.topic.utf8 = TOPIC,
4444
.topic.size = TOPIC_LEN
4545
};
46-
static struct mqtt_topic will_topic_qos_0 = {
46+
static ZTEST_DMEM struct mqtt_topic will_topic_qos_0 = {
4747
.qos = 0,
4848
.topic.utf8 = WILL_TOPIC,
4949
.topic.size = WILL_TOPIC_LEN
5050
};
51-
static struct mqtt_topic will_topic_qos_1 = {
51+
static ZTEST_DMEM struct mqtt_topic will_topic_qos_1 = {
5252
.qos = 1,
5353
.topic.utf8 = WILL_TOPIC,
5454
.topic.size = WILL_TOPIC_LEN
5555
};
56-
static struct mqtt_utf8 will_msg = {
56+
static ZTEST_DMEM struct mqtt_utf8 will_msg = {
5757
.utf8 = WILL_MSG,
5858
.size = WILL_MSG_LEN
5959
};
60-
static struct mqtt_utf8 username = {
60+
static ZTEST_DMEM struct mqtt_utf8 username = {
6161
.utf8 = USERNAME,
6262
.size = USERNAME_LEN
6363
};
64-
static struct mqtt_utf8 password = {
64+
static ZTEST_DMEM struct mqtt_utf8 password = {
6565
.utf8 = PASSWORD,
6666
.size = PASSWORD_LEN
6767
};
@@ -219,12 +219,12 @@ static void print_array(const u8_t *a, u16_t size);
219219
* Message can be generated by the following command:
220220
* mosquitto_sub -V mqttv311 -i zephyr -k 60 -t sensors
221221
*/
222-
static
222+
static ZTEST_DMEM
223223
u8_t connect1[] = {0x10, 0x12, 0x00, 0x04, 0x4d, 0x51, 0x54, 0x54,
224224
0x04, 0x02, 0x00, 0x3c, 0x00, 0x06, 0x7a, 0x65,
225225
0x70, 0x68, 0x79, 0x72};
226226

227-
static struct mqtt_client client_connect1 = {
227+
static ZTEST_DMEM struct mqtt_client client_connect1 = {
228228
.clean_session = 1, .client_id.utf8 = CLIENTID,
229229
.client_id.size = CLIENTID_LEN,
230230
.will_retain = 0, .will_topic = NULL,
@@ -242,14 +242,14 @@ static struct mqtt_client client_connect1 = {
242242
* mosquitto_sub -V mqttv311 -i zephyr -k 60 -t sensors --will-topic quitting \
243243
* --will-qos 0 --will-payload bye
244244
*/
245-
static
245+
static ZTEST_DMEM
246246
u8_t connect2[] = {0x10, 0x21, 0x00, 0x04, 0x4d, 0x51, 0x54, 0x54,
247247
0x04, 0x06, 0x00, 0x3c, 0x00, 0x06, 0x7a, 0x65,
248248
0x70, 0x68, 0x79, 0x72, 0x00, 0x08, 0x71, 0x75,
249249
0x69, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x00, 0x03,
250250
0x62, 0x79, 0x65};
251251

252-
static struct mqtt_client client_connect2 = {
252+
static ZTEST_DMEM struct mqtt_client client_connect2 = {
253253
.clean_session = 1, .client_id.utf8 = CLIENTID,
254254
.client_id.size = CLIENTID_LEN,
255255
.will_retain = 0, .will_topic = &will_topic_qos_0,
@@ -265,14 +265,14 @@ static struct mqtt_client client_connect2 = {
265265
* mosquitto_sub -V mqttv311 -i zephyr -k 60 -t sensors --will-topic quitting \
266266
* --will-qos 0 --will-payload bye --will-retain
267267
*/
268-
static
268+
static ZTEST_DMEM
269269
u8_t connect3[] = {0x10, 0x21, 0x00, 0x04, 0x4d, 0x51, 0x54, 0x54,
270270
0x04, 0x26, 0x00, 0x3c, 0x00, 0x06, 0x7a, 0x65,
271271
0x70, 0x68, 0x79, 0x72, 0x00, 0x08, 0x71, 0x75,
272272
0x69, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x00, 0x03,
273273
0x62, 0x79, 0x65};
274274

275-
static struct mqtt_client client_connect3 = {
275+
static ZTEST_DMEM struct mqtt_client client_connect3 = {
276276
.clean_session = 1, .client_id.utf8 = CLIENTID,
277277
.client_id.size = CLIENTID_LEN,
278278
.will_retain = 1, .will_topic = &will_topic_qos_0,
@@ -288,14 +288,14 @@ static struct mqtt_client client_connect3 = {
288288
* mosquitto_sub -V mqttv311 -i zephyr -k 60 -t sensors --will-topic quitting \
289289
* --will-qos 1 --will-payload bye
290290
*/
291-
static
291+
static ZTEST_DMEM
292292
u8_t connect4[] = {0x10, 0x21, 0x00, 0x04, 0x4d, 0x51, 0x54, 0x54,
293293
0x04, 0x0e, 0x00, 0x3c, 0x00, 0x06, 0x7a, 0x65,
294294
0x70, 0x68, 0x79, 0x72, 0x00, 0x08, 0x71, 0x75,
295295
0x69, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x00, 0x03,
296296
0x62, 0x79, 0x65};
297297

298-
static struct mqtt_client client_connect4 = {
298+
static ZTEST_DMEM struct mqtt_client client_connect4 = {
299299
.clean_session = 1, .client_id.utf8 = CLIENTID,
300300
.client_id.size = CLIENTID_LEN,
301301
.will_retain = 0, .will_topic = &will_topic_qos_1,
@@ -311,14 +311,14 @@ static struct mqtt_client client_connect4 = {
311311
* mosquitto_sub -V mqttv311 -i zephyr -k 60 -t sensors --will-topic quitting \
312312
* --will-qos 1 --will-payload bye --will-retain
313313
*/
314-
static
314+
static ZTEST_DMEM
315315
u8_t connect5[] = {0x10, 0x21, 0x00, 0x04, 0x4d, 0x51, 0x54, 0x54,
316316
0x04, 0x2e, 0x00, 0x3c, 0x00, 0x06, 0x7a, 0x65,
317317
0x70, 0x68, 0x79, 0x72, 0x00, 0x08, 0x71, 0x75,
318318
0x69, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x00, 0x03,
319319
0x62, 0x79, 0x65};
320320

321-
static struct mqtt_client client_connect5 = {
321+
static ZTEST_DMEM struct mqtt_client client_connect5 = {
322322
.clean_session = 1, .client_id.utf8 = CLIENTID,
323323
.client_id.size = CLIENTID_LEN,
324324
.will_retain = 1, .will_topic = &will_topic_qos_1,
@@ -334,7 +334,7 @@ static struct mqtt_client client_connect5 = {
334334
* mosquitto_sub -V mqttv311 -i zephyr -k 60 -t sensors --will-topic quitting \
335335
* --will-qos 1 --will-payload bye --will-retain -u zephyr1 -P password
336336
*/
337-
static
337+
static ZTEST_DMEM
338338
u8_t connect6[] = {0x10, 0x34, 0x00, 0x04, 0x4d, 0x51, 0x54, 0x54,
339339
0x04, 0xee, 0x00, 0x3c, 0x00, 0x06, 0x7a, 0x65,
340340
0x70, 0x68, 0x79, 0x72, 0x00, 0x08, 0x71, 0x75,
@@ -343,15 +343,15 @@ u8_t connect6[] = {0x10, 0x34, 0x00, 0x04, 0x4d, 0x51, 0x54, 0x54,
343343
0x68, 0x79, 0x72, 0x31, 0x00, 0x08, 0x70, 0x61,
344344
0x73, 0x73, 0x77, 0x6f, 0x72, 0x64};
345345

346-
static struct mqtt_client client_connect6 = {
346+
static ZTEST_DMEM struct mqtt_client client_connect6 = {
347347
.clean_session = 1, .client_id.utf8 = CLIENTID,
348348
.client_id.size = CLIENTID_LEN,
349349
.will_retain = 1, .will_topic = &will_topic_qos_1,
350350
.will_message = &will_msg, .user_name = &username,
351351
.password = &password
352352
};
353353

354-
static
354+
static ZTEST_DMEM
355355
u8_t disconnect1[] = {0xe0, 0x00};
356356

357357
/*
@@ -361,11 +361,11 @@ u8_t disconnect1[] = {0xe0, 0x00};
361361
* Message can be generated by the following command:
362362
* mosquitto_pub -V mqttv311 -i zephyr -t sensors -q 0 -m "OK"
363363
*/
364-
static
364+
static ZTEST_DMEM
365365
u8_t publish1[] = {0x30, 0x0b, 0x00, 0x07, 0x73, 0x65, 0x6e, 0x73,
366366
0x6f, 0x72, 0x73, 0x4f, 0x4b};
367367

368-
static struct mqtt_publish_param msg_publish1 = {
368+
static ZTEST_DMEM struct mqtt_publish_param msg_publish1 = {
369369
.dup_flag = 0, .retain_flag = 0, .message_id = 0,
370370
.message.topic.qos = 0,
371371
.message.topic.topic.utf8 = TOPIC,
@@ -381,11 +381,11 @@ static struct mqtt_publish_param msg_publish1 = {
381381
* Message can be generated by the following command:
382382
* mosquitto_pub -V mqttv311 -i zephyr -t sensors -q 0 -m "OK" -r
383383
*/
384-
static
384+
static ZTEST_DMEM
385385
u8_t publish2[] = {0x31, 0x0b, 0x00, 0x07, 0x73, 0x65, 0x6e, 0x73,
386386
0x6f, 0x72, 0x73, 0x4f, 0x4b};
387387

388-
static struct mqtt_publish_param msg_publish2 = {
388+
static ZTEST_DMEM struct mqtt_publish_param msg_publish2 = {
389389
.dup_flag = 0, .retain_flag = 1, .message_id = 0,
390390
.message.topic.qos = 0,
391391
.message.topic.topic.utf8 = TOPIC,
@@ -401,11 +401,11 @@ static struct mqtt_publish_param msg_publish2 = {
401401
* Message can be generated by the following command:
402402
* mosquitto_pub -V mqttv311 -i zephyr -t sensors -q 1 -m "OK" -r
403403
*/
404-
static
404+
static ZTEST_DMEM
405405
u8_t publish3[] = {0x33, 0x0d, 0x00, 0x07, 0x73, 0x65, 0x6e, 0x73,
406406
0x6f, 0x72, 0x73, 0x00, 0x01, 0x4f, 0x4b};
407407

408-
static struct mqtt_publish_param msg_publish3 = {
408+
static ZTEST_DMEM struct mqtt_publish_param msg_publish3 = {
409409
.dup_flag = 0, .retain_flag = 1, .message_id = 1,
410410
.message.topic.qos = 1,
411411
.message.topic.topic.utf8 = TOPIC,
@@ -421,10 +421,10 @@ static struct mqtt_publish_param msg_publish3 = {
421421
* Message can be generated by the following command:
422422
* mosquitto_pub -V mqttv311 -i zephyr -t sensors -q 2 -m "OK"
423423
*/
424-
static
424+
static ZTEST_DMEM
425425
u8_t publish4[] = {0x34, 0x0d, 0x00, 0x07, 0x73, 0x65, 0x6e, 0x73,
426426
0x6f, 0x72, 0x73, 0x00, 0x01, 0x4f, 0x4b};
427-
static struct mqtt_publish_param msg_publish4 = {
427+
static ZTEST_DMEM struct mqtt_publish_param msg_publish4 = {
428428
.dup_flag = 0, .retain_flag = 0, .message_id = 1,
429429
.message.topic.qos = 2,
430430
.message.topic.topic.utf8 = TOPIC,
@@ -440,10 +440,10 @@ static struct mqtt_publish_param msg_publish4 = {
440440
* Message can be generated by the following command:
441441
* mosquitto_sub -V mqttv311 -i zephyr -t sensors -q 0
442442
*/
443-
static
443+
static ZTEST_DMEM
444444
u8_t subscribe1[] = {0x82, 0x0c, 0x00, 0x01, 0x00, 0x07, 0x73, 0x65,
445445
0x6e, 0x73, 0x6f, 0x72, 0x73, 0x00};
446-
static struct mqtt_subscription_list msg_subscribe1 = {
446+
static ZTEST_DMEM struct mqtt_subscription_list msg_subscribe1 = {
447447
.message_id = 1, .list_count = 1, .list = &topic_qos_0
448448
};
449449

@@ -454,10 +454,10 @@ static struct mqtt_subscription_list msg_subscribe1 = {
454454
* Message can be generated by the following command:
455455
* mosquitto_sub -V mqttv311 -i zephyr -t sensors -q 1
456456
*/
457-
static
457+
static ZTEST_DMEM
458458
u8_t subscribe2[] = {0x82, 0x0c, 0x00, 0x01, 0x00, 0x07, 0x73, 0x65,
459459
0x6e, 0x73, 0x6f, 0x72, 0x73, 0x01};
460-
static struct mqtt_subscription_list msg_subscribe2 = {
460+
static ZTEST_DMEM struct mqtt_subscription_list msg_subscribe2 = {
461461
.message_id = 1, .list_count = 1, .list = &topic_qos_1
462462
};
463463

@@ -468,10 +468,10 @@ static struct mqtt_subscription_list msg_subscribe2 = {
468468
* Message can be generated by the following command:
469469
* mosquitto_sub -V mqttv311 -i zephyr -t sensors -q 2
470470
*/
471-
static
471+
static ZTEST_DMEM
472472
u8_t subscribe3[] = {0x82, 0x0c, 0x00, 0x01, 0x00, 0x07, 0x73, 0x65,
473473
0x6e, 0x73, 0x6f, 0x72, 0x73, 0x02};
474-
static struct mqtt_subscription_list msg_subscribe3 = {
474+
static ZTEST_DMEM struct mqtt_subscription_list msg_subscribe3 = {
475475
.message_id = 1, .list_count = 1, .list = &topic_qos_2
476476
};
477477

@@ -482,11 +482,12 @@ static struct mqtt_subscription_list msg_subscribe3 = {
482482
* Message can be generated by the following command:
483483
* mosquitto_sub -V mqttv311 -i zephyr -t sensors -q 0
484484
*/
485-
static
485+
static ZTEST_DMEM
486486
u8_t suback1[] = {0x90, 0x03, 0x00, 0x01, 0x00};
487-
static struct mqtt_suback_param msg_suback1 = {
487+
static ZTEST_DMEM u8_t data_suback1[] = { MQTT_SUBACK_SUCCESS_QoS_0 };
488+
static ZTEST_DMEM struct mqtt_suback_param msg_suback1 = {
488489
.message_id = 1, .return_codes.len = 1,
489-
.return_codes.data = (u8_t[]){ MQTT_SUBACK_SUCCESS_QoS_0 }
490+
.return_codes.data = data_suback1
490491
};
491492

492493
/*
@@ -496,11 +497,12 @@ static struct mqtt_suback_param msg_suback1 = {
496497
* Message can be generated by the following command:
497498
* mosquitto_sub -V mqttv311 -i zephyr -t sensors -q 1
498499
*/
499-
static
500+
static ZTEST_DMEM
500501
u8_t suback2[] = {0x90, 0x03, 0x00, 0x01, 0x01};
501-
static struct mqtt_suback_param msg_suback2 = {
502+
static ZTEST_DMEM u8_t data_suback2[] = { MQTT_SUBACK_SUCCESS_QoS_1 };
503+
static ZTEST_DMEM struct mqtt_suback_param msg_suback2 = {
502504
.message_id = 1, .return_codes.len = 1,
503-
.return_codes.data = (u8_t[]){ MQTT_SUBACK_SUCCESS_QoS_1 }
505+
.return_codes.data = data_suback2
504506
};
505507

506508
/*
@@ -510,37 +512,38 @@ static struct mqtt_suback_param msg_suback2 = {
510512
* Message can be generated by the following command:
511513
* mosquitto_sub -V mqttv311 -i zephyr -t sensors -q 2
512514
*/
513-
static
515+
static ZTEST_DMEM
514516
u8_t suback3[] = {0x90, 0x03, 0x00, 0x01, 0x02};
515-
static struct mqtt_suback_param msg_suback3 = {
517+
static ZTEST_DMEM u8_t data_suback3[] = { MQTT_SUBACK_SUCCESS_QoS_2 };
518+
static ZTEST_DMEM struct mqtt_suback_param msg_suback3 = {
516519
.message_id = 1, .return_codes.len = 1,
517-
.return_codes.data = (u8_t[]){ MQTT_SUBACK_SUCCESS_QoS_2 }
520+
.return_codes.data = data_suback3
518521
};
519522

520-
static
523+
static ZTEST_DMEM
521524
u8_t pingreq1[] = {0xc0, 0x00};
522525

523-
static
526+
static ZTEST_DMEM
524527
u8_t puback1[] = {0x40, 0x02, 0x00, 0x01};
525-
static struct mqtt_puback_param msg_puback1 = {.message_id = 1};
528+
static ZTEST_DMEM struct mqtt_puback_param msg_puback1 = {.message_id = 1};
526529

527-
static
530+
static ZTEST_DMEM
528531
u8_t pubrec1[] = {0x50, 0x02, 0x00, 0x01};
529-
static struct mqtt_pubrec_param msg_pubrec1 = {.message_id = 1};
532+
static ZTEST_DMEM struct mqtt_pubrec_param msg_pubrec1 = {.message_id = 1};
530533

531-
static
534+
static ZTEST_DMEM
532535
u8_t pubrel1[] = {0x62, 0x02, 0x00, 0x01};
533-
static struct mqtt_pubrel_param msg_pubrel1 = {.message_id = 1};
536+
static ZTEST_DMEM struct mqtt_pubrel_param msg_pubrel1 = {.message_id = 1};
534537

535-
static
538+
static ZTEST_DMEM
536539
u8_t pubcomp1[] = {0x70, 0x02, 0x00, 0x01};
537-
static struct mqtt_pubcomp_param msg_pubcomp1 = {.message_id = 1};
540+
static ZTEST_DMEM struct mqtt_pubcomp_param msg_pubcomp1 = {.message_id = 1};
538541

539-
static
542+
static ZTEST_DMEM
540543
u8_t unsuback1[] = {0xb0, 0x02, 0x00, 0x01};
541-
static struct mqtt_unsuback_param msg_unsuback1 = {.message_id = 1};
544+
static ZTEST_DMEM struct mqtt_unsuback_param msg_unsuback1 = {.message_id = 1};
542545

543-
static
546+
static ZTEST_DMEM
544547
struct mqtt_test mqtt_tests[] = {
545548

546549
{.test_name = "CONNECT, new session, zeros",
@@ -1083,6 +1086,6 @@ void test_mqtt_packet(void)
10831086
void test_main(void)
10841087
{
10851088
ztest_test_suite(test_mqtt_packet_fn,
1086-
ztest_unit_test(test_mqtt_packet));
1089+
ztest_user_unit_test(test_mqtt_packet));
10871090
ztest_run_test_suite(test_mqtt_packet_fn);
10881091
}

0 commit comments

Comments
 (0)