Skip to content

Commit 25897f8

Browse files
aescolarcarlescufi
authored andcommitted
tests bluetooth mesh: Fix ASSERT_TRUE/FALSE with messages
The previous ASSERT_TRUE/FALSE macros looked like they could take extra printf like parameters but did not (those extra arguments were just dropped). Define 2 new macros that can take those extra parameters and fix all uses that intended to print those extra messages. Also add an extra "\n" as the underlaying print functions do not add end of lines on their own. Signed-off-by: Alberto Escolar Piedras <[email protected]>
1 parent 146d025 commit 25897f8

File tree

6 files changed

+54
-35
lines changed

6 files changed

+54
-35
lines changed

tests/bsim/bluetooth/mesh/src/mesh_test.h

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,40 @@
6666
} \
6767
} while (0)
6868

69-
#define ASSERT_TRUE(cond, ...) \
69+
#define ASSERT_TRUE(cond) \
7070
do { \
7171
if (!(cond)) { \
7272
bst_result = Failed; \
7373
bs_trace_error_time_line( \
74-
#cond " is false.", ##__VA_ARGS__); \
74+
#cond " is false.\n"); \
7575
} \
7676
} while (0)
7777

78-
#define ASSERT_FALSE(cond, ...) \
78+
#define ASSERT_TRUE_MSG(cond, fmt, ...) \
79+
do { \
80+
if (!(cond)) { \
81+
bst_result = Failed; \
82+
bs_trace_error_time_line( \
83+
#cond " is false. " fmt, ##__VA_ARGS__); \
84+
} \
85+
} while (0)
86+
87+
88+
#define ASSERT_FALSE(cond) \
89+
do { \
90+
if (cond) { \
91+
bst_result = Failed; \
92+
bs_trace_error_time_line( \
93+
#cond " is true.\n"); \
94+
} \
95+
} while (0)
96+
97+
#define ASSERT_FALSE_MSG(cond, fmt, ...) \
7998
do { \
8099
if (cond) { \
81100
bst_result = Failed; \
82101
bs_trace_error_time_line( \
83-
#cond " is true.", ##__VA_ARGS__); \
102+
#cond " is true. " fmt, ##__VA_ARGS__); \
84103
} \
85104
} while (0)
86105

tests/bsim/bluetooth/mesh/src/test_advertiser.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static void allocate_all_array(struct net_buf **buf, size_t num_buf, uint8_t xmi
8484
*buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV,
8585
xmit, K_NO_WAIT);
8686

87-
ASSERT_FALSE(!*buf, "Out of buffers");
87+
ASSERT_FALSE_MSG(!*buf, "Out of buffers\n");
8888
buf++;
8989
}
9090
}
@@ -96,7 +96,7 @@ static void verify_adv_queue_overflow(void)
9696
/* Verity Queue overflow */
9797
dummy_buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV,
9898
BT_MESH_TRANSMIT(2, 20), K_NO_WAIT);
99-
ASSERT_TRUE(!dummy_buf, "Unexpected extra buffer");
99+
ASSERT_TRUE_MSG(!dummy_buf, "Unexpected extra buffer\n");
100100
}
101101

102102
static bool check_delta_time(uint8_t transmit, uint64_t interval)
@@ -162,7 +162,7 @@ static void realloc_end_cb(int err, void *cb_data)
162162
ASSERT_EQUAL(0, err);
163163
buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV,
164164
BT_MESH_TRANSMIT(2, 20), K_NO_WAIT);
165-
ASSERT_FALSE(!buf, "Out of buffers");
165+
ASSERT_FALSE_MSG(!buf, "Out of buffers\n");
166166

167167
k_sem_give(&observer_sem);
168168
}
@@ -248,13 +248,13 @@ static void rx_gatt_beacons(void)
248248
int err;
249249

250250
err = bt_le_scan_start(&scan_param, gatt_scan_cb);
251-
ASSERT_FALSE(err && err != -EALREADY, "starting scan failed (err %d)", err);
251+
ASSERT_FALSE_MSG(err && err != -EALREADY, "Starting scan failed (err %d)\n", err);
252252

253253
err = k_sem_take(&observer_sem, K_SECONDS(20));
254254
ASSERT_OK(err);
255255

256256
err = bt_le_scan_stop();
257-
ASSERT_FALSE(err && err != -EALREADY, "stopping scan failed (err %d)", err);
257+
ASSERT_FALSE_MSG(err && err != -EALREADY, "Stopping scan failed (err %d)\n", err);
258258
}
259259

260260
static void xmit_scan_cb(const bt_addr_le_t *addr, int8_t rssi, uint8_t adv_type,
@@ -294,13 +294,13 @@ static void rx_xmit_adv(void)
294294
int err;
295295

296296
err = bt_le_scan_start(&scan_param, xmit_scan_cb);
297-
ASSERT_FALSE(err && err != -EALREADY, "starting scan failed (err %d)", err);
297+
ASSERT_FALSE_MSG(err && err != -EALREADY, "Starting scan failed (err %d)\n", err);
298298

299299
err = k_sem_take(&observer_sem, K_SECONDS(20));
300300
ASSERT_OK(err);
301301

302302
err = bt_le_scan_stop();
303-
ASSERT_FALSE(err && err != -EALREADY, "stopping scan failed (err %d)", err);
303+
ASSERT_FALSE_MSG(err && err != -EALREADY, "Stopping scan failed (err %d)\n", err);
304304
}
305305

306306
static void send_order_start_cb(uint16_t duration, int err, void *user_data)
@@ -324,7 +324,7 @@ static void send_order_end_cb(int err, void *user_data)
324324
struct net_buf *buf = (struct net_buf *)user_data;
325325

326326
ASSERT_OK_MSG(err, "Failed adv start cb err (%d)", err);
327-
ASSERT_TRUE(!buf->data, "Data not cleared!");
327+
ASSERT_TRUE_MSG(!buf->data, "Data not cleared!\n");
328328
seq_checker++;
329329
LOG_INF("tx end: seq(%d)", seq_checker);
330330

@@ -368,7 +368,7 @@ static void receive_order(int expect_adv)
368368
int err;
369369

370370
err = bt_le_scan_start(&scan_param, receive_order_scan_cb);
371-
ASSERT_FALSE(err && err != -EALREADY, "starting scan failed (err %d)", err);
371+
ASSERT_FALSE_MSG(err && err != -EALREADY, "Starting scan failed (err %d)\n", err);
372372

373373
previous_checker = 0xff;
374374
for (int i = 0; i < expect_adv; i++) {
@@ -377,7 +377,7 @@ static void receive_order(int expect_adv)
377377
}
378378

379379
err = bt_le_scan_stop();
380-
ASSERT_FALSE(err && err != -EALREADY, "stopping scan failed (err %d)", err);
380+
ASSERT_FALSE_MSG(err && err != -EALREADY, "Stopping scan failed (err %d)\n", err);
381381
}
382382

383383
static void send_adv_buf(struct net_buf *buf, uint8_t curr, uint8_t prev)
@@ -427,7 +427,7 @@ static void test_tx_cb_single(void)
427427

428428
buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV,
429429
BT_MESH_TRANSMIT(2, 20), K_NO_WAIT);
430-
ASSERT_FALSE(!buf, "Out of buffers");
430+
ASSERT_FALSE_MSG(!buf, "Out of buffers\n");
431431

432432
send_cb.start = single_start_cb;
433433
send_cb.end = single_end_cb;
@@ -638,16 +638,16 @@ static void test_tx_random_order(void)
638638
previous_checker = 0xff;
639639
buf[0] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV,
640640
xmit, K_NO_WAIT);
641-
ASSERT_FALSE(!buf[0], "Out of buffers");
641+
ASSERT_FALSE_MSG(!buf[0], "Out of buffers\n");
642642
buf[1] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV,
643643
xmit, K_NO_WAIT);
644-
ASSERT_FALSE(!buf[1], "Out of buffers");
644+
ASSERT_FALSE_MSG(!buf[1], "Out of buffers\n");
645645

646646
send_adv_buf(buf[0], 0, 0xff);
647647

648648
buf[2] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV,
649649
xmit, K_NO_WAIT);
650-
ASSERT_FALSE(!buf[2], "Out of buffers");
650+
ASSERT_FALSE_MSG(!buf[2], "Out of buffers\n");
651651

652652
send_adv_buf(buf[2], 2, 0);
653653

tests/bsim/bluetooth/mesh/src/test_blob.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ static int blob_chunk_wr(const struct bt_mesh_blob_io *io,
7777
const struct bt_mesh_blob_chunk *chunk)
7878
{
7979
partial_block += chunk->size;
80-
ASSERT_TRUE(partial_block <= block->size, "Received block is too large");
80+
ASSERT_TRUE_MSG(partial_block <= block->size, "Received block is too large\n");
8181

8282

8383
if (partial_block == block->size) {
8484
partial_block = 0;
85-
ASSERT_FALSE(atomic_test_and_set_bit(block_bitfield, block->number),
86-
"Received duplicate block");
85+
ASSERT_FALSE_MSG(atomic_test_and_set_bit(block_bitfield, block->number),
86+
"Received duplicate block\n");
8787
}
8888

8989
if (atomic_test_bit(block_bitfield, 0)) {

tests/bsim/bluetooth/mesh/src/test_dfu.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,8 @@ static void test_dist_dfu_slot_create(void)
601601
size_t metadata_len = 4;
602602
int err, i;
603603

604-
ASSERT_TRUE(CONFIG_BT_MESH_DFU_SLOT_CNT >= 3,
605-
"CONFIG_BT_MESH_DFU_SLOT_CNT must be at least 3");
604+
ASSERT_TRUE_MSG(CONFIG_BT_MESH_DFU_SLOT_CNT >= 3,
605+
"CONFIG_BT_MESH_DFU_SLOT_CNT must be at least 3\n");
606606

607607
bt_mesh_test_cfg_set(NULL, WAIT_TIME);
608608
bt_mesh_device_setup(&prov, &dist_comp);
@@ -613,7 +613,7 @@ static void test_dist_dfu_slot_create(void)
613613
metadata[0] = i;
614614
slot[i] = slot_reserve_and_set(size, fwid, fwid_len, metadata, metadata_len);
615615

616-
ASSERT_FALSE(slot[i] == NULL, "Failed to add slot");
616+
ASSERT_FALSE_MSG(slot[i] == NULL, "Failed to add slot\n");
617617

618618
if (i > 0) {
619619
/* All but first slot are committed */
@@ -668,8 +668,8 @@ static void test_dist_dfu_slot_create_recover(void)
668668
size_t metadata_len = 4;
669669
int i, idx;
670670

671-
ASSERT_TRUE(CONFIG_BT_MESH_DFU_SLOT_CNT >= 3,
672-
"CONFIG_BT_MESH_DFU_SLOT_CNT must be at least 3");
671+
ASSERT_TRUE_MSG(CONFIG_BT_MESH_DFU_SLOT_CNT >= 3,
672+
"CONFIG_BT_MESH_DFU_SLOT_CNT must be at least 3\n");
673673

674674
bt_mesh_test_cfg_set(NULL, WAIT_TIME);
675675
bt_mesh_device_setup(&prov, &dist_comp);
@@ -698,8 +698,8 @@ static void check_delete_all(void)
698698
const struct bt_mesh_dfu_slot *slot;
699699
size_t slot_count;
700700

701-
ASSERT_TRUE(CONFIG_BT_MESH_DFU_SLOT_CNT >= 3,
702-
"CONFIG_BT_MESH_DFU_SLOT_CNT must be at least 3");
701+
ASSERT_TRUE_MSG(CONFIG_BT_MESH_DFU_SLOT_CNT >= 3,
702+
"CONFIG_BT_MESH_DFU_SLOT_CNT must be at least 3\n");
703703

704704
slot_count = bt_mesh_dfu_slot_foreach(NULL, NULL);
705705
ASSERT_EQUAL(0, slot_count);
@@ -712,8 +712,8 @@ static void check_delete_all(void)
712712

713713
static void test_dist_dfu_slot_delete_all(void)
714714
{
715-
ASSERT_TRUE(CONFIG_BT_MESH_DFU_SLOT_CNT >= 3,
716-
"CONFIG_BT_MESH_DFU_SLOT_CNT must be at least 3");
715+
ASSERT_TRUE_MSG(CONFIG_BT_MESH_DFU_SLOT_CNT >= 3,
716+
"CONFIG_BT_MESH_DFU_SLOT_CNT must be at least 3\n");
717717

718718
bt_mesh_test_cfg_set(NULL, WAIT_TIME);
719719
bt_mesh_device_setup(&prov, &dist_comp);
@@ -763,8 +763,8 @@ static void test_dist_dfu_slot_idempotency(void)
763763
size_t fwid_len = 4;
764764
struct bt_mesh_dfu_slot *slot;
765765

766-
ASSERT_TRUE(CONFIG_BT_MESH_DFU_SLOT_CNT >= 1,
767-
"CONFIG_BT_MESH_DFU_SLOT_CNT must be at least 1");
766+
ASSERT_TRUE_MSG(CONFIG_BT_MESH_DFU_SLOT_CNT >= 1,
767+
"CONFIG_BT_MESH_DFU_SLOT_CNT must be at least 1\n");
768768

769769
bt_mesh_test_cfg_set(NULL, WAIT_TIME);
770770
bt_mesh_device_setup(&prov, &dist_comp);

tests/bsim/bluetooth/mesh/src/test_provision.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ static void node_configure_and_reset(void)
565565
BT_MESH_MODEL_ID_HEALTH_SRV, &healthpub,
566566
&status));
567567
ASSERT_EQUAL(0, status);
568-
ASSERT_TRUE(healthpub.addr == BT_MESH_ADDR_UNASSIGNED, "Pub not cleared");
568+
ASSERT_TRUE_MSG(healthpub.addr == BT_MESH_ADDR_UNASSIGNED, "Pub not cleared\n");
569569

570570
/* Set pub and sub to check that they are reset */
571571
healthpub.addr = 0xc001;

tests/bsim/bluetooth/mesh/src/test_replay_cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static void test_rx_immediate_replay_attack(void)
178178

179179
k_sleep(K_SECONDS(6 * TEST_DATA_WAITING_TIME));
180180

181-
ASSERT_TRUE(rx_cnt == 3, "Device didn't receive expected data");
181+
ASSERT_TRUE_MSG(rx_cnt == 3, "Device didn't receive expected data\n");
182182

183183
PASS();
184184
}
@@ -235,7 +235,7 @@ static void test_rx_power_replay_attack(void)
235235

236236
k_sleep(K_SECONDS(6 * TEST_DATA_WAITING_TIME));
237237

238-
ASSERT_TRUE(rx_cnt == 3, "Device didn't receive expected data");
238+
ASSERT_TRUE_MSG(rx_cnt == 3, "Device didn't receive expected data\n");
239239

240240
PASS();
241241
}

0 commit comments

Comments
 (0)