diff --git a/tests/bluetooth/addr/prj.conf b/tests/bluetooth/addr/prj.conf index fec5098eecf..1f86a43c208 100644 --- a/tests/bluetooth/addr/prj.conf +++ b/tests/bluetooth/addr/prj.conf @@ -3,4 +3,4 @@ CONFIG_ZTEST=y CONFIG_BT=y CONFIG_BT_CTLR=n -CONFIG_BT_NO_DRIVER=y +CONFIG_BT_H4=n diff --git a/tests/bluetooth/addr/test.overlay b/tests/bluetooth/addr/test.overlay new file mode 100644 index 00000000000..badbe2f392a --- /dev/null +++ b/tests/bluetooth/addr/test.overlay @@ -0,0 +1,5 @@ +/ { + chosen { + /delete-property/ zephyr,bt-hci; + }; +}; diff --git a/tests/bluetooth/addr/testcase.yaml b/tests/bluetooth/addr/testcase.yaml index c4746b2da29..54cfe092aee 100644 --- a/tests/bluetooth/addr/testcase.yaml +++ b/tests/bluetooth/addr/testcase.yaml @@ -1,5 +1,7 @@ tests: bluetooth.addr: + extra_args: + - EXTRA_DTC_OVERLAY_FILE="test.overlay" platform_allow: - native_posix - native_posix/native/64 diff --git a/tests/bluetooth/bluetooth/dts/bindings/zephyr,bt-hci-test.yaml b/tests/bluetooth/bluetooth/dts/bindings/zephyr,bt-hci-test.yaml new file mode 100644 index 00000000000..cd5c0ecd760 --- /dev/null +++ b/tests/bluetooth/bluetooth/dts/bindings/zephyr,bt-hci-test.yaml @@ -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" diff --git a/tests/bluetooth/bluetooth/prj.conf b/tests/bluetooth/bluetooth/prj.conf index ee911c43132..43ee74e49e6 100644 --- a/tests/bluetooth/bluetooth/prj.conf +++ b/tests/bluetooth/bluetooth/prj.conf @@ -1,6 +1,6 @@ CONFIG_BT=y CONFIG_BT_CTLR=n -CONFIG_BT_NO_DRIVER=y +CONFIG_BT_H4=n CONFIG_LOG=y CONFIG_UART_INTERRUPT_DRIVEN=n CONFIG_ZTEST=y diff --git a/tests/bluetooth/bluetooth/src/bluetooth.c b/tests/bluetooth/bluetooth/src/bluetooth.c index 4b02efdcdc9..92889f9b598 100644 --- a/tests/bluetooth/bluetooth/src/bluetooth.c +++ b/tests/bluetooth/bluetooth/src/bluetooth.c @@ -13,11 +13,16 @@ #include #include -#include +#include + +#define DT_DRV_COMPAT zephyr_bt_hci_test + +struct driver_data { +}; #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__); @@ -25,29 +30,28 @@ static int driver_open(void) 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 const struct bt_hci_driver_api driver_api = { + .open = driver_open, + .send = driver_send, }; -static void driver_init(void) -{ - bt_hci_driver_register(&drv); -} +#define TEST_DEVICE_INIT(inst) \ + static struct driver_data driver_data_##inst = { \ + }; \ + DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &driver_data_##inst, NULL, \ + 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"); } diff --git a/tests/bluetooth/bluetooth/test.overlay b/tests/bluetooth/bluetooth/test.overlay new file mode 100644 index 00000000000..c0f0b1c5b29 --- /dev/null +++ b/tests/bluetooth/bluetooth/test.overlay @@ -0,0 +1,10 @@ +/ { + chosen { + zephyr,bt-hci = &bt_hci_test; + }; + + bt_hci_test: bt_hci_test { + compatible = "zephyr,bt-hci-test"; + status = "okay"; + }; +}; diff --git a/tests/bluetooth/bluetooth/testcase.yaml b/tests/bluetooth/bluetooth/testcase.yaml index a7dccced9ea..3c54ea6f7bf 100644 --- a/tests/bluetooth/bluetooth/testcase.yaml +++ b/tests/bluetooth/bluetooth/testcase.yaml @@ -1,5 +1,7 @@ tests: bluetooth.general: + extra_args: + - EXTRA_DTC_OVERLAY_FILE="test.overlay" platform_allow: - qemu_x86 - qemu_cortex_m3 diff --git a/tests/bluetooth/bt_crypto/prj.conf b/tests/bluetooth/bt_crypto/prj.conf index fec5098eecf..1f86a43c208 100644 --- a/tests/bluetooth/bt_crypto/prj.conf +++ b/tests/bluetooth/bt_crypto/prj.conf @@ -3,4 +3,4 @@ CONFIG_ZTEST=y CONFIG_BT=y CONFIG_BT_CTLR=n -CONFIG_BT_NO_DRIVER=y +CONFIG_BT_H4=n diff --git a/tests/bluetooth/bt_crypto/test.overlay b/tests/bluetooth/bt_crypto/test.overlay new file mode 100644 index 00000000000..badbe2f392a --- /dev/null +++ b/tests/bluetooth/bt_crypto/test.overlay @@ -0,0 +1,5 @@ +/ { + chosen { + /delete-property/ zephyr,bt-hci; + }; +}; diff --git a/tests/bluetooth/bt_crypto/testcase.yaml b/tests/bluetooth/bt_crypto/testcase.yaml index e486846175e..430d763d0cb 100644 --- a/tests/bluetooth/bt_crypto/testcase.yaml +++ b/tests/bluetooth/bt_crypto/testcase.yaml @@ -1,5 +1,7 @@ tests: bluetooth.bt_crypto: + extra_args: + - EXTRA_DTC_OVERLAY_FILE="test.overlay" platform_allow: - native_posix - native_posix/native/64 diff --git a/tests/bluetooth/bt_crypto_ccm/prj.conf b/tests/bluetooth/bt_crypto_ccm/prj.conf index 68662d4a0c5..4ab1d5395f7 100644 --- a/tests/bluetooth/bt_crypto_ccm/prj.conf +++ b/tests/bluetooth/bt_crypto_ccm/prj.conf @@ -3,6 +3,6 @@ CONFIG_ZTEST=y CONFIG_BT=y CONFIG_BT_CTLR=n -CONFIG_BT_NO_DRIVER=y +CONFIG_BT_H4=n CONFIG_LOG=y diff --git a/tests/bluetooth/bt_crypto_ccm/test.overlay b/tests/bluetooth/bt_crypto_ccm/test.overlay new file mode 100644 index 00000000000..badbe2f392a --- /dev/null +++ b/tests/bluetooth/bt_crypto_ccm/test.overlay @@ -0,0 +1,5 @@ +/ { + chosen { + /delete-property/ zephyr,bt-hci; + }; +}; diff --git a/tests/bluetooth/bt_crypto_ccm/testcase.yaml b/tests/bluetooth/bt_crypto_ccm/testcase.yaml index 43c35f6a757..77dd0dcbb8e 100644 --- a/tests/bluetooth/bt_crypto_ccm/testcase.yaml +++ b/tests/bluetooth/bt_crypto_ccm/testcase.yaml @@ -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 diff --git a/tests/bluetooth/gatt/prj.conf b/tests/bluetooth/gatt/prj.conf index c59f96a921e..f705142d552 100644 --- a/tests/bluetooth/gatt/prj.conf +++ b/tests/bluetooth/gatt/prj.conf @@ -3,7 +3,7 @@ CONFIG_ZTEST=y CONFIG_BT=y CONFIG_BT_CTLR=n -CONFIG_BT_NO_DRIVER=y +CONFIG_BT_H4=n CONFIG_LOG=y CONFIG_BT_PERIPHERAL=y diff --git a/tests/bluetooth/gatt/test.overlay b/tests/bluetooth/gatt/test.overlay new file mode 100644 index 00000000000..badbe2f392a --- /dev/null +++ b/tests/bluetooth/gatt/test.overlay @@ -0,0 +1,5 @@ +/ { + chosen { + /delete-property/ zephyr,bt-hci; + }; +}; diff --git a/tests/bluetooth/gatt/testcase.yaml b/tests/bluetooth/gatt/testcase.yaml index 5e1fa97a4b9..135f6d823ed 100644 --- a/tests/bluetooth/gatt/testcase.yaml +++ b/tests/bluetooth/gatt/testcase.yaml @@ -1,5 +1,7 @@ tests: bluetooth.gatt: + extra_args: + - EXTRA_DTC_OVERLAY_FILE="test.overlay" platform_allow: - native_posix - native_posix/native/64 diff --git a/tests/bluetooth/hci_prop_evt/dts/bindings/zephyr,bt-hci-test.yaml b/tests/bluetooth/hci_prop_evt/dts/bindings/zephyr,bt-hci-test.yaml new file mode 100644 index 00000000000..7d8adacc908 --- /dev/null +++ b/tests/bluetooth/hci_prop_evt/dts/bindings/zephyr,bt-hci-test.yaml @@ -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"] diff --git a/tests/bluetooth/hci_prop_evt/prj.conf b/tests/bluetooth/hci_prop_evt/prj.conf index 56460e4ab1a..5d87f13964c 100644 --- a/tests/bluetooth/hci_prop_evt/prj.conf +++ b/tests/bluetooth/hci_prop_evt/prj.conf @@ -3,7 +3,7 @@ CONFIG_ZTEST=y CONFIG_BT=y CONFIG_BT_CTLR=n -CONFIG_BT_NO_DRIVER=y +CONFIG_BT_H4=n CONFIG_BT_HCI_VS_EVT_USER=y diff --git a/tests/bluetooth/hci_prop_evt/src/main.c b/tests/bluetooth/hci_prop_evt/src/main.c index cf46a2bad65..ea433b62df4 100644 --- a/tests/bluetooth/hci_prop_evt/src/main.c +++ b/tests/bluetooth/hci_prop_evt/src/main.c @@ -15,9 +15,15 @@ #include #include #include -#include +#include #include +#define DT_DRV_COMPAT zephyr_bt_hci_test + +struct driver_data { + bt_hci_recv_t recv; +}; + /* HCI Proprietary vendor event */ const uint8_t hci_prop_evt_prefix[2] = { 0xAB, 0xBA }; @@ -84,10 +90,12 @@ static int cmd_handle_helper(uint16_t opcode, struct net_buf *cmd, } /* Lookup the command opcode and invoke handler. */ -static int cmd_handle(struct net_buf *cmd, +static int cmd_handle(const struct device *dev, + struct net_buf *cmd, const struct cmd_handler *handlers, size_t num_handlers) { + struct driver_data *drv = dev->data; struct net_buf *evt = NULL; struct bt_hci_evt_cc_status *ccst; struct bt_hci_cmd_hdr *chdr; @@ -105,7 +113,7 @@ static int cmd_handle(struct net_buf *cmd, } if (evt) { - bt_recv(evt); + drv->recv(dev, evt); } return err; @@ -207,15 +215,19 @@ static const struct cmd_handler cmds[] = { }; /* HCI driver open. */ -static int driver_open(void) +static int driver_open(const struct device *dev, bt_hci_recv_t recv) { + struct driver_data *drv = dev->data; + + drv->recv = recv; + return 0; } /* HCI driver send. */ -static int driver_send(struct net_buf *buf) +static int driver_send(const struct device *dev, struct net_buf *buf) { - zassert_true(cmd_handle(buf, cmds, ARRAY_SIZE(cmds)) == 0, + zassert_true(cmd_handle(dev, buf, cmds, ARRAY_SIZE(cmds)) == 0, "Unknown HCI command"); net_buf_unref(buf); @@ -223,15 +235,19 @@ static int driver_send(struct net_buf *buf) return 0; } -/* HCI driver structure. */ -static const struct bt_hci_driver drv = { - .name = "test", - .bus = BT_HCI_DRIVER_BUS_VIRTUAL, - .open = driver_open, - .send = driver_send, - .quirks = BT_QUIRK_NO_RESET, +static const struct bt_hci_driver_api driver_api = { + .open = driver_open, + .send = driver_send, }; +#define TEST_DEVICE_INIT(inst) \ + static struct driver_data driver_data_##inst = { \ + }; \ + DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &driver_data_##inst, NULL, \ + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &driver_api) + +DT_INST_FOREACH_STATUS_OKAY(TEST_DEVICE_INIT) + struct bt_recv_job_data { struct k_work work; /* Work item */ struct k_sem *sync; /* Semaphore to synchronize with */ @@ -243,12 +259,14 @@ struct bt_recv_job_data { /* Work item handler for bt_recv() jobs. */ static void bt_recv_job_cb(struct k_work *item) { + const struct device *dev = DEVICE_DT_GET(DT_DRV_INST(0)); + struct driver_data *drv = dev->data; struct bt_recv_job_data *data = CONTAINER_OF(item, struct bt_recv_job_data, work); struct k_sem *sync = job(data->buf)->sync; /* Send net buffer to host */ - bt_recv(data->buf); + drv->recv(dev, data->buf); data->buf = NULL; /* Wake up bt_recv_job_submit */ @@ -350,9 +368,6 @@ ZTEST_SUITE(test_hci_prop_evt, NULL, NULL, NULL, NULL, NULL); /* Test. */ ZTEST(test_hci_prop_evt, test_hci_prop_evt_entry) { - /* Register the test HCI driver */ - bt_hci_driver_register(&drv); - /* Go! Wait until Bluetooth initialization is done */ zassert_true((bt_enable(NULL) == 0), "bt_enable failed"); diff --git a/tests/bluetooth/hci_prop_evt/test.overlay b/tests/bluetooth/hci_prop_evt/test.overlay new file mode 100644 index 00000000000..c0f0b1c5b29 --- /dev/null +++ b/tests/bluetooth/hci_prop_evt/test.overlay @@ -0,0 +1,10 @@ +/ { + chosen { + zephyr,bt-hci = &bt_hci_test; + }; + + bt_hci_test: bt_hci_test { + compatible = "zephyr,bt-hci-test"; + status = "okay"; + }; +}; diff --git a/tests/bluetooth/hci_prop_evt/testcase.yaml b/tests/bluetooth/hci_prop_evt/testcase.yaml index dde90adf9bc..e1a41372ada 100644 --- a/tests/bluetooth/hci_prop_evt/testcase.yaml +++ b/tests/bluetooth/hci_prop_evt/testcase.yaml @@ -1,5 +1,7 @@ tests: bluetooth.hci_prop_evt: + extra_args: + - EXTRA_DTC_OVERLAY_FILE="test.overlay" platform_allow: - qemu_x86 - qemu_cortex_m3 diff --git a/tests/bluetooth/hci_uart_async/boards/native_posix.conf b/tests/bluetooth/hci_uart_async/boards/native_posix.conf deleted file mode 100644 index d9130d07be5..00000000000 --- a/tests/bluetooth/hci_uart_async/boards/native_posix.conf +++ /dev/null @@ -1,3 +0,0 @@ -# Print logs and test results on stdout as this not the -# default when SERIAL=y. -CONFIG_LOG_BACKEND_NATIVE_POSIX=y diff --git a/tests/bluetooth/hci_uart_async/boards/native_sim.conf b/tests/bluetooth/hci_uart_async/boards/native_sim.conf deleted file mode 100644 index d9130d07be5..00000000000 --- a/tests/bluetooth/hci_uart_async/boards/native_sim.conf +++ /dev/null @@ -1,3 +0,0 @@ -# Print logs and test results on stdout as this not the -# default when SERIAL=y. -CONFIG_LOG_BACKEND_NATIVE_POSIX=y diff --git a/tests/bluetooth/hci_uart_async/dts/bindings/zephyr,bt-hci-test.yaml b/tests/bluetooth/hci_uart_async/dts/bindings/zephyr,bt-hci-test.yaml new file mode 100644 index 00000000000..893e6a78cdc --- /dev/null +++ b/tests/bluetooth/hci_uart_async/dts/bindings/zephyr,bt-hci-test.yaml @@ -0,0 +1,11 @@ +description: Bluetooth HCI for test purposes + +compatible: "zephyr,bt-hci-test" + +include: bt-hci.yaml + +properties: + bt-hci-name: + default: "Mock Controller" + bt-hci-bus: + default: "BT_HCI_BUS_VIRTUAL" diff --git a/tests/bluetooth/hci_uart_async/prj.conf b/tests/bluetooth/hci_uart_async/prj.conf index 408e8f611e4..5f558afdebf 100644 --- a/tests/bluetooth/hci_uart_async/prj.conf +++ b/tests/bluetooth/hci_uart_async/prj.conf @@ -1,5 +1,3 @@ -CONFIG_BT_NO_DRIVER=y - CONFIG_RING_BUFFER=y CONFIG_ASSERT=y diff --git a/tests/bluetooth/hci_uart_async/src/test_hci_uart_async.c b/tests/bluetooth/hci_uart_async/src/test_hci_uart_async.c index 08ea8bc1a79..69b35ff7f48 100644 --- a/tests/bluetooth/hci_uart_async/src/test_hci_uart_async.c +++ b/tests/bluetooth/hci_uart_async/src/test_hci_uart_async.c @@ -14,7 +14,7 @@ #include #include -#include +#include #include LOG_MODULE_REGISTER(test, LOG_LEVEL_DBG); @@ -27,22 +27,35 @@ static const struct device *const zephyr_bt_c2h_uart = DEVICE_DT_GET(DT_CHOSEN(z /* The DUT is Sandwiched between the mock serial interface and a mock * controller. {{{ */ +#define DT_DRV_COMPAT zephyr_bt_hci_test + +struct drv_data { + bt_hci_recv_t recv; +}; + static void serial_vnd_data_callback(const struct device *dev, void *user_data); -static int drv_send(struct net_buf *buf); -static int drv_open(void); -static const struct bt_hci_driver drv = { - .name = "Mock Controller", - .bus = BT_HCI_DRIVER_BUS_VIRTUAL, +static int drv_send(const struct device *dev, struct net_buf *buf); +static int drv_open(const struct device *dev, bt_hci_recv_t recv); + +static const struct bt_hci_driver_api drv_api = { .open = drv_open, .send = drv_send, }; -static int sys_init_hci_driver_register(void) + +static int drv_init(const struct device *dev) { serial_vnd_set_callback(zephyr_bt_c2h_uart, serial_vnd_data_callback, NULL); - bt_hci_driver_register(&drv); return 0; } -SYS_INIT(sys_init_hci_driver_register, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); + +#define TEST_DEVICE_INIT(inst) \ + static struct drv_data drv_data_##inst = { \ + }; \ + DEVICE_DT_INST_DEFINE(inst, drv_init, NULL, &drv_data_##inst, NULL, \ + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &drv_api) + +DT_INST_FOREACH_STATUS_OKAY(TEST_DEVICE_INIT) + /* }}} */ /* Start the DUT "main thread". The settings for this thread are selected as @@ -68,9 +81,14 @@ SYS_INIT(sys_init_spawn_hci_uart, POST_KERNEL, 64); /* Mock controller callbacks. {{{ */ -static int drv_open(void) +static int drv_open(const struct device *dev, bt_hci_recv_t recv) { + struct drv_data *drv = dev->data; + LOG_DBG("drv_open"); + + drv->recv = recv; + return 0; } @@ -82,7 +100,7 @@ static int drv_open(void) * should use #bt_recv to send c2h packets to the DUT. */ K_FIFO_DEFINE(drv_send_fifo); /* elem T: net_buf */ -static int drv_send(struct net_buf *buf) +static int drv_send(const struct device *dev, struct net_buf *buf) { LOG_DBG("buf %p type %d len %u", buf, bt_buf_get_type(buf), buf->len); LOG_HEXDUMP_DBG(buf->data, buf->len, "buf"); @@ -206,13 +224,15 @@ ZTEST(hci_uart, test_h2c_cmd_flow_control) /* The controller sends a HCI Command Complete response. */ { + const struct device *dev = DEVICE_DT_GET(DT_DRV_INST(0)); + struct drv_data *drv = dev->data; int err; struct net_buf *buf = bt_buf_get_rx(BT_BUF_EVT, K_NO_WAIT); zassert_not_null(buf); net_buf_add_mem(buf, hci_msg_rx_evt_cmd_complete, sizeof(hci_msg_rx_evt_cmd_complete)); - err = bt_recv(buf); + err = drv->recv(dev, buf); zassert_equal(err, 0, "bt_recv failed"); } } diff --git a/tests/bluetooth/hci_uart_async/test.overlay b/tests/bluetooth/hci_uart_async/test.overlay new file mode 100644 index 00000000000..c0f0b1c5b29 --- /dev/null +++ b/tests/bluetooth/hci_uart_async/test.overlay @@ -0,0 +1,10 @@ +/ { + chosen { + zephyr,bt-hci = &bt_hci_test; + }; + + bt_hci_test: bt_hci_test { + compatible = "zephyr,bt-hci-test"; + status = "okay"; + }; +}; diff --git a/tests/bluetooth/hci_uart_async/testcase.yaml b/tests/bluetooth/hci_uart_async/testcase.yaml index 8df5113b354..b189149d104 100644 --- a/tests/bluetooth/hci_uart_async/testcase.yaml +++ b/tests/bluetooth/hci_uart_async/testcase.yaml @@ -1,5 +1,7 @@ tests: bluetooth.hci_uart_async: + extra_args: + - EXTRA_DTC_OVERLAY_FILE="test.overlay" tags: - bluetooth - uart diff --git a/tests/bluetooth/host_long_adv_recv/dts/bindings/zephyr,bt-hci-test.yaml b/tests/bluetooth/host_long_adv_recv/dts/bindings/zephyr,bt-hci-test.yaml new file mode 100644 index 00000000000..7d8adacc908 --- /dev/null +++ b/tests/bluetooth/host_long_adv_recv/dts/bindings/zephyr,bt-hci-test.yaml @@ -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"] diff --git a/tests/bluetooth/host_long_adv_recv/prj.conf b/tests/bluetooth/host_long_adv_recv/prj.conf index ab58ed5327b..96c30582c50 100644 --- a/tests/bluetooth/host_long_adv_recv/prj.conf +++ b/tests/bluetooth/host_long_adv_recv/prj.conf @@ -3,10 +3,10 @@ CONFIG_ZTEST=y CONFIG_BT=y CONFIG_BT_CTLR=n +CONFIG_BT_H4=n CONFIG_BT_HCI=n CONFIG_BT_HCI_RAW=n CONFIG_BT_OBSERVER=y -CONFIG_BT_NO_DRIVER=y CONFIG_BT_EXT_ADV=y CONFIG_LOG=y diff --git a/tests/bluetooth/host_long_adv_recv/src/main.c b/tests/bluetooth/host_long_adv_recv/src/main.c index ef3862456aa..4fb36499055 100644 --- a/tests/bluetooth/host_long_adv_recv/src/main.c +++ b/tests/bluetooth/host_long_adv_recv/src/main.c @@ -16,9 +16,15 @@ #include #include #include -#include +#include #include +#define DT_DRV_COMPAT zephyr_bt_hci_test + +struct driver_data { + bt_hci_recv_t recv; +}; + #define LOG_LEVEL CONFIG_BT_LOG_LEVEL #include LOG_MODULE_REGISTER(host_test_app); @@ -111,8 +117,10 @@ static int cmd_handle_helper(uint16_t opcode, struct net_buf *cmd, struct net_bu } /* Lookup the command opcode and invoke handler. */ -static int cmd_handle(struct net_buf *cmd, const struct cmd_handler *handlers, size_t num_handlers) +static int cmd_handle(const struct device *dev, struct net_buf *cmd, + const struct cmd_handler *handlers, size_t num_handlers) { + struct driver_data *drv = dev->data; struct net_buf *evt = NULL; struct bt_hci_evt_cc_status *ccst; struct bt_hci_cmd_hdr *chdr; @@ -130,7 +138,7 @@ static int cmd_handle(struct net_buf *cmd, const struct cmd_handler *handlers, s } if (evt) { - bt_recv(evt); + drv->recv(dev, evt); } return err; @@ -215,30 +223,39 @@ static const struct cmd_handler cmds[] = { }; /* HCI driver open. */ -static int driver_open(void) +static int driver_open(const struct device *dev, bt_hci_recv_t recv) { + struct driver_data *drv = dev->data; + + drv->recv = recv; + return 0; } /* HCI driver send. */ -static int driver_send(struct net_buf *buf) +static int driver_send(const struct device *dev, struct net_buf *buf) { - zassert_true(cmd_handle(buf, cmds, ARRAY_SIZE(cmds)) == 0, "Unknown HCI command"); + zassert_true(cmd_handle(dev, buf, cmds, ARRAY_SIZE(cmds)) == 0, "Unknown HCI command"); net_buf_unref(buf); return 0; } -/* HCI driver structure. */ -static const struct bt_hci_driver drv = { - .name = "test", - .bus = BT_HCI_DRIVER_BUS_VIRTUAL, +static const struct bt_hci_driver_api driver_api = { .open = driver_open, .send = driver_send, - .quirks = 0, }; +#define TEST_DEVICE_INIT(inst) \ + static struct driver_data driver_data_##inst = { \ + }; \ + DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &driver_data_##inst, NULL, \ + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &driver_api) + +DT_INST_FOREACH_STATUS_OKAY(TEST_DEVICE_INIT) + + struct bt_recv_job_data { struct k_work work; /* Work item */ struct k_sem *sync; /* Semaphore to synchronize with */ @@ -250,10 +267,12 @@ struct bt_recv_job_data { /* Work item handler for bt_recv() jobs. */ static void bt_recv_job_cb(struct k_work *item) { + const struct device *dev = DEVICE_DT_GET(DT_DRV_INST(0)); + struct driver_data *drv = dev->data; struct bt_recv_job_data *data = CONTAINER_OF(item, struct bt_recv_job_data, work); /* Send net buffer to host */ - bt_recv(data->buf); + drv->recv(dev, data->buf); /* Wake up bt_recv_job_submit */ k_sem_give(job(data->buf)->sync); @@ -357,9 +376,6 @@ ZTEST(long_adv_rx_tests, test_host_long_adv_recv) { struct test_adv_report expected_reports[2]; - /* Register the test HCI driver */ - bt_hci_driver_register(&drv); - /* Go! Wait until Bluetooth initialization is done */ zassert_true((bt_enable(NULL) == 0), "bt_enable failed"); diff --git a/tests/bluetooth/host_long_adv_recv/test.overlay b/tests/bluetooth/host_long_adv_recv/test.overlay new file mode 100644 index 00000000000..c0f0b1c5b29 --- /dev/null +++ b/tests/bluetooth/host_long_adv_recv/test.overlay @@ -0,0 +1,10 @@ +/ { + chosen { + zephyr,bt-hci = &bt_hci_test; + }; + + bt_hci_test: bt_hci_test { + compatible = "zephyr,bt-hci-test"; + status = "okay"; + }; +}; diff --git a/tests/bluetooth/host_long_adv_recv/testcase.yaml b/tests/bluetooth/host_long_adv_recv/testcase.yaml index 7957d03a796..dfe4465a42e 100644 --- a/tests/bluetooth/host_long_adv_recv/testcase.yaml +++ b/tests/bluetooth/host_long_adv_recv/testcase.yaml @@ -1,5 +1,7 @@ tests: bluetooth.host_long_adv_recv: + extra_args: + - EXTRA_DTC_OVERLAY_FILE="test.overlay" platform_allow: - native_posix - native_posix/native/64 diff --git a/tests/bluetooth/l2cap/prj.conf b/tests/bluetooth/l2cap/prj.conf index 69eb3d64ca7..ace0bc553f4 100644 --- a/tests/bluetooth/l2cap/prj.conf +++ b/tests/bluetooth/l2cap/prj.conf @@ -3,7 +3,7 @@ CONFIG_ZTEST=y CONFIG_BT=y CONFIG_BT_CTLR=n -CONFIG_BT_NO_DRIVER=y +CONFIG_BT_H4=n CONFIG_LOG=y CONFIG_BT_PERIPHERAL=y diff --git a/tests/bluetooth/l2cap/test.overlay b/tests/bluetooth/l2cap/test.overlay new file mode 100644 index 00000000000..badbe2f392a --- /dev/null +++ b/tests/bluetooth/l2cap/test.overlay @@ -0,0 +1,5 @@ +/ { + chosen { + /delete-property/ zephyr,bt-hci; + }; +}; diff --git a/tests/bluetooth/l2cap/testcase.yaml b/tests/bluetooth/l2cap/testcase.yaml index 8996672c866..5f19cf2eb73 100644 --- a/tests/bluetooth/l2cap/testcase.yaml +++ b/tests/bluetooth/l2cap/testcase.yaml @@ -1,5 +1,7 @@ tests: bluetooth.l2cap: + extra_args: + - EXTRA_DTC_OVERLAY_FILE="test.overlay" platform_allow: - native_posix - native_posix/native/64 diff --git a/tests/bluetooth/mesh/blob_io_flash/prj.conf b/tests/bluetooth/mesh/blob_io_flash/prj.conf index 7db7efc16cd..36de7f6b0da 100644 --- a/tests/bluetooth/mesh/blob_io_flash/prj.conf +++ b/tests/bluetooth/mesh/blob_io_flash/prj.conf @@ -10,7 +10,6 @@ CONFIG_FLASH_SIMULATOR=y CONFIG_FLASH_SIMULATOR_DOUBLE_WRITES=y CONFIG_BT=y -CONFIG_BT_NO_DRIVER=y CONFIG_BT_OBSERVER=y CONFIG_BT_PERIPHERAL=y CONFIG_BT_MESH=y diff --git a/tests/bluetooth/mesh/blob_io_flash/test.overlay b/tests/bluetooth/mesh/blob_io_flash/test.overlay new file mode 100644 index 00000000000..98f90303b70 --- /dev/null +++ b/tests/bluetooth/mesh/blob_io_flash/test.overlay @@ -0,0 +1,9 @@ +/ { + chosen { + /delete-property/ zephyr,bt-hci; + }; +}; + +&bt_hci_userchan { + status = "disabled"; +}; diff --git a/tests/bluetooth/mesh/blob_io_flash/testcase.yaml b/tests/bluetooth/mesh/blob_io_flash/testcase.yaml index c27ea3081af..d5ad661d9ef 100644 --- a/tests/bluetooth/mesh/blob_io_flash/testcase.yaml +++ b/tests/bluetooth/mesh/blob_io_flash/testcase.yaml @@ -1,5 +1,7 @@ tests: bluetooth.mesh.blob_io_flash: + extra_args: + - EXTRA_DTC_OVERLAY_FILE="test.overlay" platform_allow: - native_posix - native_sim diff --git a/tests/bluetooth/uuid/prj.conf b/tests/bluetooth/uuid/prj.conf index fec5098eecf..1f86a43c208 100644 --- a/tests/bluetooth/uuid/prj.conf +++ b/tests/bluetooth/uuid/prj.conf @@ -3,4 +3,4 @@ CONFIG_ZTEST=y CONFIG_BT=y CONFIG_BT_CTLR=n -CONFIG_BT_NO_DRIVER=y +CONFIG_BT_H4=n diff --git a/tests/bluetooth/uuid/test.overlay b/tests/bluetooth/uuid/test.overlay new file mode 100644 index 00000000000..badbe2f392a --- /dev/null +++ b/tests/bluetooth/uuid/test.overlay @@ -0,0 +1,5 @@ +/ { + chosen { + /delete-property/ zephyr,bt-hci; + }; +}; diff --git a/tests/bluetooth/uuid/testcase.yaml b/tests/bluetooth/uuid/testcase.yaml index 20e43e29a27..e3382e875c9 100644 --- a/tests/bluetooth/uuid/testcase.yaml +++ b/tests/bluetooth/uuid/testcase.yaml @@ -1,5 +1,7 @@ tests: bluetooth.uuid: + extra_args: + - EXTRA_DTC_OVERLAY_FILE="test.overlay" platform_allow: - native_posix - native_posix/native/64