-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bluetooth: buf: Add a callback for freed buffer in rx pool #81646
Merged
kartben
merged 3 commits into
zephyrproject-rtos:main
from
PavelVPV:hci_driver_async_buf_get_upstream
Dec 10, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
|
||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(buf) | ||
|
||
target_sources(app PRIVATE src/main.c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CONFIG_TEST=y | ||
CONFIG_ZTEST=y | ||
|
||
CONFIG_BT=y | ||
CONFIG_BT_CTLR=n | ||
CONFIG_BT_H4=n | ||
|
||
# Needed to enable and test the iso rx pool | ||
CONFIG_BT_OBSERVER=y | ||
CONFIG_BT_ISO_SYNC_RECEIVER=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (c) 2024 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/kernel.h> | ||
|
||
#include <errno.h> | ||
#include <zephyr/tc_util.h> | ||
#include <zephyr/ztest.h> | ||
|
||
#include <zephyr/bluetooth/hci.h> | ||
#include <zephyr/bluetooth/buf.h> | ||
#include <zephyr/bluetooth/bluetooth.h> | ||
#include <zephyr/drivers/bluetooth.h> | ||
#include <zephyr/sys/byteorder.h> | ||
|
||
static enum bt_buf_type freed_buf_type; | ||
static K_SEM_DEFINE(rx_sem, 0, 1); | ||
|
||
void bt_buf_rx_freed_cb(enum bt_buf_type type) | ||
{ | ||
freed_buf_type = type; | ||
k_sem_give(&rx_sem); | ||
} | ||
|
||
ZTEST_SUITE(test_buf_data_api, NULL, NULL, NULL, NULL, NULL); | ||
|
||
ZTEST(test_buf_data_api, test_buf_freed_cb) | ||
{ | ||
struct net_buf *buf; | ||
int err; | ||
|
||
bt_buf_rx_freed_cb_set(bt_buf_rx_freed_cb); | ||
|
||
/* Test that the callback is called for the BT_BUF_EVT type */ | ||
buf = bt_buf_get_rx(BT_BUF_EVT, K_NO_WAIT); | ||
zassert_not_null(buf, "Failed to get event buffer"); | ||
|
||
net_buf_unref(buf); | ||
/* The freed buf cb is called from net_buf_unref, therefore the semaphore should | ||
* already by given. | ||
*/ | ||
err = k_sem_take(&rx_sem, K_NO_WAIT); | ||
zassert_equal(err, 0, "Timeout while waiting for event buffer to be freed"); | ||
zassert_equal(BT_BUF_EVT, BT_BUF_EVT & freed_buf_type, "Event buffer wasn't freed"); | ||
|
||
/* Test that the callback is called for the BT_BUF_ACL_IN type */ | ||
buf = bt_buf_get_rx(BT_BUF_ACL_IN, K_NO_WAIT); | ||
zassert_not_null(buf, "Failed to get ACL buffer"); | ||
|
||
net_buf_unref(buf); | ||
/* The freed buf cb is called from net_buf_unref, therefore the semaphore should | ||
* already by given. | ||
*/ | ||
err = k_sem_take(&rx_sem, K_NO_WAIT); | ||
zassert_equal(err, 0, "Timeout while waiting for ACL buffer to be freed"); | ||
zassert_equal(BT_BUF_ACL_IN, BT_BUF_ACL_IN & freed_buf_type, "ACL buffer wasn't freed"); | ||
|
||
/* Test that the callback is called for the BT_BUF_ISO_IN type */ | ||
buf = bt_buf_get_rx(BT_BUF_ISO_IN, K_NO_WAIT); | ||
zassert_not_null(buf, "Failed to get ISO buffer"); | ||
|
||
net_buf_unref(buf); | ||
/* The freed buf cb is called from net_buf_unref, therefore the semaphore should | ||
* already by given. | ||
*/ | ||
err = k_sem_take(&rx_sem, K_NO_WAIT); | ||
zassert_equal(err, 0, "Timeout while waiting for ISO buffer to be freed"); | ||
zassert_equal(BT_BUF_ISO_IN, BT_BUF_ISO_IN & freed_buf_type, "ISO buffer wasn't freed"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
common: | ||
tags: | ||
- bluetooth | ||
- host | ||
|
||
tests: | ||
bluetooth.buf: | ||
platform_allow: | ||
- native_sim | ||
- native_sim/native/64 | ||
integration_platforms: | ||
- native_sim | ||
extra_configs: | ||
- CONFIG_BT_HCI_ACL_FLOW_CONTROL=y | ||
bluetooth.buf.no_acl_flow_control: | ||
platform_allow: | ||
- native_sim | ||
- native_sim/native/64 | ||
integration_platforms: | ||
- native_sim | ||
extra_configs: | ||
- CONFIG_BT_HCI_ACL_FLOW_CONTROL=n | ||
bluetooth.buf.hci_raw: | ||
platform_allow: | ||
- native_sim | ||
- native_sim/native/64 | ||
integration_platforms: | ||
- native_sim | ||
extra_configs: | ||
- CONFIG_BT_HCI_RAW=y |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add extra_configs here as well to make sure the config is as we expect, no matter what the default is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, though if we check the exact returned value, this may not be needed. I added
CONFIG_BT_HCI_ACL_FLOW_CONTROL=y
any way.