Bluetooth: Host: Remove bt_buf_get_cmd_complete

After the previous commit, this function no longer has any users.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
This commit is contained in:
Aleksander Wasaznik 2024-01-24 17:15:20 +01:00 committed by Carles Cufí
commit b6a10516b0
8 changed files with 0 additions and 239 deletions

View file

@ -129,17 +129,6 @@ struct net_buf *bt_buf_get_rx(enum bt_buf_type type, k_timeout_t timeout);
struct net_buf *bt_buf_get_tx(enum bt_buf_type type, k_timeout_t timeout, struct net_buf *bt_buf_get_tx(enum bt_buf_type type, k_timeout_t timeout,
const void *data, size_t size); const void *data, size_t size);
/** Allocate a buffer for an HCI Command Complete/Status Event
*
* This will set the buffer type so bt_buf_set_type() does not need to
* be explicitly called before bt_recv_prio().
*
* @param timeout Non-negative waiting period to obtain a buffer or one of the
* special values K_NO_WAIT and K_FOREVER.
* @return A new buffer.
*/
struct net_buf *bt_buf_get_cmd_complete(k_timeout_t timeout);
/** Allocate a buffer for an HCI Event /** Allocate a buffer for an HCI Event
* *
* This will set the buffer type so bt_buf_set_type() does not need to * This will set the buffer type so bt_buf_set_type() does not need to

View file

@ -86,22 +86,6 @@ struct net_buf *bt_buf_get_rx(enum bt_buf_type type, k_timeout_t timeout)
return buf; return buf;
} }
struct net_buf *bt_buf_get_cmd_complete(k_timeout_t timeout)
{
struct net_buf *buf;
buf = (struct net_buf *)atomic_ptr_clear((atomic_ptr_t *)&bt_dev.sent_cmd);
if (buf) {
bt_buf_set_type(buf, BT_BUF_EVT);
buf->len = 0U;
net_buf_reserve(buf, BT_BUF_RESERVE);
return buf;
}
return bt_buf_get_rx(BT_BUF_EVT, timeout);
}
struct net_buf *bt_buf_get_evt(uint8_t evt, bool discardable, struct net_buf *bt_buf_get_evt(uint8_t evt, bool discardable,
k_timeout_t timeout) k_timeout_t timeout)
{ {

View file

@ -177,11 +177,6 @@ struct net_buf *bt_buf_get_tx(enum bt_buf_type type, k_timeout_t timeout,
return buf; return buf;
} }
struct net_buf *bt_buf_get_cmd_complete(k_timeout_t timeout)
{
return bt_buf_get_rx(BT_BUF_EVT, timeout);
}
struct net_buf *bt_buf_get_evt(uint8_t evt, bool discardable, k_timeout_t timeout) struct net_buf *bt_buf_get_evt(uint8_t evt, bool discardable, k_timeout_t timeout)
{ {
return bt_buf_get_rx(BT_BUF_EVT, timeout); return bt_buf_get_rx(BT_BUF_EVT, timeout);

View file

@ -1,16 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.20.0)
project(bluetooth_bt_buf_get_cmd_complete)
find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE})
add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks)
add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/buf mocks)
target_link_libraries(testbinary PRIVATE mocks host_mocks)
target_sources(testbinary
PRIVATE
src/main.c
)

View file

@ -1,5 +0,0 @@
CONFIG_ZTEST=y
CONFIG_BT=y
CONFIG_ASSERT=y
CONFIG_ASSERT_LEVEL=2
CONFIG_ASSERT_VERBOSE=y

View file

@ -1,164 +0,0 @@
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/kernel.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/bluetooth/buf.h>
#include <host/hci_core.h>
#include <zephyr/fff.h>
#include "mocks/net_buf.h"
#include "mocks/net_buf_expects.h"
#include "mocks/buf_help_utils.h"
DEFINE_FFF_GLOBALS;
static void tc_setup(void *f)
{
/* Register resets */
NET_BUF_FFF_FAKES_LIST(RESET_FAKE);
}
ZTEST_SUITE(bt_buf_get_cmd_complete_returns_not_null, NULL, NULL, tc_setup, NULL, NULL);
ZTEST_SUITE(bt_buf_get_cmd_complete_returns_null, NULL, NULL, tc_setup, NULL, NULL);
/*
* Return value from bt_buf_get_cmd_complete() should be NULL
*
* This is to test the behaviour when memory allocation request fails
*
* Constraints:
* - bt_dev.sent_cmd value is NULL
* - Timeout value is a positive non-zero value
* - net_buf_alloc() returns a NULL value
*
* Expected behaviour:
* - net_buf_alloc() to be called with the correct memory allocation pool
* and the same timeout value passed to bt_buf_get_cmd_complete()
* - bt_dev.sent_cmd value is cleared after calling bt_buf_get_cmd_complete()
* - bt_buf_get_cmd_complete() returns NULL
*/
ZTEST(bt_buf_get_cmd_complete_returns_null, test_returns_null_sent_cmd_is_null)
{
struct net_buf *returned_buf;
k_timeout_t timeout = Z_TIMEOUT_TICKS(1000);
bt_dev.sent_cmd = NULL;
struct net_buf_pool *memory_pool;
if ((IS_ENABLED(CONFIG_BT_HCI_ACL_FLOW_CONTROL))) {
memory_pool = bt_buf_get_evt_pool();
} else {
memory_pool = bt_buf_get_hci_rx_pool();
}
net_buf_alloc_fixed_fake.return_val = NULL;
returned_buf = bt_buf_get_cmd_complete(timeout);
expect_single_call_net_buf_alloc(memory_pool, &timeout);
expect_not_called_net_buf_reserve();
expect_not_called_net_buf_ref();
zassert_is_null(returned_buf,
"bt_buf_get_cmd_complete() returned non-NULL value while expecting NULL");
zassert_equal(bt_dev.sent_cmd, NULL,
"bt_buf_get_cmd_complete() didn't clear bt_dev.sent_cmd");
}
/*
* Return value from bt_buf_get_cmd_complete() shouldn't be NULL
*
* Constraints:
* - bt_dev.sent_cmd value is NULL
* - Timeout value is a positive non-zero value
* - net_buf_alloc() return a not NULL value
*
* Expected behaviour:
* - net_buf_alloc() to be called with the correct memory allocation pool
* and the same timeout value passed to bt_buf_get_cmd_complete()
* - bt_dev.sent_cmd value is cleared after calling bt_buf_get_cmd_complete()
* - bt_buf_get_cmd_complete() returns the same value returned by net_buf_alloc_fixed()
* - Return buffer type is set to BT_BUF_EVT
*/
ZTEST(bt_buf_get_cmd_complete_returns_not_null, test_returns_not_null_sent_cmd_is_null)
{
static struct net_buf expected_buf;
struct net_buf *returned_buf;
uint8_t returned_buffer_type;
k_timeout_t timeout = Z_TIMEOUT_TICKS(1000);
bt_dev.sent_cmd = NULL;
struct net_buf_pool *memory_pool;
if ((IS_ENABLED(CONFIG_BT_HCI_ACL_FLOW_CONTROL))) {
memory_pool = bt_buf_get_evt_pool();
} else {
memory_pool = bt_buf_get_hci_rx_pool();
}
net_buf_alloc_fixed_fake.return_val = &expected_buf;
returned_buf = bt_buf_get_cmd_complete(timeout);
expect_single_call_net_buf_alloc(memory_pool, &timeout);
expect_single_call_net_buf_reserve(&expected_buf);
expect_not_called_net_buf_ref();
zassert_equal(returned_buf, &expected_buf,
"bt_buf_get_cmd_complete() returned incorrect buffer pointer value");
returned_buffer_type = bt_buf_get_type(returned_buf);
zassert_equal(returned_buffer_type, BT_BUF_EVT,
"bt_buf_get_cmd_complete() returned incorrect buffer type %u, expected %u (%s)",
returned_buffer_type, BT_BUF_EVT, STRINGIFY(BT_BUF_EVT));
zassert_equal(bt_dev.sent_cmd, NULL,
"bt_buf_get_cmd_complete() didn't clear bt_dev.sent_cmd");
}
/*
* Return value from bt_buf_get_cmd_complete() shouldn't be NULL
*
* Constraints:
* - bt_dev.sent_cmd value isn't NULL
* - Timeout value is a positive non-zero value
*
* Expected behaviour:
* - net_buf_alloc() isn't called
* - bt_dev.sent_cmd value is cleared after calling bt_buf_get_cmd_complete()
* - bt_buf_get_cmd_complete() returns the same value set to bt_dev.sent_cmd
* - Return buffer type is set to BT_BUF_EVT
*/
ZTEST(bt_buf_get_cmd_complete_returns_not_null, test_returns_not_null_sent_cmd_is_not_null)
{
static struct net_buf expected_buf;
struct net_buf *returned_buf;
uint8_t returned_buffer_type;
k_timeout_t timeout = Z_TIMEOUT_TICKS(1000);
bt_dev.sent_cmd = &expected_buf;
net_buf_ref_fake.return_val = &expected_buf;
returned_buf = bt_buf_get_cmd_complete(timeout);
expect_single_call_net_buf_reserve(&expected_buf);
expect_not_called_net_buf_alloc();
zassert_equal(returned_buf, &expected_buf,
"bt_buf_get_cmd_complete() returned incorrect buffer pointer value");
returned_buffer_type = bt_buf_get_type(returned_buf);
zassert_equal(returned_buffer_type, BT_BUF_EVT,
"bt_buf_get_cmd_complete() returned incorrect buffer type %u, expected %u (%s)",
returned_buffer_type, BT_BUF_EVT, STRINGIFY(BT_BUF_EVT));
zassert_equal(bt_dev.sent_cmd, NULL,
"bt_buf_get_cmd_complete() didn't clear bt_dev.sent_cmd");
}

View file

@ -1,21 +0,0 @@
common:
tags:
- bluetooth
- host
tests:
bluetooth.host.bt_buf_get_cmd_complete.default:
type: unit
bluetooth.host.bt_buf_get_cmd_complete.hci_acl_flow_control:
type: unit
extra_configs:
- CONFIG_BT_CENTRAL=y
- CONFIG_BT_HCI_ACL_FLOW_CONTROL=y
bluetooth.host.bt_buf_get_cmd_complete.iso_unicast:
type: unit
# enable CONFIG_BT_ISO_UNICAST
extra_configs:
- CONFIG_BT_ISO_CENTRAL=y
bluetooth.host.bt_buf_get_cmd_complete.iso_sync_receiver:
type: unit
extra_configs:
- CONFIG_BT_ISO_SYNC_RECEIVER=y

View file

@ -12,7 +12,6 @@
* Expected behaviour: * Expected behaviour:
* - net_buf_alloc() to be called once with : * - net_buf_alloc() to be called once with :
* - correct memory allocation pool * - correct memory allocation pool
* - same timeout value passed to bt_buf_get_cmd_complete()
*/ */
void expect_single_call_net_buf_alloc(struct net_buf_pool *pool, k_timeout_t *timeout); void expect_single_call_net_buf_alloc(struct net_buf_pool *pool, k_timeout_t *timeout);