Skip to content

Commit 33b6e9c

Browse files
PavelVPVfabiobaltieri
authored andcommitted
tests: bsim: bluetooth: host: Remove net_buf_unref call after bt_send
If `bt_send` returns 0, the buffer will be unreferenced by an hci driver. If it returns error, the buffer won't be unreferenced. Since it is a test, simply check that `bt_send` always returns 0 otherwise fail the test. Signed-off-by: Pavel Vasilyev <[email protected]>
1 parent 4abc1dd commit 33b6e9c

File tree

6 files changed

+24
-18
lines changed
  • tests/bsim/bluetooth/host

6 files changed

+24
-18
lines changed

tests/bsim/bluetooth/host/att/pipeline/tester/src/main.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ static void recv(struct net_buf *buf)
346346

347347
static void send_cmd(uint16_t opcode, struct net_buf *cmd, struct net_buf **rsp)
348348
{
349+
int err;
350+
349351
LOG_DBG("opcode %x", opcode);
350352

351353
if (!cmd) {
@@ -358,14 +360,13 @@ static void send_cmd(uint16_t opcode, struct net_buf *cmd, struct net_buf **rsp)
358360
active_opcode = opcode;
359361

360362
LOG_HEXDUMP_DBG(cmd->data, cmd->len, "HCI TX");
361-
bt_send(cmd);
363+
err = bt_send(cmd);
364+
__ASSERT(err == 0, "Failed to send HCI command: %d", err);
362365

363366
/* Wait until the command completes */
364367
k_sem_take(&cmd_sem, K_FOREVER);
365368
k_sem_give(&cmd_sem);
366369

367-
net_buf_unref(cmd);
368-
369370
/* return response. it's okay if cmd_rsp gets overwritten, since the app
370371
* gets the ref to the underlying buffer when this fn returns.
371372
*/

tests/bsim/bluetooth/host/att/sequential/tester/src/main.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ static void recv(struct net_buf *buf)
323323

324324
static void send_cmd(uint16_t opcode, struct net_buf *cmd, struct net_buf **rsp)
325325
{
326+
int err;
327+
326328
LOG_DBG("opcode %x", opcode);
327329

328330
if (!cmd) {
@@ -335,14 +337,13 @@ static void send_cmd(uint16_t opcode, struct net_buf *cmd, struct net_buf **rsp)
335337
active_opcode = opcode;
336338

337339
LOG_HEXDUMP_DBG(cmd->data, cmd->len, "HCI TX");
338-
bt_send(cmd);
340+
err = bt_send(cmd);
341+
__ASSERT(err == 0, "Failed to send HCI command: %d", err);
339342

340343
/* Wait until the command completes */
341344
k_sem_take(&cmd_sem, K_FOREVER);
342345
k_sem_give(&cmd_sem);
343346

344-
net_buf_unref(cmd);
345-
346347
/* return response. it's okay if cmd_rsp gets overwritten, since the app
347348
* gets the ref to the underlying buffer when this fn returns.
348349
*/

tests/bsim/bluetooth/host/l2cap/reassembly/peer/src/peer.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ static void recv(struct net_buf *buf)
276276

277277
static void send_cmd(uint16_t opcode, struct net_buf *cmd, struct net_buf **rsp)
278278
{
279+
int err;
280+
279281
LOG_DBG("opcode %x", opcode);
280282

281283
if (!cmd) {
@@ -289,7 +291,8 @@ static void send_cmd(uint16_t opcode, struct net_buf *cmd, struct net_buf **rsp)
289291
active_opcode = opcode;
290292

291293
LOG_HEXDUMP_DBG(cmd->data, cmd->len, "HCI TX");
292-
bt_send(cmd);
294+
err = bt_send(cmd);
295+
__ASSERT(err == 0, "Failed to send cmd: %d", err);
293296

294297
/* Wait until the command completes:
295298
*
@@ -305,8 +308,6 @@ static void send_cmd(uint16_t opcode, struct net_buf *cmd, struct net_buf **rsp)
305308
k_sem_take(&cmd_sem, K_FOREVER);
306309
k_sem_give(&cmd_sem);
307310

308-
net_buf_unref(cmd);
309-
310311
/* return response. it's okay if cmd_rsp gets overwritten, since the app
311312
* gets the ref to the underlying buffer when this fn returns.
312313
*/

tests/bsim/bluetooth/host/l2cap/split/tester/src/main.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ static void recv(struct net_buf *buf)
303303

304304
static void send_cmd(uint16_t opcode, struct net_buf *cmd, struct net_buf **rsp)
305305
{
306+
int err;
307+
306308
LOG_DBG("opcode %x", opcode);
307309

308310
if (!cmd) {
@@ -315,14 +317,13 @@ static void send_cmd(uint16_t opcode, struct net_buf *cmd, struct net_buf **rsp)
315317
active_opcode = opcode;
316318

317319
LOG_HEXDUMP_DBG(cmd->data, cmd->len, "HCI TX");
318-
bt_send(cmd);
320+
err = bt_send(cmd);
321+
__ASSERT(err == 0, "Failed to send HCI command: %d", err);
319322

320323
/* Wait until the command completes */
321324
k_sem_take(&cmd_sem, K_FOREVER);
322325
k_sem_give(&cmd_sem);
323326

324-
net_buf_unref(cmd);
325-
326327
/* return response. it's okay if cmd_rsp gets overwritten, since the app
327328
* gets the ref to the underlying buffer when this fn returns.
328329
*/

tests/bsim/bluetooth/host/misc/disconnect/tester/src/main.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ static void recv(struct net_buf *buf)
300300

301301
static void send_cmd(uint16_t opcode, struct net_buf *cmd, struct net_buf **rsp)
302302
{
303+
int err;
304+
303305
LOG_DBG("opcode %x", opcode);
304306

305307
if (!cmd) {
@@ -312,14 +314,13 @@ static void send_cmd(uint16_t opcode, struct net_buf *cmd, struct net_buf **rsp)
312314
active_opcode = opcode;
313315

314316
LOG_HEXDUMP_DBG(cmd->data, cmd->len, "HCI TX");
315-
bt_send(cmd);
317+
err = bt_send(cmd);
318+
__ASSERT(err == 0, "Failed to send HCI command: %d", err);
316319

317320
/* Wait until the command completes */
318321
k_sem_take(&cmd_sem, K_FOREVER);
319322
k_sem_give(&cmd_sem);
320323

321-
net_buf_unref(cmd);
322-
323324
/* return response. it's okay if cmd_rsp gets overwritten, since the app
324325
* gets the ref to the underlying buffer when this fn returns.
325326
*/

tests/bsim/bluetooth/host/misc/hfc_multilink/tester/src/tester.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ static void recv(struct net_buf *buf)
314314

315315
static void send_cmd(uint16_t opcode, struct net_buf *cmd, struct net_buf **rsp)
316316
{
317+
int err;
318+
317319
LOG_DBG("opcode %x", opcode);
318320

319321
if (!cmd) {
@@ -326,14 +328,13 @@ static void send_cmd(uint16_t opcode, struct net_buf *cmd, struct net_buf **rsp)
326328
active_opcode = opcode;
327329

328330
LOG_HEXDUMP_DBG(cmd->data, cmd->len, "HCI TX");
329-
bt_send(cmd);
331+
err = bt_send(cmd);
332+
__ASSERT(err == 0, "Failed to send cmd: %d", err);
330333

331334
/* Wait until the command completes */
332335
k_sem_take(&cmd_sem, K_FOREVER);
333336
k_sem_give(&cmd_sem);
334337

335-
net_buf_unref(cmd);
336-
337338
/* return response. it's okay if cmd_rsp gets overwritten, since the app
338339
* gets the ref to the underlying buffer when this fn returns.
339340
*/

0 commit comments

Comments
 (0)