Skip to content

Commit

Permalink
Bluetooth: tests: Convert to new HCI driver API
Browse files Browse the repository at this point in the history
Convert all Bluetooth tests that define dummy HCI driver instances to use
the new HCI driver API. This requires both a custom DTS binding as well
as an app-specific overlay file.

Signed-off-by: Johan Hedberg <[email protected]>
  • Loading branch information
jhedberg committed May 13, 2024
1 parent dc09f71 commit 0ae93c5
Show file tree
Hide file tree
Showing 96 changed files with 491 additions and 74 deletions.
3 changes: 3 additions & 0 deletions tests/bluetooth/addr/boards/native_posix.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
3 changes: 3 additions & 0 deletions tests/bluetooth/addr/boards/native_posix_64.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
3 changes: 3 additions & 0 deletions tests/bluetooth/addr/boards/native_posix_native_64.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
3 changes: 3 additions & 0 deletions tests/bluetooth/addr/boards/native_sim.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
3 changes: 3 additions & 0 deletions tests/bluetooth/addr/boards/native_sim_64.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
1 change: 0 additions & 1 deletion tests/bluetooth/addr/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ CONFIG_ZTEST=y

CONFIG_BT=y
CONFIG_BT_CTLR=n
CONFIG_BT_NO_DRIVER=y
5 changes: 5 additions & 0 deletions tests/bluetooth/addr/test.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/ {
chosen {
/delete-property/ zephyr,bt-hci;
};
};
2 changes: 2 additions & 0 deletions tests/bluetooth/addr/testcase.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
tests:
bluetooth.addr:
extra_args:
- EXTRA_DTC_OVERLAY_FILE="test.overlay"
platform_allow:
- native_posix
- native_posix/native/64
Expand Down
3 changes: 3 additions & 0 deletions tests/bluetooth/bluetooth/boards/native_posix.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
3 changes: 3 additions & 0 deletions tests/bluetooth/bluetooth/boards/native_posix_64.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
3 changes: 3 additions & 0 deletions tests/bluetooth/bluetooth/boards/native_sim.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
3 changes: 3 additions & 0 deletions tests/bluetooth/bluetooth/boards/native_sim_64.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
11 changes: 11 additions & 0 deletions tests/bluetooth/bluetooth/dts/bindings/zephyr,bt-hci-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
description: Bluetooth HCI for test purposes

compatible: "zephyr,bt-hci-test"

include: bt-hci.yaml

properties:
bt-hci-name:
default: "test"
bt-hci-bus:
default: "BT_HCI_BUS_VIRTUAL"
1 change: 0 additions & 1 deletion tests/bluetooth/bluetooth/prj.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
CONFIG_BT=y
CONFIG_BT_CTLR=n
CONFIG_BT_NO_DRIVER=y
CONFIG_LOG=y
CONFIG_UART_INTERRUPT_DRIVEN=n
CONFIG_ZTEST=y
47 changes: 33 additions & 14 deletions tests/bluetooth/bluetooth/src/bluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,60 @@
#include <zephyr/ztest.h>

#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/drivers/bluetooth/hci_driver.h>
#include <zephyr/drivers/bluetooth.h>

#define DT_DRV_COMPAT zephyr_bt_hci_test

struct driver_data {
};

struct driver_config {
struct bt_hci_info info;
};

#define EXPECTED_ERROR -ENOSYS

static int driver_open(void)
static int driver_open(const struct device *dev, bt_hci_recv_t recv)
{
TC_PRINT("driver: %s\n", __func__);

/* Indicate that there is no real Bluetooth device */
return EXPECTED_ERROR;
}

static int driver_send(struct net_buf *buf)
static int driver_send(const struct device *dev, struct net_buf *buf)
{
return 0;
}

static const struct bt_hci_driver drv = {
.name = "test",
.bus = BT_HCI_DRIVER_BUS_VIRTUAL,
.open = driver_open,
.send = driver_send,
};

static void driver_init(void)
static void driver_get_info(const struct device *dev, struct bt_hci_info *info)
{
bt_hci_driver_register(&drv);
const struct driver_config *config = dev->config;

*info = config->info;
}

static const struct bt_hci_driver_api driver_api = {
.get_info = driver_get_info,
.open = driver_open,
.send = driver_send,
};

#define TEST_DEVICE_INIT(inst) \
static const struct driver_config driver_config_##inst = { \
.info = BT_DT_HCI_INFO_INST_GET(inst), \
}; \
static struct driver_data driver_data_##inst = { \
}; \
DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &driver_data_##inst, &driver_config_##inst, \
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &driver_api)

DT_INST_FOREACH_STATUS_OKAY(TEST_DEVICE_INIT)

ZTEST_SUITE(test_bluetooth, NULL, NULL, NULL, NULL, NULL);

ZTEST(test_bluetooth, test_bluetooth_entry)
{
driver_init();

zassert_true((bt_enable(NULL) == EXPECTED_ERROR),
"bt_enable failed");
}
14 changes: 14 additions & 0 deletions tests/bluetooth/bluetooth/test.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/ {
chosen {
zephyr,bt-hci = &bt_hci_test;
};

bt_hci_test: bt_hci_test {
compatible = "zephyr,bt-hci-test";
status = "okay";
};
};

&bt_hci_userchan {
status = "disabled";
};
2 changes: 2 additions & 0 deletions tests/bluetooth/bluetooth/testcase.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
tests:
bluetooth.general:
extra_args:
- EXTRA_DTC_OVERLAY_FILE="test.overlay"
platform_allow:
- qemu_x86
- qemu_cortex_m3
Expand Down
3 changes: 3 additions & 0 deletions tests/bluetooth/bt_crypto/boards/native_posix.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
3 changes: 3 additions & 0 deletions tests/bluetooth/bt_crypto/boards/native_posix_64.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
3 changes: 3 additions & 0 deletions tests/bluetooth/bt_crypto/boards/native_sim.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
3 changes: 3 additions & 0 deletions tests/bluetooth/bt_crypto/boards/native_sim_64.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
1 change: 0 additions & 1 deletion tests/bluetooth/bt_crypto/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ CONFIG_ZTEST=y

CONFIG_BT=y
CONFIG_BT_CTLR=n
CONFIG_BT_NO_DRIVER=y
5 changes: 5 additions & 0 deletions tests/bluetooth/bt_crypto/test.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/ {
chosen {
/delete-property/ zephyr,bt-hci;
};
};
2 changes: 2 additions & 0 deletions tests/bluetooth/bt_crypto/testcase.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
tests:
bluetooth.bt_crypto:
extra_args:
- EXTRA_DTC_OVERLAY_FILE="test.overlay"
platform_allow:
- native_posix
- native_posix/native/64
Expand Down
3 changes: 3 additions & 0 deletions tests/bluetooth/bt_crypto_ccm/boards/native_posix.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
3 changes: 3 additions & 0 deletions tests/bluetooth/bt_crypto_ccm/boards/native_posix_64.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
3 changes: 3 additions & 0 deletions tests/bluetooth/bt_crypto_ccm/boards/native_sim.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
3 changes: 3 additions & 0 deletions tests/bluetooth/bt_crypto_ccm/boards/native_sim_64.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
1 change: 0 additions & 1 deletion tests/bluetooth/bt_crypto_ccm/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ CONFIG_ZTEST=y

CONFIG_BT=y
CONFIG_BT_CTLR=n
CONFIG_BT_NO_DRIVER=y

CONFIG_LOG=y
5 changes: 5 additions & 0 deletions tests/bluetooth/bt_crypto_ccm/test.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/ {
chosen {
/delete-property/ zephyr,bt-hci;
};
};
2 changes: 2 additions & 0 deletions tests/bluetooth/bt_crypto_ccm/testcase.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
tests:
bluetooth.bt_crypto_ccm:
extra_args:
- EXTRA_DTC_OVERLAY_FILE="test.overlay"
platform_allow:
- native_posix
- native_posix/native/64
Expand Down
3 changes: 3 additions & 0 deletions tests/bluetooth/gatt/boards/native_posix.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
3 changes: 3 additions & 0 deletions tests/bluetooth/gatt/boards/native_posix_64.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
3 changes: 3 additions & 0 deletions tests/bluetooth/gatt/boards/native_posix_native_64.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
3 changes: 3 additions & 0 deletions tests/bluetooth/gatt/boards/native_sim.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
3 changes: 3 additions & 0 deletions tests/bluetooth/gatt/boards/native_sim_64.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
1 change: 0 additions & 1 deletion tests/bluetooth/gatt/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ CONFIG_ZTEST=y

CONFIG_BT=y
CONFIG_BT_CTLR=n
CONFIG_BT_NO_DRIVER=y

CONFIG_LOG=y
CONFIG_BT_PERIPHERAL=y
Expand Down
5 changes: 5 additions & 0 deletions tests/bluetooth/gatt/test.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/ {
chosen {
/delete-property/ zephyr,bt-hci;
};
};
2 changes: 2 additions & 0 deletions tests/bluetooth/gatt/testcase.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
tests:
bluetooth.gatt:
extra_args:
- EXTRA_DTC_OVERLAY_FILE="test.overlay"
platform_allow:
- native_posix
- native_posix/native/64
Expand Down
3 changes: 3 additions & 0 deletions tests/bluetooth/hci_prop_evt/boards/native_posix.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
3 changes: 3 additions & 0 deletions tests/bluetooth/hci_prop_evt/boards/native_posix_64.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
3 changes: 3 additions & 0 deletions tests/bluetooth/hci_prop_evt/boards/native_sim.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
3 changes: 3 additions & 0 deletions tests/bluetooth/hci_prop_evt/boards/native_sim_64.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&bt_hci_userchan {
status = "disabled";
};
13 changes: 13 additions & 0 deletions tests/bluetooth/hci_prop_evt/dts/bindings/zephyr,bt-hci-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
description: Bluetooth HCI for test purposes

compatible: "zephyr,bt-hci-test"

include: bt-hci.yaml

properties:
bt-hci-name:
default: "test"
bt-hci-bus:
default: "BT_HCI_BUS_VIRTUAL"
bt-hci-quirks:
default: ["BT_HCI_QUIRK_NO_RESET"]
1 change: 0 additions & 1 deletion tests/bluetooth/hci_prop_evt/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ CONFIG_ZTEST=y

CONFIG_BT=y
CONFIG_BT_CTLR=n
CONFIG_BT_NO_DRIVER=y

CONFIG_BT_HCI_VS_EVT_USER=y

Expand Down
Loading

0 comments on commit 0ae93c5

Please sign in to comment.