Skip to content

Commit

Permalink
[nrf fromtree] Bluetooth: Host: Add BT_TESTING trace event for ACL po…
Browse files Browse the repository at this point in the history
…ol destroy

This is needed for a test to catch a double-free.

Signed-off-by: Aleksander Wasaznik <[email protected]>
(cherry picked from commit 5f89a6b)
  • Loading branch information
alwa-nordic authored and jukkar committed Dec 20, 2024
1 parent 6e1590a commit 9f0c4ec
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
27 changes: 27 additions & 0 deletions include/zephyr/bluetooth/testing.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* Copyright (c) 2024 Nordic Semiconductor ASA
* SPDX-License-Identifier: Apache-2.0
*/

/** @brief Internal testing interfaces for Bluetooth
* @file
* @internal
*
* The interfaces in this file are internal and not stable.
*/

#ifndef ZEPHYR_INCLUDE_BLUETOOTH_TESTING_H_
#define ZEPHYR_INCLUDE_BLUETOOTH_TESTING_H_

#include <zephyr/net_buf.h>

/** @brief Hook for `acl_in_pool.destroy`
*
* Weak-function interface. The user can simply define this
* function, and it will automatically become the event
* listener.
*
* @kconfig_dep{CONFIG_BT_TESTING}
*/
void bt_testing_trace_event_acl_pool_destroy(struct net_buf *buf);

#endif /* ZEPHYR_INCLUDE_BLUETOOTH_TESTING_H_ */
12 changes: 12 additions & 0 deletions subsys/bluetooth/host/hci_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <zephyr/net_buf.h>
#include <zephyr/sys/atomic.h>
#include <zephyr/sys/check.h>
#include <zephyr/sys/util_macro.h>
#include <zephyr/sys/util.h>
#include <zephyr/sys/slist.h>
#include <zephyr/sys/byteorder.h>
Expand All @@ -28,6 +29,7 @@
#include <zephyr/bluetooth/l2cap.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/bluetooth/hci_vs.h>
#include <zephyr/bluetooth/testing.h>
#if DT_HAS_CHOSEN(zephyr_bt_hci)
#include <zephyr/drivers/bluetooth.h>
#else
Expand Down Expand Up @@ -263,13 +265,23 @@ void bt_send_one_host_num_completed_packets(uint16_t handle)
BT_ASSERT_MSG(err == 0, "Unable to send Host NCP (err %d)", err);
}

#if defined(CONFIG_BT_TESTING)
__weak void bt_testing_trace_event_acl_pool_destroy(struct net_buf *buf)
{
}
#endif

#if defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL)
void bt_hci_host_num_completed_packets(struct net_buf *buf)
{
uint16_t handle = acl(buf)->handle;
struct bt_conn *conn;
uint8_t index = acl(buf)->index;

if (IS_ENABLED(CONFIG_BT_TESTING)) {
bt_testing_trace_event_acl_pool_destroy(buf);
}

net_buf_destroy(buf);

if (acl(buf)->host_ncp_sent) {
Expand Down

0 comments on commit 9f0c4ec

Please sign in to comment.