1 /*
2 * Copyright (c) 2021 Nordic Semiconductor
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6 #include "mesh_test.h"
7 #include "mesh/net.h"
8 #include "mesh/transport.h"
9 #include "mesh/va.h"
10 #include <zephyr/sys/byteorder.h>
11
12 #include "mesh/crypto.h"
13
14 #define LOG_MODULE_NAME test_transport
15
16 #include <zephyr/logging/log.h>
17 LOG_MODULE_REGISTER(LOG_MODULE_NAME);
18
19 #include "common/bt_str.h"
20
21 /*
22 * Transport layer tests:
23 * This file contains tests for sending and receiving messages end-to-end in
24 * all permutations. Covers:
25 * - Address resolution
26 * - Segmented messages
27 * - Single segment
28 * - Max length
29 * - Groups
30 * - Virtual addresses
31 * - Loopback
32 *
33 * Tests are divided into senders and receivers.
34 */
35
assert_post_action(const char * file,unsigned int line)36 void assert_post_action(const char *file, unsigned int line)
37 {
38 FAIL("Asserted at %s:%u", file, line);
39 }
40
41 #define GROUP_ADDR 0xc000
42 #define WAIT_TIME 70 /*seconds*/
43 #define SYNC_CHAN 0
44 #define CLI_DEV 0
45 #define SRV1_DEV 1
46
47 extern enum bst_result_t bst_result;
48
49 static const struct bt_mesh_test_cfg tx_cfg = {
50 .addr = 0x0001,
51 .dev_key = { 0x01 },
52 };
53 static const struct bt_mesh_test_cfg rx_cfg = {
54 .addr = 0x0002,
55 .dev_key = { 0x02 },
56 };
57
58 static int expected_send_err;
59
60 static uint8_t test_va_col_uuid[][16] = {
61 {
62 0xe3, 0x94, 0xe7, 0xc1, 0xc5, 0x14, 0x72, 0x11,
63 0x68, 0x36, 0x19, 0x30, 0x99, 0x34, 0x53, 0x62
64 },
65 {
66 0x5e, 0x49, 0x5a, 0xd9, 0x44, 0xdf, 0xae, 0xc0,
67 0x62, 0xd8, 0x0d, 0xed, 0x16, 0x82, 0xd1, 0x7d
68 },
69 };
70 static const uint16_t test_va_col_addr = 0x809D;
71
test_tx_init(void)72 static void test_tx_init(void)
73 {
74 bt_mesh_test_cfg_set(&tx_cfg, WAIT_TIME);
75 }
76
test_rx_init(void)77 static void test_rx_init(void)
78 {
79 bt_mesh_test_cfg_set(&rx_cfg, WAIT_TIME);
80 }
81
async_send_end(int err,void * data)82 static void async_send_end(int err, void *data)
83 {
84 struct k_sem *sem = data;
85
86 if (err != expected_send_err) {
87 FAIL("Async send failed: got %d, expected", err, expected_send_err);
88 }
89
90 if (sem) {
91 k_sem_give(sem);
92 }
93 }
94
rx_sar_conf(void)95 static void rx_sar_conf(void)
96 {
97 #ifdef CONFIG_BT_MESH_V1d1
98 /* Reconfigure SAR Receiver state so that the transport layer does
99 * generate Segmented Acks as rarely as possible.
100 */
101 struct bt_mesh_sar_rx rx_set = {
102 .seg_thresh = 0x1f,
103 .ack_delay_inc = CONFIG_BT_MESH_SAR_RX_ACK_DELAY_INC,
104 .discard_timeout = CONFIG_BT_MESH_SAR_RX_DISCARD_TIMEOUT,
105 .rx_seg_int_step = CONFIG_BT_MESH_SAR_RX_SEG_INT_STEP,
106 .ack_retrans_count = CONFIG_BT_MESH_SAR_RX_ACK_RETRANS_COUNT,
107 };
108
109 #if defined(CONFIG_BT_MESH_SAR_CFG)
110 bt_mesh_test_sar_conf_set(NULL, &rx_set);
111 #else
112 bt_mesh.sar_rx = rx_set;
113 #endif
114 #endif
115 }
116
117 static const struct bt_mesh_send_cb async_send_cb = {
118 .end = async_send_end,
119 };
120
121 /** Test vector containing various permutations of transport messages. */
122 static const struct {
123 uint16_t len;
124 enum bt_mesh_test_send_flags flags;
125 } test_vector[] = {
126 {.len = 1, .flags = 0},
127 {.len = 1, .flags = FORCE_SEGMENTATION},
128 {.len = BT_MESH_APP_SEG_SDU_MAX, .flags = 0},
129 {.len = BT_MESH_APP_SEG_SDU_MAX, .flags = FORCE_SEGMENTATION},
130
131 /* segmented */
132 {.len = BT_MESH_APP_SEG_SDU_MAX + 1, .flags = 0},
133 {.len = 256, .flags = LONG_MIC},
134 {.len = BT_MESH_TX_SDU_MAX - BT_MESH_MIC_SHORT, .flags = 0},
135 };
136
137 /** Test sending of unicast messages using the test vector.
138 */
test_tx_unicast(void)139 static void test_tx_unicast(void)
140 {
141 int err;
142
143 bt_mesh_test_setup();
144
145 for (int i = 0; i < ARRAY_SIZE(test_vector); i++) {
146 err = bt_mesh_test_send(rx_cfg.addr, NULL, test_vector[i].len,
147 test_vector[i].flags, K_SECONDS(10));
148 ASSERT_OK_MSG(err, "Failed sending vector %d", i);
149 }
150
151 PASS();
152 }
153
154 /** Test sending of group messages using the test vector.
155 */
test_tx_group(void)156 static void test_tx_group(void)
157 {
158 int err;
159
160 bt_mesh_test_setup();
161
162 for (int i = 0; i < ARRAY_SIZE(test_vector); i++) {
163 err = bt_mesh_test_send(GROUP_ADDR, NULL, test_vector[i].len,
164 test_vector[i].flags, K_SECONDS(20));
165 ASSERT_OK_MSG(err, "Failed sending vector %d", i);
166 }
167
168 PASS();
169 }
170
171 /** Test sending to a fixed group address. */
test_tx_fixed(void)172 static void test_tx_fixed(void)
173 {
174 bt_mesh_test_setup();
175
176 ASSERT_OK(bt_mesh_test_send(BT_MESH_ADDR_RELAYS, NULL, test_vector[0].len,
177 test_vector[0].flags, K_SECONDS(2)));
178
179 k_sleep(K_SECONDS(2));
180
181 ASSERT_OK(bt_mesh_test_send(BT_MESH_ADDR_RELAYS, NULL, test_vector[0].len,
182 test_vector[0].flags, K_SECONDS(2)));
183
184 k_sleep(K_SECONDS(2));
185
186 ASSERT_OK(bt_mesh_test_send(BT_MESH_ADDR_RELAYS, NULL, test_vector[0].len,
187 test_vector[0].flags, K_SECONDS(2)));
188
189 PASS();
190 }
191
192 /** Test sending of virtual address messages using the test vector.
193 */
test_tx_va(void)194 static void test_tx_va(void)
195 {
196 const struct bt_mesh_va *va;
197 int err;
198
199 bt_mesh_test_setup();
200
201 err = bt_mesh_va_add(test_va_uuid, &va);
202 ASSERT_OK_MSG(err, "Virtual addr add failed (err %d)", err);
203
204 /* Wait for the receiver to subscribe on address. */
205 k_sleep(K_SECONDS(1));
206
207 for (int i = 0; i < ARRAY_SIZE(test_vector); i++) {
208 err = bt_mesh_test_send(va->addr, va->uuid, test_vector[i].len,
209 test_vector[i].flags, K_SECONDS(20));
210 ASSERT_OK_MSG(err, "Failed sending vector %d", i);
211 }
212
213 PASS();
214 }
215
216 /** Test sending the test vector using virtual addresses with collision.
217 */
test_tx_va_collision(void)218 static void test_tx_va_collision(void)
219 {
220 const struct bt_mesh_va *va[ARRAY_SIZE(test_va_col_uuid)];
221 int err;
222
223 bt_mesh_test_setup();
224
225 for (int i = 0; i < ARRAY_SIZE(test_va_col_uuid); i++) {
226 err = bt_mesh_va_add(test_va_col_uuid[i], &va[i]);
227 ASSERT_OK_MSG(err, "Virtual addr add failed (err %d)", err);
228 ASSERT_EQUAL(test_va_col_addr, va[i]->addr);
229 }
230
231 /* Wait for the receiver to subscribe on address. */
232 k_sleep(K_SECONDS(1));
233
234 for (int i = 0; i < ARRAY_SIZE(test_vector); i++) {
235 for (int j = 0; j < ARRAY_SIZE(test_va_col_uuid); j++) {
236 LOG_INF("Sending msg #%d to %s addr", i, (j == 0 ? "first" : "second"));
237
238 err = bt_mesh_test_send(test_va_col_addr, va[j]->uuid, test_vector[i].len,
239 test_vector[i].flags, K_SECONDS(20));
240 ASSERT_OK_MSG(err, "Failed sending vector %d", i);
241 }
242 }
243
244 PASS();
245 }
246
247 /** Test sending of messages to own unicast address using the test vector.
248 */
test_tx_loopback(void)249 static void test_tx_loopback(void)
250 {
251 int err;
252
253 bt_mesh_test_setup();
254
255 for (int i = 0; i < ARRAY_SIZE(test_vector); i++) {
256 err = bt_mesh_test_send(cfg->addr, NULL, test_vector[i].len, test_vector[i].flags,
257 K_NO_WAIT);
258 ASSERT_OK_MSG(err, "Failed sending vector %d", i);
259 bt_mesh_test_recv(test_vector[i].len, cfg->addr, NULL, K_SECONDS(2));
260
261 if (test_stats.received != i + 1) {
262 FAIL("Didn't receive message %d", i);
263 }
264 }
265
266 PASS();
267 }
268
269 /** Test sending of messages with an app key that's unknown to the receiver.
270 *
271 * The sender should be able to send the message successfully, but the receiver
272 * should fail the decryption step and ignore the packet.
273 */
test_tx_unknown_app(void)274 static void test_tx_unknown_app(void)
275 {
276 uint8_t app_key[16] = { 0xba, 0xd0, 0x11, 0x22};
277 uint8_t status = 0;
278
279 bt_mesh_test_setup();
280
281 ASSERT_OK_MSG(bt_mesh_cfg_cli_app_key_add(0, cfg->addr, 0, 1, app_key, &status),
282 "Failed adding additional appkey");
283 if (status) {
284 FAIL("App key add status: 0x%02x", status);
285 }
286
287 ASSERT_OK_MSG(bt_mesh_cfg_cli_mod_app_bind(0, cfg->addr, cfg->addr, 1,
288 TEST_MOD_ID, &status),
289 "Failed binding additional appkey");
290 if (status) {
291 FAIL("App key add status: 0x%02x", status);
292 }
293
294 test_send_ctx.app_idx = 1;
295
296 ASSERT_OK_MSG(bt_mesh_test_send(rx_cfg.addr, NULL, 5, 0, K_SECONDS(1)),
297 "Failed sending unsegmented");
298
299 ASSERT_OK_MSG(bt_mesh_test_send(rx_cfg.addr, NULL, 25, 0, K_SECONDS(1)),
300 "Failed sending segmented");
301
302 PASS();
303 }
304
305 /** Test sending of messages using the test vector.
306 *
307 * Messages are sent to a group address that both the sender and receiver
308 * subscribes to, verifying that the loopback and advertiser paths both work
309 * when used in combination.
310 */
test_tx_loopback_group(void)311 static void test_tx_loopback_group(void)
312 {
313 uint8_t status;
314 int err;
315
316 bt_mesh_test_setup();
317
318 err = bt_mesh_cfg_cli_mod_sub_add(0, cfg->addr, cfg->addr, GROUP_ADDR,
319 TEST_MOD_ID, &status);
320 ASSERT_OK_MSG(err || status, "Mod sub add failed (err %d, status %u)",
321 err, status);
322
323 for (int i = 0; i < ARRAY_SIZE(test_vector); i++) {
324 err = bt_mesh_test_send(GROUP_ADDR, NULL, test_vector[i].len,
325 test_vector[i].flags,
326 K_SECONDS(20));
327
328 ASSERT_OK_MSG(err, "Failed sending vector %d", i);
329
330 k_sleep(K_SECONDS(1));
331 ASSERT_OK_MSG(bt_mesh_test_recv(test_vector[i].len, GROUP_ADDR,
332 NULL, K_SECONDS(1)),
333 "Failed receiving loopback %d", i);
334
335 if (test_stats.received != i + 1) {
336 FAIL("Didn't receive message %d", i);
337 }
338 }
339
340 PASS();
341 }
342
343 /** Start sending multiple segmented messages to the same destination at the
344 * same time.
345 *
346 * The second message should be blocked until the first is finished, but
347 * should still succeed.
348 */
test_tx_seg_block(void)349 static void test_tx_seg_block(void)
350 {
351 bt_mesh_test_setup();
352
353
354 ASSERT_OK(bt_mesh_test_send(rx_cfg.addr, NULL, 20, 0, K_NO_WAIT));
355
356 /* Send some more to the same address before the first is finished. */
357 ASSERT_OK(bt_mesh_test_send(rx_cfg.addr, NULL, 20, 0, K_NO_WAIT));
358 ASSERT_OK(bt_mesh_test_send(rx_cfg.addr, NULL, 20, 0, K_SECONDS(10)));
359
360 if (test_stats.sent != 3) {
361 FAIL("Not all messages completed (%u/3)", test_stats.sent);
362 }
363
364 PASS();
365 }
366
367 /** Start sending multiple segmented messages to the same destination at the
368 * same time.
369 *
370 * The second message should be blocked until the first is finished, but
371 * should still succeed.
372 */
test_tx_seg_concurrent(void)373 static void test_tx_seg_concurrent(void)
374 {
375 struct k_sem sem;
376
377 k_sem_init(&sem, 0, 1);
378 bt_mesh_test_setup();
379
380 ASSERT_OK(bt_mesh_test_send_async(rx_cfg.addr, NULL, 20, 0, &async_send_cb, &sem));
381
382 /* Send some more to the same address before the first is finished. */
383 ASSERT_OK(bt_mesh_test_send(GROUP_ADDR, NULL, 20, 0, K_SECONDS(10)));
384
385 /* Ensure that the first message finishes as well */
386 ASSERT_OK(k_sem_take(&sem, K_SECONDS(1)));
387
388 PASS();
389 }
390
391 /** Start sending a segmented message, then before it's finished, start an IV
392 * update.
393 * After the first one finishes, the IV update state shall be active.
394 * Send another message, then end the IV update state before it's finished.
395 * The IV index should change when this message finishes.
396 *
397 * The IV update should not interfere with the segmented message, and the
398 */
test_tx_seg_ivu(void)399 static void test_tx_seg_ivu(void)
400 {
401 struct k_sem sem;
402 uint32_t iv_index;
403
404 k_sem_init(&sem, 0, 1);
405
406 bt_mesh_test_setup();
407
408 /* Enable IV update test mode to override IV update timers */
409 bt_mesh_iv_update_test(true);
410
411 iv_index = BT_MESH_NET_IVI_TX;
412
413 ASSERT_OK(bt_mesh_test_send_async(rx_cfg.addr, NULL, 255, 0, &async_send_cb,
414 &sem));
415 /* Start IV update */
416 bt_mesh_iv_update();
417
418 if (iv_index != BT_MESH_NET_IVI_TX) {
419 FAIL("Should not change TX IV index before IV update ends");
420 }
421
422 k_sem_take(&sem, K_SECONDS(20));
423
424 ASSERT_OK(bt_mesh_test_send_async(rx_cfg.addr, NULL, 255, 0, &async_send_cb,
425 &sem));
426
427 /* End IV update */
428 bt_mesh_iv_update();
429
430 if (iv_index != BT_MESH_NET_IVI_TX) {
431 FAIL("Should not change TX IV index until message finishes");
432 }
433
434 k_sem_take(&sem, K_SECONDS(20));
435
436 if (iv_index + 1 != BT_MESH_NET_IVI_TX) {
437 FAIL("Should have changed TX IV index when the message was completed");
438 }
439
440 PASS();
441 }
442
443 /** Send a segmented message to an unknown unicast address, expect it to fail
444 * and return -ETIMEDOUT in the send end callback.
445 */
test_tx_seg_fail(void)446 static void test_tx_seg_fail(void)
447 {
448 struct k_sem sem;
449
450 k_sem_init(&sem, 0, 1);
451 bt_mesh_test_setup();
452
453 expected_send_err = -ETIMEDOUT;
454 ASSERT_OK(bt_mesh_test_send_async(0x0fff, NULL, 20, 0, &async_send_cb, &sem));
455 ASSERT_OK(k_sem_take(&sem, K_SECONDS(10)));
456
457 PASS();
458 }
459
460 /* Receiver test functions */
461
462 /** @brief Receive unicast messages using the test vector.
463 */
test_rx_unicast(void)464 static void test_rx_unicast(void)
465 {
466 int err;
467
468 bt_mesh_test_setup();
469 rx_sar_conf();
470
471 for (int i = 0; i < ARRAY_SIZE(test_vector); i++) {
472 err = bt_mesh_test_recv(test_vector[i].len, cfg->addr,
473 NULL, K_SECONDS(10));
474 ASSERT_OK_MSG(err, "Failed receiving vector %d", i);
475 }
476
477 PASS();
478 }
479
480 /** @brief Receive group messages using the test vector.
481 */
test_rx_group(void)482 static void test_rx_group(void)
483 {
484 uint8_t status;
485 int err;
486
487 bt_mesh_test_setup();
488
489 err = bt_mesh_cfg_cli_mod_sub_add(0, cfg->addr, cfg->addr, GROUP_ADDR,
490 TEST_MOD_ID, &status);
491 ASSERT_OK_MSG(err || status, "Mod sub add failed (err %d, status %u)", err, status);
492
493 for (int i = 0; i < ARRAY_SIZE(test_vector); i++) {
494 err = bt_mesh_test_recv(test_vector[i].len, GROUP_ADDR,
495 NULL, K_SECONDS(20));
496 ASSERT_OK_MSG(err, "Failed receiving vector %d", i);
497 }
498
499 PASS();
500 }
501
502 /** Test that a node delivers a message to a model subscribed to a fixed group address even if the
503 * corresponding feature is disabled.
504 */
test_rx_fixed(void)505 static void test_rx_fixed(void)
506 {
507 uint8_t status;
508 int err;
509
510 bt_mesh_test_setup();
511
512 /* Step 1.
513 *
514 * The model is on primary element, so it should receive the message if the Relay feature
515 * is enabled.
516 */
517 err = bt_mesh_relay_set(BT_MESH_RELAY_ENABLED,
518 BT_MESH_TRANSMIT(CONFIG_BT_MESH_RELAY_RETRANSMIT_COUNT,
519 CONFIG_BT_MESH_RELAY_RETRANSMIT_INTERVAL));
520 ASSERT_EQUAL(err, -EALREADY);
521
522 ASSERT_OK(bt_mesh_test_recv(test_vector[0].len, BT_MESH_ADDR_RELAYS, NULL, K_SECONDS(4)));
523
524 /* Step 2.
525 *
526 * Disabling the Relay feature, but subscribing the model to the all-relays address. The
527 * model should receive the message.
528 */
529 ASSERT_OK(bt_mesh_relay_set(BT_MESH_RELAY_DISABLED,
530 BT_MESH_TRANSMIT(CONFIG_BT_MESH_RELAY_RETRANSMIT_COUNT,
531 CONFIG_BT_MESH_RELAY_RETRANSMIT_INTERVAL)));
532
533 err = bt_mesh_cfg_cli_mod_sub_add(0, cfg->addr, cfg->addr, BT_MESH_ADDR_RELAYS,
534 TEST_MOD_ID, &status);
535 ASSERT_OK_MSG(err || status, "Mod sub add failed (err %d, status %u)", err, status);
536
537 ASSERT_OK(bt_mesh_test_recv(test_vector[0].len, BT_MESH_ADDR_RELAYS, NULL, K_SECONDS(4)));
538
539 /* Step 3.
540 *
541 * Unsubscribing the model so that it doesn't receive the message.
542 */
543 err = bt_mesh_cfg_cli_mod_sub_del(0, cfg->addr, cfg->addr, BT_MESH_ADDR_RELAYS,
544 TEST_MOD_ID, &status);
545 ASSERT_OK_MSG(err || status, "Mod sub del failed (err %d, status %u)", err, status);
546
547 err = bt_mesh_test_recv(test_vector[0].len, BT_MESH_ADDR_RELAYS, NULL, K_SECONDS(4));
548 ASSERT_EQUAL(err, -ETIMEDOUT);
549
550 PASS();
551 }
552
553 /** @brief Receive virtual address messages using the test vector.
554 */
test_rx_va(void)555 static void test_rx_va(void)
556 {
557 uint16_t virtual_addr;
558 uint8_t status;
559 int err;
560
561 bt_mesh_test_setup();
562
563 err = bt_mesh_cfg_cli_mod_sub_va_add(0, cfg->addr, cfg->addr, test_va_uuid,
564 TEST_MOD_ID, &virtual_addr, &status);
565 ASSERT_OK_MSG(err || status, "Sub add failed (err %d, status %u)", err, status);
566
567 for (int i = 0; i < ARRAY_SIZE(test_vector); i++) {
568 err = bt_mesh_test_recv(test_vector[i].len, virtual_addr,
569 test_va_uuid, K_SECONDS(20));
570 ASSERT_OK_MSG(err, "Failed receiving vector %d", i);
571 }
572
573 PASS();
574 }
575
576 /** @brief Receive the test vector using virtual addresses with collision.
577 */
test_rx_va_collision(void)578 static void test_rx_va_collision(void)
579 {
580 uint16_t virtual_addr;
581 uint8_t status;
582 int err;
583
584 bt_mesh_test_setup();
585
586 for (int i = 0; i < ARRAY_SIZE(test_va_col_uuid); i++) {
587 err = bt_mesh_cfg_cli_mod_sub_va_add(0, cfg->addr, cfg->addr, test_va_col_uuid[i],
588 TEST_MOD_ID, &virtual_addr, &status);
589 ASSERT_OK_MSG(err || status, "Sub add failed (err %d, status %u)", err, status);
590 ASSERT_EQUAL(test_va_col_addr, virtual_addr);
591 }
592
593 for (int i = 0; i < ARRAY_SIZE(test_vector); i++) {
594 for (int j = 0; j < ARRAY_SIZE(test_va_col_uuid); j++) {
595 LOG_INF("Recv msg #%d from %s addr", i, (j == 0 ? "first" : "second"));
596
597 err = bt_mesh_test_recv(test_vector[i].len, test_va_col_addr,
598 test_va_col_uuid[j], K_SECONDS(20));
599 ASSERT_OK_MSG(err, "Failed receiving vector %d", i);
600 }
601 }
602
603 PASS();
604 }
605
606 /** @brief Verify that this device doesn't receive any messages.
607 */
test_rx_none(void)608 static void test_rx_none(void)
609 {
610 struct bt_mesh_test_msg msg;
611 int err;
612
613 bt_mesh_test_setup();
614
615 err = bt_mesh_test_recv_msg(&msg, K_SECONDS(60));
616 if (!err) {
617 FAIL("Unexpected rx from 0x%04x", msg.ctx.addr);
618 }
619
620 PASS();
621 }
622
623 /** @brief Verify that this device doesn't receive any messages.
624 */
test_rx_seg_block(void)625 static void test_rx_seg_block(void)
626 {
627 bt_mesh_test_setup();
628
629 ASSERT_OK_MSG(bt_mesh_test_recv(20, cfg->addr, NULL, K_SECONDS(2)), "RX fail");
630 ASSERT_OK_MSG(bt_mesh_test_recv(20, cfg->addr, NULL, K_SECONDS(2)), "RX fail");
631 ASSERT_OK_MSG(bt_mesh_test_recv(20, cfg->addr, NULL, K_SECONDS(2)), "RX fail");
632
633 PASS();
634 }
635
636 /** @brief Verify that this device doesn't receive any messages.
637 */
test_rx_seg_concurrent(void)638 static void test_rx_seg_concurrent(void)
639 {
640 uint8_t status;
641 int err;
642
643 bt_mesh_test_setup();
644
645 /* Subscribe to group addr */
646 err = bt_mesh_cfg_cli_mod_sub_add(0, cfg->addr, cfg->addr, GROUP_ADDR,
647 TEST_MOD_ID, &status);
648 ASSERT_OK_MSG(err || status, "Mod sub add failed (err %d, status %u)", err, status);
649
650 /* Receive both messages from the sender.
651 * Note: The receive order is technically irrelevant, but the test_recv
652 * function fails if the order is wrong.
653 */
654 ASSERT_OK_MSG(bt_mesh_test_recv(20, cfg->addr, NULL, K_SECONDS(2)), "RX fail");
655 ASSERT_OK_MSG(bt_mesh_test_recv(20, GROUP_ADDR, NULL, K_SECONDS(2)), "RX fail");
656
657 PASS();
658 }
659
660 /** @brief Verify that this device doesn't receive any messages.
661 */
test_rx_seg_ivu(void)662 static void test_rx_seg_ivu(void)
663 {
664 bt_mesh_test_setup();
665 rx_sar_conf();
666
667 ASSERT_OK_MSG(bt_mesh_test_recv(255, cfg->addr, NULL, K_SECONDS(5)), "RX fail");
668 ASSERT_OK_MSG(bt_mesh_test_recv(255, cfg->addr, NULL, K_SECONDS(5)), "RX fail");
669
670 PASS();
671 }
672
673 #define TEST_CASE(role, name, description) \
674 { \
675 .test_id = "transport_" #role "_" #name, \
676 .test_descr = description, \
677 .test_post_init_f = test_##role##_init, \
678 .test_tick_f = bt_mesh_test_timeout, \
679 .test_main_f = test_##role##_##name, \
680 }
681
682 static const struct bst_test_instance test_connect[] = {
683 TEST_CASE(tx, unicast, "Transport: send to unicast addr"),
684 TEST_CASE(tx, group, "Transport: send to group addr"),
685 TEST_CASE(tx, fixed, "Transport: send to fixed group addr"),
686 TEST_CASE(tx, va, "Transport: send to virtual addr"),
687 TEST_CASE(tx, va_collision, "Transport: send to virtual addr"),
688 TEST_CASE(tx, loopback, "Transport: send loopback"),
689 TEST_CASE(tx, loopback_group, "Transport: send loopback and group"),
690 TEST_CASE(tx, unknown_app, "Transport: send with unknown app key"),
691 TEST_CASE(tx, seg_block, "Transport: send blocked segmented"),
692 TEST_CASE(tx, seg_concurrent, "Transport: send concurrent segmented"),
693 TEST_CASE(tx, seg_ivu, "Transport: send segmented during IV update"),
694 TEST_CASE(tx, seg_fail, "Transport: send segmented to unused addr"),
695
696 TEST_CASE(rx, unicast, "Transport: receive on unicast addr"),
697 TEST_CASE(rx, group, "Transport: receive on group addr"),
698 TEST_CASE(rx, fixed, "Transport: receive on fixed group addr"),
699 TEST_CASE(rx, va, "Transport: receive on virtual addr"),
700 TEST_CASE(rx, va_collision, "Transport: receive on virtual addr"),
701 TEST_CASE(rx, none, "Transport: receive no messages"),
702 TEST_CASE(rx, seg_block, "Transport: receive blocked segmented"),
703 TEST_CASE(rx, seg_concurrent, "Transport: receive concurrent segmented"),
704 TEST_CASE(rx, seg_ivu, "Transport: receive segmented during IV update"),
705
706 BSTEST_END_MARKER
707 };
708
test_transport_install(struct bst_test_list * tests)709 struct bst_test_list *test_transport_install(struct bst_test_list *tests)
710 {
711 tests = bst_add_tests(tests, test_connect);
712 return tests;
713 }
714