Skip to content

Commit 23f94b9

Browse files
committed
tests: Bluetooth: Controller: Fix bad string formats
A handful of Bluetooth controller tests were using %d for non-int values. Some of the values were either uint64_t or long unsigned ints. In most cases, the types could be modified to uint8_t and the formats changed to use %u. In some macros, the types were just cast, as the values would never be larger than uint8_t. The values in this case were defined as e.g. BIT(0), BIT(1) and BIT(2) (which use the UL type in the macro). Signed-off-by: Emil Gydesen <[email protected]>
1 parent 5d0ec8c commit 23f94b9

File tree

4 files changed

+77
-79
lines changed

4 files changed

+77
-79
lines changed

tests/bluetooth/controller/ctrl_collision/src/main.c

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -117,30 +117,29 @@ static void collision_setup(void *data)
117117
ull_dle_update_eff(&conn);
118118
}
119119

120-
#define CHECK_PREF_PHY_STATE(_conn, _tx, _rx) \
121-
do { \
122-
zassert_equal(_conn.phy_pref_rx, _rx, \
123-
"Preferred RX PHY mismatch %d (actual) != %d (expected)", \
124-
_conn.phy_pref_rx, _rx); \
125-
zassert_equal(_conn.phy_pref_tx, _tx, \
126-
"Preferred TX PHY mismatch %d (actual) != %d (expected)", \
127-
_conn.phy_pref_tx, _tx); \
120+
#define CHECK_PREF_PHY_STATE(_conn, _tx, _rx) \
121+
do { \
122+
zassert_equal(_conn.phy_pref_rx, _rx, \
123+
"Preferred RX PHY mismatch %u (actual) != %u (expected)", \
124+
_conn.phy_pref_rx, ((unsigned int)(_rx))); \
125+
zassert_equal(_conn.phy_pref_tx, _tx, \
126+
"Preferred TX PHY mismatch %u (actual) != %u (expected)", \
127+
_conn.phy_pref_tx, ((unsigned int)(_tx))); \
128128
} while (0)
129129

130-
#define CHECK_CURRENT_PHY_STATE(_conn, _tx, _flags, _rx) \
131-
do { \
132-
zassert_equal(_conn.lll.phy_rx, _rx, \
133-
"Current RX PHY mismatch %d (actual) != %d (expected)", \
134-
_conn.lll.phy_rx, _rx); \
135-
zassert_equal(_conn.lll.phy_tx, _tx, \
136-
"Current TX PHY mismatch %d (actual) != %d (expected)", \
137-
_conn.lll.phy_tx, _tx); \
138-
zassert_equal(_conn.lll.phy_rx, _rx, \
139-
"Current Flags mismatch %d (actual) != %d (expected)", \
140-
_conn.lll.phy_flags, _flags); \
130+
#define CHECK_CURRENT_PHY_STATE(_conn, _tx, _flags, _rx) \
131+
do { \
132+
zassert_equal(_conn.lll.phy_rx, _rx, \
133+
"Current RX PHY mismatch %u (actual) != %u (expected)", \
134+
_conn.lll.phy_rx, ((unsigned int)(_rx))); \
135+
zassert_equal(_conn.lll.phy_tx, _tx, \
136+
"Current TX PHY mismatch %u (actual) != %u (expected)", \
137+
_conn.lll.phy_tx, ((unsigned int)(_tx))); \
138+
zassert_equal(_conn.lll.phy_rx, _rx, \
139+
"Current Flags mismatch %u (actual) != %u (expected)", \
140+
_conn.lll.phy_flags, ((unsigned int)(_flags))); \
141141
} while (0)
142142

143-
144143
static bool is_instant_reached(struct ll_conn *llconn, uint16_t instant)
145144
{
146145
return ((event_counter(llconn) - instant) & 0xFFFF) <= 0x7FFF;

tests/bluetooth/controller/ctrl_feature_exchange/src/main_hci.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static void hci_setup(void *data)
8383
*/
8484
ZTEST(hci_fex, test_hci_feat_exchange_central_loc)
8585
{
86-
uint64_t err;
86+
uint8_t err;
8787
uint64_t set_featureset[] = {
8888
DEFAULT_FEATURE,
8989
DEFAULT_FEATURE };
@@ -114,7 +114,7 @@ ZTEST(hci_fex, test_hci_feat_exchange_central_loc)
114114
/* Initiate a Feature Exchange Procedure via HCI */
115115
err = ll_feature_req_send(conn_handle);
116116

117-
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Error: %d", err);
117+
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Error: %u", err);
118118

119119
event_prepare(conn_from_pool);
120120

tests/bluetooth/controller/ctrl_hci/src/main.c

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static void hci_setup(void *data)
8383
*/
8484
ZTEST(hci_fex, test_hci_feature_exchange)
8585
{
86-
uint64_t err;
86+
uint8_t err;
8787
uint64_t set_feature = DEFAULT_FEATURE;
8888
uint64_t rsp_feature = ((LL_FEAT_BIT_MASK_VALID & FEAT_FILTER_OCTET0) | DEFAULT_FEATURE) &
8989
LL_FEAT_BIT_MASK_VALID;
@@ -107,7 +107,7 @@ ZTEST(hci_fex, test_hci_feature_exchange)
107107

108108
/* Initiate a Feature Exchange Procedure via HCI */
109109
err = ll_feature_req_send(conn_handle);
110-
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Error: %d", err);
110+
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Error: %u", err);
111111

112112
/* basically copied from unit-test for feature exchange */
113113
event_prepare(conn_from_pool);
@@ -128,7 +128,7 @@ ZTEST(hci_fex, test_hci_feature_exchange)
128128
ZTEST(hci_fex, test_hci_feature_exchange_wrong_handle)
129129
{
130130
uint16_t conn_handle;
131-
uint64_t err;
131+
uint8_t err;
132132
int ctx_counter;
133133
struct proc_ctx *ctx;
134134

@@ -151,7 +151,7 @@ ZTEST(hci_fex, test_hci_feature_exchange_wrong_handle)
151151

152152
ZTEST(hci_version, test_hci_version_ind)
153153
{
154-
uint64_t err;
154+
uint8_t err;
155155
uint16_t conn_handle;
156156
struct node_tx *tx;
157157
struct node_rx_pdu *ntf;
@@ -174,7 +174,7 @@ ZTEST(hci_version, test_hci_version_ind)
174174
ull_cp_state_set(conn_from_pool, ULL_CP_CONNECTED);
175175

176176
err = ll_version_ind_send(conn_handle);
177-
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Error: %d", err);
177+
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Error: %u", err);
178178

179179
event_prepare(conn_from_pool);
180180
lt_rx(LL_VERSION_IND, conn_from_pool, &tx, &local_pdu);
@@ -248,7 +248,7 @@ ZTEST(hci_apto, test_hci_apto)
248248
ZTEST(hci_phy, test_hci_phy)
249249
{
250250
uint16_t conn_handle;
251-
uint64_t err;
251+
uint8_t err;
252252

253253
uint8_t phy_tx, phy_rx;
254254

@@ -263,11 +263,11 @@ ZTEST(hci_phy, test_hci_phy)
263263
conn_from_pool->llcp.fex.features_used = 0x00;
264264
conn_from_pool->llcp.fex.valid = 1;
265265
err = ll_phy_req_send(conn_handle, 0x03, 0xFF, 0x03);
266-
zassert_equal(err, BT_HCI_ERR_UNSUPP_REMOTE_FEATURE, "Errorcode %d", err);
266+
zassert_equal(err, BT_HCI_ERR_UNSUPP_REMOTE_FEATURE, "Errorcode %u", err);
267267

268268
conn_from_pool->llcp.fex.features_used = 0xFFFF;
269269
err = ll_phy_req_send(conn_handle, 0x03, 0xFF, 0x03);
270-
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %d", err);
270+
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %u", err);
271271
err = ll_phy_get(conn_handle + 1, &phy_tx, &phy_rx);
272272
zassert_equal(err, BT_HCI_ERR_UNKNOWN_CONN_ID);
273273

@@ -295,7 +295,7 @@ ZTEST(hci_phy, test_hci_phy)
295295
ZTEST(hci_dle, test_hci_dle)
296296
{
297297
uint16_t conn_handle;
298-
uint64_t err;
298+
uint8_t err;
299299

300300
uint16_t tx_octets, tx_time;
301301
uint16_t max_tx_octets, max_tx_time;
@@ -312,10 +312,10 @@ ZTEST(hci_dle, test_hci_dle)
312312

313313
conn_from_pool->llcp.fex.features_used = 0x00;
314314
err = ll_length_req_send(conn_handle, tx_octets, tx_time);
315-
zassert_equal(err, BT_HCI_ERR_UNSUPP_REMOTE_FEATURE, "Errorcode %d", err);
315+
zassert_equal(err, BT_HCI_ERR_UNSUPP_REMOTE_FEATURE, "Errorcode %u", err);
316316
conn_from_pool->llcp.fex.features_used = 0xFFFFFFFF;
317317
err = ll_length_req_send(conn_handle + 1, tx_octets, tx_time);
318-
zassert_equal(err, BT_HCI_ERR_UNKNOWN_CONN_ID, "Errorcode %d", err);
318+
zassert_equal(err, BT_HCI_ERR_UNKNOWN_CONN_ID, "Errorcode %u", err);
319319

320320
ll_length_max_get(&max_tx_octets, &max_tx_time, &max_rx_octets, &max_rx_time);
321321
zassert_equal(max_tx_octets, LL_LENGTH_OCTETS_RX_MAX);
@@ -342,7 +342,7 @@ ZTEST(hci_dle, test_hci_dle)
342342
ZTEST(hci_terminate, test_hci_terminate)
343343
{
344344
uint16_t conn_handle;
345-
uint64_t err;
345+
uint8_t err;
346346

347347
uint8_t reason;
348348

@@ -354,13 +354,12 @@ ZTEST(hci_terminate, test_hci_terminate)
354354

355355
reason = 0x01;
356356
err = ll_terminate_ind_send(conn_handle + 1, reason);
357-
zassert_equal(err, BT_HCI_ERR_CMD_DISALLOWED, "Errorcode %d", err);
357+
zassert_equal(err, BT_HCI_ERR_CMD_DISALLOWED, "Errorcode %u", err);
358358
err = ll_terminate_ind_send(conn_handle, reason);
359-
zassert_equal(err, BT_HCI_ERR_INVALID_PARAM, "Errorcode %d", err);
359+
zassert_equal(err, BT_HCI_ERR_INVALID_PARAM, "Errorcode %u", err);
360360
reason = BT_HCI_ERR_REMOTE_USER_TERM_CONN;
361361
err = ll_terminate_ind_send(conn_handle, reason);
362-
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %d", err);
363-
362+
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %u", err);
364363
}
365364

366365
ZTEST(hci_conn_update, test_hci_conn_update)
@@ -390,38 +389,38 @@ ZTEST(hci_conn_update, test_hci_conn_update)
390389
/* Unknown Connection ID */
391390
err = ll_conn_update(conn_handle + 1, cmd, status, interval_min, interval_max, latency,
392391
timeout, offsets);
393-
zassert_equal(err, BT_HCI_ERR_UNKNOWN_CONN_ID, "Errorcode %d", err);
392+
zassert_equal(err, BT_HCI_ERR_UNKNOWN_CONN_ID, "Errorcode %u", err);
394393

395394
/* Unknown commands */
396395
for (uint8_t i = 0U; i < sizeof(unknown_cmds); i++) {
397396
err = ll_conn_update(conn_handle, unknown_cmds[i], status, interval_min,
398397
interval_max, latency, timeout, offsets);
399-
zassert_equal(err, BT_HCI_ERR_UNKNOWN_CMD, "Errorcode %d", err);
398+
zassert_equal(err, BT_HCI_ERR_UNKNOWN_CMD, "Errorcode %u", err);
400399
}
401400

402401
/* Connection Update or Connection Parameter Req. */
403402
conn_from_pool->llcp.fex.features_used |= BIT64(BT_LE_FEAT_BIT_CONN_PARAM_REQ);
404403
err = ll_conn_update(conn_handle, cmd, status, interval_min, interval_max, latency,
405404
timeout, offsets);
406-
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %d", err);
405+
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %u", err);
407406

408407
conn_from_pool->llcp.fex.features_used &= ~BIT64(BT_LE_FEAT_BIT_CONN_PARAM_REQ);
409408
err = ll_conn_update(conn_handle, cmd, status, interval_min, interval_max, latency,
410409
timeout, offsets);
411-
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %d", err);
410+
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %u", err);
412411

413412
/* Connection Parameter Req. Reply */
414413
cmd = 2U;
415414
conn_from_pool->llcp.fex.features_used |= BIT64(BT_LE_FEAT_BIT_CONN_PARAM_REQ);
416415
err = ll_conn_update(conn_handle, cmd, status, interval_min, interval_max, latency,
417416
timeout, offsets);
418-
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %d", err);
417+
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %u", err);
419418

420419
/* Connection Parameter Req. Neg. Reply */
421420
status = 0x01;
422421
conn_from_pool->llcp.fex.features_used |= BIT64(BT_LE_FEAT_BIT_CONN_PARAM_REQ);
423422
err = ll_conn_update(conn_handle, cmd, status, 0U, 0U, 0U, 0U, NULL);
424-
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %d", err);
423+
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %u", err);
425424
}
426425

427426
/* 'Define' out Central API tests because ull_central.c is mock'ed, so API is not supported */
@@ -431,13 +430,13 @@ ZTEST(hci_channelmap, test_hci_chmap)
431430
{
432431
#ifndef ULL_CENTRAL_MOCKED
433432
uint16_t conn_handle;
434-
uint64_t err;
433+
uint8_t err;
435434
uint8_t chmap[5] = {0};
436435
uint8_t chmap_default[5] = { 0x12, 0x34, 0x56, 0x78, 0x9a };
437436
uint8_t chmap_test[5] = { 0x42, 0x00, 0x42, 0x00, 0x00 };
438437

439438
err = ll_chm_update(chmap);
440-
zassert_equal(err, BT_HCI_ERR_INVALID_PARAM, "Errorcode %d", err);
439+
zassert_equal(err, BT_HCI_ERR_INVALID_PARAM, "Errorcode %u", err);
441440

442441
conn_handle = ll_conn_handle_get(conn_from_pool);
443442
memcpy(conn_from_pool->lll.data_chan_map, chmap_default,
@@ -447,31 +446,31 @@ ZTEST(hci_channelmap, test_hci_chmap)
447446
ull_cp_state_set(conn_from_pool, ULL_CP_CONNECTED);
448447

449448
err = ll_chm_get(conn_handle + 1, chmap);
450-
zassert_equal(err, BT_HCI_ERR_UNKNOWN_CONN_ID, "Errorcode %d", err);
449+
zassert_equal(err, BT_HCI_ERR_UNKNOWN_CONN_ID, "Errorcode %u", err);
451450

452451
err = ll_chm_get(conn_handle, chmap);
453-
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %d", err);
452+
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %u", err);
454453
zassert_mem_equal(chmap, chmap_default, sizeof(chmap), "Channel map invalid");
455454

456455
test_set_role(conn_from_pool, BT_HCI_ROLE_CENTRAL);
457456

458457
err = ll_chm_get(conn_handle, chmap);
459-
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %d", err);
458+
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %u", err);
460459
zassert_mem_equal(chmap, chmap_default, sizeof(chmap), "Channel map invalid");
461460

462461
err = ll_chm_update(chmap_test);
463-
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %d", err);
462+
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %u", err);
464463

465464
err = ll_chm_get(conn_handle, chmap);
466-
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %d", err);
465+
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %u", err);
467466
zassert_mem_equal(chmap, chmap_test, sizeof(chmap), "Channel map invalid");
468467
#endif /* !defined(ULL_CENTRAL_MOCKED) */
469468
}
470469

471470
ZTEST(hci_rssi, test_hci_rssi)
472471
{
473472
uint16_t conn_handle;
474-
uint64_t err;
473+
uint8_t err;
475474

476475
uint8_t rssi;
477476

@@ -484,18 +483,18 @@ ZTEST(hci_rssi, test_hci_rssi)
484483
ull_cp_state_set(conn_from_pool, ULL_CP_CONNECTED);
485484

486485
err = ll_rssi_get(conn_handle + 1, &rssi);
487-
zassert_equal(err, BT_HCI_ERR_UNKNOWN_CONN_ID, "Errorcode %d", err);
486+
zassert_equal(err, BT_HCI_ERR_UNKNOWN_CONN_ID, "Errorcode %u", err);
488487

489488
err = ll_rssi_get(conn_handle, &rssi);
490-
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %d", err);
491-
zassert_equal(rssi, 0xcd, "RSSI %d", err);
489+
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %u", err);
490+
zassert_equal(rssi, 0xcd, "RSSI %d", rssi);
492491
}
493492

494493
ZTEST(hci_encryption, test_hci_enc)
495494
{
496495
#ifndef ULL_CENTRAL_MOCKED
497496
uint16_t conn_handle;
498-
uint64_t err;
497+
uint8_t err;
499498

500499
uint8_t rand_nr;
501500
uint8_t ediv;
@@ -511,15 +510,15 @@ ZTEST(hci_encryption, test_hci_enc)
511510
error_code = 0;
512511

513512
err = ll_enc_req_send(conn_handle + 1, &rand_nr, &ediv, &ltk[0]);
514-
zassert_equal(err, BT_HCI_ERR_UNKNOWN_CONN_ID, "Errorcode %d", err);
513+
zassert_equal(err, BT_HCI_ERR_UNKNOWN_CONN_ID, "Errorcode %u", err);
515514
err = ll_enc_req_send(conn_handle, &rand_nr, &ediv, &ltk[0]);
516-
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %d", err);
515+
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %u", err);
517516

518517
test_set_role(conn_from_pool, BT_HCI_ROLE_PERIPHERAL);
519518
err = ll_start_enc_req_send(conn_handle + 1, error_code, &ltk[0]);
520-
zassert_equal(err, BT_HCI_ERR_UNKNOWN_CONN_ID, "Errorcode %d", err);
519+
zassert_equal(err, BT_HCI_ERR_UNKNOWN_CONN_ID, "Errorcode %u", err);
521520
err = ll_start_enc_req_send(conn_handle, error_code, &ltk[0]);
522-
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %d", err);
521+
zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %u", err);
523522
#endif /* !defined(ULL_CENTRAL_MOCKED) */
524523
}
525524

tests/bluetooth/controller/ctrl_phy_update/src/main.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,27 +79,27 @@ static void phy_setup(void *data)
7979
ull_dle_update_eff(&conn);
8080
}
8181

82-
#define CHECK_PREF_PHY_STATE(_conn, _tx, _rx) \
83-
do { \
84-
zassert_equal(_conn.phy_pref_rx, _rx, \
85-
"Preferred RX PHY mismatch %d (actual) != %d (expected)", \
86-
_conn.phy_pref_rx, _rx); \
87-
zassert_equal(_conn.phy_pref_tx, _tx, \
88-
"Preferred TX PHY mismatch %d (actual) != %d (expected)", \
89-
_conn.phy_pref_tx, _tx); \
82+
#define CHECK_PREF_PHY_STATE(_conn, _tx, _rx) \
83+
do { \
84+
zassert_equal(_conn.phy_pref_rx, _rx, \
85+
"Preferred RX PHY mismatch %u (actual) != %u (expected)", \
86+
_conn.phy_pref_rx, ((unsigned int)(_rx))); \
87+
zassert_equal(_conn.phy_pref_tx, _tx, \
88+
"Preferred TX PHY mismatch %u (actual) != %u (expected)", \
89+
_conn.phy_pref_tx, ((unsigned int)(_tx))); \
9090
} while (0)
9191

92-
#define CHECK_CURRENT_PHY_STATE(_conn, _tx, _flags, _rx) \
93-
do { \
94-
zassert_equal(_conn.lll.phy_rx, _rx, \
95-
"Current RX PHY mismatch %d (actual) != %d (expected)", \
96-
_conn.lll.phy_rx, _rx); \
97-
zassert_equal(_conn.lll.phy_tx, _tx, \
98-
"Current TX PHY mismatch %d (actual) != %d (expected)", \
99-
_conn.lll.phy_tx, _tx); \
100-
zassert_equal(_conn.lll.phy_rx, _rx, \
101-
"Current Flags mismatch %d (actual) != %d (expected)", \
102-
_conn.lll.phy_flags, _flags); \
92+
#define CHECK_CURRENT_PHY_STATE(_conn, _tx, _flags, _rx) \
93+
do { \
94+
zassert_equal(_conn.lll.phy_rx, _rx, \
95+
"Current RX PHY mismatch %u (actual) != %u (expected)", \
96+
_conn.lll.phy_rx, ((unsigned int)(_rx))); \
97+
zassert_equal(_conn.lll.phy_tx, _tx, \
98+
"Current TX PHY mismatch %u (actual) != %u (expected)", \
99+
_conn.lll.phy_tx, ((unsigned int)(_tx))); \
100+
zassert_equal(_conn.lll.phy_rx, _rx, \
101+
"Current Flags mismatch %u (actual) != %u (expected)", \
102+
_conn.lll.phy_flags, ((unsigned int)(_flags))); \
103103
} while (0)
104104

105105
static bool is_instant_reached(struct ll_conn *llconn, uint16_t instant)

0 commit comments

Comments
 (0)