diff --git a/samples/bluetooth/central_hr/prj_minimal.conf b/samples/bluetooth/central_hr/prj_minimal.conf index 983b5a934d71c..7c2f183c3ffde 100644 --- a/samples/bluetooth/central_hr/prj_minimal.conf +++ b/samples/bluetooth/central_hr/prj_minimal.conf @@ -47,29 +47,29 @@ CONFIG_ARM_MPU=n # CONFIG_THREAD_ANALYZER_RUN_UNLOCKED=y # CONFIG_THREAD_ANALYZER_USE_PRINTK=y # CONFIG_THREAD_ANALYZER_AUTO_INTERVAL=20 -# CONFIG_CONSOLE=y -# CONFIG_UART_CONSOLE=y -# CONFIG_SERIAL=y -# CONFIG_PRINTK=y +CONFIG_CONSOLE=y +CONFIG_UART_CONSOLE=y +CONFIG_SERIAL=y +CONFIG_PRINTK=y # Example output of thread analyzer -# BT RX : STACK: unused 576 usage 448 / 1024 (43 %); CPU: 0 % -# BT RX pri : STACK: unused 260 usage 188 / 448 (41 %); CPU: 0 % -# BT ECC : STACK: unused 256 usage 888 / 1144 (77 %); CPU: 1 % -# BT TX : STACK: unused 296 usage 344 / 640 (53 %); CPU: 0 % -# thread_analyzer : STACK: unused 128 usage 384 / 512 (75 %); CPU: 1 % -# sysworkq : STACK: unused 856 usage 168 / 1024 (16 %); CPU: 0 % -# logging : STACK: unused 232 usage 536 / 768 (69 %); CPU: 0 % -# idle 00 : STACK: unused 208 usage 48 / 256 (18 %); CPU: 97 % -# main : STACK: unused 576 usage 448 / 1024 (43 %); CPU: 0 % +# BT CTLR RX : STACK: unused 16 usage 288 / 304 (94 %); CPU: 0 % +# BT CTLR RX pri : STACK: unused 24 usage 344 / 368 (93 %); CPU: 0 % +# BT WQ : STACK: unused 48 usage 976 / 1024 (95 %); CPU: 1 % +# thread_analyzer : STACK: unused 464 usage 560 / 1024 (54 %); CPU: 0 % +# BT LW WQ : STACK: unused 24 usage 1080 / 1104 (97 %); CPU: 19 % +# sysworkq : STACK: unused 96 usage 504 / 600 (84 %); CPU: 0 % +# idle : STACK: unused 40 usage 88 / 128 (68 %); CPU: 78 % +# main : STACK: unused 168 usage 432 / 600 (72 %); CPU: 0 % +# ISR0 : STACK: unused 200 usage 600 / 800 (75 %) CONFIG_BT_RX_STACK_SIZE=1024 CONFIG_BT_HCI_TX_STACK_SIZE_WITH_PROMPT=y CONFIG_BT_HCI_TX_STACK_SIZE=640 -CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=1100 +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=600 CONFIG_BT_LONG_WQ_STACK_SIZE=1100 CONFIG_IDLE_STACK_SIZE=128 -CONFIG_MAIN_STACK_SIZE=640 -CONFIG_ISR_STACK_SIZE=1024 +CONFIG_MAIN_STACK_SIZE=600 +CONFIG_ISR_STACK_SIZE=700 # Disable features not needed CONFIG_TIMESLICING=n diff --git a/samples/bluetooth/mesh_demo/boards/bbc_microbit.conf b/samples/bluetooth/mesh_demo/boards/bbc_microbit.conf index 4874ce5676064..6bbfb3875c9f6 100644 --- a/samples/bluetooth/mesh_demo/boards/bbc_microbit.conf +++ b/samples/bluetooth/mesh_demo/boards/bbc_microbit.conf @@ -1,17 +1,20 @@ -CONFIG_ISR_STACK_SIZE=768 +CONFIG_ISR_STACK_SIZE=700 CONFIG_MAIN_STACK_SIZE=512 -CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=1200 +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=256 CONFIG_GPIO=y CONFIG_DISPLAY=y CONFIG_MICROBIT_DISPLAY=y CONFIG_PWM=y -CONFIG_BT_RX_STACK_SIZE=1280 +CONFIG_MBEDTLS_PSA_KEY_SLOT_COUNT=1 +CONFIG_BT_MESH_ADV_STACK_SIZE=200 + +CONFIG_BT_RX_STACK_SIZE=2000 CONFIG_BT_CTLR_DUP_FILTER_LEN=0 CONFIG_BT_PHY_UPDATE=n CONFIG_BT_DATA_LEN_UPDATE=n CONFIG_BT_EXT_ADV=n -CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT=15 +CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT=1 CONFIG_BT_MESH_SEG_BUFS=6 CONFIG_BT_MESH_ADV_BUF_COUNT=3 diff --git a/samples/bluetooth/mesh_demo/src/microbit.c b/samples/bluetooth/mesh_demo/src/microbit.c index 38568d26c5a23..fd42dd20d4a78 100644 --- a/samples/bluetooth/mesh_demo/src/microbit.c +++ b/samples/bluetooth/mesh_demo/src/microbit.c @@ -20,21 +20,14 @@ #define SCROLL_SPEED 300 -#define BUZZER_PWM_CHANNEL 0 -#define BEEP_DURATION K_MSEC(60) - #define SEQ_PER_BIT 976 #define SEQ_PAGE (NRF_FICR->CODEPAGESIZE * (NRF_FICR->CODESIZE - 1)) #define SEQ_MAX (NRF_FICR->CODEPAGESIZE * 8 * SEQ_PER_BIT) static const struct gpio_dt_spec button_a = - GPIO_DT_SPEC_GET(DT_NODELABEL(buttona), gpios); + GPIO_DT_SPEC_GET(DT_ALIAS(sw0), gpios); static const struct gpio_dt_spec button_b = - GPIO_DT_SPEC_GET(DT_NODELABEL(buttonb), gpios); -static const struct device *const nvm = - DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller)); -static const struct device *const pwm = - DEVICE_DT_GET_ANY(nordic_nrf_sw_pwm); + GPIO_DT_SPEC_GET(DT_ALIAS(sw1), gpios); static struct k_work button_work; @@ -64,6 +57,13 @@ static void button_pressed(const struct device *dev, struct gpio_callback *cb, } } +#if defined(CONFIG_PWM) +#define BUZZER_PWM_CHANNEL 0 +#define BEEP_DURATION K_MSEC(60) + +static const struct device *const pwm = + DEVICE_DT_GET_ANY(nordic_nrf_sw_pwm); + static const struct { char note; uint32_t period; @@ -139,6 +139,11 @@ void board_play_tune(const char *str) pwm_set(pwm, BUZZER_PWM_CHANNEL, 0, 0, 0); } } +#else +void board_play_tune(const char *str) +{ +} +#endif /* CONFIG_PWM */ void board_heartbeat(uint8_t hops, uint16_t feat) { @@ -267,13 +272,6 @@ int board_init(uint16_t *addr) { struct mb_display *disp = mb_display_get(); - if (!(device_is_ready(nvm) && device_is_ready(pwm) && - gpio_is_ready_dt(&button_a) && - gpio_is_ready_dt(&button_b))) { - printk("One or more devices are not ready\n"); - return -ENODEV; - } - *addr = NRF_UICR->CUSTOMER[0]; if (!*addr || *addr == 0xffff) { #if defined(NODE_ADDR) diff --git a/samples/bluetooth/peripheral_hr/prj_minimal.conf b/samples/bluetooth/peripheral_hr/prj_minimal.conf index d4d368101fa54..5fc74dcc729f3 100644 --- a/samples/bluetooth/peripheral_hr/prj_minimal.conf +++ b/samples/bluetooth/peripheral_hr/prj_minimal.conf @@ -54,29 +54,28 @@ CONFIG_BUILTIN_STACK_GUARD=n # CONFIG_THREAD_ANALYZER_RUN_UNLOCKED=y # CONFIG_THREAD_ANALYZER_USE_PRINTK=y # CONFIG_THREAD_ANALYZER_AUTO_INTERVAL=20 -# CONFIG_CONSOLE=y -# CONFIG_UART_CONSOLE=y -# CONFIG_SERIAL=y -# CONFIG_PRINTK=y +CONFIG_CONSOLE=y +CONFIG_UART_CONSOLE=y +CONFIG_SERIAL=y +CONFIG_PRINTK=y # Example output of thread analyzer -# BT RX : STACK: unused 576 usage 448 / 1024 (43 %); CPU: 0 % -# BT RX pri : STACK: unused 260 usage 188 / 448 (41 %); CPU: 0 % -# BT ECC : STACK: unused 256 usage 888 / 1144 (77 %); CPU: 1 % -# BT TX : STACK: unused 296 usage 344 / 640 (53 %); CPU: 0 % -# thread_analyzer : STACK: unused 128 usage 384 / 512 (75 %); CPU: 1 % -# sysworkq : STACK: unused 856 usage 168 / 1024 (16 %); CPU: 0 % -# logging : STACK: unused 232 usage 536 / 768 (69 %); CPU: 0 % -# idle 00 : STACK: unused 208 usage 48 / 256 (18 %); CPU: 97 % -# main : STACK: unused 576 usage 448 / 1024 (43 %); CPU: 0 % -CONFIG_BT_RX_STACK_SIZE=1024 +# BT CTLR RX : STACK: unused 32 usage 288 / 320 (90 %); CPU: 0 % +# BT CTLR RX pri : STACK: unused 32 usage 344 / 376 (91 %); CPU: 0 % +# BT WQ : STACK: unused 32 usage 944 / 976 (96 %); CPU: 0 % +# BT LW WQ : STACK: unused 8 usage 1096 / 1104 (99 %); CPU: 8 % +# sysworkq : STACK: unused 40 usage 360 / 400 (90 %); CPU: 0 % +# idle : STACK: unused 40 usage 88 / 128 (68 %); CPU: 90 % +# main : STACK: unused 72 usage 608 / 680 (89 %); CPU: 0 % +# ISR0 : STACK: unused 104 usage 600 / 704 (85 %) +CONFIG_BT_RX_STACK_SIZE=976 CONFIG_BT_HCI_TX_STACK_SIZE_WITH_PROMPT=y CONFIG_BT_HCI_TX_STACK_SIZE=640 -CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=1100 -CONFIG_BT_LONG_WQ_STACK_SIZE=1100 +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=400 CONFIG_IDLE_STACK_SIZE=128 -CONFIG_MAIN_STACK_SIZE=640 -CONFIG_ISR_STACK_SIZE=1024 +CONFIG_MAIN_STACK_SIZE=680 +CONFIG_ISR_STACK_SIZE=700 +CONFIG_BT_LONG_WQ_STACK_SIZE=1120 # Disable features not needed CONFIG_TIMESLICING=n diff --git a/subsys/bluetooth/controller/Kconfig.ll_sw_split b/subsys/bluetooth/controller/Kconfig.ll_sw_split index 950e9bc7e58b6..8ccc1245037ef 100644 --- a/subsys/bluetooth/controller/Kconfig.ll_sw_split +++ b/subsys/bluetooth/controller/Kconfig.ll_sw_split @@ -127,6 +127,7 @@ config BT_CTLR_RX_PRIO_STACK_SIZE # Hidden int depends on !BT_HCI_RAW + default 376 if SOC_SERIES_NRF51X && !BT_EXT_ADV default 448 help Controller's Co-Operative high priority Rx thread stack size. @@ -141,6 +142,7 @@ config BT_CTLR_RX_PRIO_STACK_SIZE config BT_CTLR_RX_STACK_SIZE # Hidden, Controller's Co-Operative Rx thread stack size. int + default 320 if SOC_SERIES_NRF51X && !BT_EXT_ADV default 896 config BT_CTLR_SETTINGS diff --git a/subsys/bluetooth/host/Kconfig b/subsys/bluetooth/host/Kconfig index 72deb4343dc45..5c075bca5f2f4 100644 --- a/subsys/bluetooth/host/Kconfig +++ b/subsys/bluetooth/host/Kconfig @@ -75,7 +75,6 @@ config BT_HCI_TX_PRIO choice BT_RECV_CONTEXT prompt "BT RX Thread Selection" - default BT_RECV_WORKQ_SYS if SOC_SERIES_NRF51X default BT_RECV_WORKQ_BT help Selects in which context incoming low priority HCI packets are processed. @@ -85,7 +84,8 @@ choice BT_RECV_CONTEXT packets are processed. config BT_RECV_WORKQ_SYS - bool "Process low priority HCI packets in the system work queue" + bool "Process low priority HCI packets in the system work queue [DEPRECATED]" + select DEPRECATED help When this option is selected, the host will process incoming low priority HCI packets in the system work queue. @@ -127,6 +127,20 @@ config BT_RX_PRIO int default 8 +config BT_WQ + bool + default y if BT_RECV_WORKQ_BT + +if BT_WQ +config BT_WQ_STACK_SIZE + int + default BT_RX_STACK_SIZE + +config BT_WQ_PRIO + int + default BT_RX_PRIO +endif + config BT_DRIVER_RX_HIGH_PRIO # Hidden option for Co-Operative HCI driver RX thread priority int diff --git a/subsys/bluetooth/host/adv.c b/subsys/bluetooth/host/adv.c index 749495bcb5633..608aaafcc420e 100644 --- a/subsys/bluetooth/host/adv.c +++ b/subsys/bluetooth/host/adv.c @@ -1318,8 +1318,8 @@ int bt_le_adv_start(const struct bt_le_adv_param *param, if (ad_is_limited(ad, ad_len)) { k_work_init_delayable(&adv->lim_adv_timeout_work, adv_timeout); - k_work_reschedule(&adv->lim_adv_timeout_work, - K_SECONDS(CONFIG_BT_LIM_ADV_TIMEOUT)); + bt_work_reschedule(&adv->lim_adv_timeout_work, + K_SECONDS(CONFIG_BT_LIM_ADV_TIMEOUT)); } return err; diff --git a/subsys/bluetooth/host/att.c b/subsys/bluetooth/host/att.c index 66833d1cfcc53..2696ea128c253 100644 --- a/subsys/bluetooth/host/att.c +++ b/subsys/bluetooth/host/att.c @@ -625,7 +625,7 @@ static void chan_rebegin_att_timeout(struct bt_att_tx_meta_data *user_data) * in-flight. */ if (chan->req) { - k_work_reschedule(&chan->timeout_work, BT_ATT_TIMEOUT); + bt_work_reschedule(&chan->timeout_work, BT_ATT_TIMEOUT); } } @@ -3544,8 +3544,8 @@ static int att_schedule_eatt_connect(struct bt_conn *conn, uint8_t chans_to_conn att->eatt.chans_to_connect = chans_to_connect; - return k_work_reschedule(&att->eatt.connection_work, - credit_based_connection_delay(conn)); + return bt_work_reschedule(&att->eatt.connection_work, + credit_based_connection_delay(conn)); } static void handle_potential_collision(struct bt_att *att) diff --git a/subsys/bluetooth/host/classic/avctp.c b/subsys/bluetooth/host/classic/avctp.c index 5f921f4a422e5..3fac9e5ff5727 100644 --- a/subsys/bluetooth/host/classic/avctp.c +++ b/subsys/bluetooth/host/classic/avctp.c @@ -63,7 +63,7 @@ static void avctp_tx_raise(int msec) return; } LOG_DBG("kick TX"); - k_work_schedule(&avctp_tx_work, K_MSEC(msec)); + bt_work_schedule(&avctp_tx_work, K_MSEC(msec)); } static void bt_avctp_clear_tx(struct bt_avctp *session) diff --git a/subsys/bluetooth/host/classic/avdtp.c b/subsys/bluetooth/host/classic/avdtp.c index 3ca4546a54c62..8a5beb27d568c 100644 --- a/subsys/bluetooth/host/classic/avdtp.c +++ b/subsys/bluetooth/host/classic/avdtp.c @@ -288,7 +288,7 @@ static void avdtp_tx_raise(void) { if (!sys_slist_is_empty(&avdtp_tx_list)) { LOG_DBG("kick TX"); - k_work_submit(&avdtp_tx_work); + bt_work_submit(&avdtp_tx_work); } } @@ -1390,7 +1390,7 @@ static int avdtp_send_cmd(struct bt_avdtp *session, struct net_buf *buf, struct /* Initialize and start timeout timer */ k_work_init_delayable(&session->timeout_work, avdtp_timeout); /* Start timeout work */ - k_work_reschedule(&session->timeout_work, AVDTP_TIMEOUT); + bt_work_reschedule(&session->timeout_work, AVDTP_TIMEOUT); return 0; } diff --git a/subsys/bluetooth/host/classic/br.c b/subsys/bluetooth/host/classic/br.c index 23a43a01959b3..ce99acef4483d 100644 --- a/subsys/bluetooth/host/classic/br.c +++ b/subsys/bluetooth/host/classic/br.c @@ -1259,8 +1259,8 @@ int bt_br_set_discoverable(bool enable, bool limited) err = write_scan_enable(BT_BREDR_SCAN_INQUIRY | BT_BREDR_SCAN_PAGE); if (!err && (limited == true)) { atomic_set_bit(bt_dev.flags, BT_DEV_LIMITED_DISCOVERABLE_MODE); - k_work_reschedule(&bt_br_limited_discoverable_timeout, - K_SECONDS(CONFIG_BT_LIMITED_DISCOVERABLE_DURATION)); + bt_work_reschedule(&bt_br_limited_discoverable_timeout, + K_SECONDS(CONFIG_BT_LIMITED_DISCOVERABLE_DURATION)); } return err; } diff --git a/subsys/bluetooth/host/classic/hfp_ag.c b/subsys/bluetooth/host/classic/hfp_ag.c index 7600e64cf714e..7441bcb4bc766 100644 --- a/subsys/bluetooth/host/classic/hfp_ag.c +++ b/subsys/bluetooth/host/classic/hfp_ag.c @@ -429,7 +429,7 @@ static int hfp_ag_send_data(struct bt_hfp_ag *ag, bt_hfp_ag_tx_cb_t cb, void *us hfp_ag_unlock(ag); /* Always active tx work */ - k_work_reschedule(&ag->tx_work, K_NO_WAIT); + bt_work_reschedule(&ag->tx_work, K_NO_WAIT); return 0; @@ -724,20 +724,20 @@ static void bt_hfp_ag_set_call_state(struct bt_hfp_ag_call *call, bt_hfp_call_st free_call(call); break; case BT_HFP_CALL_OUTGOING: - k_work_reschedule(&call->deferred_work, + bt_work_reschedule(&call->deferred_work, K_SECONDS(CONFIG_BT_HFP_AG_OUTGOING_TIMEOUT)); break; case BT_HFP_CALL_INCOMING: - k_work_reschedule(&call->deferred_work, + bt_work_reschedule(&call->deferred_work, K_SECONDS(CONFIG_BT_HFP_AG_INCOMING_TIMEOUT)); break; case BT_HFP_CALL_ALERTING: if (!atomic_test_bit(call->flags, BT_HFP_AG_CALL_INCOMING_3WAY)) { - k_work_reschedule(&call->ringing_work, K_NO_WAIT); + bt_work_reschedule(&call->ringing_work, K_NO_WAIT); } else { k_work_cancel_delayable(&call->ringing_work); } - k_work_reschedule(&call->deferred_work, + bt_work_reschedule(&call->deferred_work, K_SECONDS(CONFIG_BT_HFP_AG_ALERTING_TIMEOUT)); break; case BT_HFP_CALL_ACTIVE: @@ -872,7 +872,7 @@ static void bt_ag_tx_work(struct k_work *work) LOG_WRN("tx ongoing flag is not set"); } /* Due to the work is failed, restart the tx work */ - k_work_reschedule(&ag->tx_work, K_NO_WAIT); + bt_work_reschedule(&ag->tx_work, K_NO_WAIT); } } @@ -1162,7 +1162,7 @@ static int bt_hfp_ag_cind_handler(struct bt_hfp_ag *ag, struct net_buf *buf) } else { err = -EINPROGRESS; atomic_set_bit(ag->flags, BT_HGP_AG_ONGOING_CALLS); - k_work_reschedule(&ag->ongoing_call_work, + bt_work_reschedule(&ag->ongoing_call_work, K_MSEC(CONFIG_BT_HFP_AG_GET_ONGOING_CALL_TIMEOUT)); } } @@ -3595,7 +3595,7 @@ static void hfp_ag_sent(struct bt_rfcomm_dlc *dlc, int err) LOG_DBG("Completed pending tx %p", tx); /* Restart the tx work */ - k_work_reschedule(&ag->tx_work, K_NO_WAIT); + bt_work_reschedule(&ag->tx_work, K_NO_WAIT); tx->err = err; k_fifo_put(&ag_tx_notify, tx); @@ -3739,7 +3739,7 @@ static void bt_ag_ringing_work_cb(struct bt_hfp_ag *ag, void *user_data) return; } - k_work_reschedule(&call->ringing_work, + bt_work_reschedule(&call->ringing_work, K_SECONDS(CONFIG_BT_HFP_AG_RING_NOTIFY_INTERVAL)); err = hfp_ag_send_data(ag, NULL, NULL, "\r\nRING\r\n"); diff --git a/subsys/bluetooth/host/classic/l2cap_br.c b/subsys/bluetooth/host/classic/l2cap_br.c index d0929c8d2b1a8..7b766e105b9c2 100644 --- a/subsys/bluetooth/host/classic/l2cap_br.c +++ b/subsys/bluetooth/host/classic/l2cap_br.c @@ -445,29 +445,29 @@ static void l2cap_br_start_timer(struct bt_l2cap_br_chan *br_chan, enum l2cap_br if (type == BT_L2CAP_BR_TIMER_RET) { if (!atomic_test_and_set_bit(br_chan->flags, L2CAP_FLAG_RET_TIMER)) { k_work_cancel_delayable(&br_chan->monitor_work); - k_work_schedule(&br_chan->ret_work, K_MSEC(br_chan->tx.ret_timeout)); + bt_work_schedule(&br_chan->ret_work, K_MSEC(br_chan->tx.ret_timeout)); LOG_DBG("Start ret timer"); } else { if (!restart) { return; } - k_work_reschedule(&br_chan->ret_work, K_MSEC(br_chan->tx.ret_timeout)); + bt_work_reschedule(&br_chan->ret_work, K_MSEC(br_chan->tx.ret_timeout)); LOG_DBG("Restart ret timer"); } } else { if (atomic_test_and_clear_bit(br_chan->flags, L2CAP_FLAG_RET_TIMER)) { k_work_cancel_delayable(&br_chan->ret_work); - k_work_schedule(&br_chan->monitor_work, - K_MSEC(br_chan->tx.monitor_timeout)); + bt_work_schedule(&br_chan->monitor_work, + K_MSEC(br_chan->tx.monitor_timeout)); LOG_DBG("Start monitor timer"); } else { if (!restart) { return; } - k_work_reschedule(&br_chan->monitor_work, - K_MSEC(br_chan->tx.monitor_timeout)); + bt_work_reschedule(&br_chan->monitor_work, + K_MSEC(br_chan->tx.monitor_timeout)); LOG_DBG("Restart monitor timer"); } } @@ -743,7 +743,7 @@ static void l2cap_br_ret_timeout(struct k_work *work) /* Restart the timer */ if (atomic_test_bit(br_chan->flags, L2CAP_FLAG_RET_TIMER)) { - k_work_schedule(&br_chan->ret_work, K_MSEC(br_chan->tx.ret_timeout)); + bt_work_schedule(&br_chan->ret_work, K_MSEC(br_chan->tx.ret_timeout)); } LOG_DBG("chan %p retransmission timeout", br_chan); @@ -812,7 +812,7 @@ static void l2cap_br_monitor_timeout(struct k_work *work) /* Restart the timer */ if (!atomic_test_bit(br_chan->flags, L2CAP_FLAG_RET_TIMER)) { - k_work_schedule(&br_chan->monitor_work, K_MSEC(br_chan->tx.monitor_timeout)); + bt_work_schedule(&br_chan->monitor_work, K_MSEC(br_chan->tx.monitor_timeout)); } LOG_DBG("chan %p monitor timeout", br_chan); @@ -974,7 +974,7 @@ static void l2cap_br_chan_send_req(struct bt_l2cap_br_chan *chan, * final expiration, when the response is received, or the physical * link is lost. */ - k_work_reschedule(&chan->rtx_work, timeout); + bt_work_reschedule(&chan->rtx_work, timeout); } #if defined(CONFIG_BT_L2CAP_RET_FC) @@ -4913,7 +4913,7 @@ static void l2cap_br_conn_rsp(struct bt_l2cap_br *l2cap, uint8_t ident, struct n break; case BT_L2CAP_BR_PENDING: br_chan->ident = ident; - k_work_reschedule(&br_chan->rtx_work, L2CAP_BR_CONN_TIMEOUT); + bt_work_reschedule(&br_chan->rtx_work, L2CAP_BR_CONN_TIMEOUT); break; default: l2cap_br_chan_cleanup(chan); diff --git a/subsys/bluetooth/host/classic/rfcomm.c b/subsys/bluetooth/host/classic/rfcomm.c index 26ad8d0c46725..aca1dec49b41e 100644 --- a/subsys/bluetooth/host/classic/rfcomm.c +++ b/subsys/bluetooth/host/classic/rfcomm.c @@ -242,7 +242,7 @@ static void rfcomm_dlc_tx_trigger(struct bt_rfcomm_dlc *dlc) LOG_DBG("DLC %p TX trigger", dlc); - err = k_work_submit(&dlc->tx_work); + err = bt_work_submit(&dlc->tx_work); if (err < 0) { LOG_ERR("Failed to submit tx work: %d", err); } @@ -408,7 +408,7 @@ static void rfcomm_session_disconnect(struct bt_rfcomm_session *session) session->state = BT_RFCOMM_STATE_DISCONNECTING; rfcomm_send_disc(session, 0); - k_work_reschedule(&session->rtx_work, RFCOMM_DISC_TIMEOUT); + bt_work_reschedule(&session->rtx_work, RFCOMM_DISC_TIMEOUT); } static struct net_buf *rfcomm_make_uih_msg(struct bt_rfcomm_session *session, @@ -498,7 +498,7 @@ static void rfcomm_dlc_init(struct bt_rfcomm_dlc *dlc, k_work_init_delayable(&dlc->rtx_work, rfcomm_dlc_rtx_timeout); /* Start a conn timer which includes auth as well */ - k_work_schedule(&dlc->rtx_work, RFCOMM_CONN_TIMEOUT); + bt_work_schedule(&dlc->rtx_work, RFCOMM_CONN_TIMEOUT); dlc->_next = session->dlcs; session->dlcs = dlc; @@ -686,7 +686,7 @@ static void rfcomm_dlc_tx_worker(struct k_work *work) if (dlc->state == BT_RFCOMM_STATE_DISCONNECTING) { rfcomm_send_disc(dlc->session, dlc->dlci); - k_work_reschedule(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT); + bt_work_reschedule(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT); } else { rfcomm_dlc_destroy(dlc); } @@ -955,7 +955,7 @@ static int rfcomm_dlc_close(struct bt_rfcomm_dlc *dlc) case BT_RFCOMM_STATE_CONFIG: dlc->state = BT_RFCOMM_STATE_DISCONNECTING; rfcomm_send_disc(dlc->session, dlc->dlci); - k_work_reschedule(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT); + bt_work_reschedule(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT); break; case BT_RFCOMM_STATE_CONNECTED: dlc->state = BT_RFCOMM_STATE_DISCONNECTING; @@ -1375,8 +1375,8 @@ static void rfcomm_handle_disc(struct bt_rfcomm_session *session, uint8_t dlci) if (!session->dlcs) { /* Start a session idle timer */ - k_work_reschedule(&dlc->session->rtx_work, - RFCOMM_IDLE_TIMEOUT); + bt_work_reschedule(&dlc->session->rtx_work, + RFCOMM_IDLE_TIMEOUT); } } else { /* Cancel idle timer */ @@ -1834,7 +1834,7 @@ int bt_rfcomm_dlc_disconnect(struct bt_rfcomm_dlc *dlc) */ dlc->state = BT_RFCOMM_STATE_USER_DISCONNECT; rfcomm_dlc_tx_trigger(dlc); - k_work_reschedule(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT); + bt_work_reschedule(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT); return 0; } diff --git a/subsys/bluetooth/host/conn.c b/subsys/bluetooth/host/conn.c index fb31f879191e0..193fcade09e25 100644 --- a/subsys/bluetooth/host/conn.c +++ b/subsys/bluetooth/host/conn.c @@ -1219,8 +1219,7 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state) } #endif /* CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS */ - k_work_schedule(&conn->deferred_work, - CONN_UPDATE_TIMEOUT); + k_work_schedule(&conn->deferred_work, CONN_UPDATE_TIMEOUT); } #endif /* CONFIG_BT_CONN */ @@ -1832,7 +1831,7 @@ static K_WORK_DEFINE(procedures_on_connect, auto_initiated_procedures); static void schedule_auto_initiated_procedures(struct bt_conn *conn) { LOG_DBG("[%p] Scheduling auto-init procedures", conn); - k_work_submit(&procedures_on_connect); + bt_work_submit(&procedures_on_connect); } void bt_conn_connected(struct bt_conn *conn) diff --git a/subsys/bluetooth/host/gatt.c b/subsys/bluetooth/host/gatt.c index ea1dc73e158a9..f7e68de8164fd 100644 --- a/subsys/bluetooth/host/gatt.c +++ b/subsys/bluetooth/host/gatt.c @@ -1321,7 +1321,7 @@ static int gatt_register(struct bt_gatt_service *svc) static inline void sc_work_submit(k_timeout_t timeout) { #if defined(CONFIG_BT_GATT_SERVICE_CHANGED) - k_work_reschedule(&gatt_sc.work, timeout); + bt_work_reschedule(&gatt_sc.work, timeout); #endif } @@ -1483,8 +1483,8 @@ static void gatt_delayed_store_enqueue(uint8_t id, const bt_addr_le_t *peer_addr atomic_set_bit(el->flags, flag); - k_work_reschedule(&gatt_delayed_store.work, - K_MSEC(CONFIG_BT_SETTINGS_DELAYED_STORE_MS)); + bt_work_reschedule(&gatt_delayed_store.work, + K_MSEC(CONFIG_BT_SETTINGS_DELAYED_STORE_MS)); } } @@ -1565,7 +1565,7 @@ void bt_gatt_init(void) if (IS_ENABLED(CONFIG_BT_LONG_WQ)) { bt_long_wq_schedule(&db_hash.work, DB_HASH_TIMEOUT); } else { - k_work_schedule(&db_hash.work, DB_HASH_TIMEOUT); + bt_work_schedule(&db_hash.work, DB_HASH_TIMEOUT); } #endif /* CONFIG_BT_GATT_CACHING */ @@ -1640,7 +1640,7 @@ static void db_changed(void) if (IS_ENABLED(CONFIG_BT_LONG_WQ)) { bt_long_wq_reschedule(&db_hash.work, DB_HASH_TIMEOUT); } else { - k_work_reschedule(&db_hash.work, DB_HASH_TIMEOUT); + bt_work_reschedule(&db_hash.work, DB_HASH_TIMEOUT); } for (i = 0; i < ARRAY_SIZE(cf_cfg); i++) { @@ -2511,8 +2511,8 @@ static int gatt_notify_mult(struct bt_conn *conn, uint16_t handle, /* Use `k_work_schedule` to keep the original deadline, instead of * re-setting the timeout whenever a new notification is appended. */ - k_work_schedule(&nfy_mult_work, - K_MSEC(CONFIG_BT_GATT_NOTIFY_MULTIPLE_FLUSH_MS)); + bt_work_schedule(&nfy_mult_work, + K_MSEC(CONFIG_BT_GATT_NOTIFY_MULTIPLE_FLUSH_MS)); return 0; } diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 33306596b2ce7..ed7376ae8d35a 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -119,10 +119,29 @@ void bt_tx_irq_raise(void); /* Stacks for the threads */ static void rx_work_handler(struct k_work *work); static K_WORK_DEFINE(rx_work, rx_work_handler); -#if defined(CONFIG_BT_RECV_WORKQ_BT) -static struct k_work_q bt_workq; -static K_KERNEL_STACK_DEFINE(rx_thread_stack, CONFIG_BT_RX_STACK_SIZE); -#endif /* CONFIG_BT_RECV_WORKQ_BT */ + +#if defined(CONFIG_BT_WQ) +static struct k_work_q _bt_wq; +static K_KERNEL_STACK_DEFINE(bt_wq_stack, CONFIG_BT_WQ_STACK_SIZE); +static struct k_work_q * const bt_wq = &_bt_wq; +#else +static struct k_work_q * const bt_wq = &k_sys_work_q; +#endif /* CONFIG_BT_WQ */ + +int bt_work_submit(struct k_work *work) +{ + return k_work_submit_to_queue(bt_wq, work); +} + +int bt_work_schedule(struct k_work_delayable *work, k_timeout_t delay) +{ + return k_work_schedule_for_queue(bt_wq, work, delay); +} + +int bt_work_reschedule(struct k_work_delayable *work, k_timeout_t delay) +{ + return k_work_reschedule_for_queue(bt_wq, work, delay); +} static void init_work(struct k_work *work); @@ -472,10 +491,10 @@ int bt_hci_cmd_send_sync(uint16_t opcode, struct net_buf *buf, /* TODO: disallow sending sync commands from syswq altogether */ - /* Since the commands are now processed in the syswq, we cannot suspend - * and wait. We have to send the command from the current context. + /* We cannot suspend and wait in the context that commands are processed in. + * We have to send the command from the current context. */ - if (k_current_get() == &k_sys_work_q.thread) { + if (k_current_get() == k_work_queue_thread_get(bt_wq)) { /* drain the command queue until we get to send the command of interest. */ struct net_buf *cmd = NULL; @@ -2094,8 +2113,8 @@ static void le_conn_update_complete(struct net_buf *buf) evt->status == BT_HCI_ERR_UNSUPP_LL_PARAM_VAL && conn->le.conn_param_retry_countdown) { conn->le.conn_param_retry_countdown--; - k_work_schedule(&conn->deferred_work, - K_MSEC(CONFIG_BT_CONN_PARAM_RETRY_TIMEOUT)); + bt_work_schedule(&conn->deferred_work, + K_MSEC(CONFIG_BT_CONN_PARAM_RETRY_TIMEOUT)); } else { atomic_clear_bit(conn->flags, BT_CONN_PERIPHERAL_PARAM_AUTO_UPDATE); @@ -4352,11 +4371,7 @@ static void rx_queue_put(struct net_buf *buf) { net_buf_slist_put(&bt_dev.rx_queue, buf); -#if defined(CONFIG_BT_RECV_WORKQ_SYS) - const int err = k_work_submit(&rx_work); -#elif defined(CONFIG_BT_RECV_WORKQ_BT) - const int err = k_work_submit_to_queue(&bt_workq, &rx_work); -#endif /* CONFIG_BT_RECV_WORKQ_SYS */ + const int err = bt_work_submit(&rx_work); if (err < 0) { LOG_ERR("Could not submit rx_work: %d", err); } @@ -4540,12 +4555,7 @@ static void rx_work_handler(struct k_work *work) * we used a while() loop with a k_yield() statement. */ if (!sys_slist_is_empty(&bt_dev.rx_queue)) { - -#if defined(CONFIG_BT_RECV_WORKQ_SYS) - err = k_work_submit(&rx_work); -#elif defined(CONFIG_BT_RECV_WORKQ_BT) - err = k_work_submit_to_queue(&bt_workq, &rx_work); -#endif + err = bt_work_submit(&rx_work); if (err < 0) { LOG_ERR("Could not submit rx_work: %d", err); } @@ -4556,7 +4566,7 @@ static void rx_work_handler(struct k_work *work) k_tid_t bt_testing_tx_tid_get(void) { /* We now TX everything from the syswq */ - return &k_sys_work_q.thread; + return k_work_queue_thread_get(bt_wq); } #if defined(CONFIG_BT_ISO) @@ -4614,13 +4624,11 @@ int bt_enable(bt_ready_cb_t cb) } k_fifo_init(&bt_dev.cmd_tx_queue); -#if defined(CONFIG_BT_RECV_WORKQ_BT) - /* RX thread */ - k_work_queue_init(&bt_workq); - k_work_queue_start(&bt_workq, rx_thread_stack, - CONFIG_BT_RX_STACK_SIZE, - K_PRIO_COOP(CONFIG_BT_RX_PRIO), NULL); - k_thread_name_set(&bt_workq.thread, "BT RX WQ"); +#if defined(CONFIG_BT_WQ) + k_work_queue_init(bt_wq); + k_work_queue_start(bt_wq, bt_wq_stack, CONFIG_BT_WQ_STACK_SIZE, + K_PRIO_COOP(CONFIG_BT_WQ_PRIO), NULL); + k_thread_name_set(k_work_queue_thread_get(bt_wq), "BT WQ"); #endif err = bt_hci_open(bt_dev.hci, bt_hci_recv); @@ -4635,7 +4643,7 @@ int bt_enable(bt_ready_cb_t cb) return bt_init(); } - k_work_submit(&bt_dev.init); + bt_work_submit(&bt_dev.init); return 0; } @@ -4698,9 +4706,9 @@ int bt_disable(void) return err; } -#if defined(CONFIG_BT_RECV_WORKQ_BT) - /* Abort RX thread */ - k_thread_abort(&bt_workq.thread); +#if defined(CONFIG_BT_WQ) + /* Abort Bluetooth thread */ + k_thread_abort(k_work_queue_thread_get(bt_wq)); #endif /* Some functions rely on checking this bitfield */ @@ -5036,5 +5044,5 @@ static K_WORK_DEFINE(tx_work, tx_processor); void bt_tx_irq_raise(void) { LOG_DBG("kick TX"); - k_work_submit(&tx_work); + bt_work_submit(&tx_work); } diff --git a/subsys/bluetooth/host/hci_core.h b/subsys/bluetooth/host/hci_core.h index 315db2d388846..c212105311612 100644 --- a/subsys/bluetooth/host/hci_core.h +++ b/subsys/bluetooth/host/hci_core.h @@ -449,6 +449,10 @@ enum bt_security_err bt_security_err_get(uint8_t hci_err); int bt_hci_recv(const struct device *dev, struct net_buf *buf); +int bt_work_submit(struct k_work *work); +int bt_work_schedule(struct k_work_delayable *work, k_timeout_t delay); +int bt_work_reschedule(struct k_work_delayable *work, k_timeout_t delay); + /* Data type to store state related with command to be updated * when command completes successfully. */ diff --git a/subsys/bluetooth/host/id.c b/subsys/bluetooth/host/id.c index a43aaef78f44f..5820c29c9efd5 100644 --- a/subsys/bluetooth/host/id.c +++ b/subsys/bluetooth/host/id.c @@ -342,7 +342,7 @@ static void le_rpa_timeout_submit(void) le_rpa_timeout_update(); #endif - (void)k_work_schedule(&bt_dev.rpa_update, K_SECONDS(bt_dev.rpa_timeout)); + (void)bt_work_schedule(&bt_dev.rpa_update, K_SECONDS(bt_dev.rpa_timeout)); } /* this function sets new RPA only if current one is no longer valid */ diff --git a/subsys/bluetooth/host/keys.c b/subsys/bluetooth/host/keys.c index 1205494e856f0..b4901723c14a0 100644 --- a/subsys/bluetooth/host/keys.c +++ b/subsys/bluetooth/host/keys.c @@ -448,7 +448,7 @@ static void id_add(struct bt_keys *keys, void *user_data) __ASSERT_NO_MSG(keys != NULL); bt_id_pending_keys_update_set(keys, BT_KEYS_ID_PENDING_ADD); - k_work_submit(&add_id_work); + bt_work_submit(&add_id_work); } static int keys_commit(void) diff --git a/subsys/bluetooth/host/l2cap.c b/subsys/bluetooth/host/l2cap.c index 5772ca662ce81..05a7f376df9e7 100644 --- a/subsys/bluetooth/host/l2cap.c +++ b/subsys/bluetooth/host/l2cap.c @@ -532,7 +532,7 @@ static void l2cap_chan_send_req(struct bt_l2cap_chan *chan, * final expiration, when the response is received, or the physical * link is lost. */ - k_work_reschedule(&(BT_L2CAP_LE_CHAN(chan)->rtx_work), timeout); + bt_work_reschedule(&(BT_L2CAP_LE_CHAN(chan)->rtx_work), timeout); } static int l2cap_le_conn_req(struct bt_l2cap_le_chan *ch) @@ -2813,7 +2813,7 @@ static void l2cap_chan_recv_queue(struct bt_l2cap_le_chan *chan, } k_fifo_put(&chan->rx_queue, buf); - k_work_submit(&chan->rx_work); + bt_work_submit(&chan->rx_work); } #endif /* CONFIG_BT_L2CAP_DYNAMIC_CHANNEL */ diff --git a/subsys/bluetooth/host/settings.c b/subsys/bluetooth/host/settings.c index 84b4f1eb4b6a8..ada0937841e87 100644 --- a/subsys/bluetooth/host/settings.c +++ b/subsys/bluetooth/host/settings.c @@ -447,7 +447,7 @@ K_WORK_DEFINE(store_id_work, do_store_id); int bt_settings_store_id(void) { - k_work_submit(&store_id_work); + bt_work_submit(&store_id_work); return 0; } @@ -473,7 +473,7 @@ K_WORK_DEFINE(store_irk_work, do_store_irk); int bt_settings_store_irk(void) { #if defined(CONFIG_BT_PRIVACY) - k_work_submit(&store_irk_work); + bt_work_submit(&store_irk_work); #endif /* defined(CONFIG_BT_PRIVACY) */ return 0; } diff --git a/subsys/bluetooth/host/smp.c b/subsys/bluetooth/host/smp.c index 702e6fc0d215e..7e7d1c71636cc 100644 --- a/subsys/bluetooth/host/smp.c +++ b/subsys/bluetooth/host/smp.c @@ -1002,7 +1002,7 @@ static void smp_br_send(struct bt_smp_br *smp, struct net_buf *buf, return; } - k_work_reschedule(&smp->work, SMP_TIMEOUT); + bt_work_reschedule(&smp->work, SMP_TIMEOUT); } static void bt_smp_br_connected(struct bt_l2cap_chan *chan) @@ -2054,7 +2054,7 @@ static void smp_send(struct bt_smp *smp, struct net_buf *buf, return; } - k_work_reschedule(&smp->work, SMP_TIMEOUT); + bt_work_reschedule(&smp->work, SMP_TIMEOUT); } static int smp_error(struct bt_smp *smp, uint8_t reason) @@ -4749,7 +4749,7 @@ static uint8_t smp_keypress_notif(struct bt_smp *smp, struct net_buf *buf) } /* Reset SMP timeout, like the spec says. */ - k_work_reschedule(&smp->work, SMP_TIMEOUT); + bt_work_reschedule(&smp->work, SMP_TIMEOUT); if (smp_auth_cb->passkey_display_keypress) { smp_auth_cb->passkey_display_keypress(conn, type); diff --git a/tests/bluetooth/host/CMakeLists.txt b/tests/bluetooth/host/CMakeLists.txt deleted file mode 100644 index 173c6d90566de..0000000000000 --- a/tests/bluetooth/host/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -# -# CMakeLists.txt file for creating of host mocks library. -# - -add_library(host_mocks STATIC - host_mocks/assert.c -) - -target_include_directories(host_mocks PUBLIC - ${ZEPHYR_BASE}/subsys/bluetooth - ${ZEPHYR_BASE}/subsys/bluetooth/host - ${ZEPHYR_BASE}/tests/bluetooth/host -) - -target_link_libraries(host_mocks PRIVATE test_interface) -target_compile_options(test_interface INTERFACE -include ztest.h) diff --git a/tests/bluetooth/host/conn/CMakeLists.txt b/tests/bluetooth/host/conn/CMakeLists.txt deleted file mode 100644 index 2d3c317dec084..0000000000000 --- a/tests/bluetooth/host/conn/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -project(conn) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/conn - ${ZEPHYR_BASE}/tests/bluetooth/host/conn/mocks/zephyr/include -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/conn/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_include_directories(mocks PUBLIC - ${ZEPHYR_BASE}/subsys/bluetooth/host -) - -target_sources(testbinary - PRIVATE - src/main.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/conn.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/lib/net_buf/buf.c - ${ZEPHYR_BASE}/lib/net_buf/buf_simple.c -) diff --git a/tests/bluetooth/host/conn/mocks/CMakeLists.txt b/tests/bluetooth/host/conn/mocks/CMakeLists.txt deleted file mode 100644 index 2d4399c6b7dd2..0000000000000 --- a/tests/bluetooth/host/conn/mocks/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -# -# CMakeLists.txt file for creating of mocks library. -# - -add_library(mocks STATIC - addr_internal.c - att_internal.c - bt_str.c - buf_view.c - hci_core.c - id.c - kernel.c - l2cap_internal.c - scan.c - smp.c - spinlock.c - sys_clock.c -) - -target_include_directories(mocks PUBLIC - ${ZEPHYR_BASE}/tests/bluetooth/host/conn/mocks - ${ZEPHYR_BASE}/subsys/bluetooth -) - -target_compile_options(test_interface INTERFACE -include ztest.h) -target_link_libraries(mocks PRIVATE test_interface) -target_link_options(mocks PUBLIC - "SHELL:-T ${ZEPHYR_BASE}/tests/bluetooth/host/conn/mocks/mock-sections.ld" -) - -target_compile_options(mocks - PRIVATE - -DCONFIG_BT_ID_MAX=1 -) diff --git a/tests/bluetooth/host/conn/mocks/addr_internal.c b/tests/bluetooth/host/conn/mocks/addr_internal.c deleted file mode 100644 index c76067183aeab..0000000000000 --- a/tests/bluetooth/host/conn/mocks/addr_internal.c +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include "addr_internal.h" - -DEFINE_FAKE_VOID_FUNC(bt_addr_le_copy_resolved, bt_addr_le_t *, const bt_addr_le_t *); -DEFINE_FAKE_VALUE_FUNC(bool, bt_addr_le_is_resolved, const bt_addr_le_t *); diff --git a/tests/bluetooth/host/conn/mocks/addr_internal.h b/tests/bluetooth/host/conn/mocks/addr_internal.h deleted file mode 100644 index 20651ea485c93..0000000000000 --- a/tests/bluetooth/host/conn/mocks/addr_internal.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -/* List of fakes used by this unit tester */ -#define ADDR_INTERNAL_MOCKS_FFF_FAKES_LIST(FAKE) \ - FAKE(bt_addr_le_copy_resolved) \ - FAKE(bt_addr_le_is_resolved) - -DECLARE_FAKE_VOID_FUNC(bt_addr_le_copy_resolved, bt_addr_le_t *, const bt_addr_le_t *); -DECLARE_FAKE_VALUE_FUNC(bool, bt_addr_le_is_resolved, const bt_addr_le_t *); diff --git a/tests/bluetooth/host/conn/mocks/att_internal.c b/tests/bluetooth/host/conn/mocks/att_internal.c deleted file mode 100644 index 61485478153d6..0000000000000 --- a/tests/bluetooth/host/conn/mocks/att_internal.c +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include "att_internal.h" - -DEFINE_FAKE_VOID_FUNC(bt_att_init); diff --git a/tests/bluetooth/host/conn/mocks/att_internal.h b/tests/bluetooth/host/conn/mocks/att_internal.h deleted file mode 100644 index b7a37ee9b464c..0000000000000 --- a/tests/bluetooth/host/conn/mocks/att_internal.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -/* List of fakes used by this unit tester */ -#define ATT_INTERNAL_MOCKS_FFF_FAKES_LIST(FAKE) FAKE(bt_att_init) - -DECLARE_FAKE_VOID_FUNC(bt_att_init); diff --git a/tests/bluetooth/host/conn/mocks/bt_str.c b/tests/bluetooth/host/conn/mocks/bt_str.c deleted file mode 100644 index 21a1c72751b3a..0000000000000 --- a/tests/bluetooth/host/conn/mocks/bt_str.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -#include "bt_str.h" - -const char *bt_addr_le_str(const bt_addr_le_t *addr) -{ - static char str[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(addr, str, sizeof(str)); - - return str; -} diff --git a/tests/bluetooth/host/conn/mocks/bt_str.h b/tests/bluetooth/host/conn/mocks/bt_str.h deleted file mode 100644 index 53786cd31e28d..0000000000000 --- a/tests/bluetooth/host/conn/mocks/bt_str.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -const char *bt_addr_le_str(const bt_addr_le_t *addr); diff --git a/tests/bluetooth/host/conn/mocks/buf_view.c b/tests/bluetooth/host/conn/mocks/buf_view.c deleted file mode 100644 index 30c11cc59ec24..0000000000000 --- a/tests/bluetooth/host/conn/mocks/buf_view.c +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include "buf_view.h" - -DEFINE_FAKE_VALUE_FUNC(bool, bt_buf_has_view, const struct net_buf *); -DEFINE_FAKE_VALUE_FUNC(struct net_buf *, bt_buf_make_view, struct net_buf *, struct net_buf *, - size_t, struct bt_buf_view_meta *); -DEFINE_FAKE_VOID_FUNC(bt_buf_destroy_view, struct net_buf *, struct bt_buf_view_meta *); diff --git a/tests/bluetooth/host/conn/mocks/buf_view.h b/tests/bluetooth/host/conn/mocks/buf_view.h deleted file mode 100644 index 480510a888033..0000000000000 --- a/tests/bluetooth/host/conn/mocks/buf_view.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -/* List of fakes used by this unit tester */ -#define BUF_VIEW_MOCKS_FFF_FAKES_LIST(FAKE) FAKE(bt_buf_has_view) \ - FAKE(bt_buf_make_view) \ - FAKE(bt_buf_destroy_view) - -DECLARE_FAKE_VALUE_FUNC(bool, bt_buf_has_view, const struct net_buf *); -DECLARE_FAKE_VALUE_FUNC(struct net_buf *, bt_buf_make_view, struct net_buf *, struct net_buf *, - size_t, struct bt_buf_view_meta *); -DECLARE_FAKE_VOID_FUNC(bt_buf_destroy_view, struct net_buf *, struct bt_buf_view_meta *); diff --git a/tests/bluetooth/host/conn/mocks/hci_core.c b/tests/bluetooth/host/conn/mocks/hci_core.c deleted file mode 100644 index 3ba21db49a619..0000000000000 --- a/tests/bluetooth/host/conn/mocks/hci_core.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -#include - -#include "hci_core.h" - -DEFINE_FAKE_VALUE_FUNC(struct net_buf *, bt_hci_cmd_alloc, k_timeout_t); -DEFINE_FAKE_VALUE_FUNC(int, bt_hci_cmd_send_sync, uint16_t, struct net_buf *, struct net_buf **); -DEFINE_FAKE_VALUE_FUNC(int, bt_hci_le_read_remote_features, struct bt_conn *); -DEFINE_FAKE_VALUE_FUNC(int, bt_hci_disconnect, uint16_t, uint8_t); -DEFINE_FAKE_VALUE_FUNC(bool, bt_le_conn_params_valid, const struct bt_le_conn_param *); -DEFINE_FAKE_VOID_FUNC(bt_tx_irq_raise); -DEFINE_FAKE_VALUE_FUNC(int, bt_send, struct net_buf *); -DEFINE_FAKE_VOID_FUNC(bt_send_one_host_num_completed_packets, uint16_t); -DEFINE_FAKE_VOID_FUNC(bt_acl_set_ncp_sent, struct net_buf *, bool); -DEFINE_FAKE_VALUE_FUNC(int, bt_le_create_conn, const struct bt_conn *); -DEFINE_FAKE_VALUE_FUNC(int, bt_le_create_conn_cancel); -DEFINE_FAKE_VALUE_FUNC(int, bt_le_create_conn_synced, const struct bt_conn *, - const struct bt_le_ext_adv *, uint8_t); -DEFINE_FAKE_VALUE_FUNC(const bt_addr_le_t *, bt_lookup_id_addr, uint8_t, const bt_addr_le_t *); -DEFINE_FAKE_VALUE_FUNC(int, bt_le_set_phy, struct bt_conn *, uint8_t, uint8_t, uint8_t, uint8_t); - -struct bt_dev bt_dev = { - .manufacturer = 0x1234, -}; diff --git a/tests/bluetooth/host/conn/mocks/hci_core.h b/tests/bluetooth/host/conn/mocks/hci_core.h deleted file mode 100644 index a12185a537ff5..0000000000000 --- a/tests/bluetooth/host/conn/mocks/hci_core.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -/* List of fakes used by this unit tester */ -#define HCI_CORE_MOCKS_FFF_FAKES_LIST(FAKE) \ - FAKE(bt_hci_cmd_alloc) \ - FAKE(bt_hci_cmd_send_sync) \ - FAKE(bt_hci_le_read_remote_features) \ - FAKE(bt_hci_disconnect) \ - FAKE(bt_le_conn_params_valid) \ - FAKE(bt_tx_irq_raise) \ - FAKE(bt_send) \ - FAKE(bt_send_one_host_num_completed_packets) \ - FAKE(bt_acl_set_ncp_sent) \ - FAKE(bt_le_create_conn) \ - FAKE(bt_le_create_conn_cancel) \ - FAKE(bt_le_create_conn_synced) \ - FAKE(bt_lookup_id_addr) \ - FAKE(bt_le_set_phy) - -DECLARE_FAKE_VALUE_FUNC(struct net_buf *, bt_hci_cmd_alloc, k_timeout_t); -DECLARE_FAKE_VALUE_FUNC(int, bt_hci_cmd_send_sync, uint16_t, struct net_buf *, struct net_buf **); -DECLARE_FAKE_VALUE_FUNC(int, bt_hci_le_read_remote_features, struct bt_conn *); -DECLARE_FAKE_VALUE_FUNC(int, bt_hci_disconnect, uint16_t, uint8_t); -DECLARE_FAKE_VALUE_FUNC(bool, bt_le_conn_params_valid, const struct bt_le_conn_param *); -DECLARE_FAKE_VOID_FUNC(bt_tx_irq_raise); -DECLARE_FAKE_VALUE_FUNC(int, bt_send, struct net_buf *); -DECLARE_FAKE_VOID_FUNC(bt_send_one_host_num_completed_packets, uint16_t); -DECLARE_FAKE_VOID_FUNC(bt_acl_set_ncp_sent, struct net_buf *, bool); -DECLARE_FAKE_VALUE_FUNC(int, bt_le_create_conn, const struct bt_conn *); -DECLARE_FAKE_VALUE_FUNC(int, bt_le_create_conn_cancel); -DECLARE_FAKE_VALUE_FUNC(int, bt_le_create_conn_synced, const struct bt_conn *, - const struct bt_le_ext_adv *, uint8_t); -DECLARE_FAKE_VALUE_FUNC(const bt_addr_le_t *, bt_lookup_id_addr, uint8_t, const bt_addr_le_t *); -DECLARE_FAKE_VALUE_FUNC(int, bt_le_set_phy, struct bt_conn *, uint8_t, uint8_t, uint8_t, uint8_t); diff --git a/tests/bluetooth/host/conn/mocks/id.c b/tests/bluetooth/host/conn/mocks/id.c deleted file mode 100644 index 887ea69caad8a..0000000000000 --- a/tests/bluetooth/host/conn/mocks/id.c +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include "id.h" - -DEFINE_FAKE_VALUE_FUNC(bool, bt_id_scan_random_addr_check); diff --git a/tests/bluetooth/host/conn/mocks/id.h b/tests/bluetooth/host/conn/mocks/id.h deleted file mode 100644 index e6e3bb8f8a2e7..0000000000000 --- a/tests/bluetooth/host/conn/mocks/id.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -/* List of fakes used by this unit tester */ -#define ID_MOCKS_FFF_FAKES_LIST(FAKE) FAKE(bt_id_scan_random_addr_check) - -DECLARE_FAKE_VALUE_FUNC(bool, bt_id_scan_random_addr_check); diff --git a/tests/bluetooth/host/conn/mocks/kernel.c b/tests/bluetooth/host/conn/mocks/kernel.c deleted file mode 100644 index af7a319b8a2a6..0000000000000 --- a/tests/bluetooth/host/conn/mocks/kernel.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2024-2025 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include -#include - -#include "kernel.h" - -DEFINE_FAKE_VALUE_FUNC(bool, k_is_in_isr); -DEFINE_FAKE_VALUE_FUNC(int, k_poll_signal_raise, struct k_poll_signal *, int); -DEFINE_FAKE_VALUE_FUNC(int, k_sem_take, struct k_sem *, k_timeout_t); -DEFINE_FAKE_VALUE_FUNC(unsigned int, k_sem_count_get, struct k_sem *); -DEFINE_FAKE_VOID_FUNC(k_sem_give, struct k_sem *); -DEFINE_FAKE_VALUE_FUNC(k_tid_t, k_sched_current_thread_query); -DEFINE_FAKE_VOID_FUNC(k_work_init, struct k_work *, k_work_handler_t); -DEFINE_FAKE_VOID_FUNC(k_work_init_delayable, struct k_work_delayable *, k_work_handler_t); -DEFINE_FAKE_VALUE_FUNC(int, k_work_cancel_delayable, struct k_work_delayable *); -DEFINE_FAKE_VALUE_FUNC(bool, k_work_flush, struct k_work *, struct k_work_sync *); -DEFINE_FAKE_VALUE_FUNC(int, k_work_submit, struct k_work *); -DEFINE_FAKE_VALUE_FUNC(int, k_work_submit_to_queue, struct k_work_q *, struct k_work *); -DEFINE_FAKE_VALUE_FUNC(int, k_work_reschedule, struct k_work_delayable *, k_timeout_t); -DEFINE_FAKE_VALUE_FUNC(int, k_work_schedule, struct k_work_delayable *, k_timeout_t); -DEFINE_FAKE_VALUE_FUNC(int, k_work_busy_get, const struct k_work *); -DEFINE_FAKE_VOID_FUNC(k_queue_init, struct k_queue *); -DEFINE_FAKE_VOID_FUNC(k_queue_append, struct k_queue *, void *); -DEFINE_FAKE_VALUE_FUNC(int, k_queue_is_empty, struct k_queue *); -DEFINE_FAKE_VALUE_FUNC(void *, k_queue_get, struct k_queue *, k_timeout_t); -DEFINE_FAKE_VOID_FUNC(k_queue_prepend, struct k_queue *, void *); -DEFINE_FAKE_VALUE_FUNC(void *, k_heap_alloc, struct k_heap *, size_t, k_timeout_t); -DEFINE_FAKE_VOID_FUNC(k_heap_free, struct k_heap *, void *); -DEFINE_FAKE_VOID_FUNC(k_sched_lock); -DEFINE_FAKE_VOID_FUNC(k_sched_unlock); -DEFINE_FAKE_VALUE_FUNC(void *, k_heap_aligned_alloc, struct k_heap *, - size_t, size_t, k_timeout_t); - -struct k_work_q k_sys_work_q; diff --git a/tests/bluetooth/host/conn/mocks/kernel.h b/tests/bluetooth/host/conn/mocks/kernel.h deleted file mode 100644 index db02f0ada830d..0000000000000 --- a/tests/bluetooth/host/conn/mocks/kernel.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2024-2025 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include - -#include -#include - -/* List of fakes used by this unit tester */ -#define KERNEL_MOCKS_FFF_FAKES_LIST(FAKE) \ - FAKE(k_is_in_isr) \ - FAKE(k_poll_signal_raise) \ - FAKE(k_sem_take) \ - FAKE(k_sem_count_get) \ - FAKE(k_sem_give) \ - FAKE(k_sched_current_thread_query) \ - FAKE(k_work_init) \ - FAKE(k_work_init_delayable) \ - FAKE(k_work_cancel_delayable) \ - FAKE(k_work_flush) \ - FAKE(k_work_submit) \ - FAKE(k_work_submit_to_queue) \ - FAKE(k_work_reschedule) \ - FAKE(k_work_schedule) \ - FAKE(k_queue_init) \ - FAKE(k_queue_append) \ - FAKE(k_queue_is_empty) \ - FAKE(k_queue_get) \ - FAKE(k_queue_prepend) \ - FAKE(k_heap_alloc) \ - FAKE(k_heap_aligned_alloc) \ - FAKE(k_heap_free) \ - FAKE(k_sched_lock) \ - FAKE(k_sched_unlock) \ - -DECLARE_FAKE_VALUE_FUNC(bool, k_is_in_isr); -DECLARE_FAKE_VALUE_FUNC(int, k_poll_signal_raise, struct k_poll_signal *, int); -DECLARE_FAKE_VALUE_FUNC(int, k_sem_take, struct k_sem *, k_timeout_t); -DECLARE_FAKE_VALUE_FUNC(unsigned int, k_sem_count_get, struct k_sem *); -DECLARE_FAKE_VOID_FUNC(k_sem_give, struct k_sem *); -DECLARE_FAKE_VALUE_FUNC(k_tid_t, k_sched_current_thread_query); -DECLARE_FAKE_VOID_FUNC(k_work_init, struct k_work *, k_work_handler_t); -DECLARE_FAKE_VOID_FUNC(k_work_init_delayable, struct k_work_delayable *, k_work_handler_t); -DECLARE_FAKE_VALUE_FUNC(int, k_work_busy_get, const struct k_work *); -DECLARE_FAKE_VALUE_FUNC(int, k_work_cancel_delayable, struct k_work_delayable *); -DECLARE_FAKE_VALUE_FUNC(bool, k_work_flush, struct k_work *, struct k_work_sync *); -DECLARE_FAKE_VALUE_FUNC(int, k_work_submit, struct k_work *); -DECLARE_FAKE_VALUE_FUNC(int, k_work_submit_to_queue, struct k_work_q *, struct k_work *); -DECLARE_FAKE_VALUE_FUNC(int, k_work_reschedule, struct k_work_delayable *, k_timeout_t); -DECLARE_FAKE_VALUE_FUNC(int, k_work_schedule, struct k_work_delayable *, k_timeout_t); -DECLARE_FAKE_VOID_FUNC(k_queue_init, struct k_queue *); -DECLARE_FAKE_VOID_FUNC(k_queue_append, struct k_queue *, void *); -DECLARE_FAKE_VALUE_FUNC(int, k_queue_is_empty, struct k_queue *); -DECLARE_FAKE_VALUE_FUNC(void *, k_queue_get, struct k_queue *, k_timeout_t); -DECLARE_FAKE_VOID_FUNC(k_queue_prepend, struct k_queue *, void *); -DECLARE_FAKE_VALUE_FUNC(void *, k_heap_alloc, struct k_heap *, size_t, k_timeout_t); -DECLARE_FAKE_VOID_FUNC(k_heap_free, struct k_heap *, void *); -DECLARE_FAKE_VOID_FUNC(k_sched_lock); -DECLARE_FAKE_VOID_FUNC(k_sched_unlock); -DECLARE_FAKE_VALUE_FUNC(void *, k_heap_aligned_alloc, struct k_heap *, - size_t, size_t, k_timeout_t); diff --git a/tests/bluetooth/host/conn/mocks/l2cap_internal.c b/tests/bluetooth/host/conn/mocks/l2cap_internal.c deleted file mode 100644 index 5f638fa12af98..0000000000000 --- a/tests/bluetooth/host/conn/mocks/l2cap_internal.c +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include "l2cap_internal.h" - -DEFINE_FAKE_VOID_FUNC(bt_l2cap_init); -DEFINE_FAKE_VOID_FUNC(bt_l2cap_recv, struct bt_conn *, struct net_buf *, bool); -DEFINE_FAKE_VOID_FUNC(bt_l2cap_connected, struct bt_conn *); -DEFINE_FAKE_VALUE_FUNC(int, bt_l2cap_update_conn_param, struct bt_conn *, - const struct bt_le_conn_param *); -DEFINE_FAKE_VOID_FUNC(bt_l2cap_disconnected, struct bt_conn *); -DEFINE_FAKE_VALUE_FUNC(struct net_buf *, l2cap_data_pull, struct bt_conn *, size_t, size_t *); diff --git a/tests/bluetooth/host/conn/mocks/l2cap_internal.h b/tests/bluetooth/host/conn/mocks/l2cap_internal.h deleted file mode 100644 index bf553d2cec7fe..0000000000000 --- a/tests/bluetooth/host/conn/mocks/l2cap_internal.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -/* List of fakes used by this unit tester */ -#define L2CAP_INTERNAL_MOCKS_FFF_FAKES_LIST(FAKE) \ - FAKE(bt_l2cap_init) \ - FAKE(bt_l2cap_recv) \ - FAKE(bt_l2cap_connected) \ - FAKE(bt_l2cap_update_conn_param) \ - FAKE(bt_l2cap_disconnected) \ - FAKE(l2cap_data_pull) - -DECLARE_FAKE_VOID_FUNC(bt_l2cap_init); -DECLARE_FAKE_VOID_FUNC(bt_l2cap_recv, struct bt_conn *, struct net_buf *, bool); -DECLARE_FAKE_VOID_FUNC(bt_l2cap_connected, struct bt_conn *); -DECLARE_FAKE_VALUE_FUNC(int, bt_l2cap_update_conn_param, struct bt_conn *, - const struct bt_le_conn_param *); -DECLARE_FAKE_VOID_FUNC(bt_l2cap_disconnected, struct bt_conn *); -DECLARE_FAKE_VALUE_FUNC(struct net_buf *, l2cap_data_pull, struct bt_conn *, size_t, size_t *); diff --git a/tests/bluetooth/host/conn/mocks/mock-sections.ld b/tests/bluetooth/host/conn/mocks/mock-sections.ld deleted file mode 100644 index 3b296f55b1e4b..0000000000000 --- a/tests/bluetooth/host/conn/mocks/mock-sections.ld +++ /dev/null @@ -1,29 +0,0 @@ -/* This is a stub file for the linker. None of the sections are used by the test. */ - -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -SECTIONS -{ - bt_conn_cb_area : ALIGN(4) - { - _bt_conn_cb_list_start = .; - KEEP(*(SORT_BY_NAME(._bt_conn_cb.static.*))) - _bt_conn_cb_list_end = .; - } -} -INSERT AFTER .data; - -SECTIONS -{ - net_buf_pool : ALIGN(4) - { - _net_buf_pool_list_start = .; - KEEP(*(SORT_BY_NAME(._net_buf_pool.static.*))) - _net_buf_pool_list_end_end = .; - } -} -INSERT AFTER .bss; diff --git a/tests/bluetooth/host/conn/mocks/scan.c b/tests/bluetooth/host/conn/mocks/scan.c deleted file mode 100644 index 1359f5396060e..0000000000000 --- a/tests/bluetooth/host/conn/mocks/scan.c +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -#include "scan.h" - -DEFINE_FAKE_VALUE_FUNC(int, bt_le_scan_user_add, enum bt_le_scan_user); -DEFINE_FAKE_VALUE_FUNC(int, bt_le_scan_user_remove, enum bt_le_scan_user); -DEFINE_FAKE_VALUE_FUNC(bool, bt_le_explicit_scanner_running); diff --git a/tests/bluetooth/host/conn/mocks/scan.h b/tests/bluetooth/host/conn/mocks/scan.h deleted file mode 100644 index b694e309d163a..0000000000000 --- a/tests/bluetooth/host/conn/mocks/scan.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -#include - -/* List of fakes used by this unit tester */ -#define SCAN_MOCKS_FFF_FAKES_LIST(FAKE) \ - FAKE(bt_le_scan_user_add) \ - FAKE(bt_le_scan_user_remove) \ - FAKE(bt_le_explicit_scanner_running) - -DECLARE_FAKE_VALUE_FUNC(int, bt_le_scan_user_add, enum bt_le_scan_user); -DECLARE_FAKE_VALUE_FUNC(int, bt_le_scan_user_remove, enum bt_le_scan_user); -DECLARE_FAKE_VALUE_FUNC(bool, bt_le_explicit_scanner_running); diff --git a/tests/bluetooth/host/conn/mocks/smp.c b/tests/bluetooth/host/conn/mocks/smp.c deleted file mode 100644 index 2377f49a998f4..0000000000000 --- a/tests/bluetooth/host/conn/mocks/smp.c +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include "smp.h" - -DEFINE_FAKE_VOID_FUNC(bt_smp_init); diff --git a/tests/bluetooth/host/conn/mocks/smp.h b/tests/bluetooth/host/conn/mocks/smp.h deleted file mode 100644 index 3e64c15fd8d68..0000000000000 --- a/tests/bluetooth/host/conn/mocks/smp.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -/* List of fakes used by this unit tester */ -#define SMP_MOCKS_FFF_FAKES_LIST(FAKE) FAKE(bt_smp_init) - -DECLARE_FAKE_VOID_FUNC(bt_smp_init); diff --git a/tests/bluetooth/host/conn/mocks/spinlock.c b/tests/bluetooth/host/conn/mocks/spinlock.c deleted file mode 100644 index 0fb772d102871..0000000000000 --- a/tests/bluetooth/host/conn/mocks/spinlock.c +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include "spinlock.h" - -DEFINE_FAKE_VALUE_FUNC(bool, z_spin_lock_valid, struct k_spinlock *); -DEFINE_FAKE_VALUE_FUNC(bool, z_spin_unlock_valid, struct k_spinlock *); -DEFINE_FAKE_VOID_FUNC(z_spin_lock_set_owner, struct k_spinlock *); diff --git a/tests/bluetooth/host/conn/mocks/spinlock.h b/tests/bluetooth/host/conn/mocks/spinlock.h deleted file mode 100644 index 578c7176d8dc6..0000000000000 --- a/tests/bluetooth/host/conn/mocks/spinlock.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -/* List of fakes used by this unit tester */ -#define SPINLOCK_MOCKS_FFF_FAKES_LIST(FAKE) \ - FAKE(z_spin_lock_valid) \ - FAKE(z_spin_unlock_valid) \ - FAKE(z_spin_lock_set_owner) - -DECLARE_FAKE_VALUE_FUNC(bool, z_spin_lock_valid, struct k_spinlock *); -DECLARE_FAKE_VALUE_FUNC(bool, z_spin_unlock_valid, struct k_spinlock *); -DECLARE_FAKE_VOID_FUNC(z_spin_lock_set_owner, struct k_spinlock *); diff --git a/tests/bluetooth/host/conn/mocks/sys_clock.c b/tests/bluetooth/host/conn/mocks/sys_clock.c deleted file mode 100644 index 070d26855a6f4..0000000000000 --- a/tests/bluetooth/host/conn/mocks/sys_clock.c +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include "sys_clock.h" - -DEFINE_FAKE_VALUE_FUNC(k_timepoint_t, sys_timepoint_calc, k_timeout_t); -DEFINE_FAKE_VALUE_FUNC(k_timeout_t, sys_timepoint_timeout, k_timepoint_t); diff --git a/tests/bluetooth/host/conn/mocks/sys_clock.h b/tests/bluetooth/host/conn/mocks/sys_clock.h deleted file mode 100644 index 1594386e7fc6d..0000000000000 --- a/tests/bluetooth/host/conn/mocks/sys_clock.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -/* List of fakes used by this unit tester */ -#define SYS_CLOCK_MOCKS_FFF_FAKES_LIST(FAKE) \ - FAKE(sys_timepoint_calc) \ - FAKE(sys_timepoint_timeout) - -DECLARE_FAKE_VALUE_FUNC(k_timepoint_t, sys_timepoint_calc, k_timeout_t); -DECLARE_FAKE_VALUE_FUNC(k_timeout_t, sys_timepoint_timeout, k_timepoint_t); diff --git a/tests/bluetooth/host/conn/mocks/zephyr/syscalls/device.h b/tests/bluetooth/host/conn/mocks/zephyr/syscalls/device.h deleted file mode 100644 index db591a5b5e530..0000000000000 --- a/tests/bluetooth/host/conn/mocks/zephyr/syscalls/device.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/* - * Dummy header file to avoid compiler errors - * intentionally left blank - */ diff --git a/tests/bluetooth/host/conn/prj.conf b/tests/bluetooth/host/conn/prj.conf deleted file mode 100644 index eb8d5a0fdbf79..0000000000000 --- a/tests/bluetooth/host/conn/prj.conf +++ /dev/null @@ -1,20 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y - -CONFIG_BT=y -CONFIG_BT_HCI=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_EXT_ADV=y -CONFIG_BT_PER_ADV=y -CONFIG_BT_PER_ADV_SYNC=y - -CONFIG_BT_MAX_CONN=1 -CONFIG_BT_L2CAP_TX_MTU=23 -CONFIG_BT_CONN_PARAM_UPDATE_TIMEOUT=5000 -CONFIG_BT_L2CAP_TX_BUF_COUNT=3 -CONFIG_BT_ID_MAX=1 -CONFIG_BT_CENTRAL=y - -CONFIG_NET_BUF=y diff --git a/tests/bluetooth/host/conn/src/main.c b/tests/bluetooth/host/conn/src/main.c deleted file mode 100644 index d4c800bd52163..0000000000000 --- a/tests/bluetooth/host/conn/src/main.c +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (c) 2024-2025 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include - -#include - -#include "mocks/addr_internal.h" -#include "mocks/att_internal.h" -#include "mocks/bt_str.h" -#include "mocks/buf_view.h" -#include "mocks/hci_core.h" -#include "mocks/id.h" -#include "mocks/kernel.h" -#include "mocks/l2cap_internal.h" -#include "mocks/scan.h" -#include "mocks/smp.h" -#include "mocks/spinlock.h" -#include "mocks/sys_clock.h" - -DEFINE_FFF_GLOBALS; - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - ADDR_INTERNAL_MOCKS_FFF_FAKES_LIST(RESET_FAKE); - ATT_INTERNAL_MOCKS_FFF_FAKES_LIST(RESET_FAKE); - BUF_VIEW_MOCKS_FFF_FAKES_LIST(RESET_FAKE); - HCI_CORE_MOCKS_FFF_FAKES_LIST(RESET_FAKE); - ID_MOCKS_FFF_FAKES_LIST(RESET_FAKE); - KERNEL_MOCKS_FFF_FAKES_LIST(RESET_FAKE); - L2CAP_INTERNAL_MOCKS_FFF_FAKES_LIST(RESET_FAKE); - SCAN_MOCKS_FFF_FAKES_LIST(RESET_FAKE); - SMP_MOCKS_FFF_FAKES_LIST(RESET_FAKE); - SPINLOCK_MOCKS_FFF_FAKES_LIST(RESET_FAKE); - SYS_CLOCK_MOCKS_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(conn, NULL, NULL, NULL, NULL, NULL); - -/* - * Test that bt_conn_le_create() returns -EINVAL if conn is not NULL and - * CONFIG_BT_CONN_CHECK_NULL_BEFORE_CREATE is enabled. - * - * The test must be compiled with and without CONFIG_BT_CONN_CHECK_NULL_BEFORE_CREATE - * to ensure that the -EINVAL error is returned only when this Kconfig option is enabled. - */ -ZTEST(conn, test_bt_conn_le_create_check_null_conn) -{ - bt_addr_le_t peer = {.a.val = {0x01}}; - const struct bt_conn_le_create_param create_param = { - .options = BT_CONN_LE_OPT_NONE, - .interval = BT_GAP_SCAN_FAST_INTERVAL, - .window = BT_GAP_SCAN_FAST_WINDOW, - .interval_coded = 0, - .window_coded = 0, - .timeout = 100UL * MSEC_PER_SEC / 10, - }; - struct bt_conn *conn; - int err; - - /* Set conn to any non-NULL value to trigger the check. */ - conn = (struct bt_conn *)1; - - err = bt_conn_le_create(&peer, &create_param, BT_LE_CONN_PARAM_DEFAULT, &conn); - /* err must not be -EINVAL if CONFIG_BT_CONN_CHECK_NULL_BEFORE_CREATE is not enabled, - * otherwise -EAGAIN is returned. - * - * The printk is used to see what actually was compiled. - */ -#if defined(CONFIG_BT_CONN_CHECK_NULL_BEFORE_CREATE) - printk("Expected error -EINVAL\n"); - zassert_equal(err, -EINVAL, "Failed starting initiator (err %d)", err); -#else - printk("Expected error -EAGAIN\n"); - zassert_equal(err, -EAGAIN, "Failed starting initiator (err %d)", err); -#endif - - /* If the conn is NULL, next error must not be -EINVAL. */ - conn = NULL; - err = bt_conn_le_create(&peer, &create_param, BT_LE_CONN_PARAM_DEFAULT, &conn); - zassert_not_equal(err, -EINVAL, "Failed starting initiator (err %d)", err); -} - -/* - * Test that bt_conn_le_create_synced() returns -EINVAL if conn is not NULL and - * CONFIG_BT_CONN_CHECK_NULL_BEFORE_CREATE is enabled. - * - * The test must be compiled with and without CONFIG_BT_CONN_CHECK_NULL_BEFORE_CREATE - * to ensure that the -EINVAL error is returned only when this Kconfig option is enabled. - */ -ZTEST(conn, test_bt_conn_le_create_synced_check_null_conn) -{ - bt_addr_le_t peer = {.a.val = {0x01}}; - struct bt_le_conn_param conn_param = { - .interval_min = 0x30, - .interval_max = 0x30, - .latency = 0, - .timeout = 400, - }; - struct bt_conn_le_create_synced_param synced_param = { - .peer = &peer, - }; - struct bt_le_ext_adv *adv = NULL; - struct bt_conn *conn; - int err; - - /* Set conn to any non-NULL value to trigger the check. */ - conn = (struct bt_conn *)1; - err = bt_conn_le_create_synced(adv, &synced_param, &conn_param, &conn); - - /* err must not be -EINVAL if CONFIG_BT_CONN_CHECK_NULL_BEFORE_CREATE is not enabled, - * otherwise -EAGAIN is returned. - * - * The printk is used to see what actually was compiled. - */ -#if defined(CONFIG_BT_CONN_CHECK_NULL_BEFORE_CREATE) - printk("Expected error -EINVAL\n"); - zassert_equal(err, -EINVAL, "Failed starting initiator (err %d)", err); -#else - printk("Expected error -EAGAIN\n"); - zassert_equal(err, -EAGAIN, "Failed starting initiator (err %d)", err); -#endif - - /* If the conn is NULL, next error must not be -EINVAL. */ - conn = NULL; - err = bt_conn_le_create_synced(adv, &synced_param, &conn_param, &conn); - zassert_not_equal(err, -EINVAL, "Failed starting initiator (err %d)", err); -} - -ZTEST(conn, test_bt_conn_is_type) -{ - struct bt_conn conn = {0}; - - conn.type = BT_CONN_TYPE_LE; - zassert_true(bt_conn_is_type(&conn, BT_CONN_TYPE_LE)); - zassert_false(bt_conn_is_type(&conn, 0)); - zassert_false(bt_conn_is_type(&conn, BT_CONN_TYPE_BR)); - zassert_false(bt_conn_is_type(&conn, BT_CONN_TYPE_SCO)); - zassert_false(bt_conn_is_type(&conn, BT_CONN_TYPE_ISO)); - - zassert_true(bt_conn_is_type(&conn, BT_CONN_TYPE_LE | BT_CONN_TYPE_BR)); - zassert_true(bt_conn_is_type(&conn, BT_CONN_TYPE_LE | BT_CONN_TYPE_SCO)); - zassert_true(bt_conn_is_type(&conn, BT_CONN_TYPE_LE | BT_CONN_TYPE_ISO)); - zassert_true(bt_conn_is_type(&conn, BT_CONN_TYPE_ALL)); - - conn.type = BT_CONN_TYPE_BR; - zassert_true(bt_conn_is_type(&conn, BT_CONN_TYPE_BR)); - - conn.type = BT_CONN_TYPE_SCO; - zassert_true(bt_conn_is_type(&conn, BT_CONN_TYPE_SCO)); - - conn.type = BT_CONN_TYPE_ISO; - zassert_true(bt_conn_is_type(&conn, BT_CONN_TYPE_ISO)); -} diff --git a/tests/bluetooth/host/conn/testcase.yaml b/tests/bluetooth/host/conn/testcase.yaml deleted file mode 100644 index 1be5442b61d25..0000000000000 --- a/tests/bluetooth/host/conn/testcase.yaml +++ /dev/null @@ -1,11 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.conn.test_default: - type: unit - bluetooth.host.conn.check_null_before_create: - type: unit - extra_configs: - - CONFIG_BT_CONN_CHECK_NULL_BEFORE_CREATE=y diff --git a/tests/bluetooth/host/crypto/CMakeLists.txt b/tests/bluetooth/host/crypto/CMakeLists.txt deleted file mode 100644 index d3b3c529042e0..0000000000000 --- a/tests/bluetooth/host/crypto/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -# -# CMakeLists.txt file for creating of mocks library. -# - -add_library(mocks STATIC - mocks/kernel.c - mocks/hci_core.c - mocks/hci_core_expects.c - mocks/aes.c - mocks/aes_expects.c - mocks/prng.c - mocks/prng_expects.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/crypto_psa.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -) - -target_include_directories(mocks PUBLIC - . - ${ZEPHYR_BASE}/subsys/bluetooth - ${ZEPHYR_BASE}/subsys/bluetooth/host - ${ZEPHYR_BASE}/tests/bluetooth/host - ${ZEPHYR_BASE}/tests/bluetooth/host/crypto/mocks - ${ZEPHYR_MBEDTLS_MODULE_DIR}/include -) - -target_link_libraries(mocks PRIVATE test_interface) diff --git a/tests/bluetooth/host/crypto/bt_encrypt_be/CMakeLists.txt b/tests/bluetooth/host/crypto/bt_encrypt_be/CMakeLists.txt deleted file mode 100644 index a0b3bb65d30bc..0000000000000 --- a/tests/bluetooth/host/crypto/bt_encrypt_be/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -find_package(Zephyr COMPONENTS unittest HINTS $ENV{ZEPHYR_BASE}) - -project(bt_encrypt_be) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/crypto mocks) - -target_sources(testbinary PRIVATE - src/main.c - src/test_suite_invalid_inputs.c -) -target_link_libraries(testbinary PRIVATE mocks host_mocks) diff --git a/tests/bluetooth/host/crypto/bt_encrypt_be/prj.conf b/tests/bluetooth/host/crypto/bt_encrypt_be/prj.conf deleted file mode 100644 index 9b9d1e2cafc40..0000000000000 --- a/tests/bluetooth/host/crypto/bt_encrypt_be/prj.conf +++ /dev/null @@ -1,8 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_MAX_PAIRED=7 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/crypto/bt_encrypt_be/src/main.c b/tests/bluetooth/host/crypto/bt_encrypt_be/src/main.c deleted file mode 100644 index f67bd165ddf7f..0000000000000 --- a/tests/bluetooth/host/crypto/bt_encrypt_be/src/main.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/aes.h" -#include "mocks/aes_expects.h" - -#include -#include -#include - -#include - -DEFINE_FFF_GLOBALS; - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - AES_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(bt_encrypt_be, NULL, NULL, NULL, NULL, NULL); - -/* - * Test bt_encrypt_be() succeeds - * - * Constraints: - * - psa_import_key() succeeds and returns 'PSA_SUCCESS'. - * - psa_cipher_encrypt() succeeds and returns 'PSA_SUCCESS'. - * - * Expected behaviour: - * - bt_encrypt_be() returns 0 (success) - */ -ZTEST(bt_encrypt_be, test_bt_encrypt_be_succeeds) -{ - int err; - const uint8_t key[16] = {0}; - const uint8_t plaintext[16] = {0}; - uint8_t enc_data[16] = {0}; - - psa_import_key_fake.return_val = PSA_SUCCESS; - psa_cipher_encrypt_fake.return_val = PSA_SUCCESS; - - err = bt_encrypt_be(key, plaintext, enc_data); - - expect_single_call_psa_cipher_encrypt(enc_data); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); -} diff --git a/tests/bluetooth/host/crypto/bt_encrypt_be/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/crypto/bt_encrypt_be/src/test_suite_invalid_inputs.c deleted file mode 100644 index 06aab4d114914..0000000000000 --- a/tests/bluetooth/host/crypto/bt_encrypt_be/src/test_suite_invalid_inputs.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" -#include "mocks/aes.h" - -#include -#include - -#include - -ZTEST_SUITE(bt_encrypt_be_invalid_cases, NULL, NULL, NULL, NULL, NULL); - -/* - * Test passing NULL reference for the key argument - * - * Constraints: - * - NULL reference is used for the key argument - * - Valid references are used for the other arguments - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_encrypt_be_invalid_cases, test_null_key_reference) -{ - const uint8_t plaintext[16] = {0}; - uint8_t enc_data[16] = {0}; - - expect_assert(); - bt_encrypt_le(NULL, plaintext, enc_data); -} - -/* - * Test passing NULL reference for the plain text argument - * - * Constraints: - * - NULL reference is used for the plain text argument - * - Valid references are used for the other arguments - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_encrypt_be_invalid_cases, test_null_plaintext_reference) -{ - const uint8_t key[16] = {0}; - uint8_t enc_data[16] = {0}; - - expect_assert(); - bt_encrypt_le(key, NULL, enc_data); -} - -/* - * Test passing NULL reference for the encrypted data destination buffer argument - * - * Constraints: - * - NULL reference is used for the encrypted data destination buffer argument - * - Valid references are used for the other arguments - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_encrypt_be_invalid_cases, test_null_enc_data_reference) -{ - const uint8_t key[16] = {0}; - const uint8_t plaintext[16] = {0}; - - expect_assert(); - bt_encrypt_le(key, plaintext, NULL); -} - -/* - * Test bt_encrypt_le() fails when tc_aes128_set_encrypt_key() fails - * - * Constraints: - * - psa_import_key() fails and returns 'PSA_ERROR_GENERIC_ERROR'. - * - * Expected behaviour: - * - bt_encrypt_le() returns a negative error code '-EINVAL' (failure) - */ -ZTEST(bt_encrypt_be_invalid_cases, test_psa_import_key_fails) -{ - int err; - const uint8_t key[16] = {0}; - const uint8_t plaintext[16] = {0}; - uint8_t enc_data[16] = {0}; - - psa_import_key_fake.return_val = PSA_ERROR_GENERIC_ERROR; - - err = bt_encrypt_le(key, plaintext, enc_data); - - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); -} - -/* - * Test bt_encrypt_le() fails when tc_aes_encrypt() fails - * - * Constraints: - * - psa_import_key() succeeds and returns 'PSA_SUCCESS'. - * - psa_cipher_encrypt() fails and returns 'PSA_ERROR_GENERIC_ERROR'. - * - * Expected behaviour: - * - bt_encrypt_le() returns a negative error code '-EINVAL' (failure) - */ -ZTEST(bt_encrypt_be_invalid_cases, test_psa_cipher_encrypt_fails) -{ - int err; - const uint8_t key[16] = {0}; - const uint8_t plaintext[16] = {0}; - uint8_t enc_data[16] = {0}; - - psa_import_key_fake.return_val = PSA_SUCCESS; - psa_cipher_encrypt_fake.return_val = -EINVAL; - - err = bt_encrypt_le(key, plaintext, enc_data); - - zassert_true(err == -EIO, "Unexpected error code '%d' was returned", err); -} diff --git a/tests/bluetooth/host/crypto/bt_encrypt_be/testcase.yaml b/tests/bluetooth/host/crypto/bt_encrypt_be/testcase.yaml deleted file mode 100644 index c7427efb3e657..0000000000000 --- a/tests/bluetooth/host/crypto/bt_encrypt_be/testcase.yaml +++ /dev/null @@ -1,7 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_encrypt_be.default: - type: unit diff --git a/tests/bluetooth/host/crypto/bt_encrypt_le/CMakeLists.txt b/tests/bluetooth/host/crypto/bt_encrypt_le/CMakeLists.txt deleted file mode 100644 index eac13178c041e..0000000000000 --- a/tests/bluetooth/host/crypto/bt_encrypt_le/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -find_package(Zephyr COMPONENTS unittest HINTS $ENV{ZEPHYR_BASE}) - -project(bt_encrypt_le) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/crypto mocks) - -target_sources(testbinary PRIVATE - src/main.c - src/test_suite_invalid_inputs.c -) -target_link_libraries(testbinary PRIVATE mocks host_mocks) diff --git a/tests/bluetooth/host/crypto/bt_encrypt_le/prj.conf b/tests/bluetooth/host/crypto/bt_encrypt_le/prj.conf deleted file mode 100644 index 9b9d1e2cafc40..0000000000000 --- a/tests/bluetooth/host/crypto/bt_encrypt_le/prj.conf +++ /dev/null @@ -1,8 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_MAX_PAIRED=7 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/crypto/bt_encrypt_le/src/main.c b/tests/bluetooth/host/crypto/bt_encrypt_le/src/main.c deleted file mode 100644 index e59a2802547e6..0000000000000 --- a/tests/bluetooth/host/crypto/bt_encrypt_le/src/main.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/aes.h" -#include "mocks/aes_expects.h" - -#include -#include -#include - -#include - -DEFINE_FFF_GLOBALS; - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - AES_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(bt_encrypt_le, NULL, NULL, NULL, NULL, NULL); - -/* - * Test bt_encrypt_le() succeeds - * - * Constraints: - * - tc_aes128_set_encrypt_key() succeeds and returns 'TC_CRYPTO_SUCCESS'. - * - tc_aes_encrypt() succeeds and returns 'TC_CRYPTO_SUCCESS'. - * - * Expected behaviour: - * - bt_encrypt_le() returns 0 (success) - */ -ZTEST(bt_encrypt_le, test_bt_encrypt_le_succeeds) -{ - int err; - const uint8_t key[16] = {0}; - const uint8_t plaintext[16] = {0}; - uint8_t enc_data[16] = {0}; - - psa_import_key_fake.return_val = PSA_SUCCESS; - psa_cipher_encrypt_fake.return_val = PSA_SUCCESS; - - err = bt_encrypt_le(key, plaintext, enc_data); - - expect_single_call_psa_cipher_encrypt(enc_data); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); -} diff --git a/tests/bluetooth/host/crypto/bt_encrypt_le/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/crypto/bt_encrypt_le/src/test_suite_invalid_inputs.c deleted file mode 100644 index a2bf6af09dfb7..0000000000000 --- a/tests/bluetooth/host/crypto/bt_encrypt_le/src/test_suite_invalid_inputs.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" -#include "mocks/aes.h" - -#include -#include - -#include - -ZTEST_SUITE(bt_encrypt_le_invalid_cases, NULL, NULL, NULL, NULL, NULL); - -/* - * Test passing NULL reference for the key argument - * - * Constraints: - * - NULL reference is used for the key argument - * - Valid references are used for the other arguments - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_encrypt_le_invalid_cases, test_null_key_reference) -{ - const uint8_t plaintext[16] = {0}; - uint8_t enc_data[16] = {0}; - - expect_assert(); - bt_encrypt_le(NULL, plaintext, enc_data); -} - -/* - * Test passing NULL reference for the plain text argument - * - * Constraints: - * - NULL reference is used for the plain text argument - * - Valid references are used for the other arguments - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_encrypt_le_invalid_cases, test_null_plaintext_reference) -{ - const uint8_t key[16] = {0}; - uint8_t enc_data[16] = {0}; - - expect_assert(); - bt_encrypt_le(key, NULL, enc_data); -} - -/* - * Test passing NULL reference for the encrypted data destination buffer argument - * - * Constraints: - * - NULL reference is used for the encrypted data destination buffer argument - * - Valid references are used for the other arguments - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_encrypt_le_invalid_cases, test_null_enc_data_reference) -{ - const uint8_t key[16] = {0}; - const uint8_t plaintext[16] = {0}; - - expect_assert(); - bt_encrypt_le(key, plaintext, NULL); -} - -/* - * Test bt_encrypt_le() fails when tc_aes128_set_encrypt_key() fails - * - * Constraints: - * - tc_aes128_set_encrypt_key() fails and returns 'TC_CRYPTO_FAIL'. - * - * Expected behaviour: - * - bt_encrypt_le() returns a negative error code '-EINVAL' (failure) - */ -ZTEST(bt_encrypt_le_invalid_cases, test_tc_aes128_set_encrypt_key_fails) -{ - int err; - const uint8_t key[16] = {0}; - const uint8_t plaintext[16] = {0}; - uint8_t enc_data[16] = {0}; - - psa_import_key_fake.return_val = PSA_ERROR_GENERIC_ERROR; - - err = bt_encrypt_le(key, plaintext, enc_data); - - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); -} - -/* - * Test bt_encrypt_le() fails when tc_aes_encrypt() fails - * - * Constraints: - * - psa_import_key() succeeds and returns 'PSA_SUCCESS'. - * - psa_cipher_encrypt() fails and returns '-EINVAL'. - * - * Expected behaviour: - * - bt_encrypt_le() returns a negative error code '-EINVAL' (failure) - */ -ZTEST(bt_encrypt_le_invalid_cases, test_tc_aes_encrypt_fails) -{ - int err; - const uint8_t key[16] = {0}; - const uint8_t plaintext[16] = {0}; - uint8_t enc_data[16] = {0}; - - psa_import_key_fake.return_val = PSA_SUCCESS; - psa_cipher_encrypt_fake.return_val = -EINVAL; - - err = bt_encrypt_le(key, plaintext, enc_data); - - zassert_true(err == -EIO, "Unexpected error code '%d' was returned", err); -} diff --git a/tests/bluetooth/host/crypto/bt_encrypt_le/testcase.yaml b/tests/bluetooth/host/crypto/bt_encrypt_le/testcase.yaml deleted file mode 100644 index 899d2379dc9bb..0000000000000 --- a/tests/bluetooth/host/crypto/bt_encrypt_le/testcase.yaml +++ /dev/null @@ -1,7 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_encrypt_le.default: - type: unit diff --git a/tests/bluetooth/host/crypto/bt_rand/CMakeLists.txt b/tests/bluetooth/host/crypto/bt_rand/CMakeLists.txt deleted file mode 100644 index f6c604e671e62..0000000000000 --- a/tests/bluetooth/host/crypto/bt_rand/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -find_package(Zephyr COMPONENTS unittest HINTS $ENV{ZEPHYR_BASE}) - -project(bt_rand) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/crypto mocks) - -target_sources(testbinary PRIVATE - src/main.c - src/test_suite_invalid_inputs.c -) -target_link_libraries(testbinary PRIVATE mocks host_mocks) diff --git a/tests/bluetooth/host/crypto/bt_rand/prj.conf b/tests/bluetooth/host/crypto/bt_rand/prj.conf deleted file mode 100644 index 9b9d1e2cafc40..0000000000000 --- a/tests/bluetooth/host/crypto/bt_rand/prj.conf +++ /dev/null @@ -1,8 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_MAX_PAIRED=7 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/crypto/bt_rand/src/main.c b/tests/bluetooth/host/crypto/bt_rand/src/main.c deleted file mode 100644 index 0ea192e003673..0000000000000 --- a/tests/bluetooth/host/crypto/bt_rand/src/main.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/hci_core.h" -#include "mocks/hci_core_expects.h" -#include "mocks/prng.h" -#include "mocks/prng_expects.h" - -#include -#include -#include - -#include - -DEFINE_FFF_GLOBALS; - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); - PRNG_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(bt_rand, NULL, NULL, NULL, NULL, NULL); - -/* - * Test bt_rand() succeeds while 'CONFIG_BT_HOST_CRYPTO_PRNG' isn't enabled. - * - * Constraints: - * - 'CONFIG_BT_HOST_CRYPTO_PRNG' isn't enabled - * - bt_hci_le_rand() succeeds and returns 0 (success) - * - * Expected behaviour: - * - bt_rand() returns 0 (success) - */ -ZTEST(bt_rand, test_bt_rand_succeeds_host_crypto_prng_disabled) -{ - int err; - uint8_t buf[16]; - size_t buf_len = 16; - uint8_t expected_args_history[] = {16}; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_HOST_CRYPTO_PRNG); - - bt_hci_le_rand_fake.return_val = 0; - - err = bt_rand(buf, buf_len); - - expect_call_count_bt_hci_le_rand(1, expected_args_history); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); -} - -/* - * Test bt_rand() succeeds when psa_generate_random() succeeds on the first call while - * 'CONFIG_BT_HOST_CRYPTO_PRNG' is enabled. - * - * Constraints: - * - 'CONFIG_BT_HOST_CRYPTO_PRNG' is enabled - * - psa_generate_random() succeeds and returns 'PSA_SUCCESS' on the first call. - * - * Expected behaviour: - * - bt_rand() returns 0 (success) - */ -ZTEST(bt_rand, test_psa_generate_random_succeeds_on_first_call) -{ - int err; - uint8_t buf[16]; - size_t buf_len = 16; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_HOST_CRYPTO_PRNG); - - psa_generate_random_fake.return_val = PSA_SUCCESS; - - err = bt_rand(buf, buf_len); - - expect_single_call_psa_generate_random(buf, buf_len); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); -} diff --git a/tests/bluetooth/host/crypto/bt_rand/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/crypto/bt_rand/src/test_suite_invalid_inputs.c deleted file mode 100644 index 78edae4a2e6ab..0000000000000 --- a/tests/bluetooth/host/crypto/bt_rand/src/test_suite_invalid_inputs.c +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" -#include "mocks/hci_core.h" -#include "mocks/hci_core_expects.h" -#include "mocks/prng.h" -#include "mocks/prng_expects.h" - -#include -#include - -#include - -ZTEST_SUITE(bt_rand_invalid_cases, NULL, NULL, NULL, NULL, NULL); - -/* - * Test passing NULL reference destination buffer argument - * - * Constraints: - * - NULL reference is used as an argument for the destination buffer - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_rand_invalid_cases, test_null_dst_buf_reference) -{ - expect_assert(); - bt_rand(NULL, 1); -} - -/* - * Test passing a valid destination buffer reference with size 0 - * - * Constraints: - * - A valid reference is used as an argument for the destination buffer - * - Destination buffer size is passed as 0 - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_rand_invalid_cases, test_zero_dst_buf_size_reference) -{ - uint8_t buf[16]; - - expect_assert(); - bt_rand(buf, 0); -} - -/* - * Test bt_rand() fails when bt_hci_le_rand() fails while 'CONFIG_BT_HOST_CRYPTO_PRNG' - * isn't enabled. - * - * Constraints: - * - 'CONFIG_BT_HOST_CRYPTO_PRNG' isn't enabled - * - bt_hci_le_rand() fails and returns a negative error code. - * - * Expected behaviour: - * - bt_rand() returns a negative error code (failure) - */ -ZTEST(bt_rand_invalid_cases, test_bt_hci_le_rand_fails) -{ - int err; - uint8_t buf[16]; - size_t buf_len = 16; - uint8_t expected_args_history[] = {16}; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_HOST_CRYPTO_PRNG); - - bt_hci_le_rand_fake.return_val = -1; - - err = bt_rand(buf, buf_len); - - expect_call_count_bt_hci_le_rand(1, expected_args_history); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); -} - -/* - * Test bt_rand() fails when psa_generate_random() fails on the first call while - * 'CONFIG_BT_HOST_CRYPTO_PRNG' is enabled. - * - * Constraints: - * - 'CONFIG_BT_HOST_CRYPTO_PRNG' is enabled - * - psa_generate_random() fails and returns '-EIO' on the first call. - * - * Expected behaviour: - * - bt_rand() returns a negative error code '-EIO' (failure) - */ -ZTEST(bt_rand_invalid_cases, test_tc_hmac_prng_generate_fails_on_first_call) -{ - int err; - uint8_t buf[16]; - size_t buf_len = 16; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_HOST_CRYPTO_PRNG); - - psa_generate_random_fake.return_val = -EIO; - - err = bt_rand(buf, buf_len); - - expect_single_call_psa_generate_random(buf, buf_len); - - zassert_true(err == -EIO, "Unexpected error code '%d' was returned", err); -} diff --git a/tests/bluetooth/host/crypto/bt_rand/testcase.yaml b/tests/bluetooth/host/crypto/bt_rand/testcase.yaml deleted file mode 100644 index 9e7801173e9aa..0000000000000 --- a/tests/bluetooth/host/crypto/bt_rand/testcase.yaml +++ /dev/null @@ -1,11 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_rand.default: - type: unit - bluetooth.host.bt_rand.host_crypto_prng_disabled: - type: unit - extra_configs: - - CONFIG_BT_HOST_CRYPTO_PRNG=n diff --git a/tests/bluetooth/host/crypto/mocks/aes.c b/tests/bluetooth/host/crypto/mocks/aes.c deleted file mode 100644 index 37184f49e6705..0000000000000 --- a/tests/bluetooth/host/crypto/mocks/aes.c +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "mocks/aes.h" - -DEFINE_FAKE_VALUE_FUNC(psa_status_t, psa_crypto_init); -DEFINE_FAKE_VALUE_FUNC(psa_status_t, psa_generate_random, uint8_t *, size_t); -DEFINE_FAKE_VALUE_FUNC(psa_status_t, psa_import_key, const psa_key_attributes_t *, const uint8_t *, - size_t, mbedtls_svc_key_id_t *); -DEFINE_FAKE_VALUE_FUNC(psa_status_t, psa_cipher_encrypt, mbedtls_svc_key_id_t, psa_algorithm_t, - const uint8_t *, size_t, uint8_t *, size_t, size_t *); -DEFINE_FAKE_VALUE_FUNC(psa_status_t, psa_destroy_key, mbedtls_svc_key_id_t); diff --git a/tests/bluetooth/host/crypto/mocks/aes.h b/tests/bluetooth/host/crypto/mocks/aes.h deleted file mode 100644 index 3f072dab76086..0000000000000 --- a/tests/bluetooth/host/crypto/mocks/aes.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -/* List of fakes used by this unit tester */ -#define AES_FFF_FAKES_LIST(FAKE) \ - FAKE(psa_crypto_init) \ - FAKE(psa_generate_random) \ - FAKE(psa_import_key) \ - FAKE(psa_cipher_encrypt) \ - FAKE(psa_destroy_key) - -DECLARE_FAKE_VALUE_FUNC(psa_status_t, psa_crypto_init); -DECLARE_FAKE_VALUE_FUNC(psa_status_t, psa_generate_random, uint8_t *, size_t); -DECLARE_FAKE_VALUE_FUNC(psa_status_t, psa_import_key, const psa_key_attributes_t *, const uint8_t *, - size_t, mbedtls_svc_key_id_t *); -DECLARE_FAKE_VALUE_FUNC(psa_status_t, psa_cipher_encrypt, mbedtls_svc_key_id_t, psa_algorithm_t, - const uint8_t *, size_t, uint8_t *, size_t, size_t *); -DECLARE_FAKE_VALUE_FUNC(psa_status_t, psa_destroy_key, mbedtls_svc_key_id_t); diff --git a/tests/bluetooth/host/crypto/mocks/aes_expects.c b/tests/bluetooth/host/crypto/mocks/aes_expects.c deleted file mode 100644 index 6927354712ac5..0000000000000 --- a/tests/bluetooth/host/crypto/mocks/aes_expects.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "mocks/aes.h" -#include "mocks/aes_expects.h" - -void expect_single_call_psa_cipher_encrypt(uint8_t *out) -{ - const char *func_name = "psa_cipher_encrypt"; - - zassert_equal(psa_cipher_encrypt_fake.call_count, 1, "'%s()' was called more than once", - func_name); - - zassert_not_equal(psa_cipher_encrypt_fake.arg1_val, 0, - "'%s()' was called with incorrect '%s' value", func_name, "arg1"); - zassert_not_equal(psa_cipher_encrypt_fake.arg3_val, 0, - "'%s()' was called with incorrect '%s' value", func_name, "arg3"); - zassert_equal_ptr(psa_cipher_encrypt_fake.arg4_val, out, - "'%s()' was called with incorrect '%s' value", func_name, "arg4"); - zassert_not_equal(psa_cipher_encrypt_fake.arg5_val, 0, - "'%s()' was called with incorrect '%s' value", func_name, "arg5"); -} diff --git a/tests/bluetooth/host/crypto/mocks/aes_expects.h b/tests/bluetooth/host/crypto/mocks/aes_expects.h deleted file mode 100644 index 031db8439a9c2..0000000000000 --- a/tests/bluetooth/host/crypto/mocks/aes_expects.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -/* - * Validate expected behaviour when psa_cipher_encrypt() is called - * - * Expected behaviour: - * - psa_cipher_encrypt() to be called once with correct parameters - */ -void expect_single_call_psa_cipher_encrypt(uint8_t *out); diff --git a/tests/bluetooth/host/crypto/mocks/hci_core.c b/tests/bluetooth/host/crypto/mocks/hci_core.c deleted file mode 100644 index 883dcc1690366..0000000000000 --- a/tests/bluetooth/host/crypto/mocks/hci_core.c +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include "mocks/hci_core.h" - -struct bt_dev bt_dev = { - .manufacturer = 0x1234, -}; - -DEFINE_FAKE_VALUE_FUNC(int, bt_hci_le_rand, void *, size_t); diff --git a/tests/bluetooth/host/crypto/mocks/hci_core.h b/tests/bluetooth/host/crypto/mocks/hci_core.h deleted file mode 100644 index 5dd3f7decde8b..0000000000000 --- a/tests/bluetooth/host/crypto/mocks/hci_core.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -/* List of fakes used by this unit tester */ -#define HCI_CORE_FFF_FAKES_LIST(FAKE) \ - FAKE(bt_hci_le_rand) \ - -DECLARE_FAKE_VALUE_FUNC(int, bt_hci_le_rand, void *, size_t); diff --git a/tests/bluetooth/host/crypto/mocks/hci_core_expects.c b/tests/bluetooth/host/crypto/mocks/hci_core_expects.c deleted file mode 100644 index c8f54d7a0894f..0000000000000 --- a/tests/bluetooth/host/crypto/mocks/hci_core_expects.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "mocks/hci_core.h" -#include "mocks/hci_core_expects.h" - -void expect_call_count_bt_hci_le_rand(int call_count, uint8_t args_history[]) -{ - const char *func_name = "bt_hci_le_rand"; - - zassert_equal(bt_hci_le_rand_fake.call_count, call_count, - "'%s()' was called more than once", func_name); - - for (size_t i = 0; i < call_count; i++) { - zassert_not_null(bt_hci_le_rand_fake.arg0_history[i], - "'%s()' was called with incorrect '%s' value", func_name, - "buffer"); - zassert_equal(bt_hci_le_rand_fake.arg1_history[i], args_history[i], - "'%s()' was called with incorrect '%s' value", func_name, "len"); - } -} - -void expect_not_called_bt_hci_le_rand(void) -{ - const char *func_name = "bt_hci_le_rand"; - - zassert_equal(bt_hci_le_rand_fake.call_count, 0, "'%s()' was called unexpectedly", - func_name); -} diff --git a/tests/bluetooth/host/crypto/mocks/hci_core_expects.h b/tests/bluetooth/host/crypto/mocks/hci_core_expects.h deleted file mode 100644 index 66b9d1a58a1fc..0000000000000 --- a/tests/bluetooth/host/crypto/mocks/hci_core_expects.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -/* - * Validate expected behaviour when bt_hci_le_rand() is called - * - * Expected behaviour: - * - bt_hci_le_rand() to be called once with correct parameters - */ -void expect_call_count_bt_hci_le_rand(int call_count, uint8_t args_history[]); - -/* - * Validate expected behaviour when bt_hci_le_rand() isn't called - * - * Expected behaviour: - * - bt_hci_le_rand() isn't called at all - */ -void expect_not_called_bt_hci_le_rand(void); diff --git a/tests/bluetooth/host/crypto/mocks/kernel.c b/tests/bluetooth/host/crypto/mocks/kernel.c deleted file mode 100644 index c691574d2c72a..0000000000000 --- a/tests/bluetooth/host/crypto/mocks/kernel.c +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "mocks/kernel.h" - -DEFINE_FAKE_VALUE_FUNC(int64_t, k_uptime_ticks); diff --git a/tests/bluetooth/host/crypto/mocks/kernel.h b/tests/bluetooth/host/crypto/mocks/kernel.h deleted file mode 100644 index 718d45f44ec5f..0000000000000 --- a/tests/bluetooth/host/crypto/mocks/kernel.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -/* List of fakes used by this unit tester */ -#define KERNEL_FFF_FAKES_LIST(FAKE) \ - FAKE(k_uptime_ticks) \ - -DECLARE_FAKE_VALUE_FUNC(int64_t, k_uptime_ticks); diff --git a/tests/bluetooth/host/crypto/mocks/prng.c b/tests/bluetooth/host/crypto/mocks/prng.c deleted file mode 100644 index d38c9c4826a03..0000000000000 --- a/tests/bluetooth/host/crypto/mocks/prng.c +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "mocks/prng.h" - -DEFINE_FAKE_VALUE_FUNC(psa_status_t, psa_crypto_init); -DEFINE_FAKE_VALUE_FUNC(psa_status_t, psa_generate_random, uint8_t *, size_t); diff --git a/tests/bluetooth/host/crypto/mocks/prng.h b/tests/bluetooth/host/crypto/mocks/prng.h deleted file mode 100644 index d5198e49459dd..0000000000000 --- a/tests/bluetooth/host/crypto/mocks/prng.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -/* List of fakes used by this unit tester */ -#define PRNG_FFF_FAKES_LIST(FAKE) \ - FAKE(psa_crypto_init) \ - FAKE(psa_generate_random) - -DECLARE_FAKE_VALUE_FUNC(psa_status_t, psa_crypto_init); -DECLARE_FAKE_VALUE_FUNC(psa_status_t, psa_generate_random, uint8_t *, size_t); diff --git a/tests/bluetooth/host/crypto/mocks/prng_expects.c b/tests/bluetooth/host/crypto/mocks/prng_expects.c deleted file mode 100644 index 0dc11c639b532..0000000000000 --- a/tests/bluetooth/host/crypto/mocks/prng_expects.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "mocks/prng.h" -#include "mocks/prng_expects.h" - -void expect_single_call_tc_psa_crypto_init(void) -{ - const char *func_name = "psa_crypto_init"; - - zassert_equal(psa_crypto_init_fake.call_count, 1, "'%s()' was called more than once", - func_name); -} - -void expect_single_call_psa_generate_random(uint8_t *out, size_t outlen) -{ - const char *func_name = "psa_generate_random"; - - zassert_equal(psa_generate_random_fake.call_count, 1, - "'%s()' was called more than once", func_name); - - zassert_equal_ptr(psa_generate_random_fake.arg0_val, out, - "'%s()' was called with incorrect '%s' value", func_name, "out"); - zassert_equal(psa_generate_random_fake.arg1_val, outlen, - "'%s()' was called with incorrect '%s' value", func_name, "outlen"); -} diff --git a/tests/bluetooth/host/crypto/mocks/prng_expects.h b/tests/bluetooth/host/crypto/mocks/prng_expects.h deleted file mode 100644 index 43db853c9066d..0000000000000 --- a/tests/bluetooth/host/crypto/mocks/prng_expects.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -/* - * Validate expected behaviour when psa_crypto_init() is called - * - * Expected behaviour: - * - psa_crypto_init() to be called once with correct parameters - */ -void expect_single_call_tc_psa_crypto_init(void); - -/* - * Validate expected behaviour when psa_generate_random() is called - * - * Expected behaviour: - * - psa_generate_random() to be called once with correct parameters - */ -void expect_single_call_psa_generate_random(uint8_t *out, unsigned int outlen); diff --git a/tests/bluetooth/host/crypto/testing_common_defs.h b/tests/bluetooth/host/crypto/testing_common_defs.h deleted file mode 100644 index 5407ea3e2e8c4..0000000000000 --- a/tests/bluetooth/host/crypto/testing_common_defs.h +++ /dev/null @@ -1,5 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ diff --git a/tests/bluetooth/host/cs/bt_le_cs_parse_pct/CMakeLists.txt b/tests/bluetooth/host/cs/bt_le_cs_parse_pct/CMakeLists.txt deleted file mode 100644 index 089406a316f21..0000000000000 --- a/tests/bluetooth/host/cs/bt_le_cs_parse_pct/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -project(bt_step_data_parse) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/cs/mocks -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/cs/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/cs.c - ${ZEPHYR_BASE}/lib/net_buf/buf_simple.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c -) diff --git a/tests/bluetooth/host/cs/bt_le_cs_parse_pct/prj.conf b/tests/bluetooth/host/cs/bt_le_cs_parse_pct/prj.conf deleted file mode 100644 index 8ff995b6f0405..0000000000000 --- a/tests/bluetooth/host/cs/bt_le_cs_parse_pct/prj.conf +++ /dev/null @@ -1,10 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_HCI=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_CHANNEL_SOUNDING=y -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y -CONFIG_NET_BUF=y diff --git a/tests/bluetooth/host/cs/bt_le_cs_parse_pct/src/main.c b/tests/bluetooth/host/cs/bt_le_cs_parse_pct/src/main.c deleted file mode 100644 index 70f07748f533b..0000000000000 --- a/tests/bluetooth/host/cs/bt_le_cs_parse_pct/src/main.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -DEFINE_FFF_GLOBALS; - -ZTEST_SUITE(bt_le_cs_parse_pct, NULL, NULL, NULL, NULL, NULL); - -/* - * Test success case - * - * Constraints: - * - Valid PCT is passed in - * - * Expected behaviour: - * - IQ term matches expected values - */ -ZTEST(bt_le_cs_parse_pct, test_parsing_success) -{ - struct bt_le_cs_iq_sample iq; - - struct { - uint8_t input[3]; - struct bt_le_cs_iq_sample output; - } test_vector[] = { - /* Edge cases */ - {.input = {0x00, 0x00, 0x00}, .output = {.i = 0, .q = 0}}, - {.input = {0xFF, 0xFF, 0xFF}, .output = {.i = -1, .q = -1}}, - {.input = {0xFF, 0x00, 0xFF}, .output = {.i = 255, .q = -16}}, - {.input = {0xFF, 0x00, 0x00}, .output = {.i = 255, .q = 0}}, - {.input = {0x00, 0xFF, 0x00}, .output = {.i = -256, .q = 15}}, - {.input = {0x00, 0x00, 0xFF}, .output = {.i = 0, .q = -16}}, - {.input = {0x00, 0x08, 0x80}, .output = {.i = -2048, .q = -2048}}, - {.input = {0xFF, 0xF7, 0x7F}, .output = {.i = 2047, .q = 2047}}, - - /* Randomly generated using python */ - {.input = {0xEF, 0xCD, 0xAB}, .output = {.i = -529, .q = -1348}}, - {.input = {0x30, 0x75, 0x44}, .output = {.i = 1328, .q = 1095}}, - {.input = {0x46, 0x5D, 0xEB}, .output = {.i = -698, .q = -331}}, - {.input = {0xE8, 0x14, 0x45}, .output = {.i = 1256, .q = 1105}}, - {.input = {0x23, 0xCA, 0x5C}, .output = {.i = -1501, .q = 1484}}, - {.input = {0x68, 0xA0, 0x15}, .output = {.i = 104, .q = 346}}, - {.input = {0x39, 0x73, 0x1B}, .output = {.i = 825, .q = 439}}, - {.input = {0x23, 0x72, 0x3D}, .output = {.i = 547, .q = 983}}, - {.input = {0xF5, 0xF8, 0x3D}, .output = {.i = -1803, .q = 991}}, - {.input = {0xF7, 0xB4, 0xB9}, .output = {.i = 1271, .q = -1125}}, - {.input = {0x61, 0x9F, 0xD5}, .output = {.i = -159, .q = -679}}, - {.input = {0x9B, 0x21, 0xC6}, .output = {.i = 411, .q = -926}}, - {.input = {0x14, 0x86, 0x0F}, .output = {.i = 1556, .q = 248}}, - {.input = {0x8E, 0xBB, 0xC6}, .output = {.i = -1138, .q = -917}}, - {.input = {0x5B, 0xD1, 0xC2}, .output = {.i = 347, .q = -979}}, - {.input = {0x99, 0x4A, 0x28}, .output = {.i = -1383, .q = 644}}, - {.input = {0x32, 0x16, 0x2B}, .output = {.i = 1586, .q = 689}}, - {.input = {0x3E, 0x8C, 0xD4}, .output = {.i = -962, .q = -696}}, - {.input = {0x2B, 0x1F, 0x95}, .output = {.i = -213, .q = -1711}}, - {.input = {0x22, 0xE6, 0xD6}, .output = {.i = 1570, .q = -658}}, - {.input = {0x0B, 0x31, 0xD6}, .output = {.i = 267, .q = -669}}, - {.input = {0x1B, 0x98, 0x9D}, .output = {.i = -2021, .q = -1575}}, - {.input = {0x8E, 0x97, 0x63}, .output = {.i = 1934, .q = 1593}}, - {.input = {0x97, 0x91, 0x8D}, .output = {.i = 407, .q = -1831}}, - {.input = {0x67, 0xF7, 0x1F}, .output = {.i = 1895, .q = 511}}, - {.input = {0xD6, 0x5C, 0x23}, .output = {.i = -810, .q = 565}}, - {.input = {0x92, 0xD3, 0x0B}, .output = {.i = 914, .q = 189}}, - {.input = {0xE8, 0xF3, 0x23}, .output = {.i = 1000, .q = 575}}, - {.input = {0xE6, 0xE3, 0xAD}, .output = {.i = 998, .q = -1314}}, - {.input = {0x6E, 0x70, 0xA9}, .output = {.i = 110, .q = -1385}}, - {.input = {0x63, 0x65, 0x28}, .output = {.i = 1379, .q = 646}}, - {.input = {0x27, 0x0F, 0x32}, .output = {.i = -217, .q = 800}}, - {.input = {0x3F, 0x8C, 0xE1}, .output = {.i = -961, .q = -488}}, - {.input = {0x4E, 0x86, 0xAA}, .output = {.i = 1614, .q = -1368}}, - {.input = {0x9E, 0xD1, 0xF6}, .output = {.i = 414, .q = -147}}, - {.input = {0x86, 0x09, 0x56}, .output = {.i = -1658, .q = 1376}}, - {.input = {0xFF, 0x09, 0x41}, .output = {.i = -1537, .q = 1040}}, - {.input = {0x89, 0xC5, 0x1F}, .output = {.i = 1417, .q = 508}}, - {.input = {0x1A, 0xE2, 0x9A}, .output = {.i = 538, .q = -1618}}, - {.input = {0x7E, 0x03, 0xB8}, .output = {.i = 894, .q = -1152}}, - {.input = {0x5E, 0x28, 0xB3}, .output = {.i = -1954, .q = -1230}}, - {.input = {0xFF, 0x50, 0xF0}, .output = {.i = 255, .q = -251}}, - {.input = {0xB0, 0x07, 0x87}, .output = {.i = 1968, .q = -1936}}, - {.input = {0x7E, 0xD7, 0x0C}, .output = {.i = 1918, .q = 205}}, - {.input = {0x26, 0xA2, 0xC9}, .output = {.i = 550, .q = -870}}, - {.input = {0x97, 0x71, 0x72}, .output = {.i = 407, .q = 1831}}, - {.input = {0x73, 0x0E, 0xC1}, .output = {.i = -397, .q = -1008}}, - {.input = {0xAC, 0x20, 0x6B}, .output = {.i = 172, .q = 1714}}, - {.input = {0x85, 0x7D, 0xB4}, .output = {.i = -635, .q = -1209}}, - {.input = {0xCC, 0xE3, 0x1B}, .output = {.i = 972, .q = 446}}, - {.input = {0x88, 0x48, 0x65}, .output = {.i = -1912, .q = 1620}}, - }; - - for (uint16_t k = 0; k < ARRAY_SIZE(test_vector); k++) { - iq = bt_le_cs_parse_pct(test_vector[k].input); - - zassert_equal(iq.i, test_vector[k].output.i, - "Failed for k = %u, expected %d, not %d", k, test_vector[k].output.i, - iq.i); - zassert_equal(iq.q, test_vector[k].output.q, - "Failed for k = %u, expected %d, not %d", k, test_vector[k].output.q, - iq.q); - } -} diff --git a/tests/bluetooth/host/cs/bt_le_cs_parse_pct/testcase.yaml b/tests/bluetooth/host/cs/bt_le_cs_parse_pct/testcase.yaml deleted file mode 100644 index deab8ebd2949a..0000000000000 --- a/tests/bluetooth/host/cs/bt_le_cs_parse_pct/testcase.yaml +++ /dev/null @@ -1,7 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.cs.bt_le_cs_parse_pct: - type: unit diff --git a/tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/CMakeLists.txt b/tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/CMakeLists.txt deleted file mode 100644 index aee0c445f6b2d..0000000000000 --- a/tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -get_filename_component(project_name ${CMAKE_CURRENT_SOURCE_DIR} NAME) -project(${project_name}) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/cs/mocks -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/cs/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/cs.c - ${ZEPHYR_BASE}/lib/net_buf/buf_simple.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c -) diff --git a/tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/prj.conf b/tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/prj.conf deleted file mode 100644 index 8ff995b6f0405..0000000000000 --- a/tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/prj.conf +++ /dev/null @@ -1,10 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_HCI=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_CHANNEL_SOUNDING=y -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y -CONFIG_NET_BUF=y diff --git a/tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/src/main.c b/tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/src/main.c deleted file mode 100644 index 72784fba71dbe..0000000000000 --- a/tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/src/main.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -DEFINE_FFF_GLOBALS; - -ZTEST_SUITE(bt_le_cs_set_valid_chmap_bits, NULL, NULL, NULL, NULL, NULL); - -/* - * Test uninitialized chmap buffer is populated correctly - * - * Expected behaviour: - * - test_chmap matches correct_chmap - */ -ZTEST(bt_le_cs_set_valid_chmap_bits, test_uninitialized_chmap) -{ - uint8_t test_chmap[10]; - - bt_le_cs_set_valid_chmap_bits(test_chmap); - - uint8_t correct_chmap[10] = {0xFC, 0xFF, 0x7F, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F}; - - zassert_mem_equal(test_chmap, correct_chmap, 10); -} diff --git a/tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/testcase.yaml b/tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/testcase.yaml deleted file mode 100644 index b040e50155924..0000000000000 --- a/tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/testcase.yaml +++ /dev/null @@ -1,7 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.cs.bt_le_cs_set_valid_chmap_bits: - type: unit diff --git a/tests/bluetooth/host/cs/bt_le_cs_step_data_parse/CMakeLists.txt b/tests/bluetooth/host/cs/bt_le_cs_step_data_parse/CMakeLists.txt deleted file mode 100644 index 089406a316f21..0000000000000 --- a/tests/bluetooth/host/cs/bt_le_cs_step_data_parse/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -project(bt_step_data_parse) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/cs/mocks -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/cs/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/cs.c - ${ZEPHYR_BASE}/lib/net_buf/buf_simple.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c -) diff --git a/tests/bluetooth/host/cs/bt_le_cs_step_data_parse/prj.conf b/tests/bluetooth/host/cs/bt_le_cs_step_data_parse/prj.conf deleted file mode 100644 index 8ff995b6f0405..0000000000000 --- a/tests/bluetooth/host/cs/bt_le_cs_step_data_parse/prj.conf +++ /dev/null @@ -1,10 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_HCI=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_CHANNEL_SOUNDING=y -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y -CONFIG_NET_BUF=y diff --git a/tests/bluetooth/host/cs/bt_le_cs_step_data_parse/src/main.c b/tests/bluetooth/host/cs/bt_le_cs_step_data_parse/src/main.c deleted file mode 100644 index 1ed0f2d640b76..0000000000000 --- a/tests/bluetooth/host/cs/bt_le_cs_step_data_parse/src/main.c +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/conn.h" -#include "mocks/hci_core.h" -#include "mocks/net_buf.h" - -#include -#include -#include - -DEFINE_FFF_GLOBALS; - -FAKE_VALUE_FUNC(bool, bt_le_cs_step_data_parse_func, struct bt_le_cs_subevent_step *, void *); - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - RESET_FAKE(bt_le_cs_step_data_parse_func); - CONN_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(bt_le_cs_step_data_parse, NULL, NULL, NULL, NULL, NULL); - -/* - * Test empty data buffer - * - * Constraints: - * - buffer len set to 0 - * - * Expected behaviour: - * - Callback function is not called - */ -ZTEST(bt_le_cs_step_data_parse, test_parsing_empty_buf) -{ - struct net_buf_simple *buf = NET_BUF_SIMPLE(0); - - bt_le_cs_step_data_parse(buf, bt_le_cs_step_data_parse_func, NULL); - - zassert_equal(bt_le_cs_step_data_parse_func_fake.call_count, 0); -} - -/* - * Test malformed step data - * - * Constraints: - * - step data with a step length going out of bounds - * - * Expected behaviour: - * - Callback function is called once - */ -ZTEST(bt_le_cs_step_data_parse, test_parsing_invalid_length) -{ - struct net_buf_simple buf; - uint8_t data[] = { - 0x00, 0x01, 0x01, 0x00, /* mode 0 */ - 0x03, 0x20, 0x03, 0x00, 0x11, /* mode 3 step with bad length */ - }; - - bt_le_cs_step_data_parse_func_fake.return_val = true; - - net_buf_simple_init_with_data(&buf, data, ARRAY_SIZE(data)); - - bt_le_cs_step_data_parse(&buf, bt_le_cs_step_data_parse_func, NULL); - - zassert_equal(1, bt_le_cs_step_data_parse_func_fake.call_count, "called %d", - bt_le_cs_step_data_parse_func_fake.call_count); -} - -/* - * Test parsing stopped - * - * Constraints: - * - Data contains valid step data - * - Callback function returns false to stop parsing - * - * Expected behaviour: - * - Once parsing is stopped, the callback is not called anymore - */ -ZTEST(bt_le_cs_step_data_parse, test_parsing_stopped) -{ - struct net_buf_simple buf; - uint8_t data[] = { - 0x00, 0x05, 0x01, 0x00, /* mode 0 */ - 0x01, 0x10, 0x02, 0x00, 0x11, /* mode 1 */ - 0x02, 0x11, 0x02, 0x00, 0x11, /* mode 2 */ - }; - - bt_le_cs_step_data_parse_func_fake.return_val = false; - - net_buf_simple_init_with_data(&buf, data, ARRAY_SIZE(data)); - - bt_le_cs_step_data_parse(&buf, bt_le_cs_step_data_parse_func, NULL); - - zassert_equal(1, bt_le_cs_step_data_parse_func_fake.call_count, "called %d", - bt_le_cs_step_data_parse_func_fake.call_count); -} - -struct custom_user_data { - const uint8_t *data; - size_t len; -}; - -static bool bt_le_cs_step_data_parse_func_custom_fake(struct bt_le_cs_subevent_step *step, - void *user_data) -{ - struct custom_user_data *ud = user_data; - - /* mode check */ - zassert_true(ud->len-- > 0); - zassert_equal(step->mode, *ud->data); - ud->data++; - - /* channel check */ - zassert_true(ud->len-- > 0); - zassert_equal(step->channel, *ud->data); - ud->data++; - - /* step data length check */ - zassert_true(ud->len-- > 0); - zassert_equal(step->data_len, *ud->data); - ud->data++; - - /* value check */ - zassert_true(ud->len >= step->data_len); - zassert_mem_equal(step->data, ud->data, step->data_len); - ud->data += step->data_len; - ud->len -= step->data_len; - - return true; -} - -/* - * Test parsing successfully - * - * Constraints: - * - Data contains valid step data - * - Callback function returns false to stop parsing - * - * Expected behaviour: - * - Data passed to the callback match the expected data - */ -ZTEST(bt_le_cs_step_data_parse, test_parsing_success) -{ - struct net_buf_simple buf; - uint8_t data[] = { - 0x00, 0x05, 0x01, 0x00, /* mode 0 */ - 0x03, 0x11, 0x01, 0x11, /* mode 3 */ - 0x02, 0x12, 0x02, 0x00, 0x11, /* mode 2 */ - 0x03, 0x13, 0x01, 0x11, /* mode 3 */ - 0x02, 0x14, 0x02, 0x00, 0x11, /* mode 2 */ - }; - - struct custom_user_data user_data = { - .data = data, - .len = ARRAY_SIZE(data), - }; - - bt_le_cs_step_data_parse_func_fake.custom_fake = bt_le_cs_step_data_parse_func_custom_fake; - - net_buf_simple_init_with_data(&buf, data, ARRAY_SIZE(data)); - - bt_le_cs_step_data_parse(&buf, bt_le_cs_step_data_parse_func, &user_data); - - zassert_equal(5, bt_le_cs_step_data_parse_func_fake.call_count, "called %d", - bt_le_cs_step_data_parse_func_fake.call_count); -} diff --git a/tests/bluetooth/host/cs/bt_le_cs_step_data_parse/testcase.yaml b/tests/bluetooth/host/cs/bt_le_cs_step_data_parse/testcase.yaml deleted file mode 100644 index 2e65668c519c0..0000000000000 --- a/tests/bluetooth/host/cs/bt_le_cs_step_data_parse/testcase.yaml +++ /dev/null @@ -1,7 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.cs.bt_le_cs_step_data_parse: - type: unit diff --git a/tests/bluetooth/host/cs/mocks/CMakeLists.txt b/tests/bluetooth/host/cs/mocks/CMakeLists.txt deleted file mode 100644 index 1ab1a58a1d02c..0000000000000 --- a/tests/bluetooth/host/cs/mocks/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -add_library(mocks STATIC - conn.c - hci_core.c - net_buf.c -) - -target_include_directories(mocks PUBLIC - .. - ${ZEPHYR_BASE}/subsys/bluetooth - ${ZEPHYR_BASE}/subsys/bluetooth/host - ${ZEPHYR_BASE}/tests/bluetooth/host - ${ZEPHYR_BASE}/tests/bluetooth/host/cs/mocks -) - -target_link_libraries(mocks PRIVATE test_interface) diff --git a/tests/bluetooth/host/cs/mocks/conn.c b/tests/bluetooth/host/cs/mocks/conn.c deleted file mode 100644 index 8825b250c7044..0000000000000 --- a/tests/bluetooth/host/cs/mocks/conn.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/conn.h" - -#include - -DEFINE_FAKE_VOID_FUNC(bt_conn_unref, struct bt_conn *); -DEFINE_FAKE_VALUE_FUNC(struct bt_conn *, bt_conn_lookup_handle, uint16_t, enum bt_conn_type); -DEFINE_FAKE_VOID_FUNC(bt_conn_notify_remote_cs_capabilities, struct bt_conn *, - uint8_t, struct bt_conn_le_cs_capabilities *); -DEFINE_FAKE_VOID_FUNC(bt_conn_notify_remote_cs_fae_table, struct bt_conn *, - uint8_t, struct bt_conn_le_cs_fae_table *); -DEFINE_FAKE_VOID_FUNC(bt_conn_notify_cs_config_created, struct bt_conn *, - uint8_t, struct bt_conn_le_cs_config *); -DEFINE_FAKE_VOID_FUNC(bt_conn_notify_cs_config_removed, struct bt_conn *, uint8_t); -DEFINE_FAKE_VOID_FUNC(bt_conn_notify_cs_subevent_result, struct bt_conn *, - struct bt_conn_le_cs_subevent_result *); -DEFINE_FAKE_VOID_FUNC(bt_conn_notify_cs_security_enable_available, struct bt_conn *, uint8_t); -DEFINE_FAKE_VOID_FUNC(bt_conn_notify_cs_procedure_enable_available, struct bt_conn *, - uint8_t, struct bt_conn_le_cs_procedure_enable_complete *); diff --git a/tests/bluetooth/host/cs/mocks/conn.h b/tests/bluetooth/host/cs/mocks/conn.h deleted file mode 100644 index 3ec35814d7b4c..0000000000000 --- a/tests/bluetooth/host/cs/mocks/conn.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -#include - -/* List of fakes used by this unit tester */ -#define CONN_FFF_FAKES_LIST(FAKE) \ - FAKE(bt_conn_unref) \ - FAKE(bt_conn_lookup_handle) \ - FAKE(bt_conn_notify_remote_cs_capabilities) \ - FAKE(bt_conn_notify_cs_config_created) \ - FAKE(bt_conn_notify_cs_config_removed) \ - FAKE(bt_conn_notify_cs_subevent_result) \ - FAKE(bt_conn_notify_cs_security_enable_available) \ - FAKE(bt_conn_notify_cs_procedure_enable_available) \ - FAKE(bt_conn_notify_remote_cs_fae_table) - -DECLARE_FAKE_VOID_FUNC(bt_conn_unref, struct bt_conn *); -DECLARE_FAKE_VALUE_FUNC(struct bt_conn *, bt_conn_lookup_handle, uint16_t, enum bt_conn_type); -DECLARE_FAKE_VOID_FUNC(bt_conn_notify_remote_cs_capabilities, struct bt_conn *, - uint8_t, struct bt_conn_le_cs_capabilities *); -DECLARE_FAKE_VOID_FUNC(bt_conn_notify_remote_cs_fae_table, struct bt_conn *, - uint8_t, struct bt_conn_le_cs_fae_table *); -DECLARE_FAKE_VOID_FUNC(bt_conn_notify_cs_config_created, struct bt_conn *, - uint8_t, struct bt_conn_le_cs_config *); -DECLARE_FAKE_VOID_FUNC(bt_conn_notify_cs_config_removed, struct bt_conn *, uint8_t); -DECLARE_FAKE_VOID_FUNC(bt_conn_notify_cs_subevent_result, struct bt_conn *, - struct bt_conn_le_cs_subevent_result *); -DECLARE_FAKE_VOID_FUNC(bt_conn_notify_cs_security_enable_available, struct bt_conn *, uint8_t); -DECLARE_FAKE_VOID_FUNC(bt_conn_notify_cs_procedure_enable_available, struct bt_conn *, - uint8_t, struct bt_conn_le_cs_procedure_enable_complete *); diff --git a/tests/bluetooth/host/cs/mocks/hci_core.c b/tests/bluetooth/host/cs/mocks/hci_core.c deleted file mode 100644 index cb5bbd4acbd77..0000000000000 --- a/tests/bluetooth/host/cs/mocks/hci_core.c +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/hci_core.h" - -#include -#include - -DEFINE_FAKE_VALUE_FUNC(struct net_buf *, bt_hci_cmd_alloc, k_timeout_t); -DEFINE_FAKE_VALUE_FUNC(int, bt_hci_cmd_send_sync, uint16_t, struct net_buf *, struct net_buf **); diff --git a/tests/bluetooth/host/cs/mocks/hci_core.h b/tests/bluetooth/host/cs/mocks/hci_core.h deleted file mode 100644 index f754a111d6cbc..0000000000000 --- a/tests/bluetooth/host/cs/mocks/hci_core.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -/* List of fakes used by this unit tester */ -#define HCI_CORE_FFF_FAKES_LIST(FAKE) \ - FAKE(bt_hci_cmd_alloc) \ - FAKE(bt_hci_cmd_send_sync) - -DECLARE_FAKE_VALUE_FUNC(struct net_buf *, bt_hci_cmd_alloc, k_timeout_t); -DECLARE_FAKE_VALUE_FUNC(int, bt_hci_cmd_send_sync, uint16_t, struct net_buf *, struct net_buf **); diff --git a/tests/bluetooth/host/cs/mocks/net_buf.c b/tests/bluetooth/host/cs/mocks/net_buf.c deleted file mode 100644 index 22ceb93a25e5a..0000000000000 --- a/tests/bluetooth/host/cs/mocks/net_buf.c +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -#include "mocks/net_buf.h" - -const struct net_buf_data_cb net_buf_fixed_cb; - -DEFINE_FAKE_VOID_FUNC(net_buf_unref, struct net_buf *); -DEFINE_FAKE_VOID_FUNC(net_buf_reset, struct net_buf *); -DEFINE_FAKE_VOID_FUNC(net_buf_slist_put, sys_slist_t *, struct net_buf *); -DEFINE_FAKE_VALUE_FUNC(struct net_buf *, net_buf_alloc_fixed, struct net_buf_pool *, k_timeout_t); diff --git a/tests/bluetooth/host/cs/mocks/net_buf.h b/tests/bluetooth/host/cs/mocks/net_buf.h deleted file mode 100644 index 14437d3d158c1..0000000000000 --- a/tests/bluetooth/host/cs/mocks/net_buf.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -/* List of fakes used by this unit tester */ -#define NET_BUF_FFF_FAKES_LIST(FAKE) \ - FAKE(net_buf_unref) \ - FAKE(net_buf_reset) \ - FAKE(net_buf_slist_put) \ - FAKE(net_buf_alloc_fixed) - -DECLARE_FAKE_VOID_FUNC(net_buf_unref, struct net_buf *); -DECLARE_FAKE_VOID_FUNC(net_buf_reset, struct net_buf *); -DECLARE_FAKE_VOID_FUNC(net_buf_slist_put, sys_slist_t *, struct net_buf *); -DECLARE_FAKE_VALUE_FUNC(struct net_buf *, net_buf_alloc_fixed, struct net_buf_pool *, k_timeout_t); diff --git a/tests/bluetooth/host/data/bt_data_parse/CMakeLists.txt b/tests/bluetooth/host/data/bt_data_parse/CMakeLists.txt deleted file mode 100644 index 96be82d20f725..0000000000000 --- a/tests/bluetooth/host/data/bt_data_parse/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -find_package(Zephyr COMPONENTS unittest HINTS $ENV{ZEPHYR_BASE}) - -project(bt_data_parse) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) - -target_link_libraries(testbinary PRIVATE host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/data.c - ${ZEPHYR_BASE}/lib/net_buf/buf_simple.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -) diff --git a/tests/bluetooth/host/data/bt_data_parse/prj.conf b/tests/bluetooth/host/data/bt_data_parse/prj.conf deleted file mode 100644 index 432d8998c06d1..0000000000000 --- a/tests/bluetooth/host/data/bt_data_parse/prj.conf +++ /dev/null @@ -1,6 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y -CONFIG_NET_BUF=y diff --git a/tests/bluetooth/host/data/bt_data_parse/src/main.c b/tests/bluetooth/host/data/bt_data_parse/src/main.c deleted file mode 100644 index c25af6d40458f..0000000000000 --- a/tests/bluetooth/host/data/bt_data_parse/src/main.c +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright (c) 2023 Codecoup - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -DEFINE_FFF_GLOBALS; - -FAKE_VALUE_FUNC(bool, bt_data_parse_func, struct bt_data *, void *); - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - RESET_FAKE(bt_data_parse_func); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(bt_data_parse, NULL, NULL, NULL, NULL, NULL); - -/* - * Test empty data buffer - * - * Constraints: - * - data.len set to 0 - * - * Expected behaviour: - * - Callback function is not called - */ -ZTEST(bt_data_parse, test_parsing_empty_buf) -{ - struct net_buf_simple *buf = NET_BUF_SIMPLE(0); - - bt_data_parse(buf, bt_data_parse_func, NULL); - - zassert_equal(bt_data_parse_func_fake.call_count, 0); -} - -/* - * Test AD Structure invalid length - * - * Constraints: - * - AD Structure N length > number of bytes after - * - * Expected behaviour: - * - Callback function is called N - 1 times - */ -ZTEST(bt_data_parse, test_parsing_invalid_length) -{ - struct net_buf_simple buf; - uint8_t data[] = { - /* Significant part */ - 0x02, 0x01, 0x00, /* AD Structure 1 */ - 0x03, 0x02, 0x01, 0x00, /* AD Structure 2 */ - /* Invalid length 0xff */ - 0xff, 0x03, 0x02, 0x01, /* AD Structure N */ - 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, /* AD Structure N + 1 */ - }; - - bt_data_parse_func_fake.return_val = true; - - net_buf_simple_init_with_data(&buf, data, ARRAY_SIZE(data)); - - bt_data_parse(&buf, bt_data_parse_func, NULL); - - zassert_equal(2, bt_data_parse_func_fake.call_count, - "called %d", bt_data_parse_func_fake.call_count); -} - -/* - * Test early termination of the significant part - * - * Constraints: - * - The significant part contains a sequence of N AD structures - * - The non-significant part extends the data with all-zero octets - * - * Expected behaviour: - * - Callback function is called N times - */ -ZTEST(bt_data_parse, test_parsing_early_termination) -{ - struct net_buf_simple buf; - uint8_t data[] = { - /* Significant part */ - 0x02, 0x01, 0x00, /* AD Structure 1 */ - 0x03, 0x02, 0x01, 0x00, /* AD Structure 2 */ - 0x04, 0x03, 0x02, 0x01, 0x00, /* AD Structure 3 */ - /* Non-significant part */ - 0x00, 0x00, 0x00, 0x00, 0x00 - }; - - bt_data_parse_func_fake.return_val = true; - - net_buf_simple_init_with_data(&buf, data, ARRAY_SIZE(data)); - - bt_data_parse(&buf, bt_data_parse_func, NULL); - - zassert_equal(3, bt_data_parse_func_fake.call_count, - "called %d", bt_data_parse_func_fake.call_count); -} - -/* - * Test parsing stopped - * - * Constraints: - * - Data contains valid AD Structures - * - Callback function returns false to stop parsing - * - * Expected behaviour: - * - Once parsing is stopped, the callback is not called anymore - */ -ZTEST(bt_data_parse, test_parsing_stopped) -{ - struct net_buf_simple buf; - uint8_t data[] = { - /* Significant part */ - 0x02, 0x01, 0x00, /* AD Structure 1 */ - 0x03, 0x02, 0x01, 0x00, /* AD Structure 2 */ - }; - - bt_data_parse_func_fake.return_val = false; - - net_buf_simple_init_with_data(&buf, data, ARRAY_SIZE(data)); - - bt_data_parse(&buf, bt_data_parse_func, NULL); - - zassert_equal(1, bt_data_parse_func_fake.call_count, - "called %d", bt_data_parse_func_fake.call_count); -} - -struct custom_fake_user_data { - const uint8_t *data; - size_t len; -}; - -static bool bt_data_parse_func_custom_fake(struct bt_data *data, - void *user_data) -{ - struct custom_fake_user_data *ud = user_data; - - /* length check */ - zassert_true(ud->len-- > 0); - zassert_equal(data->data_len, *ud->data - 1); - ud->data++; - - /* type check */ - zassert_true(ud->len-- > 0); - zassert_equal(data->type, *ud->data); - ud->data++; - - /* value check */ - zassert_true(ud->len >= data->data_len); - zassert_mem_equal(data->data, ud->data, data->data_len); - ud->data += data->data_len; - ud->len -= data->data_len; - - return true; -} - -/* - * Test parsing AD Data - * - * Constraints: - * - Data contains valid AD Structures - * - Callback function returns false to stop parsing - * - * Expected behaviour: - * - Data passed to the callback match the expected data - */ -ZTEST(bt_data_parse, test_parsing_success) -{ - struct net_buf_simple buf; - uint8_t data[] = { - /* Significant part */ - 0x02, 0x01, 0x00, /* AD Structure 1 */ - 0x03, 0x02, 0x01, 0x00, /* AD Structure 2 */ - }; - struct custom_fake_user_data user_data = { - .data = data, - .len = ARRAY_SIZE(data), - }; - - bt_data_parse_func_fake.custom_fake = bt_data_parse_func_custom_fake; - - net_buf_simple_init_with_data(&buf, data, ARRAY_SIZE(data)); - - bt_data_parse(&buf, bt_data_parse_func, &user_data); - - zassert_equal(2, bt_data_parse_func_fake.call_count, - "called %d", bt_data_parse_func_fake.call_count); -} diff --git a/tests/bluetooth/host/data/bt_data_parse/testcase.yaml b/tests/bluetooth/host/data/bt_data_parse/testcase.yaml deleted file mode 100644 index 2f247a5a3a987..0000000000000 --- a/tests/bluetooth/host/data/bt_data_parse/testcase.yaml +++ /dev/null @@ -1,7 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_data_parse: - type: unit diff --git a/tests/bluetooth/host/host_mocks/assert.c b/tests/bluetooth/host/host_mocks/assert.c deleted file mode 100644 index ac4df1671790e..0000000000000 --- a/tests/bluetooth/host/host_mocks/assert.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "host_mocks/assert.h" - -DEFINE_FAKE_VALUE_FUNC(bool, mock_check_if_assert_expected); - -void assert_print(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vprintk(fmt, ap); - va_end(ap); -} - -void assert_post_action(const char *file, unsigned int line) -{ - /* ztest_test_pass()/ztest_test_fail() are used to stop the execution - * If this is an unexpected assert (i.e. not following expect_assert()) - * calling mock_check_if_assert_expected() will return 'false' as - * a default return value - */ - if (mock_check_if_assert_expected() == true) { - printk("Assertion expected as part of a test case.\n"); - /* Mark the test as passed and stop execution: - * Needed in the passing scenario to prevent undefined behavior after hitting the - * assert. In real builds (non-UT), the system will be halted by the assert. - */ - ztest_test_pass(); - } else { - /* Mark the test as failed and stop execution */ - ztest_test_fail(); - } -} diff --git a/tests/bluetooth/host/host_mocks/assert.h b/tests/bluetooth/host/host_mocks/assert.h deleted file mode 100644 index 7c2b11b8393d5..0000000000000 --- a/tests/bluetooth/host/host_mocks/assert.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -/* List of fakes used by this unit tester */ -#define ASSERT_FFF_FAKES_LIST(FAKE) \ - FAKE(mock_check_if_assert_expected) \ - -DECLARE_FAKE_VALUE_FUNC(bool, mock_check_if_assert_expected); - -#define expect_assert() (mock_check_if_assert_expected_fake.return_val = 1) diff --git a/tests/bluetooth/host/id/bt_br_oob_get_local/CMakeLists.txt b/tests/bluetooth/host/id/bt_br_oob_get_local/CMakeLists.txt deleted file mode 100644 index 27e8bd0bf07fb..0000000000000 --- a/tests/bluetooth/host/id/bt_br_oob_get_local/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -project(bt_br_oob_get_local) - -# Suppress the format-zero-length error if GNUC is used -if (CMAKE_C_COMPILER_ID MATCHES "GNU") -add_compile_options(-Wno-error=format-zero-length -Wno-format-zero-length) -endif() - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_invalid_inputs.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/id.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -) diff --git a/tests/bluetooth/host/id/bt_br_oob_get_local/prj.conf b/tests/bluetooth/host/id/bt_br_oob_get_local/prj.conf deleted file mode 100644 index d895ea85bb75d..0000000000000 --- a/tests/bluetooth/host/id/bt_br_oob_get_local/prj.conf +++ /dev/null @@ -1,10 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_CLASSIC=y -CONFIG_BT_SMP=y -CONFIG_BT_ID_MAX=4 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/id/bt_br_oob_get_local/src/main.c b/tests/bluetooth/host/id/bt_br_oob_get_local/src/main.c deleted file mode 100644 index 50c5bb142fa58..0000000000000 --- a/tests/bluetooth/host/id/bt_br_oob_get_local/src/main.c +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include - -DEFINE_FFF_GLOBALS; - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(bt_br_oob_get_local, NULL, NULL, NULL, NULL, NULL); - -/* - * Get BR/EDR local Out Of Band information - * - * Constraints: - * - Use a valid reference - * - * Expected behaviour: - * - Address is copied to the passed OOB reference - */ -ZTEST(bt_br_oob_get_local, test_get_local_out_of_band_information) -{ - int err; - struct bt_br_oob oob; - - bt_addr_le_copy(&bt_dev.id_addr[0], BT_RPA_LE_ADDR); - - err = bt_br_oob_get_local(&oob); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_mem_equal(&oob.addr, &BT_RPA_LE_ADDR->a, sizeof(bt_addr_t), - "Incorrect address was set"); -} diff --git a/tests/bluetooth/host/id/bt_br_oob_get_local/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/id/bt_br_oob_get_local/src/test_suite_invalid_inputs.c deleted file mode 100644 index 350c61b5d2110..0000000000000 --- a/tests/bluetooth/host/id/bt_br_oob_get_local/src/test_suite_invalid_inputs.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include - -ZTEST_SUITE(bt_br_oob_get_local_invalid_inputs, NULL, NULL, NULL, NULL, NULL); - -/* - * Test passing NULL reference for the OOB reference argument - * - * Constraints: - * - NULL reference is used as an argument for the OOB reference - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_br_oob_get_local_invalid_inputs, test_null_oob_reference) -{ - expect_assert(); - bt_br_oob_get_local(NULL); -} diff --git a/tests/bluetooth/host/id/bt_br_oob_get_local/testcase.yaml b/tests/bluetooth/host/id/bt_br_oob_get_local/testcase.yaml deleted file mode 100644 index 0612c34596ede..0000000000000 --- a/tests/bluetooth/host/id/bt_br_oob_get_local/testcase.yaml +++ /dev/null @@ -1,7 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_br_oob_get_local.default: - type: unit diff --git a/tests/bluetooth/host/id/bt_id_add/CMakeLists.txt b/tests/bluetooth/host/id/bt_id_add/CMakeLists.txt deleted file mode 100644 index 57bf0b2729e62..0000000000000 --- a/tests/bluetooth/host/id/bt_id_add/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -project(bt_id_add) - -# Suppress the format-zero-length error if GNUC is used -if (CMAKE_C_COMPILER_ID MATCHES "GNU") -add_compile_options(-Wno-error=format-zero-length -Wno-format-zero-length) -endif() - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_invalid_inputs.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/id.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -) diff --git a/tests/bluetooth/host/id/bt_id_add/prj.conf b/tests/bluetooth/host/id/bt_id_add/prj.conf deleted file mode 100644 index 82e46bfe20fff..0000000000000 --- a/tests/bluetooth/host/id/bt_id_add/prj.conf +++ /dev/null @@ -1,9 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_SMP=y -CONFIG_BT_ID_MAX=2 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/id/bt_id_add/src/main.c b/tests/bluetooth/host/id/bt_id_add/src/main.c deleted file mode 100644 index 840dc2bd0343d..0000000000000 --- a/tests/bluetooth/host/id/bt_id_add/src/main.c +++ /dev/null @@ -1,340 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/adv.h" -#include "mocks/adv_expects.h" -#include "mocks/conn.h" -#include "mocks/conn_expects.h" -#include "mocks/hci_core.h" -#include "mocks/hci_core_expects.h" -#include "mocks/net_buf.h" -#include "mocks/net_buf_expects.h" -#include "mocks/scan.h" -#include "mocks/scan_expects.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include -#include - -DEFINE_FFF_GLOBALS; - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - - ADV_FFF_FAKES_LIST(RESET_FAKE); - CONN_FFF_FAKES_LIST(RESET_FAKE); - NET_BUF_FFF_FAKES_LIST(RESET_FAKE); - HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(bt_id_add, NULL, NULL, NULL, NULL, NULL); - -/* - * Test adding key to the resolving list when size of the controller resolving list is zero - * - * Constraints: - * - bt_dev.le.rl_size is set to 0 - * - * Expected behaviour: - * - Passed key state is updated by setting 'BT_KEYS_ID_ADDED' bit - */ -ZTEST(bt_id_add, test_zero_controller_list_size) -{ - struct bt_keys keys = {0}; - uint8_t expected_rl_entries; - - bt_dev.le.rl_size = 0; - bt_dev.le.rl_entries = 0; - expected_rl_entries = bt_dev.le.rl_entries + 1; - - bt_id_add(&keys); - - expect_not_called_bt_conn_lookup_state_le(); - - zassert_equal(expected_rl_entries, bt_dev.le.rl_entries, "Incorrect entries count"); - zassert_true((keys.state & BT_KEYS_ID_ADDED) == BT_KEYS_ID_ADDED, "Incorrect key state"); -} - -/* - * Test adding key to the resolving list when host side resolving is used - * - * Constraints: - * - bt_dev.le.rl_size is set to a value greater than 0 - * - 'bt_dev.le.rl_entries > bt_dev.le.rl_size' condition is true - * - * Expected behaviour: - * - Passed key state is updated by setting 'BT_KEYS_ID_ADDED' bit - */ -ZTEST(bt_id_add, test_host_side_resolving_used) -{ - struct bt_keys keys = {0}; - uint8_t expected_rl_entries; - - bt_dev.le.rl_size = 1; - bt_dev.le.rl_entries = 2; - expected_rl_entries = bt_dev.le.rl_entries + 1; - - bt_id_add(&keys); - - expect_not_called_bt_conn_lookup_state_le(); - - zassert_equal(expected_rl_entries, bt_dev.le.rl_entries, "Incorrect entries count"); - zassert_true((keys.state & BT_KEYS_ID_ADDED) == BT_KEYS_ID_ADDED, "Incorrect key state"); -} - -/* - * Test adding key to the resolving list if host side resolving isn't used. - * bt_conn_lookup_state_le() returns a valid connection reference. - * - * Constraints: - * - bt_dev.le.rl_size is set to a value greater than 0 - * - 'bt_dev.le.rl_entries > bt_dev.le.rl_size' condition is false - * - bt_conn_lookup_state_le() returns a valid connection reference. - * - * Expected behaviour: - * - Passed key state is updated by setting 'BT_KEYS_ID_PENDING_ADD' bit - * - 'BT_DEV_ID_PENDING' in bt_dev.flags is set - */ -ZTEST(bt_id_add, test_conn_lookup_returns_valid_conn_ref) -{ - struct bt_keys keys = {0}; - struct bt_conn conn_ref = {0}; - - /* Break the host-side resolving condition */ - bt_dev.le.rl_size = 1; - bt_dev.le.rl_entries = 1; - - bt_conn_lookup_state_le_fake.return_val = &conn_ref; - - bt_id_add(&keys); - - expect_single_call_bt_conn_lookup_state_le(BT_ID_DEFAULT, NULL, BT_CONN_INITIATING); - expect_single_call_bt_conn_unref(&conn_ref); - - zassert_true((keys.state & BT_KEYS_ID_PENDING_ADD) == BT_KEYS_ID_PENDING_ADD, - "Incorrect key state"); - zassert_true(atomic_test_bit(bt_dev.flags, BT_DEV_ID_PENDING), - "Flags were not correctly set"); -} - -void bt_le_ext_adv_foreach_custom_fake(void (*func)(struct bt_le_ext_adv *adv, void *data), - void *data) -{ - struct bt_le_ext_adv adv_params = {0}; - - __ASSERT_NO_MSG(func != NULL); - __ASSERT_NO_MSG(data != NULL); - - atomic_set_bit(adv_params.flags, BT_ADV_ENABLED); - atomic_set_bit(adv_params.flags, BT_ADV_LIMITED); - - func(&adv_params, data); -} - -/* - * Test adding key to the resolving list if host side resolving isn't used. - * bt_conn_lookup_state_le() returns a NULL connection reference and 'CONFIG_BT_BROADCASTER' and - * 'CONFIG_BT_EXT_ADV' are enabled. - * - * Constraints: - * - bt_dev.le.rl_size is set to a value greater than 0 - * - 'bt_dev.le.rl_entries > bt_dev.le.rl_size' condition is false - * - bt_conn_lookup_state_le() returns NULL. - * - 'CONFIG_BT_BROADCASTER' and 'CONFIG_BT_EXT_ADV' are enabled. - * - adv_is_limited_enabled() sets advertise enable flag to true - * - * Expected behaviour: - * - Passed key state is updated by setting 'BT_KEYS_ID_PENDING_ADD' bit and 'BT_DEV_ID_PENDING' - * in bt_dev.flags is set if advertising is enabled - */ -ZTEST(bt_id_add, test_conn_lookup_returns_null_broadcaster_ext_adv_enabled) -{ - struct bt_keys keys = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_EXT_ADV); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_BROADCASTER); - - /* Break the host-side resolving condition */ - bt_dev.le.rl_size = 1; - bt_dev.le.rl_entries = 1; - - bt_conn_lookup_state_le_fake.return_val = NULL; - - /* When bt_le_ext_adv_foreach() is called, this callback will be triggered and causes - * adv_is_limited_enabled() to set the advertising enable flag to true. - */ - bt_le_ext_adv_foreach_fake.custom_fake = bt_le_ext_adv_foreach_custom_fake; - - bt_id_add(&keys); - - expect_single_call_bt_le_ext_adv_foreach(); - - zassert_true((keys.state & BT_KEYS_ID_PENDING_ADD) == BT_KEYS_ID_PENDING_ADD, - "Incorrect key state"); - zassert_true(atomic_test_bit(bt_dev.flags, BT_DEV_ID_PENDING), - "Flags were not correctly set"); -} - -/* - * Test adding key to the resolving list if host side resolving isn't used. - * bt_conn_lookup_state_le() returns a NULL connection reference. - * 'CONFIG_BT_BROADCASTER' is enabled while 'CONFIG_BT_EXT_ADV' isn't enabled. - * - * Constraints: - * - bt_dev.le.rl_size is set to a value greater than 0 - * - bt_dev.le.rl_entries equals bt_dev.le.rl_size - * - bt_conn_lookup_state_le() returns NULL. - * - 'CONFIG_BT_BROADCASTER' is enabled. - * - 'CONFIG_BT_EXT_ADV' isn't enabled. - * - * Expected behaviour: - * - Passed key state is updated by setting 'BT_KEYS_ID_ADDED' bit - */ -ZTEST(bt_id_add, test_conn_lookup_returns_null_broadcaster_no_ext_adv) -{ - struct bt_keys keys = {0}; - struct net_buf net_buff = {0}; - uint8_t expected_rl_entries; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_EXT_ADV); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_BROADCASTER); - - /* Break the host-side resolving condition */ - bt_dev.le.rl_size = 1; - bt_dev.le.rl_entries = 1; - expected_rl_entries = bt_dev.le.rl_entries + 1; - - bt_conn_lookup_state_le_fake.return_val = NULL; - - /* This makes addr_res_enable() succeeds and returns 0 */ - bt_hci_cmd_alloc_fake.return_val = &net_buff; - bt_hci_cmd_send_sync_fake.return_val = 0; - - bt_id_add(&keys); - - zassert_equal(expected_rl_entries, bt_dev.le.rl_entries, "Incorrect entries count"); - zassert_true((keys.state & BT_KEYS_ID_ADDED) == BT_KEYS_ID_ADDED, "Incorrect key state"); -} - -/* - * Test adding key to the resolving list if host side resolving isn't used. - * bt_conn_lookup_state_le() returns a NULL connection reference. - * Number of entries in the resolving list is 0. - * 'CONFIG_BT_BROADCASTER' is enabled while 'CONFIG_BT_EXT_ADV' isn't enabled. - * - * Constraints: - * - bt_dev.le.rl_size is set to a value greater than 0 - * - bt_dev.le.rl_entries is set to 0 - * - bt_conn_lookup_state_le() returns NULL. - * - 'CONFIG_BT_BROADCASTER' is enabled. - * - 'CONFIG_BT_EXT_ADV' isn't enabled. - * - * Expected behaviour: - * - Passed key state is updated by setting 'BT_KEYS_ID_ADDED' bit - */ -ZTEST(bt_id_add, test_conn_lookup_returns_null_no_ext_adv_no_resolving_entries) -{ - struct bt_keys keys = {0}; - struct net_buf net_buff = {0}; - struct bt_hci_cp_le_add_dev_to_rl cp = {0}; - uint8_t expected_rl_entries; - uint8_t zero_irk[16] = {0}; - uint8_t testing_irk_value[16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15}; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_EXT_ADV); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_BROADCASTER); - - bt_addr_le_copy(&keys.addr, BT_RPA_LE_ADDR); - memcpy(keys.irk.val, testing_irk_value, 16); - - /* Break the host-side resolving condition */ - bt_dev.le.rl_size = 1; - bt_dev.le.rl_entries = 0; - expected_rl_entries = bt_dev.le.rl_entries + 1; - - bt_conn_lookup_state_le_fake.return_val = NULL; - - /* This makes hci_id_add() succeeds and returns 0 */ - net_buf_simple_add_fake.return_val = &cp; - bt_hci_cmd_alloc_fake.return_val = &net_buff; - bt_hci_cmd_send_sync_fake.return_val = 0; - - bt_id_add(&keys); - - /* This verifies hci_id_add() behaviour */ - expect_single_call_net_buf_simple_add(&net_buff.b, sizeof(cp)); - zassert_mem_equal(&cp.peer_id_addr, BT_RPA_LE_ADDR, sizeof(bt_addr_le_t), - "Incorrect address was set"); - zassert_mem_equal(cp.peer_irk, testing_irk_value, sizeof(testing_irk_value), - "Incorrect IRK value was set"); - zassert_mem_equal(cp.local_irk, zero_irk, sizeof(zero_irk), "Incorrect IRK value was set"); - - zassert_equal(expected_rl_entries, bt_dev.le.rl_entries, "Incorrect entries count"); - zassert_true((keys.state & BT_KEYS_ID_ADDED) == BT_KEYS_ID_ADDED, "Incorrect key state"); -} - -/* - * Test stopping scanning procedure if it is currently active and re-enable it after updating keys. - * If it is active, it is disabled then re-enabled after updating the key status. - * bt_conn_lookup_state_le() returns a NULL connection reference. - * 'CONFIG_BT_BROADCASTER', 'CONFIG_BT_OBSERVER' and 'CONFIG_BT_EXT_ADV' are enabled. - * - * Constraints: - * - bt_dev.le.rl_size is set to a value greater than 0 - * - bt_dev.le.rl_entries is set to 0 - * - bt_conn_lookup_state_le() returns NULL. - * - 'CONFIG_BT_BROADCASTER' is enabled. - * - 'CONFIG_BT_OBSERVER' is enabled. - * - 'CONFIG_BT_EXT_ADV' is enabled. - * - * Expected behaviour: - * - Passed key state is updated by setting 'BT_KEYS_ID_ADDED' bit - */ -ZTEST(bt_id_add, test_scan_re_enabled_observer_enabled_ext_adv) -{ - struct bt_keys keys = {0}; - struct net_buf net_buff = {0}; - struct bt_hci_cp_le_add_dev_to_rl cp = {0}; - uint8_t expected_args_history[] = {BT_HCI_LE_SCAN_DISABLE, BT_HCI_LE_SCAN_ENABLE}; - uint8_t expected_rl_entries; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_EXT_ADV); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_OBSERVER); - - /* Break the host-side resolving condition */ - bt_dev.le.rl_size = 1; - bt_dev.le.rl_entries = 0; - expected_rl_entries = bt_dev.le.rl_entries + 1; - - /* Make scan enabled flag true */ - atomic_set_bit(bt_dev.flags, BT_DEV_SCANNING); - atomic_set_bit(bt_dev.flags, BT_DEV_SCAN_LIMITED); - - bt_conn_lookup_state_le_fake.return_val = NULL; - - /* This makes hci_id_add() succeeds and returns 0 */ - net_buf_simple_add_fake.return_val = &cp; - bt_hci_cmd_alloc_fake.return_val = &net_buff; - bt_hci_cmd_send_sync_fake.return_val = 0; - - bt_id_add(&keys); - - expect_call_count_bt_le_scan_set_enable(2, expected_args_history); - - zassert_equal(expected_rl_entries, bt_dev.le.rl_entries, "Incorrect entries count"); - zassert_true((keys.state & BT_KEYS_ID_ADDED) == BT_KEYS_ID_ADDED, "Incorrect key state"); - zassert_true((keys.state & BT_KEYS_ID_PENDING_ADD) == BT_KEYS_ID_PENDING_ADD, - "Incorrect key state"); -} diff --git a/tests/bluetooth/host/id/bt_id_add/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/id/bt_id_add/src/test_suite_invalid_inputs.c deleted file mode 100644 index e7f9671b076e1..0000000000000 --- a/tests/bluetooth/host/id/bt_id_add/src/test_suite_invalid_inputs.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" - -#include -#include -#include - -#include -#include -#include - -ZTEST_SUITE(bt_id_add_invalid_inputs, NULL, NULL, NULL, NULL, NULL); - -/* - * Test passing NULL value for keys reference - * - * Constraints: - * - Keys reference is passed as NULL - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_id_add_invalid_inputs, test_null_keys_ref) -{ - expect_assert(); - bt_id_add(NULL); -} diff --git a/tests/bluetooth/host/id/bt_id_add/testcase.yaml b/tests/bluetooth/host/id/bt_id_add/testcase.yaml deleted file mode 100644 index 8c708256a3b2f..0000000000000 --- a/tests/bluetooth/host/id/bt_id_add/testcase.yaml +++ /dev/null @@ -1,22 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_id_add.default: - type: unit - bluetooth.host.bt_id_add.broadcaster_ext_adv_enabled: - type: unit - extra_configs: - - CONFIG_BT_EXT_ADV=y - - CONFIG_BT_BROADCASTER=y - bluetooth.host.bt_id_add.broadcaster_no_ext_adv: - type: unit - extra_configs: - - CONFIG_BT_BROADCASTER=y - bluetooth.host.bt_id_add.observer_ext_adv: - type: unit - extra_configs: - - CONFIG_BT_EXT_ADV=y - - CONFIG_BT_OBSERVER=y - - CONFIG_BT_BROADCASTER=y diff --git a/tests/bluetooth/host/id/bt_id_adv_random_addr_check/CMakeLists.txt b/tests/bluetooth/host/id/bt_id_adv_random_addr_check/CMakeLists.txt deleted file mode 100644 index 83c5120962533..0000000000000 --- a/tests/bluetooth/host/id/bt_id_adv_random_addr_check/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -project(bt_id_adv_random_addr_check) - -# Suppress the format-zero-length error if GNUC is used -if (CMAKE_C_COMPILER_ID MATCHES "GNU") -add_compile_options(-Wno-error=format-zero-length -Wno-format-zero-length) -endif() - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_invalid_inputs.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/id.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -) diff --git a/tests/bluetooth/host/id/bt_id_adv_random_addr_check/prj.conf b/tests/bluetooth/host/id/bt_id_adv_random_addr_check/prj.conf deleted file mode 100644 index 3de82617e4006..0000000000000 --- a/tests/bluetooth/host/id/bt_id_adv_random_addr_check/prj.conf +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_ID_MAX=2 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/id/bt_id_adv_random_addr_check/src/main.c b/tests/bluetooth/host/id/bt_id_adv_random_addr_check/src/main.c deleted file mode 100644 index a8a1e6e8c3e25..0000000000000 --- a/tests/bluetooth/host/id/bt_id_adv_random_addr_check/src/main.c +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/adv.h" -#include "mocks/adv_expects.h" - -#include -#include -#include - -#include -#include - -DEFINE_FFF_GLOBALS; - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - - ADV_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(bt_id_adv_random_addr_check, NULL, NULL, NULL, NULL, NULL); - -/* - * Test checking advertising random address if observer role isn't enabled - * - * Constraints: - * - 'CONFIG_BT_OBSERVER' isn't enabled - * - * Expected behaviour: - * - bt_id_adv_random_addr_check() returns true - */ -ZTEST(bt_id_adv_random_addr_check, test_check_returns_true_observer_role_not_supported) -{ - bool result; - struct bt_le_adv_param adv_param = {0}; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_OBSERVER); - - result = bt_id_adv_random_addr_check(&adv_param); - - zassert_true(result, "Incorrect result was returned"); -} - -/* - * Test checking scan random address if extended advertising is enabled - * - * Constraints: - * - 'CONFIG_BT_EXT_ADV' is enabled - * - * Expected behaviour: - * - bt_id_scan_random_addr_check() returns true - */ -ZTEST(bt_id_adv_random_addr_check, test_check_returns_true_ext_adv_enabled) -{ - bool result; - struct bt_le_adv_param adv_param = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_EXT_ADV); - - result = bt_id_adv_random_addr_check(&adv_param); - - zassert_true(result, "Incorrect result was returned"); -} - -/* - * Test checking advertising random address when scanner roles aren't active so that - * 'BT_DEV_INITIATING' and 'BT_DEV_SCANNING' aren't set in bt_dev.flags - * - * Constraints: - * - 'CONFIG_BT_OBSERVER' is enabled - * - 'CONFIG_BT_EXT_ADV' isn't enabled - * - 'BT_DEV_INITIATING' and 'BT_DEV_SCANNING' aren't set in bt_dev.flags - * - * Expected behaviour: - * - bt_id_scan_random_addr_check() returns true - */ -ZTEST(bt_id_adv_random_addr_check, test_scanner_roles_not_active) -{ - bool result; - struct bt_le_adv_param adv_param; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_OBSERVER); - Z_TEST_SKIP_IFDEF(CONFIG_BT_EXT_ADV); - - atomic_clear_bit(bt_dev.flags, BT_DEV_INITIATING); - atomic_clear_bit(bt_dev.flags, BT_DEV_SCANNING); - - result = bt_id_adv_random_addr_check(&adv_param); - - zassert_true(result, "Incorrect result was returned"); -} - -/* - * Test that advertiser cannot start with random static identity or - * using an RPA generated for a different identity than scanner roles when privacy is enabled - * - * Constraints: - * - 'CONFIG_BT_PRIVACY' is enabled - * - 'CONFIG_BT_OBSERVER' is enabled - * - 'CONFIG_BT_EXT_ADV' isn't enabled - * - * Expected behaviour: - * - bt_id_scan_random_addr_check() returns false - */ -ZTEST(bt_id_adv_random_addr_check, test_check_returns_false_scanner_uses_random_identity) -{ - bool result; - struct bt_le_adv_param adv_param = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_OBSERVER); - Z_TEST_SKIP_IFDEF(CONFIG_BT_EXT_ADV); - - atomic_set_bit(bt_dev.flags, BT_DEV_INITIATING); - atomic_set_bit(bt_dev.flags, BT_DEV_SCANNING); - - adv_param.options |= BT_LE_ADV_OPT_USE_IDENTITY; - bt_dev.id_addr[adv_param.id].type = BT_ADDR_LE_RANDOM; - - result = bt_id_adv_random_addr_check(&adv_param); - - zassert_false(result, "Incorrect result was returned"); -} - -/* - * Test that advertiser cannot start with random static identity or using an RPA generated for - * a different identity than scanner roles while 'CONFIG_BT_PRIVACY' isn't enabled and - * 'CONFIG_BT_SCAN_WITH_IDENTITY' is enabled - * - * Constraints: - * - 'CONFIG_BT_SCAN_WITH_IDENTITY' is enabled - * - 'CONFIG_BT_PRIVACY' isn't enabled - * - 'CONFIG_BT_OBSERVER' is enabled - * - 'CONFIG_BT_EXT_ADV' isn't enabled - * - * Expected behaviour: - * - bt_id_scan_random_addr_check() returns false - */ -ZTEST(bt_id_adv_random_addr_check, test_check_returns_false_advertise_with_local_identity) -{ - bool result; - struct bt_le_adv_param adv_param = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_SCAN_WITH_IDENTITY); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_OBSERVER); - Z_TEST_SKIP_IFDEF(CONFIG_BT_EXT_ADV); - - atomic_set_bit(bt_dev.flags, BT_DEV_SCANNING); - - adv_param.options &= ~BT_LE_ADV_OPT_CONN; - adv_param.options |= BT_LE_ADV_OPT_USE_IDENTITY; - bt_dev.id_addr[BT_ID_DEFAULT].type = BT_ADDR_LE_RANDOM; - - result = bt_id_adv_random_addr_check(&adv_param); - - zassert_false(result, "Incorrect result was returned"); -} - -/* - * Test that advertiser cannot start with random static identity or using an RPA generated for - * a different identity than scanner roles while 'CONFIG_BT_PRIVACY' isn't enabled and - * 'CONFIG_BT_SCAN_WITH_IDENTITY' is enabled - * - * Constraints: - * - 'CONFIG_BT_SCAN_WITH_IDENTITY' is enabled - * - 'CONFIG_BT_PRIVACY' isn't enabled - * - 'CONFIG_BT_OBSERVER' is enabled - * - 'CONFIG_BT_EXT_ADV' isn't enabled - * - * Expected behaviour: - * - bt_id_scan_random_addr_check() returns false - */ -ZTEST(bt_id_adv_random_addr_check, test_check_returns_false_advertise_with_different_identity) -{ - bool result; - struct bt_le_adv_param adv_param = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_SCAN_WITH_IDENTITY); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_OBSERVER); - Z_TEST_SKIP_IFDEF(CONFIG_BT_EXT_ADV); - - atomic_set_bit(bt_dev.flags, BT_DEV_SCANNING); - - adv_param.id = 1; - bt_dev.id_addr[adv_param.id].type = BT_ADDR_LE_RANDOM; - bt_dev.id_addr[BT_ID_DEFAULT].type = BT_ADDR_LE_RANDOM; - - result = bt_id_adv_random_addr_check(&adv_param); - - zassert_false(result, "Incorrect result was returned"); -} - -/* - * Test checking advertising random address returns 'true' as a default value - * - * Constraints: - * - 'CONFIG_BT_OBSERVER' is enabled - * - 'CONFIG_BT_EXT_ADV' isn't enabled - * - 'BT_DEV_INITIATING' and 'BT_DEV_SCANNING' are set in bt_dev.flags - * - 'CONFIG_BT_SCAN_WITH_IDENTITY' isn't enabled - * - 'CONFIG_BT_PRIVACY' isn't enabled - * - * Expected behaviour: - * - bt_id_scan_random_addr_check() returns true - */ -ZTEST(bt_id_adv_random_addr_check, test_default_return_value) -{ - bool result; - struct bt_le_adv_param adv_param; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_OBSERVER); - Z_TEST_SKIP_IFDEF(CONFIG_BT_EXT_ADV); - Z_TEST_SKIP_IFDEF(CONFIG_BT_SCAN_WITH_IDENTITY); - Z_TEST_SKIP_IFDEF(CONFIG_BT_PRIVACY); - - atomic_set_bit(bt_dev.flags, BT_DEV_INITIATING); - atomic_set_bit(bt_dev.flags, BT_DEV_SCANNING); - - result = bt_id_adv_random_addr_check(&adv_param); - - zassert_true(result, "Incorrect result was returned"); -} diff --git a/tests/bluetooth/host/id/bt_id_adv_random_addr_check/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/id/bt_id_adv_random_addr_check/src/test_suite_invalid_inputs.c deleted file mode 100644 index 1802afb772edf..0000000000000 --- a/tests/bluetooth/host/id/bt_id_adv_random_addr_check/src/test_suite_invalid_inputs.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" - -#include -#include -#include - -#include -#include - -ZTEST_SUITE(bt_id_adv_random_addr_check_invalid_inputs, NULL, NULL, NULL, NULL, NULL); - -/* - * Test passing NULL value for the advertising parameters - * - * Constraints: - * - Advertising parameters reference is passed as NULL - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_id_adv_random_addr_check_invalid_inputs, test_null_advertising_parameters_ref) -{ - expect_assert(); - bt_id_adv_random_addr_check(NULL); -} diff --git a/tests/bluetooth/host/id/bt_id_adv_random_addr_check/testcase.yaml b/tests/bluetooth/host/id/bt_id_adv_random_addr_check/testcase.yaml deleted file mode 100644 index 2cf7899f636b0..0000000000000 --- a/tests/bluetooth/host/id/bt_id_adv_random_addr_check/testcase.yaml +++ /dev/null @@ -1,29 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_id_adv_random_addr_check.default: - type: unit - bluetooth.host.bt_id_adv_random_addr_check.observer_enabled: - type: unit - extra_configs: - - CONFIG_BT_CENTRAL=y - - CONFIG_BT_OBSERVER=y - bluetooth.host.bt_id_adv_random_addr_check.observer_privacy_enabled: - type: unit - extra_configs: - - CONFIG_BT_SMP=y - - CONFIG_BT_PRIVACY=y - - CONFIG_BT_CENTRAL=y - - CONFIG_BT_OBSERVER=y - bluetooth.host.bt_id_adv_random_addr_check.observer_scan_with_identity_enabled: - type: unit - extra_configs: - - CONFIG_BT_SCAN_WITH_IDENTITY=y - - CONFIG_BT_CENTRAL=y - - CONFIG_BT_OBSERVER=y - bluetooth.host.bt_id_adv_random_addr_check.bt_ext_adv_enabled: - type: unit - extra_configs: - - CONFIG_BT_EXT_ADV=y diff --git a/tests/bluetooth/host/id/bt_id_create/CMakeLists.txt b/tests/bluetooth/host/id/bt_id_create/CMakeLists.txt deleted file mode 100644 index d89d4b18f3bf2..0000000000000 --- a/tests/bluetooth/host/id/bt_id_create/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -project(bt_id_create) - -# Suppress the format-zero-length error if GNUC is used -if (CMAKE_C_COMPILER_ID MATCHES "GNU") -add_compile_options(-Wno-error=format-zero-length -Wno-format-zero-length) -endif() - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_invalid_inputs.c - src/test_suite_privacy_enabled.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/id.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -) diff --git a/tests/bluetooth/host/id/bt_id_create/Kconfig b/tests/bluetooth/host/id/bt_id_create/Kconfig deleted file mode 100644 index 4dbe3e79c9f77..0000000000000 --- a/tests/bluetooth/host/id/bt_id_create/Kconfig +++ /dev/null @@ -1,11 +0,0 @@ -# Copyright (c) 2023 Nordic Semiconductor ASA -# -# SPDX-License-Identifier: Apache-2.0 - -config SELECT_BT_HCI_SET_PUBLIC_ADDR - bool "dummy kconfig" - select BT_HCI_SET_PUBLIC_ADDR - help - dummy kconfig - -source "Kconfig.zephyr" diff --git a/tests/bluetooth/host/id/bt_id_create/prj.conf b/tests/bluetooth/host/id/bt_id_create/prj.conf deleted file mode 100644 index 5f8cdcef01788..0000000000000 --- a/tests/bluetooth/host/id/bt_id_create/prj.conf +++ /dev/null @@ -1,8 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_ID_MAX=2 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/id/bt_id_create/src/main.c b/tests/bluetooth/host/id/bt_id_create/src/main.c deleted file mode 100644 index 0c8b3d08bfe76..0000000000000 --- a/tests/bluetooth/host/id/bt_id_create/src/main.c +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include -#include -#include - -DEFINE_FFF_GLOBALS; - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - ADDR_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(bt_id_create, NULL, NULL, NULL, NULL, NULL); - -static int bt_addr_le_create_static_custom_fake(bt_addr_le_t *addr) -{ - const char *func_name = "bt_addr_le_create_static"; - - zassert_not_null(addr, "'%s()' was called with incorrect '%s' value", func_name, "addr"); - - /* This is required to test when the generated address already exists in the ID list */ - if (bt_addr_le_create_static_fake.call_count == 1) { - bt_addr_le_copy(addr, BT_STATIC_RANDOM_LE_ADDR_1); - } else { - bt_addr_le_copy(addr, BT_STATIC_RANDOM_LE_ADDR_2); - } - - return 0; -} - -/* - * Test creating a new identity. - * As a NULL is passed to bt_id_create() for the address and 'BT_DEV_ENABLE' is set, - * a new random address is generated. - * - * Constraints: - * - Input address is NULL - * - Input IRK is NULL - * - 'BT_DEV_ENABLE' flag is set in bt_dev.flags - * - bt_addr_le_create_static() returns a zero error code (success) - * - * Expected behaviour: - * - A new identity is created and the address is loaded to bt_dev.id_addr[] - * - bt_dev.id_count is incremented - */ -ZTEST(bt_id_create, test_create_id_null_address) -{ - int id_count, new_id; - - id_count = bt_dev.id_count; - atomic_set_bit(bt_dev.flags, BT_DEV_ENABLE); - bt_addr_le_create_static_fake.custom_fake = bt_addr_le_create_static_custom_fake; - - new_id = bt_id_create(NULL, NULL); - - expect_call_count_bt_addr_le_create_static(1); - - zassert_true(new_id >= 0, "Unexpected error code '%d' was returned", new_id); - zassert_true(bt_dev.id_count == (id_count + 1), "Incorrect ID count %d was set", - bt_dev.id_count); - zassert_mem_equal(&bt_dev.id_addr[new_id], BT_STATIC_RANDOM_LE_ADDR_1, sizeof(bt_addr_le_t), - "Incorrect address was set"); -} - -/* - * Test creating a new identity and ensure that the generated address isn't in the ID list. - * As a NULL is passed to bt_id_create() for the address and 'BT_DEV_ENABLE' is set, - * a new random address is generated. - * - * Constraints: - * - Input address is NULL - * - Input IRK is NULL - * - 'BT_DEV_ENABLE' flag is set in bt_dev.flags - * - bt_addr_le_create_static() returns a zero error code (success) - * - * Expected behaviour: - * - A new identity is created and the address is loaded to bt_dev.id_addr[] - * - bt_dev.id_count is incremented - */ -ZTEST(bt_id_create, test_create_id_null_address_with_no_duplication) -{ - int id_count, new_id; - - bt_dev.id_count = 1; - bt_addr_le_copy(&bt_dev.id_addr[0], BT_STATIC_RANDOM_LE_ADDR_1); - - id_count = bt_dev.id_count; - atomic_set_bit(bt_dev.flags, BT_DEV_ENABLE); - bt_addr_le_create_static_fake.custom_fake = bt_addr_le_create_static_custom_fake; - - new_id = bt_id_create(NULL, NULL); - - expect_call_count_bt_addr_le_create_static(2); - - zassert_true(new_id >= 0, "Unexpected error code '%d' was returned", new_id); - zassert_true(bt_dev.id_count == (id_count + 1), "Incorrect ID count %d was set", - bt_dev.id_count); - zassert_mem_equal(&bt_dev.id_addr[new_id], BT_STATIC_RANDOM_LE_ADDR_2, sizeof(bt_addr_le_t), - "Incorrect address was set"); -} - -/* - * Test creating a new identity. - * As an initialized address to BT_ADDR_LE_ANY is passed to bt_id_create() for the address and - * 'BT_DEV_ENABLE' is set, a new random address is generated. - * The generated address should be copied to the address reference passed - * - * Constraints: - * - Input address is NULL - * - Input IRK is NULL - * - 'BT_DEV_ENABLE' flag is set in bt_dev.flags - * - bt_addr_le_create_static() returns a zero error code (success) - * - * Expected behaviour: - * - A new identity is created and the address is loaded to bt_dev.id_addr[] - * - bt_dev.id_count is incremented - */ -ZTEST(bt_id_create, test_create_id_bt_addr_le_any_address) -{ - int id_count, new_id; - bt_addr_le_t addr = bt_addr_le_any; - - id_count = bt_dev.id_count; - atomic_set_bit(bt_dev.flags, BT_DEV_ENABLE); - bt_addr_le_create_static_fake.custom_fake = bt_addr_le_create_static_custom_fake; - - new_id = bt_id_create(&addr, NULL); - - expect_call_count_bt_addr_le_create_static(1); - - zassert_true(new_id >= 0, "Unexpected error code '%d' was returned", new_id); - zassert_true(bt_dev.id_count == (id_count + 1), "Incorrect ID count %d was set", - bt_dev.id_count); - zassert_mem_equal(&bt_dev.id_addr[new_id], BT_STATIC_RANDOM_LE_ADDR_1, sizeof(bt_addr_le_t), - "Incorrect address was set"); - zassert_mem_equal(&addr, BT_STATIC_RANDOM_LE_ADDR_1, sizeof(bt_addr_le_t), - "Incorrect address was set"); -} - -/* - * Test creating a new identity, but bt_addr_le_create_static() returns an error. - * - * Constraints: - * - Input address is NULL - * - Input IRK is NULL - * - 'BT_DEV_ENABLE' flag is set in bt_dev.flags - * - bt_addr_le_create_static() returns a non-zero error code (failure) - * - * Expected behaviour: - * - No new identity is created - * - bt_dev.id_count is kept unchanged - */ -ZTEST(bt_id_create, test_create_id_null_address_fails) -{ - int id_count, err; - - id_count = bt_dev.id_count; - atomic_set_bit(bt_dev.flags, BT_DEV_ENABLE); - bt_addr_le_create_static_fake.return_val = -1; - - err = bt_id_create(NULL, NULL); - - expect_call_count_bt_addr_le_create_static(1); - - zassert_true(err == -1, "Unexpected error code '%d' was returned", err); - zassert_true(bt_dev.id_count == id_count, "Incorrect ID count %d was set", bt_dev.id_count); -} - -/* - * Test creating a new identity. - * A valid random static address is passed to bt_id_create() for the address and 'BT_DEV_ENABLE' is - * set, the same address is used and copied to bt_dev.id_addr[]. - * - * Constraints: - * - Valid private random address is used - * - Input IRK is NULL - * - 'BT_DEV_ENABLE' flag is set in bt_dev.flags - * - * Expected behaviour: - * - The same address is used and loaded to bt_dev.id_addr[] - * - bt_dev.id_count is incremented - */ -ZTEST(bt_id_create, test_create_id_valid_input_address) -{ - int id_count, new_id; - bt_addr_le_t addr = *BT_STATIC_RANDOM_LE_ADDR_1; - - id_count = bt_dev.id_count; - atomic_set_bit(bt_dev.flags, BT_DEV_ENABLE); - /* Calling bt_addr_le_create_static() isn't expected */ - bt_addr_le_create_static_fake.return_val = -1; - - new_id = bt_id_create(&addr, NULL); - - expect_not_called_bt_addr_le_create_static(); - - zassert_true(new_id >= 0, "Unexpected error code '%d' was returned", new_id); - zassert_true(bt_dev.id_count == (id_count + 1), "Incorrect ID count %d was set", - bt_dev.id_count); - zassert_mem_equal(&bt_dev.id_addr[new_id], BT_STATIC_RANDOM_LE_ADDR_1, sizeof(bt_addr_le_t), - "Incorrect address was set"); -} - -/* - * Test creating a new public identity. - * - * Constraints: - * - A valid address of type public is used - * - Input IRK is NULL - * - 'BT_DEV_ENABLE' flag is set in bt_dev.flags - * - * Expected behaviour: - * - The public address is loaded to bt_dev.id_addr[BT_ID_DEFAULT] - * - bt_dev.id_count is incremented - */ -ZTEST(bt_id_create, test_public_address) -{ - int id_count, new_id; - bt_addr_le_t addr = *BT_LE_ADDR; - - if (!IS_ENABLED(CONFIG_BT_HCI_SET_PUBLIC_ADDR)) { - ztest_test_skip(); - } - - id_count = bt_dev.id_count; - atomic_set_bit(bt_dev.flags, BT_DEV_ENABLE); - /* Calling bt_addr_le_create_static() isn't expected */ - bt_addr_le_create_static_fake.return_val = -1; - - new_id = bt_id_create(&addr, NULL); - - expect_not_called_bt_addr_le_create_static(); - - zassert_true(new_id == BT_ID_DEFAULT, "Unexpected error code '%d' was returned", new_id); - zassert_true(bt_dev.id_count == (id_count + 1), "Incorrect ID count %d was set", - bt_dev.id_count); - zassert_mem_equal(&bt_dev.id_addr[new_id], BT_LE_ADDR, sizeof(bt_addr_le_t), - "Incorrect address was set"); -} diff --git a/tests/bluetooth/host/id/bt_id_create/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/id/bt_id_create/src/test_suite_invalid_inputs.c deleted file mode 100644 index e803694326acb..0000000000000 --- a/tests/bluetooth/host/id/bt_id_create/src/test_suite_invalid_inputs.c +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include - -ZTEST_SUITE(bt_id_create_invalid_inputs, NULL, NULL, NULL, NULL, NULL); - -/* - * Test invalid input arguments to bt_id_create() using NULLs for address and IRK parameters. - * - * Constraints: - * - Input address is NULL - * - Input IRK is NULL - * - * Expected behaviour: - * - '-EINVAL' error code is returned representing invalid values were used. - */ -ZTEST(bt_id_create_invalid_inputs, test_null_addr_null_irk) -{ - int err; - - err = bt_id_create(NULL, NULL); - - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); -} - -/* - * Test invalid input arguments to bt_id_create() using NULL for the address parameter - * while the IRK parameter is a valid pointer. - * - * Constraints: - * - Input address is NULL - * - Input IRK isn't NULL - * - * Expected behaviour: - * - '-EINVAL' error code is returned representing invalid values were used. - */ -ZTEST(bt_id_create_invalid_inputs, test_null_addr_valid_irk_no_privacy_enabled) -{ - int err; - uint8_t valid_irk_ptr[16]; - - err = bt_id_create(NULL, valid_irk_ptr); - - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); -} - -/* - * Test invalid input arguments to bt_id_create() using NULLs for address and IRK parameters - * while the identity list is full. - * - * Constraints: - * - Input address is NULL - * - Input IRK is NULL - * - Identity list is full - * - * Expected behaviour: - * - '-ENOMEM' error code is returned representing invalid values were used. - */ -ZTEST(bt_id_create_invalid_inputs, test_id_list_is_full) -{ - int err; - - bt_dev.id_count = ARRAY_SIZE(bt_dev.id_addr); - - err = bt_id_create(NULL, NULL); - - zassert_true(err == -ENOMEM, "Unexpected error code '%d' was returned", err); -} - -/* - * Test invalid input arguments to bt_id_create() by using a valid address of type public and using - * NULL value for the IRK. - * - * Constraints: - * - A valid address of type public is used - * - Input IRK is NULL - * - * Expected behaviour: - * - '-EINVAL' error code is returned representing invalid values were used. - */ -ZTEST(bt_id_create_invalid_inputs, test_public_address) -{ - int err; - - if (IS_ENABLED(CONFIG_BT_HCI_SET_PUBLIC_ADDR)) { - ztest_test_skip(); - } - - err = bt_id_create(BT_LE_ADDR, NULL); - - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); -} - -/* - * Test invalid input arguments to bt_id_create() by using a valid address of type RPA and using - * NULL value for the IRK. - * - * Constraints: - * - An RPA address of type random is used - * - Input IRK is NULL - * - * Expected behaviour: - * - '-EINVAL' error code is returned representing invalid values were used. - */ -ZTEST(bt_id_create_invalid_inputs, test_rpa_address) -{ - int err; - - err = bt_id_create(BT_RPA_LE_ADDR, NULL); - - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); -} - -/* - * Test invalid input arguments to bt_id_create() by using an address that already exists - * in the identity list. - * - * Constraints: - * - A valid random static address is used - * - Input address already exists in the identity list - * - Input IRK is NULL - * - * Expected behaviour: - * - '-EALREADY' error code is returned representing invalid values were used. - */ -ZTEST(bt_id_create_invalid_inputs, test_pa_address_exists_in_id_list) -{ - int err; - - bt_dev.id_count = 1; - bt_addr_le_copy(&bt_dev.id_addr[0], BT_STATIC_RANDOM_LE_ADDR_1); - - err = bt_id_create(BT_STATIC_RANDOM_LE_ADDR_1, NULL); - - zassert_true(err == -EALREADY, "Unexpected error code '%d' was returned", err); -} - -/* - * Test invalid input arguments to bt_id_create() by using a valid static random address and - * a valid pointer to an IRK that's filled with zeros. - * - * Constraints: - * - A static random address is used - * - Input IRK is filled with zeros - * - * Expected behaviour: - * - '-EINVAL' error code is returned representing invalid values were used. - */ -ZTEST(bt_id_create_invalid_inputs, test_zero_irk_with_privacy) -{ - int err; - uint8_t zero_irk[16] = {0}; - - err = bt_id_create(BT_STATIC_RANDOM_LE_ADDR_1, zero_irk); - - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); -} diff --git a/tests/bluetooth/host/id/bt_id_create/src/test_suite_privacy_enabled.c b/tests/bluetooth/host/id/bt_id_create/src/test_suite_privacy_enabled.c deleted file mode 100644 index 551b78f19fd80..0000000000000 --- a/tests/bluetooth/host/id/bt_id_create/src/test_suite_privacy_enabled.c +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#if defined(CONFIG_BT_PRIVACY) - -#include "mocks/crypto.h" -#include "mocks/crypto_expects.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include -#include -#include - -static uint8_t testing_irk_value[16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15}; - -static void tc_setup(void *f) -{ - CRYPTO_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_SUITE(bt_id_create_privacy_enabled, NULL, NULL, tc_setup, NULL, NULL); - -static int bt_rand_custom_fake(void *buf, size_t len) -{ - __ASSERT_NO_MSG(buf != NULL); - __ASSERT_NO_MSG(len == 16); - - memcpy(buf, testing_irk_value, len); - - return 0; -} - -/* - * Test creating a new identity. - * A valid random static address is passed to bt_id_create() for the address and 'BT_DEV_ENABLE' is - * set, the same address is used and copied to bt_dev.id_addr[]. - * - * Constraints: - * - Valid private random address is used - * - Input IRK is NULL - * - 'BT_DEV_ENABLE' flag is set in bt_dev.flags - * - * Expected behaviour: - * - The same address is used and loaded to bt_dev.id_addr[] - * - IRK is loaded to bt_dev.irk[] - * - bt_dev.id_count is incremented - */ -ZTEST(bt_id_create_privacy_enabled, test_create_id_valid_input_address_null_irk) -{ - int id_count, new_id; - bt_addr_le_t addr = *BT_STATIC_RANDOM_LE_ADDR_1; - - id_count = bt_dev.id_count; - atomic_set_bit(bt_dev.flags, BT_DEV_ENABLE); - bt_rand_fake.custom_fake = bt_rand_custom_fake; - /* Calling bt_addr_le_create_static() isn't expected */ - bt_addr_le_create_static_fake.return_val = -1; - - new_id = bt_id_create(&addr, NULL); - - expect_not_called_bt_addr_le_create_static(); - expect_single_call_bt_rand(&bt_dev.irk[new_id], 16); - - zassert_true(new_id >= 0, "Unexpected error code '%d' was returned", new_id); - zassert_true(bt_dev.id_count == (id_count + 1), "Incorrect ID count %d was set", - bt_dev.id_count); - zassert_mem_equal(&bt_dev.id_addr[new_id], BT_STATIC_RANDOM_LE_ADDR_1, sizeof(bt_addr_le_t), - "Incorrect address was set"); - zassert_mem_equal(&bt_dev.irk[new_id], testing_irk_value, sizeof(testing_irk_value), - "Incorrect address was set"); -} - -/* - * Test creating a new identity. - * A valid random static address is passed to bt_id_create() for the address and 'BT_DEV_ENABLE' is - * set, the same address is used and copied to bt_dev.id_addr[]. - * - * Constraints: - * - Valid private random address is used - * - Input IRK is cleared (zero filled) - * - 'BT_DEV_ENABLE' flag is set in bt_dev.flags - * - * Expected behaviour: - * - The same address is used and loaded to bt_dev.id_addr[] - * - IRK is loaded to bt_dev.irk[] - * - IRK is loaded to input IRK buffer - * - bt_dev.id_count is incremented - */ -ZTEST(bt_id_create_privacy_enabled, test_create_id_valid_input_address_cleared_irk) -{ - int id_count, new_id; - bt_addr_le_t addr = *BT_STATIC_RANDOM_LE_ADDR_1; - uint8_t zero_irk[16] = {0}; - - id_count = bt_dev.id_count; - atomic_set_bit(bt_dev.flags, BT_DEV_ENABLE); - bt_rand_fake.custom_fake = bt_rand_custom_fake; - /* Calling bt_addr_le_create_static() isn't expected */ - bt_addr_le_create_static_fake.return_val = -1; - - new_id = bt_id_create(&addr, zero_irk); - - expect_not_called_bt_addr_le_create_static(); - expect_single_call_bt_rand(&bt_dev.irk[new_id], 16); - - zassert_true(new_id >= 0, "Unexpected error code '%d' was returned", new_id); - zassert_true(bt_dev.id_count == (id_count + 1), "Incorrect ID count %d was set", - bt_dev.id_count); - zassert_mem_equal(&bt_dev.id_addr[new_id], BT_STATIC_RANDOM_LE_ADDR_1, sizeof(bt_addr_le_t), - "Incorrect address was set"); - zassert_mem_equal(&bt_dev.irk[new_id], testing_irk_value, sizeof(testing_irk_value), - "Incorrect address was set"); - zassert_mem_equal(zero_irk, testing_irk_value, sizeof(testing_irk_value), - "Incorrect address was set"); -} - -/* - * Test creating a new identity. - * A valid random static address is passed to bt_id_create() for the address and 'BT_DEV_ENABLE' is - * set, the same address is used and copied to bt_dev.id_addr[]. - * - * Constraints: - * - Valid private random address is used - * - Input IRK is filled with non-zero values - * - 'BT_DEV_ENABLE' flag is set in bt_dev.flags - * - * Expected behaviour: - * - The same address is used and loaded to bt_dev.id_addr[] - * - Input IRK is loaded to bt_dev.irk[] - * - bt_dev.id_count is incremented - */ -ZTEST(bt_id_create_privacy_enabled, test_create_id_valid_input_address_filled_irk) -{ - int id_count, new_id; - bt_addr_le_t addr = *BT_STATIC_RANDOM_LE_ADDR_1; - - id_count = bt_dev.id_count; - atomic_set_bit(bt_dev.flags, BT_DEV_ENABLE); - bt_rand_fake.custom_fake = bt_rand_custom_fake; - /* Calling bt_addr_le_create_static() isn't expected */ - bt_addr_le_create_static_fake.return_val = -1; - - new_id = bt_id_create(&addr, testing_irk_value); - - expect_not_called_bt_addr_le_create_static(); - expect_not_called_bt_rand(); - - zassert_true(new_id >= 0, "Unexpected error code '%d' was returned", new_id); - zassert_true(bt_dev.id_count == (id_count + 1), "Incorrect ID count %d was set", - bt_dev.id_count); - zassert_mem_equal(&bt_dev.id_addr[new_id], BT_STATIC_RANDOM_LE_ADDR_1, sizeof(bt_addr_le_t), - "Incorrect address was set"); - zassert_mem_equal(&bt_dev.irk[new_id], testing_irk_value, sizeof(testing_irk_value), - "Incorrect address was set"); -} -#endif diff --git a/tests/bluetooth/host/id/bt_id_create/testcase.yaml b/tests/bluetooth/host/id/bt_id_create/testcase.yaml deleted file mode 100644 index 6d9d713f10ee5..0000000000000 --- a/tests/bluetooth/host/id/bt_id_create/testcase.yaml +++ /dev/null @@ -1,18 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_id_create.default: - type: unit - bluetooth.host.bt_id_create.bt_set_public_addr: - type: unit - extra_configs: - - CONFIG_BT_SMP=y - - CONFIG_BT_PRIVACY=y - - CONFIG_SELECT_BT_HCI_SET_PUBLIC_ADDR=y - bluetooth.host.bt_id_create.bt_privacy_enabled: - type: unit - extra_configs: - - CONFIG_BT_SMP=y - - CONFIG_BT_PRIVACY=y diff --git a/tests/bluetooth/host/id/bt_id_del/CMakeLists.txt b/tests/bluetooth/host/id/bt_id_del/CMakeLists.txt deleted file mode 100644 index cd1e3c88a4d4f..0000000000000 --- a/tests/bluetooth/host/id/bt_id_del/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -project(bt_id_del) - -# Suppress the format-zero-length error if GNUC is used -if (CMAKE_C_COMPILER_ID MATCHES "GNU") -add_compile_options(-Wno-error=format-zero-length -Wno-format-zero-length) -endif() - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_invalid_inputs.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/id.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -) diff --git a/tests/bluetooth/host/id/bt_id_del/prj.conf b/tests/bluetooth/host/id/bt_id_del/prj.conf deleted file mode 100644 index 82e46bfe20fff..0000000000000 --- a/tests/bluetooth/host/id/bt_id_del/prj.conf +++ /dev/null @@ -1,9 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_SMP=y -CONFIG_BT_ID_MAX=2 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/id/bt_id_del/src/main.c b/tests/bluetooth/host/id/bt_id_del/src/main.c deleted file mode 100644 index ac37caf3678c7..0000000000000 --- a/tests/bluetooth/host/id/bt_id_del/src/main.c +++ /dev/null @@ -1,400 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/adv.h" -#include "mocks/adv_expects.h" -#include "mocks/conn.h" -#include "mocks/conn_expects.h" -#include "mocks/hci_core.h" -#include "mocks/hci_core_expects.h" -#include "mocks/keys.h" -#include "mocks/keys_expects.h" -#include "mocks/net_buf.h" -#include "mocks/net_buf_expects.h" -#include "mocks/scan.h" -#include "mocks/scan_expects.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include - -DEFINE_FFF_GLOBALS; - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - - ADV_FFF_FAKES_LIST(RESET_FAKE); - CONN_FFF_FAKES_LIST(RESET_FAKE); - KEYS_FFF_FAKES_LIST(RESET_FAKE); - NET_BUF_FFF_FAKES_LIST(RESET_FAKE); - HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(bt_id_del, NULL, NULL, NULL, NULL, NULL); - -/* - * Test deleting key from the resolving list when size of controller resolving list is zero - * - * Constraints: - * - bt_dev.le.rl_size is set to 0 - * - bt_dev.le.rl_entries is greater than 0 - * - * Expected behaviour: - * - Passed key state is updated by clearing 'BT_KEYS_ID_ADDED' bit - */ -ZTEST(bt_id_del, test_zero_controller_list_size) -{ - struct bt_keys keys = {0}; - uint8_t expected_rl_entries; - - bt_dev.le.rl_size = 0; - bt_dev.le.rl_entries = 1; - expected_rl_entries = bt_dev.le.rl_entries - 1; - keys.state |= BT_KEYS_ID_ADDED; - - bt_id_del(&keys); - - expect_not_called_bt_conn_lookup_state_le(); - - zassert_equal(expected_rl_entries, bt_dev.le.rl_entries, "Incorrect entries count"); - zassert_false(keys.state & BT_KEYS_ID_ADDED, "Incorrect key state"); -} - -/* - * Test deleting key from the resolving list when size of controller resolving list isn't zero - * and number of entries in the resolving list is greater than controller resolving list size. - * - * Constraints: - * - bt_dev.le.rl_size is set to 0 - * - bt_dev.le.rl_entries is greater than (bt_dev.le.rl_size + 1) - * - * Expected behaviour: - * - Passed key state is updated by clearing 'BT_KEYS_ID_ADDED' bit - */ -ZTEST(bt_id_del, test_resolving_list_entries_greater_than_controller_list_size) -{ - struct bt_keys keys = {0}; - uint8_t expected_rl_entries; - - bt_dev.le.rl_size = 1; - bt_dev.le.rl_entries = 3; - expected_rl_entries = bt_dev.le.rl_entries - 1; - keys.state |= BT_KEYS_ID_ADDED; - - bt_id_del(&keys); - - expect_not_called_bt_conn_lookup_state_le(); - - zassert_equal(expected_rl_entries, bt_dev.le.rl_entries, "Incorrect entries count"); - zassert_false(keys.state & BT_KEYS_ID_ADDED, "Incorrect key state"); -} - -/* - * Test deleting key from the resolving list if host side resolving isn't used. - * bt_conn_lookup_state_le() returns a valid connection reference. - * - * Constraints: - * - bt_dev.le.rl_size is set to a value greater than 0 - * - 'bt_dev.le.rl_entries > bt_dev.le.rl_size + 1' condition is false - * - bt_conn_lookup_state_le() returns a valid connection reference. - * - * Expected behaviour: - * - Passed key state is updated by setting 'BT_KEYS_ID_PENDING_DEL' bit - * - 'BT_DEV_ID_PENDING' in bt_dev.flags is set - */ -ZTEST(bt_id_del, test_conn_lookup_returns_valid_conn_ref) -{ - struct bt_keys keys = {0}; - struct bt_conn conn_ref = {0}; - - /* Break the host-side resolving condition */ - bt_dev.le.rl_size = 1; - bt_dev.le.rl_entries = 1; - - bt_conn_lookup_state_le_fake.return_val = &conn_ref; - - bt_id_del(&keys); - - expect_single_call_bt_conn_lookup_state_le(BT_ID_DEFAULT, NULL, BT_CONN_INITIATING); - expect_single_call_bt_conn_unref(&conn_ref); - - zassert_true((keys.state & BT_KEYS_ID_PENDING_DEL) == BT_KEYS_ID_PENDING_DEL, - "Incorrect key state"); - zassert_true(atomic_test_bit(bt_dev.flags, BT_DEV_ID_PENDING), - "Flags were not correctly set"); -} - -void bt_le_ext_adv_foreach_custom_fake(void (*func)(struct bt_le_ext_adv *adv, void *data), - void *data) -{ - struct bt_le_ext_adv adv_params = {0}; - - __ASSERT_NO_MSG(func != NULL); - __ASSERT_NO_MSG(data != NULL); - - atomic_set_bit(adv_params.flags, BT_ADV_ENABLED); - atomic_set_bit(adv_params.flags, BT_ADV_LIMITED); - - func(&adv_params, data); -} - -/* - * Test deleting key from the resolving list if host side resolving isn't used. - * bt_conn_lookup_state_le() returns a NULL connection reference and 'CONFIG_BT_BROADCASTER' and - * 'CONFIG_BT_EXT_ADV' are enabled. - * - * Constraints: - * - bt_dev.le.rl_size is set to a value greater than 0 - * - 'bt_dev.le.rl_entries > bt_dev.le.rl_size + 1' condition is false - * - bt_conn_lookup_state_le() returns NULL. - * - 'CONFIG_BT_BROADCASTER' and 'CONFIG_BT_EXT_ADV' are enabled. - * - adv_is_limited_enabled() sets advertise enable flag to true - * - * Expected behaviour: - * - Passed key state is updated by setting 'BT_KEYS_ID_PENDING_DEL' bit - * - 'BT_DEV_ID_PENDING' in bt_dev.flags is set if advertising is enabled - */ -ZTEST(bt_id_del, test_conn_lookup_returns_null_broadcaster_ext_adv_enabled) -{ - struct bt_keys keys = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_EXT_ADV); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_BROADCASTER); - - /* Break the host-side resolving condition */ - bt_dev.le.rl_size = 1; - bt_dev.le.rl_entries = 1; - - bt_conn_lookup_state_le_fake.return_val = NULL; - - /* When bt_le_ext_adv_foreach() is called, this callback will be triggered and causes - * adv_is_limited_enabled() to set the advertising enable flag to true. - */ - bt_le_ext_adv_foreach_fake.custom_fake = bt_le_ext_adv_foreach_custom_fake; - - bt_id_del(&keys); - - expect_single_call_bt_le_ext_adv_foreach(); - - zassert_true((keys.state & BT_KEYS_ID_PENDING_DEL) == BT_KEYS_ID_PENDING_DEL, - "Incorrect key state"); - zassert_true(atomic_test_bit(bt_dev.flags, BT_DEV_ID_PENDING), - "Flags were not correctly set"); -} - -/* - * Test deleting key from the resolving list when host side resolving isn't used. - * bt_conn_lookup_state_le() returns a NULL connection reference. - * 'CONFIG_BT_BROADCASTER' is enabled while 'CONFIG_BT_EXT_ADV' isn't enabled. - * - * Constraints: - * - bt_dev.le.rl_size is set to a value greater than 0 - * - (bt_dev.le.rl_entries > bt_dev.le.rl_size ) true - * - (bt_dev.le.rl_entries > bt_dev.le.rl_size + 1) false - * - bt_conn_lookup_state_le() returns NULL. - * - 'CONFIG_BT_BROADCASTER' is enabled. - * - 'CONFIG_BT_EXT_ADV' isn't enabled. - * - 'CONFIG_BT_PRIVACY' isn't enabled. - * - * Expected behaviour: - * - Passed key state is updated by setting 'BT_KEYS_ID_ADDED' bit - */ -ZTEST(bt_id_del, test_conn_lookup_returns_null_broadcaster_no_ext_adv) -{ - struct bt_keys keys = {0}; - struct net_buf net_buff = {0}; - uint8_t expected_rl_entries; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_EXT_ADV); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_BROADCASTER); - Z_TEST_SKIP_IFDEF(CONFIG_BT_PRIVACY); - - /* Break the host-side resolving condition */ - bt_dev.le.rl_size = 1; - /* - * (bt_dev.le.rl_entries > bt_dev.le.rl_size ) true - * (bt_dev.le.rl_entries > bt_dev.le.rl_size + 1) false - */ - bt_dev.le.rl_entries = 2; - expected_rl_entries = bt_dev.le.rl_entries - 1; - - bt_conn_lookup_state_le_fake.return_val = NULL; - keys.state |= BT_KEYS_ID_ADDED; - - /* This makes addr_res_enable() succeeds and returns 0 */ - bt_hci_cmd_alloc_fake.return_val = &net_buff; - bt_hci_cmd_send_sync_fake.return_val = 0; - - bt_id_del(&keys); - - expect_single_call_bt_keys_foreach_type(BT_KEYS_IRK); - - zassert_equal(expected_rl_entries, bt_dev.le.rl_entries, "Incorrect entries count"); - zassert_false(keys.state & BT_KEYS_ID_ADDED, "Incorrect key state"); -} - -/* - * Test deleting key from the resolving list when host side resolving isn't used. - * bt_conn_lookup_state_le() returns a NULL connection reference. - * 'CONFIG_BT_BROADCASTER' and 'CONFIG_BT_PRIVACY' are enabled while 'CONFIG_BT_EXT_ADV' isn't - * enabled. - * - * Constraints: - * - bt_dev.le.rl_size is set to a value greater than 0 - * - (bt_dev.le.rl_entries > bt_dev.le.rl_size ) true - * - (bt_dev.le.rl_entries > bt_dev.le.rl_size + 1) false - * - bt_conn_lookup_state_le() returns NULL. - * - 'CONFIG_BT_BROADCASTER' is enabled. - * - 'CONFIG_BT_EXT_ADV' isn't enabled. - * - 'CONFIG_BT_PRIVACY' is enabled. - * - * Expected behaviour: - * - Passed key state is updated by setting 'BT_KEYS_ID_ADDED' bit - */ -ZTEST(bt_id_del, test_conn_lookup_returns_null_broadcaster_no_ext_adv_privacy_enabled) -{ - struct bt_keys keys = {0}; - struct net_buf net_buff = {0}; - uint8_t expected_rl_entries; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_EXT_ADV); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_BROADCASTER); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - - /* Break the host-side resolving condition */ - bt_dev.le.rl_size = 1; - /* - * (bt_dev.le.rl_entries > bt_dev.le.rl_size ) true - * (bt_dev.le.rl_entries > bt_dev.le.rl_size + 1) false - */ - bt_dev.le.rl_entries = 2; - expected_rl_entries = bt_dev.le.rl_entries - 1; - - bt_conn_lookup_state_le_fake.return_val = NULL; - keys.state |= BT_KEYS_ID_ADDED; - - /* This makes addr_res_enable() succeeds and returns 0 */ - bt_hci_cmd_alloc_fake.return_val = &net_buff; - bt_hci_cmd_send_sync_fake.return_val = 0; - - bt_id_del(&keys); - - expect_single_call_bt_keys_foreach_type(BT_KEYS_ALL); - - zassert_equal(expected_rl_entries, bt_dev.le.rl_entries, "Incorrect entries count"); - zassert_false(keys.state & BT_KEYS_ID_ADDED, "Incorrect key state"); -} - -/* - * Test deleting key from the resolving list when host side resolving isn't used. - * bt_conn_lookup_state_le() returns a NULL connection reference. - * 'CONFIG_BT_BROADCASTER' and 'CONFIG_BT_PRIVACY' are enabled while 'CONFIG_BT_EXT_ADV' isn't - * enabled. - * An HCI key address delete request is sent through hci_id_del() - * - * Constraints: - * - bt_dev.le.rl_size is set to a value greater than 0 - * - bt_dev.le.rl_entries equals bt_dev.le.rl_size - * - bt_conn_lookup_state_le() returns NULL. - * - 'CONFIG_BT_BROADCASTER' is enabled. - * - 'CONFIG_BT_EXT_ADV' isn't enabled. - * - 'CONFIG_BT_PRIVACY' is enabled. - * - * Expected behaviour: - * - hci_id_del() uses the correct address while creating the HCI request - * - Passed key state is updated by setting 'BT_KEYS_ID_ADDED' bit - */ -ZTEST(bt_id_del, test_send_hci_id_del) -{ - struct bt_keys keys = {0}; - struct net_buf net_buff = {0}; - struct bt_hci_cp_le_rem_dev_from_rl cp = {0}; - uint8_t expected_rl_entries; - - /* Break the host-side resolving condition */ - bt_dev.le.rl_size = 1; - bt_dev.le.rl_entries = 1; - expected_rl_entries = bt_dev.le.rl_entries - 1; - - bt_conn_lookup_state_le_fake.return_val = NULL; - keys.state |= BT_KEYS_ID_ADDED; - - bt_addr_le_copy(&keys.addr, BT_RPA_LE_ADDR); - - /* This makes hci_id_del() succeeds and returns 0 */ - net_buf_simple_add_fake.return_val = &cp; - bt_hci_cmd_alloc_fake.return_val = &net_buff; - bt_hci_cmd_send_sync_fake.return_val = 0; - - bt_id_del(&keys); - - /* This verifies hci_id_del() behaviour */ - expect_single_call_net_buf_simple_add(&net_buff.b, sizeof(cp)); - - zassert_mem_equal(&cp.peer_id_addr, BT_RPA_LE_ADDR, sizeof(bt_addr_le_t), - "Incorrect address was set"); - zassert_equal(expected_rl_entries, bt_dev.le.rl_entries, "Incorrect entries count"); - zassert_false(keys.state & BT_KEYS_ID_ADDED, "Incorrect key state"); -} - -/* - * Test stopping scanning procedure if it is currently active and re-enable it after updating keys. - * If it is active, it is disabled then re-enabled after updating the key status. - * bt_conn_lookup_state_le() returns a NULL connection reference. - * 'CONFIG_BT_BROADCASTER', 'CONFIG_BT_OBSERVER' and 'CONFIG_BT_EXT_ADV' are enabled. - * - * Constraints: - * - bt_dev.le.rl_size is set to a value greater than 0 - * - bt_dev.le.rl_entries is set to 0 - * - bt_conn_lookup_state_le() returns NULL. - * - 'CONFIG_BT_BROADCASTER' is enabled. - * - 'CONFIG_BT_OBSERVER' is enabled. - * - 'CONFIG_BT_EXT_ADV' is enabled. - * - * Expected behaviour: - * - Passed key state is updated by setting 'BT_KEYS_ID_ADDED' bit - */ -ZTEST(bt_id_del, test_scan_re_enabled_observer_enabled_ext_adv) -{ - struct bt_keys keys = {0}; - struct net_buf net_buff = {0}; - struct bt_hci_cp_le_rem_dev_from_rl cp = {0}; - uint8_t expected_args_history[] = {BT_HCI_LE_SCAN_DISABLE, BT_HCI_LE_SCAN_ENABLE}; - uint8_t expected_rl_entries; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_EXT_ADV); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_OBSERVER); - - /* Break the host-side resolving condition */ - bt_dev.le.rl_size = 1; - bt_dev.le.rl_entries = 1; - expected_rl_entries = bt_dev.le.rl_entries - 1; - - /* Make scan enabled flag true */ - atomic_set_bit(bt_dev.flags, BT_DEV_SCANNING); - atomic_set_bit(bt_dev.flags, BT_DEV_SCAN_LIMITED); - - bt_conn_lookup_state_le_fake.return_val = NULL; - - /* This makes hci_id_del() succeeds and returns 0 */ - net_buf_simple_add_fake.return_val = &cp; - bt_hci_cmd_alloc_fake.return_val = &net_buff; - bt_hci_cmd_send_sync_fake.return_val = 0; - - bt_id_del(&keys); - - expect_call_count_bt_le_scan_set_enable(2, expected_args_history); - - zassert_equal(expected_rl_entries, bt_dev.le.rl_entries, "Incorrect entries count"); - zassert_false(keys.state & BT_KEYS_ID_ADDED, "Incorrect key state"); -} diff --git a/tests/bluetooth/host/id/bt_id_del/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/id/bt_id_del/src/test_suite_invalid_inputs.c deleted file mode 100644 index 66bc9d52731d0..0000000000000 --- a/tests/bluetooth/host/id/bt_id_del/src/test_suite_invalid_inputs.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" - -#include -#include -#include - -#include -#include -#include - -ZTEST_SUITE(bt_id_del_invalid_inputs, NULL, NULL, NULL, NULL, NULL); - -/* - * Test passing NULL value for keys reference - * - * Constraints: - * - Keys reference is passed as NULL - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_id_del_invalid_inputs, test_null_keys_ref) -{ - expect_assert(); - bt_id_del(NULL); -} - -/* - * Test deleting key from the resolving list when size resolving list is zero - * - * Constraints: - * - bt_dev.le.rl_size is set to 0 - * - bt_dev.le.rl_entries is set to 0 - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_id_del_invalid_inputs, test_zero_controller_list_size) -{ - struct bt_keys keys = {0}; - - bt_dev.le.rl_size = 0; - bt_dev.le.rl_entries = 0; - - expect_assert(); - bt_id_del(&keys); -} diff --git a/tests/bluetooth/host/id/bt_id_del/testcase.yaml b/tests/bluetooth/host/id/bt_id_del/testcase.yaml deleted file mode 100644 index 4dd7a40dade2f..0000000000000 --- a/tests/bluetooth/host/id/bt_id_del/testcase.yaml +++ /dev/null @@ -1,28 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_id_del.default: - type: unit - bluetooth.host.bt_id_del.broadcaster_ext_adv_enabled: - type: unit - extra_configs: - - CONFIG_BT_EXT_ADV=y - - CONFIG_BT_BROADCASTER=y - bluetooth.host.bt_id_del.broadcaster_no_ext_adv: - type: unit - extra_configs: - - CONFIG_BT_BROADCASTER=y - bluetooth.host.bt_id_del.broadcaster_no_ext_adv_privacy_enabled: - type: unit - extra_configs: - - CONFIG_BT_CENTRAL=y - - CONFIG_BT_PRIVACY=y - - CONFIG_BT_BROADCASTER=y - bluetooth.host.bt_id_del.observer_ext_adv: - type: unit - extra_configs: - - CONFIG_BT_EXT_ADV=y - - CONFIG_BT_OBSERVER=y - - CONFIG_BT_BROADCASTER=y diff --git a/tests/bluetooth/host/id/bt_id_delete/CMakeLists.txt b/tests/bluetooth/host/id/bt_id_delete/CMakeLists.txt deleted file mode 100644 index e60410577e8b2..0000000000000 --- a/tests/bluetooth/host/id/bt_id_delete/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -project(bt_id_delete) - -# Suppress the format-zero-length error if GNUC is used -if (CMAKE_C_COMPILER_ID MATCHES "GNU") -add_compile_options(-Wno-error=format-zero-length -Wno-format-zero-length) -endif() - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_bt_settings.c - src/test_suite_invalid_inputs.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/id.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -) diff --git a/tests/bluetooth/host/id/bt_id_delete/prj.conf b/tests/bluetooth/host/id/bt_id_delete/prj.conf deleted file mode 100644 index cae35e7d56cb8..0000000000000 --- a/tests/bluetooth/host/id/bt_id_delete/prj.conf +++ /dev/null @@ -1,9 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_SMP=y -CONFIG_BT_ID_MAX=4 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/id/bt_id_delete/src/main.c b/tests/bluetooth/host/id/bt_id_delete/src/main.c deleted file mode 100644 index 58c2c8c5733fb..0000000000000 --- a/tests/bluetooth/host/id/bt_id_delete/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/adv.h" -#include "mocks/hci_core.h" -#include "mocks/settings.h" -#include "mocks/settings_expects.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include - -DEFINE_FFF_GLOBALS; - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - - ADV_FFF_FAKES_LIST(RESET_FAKE); - SETTINGS_FFF_FAKES_LIST(RESET_FAKE); - HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(bt_id_delete, NULL, NULL, NULL, NULL, NULL); - -/* - * Test deleting an ID, but not the last one - * - * Constraints: - * - ID value used is neither corresponds to default index nor the last index - * - * Expected behaviour: - * - bt_dev.id_addr[] at index equals to the ID value used is cleared - * - bt_dev.irk[] at index equals to the ID value used is cleared (if privacy is enabled) - * - bt_id_delete() returns 0 - */ -ZTEST(bt_id_delete, test_delete_non_default_no_last_item) -{ - int err; - uint8_t id; - int id_count; -#if defined(CONFIG_BT_PRIVACY) - uint8_t zero_irk[16] = {0}; -#endif - - bt_dev.id_count = 3; - id = 1; - id_count = bt_dev.id_count; - - bt_addr_le_copy(&bt_dev.id_addr[0], BT_RPA_LE_ADDR); - bt_addr_le_copy(&bt_dev.id_addr[1], BT_STATIC_RANDOM_LE_ADDR_1); - bt_addr_le_copy(&bt_dev.id_addr[2], BT_STATIC_RANDOM_LE_ADDR_2); - - atomic_clear_bit(bt_dev.flags, BT_DEV_READY); - - err = bt_id_delete(id); - - expect_not_called_bt_settings_store_id(); - expect_not_called_bt_settings_store_irk(); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_true(bt_dev.id_count == id_count, "Incorrect ID count %d was set", bt_dev.id_count); - - zassert_mem_equal(&bt_dev.id_addr[id], BT_ADDR_LE_ANY, sizeof(bt_addr_le_t), - "Incorrect address was set"); -#if defined(CONFIG_BT_PRIVACY) - zassert_mem_equal(bt_dev.irk[id], zero_irk, sizeof(zero_irk), - "Incorrect IRK value was set"); -#endif -} - -/* - * Test deleting last ID - * - * Constraints: - * - ID value used corresponds to the last item in the list bt_dev.id_addr[] - * - * Expected behaviour: - * - bt_dev.id_addr[] at index equals to the ID value used is cleared - * - bt_dev.irk[] at index equals to the ID value used is cleared (if privacy is enabled) - * - bt_dev.id_count is decremented - * - bt_id_delete() returns 0 - */ -ZTEST(bt_id_delete, test_delete_last_id) -{ - int err; - uint8_t id; - int id_count; -#if defined(CONFIG_BT_PRIVACY) - uint8_t zero_irk[16] = {0}; -#endif - - bt_dev.id_count = 2; - id = bt_dev.id_count - 1; - id_count = bt_dev.id_count; - - bt_addr_le_copy(&bt_dev.id_addr[0], BT_STATIC_RANDOM_LE_ADDR_1); - bt_addr_le_copy(&bt_dev.id_addr[1], BT_STATIC_RANDOM_LE_ADDR_2); - - atomic_clear_bit(bt_dev.flags, BT_DEV_READY); - - err = bt_id_delete(id); - - expect_not_called_bt_settings_store_id(); - expect_not_called_bt_settings_store_irk(); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - - zassert_true(bt_dev.id_count == (id_count - 1), "Incorrect ID count %d was set", - bt_dev.id_count); - - zassert_mem_equal(&bt_dev.id_addr[id], BT_ADDR_LE_ANY, sizeof(bt_addr_le_t), - "Incorrect address was set"); -#if defined(CONFIG_BT_PRIVACY) - zassert_mem_equal(bt_dev.irk[id], zero_irk, sizeof(zero_irk), - "Incorrect IRK value was set"); -#endif -} diff --git a/tests/bluetooth/host/id/bt_id_delete/src/test_suite_bt_settings.c b/tests/bluetooth/host/id/bt_id_delete/src/test_suite_bt_settings.c deleted file mode 100644 index d7cefdd9fea92..0000000000000 --- a/tests/bluetooth/host/id/bt_id_delete/src/test_suite_bt_settings.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/adv.h" -#include "mocks/hci_core.h" -#include "mocks/settings.h" -#include "mocks/settings_expects.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include - -ZTEST_SUITE(bt_id_delete_bt_settings, NULL, NULL, NULL, NULL, NULL); - -/* - * Test deleting an ID, but not the last one - * As 'CONFIG_BT_SETTINGS' is enabled, settings should be saved by calling bt_settings_store_id() - * and bt_settings_store_irk() if 'BT_DEV_READY' flag in bt_dev.flags is set - * - * Constraints: - * - ID value used is neither corresponds to default index nor the last index - * - 'CONFIG_BT_SETTINGS' is enabled - * - 'BT_DEV_READY' flag in bt_dev.flags is set - * - * Expected behaviour: - * - bt_dev.id_addr[] at index equals to the ID value used is cleared - * - bt_dev.irk[] at index equals to the ID value used is cleared (if privacy is enabled) - * - bt_settings_store_id() and bt_settings_store_irk() are called to save settings - * - bt_dev.id_count is kept unchanged - * - bt_id_delete() returns 0 - */ -ZTEST(bt_id_delete_bt_settings, test_delete_non_default_no_last_item_settings_enabled) -{ - int err; - uint8_t id; - int id_count; -#if defined(CONFIG_BT_PRIVACY) - uint8_t zero_irk[16] = {0}; -#endif - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_SETTINGS); - - bt_dev.id_count = 3; - id = 1; - id_count = bt_dev.id_count; - - bt_addr_le_copy(&bt_dev.id_addr[0], BT_RPA_LE_ADDR); - bt_addr_le_copy(&bt_dev.id_addr[1], BT_STATIC_RANDOM_LE_ADDR_1); - bt_addr_le_copy(&bt_dev.id_addr[2], BT_STATIC_RANDOM_LE_ADDR_2); - - atomic_set_bit(bt_dev.flags, BT_DEV_READY); - - err = bt_id_delete(id); - - expect_single_call_bt_settings_store_id(); - expect_single_call_bt_settings_store_irk(); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_true(bt_dev.id_count == id_count, "Incorrect ID count %d was set", bt_dev.id_count); - - zassert_mem_equal(&bt_dev.id_addr[id], BT_ADDR_LE_ANY, sizeof(bt_addr_le_t), - "Incorrect address was set"); -#if defined(CONFIG_BT_PRIVACY) - zassert_mem_equal(bt_dev.irk[id], zero_irk, sizeof(zero_irk), - "Incorrect IRK value was set"); -#endif -} - -/* - * Test deleting last ID. As 'CONFIG_BT_SETTINGS' is enabled, settings should - * be saved by calling bt_settings_store_id() and bt_settings_store_irk() if - * 'BT_DEV_READY' flag in bt_dev.flags is set - * - * Constraints: - * - ID value used corresponds to the last item in the list bt_dev.id_addr[] - * - 'CONFIG_BT_SETTINGS' is enabled - * - 'BT_DEV_READY' flag in bt_dev.flags is set - * - * Expected behaviour: - * - bt_dev.id_addr[] at index equals to the ID value used is cleared - * - bt_dev.irk[] at index equals to the ID value used is cleared (if privacy - * is enabled) - * - bt_settings_store_id() and bt_settings_store_irk() are called to save settings - * - bt_dev.id_count is decremented - * - bt_id_delete() returns 0 - */ -ZTEST(bt_id_delete_bt_settings, test_delete_last_id_settings_enabled) -{ - int err; - uint8_t id; - int id_count; -#if defined(CONFIG_BT_PRIVACY) - uint8_t zero_irk[16] = {0}; -#endif - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_SETTINGS); - - bt_dev.id_count = 2; - id = bt_dev.id_count - 1; - id_count = bt_dev.id_count; - - bt_addr_le_copy(&bt_dev.id_addr[0], BT_STATIC_RANDOM_LE_ADDR_1); - bt_addr_le_copy(&bt_dev.id_addr[1], BT_STATIC_RANDOM_LE_ADDR_2); - - atomic_set_bit(bt_dev.flags, BT_DEV_READY); - - err = bt_id_delete(id); - - expect_single_call_bt_settings_store_id(); - expect_single_call_bt_settings_store_irk(); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_true(bt_dev.id_count == (id_count - 1), "Incorrect ID count %d was set", - bt_dev.id_count); - - zassert_mem_equal(&bt_dev.id_addr[id], BT_ADDR_LE_ANY, sizeof(bt_addr_le_t), - "Incorrect address was set"); -#if defined(CONFIG_BT_PRIVACY) - zassert_mem_equal(bt_dev.irk[id], zero_irk, sizeof(zero_irk), - "Incorrect IRK value was set"); -#endif -} diff --git a/tests/bluetooth/host/id/bt_id_delete/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/id/bt_id_delete/src/test_suite_invalid_inputs.c deleted file mode 100644 index 1efca19032a0e..0000000000000 --- a/tests/bluetooth/host/id/bt_id_delete/src/test_suite_invalid_inputs.c +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/adv.h" -#include "mocks/adv_expects.h" -#include "mocks/hci_core.h" -#include "mocks/hci_core_expects.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include - -ZTEST_SUITE(bt_id_delete_invalid_inputs, NULL, NULL, NULL, NULL, NULL); - -/* - * Test deleting default ID which shouldn't be allowed - * - * Constraints: - * - BT_ID_DEFAULT value is used for the ID - * - * Expected behaviour: - * - '-EINVAL' error code is returned representing invalid values were used. - */ -ZTEST(bt_id_delete_invalid_inputs, test_deleting_default_id) -{ - int err; - - err = bt_id_delete(BT_ID_DEFAULT); - - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); -} - -/* - * Test deleting ID value that is equal to bt_dev.id_count - * - * Constraints: - * - bt_dev.id_count is greater than 0 - * - ID value used is equal to bt_dev.id_count - * - * Expected behaviour: - * - '-EINVAL' error code is returned representing invalid values were used. - */ -ZTEST(bt_id_delete_invalid_inputs, test_deleting_id_value_equal_to_dev_id_count) -{ - int err; - - bt_dev.id_count = 1; - - err = bt_id_delete(bt_dev.id_count); - - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); -} - -/* - * Test deleting ID that corresponds to a zero-filled item - * - * Constraints: - * - bt_dev.id_count is greater than 1 - * - ID value used corresponds to a zero-filled item - * - * Expected behaviour: - * - '-EALREADY' error code is returned representing invalid values were used. - */ -ZTEST(bt_id_delete_invalid_inputs, test_deleting_id_with_zero_filled_item) -{ - int err; - - bt_dev.id_count = 2; - bt_addr_le_copy(&bt_dev.id_addr[0], BT_STATIC_RANDOM_LE_ADDR_1); - bt_addr_le_copy(&bt_dev.id_addr[1], BT_ADDR_LE_ANY); - - err = bt_id_delete(1); - - zassert_true(err == -EALREADY, "Unexpected error code '%d' was returned", err); -} - -static void bt_le_ext_adv_foreach_custom_fake(void (*func)(struct bt_le_ext_adv *adv, void *data), - void *data) -{ - struct bt_le_ext_adv adv_params = {0}; - - __ASSERT_NO_MSG(func != NULL); - __ASSERT_NO_MSG(data != NULL); - - if (IS_ENABLED(CONFIG_BT_EXT_ADV)) { - /* Only check if the ID is in use, as the advertiser can be - * started and stopped without reconfiguring parameters. - */ - adv_params.id = bt_dev.id_count - 1; - } else { - atomic_set_bit(adv_params.flags, BT_ADV_ENABLED); - adv_params.id = bt_dev.id_count - 1; - } - - func(&adv_params, data); -} - -/* - * Test deleting an ID if the 'CONFIG_BT_BROADCASTER' is enabled and the same ID is already - * in use with the advertising data. - * - * Constraints: - * - ID value used corresponds to a currently used ID in advertising - * - 'CONFIG_BT_BROADCASTER' is enabled - * - * Expected behaviour: - * - '-EBUSY' error code is returned representing invalid values were used. - */ -ZTEST(bt_id_delete_invalid_inputs, test_deleting_id_used_in_advertising) -{ - int err; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_BROADCASTER); - - bt_dev.id_count = 2; - bt_addr_le_copy(&bt_dev.id_addr[0], BT_STATIC_RANDOM_LE_ADDR_1); - bt_addr_le_copy(&bt_dev.id_addr[1], BT_STATIC_RANDOM_LE_ADDR_2); - - /* When bt_le_ext_adv_foreach() is called, this callback will be triggered and causes - * adv_id_check_func() to set the advertising enable flag to true. - */ - bt_le_ext_adv_foreach_fake.custom_fake = bt_le_ext_adv_foreach_custom_fake; - - err = bt_id_delete(bt_dev.id_count - 1); - - expect_single_call_bt_le_ext_adv_foreach(); - - zassert_true(err == -EBUSY, "Unexpected error code '%d' was returned", err); -} - -/* - * Test returning error when bt_unpair() fails - * - * Constraints: - * - 'CONFIG_BT_CONN' is enabled - * - bt_unpair() fails and returns a negative error code - * - * Expected behaviour: - * - '-EALREADY' error code is returned representing invalid values were used. - */ -ZTEST(bt_id_delete_invalid_inputs, test_bt_unpair_fails) -{ - int err; - uint8_t id; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_CONN); - - bt_dev.id_count = 2; - id = bt_dev.id_count - 1; - - bt_addr_le_copy(&bt_dev.id_addr[0], BT_STATIC_RANDOM_LE_ADDR_1); - bt_addr_le_copy(&bt_dev.id_addr[1], BT_STATIC_RANDOM_LE_ADDR_2); - - bt_unpair_fake.return_val = -1; - - err = bt_id_delete(id); - - expect_single_call_bt_unpair(id, NULL); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); -} diff --git a/tests/bluetooth/host/id/bt_id_delete/testcase.yaml b/tests/bluetooth/host/id/bt_id_delete/testcase.yaml deleted file mode 100644 index 6b9865ac64fad..0000000000000 --- a/tests/bluetooth/host/id/bt_id_delete/testcase.yaml +++ /dev/null @@ -1,24 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_id_delete.default: - type: unit - bluetooth.host.bt_id_delete.default_bt_settings_enabled: - type: unit - extra_configs: - - CONFIG_SETTINGS=y - - CONFIG_BT_SETTINGS=y - bluetooth.host.bt_id_delete.privacy_enabled: - type: unit - extra_configs: - - CONFIG_BT_SMP=y - - CONFIG_BT_PRIVACY=y - bluetooth.host.bt_id_delete.privacy_bt_settings_enabled: - type: unit - extra_configs: - - CONFIG_SETTINGS=y - - CONFIG_BT_SETTINGS=y - - CONFIG_BT_SMP=y - - CONFIG_BT_PRIVACY=y diff --git a/tests/bluetooth/host/id/bt_id_get/CMakeLists.txt b/tests/bluetooth/host/id/bt_id_get/CMakeLists.txt deleted file mode 100644 index b12fd364e0f4d..0000000000000 --- a/tests/bluetooth/host/id/bt_id_get/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -project(bt_id_get) - -# Suppress the format-zero-length error if GNUC is used -if (CMAKE_C_COMPILER_ID MATCHES "GNU") -add_compile_options(-Wno-error=format-zero-length -Wno-format-zero-length) -endif() - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/id.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -) diff --git a/tests/bluetooth/host/id/bt_id_get/prj.conf b/tests/bluetooth/host/id/bt_id_get/prj.conf deleted file mode 100644 index cae35e7d56cb8..0000000000000 --- a/tests/bluetooth/host/id/bt_id_get/prj.conf +++ /dev/null @@ -1,9 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_SMP=y -CONFIG_BT_ID_MAX=4 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/id/bt_id_get/src/main.c b/tests/bluetooth/host/id/bt_id_get/src/main.c deleted file mode 100644 index bc17424480024..0000000000000 --- a/tests/bluetooth/host/id/bt_id_get/src/main.c +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include - -DEFINE_FFF_GLOBALS; - -/* This LUT contains different testing addresses. */ -static const bt_addr_le_t *testing_addr_lut[] = {BT_LE_ADDR, BT_STATIC_RANDOM_LE_ADDR_1, - BT_STATIC_RANDOM_LE_ADDR_2, BT_RPA_LE_ADDR}; - -/* This is the destination address used during UTs */ -static bt_addr_le_t copy_dst_addrs[CONFIG_BT_ID_MAX]; - -BUILD_ASSERT(ARRAY_SIZE(testing_addr_lut) == CONFIG_BT_ID_MAX); - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - memset(copy_dst_addrs, 0x00, sizeof(copy_dst_addrs)); - - for (size_t i = 0; i < CONFIG_BT_ID_MAX; i++) { - const bt_addr_le_t *src = testing_addr_lut[i]; - bt_addr_le_t *dst = &bt_dev.id_addr[bt_dev.id_count++]; - - memcpy(dst, src, sizeof(bt_addr_le_t)); - } - - for (size_t i = 0; i < CONFIG_BT_ID_MAX; i++) { - memcpy(©_dst_addrs[i], BT_ADDR_LE_ANY, sizeof(bt_addr_le_t)); - } -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(bt_id_get, NULL, NULL, NULL, NULL, NULL); - -/* - * Get currently stored ID count - * - * Constraints: - * - Use NULL value for the address - * - * Expected behaviour: - * - Count parameter pointer is dereferenced and loaded with the current bt_dev.id_count - */ -ZTEST(bt_id_get, test_get_current_id_count) -{ - size_t count; - - bt_id_get(NULL, &count); - - zassert_equal(count, CONFIG_BT_ID_MAX, "Incorrect ID count %d was returned", count); -} - -/* - * Copy minimum number of addresses to the destination array - * - * Constraints: - * - Destination array is initially cleared - * - * Expected behaviour: - * - Count parameter pointer is dereferenced and loaded with actual number of copied items - */ -ZTEST(bt_id_get, test_copy_minimum_count) -{ - size_t stored_count = bt_dev.id_count; - size_t testing_counts[] = {0, 1, bt_dev.id_count, bt_dev.id_count + 2}; - - for (size_t it = 0; it < ARRAY_SIZE(testing_counts); it++) { - size_t count = testing_counts[it]; - size_t expected_count = MIN(count, stored_count); - - bt_id_get(copy_dst_addrs, &count); - - zassert_equal(count, expected_count, "Incorrect ID count %d was returned", count); - - /* Verify copied items */ - for (size_t i = 0; i < count; i++) { - const bt_addr_le_t *src = testing_addr_lut[i]; - bt_addr_le_t *dst = ©_dst_addrs[i]; - - zassert_mem_equal(src, dst, sizeof(bt_addr_le_t), - "Incorrect address was set"); - } - - /* Verify the rest of items */ - for (size_t i = count; i < stored_count; i++) { - bt_addr_le_t *src = ©_dst_addrs[i]; - - zassert_mem_equal(src, BT_ADDR_LE_ANY, sizeof(bt_addr_le_t), - "Incorrect address was set"); - } - } -} diff --git a/tests/bluetooth/host/id/bt_id_get/testcase.yaml b/tests/bluetooth/host/id/bt_id_get/testcase.yaml deleted file mode 100644 index 4a8c02bc9ca1f..0000000000000 --- a/tests/bluetooth/host/id/bt_id_get/testcase.yaml +++ /dev/null @@ -1,7 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_id_get.default: - type: unit diff --git a/tests/bluetooth/host/id/bt_id_init/CMakeLists.txt b/tests/bluetooth/host/id/bt_id_init/CMakeLists.txt deleted file mode 100644 index 825d83631bcb1..0000000000000 --- a/tests/bluetooth/host/id/bt_id_init/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -project(bt_id_init) - -# Suppress the format-zero-length error if GNUC is used -if (CMAKE_C_COMPILER_ID MATCHES "GNU") -add_compile_options(-Wno-error=format-zero-length -Wno-format-zero-length) -endif() - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_setup_public_identity.c - src/test_suite_setup_static_random_identity.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/id.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -) diff --git a/tests/bluetooth/host/id/bt_id_init/prj.conf b/tests/bluetooth/host/id/bt_id_init/prj.conf deleted file mode 100644 index 5f8cdcef01788..0000000000000 --- a/tests/bluetooth/host/id/bt_id_init/prj.conf +++ /dev/null @@ -1,8 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_ID_MAX=2 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/id/bt_id_init/src/main.c b/tests/bluetooth/host/id/bt_id_init/src/main.c deleted file mode 100644 index 96175434bc3ab..0000000000000 --- a/tests/bluetooth/host/id/bt_id_init/src/main.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/crypto.h" -#include "mocks/hci_core.h" -#include "mocks/kernel.h" -#include "mocks/kernel_expects.h" -#include "mocks/smp.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include - -DEFINE_FFF_GLOBALS; - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - - KERNEL_FFF_FAKES_LIST(RESET_FAKE); - SMP_FFF_FAKES_LIST(RESET_FAKE); - CRYPTO_FFF_FAKES_LIST(RESET_FAKE); - HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(bt_id_init, NULL, NULL, NULL, NULL, NULL); - -/* - * Test initializing the device identity by calling bt_id_init() while the device identity count - * bt_dev.id_count isn't 0. - * - * Constraints: - * - bt_dev.id_count is set to value greater than 0 - * - * Expected behaviour: - * - bt_id_init() returns 0 and identity count isn't changed - */ -ZTEST(bt_id_init, test_init_dev_identity_while_valid_identities_exist) -{ - int err; - - bt_dev.id_count = 1; - - err = bt_id_init(); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_true(bt_dev.id_count == 1, "Incorrect value '%d' was set to bt_dev.id_count", - bt_dev.id_count); - -#if defined(CONFIG_BT_PRIVACY) - expect_single_call_k_work_init_delayable(&bt_dev.rpa_update); -#endif -} - -/* - * Test initializing the device identity by calling bt_id_init() while the device identity count - * bt_dev.id_count is set to 0 and 'CONFIG_BT_SETTINGS' is enabled. - * - * Constraints: - * - bt_dev.id_count is set 0 - * - 'CONFIG_BT_SETTINGS' is enabled - * - * Expected behaviour: - * - bt_id_init() returns 0 and identity count isn't changed - */ -ZTEST(bt_id_init, test_init_dev_identity_while_bt_settings_enabled) -{ - int err; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_SETTINGS); - - err = bt_id_init(); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_true(bt_dev.id_count == 0, "Incorrect value '%d' was set to bt_dev.id_count", - bt_dev.id_count); - -#if defined(CONFIG_BT_PRIVACY) - expect_single_call_k_work_init_delayable(&bt_dev.rpa_update); -#endif -} diff --git a/tests/bluetooth/host/id/bt_id_init/src/test_suite_setup_public_identity.c b/tests/bluetooth/host/id/bt_id_init/src/test_suite_setup_public_identity.c deleted file mode 100644 index bd80a5d9fc9cd..0000000000000 --- a/tests/bluetooth/host/id/bt_id_init/src/test_suite_setup_public_identity.c +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/crypto.h" -#include "mocks/hci_core.h" -#include "mocks/kernel.h" -#include "mocks/kernel_expects.h" -#include "mocks/smp.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include - -/* Hold data representing HCI command response for command BT_HCI_OP_READ_BD_ADDR */ -static struct net_buf hci_cmd_rsp; - -/* Hold data representing response data for HCI command BT_HCI_OP_READ_BD_ADDR */ -static struct bt_hci_rp_read_bd_addr hci_rp_read_bd_addr; - -static void tc_setup(void *f) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - memset(&hci_cmd_rsp, 0x00, sizeof(struct net_buf)); - memset(&hci_rp_read_bd_addr, 0x00, sizeof(struct bt_hci_rp_read_bd_addr)); -} - -ZTEST_SUITE(bt_id_init_setup_public_identity, NULL, NULL, tc_setup, NULL, NULL); - -static int bt_hci_cmd_send_sync_custom_fake(uint16_t opcode, struct net_buf *buf, - struct net_buf **rsp) -{ - const char *func_name = "bt_hci_cmd_send_sync"; - - zassert_equal(opcode, BT_HCI_OP_READ_BD_ADDR, "'%s()' was called with incorrect '%s' value", - func_name, "opcode"); - zassert_is_null(buf, "'%s()' was called with incorrect '%s' value", func_name, "buf"); - zassert_not_null(rsp, "'%s()' was called with incorrect '%s' value", func_name, "rsp"); - - *rsp = &hci_cmd_rsp; - hci_cmd_rsp.data = (void *)&hci_rp_read_bd_addr; - - return 0; -} - -/* - * Test initializing the device identity with public address by calling bt_id_init() while the - * device has no identity and bt_dev.id_count is set to 0. - * bt_setup_public_id_addr() should return 0 (success). - * - * Constraints: - * - bt_dev.id_count is set to 0 - * - bt_setup_public_id_addr() succeeds and returns 0 - * - * Expected behaviour: - * - bt_id_init() returns 0 - * - bt_dev.id_count is set to 1 - */ -ZTEST(bt_id_init_setup_public_identity, test_init_dev_identity_succeeds) -{ - int err; - struct bt_hci_rp_read_bd_addr *rp = (void *)&hci_rp_read_bd_addr; - - bt_addr_copy(&rp->bdaddr, BT_ADDR); - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_SETTINGS); - - err = bt_id_init(); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_mem_equal(&bt_dev.id_addr[BT_ID_DEFAULT], BT_LE_ADDR, sizeof(bt_addr_le_t), - "Incorrect address was set"); - zassert_true(bt_dev.id_count == 1, "Incorrect value '%d' was set to bt_dev.id_count", - bt_dev.id_count); - -#if defined(CONFIG_BT_PRIVACY) - expect_single_call_k_work_init_delayable(&bt_dev.rpa_update); -#endif -} - -/* - * Test initializing the device identity with public address by calling bt_id_init() while the - * device has no identity and bt_dev.id_count is set to 0. - * bt_setup_public_id_addr() should return a negative value (failure). - * - * Constraints: - * - bt_dev.id_count is set to 0 - * - bt_setup_public_id_addr() fails in setting up device identity - * - * Expected behaviour: - * - bt_id_init() returns a negative error code (failure) - */ -ZTEST(bt_id_init_setup_public_identity, test_init_dev_identity_fails) -{ - int err; - struct bt_hci_rp_read_bd_addr *rp = (void *)&hci_rp_read_bd_addr; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - - bt_addr_copy(&rp->bdaddr, BT_ADDR); - bt_rand_fake.return_val = -1; - bt_smp_irk_get_fake.return_val = -1; - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - err = bt_id_init(); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); -} diff --git a/tests/bluetooth/host/id/bt_id_init/src/test_suite_setup_static_random_identity.c b/tests/bluetooth/host/id/bt_id_init/src/test_suite_setup_static_random_identity.c deleted file mode 100644 index 67c9e110c9bbf..0000000000000 --- a/tests/bluetooth/host/id/bt_id_init/src/test_suite_setup_static_random_identity.c +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/crypto.h" -#include "mocks/hci_core.h" -#include "mocks/kernel.h" -#include "mocks/kernel_expects.h" -#include "mocks/smp.h" -#include "testing_common_defs.h" - -#include -#include -#include -#include - -#include -#include - -/* Hold data representing HCI command response for command BT_HCI_OP_VS_READ_STATIC_ADDRS */ -static struct net_buf hci_cmd_rsp; - -/* Hold data representing response data for HCI command BT_HCI_OP_VS_READ_STATIC_ADDRS */ -static struct custom_bt_hci_rp_vs_read_static_addrs { - struct bt_hci_rp_vs_read_static_addrs hci_rp_vs_read_static_addrs; - struct bt_hci_vs_static_addr hci_vs_static_addr[CONFIG_BT_ID_MAX]; -} __packed hci_cmd_rsp_data; - -static void tc_setup(void *f) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - memset(&hci_cmd_rsp, 0x00, sizeof(struct net_buf)); - memset(&hci_cmd_rsp_data, 0x00, sizeof(struct custom_bt_hci_rp_vs_read_static_addrs)); - - HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_SUITE(bt_id_init_setup_static_random_identity, NULL, NULL, tc_setup, NULL, NULL); - -static int bt_hci_cmd_send_sync_custom_fake(uint16_t opcode, struct net_buf *buf, - struct net_buf **rsp) -{ - const char *func_name = "bt_hci_cmd_send_sync"; - - /* When bt_setup_public_id_addr() is called, this will make it returns 0 without changing - * bt_dev.id_count value - */ - if (opcode == BT_HCI_OP_READ_BD_ADDR) { - return -1; - } - - zassert_equal(opcode, BT_HCI_OP_VS_READ_STATIC_ADDRS, - "'%s()' was called with incorrect '%s' value", func_name, "opcode"); - zassert_is_null(buf, "'%s()' was called with incorrect '%s' value", func_name, "buf"); - zassert_not_null(rsp, "'%s()' was called with incorrect '%s' value", func_name, "rsp"); - - *rsp = &hci_cmd_rsp; - hci_cmd_rsp.data = (void *)&hci_cmd_rsp_data.hci_rp_vs_read_static_addrs; - - return 0; -} - -/* - * Test initializing the device identity with static random address by calling bt_id_init() while - * the device has no identity and bt_dev.id_count is set to 0. - * bt_setup_public_id_addr() should fail to setup the identity with public address, so the function - * should attempt to setup a static random identity. - * - * Constraints: - * - bt_dev.id_count is set to 0 - * - bt_setup_public_id_addr() returns 0 without setting up the device identity - * - bt_setup_random_id_addr() returns 0 (success) - * - set_random_address() returns 0 (success) - * - * Expected behaviour: - * - bt_id_init() returns 0 - * - bt_dev.id_count is set to 1 - */ -ZTEST(bt_id_init_setup_static_random_identity, test_init_dev_identity_succeeds) -{ - int err; - uint16_t *vs_commands = (uint16_t *)bt_dev.vs_commands; - struct bt_hci_rp_vs_read_static_addrs *rp = - (void *)&hci_cmd_rsp_data.hci_rp_vs_read_static_addrs; - struct bt_hci_vs_static_addr *static_addr = (void *)&hci_cmd_rsp_data.hci_vs_static_addr; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_SETTINGS); - - /* This part will make bt_setup_random_id_addr() returns 0 (success) and sets - * bt_dev.id_count value to 1 - */ - *vs_commands = (1 << BT_VS_CMD_BIT_READ_STATIC_ADDRS); - - rp->num_addrs = 1; - bt_addr_copy(&static_addr[0].bdaddr, &BT_STATIC_RANDOM_LE_ADDR_1->a); - - hci_cmd_rsp.len = sizeof(struct bt_hci_rp_vs_read_static_addrs) + - rp->num_addrs * sizeof(struct bt_hci_vs_static_addr); - - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - /* This will make set_random_address() succeeds and returns 0 */ - bt_addr_copy(&bt_dev.random_addr.a, &BT_STATIC_RANDOM_LE_ADDR_1->a); - - err = bt_id_init(); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - - zassert_true(bt_dev.id_count == 1, "Incorrect value '%d' was set to bt_dev.id_count", - bt_dev.id_count); - - zassert_mem_equal(&bt_dev.id_addr[0], BT_STATIC_RANDOM_LE_ADDR_1, sizeof(bt_addr_le_t), - "Incorrect address was set"); - -#if defined(CONFIG_BT_PRIVACY) - expect_single_call_k_work_init_delayable(&bt_dev.rpa_update); -#endif -} - -/* - * Test initializing the device identity with static random address by calling bt_id_init() while - * the device has no identity and bt_dev.id_count is set to 0. - * bt_setup_public_id_addr() should fail to setup the identity with public address, so the function - * should attempt to setup a static random identity which should fail as well when - * bt_setup_random_id_addr() is called. - * - * Constraints: - * - bt_dev.id_count is set to 0 - * - bt_setup_public_id_addr() returns 0 without setting up the device identity - * - bt_setup_random_id_addr() returns a negative error code (failure) - * - * Expected behaviour: - * - bt_id_init() returns a negative error code (failure) - */ -ZTEST(bt_id_init_setup_static_random_identity, test_init_dev_identity_bt_setup_random_id_addr_fails) -{ - int err; - uint16_t *vs_commands = (uint16_t *)bt_dev.vs_commands; - struct bt_hci_rp_vs_read_static_addrs *rp = - (void *)&hci_cmd_rsp_data.hci_rp_vs_read_static_addrs; - struct bt_hci_vs_static_addr *static_addr = (void *)&hci_cmd_rsp_data.hci_vs_static_addr; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - - /* This part will make bt_setup_random_id_addr() returns a negative number representing an - * execution error - */ - *vs_commands = (1 << BT_VS_CMD_BIT_READ_STATIC_ADDRS); - - rp->num_addrs = 1; - bt_addr_copy(&static_addr[0].bdaddr, &BT_STATIC_RANDOM_LE_ADDR_1->a); - - hci_cmd_rsp.len = sizeof(struct bt_hci_rp_vs_read_static_addrs) + - rp->num_addrs * sizeof(struct bt_hci_vs_static_addr); - - bt_rand_fake.return_val = -1; - bt_smp_irk_get_fake.return_val = -1; - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - err = bt_id_init(); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); -} - -/* - * Test initializing the device identity with static random address by calling bt_id_init() while - * the device has no identity and bt_dev.id_count is set to 0. - * bt_setup_public_id_addr() should fail to setup the identity with public address, so the function - * should attempt to setup a static random identity which should fail as well when - * bt_setup_random_id_addr() is called. - * - * Constraints: - * - bt_dev.id_count is set to 0 - * - bt_setup_public_id_addr() returns 0 without setting up the device identity - * - bt_setup_random_id_addr() returns 0 (success) - * - set_random_address() returns a negative error code (failure) - * - * Expected behaviour: - * - bt_id_init() returns a negative error code (failure) - */ -ZTEST(bt_id_init_setup_static_random_identity, test_init_dev_identity_set_random_address_fails) -{ - int err; - uint16_t *vs_commands = (uint16_t *)bt_dev.vs_commands; - struct bt_hci_rp_vs_read_static_addrs *rp = - (void *)&hci_cmd_rsp_data.hci_rp_vs_read_static_addrs; - struct bt_hci_vs_static_addr *static_addr = (void *)&hci_cmd_rsp_data.hci_vs_static_addr; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_SETTINGS); - - /* This part will make bt_setup_random_id_addr() returns 0 (success) and sets - * bt_dev.id_count value to 1 - */ - *vs_commands = (1 << BT_VS_CMD_BIT_READ_STATIC_ADDRS); - - rp->num_addrs = 1; - bt_addr_copy(&static_addr[0].bdaddr, &BT_STATIC_RANDOM_LE_ADDR_1->a); - - hci_cmd_rsp.len = sizeof(struct bt_hci_rp_vs_read_static_addrs) + - rp->num_addrs * sizeof(struct bt_hci_vs_static_addr); - - /* This will make set_random_address() returns a negative number error code */ - bt_hci_cmd_alloc_fake.return_val = NULL; - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - err = bt_id_init(); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); -} diff --git a/tests/bluetooth/host/id/bt_id_init/testcase.yaml b/tests/bluetooth/host/id/bt_id_init/testcase.yaml deleted file mode 100644 index 6920b84cab03e..0000000000000 --- a/tests/bluetooth/host/id/bt_id_init/testcase.yaml +++ /dev/null @@ -1,17 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_id_init.default: - type: unit - bluetooth.host.bt_id_init.default_bt_settings_enabled: - type: unit - extra_configs: - - CONFIG_SETTINGS=y - - CONFIG_BT_SETTINGS=y - bluetooth.host.bt_id_init.bt_privacy_enabled: - type: unit - extra_configs: - - CONFIG_BT_SMP=y - - CONFIG_BT_PRIVACY=y diff --git a/tests/bluetooth/host/id/bt_id_read_public_addr/CMakeLists.txt b/tests/bluetooth/host/id/bt_id_read_public_addr/CMakeLists.txt deleted file mode 100644 index 57f5e30d3bb65..0000000000000 --- a/tests/bluetooth/host/id/bt_id_read_public_addr/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -project(bt_id_read_public_addr) - -# Suppress the format-zero-length error if GNUC is used -if (CMAKE_C_COMPILER_ID MATCHES "GNU") -add_compile_options(-Wno-error=format-zero-length -Wno-format-zero-length) -endif() - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_invalid_inputs.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/id.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -) diff --git a/tests/bluetooth/host/id/bt_id_read_public_addr/prj.conf b/tests/bluetooth/host/id/bt_id_read_public_addr/prj.conf deleted file mode 100644 index 42703d413005e..0000000000000 --- a/tests/bluetooth/host/id/bt_id_read_public_addr/prj.conf +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/id/bt_id_read_public_addr/src/main.c b/tests/bluetooth/host/id/bt_id_read_public_addr/src/main.c deleted file mode 100644 index ff388c712ceb1..0000000000000 --- a/tests/bluetooth/host/id/bt_id_read_public_addr/src/main.c +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/hci_core.h" -#include "mocks/hci_core_expects.h" -#include "mocks/net_buf.h" -#include "mocks/net_buf_expects.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include - -DEFINE_FFF_GLOBALS; - -/* Hold data representing HCI command response for command BT_HCI_OP_READ_BD_ADDR */ -static struct net_buf hci_cmd_rsp; - -/* Hold data representing response data for HCI command BT_HCI_OP_READ_BD_ADDR */ -static struct bt_hci_rp_read_bd_addr hci_rp_read_bd_addr; - -static void tc_setup(void *f) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - memset(&hci_cmd_rsp, 0x00, sizeof(struct net_buf)); - memset(&hci_rp_read_bd_addr, 0x00, sizeof(struct bt_hci_rp_read_bd_addr)); - NET_BUF_FFF_FAKES_LIST(RESET_FAKE); - HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_SUITE(bt_id_read_public_addr, NULL, NULL, tc_setup, NULL, NULL); - -/* - * Test reading controller public address through bt_hci_cmd_send_sync(), but - * operation fails and a non-success error code is returned. - * - * Constraints: - * - A valid address reference is passed to bt_id_read_public_addr() - * - bt_hci_cmd_send_sync() returns a non-zero error code - * - * Expected behaviour: - * - Execution stops and a zero return value is returned which represents failure - */ -ZTEST(bt_id_read_public_addr, test_bt_hci_cmd_send_sync_returns_err) -{ - int err; - bt_addr_le_t addr; - - bt_hci_cmd_send_sync_fake.return_val = 1; - - err = bt_id_read_public_addr(&addr); - - expect_single_call_bt_hci_cmd_send_sync(BT_HCI_OP_READ_BD_ADDR); - expect_not_called_net_buf_unref(); - - zassert_true(err == 0, "Unexpected error code '%d' was returned", err); -} - -static int bt_hci_cmd_send_sync_custom_fake(uint16_t opcode, struct net_buf *buf, - struct net_buf **rsp) -{ - const char *func_name = "bt_hci_cmd_send_sync"; - - zassert_equal(opcode, BT_HCI_OP_READ_BD_ADDR, "'%s()' was called with incorrect '%s' value", - func_name, "opcode"); - zassert_is_null(buf, "'%s()' was called with incorrect '%s' value", func_name, "buf"); - zassert_not_null(rsp, "'%s()' was called with incorrect '%s' value", func_name, "rsp"); - - *rsp = &hci_cmd_rsp; - hci_cmd_rsp.data = (void *)&hci_rp_read_bd_addr; - - return 0; -} - -/* - * Test reading controller public address through bt_hci_cmd_send_sync(). - * Although, bt_hci_cmd_send_sync() return value is success but response data contains - * an invalid BT address - * - * Constraints: - * - A valid address reference is passed to bt_id_read_public_addr() - * - bt_hci_cmd_send_sync() returns zero - * - Response data contains invalid address - * - * Expected behaviour: - * - Execution stops and a zero return value is returned which represents failure - */ -ZTEST(bt_id_read_public_addr, test_bt_hci_cmd_send_sync_response_has_invalid_bt_address) -{ - int err; - bt_addr_le_t addr; - const bt_addr_t *invalid_bt_address[] = {BT_ADDR_ANY, BT_ADDR_NONE}; - struct bt_hci_rp_read_bd_addr *rp = (void *)&hci_rp_read_bd_addr; - - for (size_t i = 0; i < ARRAY_SIZE(invalid_bt_address); i++) { - - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - memset(&hci_cmd_rsp, 0x00, sizeof(struct net_buf)); - memset(&hci_rp_read_bd_addr, 0x00, sizeof(struct bt_hci_rp_read_bd_addr)); - NET_BUF_FFF_FAKES_LIST(RESET_FAKE); - HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); - - bt_addr_copy(&rp->bdaddr, invalid_bt_address[i]); - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - err = bt_id_read_public_addr(&addr); - - expect_single_call_bt_hci_cmd_send_sync(BT_HCI_OP_READ_BD_ADDR); - expect_single_call_net_buf_unref(&hci_cmd_rsp); - - zassert_true(err == 0, "Unexpected error code '%d' was returned", err); - } -} - -/* - * Test reading controller public address through bt_hci_cmd_send_sync(). - * bt_hci_cmd_send_sync() return value is success and response data contains a valid BT address. - * - * Constraints: - * - A valid address reference is passed to bt_id_read_public_addr() - * - bt_hci_cmd_send_sync() returns zero - * - Response data contains a valid address - * - * Expected behaviour: - * - Return value is success - */ -ZTEST(bt_id_read_public_addr, test_bt_hci_cmd_send_sync_response_has_valid_bt_address) -{ - int err; - bt_addr_le_t addr; - struct bt_hci_rp_read_bd_addr *rp = (void *)&hci_rp_read_bd_addr; - - bt_addr_copy(&rp->bdaddr, &BT_LE_ADDR->a); - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - err = bt_id_read_public_addr(&addr); - - expect_single_call_bt_hci_cmd_send_sync(BT_HCI_OP_READ_BD_ADDR); - expect_single_call_net_buf_unref(&hci_cmd_rsp); - - zassert_true(err == 1, "Unexpected error code '%d' was returned", err); - zassert_mem_equal(&addr, BT_LE_ADDR, sizeof(bt_addr_le_t), "Incorrect address was set"); -} diff --git a/tests/bluetooth/host/id/bt_id_read_public_addr/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/id/bt_id_read_public_addr/src/test_suite_invalid_inputs.c deleted file mode 100644 index 8ecd97624e173..0000000000000 --- a/tests/bluetooth/host/id/bt_id_read_public_addr/src/test_suite_invalid_inputs.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" - -#include -#include -#include - -#include - -ZTEST_SUITE(bt_id_read_public_addr_invalid_inputs, NULL, NULL, NULL, NULL, NULL); - -/* - * Test reading controller public address through bt_hci_cmd_send_sync() with NULL address. - * - * Constraints: - * - Address is passed as NULL - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_id_read_public_addr_invalid_inputs, test_null_device_address) -{ - expect_assert(); - bt_id_read_public_addr(NULL); -} diff --git a/tests/bluetooth/host/id/bt_id_read_public_addr/testcase.yaml b/tests/bluetooth/host/id/bt_id_read_public_addr/testcase.yaml deleted file mode 100644 index 6299291bc019d..0000000000000 --- a/tests/bluetooth/host/id/bt_id_read_public_addr/testcase.yaml +++ /dev/null @@ -1,7 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_id_read_public_addr.default: - type: unit diff --git a/tests/bluetooth/host/id/bt_id_reset/CMakeLists.txt b/tests/bluetooth/host/id/bt_id_reset/CMakeLists.txt deleted file mode 100644 index 975ad7ed321b3..0000000000000 --- a/tests/bluetooth/host/id/bt_id_reset/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -project(bt_id_reset) - -# Suppress the format-zero-length error if GNUC is used -if (CMAKE_C_COMPILER_ID MATCHES "GNU") -add_compile_options(-Wno-error=format-zero-length -Wno-format-zero-length) -endif() - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_invalid_inputs.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/id.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -) diff --git a/tests/bluetooth/host/id/bt_id_reset/prj.conf b/tests/bluetooth/host/id/bt_id_reset/prj.conf deleted file mode 100644 index cae35e7d56cb8..0000000000000 --- a/tests/bluetooth/host/id/bt_id_reset/prj.conf +++ /dev/null @@ -1,9 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_SMP=y -CONFIG_BT_ID_MAX=4 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/id/bt_id_reset/src/main.c b/tests/bluetooth/host/id/bt_id_reset/src/main.c deleted file mode 100644 index fca661716a9f8..0000000000000 --- a/tests/bluetooth/host/id/bt_id_reset/src/main.c +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/addr.h" -#include "mocks/addr_expects.h" -#include "mocks/adv.h" -#include "mocks/hci_core.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include - -DEFINE_FFF_GLOBALS; - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - - ADV_FFF_FAKES_LIST(RESET_FAKE); - ADDR_FFF_FAKES_LIST(RESET_FAKE); - HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(bt_id_reset, NULL, NULL, NULL, NULL, NULL); - -static int bt_addr_le_create_static_custom_fake(bt_addr_le_t *addr) -{ - const char *func_name = "bt_addr_le_create_static"; - - zassert_not_null(addr, "'%s()' was called with incorrect '%s' value", func_name, "addr"); - - /* This is required to test when the generated address already exists in the ID list */ - if (bt_addr_le_create_static_fake.call_count == 1) { - bt_addr_le_copy(addr, BT_STATIC_RANDOM_LE_ADDR_1); - } else { - bt_addr_le_copy(addr, BT_STATIC_RANDOM_LE_ADDR_2); - } - - return 0; -} - -/* - * Test resetting an ID while using a NULL value for the address. - * As a NULL is passed to bt_id_reset() for the address and 'BT_DEV_ENABLE' is set, - * a new random address is generated. - * - * Constraints: - * - Input address is NULL - * - Input IRK is NULL - * - 'BT_DEV_ENABLE' flag is set in bt_dev.flags - * - bt_addr_le_create_static() returns a zero error code (success) - * - * Expected behaviour: - * - A new identity is created and the address is loaded to bt_dev.id_addr[] - * - bt_dev.id_count isn't changed - */ -ZTEST(bt_id_reset, test_reset_id_null_address) -{ - uint8_t input_id; - int id_count, returned_id; - - bt_dev.id_count = 2; - input_id = bt_dev.id_count - 1; /* ID must not equal BT_ID_DEFAULT */ - id_count = bt_dev.id_count; - atomic_set_bit(bt_dev.flags, BT_DEV_ENABLE); - bt_addr_le_create_static_fake.custom_fake = bt_addr_le_create_static_custom_fake; - - returned_id = bt_id_reset(input_id, NULL, NULL); - - expect_call_count_bt_addr_le_create_static(1); - - zassert_true(returned_id >= 0, "Unexpected error code '%d' was returned", returned_id); - zassert_equal(returned_id, input_id, "Incorrect ID %d was returned", returned_id); - zassert_true(bt_dev.id_count == id_count, "Incorrect ID count %d was set", bt_dev.id_count); - zassert_mem_equal(&bt_dev.id_addr[returned_id], BT_STATIC_RANDOM_LE_ADDR_1, - sizeof(bt_addr_le_t), "Incorrect address was set"); -} - -/* - * Test resetting an identity and generating a new one while ensuring that the generated address - * isn't in the ID list. As a NULL is passed to bt_id_reset() for the address and 'BT_DEV_ENABLE' - * is set, a new random address is generated. - * - * Constraints: - * - Input address is NULL - * - Input IRK is NULL - * - 'BT_DEV_ENABLE' flag is set in bt_dev.flags - * - bt_addr_le_create_static() returns a zero error code (success) - * - * Expected behaviour: - * - A new identity is created and the address is loaded to bt_dev.id_addr[] - * - bt_dev.id_count isn't changed - */ -ZTEST(bt_id_reset, test_reset_id_null_address_with_no_duplication) -{ - uint8_t input_id; - int id_count, returned_id; - - bt_dev.id_count = 2; - bt_addr_le_copy(&bt_dev.id_addr[0], BT_STATIC_RANDOM_LE_ADDR_1); - - input_id = bt_dev.id_count - 1; /* ID must not equal BT_ID_DEFAULT */ - id_count = bt_dev.id_count; - atomic_set_bit(bt_dev.flags, BT_DEV_ENABLE); - bt_addr_le_create_static_fake.custom_fake = bt_addr_le_create_static_custom_fake; - - returned_id = bt_id_reset(input_id, NULL, NULL); - - expect_call_count_bt_addr_le_create_static(2); - - zassert_true(returned_id >= 0, "Unexpected error code '%d' was returned", returned_id); - zassert_equal(returned_id, input_id, "Incorrect ID %d was returned", returned_id); - zassert_true(bt_dev.id_count == id_count, "Incorrect ID count %d was set", bt_dev.id_count); - zassert_mem_equal(&bt_dev.id_addr[returned_id], BT_STATIC_RANDOM_LE_ADDR_2, - sizeof(bt_addr_le_t), "Incorrect address was set"); -} - -/* - * Test resetting an identity and using BT_ADDR_LE_ANY as an input. - * As an initialized address to BT_ADDR_LE_ANY is passed to bt_id_reset() for the address and - * 'BT_DEV_ENABLE' is set, a new random address is generated. - * The generated address should be copied to the address reference passed - * - * Constraints: - * - Input address is NULL - * - Input IRK is NULL - * - 'BT_DEV_ENABLE' flag is set in bt_dev.flags - * - bt_addr_le_create_static() returns a zero error code (success) - * - * Expected behaviour: - * - A new identity is created and the address is loaded to bt_dev.id_addr[] - * - bt_dev.id_count isn't changed - * - Generated address is copied to the address reference passed - */ -ZTEST(bt_id_reset, test_reset_id_bt_addr_le_any_address) -{ - uint8_t input_id; - int id_count, returned_id; - bt_addr_le_t addr = bt_addr_le_any; - - bt_dev.id_count = 2; - input_id = bt_dev.id_count - 1; /* ID must not equal BT_ID_DEFAULT */ - id_count = bt_dev.id_count; - atomic_set_bit(bt_dev.flags, BT_DEV_ENABLE); - bt_addr_le_create_static_fake.custom_fake = bt_addr_le_create_static_custom_fake; - - returned_id = bt_id_reset(input_id, &addr, NULL); - - expect_call_count_bt_addr_le_create_static(1); - - zassert_true(returned_id >= 0, "Unexpected error code '%d' was returned", returned_id); - zassert_equal(returned_id, input_id, "Incorrect ID %d was returned", returned_id); - zassert_true(bt_dev.id_count == id_count, "Incorrect ID count %d was set", bt_dev.id_count); - zassert_mem_equal(&bt_dev.id_addr[returned_id], BT_STATIC_RANDOM_LE_ADDR_1, - sizeof(bt_addr_le_t), "Incorrect address was set"); - zassert_mem_equal(&addr, BT_STATIC_RANDOM_LE_ADDR_1, sizeof(bt_addr_le_t), - "Incorrect address was set"); -} - -/* - * Test resetting an identity, but bt_addr_le_create_static() returns an error. - * - * Constraints: - * - Input address is NULL - * - Input IRK is NULL - * - 'BT_DEV_ENABLE' flag is set in bt_dev.flags - * - bt_addr_le_create_static() returns a non-zero error code (failure) - * - * Expected behaviour: - * - No new identity is created - * - bt_dev.id_count is kept unchanged - */ -ZTEST(bt_id_reset, test_reset_id_null_address_fails) -{ - uint8_t input_id; - int id_count, err; - - bt_dev.id_count = 2; - input_id = bt_dev.id_count - 1; /* ID must not equal BT_ID_DEFAULT */ - id_count = bt_dev.id_count; - atomic_set_bit(bt_dev.flags, BT_DEV_ENABLE); - bt_addr_le_create_static_fake.return_val = -1; - - err = bt_id_reset(input_id, NULL, NULL); - - expect_call_count_bt_addr_le_create_static(1); - - zassert_true(err == -1, "Unexpected error code '%d' was returned", err); - zassert_true(bt_dev.id_count == id_count, "Incorrect ID count %d was set", bt_dev.id_count); -} - -/* - * Test resetting an identity while a valid random static address is passed to bt_id_reset() for - * the address and 'BT_DEV_ENABLE' is set. - * The same address is used and copied to bt_dev.id_addr[]. - * - * Constraints: - * - Valid private random address is used - * - Input IRK is NULL - * - 'BT_DEV_ENABLE' flag is set in bt_dev.flags - * - * Expected behaviour: - * - The same address is used and loaded to bt_dev.id_addr[] - * - bt_dev.id_count is kept unchanged - */ -ZTEST(bt_id_reset, test_reset_id_valid_input_address) -{ - uint8_t input_id; - int id_count, returned_id; - bt_addr_le_t addr = *BT_STATIC_RANDOM_LE_ADDR_1; - - bt_dev.id_count = 2; - input_id = bt_dev.id_count - 1; /* ID must not equal BT_ID_DEFAULT */ - id_count = bt_dev.id_count; - atomic_set_bit(bt_dev.flags, BT_DEV_ENABLE); - /* Calling bt_addr_le_create_static() isn't expected */ - bt_addr_le_create_static_fake.return_val = -1; - - returned_id = bt_id_reset(input_id, &addr, NULL); - - expect_not_called_bt_addr_le_create_static(); - - zassert_true(returned_id >= 0, "Unexpected error code '%d' was returned", returned_id); - zassert_equal(returned_id, input_id, "Incorrect ID %d was returned", returned_id); - zassert_true(bt_dev.id_count == id_count, "Incorrect ID count %d was set", bt_dev.id_count); - zassert_mem_equal(&bt_dev.id_addr[returned_id], BT_STATIC_RANDOM_LE_ADDR_1, - sizeof(bt_addr_le_t), "Incorrect address was set"); -} diff --git a/tests/bluetooth/host/id/bt_id_reset/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/id/bt_id_reset/src/test_suite_invalid_inputs.c deleted file mode 100644 index 8fc97715bda60..0000000000000 --- a/tests/bluetooth/host/id/bt_id_reset/src/test_suite_invalid_inputs.c +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/adv.h" -#include "mocks/adv_expects.h" -#include "mocks/hci_core.h" -#include "mocks/hci_core_expects.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include - -ZTEST_SUITE(bt_id_reset_invalid_inputs, NULL, NULL, NULL, NULL, NULL); - -/* - * Test resetting default ID which shouldn't be allowed - * - * Constraints: - * - BT_ID_DEFAULT value is used for the ID - * - Input address is NULL - * - Input IRK is NULL - * - * Expected behaviour: - * - '-EINVAL' error code is returned representing invalid values were used. - */ -ZTEST(bt_id_reset_invalid_inputs, test_resetting_default_id) -{ - int err; - - err = bt_id_reset(BT_ID_DEFAULT, NULL, NULL); - - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); -} - -/* - * Test resetting ID value that is equal to bt_dev.id_count - * - * Constraints: - * - bt_dev.id_count is greater than 0 - * - ID value used is equal to bt_dev.id_count - * - Input address is NULL - * - Input IRK is NULL - * - * Expected behaviour: - * - '-EINVAL' error code is returned representing invalid values were used. - */ -ZTEST(bt_id_reset_invalid_inputs, test_resetting_id_value_equal_to_dev_id_count) -{ - int err; - - bt_dev.id_count = 1; - - err = bt_id_reset(bt_dev.id_count, NULL, NULL); - - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); -} - -/* - * Test using a valid IRK pointer value while privacy isn't enabled - * - * Constraints: - * - BT_ID_DEFAULT is used for the ID - * - Input address is NULL - * - Input IRK isn't NULL - * - 'CONFIG_BT_PRIVACY' isn't enabled - * - * Expected behaviour: - * - '-EINVAL' error code is returned representing invalid values were used. - */ -ZTEST(bt_id_reset_invalid_inputs, test_null_addr_valid_irk_no_privacy_enabled) -{ - int err; - uint8_t valid_irk_ptr[16]; - - err = bt_id_reset(BT_ID_DEFAULT, NULL, valid_irk_ptr); - - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); -} - -/* - * Test invalid input arguments to bt_id_reset() by using a valid address of type public and using - * NULL value for the IRK. - * - * Constraints: - * - BT_ID_DEFAULT is used for the ID - * - A valid address of type public is used - * - Input IRK is NULL - * - * Expected behaviour: - * - '-EINVAL' error code is returned representing invalid values were used. - */ -ZTEST(bt_id_reset_invalid_inputs, test_public_address) -{ - int err; - - err = bt_id_reset(BT_ID_DEFAULT, BT_LE_ADDR, NULL); - - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); -} - -/* - * Test invalid input arguments to bt_id_reset() by using a valid address of type RPA and using - * NULL value for the IRK. - * - * Constraints: - * - BT_ID_DEFAULT is used for the ID - * - An RPA address of type random is used - * - Input IRK is NULL - * - * Expected behaviour: - * - '-EINVAL' error code is returned representing invalid values were used. - */ -ZTEST(bt_id_reset_invalid_inputs, test_rpa_address) -{ - int err; - - err = bt_id_reset(BT_ID_DEFAULT, BT_RPA_LE_ADDR, NULL); - - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); -} - -/* - * Test invalid input arguments to bt_id_reset() by using an address that already exists - * in the identity list. - * - * Constraints: - * - BT_ID_DEFAULT is used for the ID - * - A valid random static address is used - * - Input address already exists in the identity list - * - Input IRK is NULL - * - * Expected behaviour: - * - '-EALREADY' error code is returned representing invalid values were used. - */ -ZTEST(bt_id_reset_invalid_inputs, test_pa_address_exists_in_id_list) -{ - int err; - - bt_dev.id_count = 1; - bt_addr_le_copy(&bt_dev.id_addr[0], BT_STATIC_RANDOM_LE_ADDR_1); - - err = bt_id_reset(BT_ID_DEFAULT, BT_STATIC_RANDOM_LE_ADDR_1, NULL); - - zassert_true(err == -EALREADY, "Unexpected error code '%d' was returned", err); -} - -static void bt_le_ext_adv_foreach_custom_fake(void (*func)(struct bt_le_ext_adv *adv, void *data), - void *data) -{ - struct bt_le_ext_adv adv_params = {0}; - - __ASSERT_NO_MSG(func != NULL); - __ASSERT_NO_MSG(data != NULL); - - if (IS_ENABLED(CONFIG_BT_EXT_ADV)) { - /* Only check if the ID is in use, as the advertiser can be - * started and stopped without reconfiguring parameters. - */ - adv_params.id = bt_dev.id_count - 1; - } else { - atomic_set_bit(adv_params.flags, BT_ADV_ENABLED); - adv_params.id = bt_dev.id_count - 1; - } - - func(&adv_params, data); -} - -/* - * Test resetting an ID if the 'CONFIG_BT_BROADCASTER' is enabled and the same ID is already - * in use with the advertising data. - * - * Constraints: - * - A valid random static address is used - * - Input address doesn't exist in the identity list - * - Input IRK is NULL - * - 'CONFIG_BT_BROADCASTER' is enabled - * - * Expected behaviour: - * - '-EBUSY' error code is returned representing invalid values were used. - */ -ZTEST(bt_id_reset_invalid_inputs, test_resetting_id_used_in_advertising) -{ - int err; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_BROADCASTER); - - bt_dev.id_count = 2; - - /* When bt_le_ext_adv_foreach() is called, this callback will be triggered and causes - * adv_id_check_func() to set the advertising enable flag to true. - */ - bt_le_ext_adv_foreach_fake.custom_fake = bt_le_ext_adv_foreach_custom_fake; - - err = bt_id_reset(bt_dev.id_count - 1, BT_STATIC_RANDOM_LE_ADDR_1, NULL); - - expect_single_call_bt_le_ext_adv_foreach(); - - zassert_true(err == -EBUSY, "Unexpected error code '%d' was returned", err); -} - -/* - * Test returning error when the ID used corresponds to an empty address and bt_unpair() fails - * - * Constraints: - * - A valid random static address is used - * - Input address doesn't exist in the identity list - * - Input IRK is NULL - * - 'CONFIG_BT_CONN' is enabled - * - bt_unpair() fails and returns a negative error code - * - * Expected behaviour: - * - '-EALREADY' error code is returned representing invalid values were used. - */ -ZTEST(bt_id_reset_invalid_inputs, test_bt_unpair_fails) -{ - int err; - uint8_t id; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_CONN); - - bt_dev.id_count = 2; - id = bt_dev.id_count - 1; - - bt_addr_le_copy(&bt_dev.id_addr[0], BT_STATIC_RANDOM_LE_ADDR_1); - bt_addr_le_copy(&bt_dev.id_addr[1], BT_STATIC_RANDOM_LE_ADDR_1); - - bt_unpair_fake.return_val = -1; - - err = bt_id_reset(id, BT_STATIC_RANDOM_LE_ADDR_2, NULL); - - expect_single_call_bt_unpair(id, NULL); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); -} diff --git a/tests/bluetooth/host/id/bt_id_reset/testcase.yaml b/tests/bluetooth/host/id/bt_id_reset/testcase.yaml deleted file mode 100644 index d1396b3d8abd4..0000000000000 --- a/tests/bluetooth/host/id/bt_id_reset/testcase.yaml +++ /dev/null @@ -1,7 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_id_reset.default: - type: unit diff --git a/tests/bluetooth/host/id/bt_id_scan_random_addr_check/CMakeLists.txt b/tests/bluetooth/host/id/bt_id_scan_random_addr_check/CMakeLists.txt deleted file mode 100644 index 70d21a3b6adc9..0000000000000 --- a/tests/bluetooth/host/id/bt_id_scan_random_addr_check/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -project(bt_id_scan_random_addr_check) - -# Suppress the format-zero-length error if GNUC is used -if (CMAKE_C_COMPILER_ID MATCHES "GNU") -add_compile_options(-Wno-error=format-zero-length -Wno-format-zero-length) -endif() - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks mocks) - - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/id.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -) diff --git a/tests/bluetooth/host/id/bt_id_scan_random_addr_check/prj.conf b/tests/bluetooth/host/id/bt_id_scan_random_addr_check/prj.conf deleted file mode 100644 index 5f8cdcef01788..0000000000000 --- a/tests/bluetooth/host/id/bt_id_scan_random_addr_check/prj.conf +++ /dev/null @@ -1,8 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_ID_MAX=2 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/id/bt_id_scan_random_addr_check/src/main.c b/tests/bluetooth/host/id/bt_id_scan_random_addr_check/src/main.c deleted file mode 100644 index f2b4a4ccb6e7a..0000000000000 --- a/tests/bluetooth/host/id/bt_id_scan_random_addr_check/src/main.c +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/adv.h" -#include "mocks/adv_expects.h" - -#include -#include -#include - -#include -#include - -DEFINE_FFF_GLOBALS; - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - - ADV_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(bt_id_scan_random_addr_check, NULL, NULL, NULL, NULL, NULL); - -/* - * Test checking scan random address if broadcaster role isn't enabled - * - * Constraints: - * - 'CONFIG_BT_BROADCASTER' isn't enabled - * - * Expected behaviour: - * - bt_id_scan_random_addr_check() returns true - */ -ZTEST(bt_id_scan_random_addr_check, test_scan_returns_true_broadcaster_role_not_supported) -{ - bool result; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_BROADCASTER); - - result = bt_id_scan_random_addr_check(); - - zassert_true(result, "Incorrect result was returned"); - expect_not_called_bt_le_adv_lookup_legacy(); -} - -/* - * Test checking scan random address if extended advertising is enabled - * - * Constraints: - * - 'CONFIG_BT_EXT_ADV' is enabled - * - * Expected behaviour: - * - bt_id_scan_random_addr_check() returns true - */ -ZTEST(bt_id_scan_random_addr_check, test_scan_returns_true_ext_adv_enabled) -{ - bool result; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_EXT_ADV); - - result = bt_id_scan_random_addr_check(); - - zassert_true(result, "Incorrect result was returned"); - expect_not_called_bt_le_adv_lookup_legacy(); -} - -/* - * Test checking scan random address when broadcaster role is enabled, but - * bt_le_adv_lookup_legacy() fails - * - * Constraints: - * - 'CONFIG_BT_BROADCASTER' is enabled - * - 'CONFIG_BT_EXT_ADV' isn't enabled - * - bt_le_adv_lookup_legacy() returns NULL - * - * Expected behaviour: - * - bt_id_scan_random_addr_check() returns true - */ -ZTEST(bt_id_scan_random_addr_check, test_scan_returns_true_bt_le_adv_lookup_legacy_fails) -{ - bool result; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_BROADCASTER); - Z_TEST_SKIP_IFDEF(CONFIG_BT_EXT_ADV); - - bt_le_adv_lookup_legacy_fake.return_val = NULL; - - result = bt_id_scan_random_addr_check(); - - zassert_true(result, "Incorrect result was returned"); - expect_single_call_bt_le_adv_lookup_legacy(); -} - -/* - * Test checking scan random address when broadcaster role is enabled. - * bt_le_adv_lookup_legacy() returns a valid reference with 'BT_ADV_ENABLED' flag not set - * - * Constraints: - * - 'CONFIG_BT_BROADCASTER' is enabled - * - 'CONFIG_BT_EXT_ADV' isn't enabled - * - bt_le_adv_lookup_legacy() returns a valid reference with 'BT_ADV_ENABLED' flag not set - * - * Expected behaviour: - * - bt_id_scan_random_addr_check() returns true - */ -ZTEST(bt_id_scan_random_addr_check, test_scan_returns_true_advertiser_not_active) -{ - bool result; - struct bt_le_ext_adv adv = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_BROADCASTER); - Z_TEST_SKIP_IFDEF(CONFIG_BT_EXT_ADV); - - atomic_clear_bit(adv.flags, BT_ADV_ENABLED); - bt_le_adv_lookup_legacy_fake.return_val = &adv; - - result = bt_id_scan_random_addr_check(); - - zassert_true(result, "Incorrect result was returned"); - expect_single_call_bt_le_adv_lookup_legacy(); -} - -/* - * Test when privacy is not enabled then the random address will be attempted to be set. - * - * Constraints: - * - 'CONFIG_BT_PRIVACY' isn't enabled - * - 'CONFIG_BT_BROADCASTER' is enabled - * - 'CONFIG_BT_EXT_ADV' isn't enabled - * - bt_le_adv_lookup_legacy() returns a valid reference with 'BT_ADV_ENABLED' flag not set - * - * Expected behaviour: - * - bt_id_scan_random_addr_check() returns false - */ -ZTEST(bt_id_scan_random_addr_check, test_scan_returns_true_advertiser_active_no_privacy) -{ - bool result; - struct bt_le_ext_adv adv = {0}; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_PRIVACY); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_BROADCASTER); - Z_TEST_SKIP_IFDEF(CONFIG_BT_EXT_ADV); - - atomic_set_bit(adv.flags, BT_ADV_ENABLED); - bt_le_adv_lookup_legacy_fake.return_val = &adv; - - result = bt_id_scan_random_addr_check(); - - zassert_true(result, "Incorrect result was returned"); - expect_single_call_bt_le_adv_lookup_legacy(); -} - -/* - * Test that scanner or initiator cannot start if the random address is used by the advertiser for - * an RPA with a different identity or for a random static identity address. - * - * Constraints: - * - 'CONFIG_BT_PRIVACY' is enabled - * - 'CONFIG_BT_BROADCASTER' is enabled - * - 'CONFIG_BT_EXT_ADV' isn't enabled - * - bt_le_adv_lookup_legacy() returns a valid reference with 'BT_ADV_ENABLED' and - * 'BT_ADV_USE_IDENTITY' flags set - * - * Expected behaviour: - * - bt_id_scan_random_addr_check() returns false - */ -ZTEST(bt_id_scan_random_addr_check, test_scan_returns_false_advertiser_active_privacy_enabled) -{ - bool result; - struct bt_le_ext_adv adv = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_BROADCASTER); - Z_TEST_SKIP_IFDEF(CONFIG_BT_EXT_ADV); - - atomic_set_bit(adv.flags, BT_ADV_ENABLED); - atomic_set_bit(adv.flags, BT_ADV_USE_IDENTITY); - bt_dev.id_addr[adv.id].type = BT_ADDR_LE_RANDOM; - bt_le_adv_lookup_legacy_fake.return_val = &adv; - - result = bt_id_scan_random_addr_check(); - - zassert_false(result, "Incorrect result was returned"); - expect_single_call_bt_le_adv_lookup_legacy(); -} diff --git a/tests/bluetooth/host/id/bt_id_scan_random_addr_check/testcase.yaml b/tests/bluetooth/host/id/bt_id_scan_random_addr_check/testcase.yaml deleted file mode 100644 index c48b256d001a9..0000000000000 --- a/tests/bluetooth/host/id/bt_id_scan_random_addr_check/testcase.yaml +++ /dev/null @@ -1,21 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_id_scan_random_addr_check.default: - type: unit - bluetooth.host.bt_id_scan_random_addr_check.broadcaster_enabled: - type: unit - extra_configs: - - CONFIG_BT_BROADCASTER=y - bluetooth.host.bt_id_scan_random_addr_check.broadcaster_privacy_enabled: - type: unit - extra_configs: - - CONFIG_BT_SMP=y - - CONFIG_BT_PRIVACY=y - - CONFIG_BT_BROADCASTER=y - bluetooth.host.bt_id_scan_random_addr_check.bt_ext_adv_enabled: - type: unit - extra_configs: - - CONFIG_BT_EXT_ADV=y diff --git a/tests/bluetooth/host/id/bt_id_set_adv_own_addr/CMakeLists.txt b/tests/bluetooth/host/id/bt_id_set_adv_own_addr/CMakeLists.txt deleted file mode 100644 index 9f4cd28f1a637..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_adv_own_addr/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -project(bt_id_set_adv_own_addr) - -# Suppress the format-zero-length error if GNUC is used -if (CMAKE_C_COMPILER_ID MATCHES "GNU") -add_compile_options(-Wno-error=format-zero-length -Wno-format-zero-length) -endif() - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_invalid_inputs.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/id.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -) diff --git a/tests/bluetooth/host/id/bt_id_set_adv_own_addr/prj.conf b/tests/bluetooth/host/id/bt_id_set_adv_own_addr/prj.conf deleted file mode 100644 index 95e91d3abd683..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_adv_own_addr/prj.conf +++ /dev/null @@ -1,13 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_SMP=y -CONFIG_BT_ID_MAX=4 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y - -# Enabling optimizations will make the test fail. -# Reason is (at the time of writing) unknown. -CONFIG_NO_OPTIMIZATIONS=y diff --git a/tests/bluetooth/host/id/bt_id_set_adv_own_addr/src/main.c b/tests/bluetooth/host/id/bt_id_set_adv_own_addr/src/main.c deleted file mode 100644 index 8304906d37e31..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_adv_own_addr/src/main.c +++ /dev/null @@ -1,348 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/crypto.h" -#include "mocks/scan.h" -#include "mocks/scan_expects.h" -#include "mocks/hci_core.h" -#include "mocks/hci_core_expects.h" -#include "mocks/net_buf.h" -#include "mocks/net_buf_expects.h" -#include "testing_common_defs.h" - -#include -#include -#include -#include - -#include -#include - -DEFINE_FFF_GLOBALS; - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - - CRYPTO_FFF_FAKES_LIST(RESET_FAKE); - HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(bt_id_set_adv_own_addr, NULL, NULL, NULL, NULL, NULL); - -/* - * Test setting the advertising private address through bt_id_set_adv_private_addr() if - * privacy is enabled and 'BT_LE_ADV_OPT_USE_IDENTITY' options bit isn't set. - * - * Constraints: - * - Options 'BT_LE_ADV_OPT_CONN' bit is set - * - Options 'BT_LE_ADV_OPT_USE_IDENTITY' bit isn't set - * - 'CONFIG_BT_PRIVACY' is enabled - * - bt_id_set_adv_private_addr() succeeds and returns 0 - * - * Expected behaviour: - * - bt_id_set_adv_own_addr() succeeds and returns 0 - * - Address type reference is updated - */ -ZTEST(bt_id_set_adv_own_addr, test_bt_id_set_adv_private_addr_succeeds_adv_connectable) -{ - int err; - uint32_t options = 0; - struct bt_le_ext_adv adv = {0}; - uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; - bool dir_adv_test_lut[] = {true, false}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - - options |= BT_LE_ADV_OPT_CONN; - - /* This will cause bt_id_set_adv_private_addr() to return 0 */ - atomic_set_bit(bt_dev.flags, BT_DEV_RPA_VALID); - - for (size_t i = 0; i < ARRAY_SIZE(dir_adv_test_lut); i++) { - err = bt_id_set_adv_own_addr(&adv, options, dir_adv_test_lut[i], &own_addr_type); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_true(own_addr_type == BT_HCI_OWN_ADDR_RANDOM, - "Address type reference was incorrectly set"); - } - - options |= BT_LE_ADV_OPT_DIR_ADDR_RPA; - - bt_dev.le.features[(BT_LE_FEAT_BIT_PRIVACY) >> 3] |= BIT((BT_LE_FEAT_BIT_PRIVACY)&7); - - err = bt_id_set_adv_own_addr(&adv, options, true, &own_addr_type); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_true(own_addr_type == BT_HCI_OWN_ADDR_RPA_OR_RANDOM, - "Address type reference was incorrectly set"); -} - -/* - * Test setting the advertising private address with a static random address through - * bt_id_set_adv_random_addr() if privacy isn't enabled. - * - * Constraints: - * - Options 'BT_LE_ADV_OPT_CONN' bit is set - * - 'CONFIG_BT_PRIVACY' isn't enabled - * - bt_id_set_adv_random_addr() succeeds and returns 0 - * - * Expected behaviour: - * - bt_id_set_adv_own_addr() succeeds and returns 0 - * - Address type reference is updated - */ -ZTEST(bt_id_set_adv_own_addr, test_bt_id_set_adv_random_addr_succeeds_adv_connectable) -{ - int err; - uint32_t options = 0; - struct bt_le_ext_adv adv = {0}; - uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; - bool dir_adv_test_lut[] = {true, false}; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_PRIVACY); - /* If 'CONFIG_BT_EXT_ADV' is defined, it changes bt_id_set_adv_random_addr() behaviour */ - Z_TEST_SKIP_IFDEF(CONFIG_BT_EXT_ADV); - - options |= BT_LE_ADV_OPT_CONN; - - adv.id = 0; - bt_addr_le_copy(&bt_dev.id_addr[adv.id], BT_RPA_LE_ADDR); - - /* This will cause bt_id_set_adv_random_addr() to return 0 */ - bt_addr_copy(&bt_dev.random_addr.a, &BT_RPA_LE_ADDR->a); - - for (size_t i = 0; i < ARRAY_SIZE(dir_adv_test_lut); i++) { - err = bt_id_set_adv_own_addr(&adv, options, dir_adv_test_lut[i], &own_addr_type); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_true(own_addr_type == BT_HCI_OWN_ADDR_RANDOM, - "Address type reference was incorrectly set"); - } - - options |= BT_LE_ADV_OPT_DIR_ADDR_RPA; - - bt_dev.le.features[(BT_LE_FEAT_BIT_PRIVACY) >> 3] |= BIT((BT_LE_FEAT_BIT_PRIVACY)&7); - - err = bt_id_set_adv_own_addr(&adv, options, true, &own_addr_type); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_true(own_addr_type == BT_HCI_OWN_ADDR_RPA_OR_RANDOM, - "Address type reference was incorrectly set"); -} - -/* - * Test setting the advertising private address with a static random address through - * bt_id_set_adv_random_addr() when device isn't advertising as a connectable device (i.e. - * BT_LE_ADV_OPT_CONN bit in options isn't set) and the advertisement is using the device - * identity (i.e. BT_LE_ADV_OPT_USE_IDENTITY bit is set in options). - * - * Constraints: - * - Options 'BT_LE_ADV_OPT_USE_IDENTITY' bit is set - * - Options 'BT_LE_ADV_OPT_CONN' bit isn't set - * - bt_id_set_adv_random_addr() succeeds and returns 0 - * - * Expected behaviour: - * - bt_id_set_adv_own_addr() succeeds and returns 0 - * - Address type reference is updated - */ -ZTEST(bt_id_set_adv_own_addr, test_bt_id_set_adv_random_addr_succeeds_not_connectable) -{ - int err; - uint32_t options = 0; - struct bt_le_ext_adv adv = {0}; - uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; - bool dir_adv_test_lut[] = {true, false}; - - /* If 'CONFIG_BT_EXT_ADV' is defined, it changes bt_id_set_adv_random_addr() behaviour */ - Z_TEST_SKIP_IFDEF(CONFIG_BT_EXT_ADV); - - options |= BT_LE_ADV_OPT_USE_IDENTITY; - options &= ~BT_LE_ADV_OPT_CONN; - - adv.id = 0; - bt_addr_le_copy(&bt_dev.id_addr[adv.id], BT_RPA_LE_ADDR); - - /* This will cause bt_id_set_adv_random_addr() to return 0 */ - bt_addr_copy(&bt_dev.random_addr.a, &BT_RPA_LE_ADDR->a); - - for (size_t i = 0; i < ARRAY_SIZE(dir_adv_test_lut); i++) { - err = bt_id_set_adv_own_addr(&adv, options, dir_adv_test_lut[i], &own_addr_type); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_true(own_addr_type == BT_HCI_OWN_ADDR_RANDOM, - "Address type reference was incorrectly set"); - } -} - -/* - * Test setting the advertising private address through bt_id_set_adv_private_addr() if - * 'BT_LE_ADV_OPT_USE_IDENTITY' and 'BT_LE_ADV_OPT_USE_IDENTITY' options bits aren't set. - * - * Constraints: - * - Options 'BT_LE_ADV_OPT_CONN' bit isn't set - * - Options 'BT_LE_ADV_OPT_USE_IDENTITY' bit isn't set - * - bt_id_set_adv_random_addr() succeeds and returns 0 - * - * Expected behaviour: - * - bt_id_set_adv_own_addr() succeeds and returns 0 - * - Address type reference is updated - */ -ZTEST(bt_id_set_adv_own_addr, test_bt_id_set_adv_private_addr_succeeds_not_connectable) -{ - int err; - uint32_t options = 0; - struct bt_le_ext_adv adv = {0}; - uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; - bool dir_adv_test_lut[] = {true, false}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_EXT_ADV); - - options &= ~BT_LE_ADV_OPT_CONN; - options &= ~BT_LE_ADV_OPT_USE_IDENTITY; - - /* This will cause bt_id_set_adv_private_addr() to return 0 */ - atomic_set_bit(bt_dev.flags, BT_DEV_RPA_VALID); - - for (size_t i = 0; i < ARRAY_SIZE(dir_adv_test_lut); i++) { - err = bt_id_set_adv_own_addr(&adv, options, dir_adv_test_lut[i], &own_addr_type); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_true(own_addr_type == BT_HCI_OWN_ADDR_RANDOM, - "Address type reference was incorrectly set"); - } -} - -/* - * Test stopping scanning if it is supported through enabling 'CONFIG_BT_OBSERVER' and active - * before updating the device advertising address and then re-enable it after the update is done. - * - * Constraints: - * - Options 'BT_LE_ADV_OPT_CONN' bit isn't set - * - Options 'BT_LE_ADV_OPT_USE_IDENTITY' bit isn't set - * - * Expected behaviour: - * - Scanning is disabled and then re-enabled again after updating the address - */ -ZTEST(bt_id_set_adv_own_addr, test_observer_scanning_re_enabled_after_updating_address) -{ - uint32_t options = 0; - struct bt_le_ext_adv adv = {0}; - uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; - uint8_t expected_args_history[] = {BT_HCI_LE_SCAN_DISABLE, BT_HCI_LE_SCAN_ENABLE}; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_PRIVACY); - Z_TEST_SKIP_IFDEF(CONFIG_BT_EXT_ADV); - Z_TEST_SKIP_IFDEF(CONFIG_BT_SCAN_WITH_IDENTITY); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_OBSERVER); - - options &= ~BT_LE_ADV_OPT_CONN; - options &= ~BT_LE_ADV_OPT_USE_IDENTITY; - - /* Set device scanning active flag */ - atomic_set_bit(bt_dev.flags, BT_DEV_SCANNING); - - bt_id_set_adv_own_addr(&adv, options, true, &own_addr_type); - zassert_true(own_addr_type == BT_HCI_OWN_ADDR_RANDOM, - "Address type reference was incorrectly set"); - - expect_call_count_bt_le_scan_set_enable(2, expected_args_history); -} - -/* - * Test setting the advertiser address while 'CONFIG_BT_SCAN_WITH_IDENTITY' is enabled - * and scanning is ongoing. The scanner is using a random identity address. - * - * Constraints: - * - Options 'BT_LE_ADV_OPT_CONN' bit isn't set - * - * Expected behaviour: - * - Scanning is not disabled. - * - The advertiser doesn't attempt to change the identity addr with bt_id_set_adv_private_addr() - * - The advertiser uses the same identity address as the scanner. - */ -ZTEST(bt_id_set_adv_own_addr, test_set_adv_own_addr_while_scanning_with_identity_random) -{ - uint32_t options = 0; - struct bt_le_ext_adv adv = {0}; - struct net_buf net_buff; - int err; - uint8_t scan_own_addr_type = BT_ADDR_LE_ANONYMOUS; - uint8_t adv_own_addr_type = BT_ADDR_LE_ANONYMOUS; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_PRIVACY); - Z_TEST_SKIP_IFDEF(CONFIG_BT_EXT_ADV); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_OBSERVER); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_SCAN_WITH_IDENTITY); - - bt_hci_cmd_alloc_fake.return_val = &net_buff; - bt_hci_cmd_send_sync_fake.return_val = 0; - - options &= ~BT_LE_ADV_OPT_CONN; - bt_addr_le_copy(&bt_dev.id_addr[BT_ID_DEFAULT], BT_STATIC_RANDOM_LE_ADDR_1); - - err = bt_id_set_scan_own_addr(false, &scan_own_addr_type); - - expect_single_call_bt_hci_cmd_alloc(); - expect_single_call_bt_hci_cmd_send_sync(BT_HCI_OP_LE_SET_RANDOM_ADDRESS); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_true(scan_own_addr_type == BT_HCI_OWN_ADDR_RANDOM, - "Address type reference was incorrectly set"); - - atomic_set_bit(bt_dev.flags, BT_DEV_SCANNING); - - bt_id_set_adv_own_addr(&adv, options, true, &adv_own_addr_type); - zassert_true(adv_own_addr_type == BT_HCI_OWN_ADDR_RANDOM, - "Address type reference was incorrectly set"); - - expect_call_count_bt_le_scan_set_enable(0, NULL); -} - -/* - * Test setting the advertiser address while 'CONFIG_BT_SCAN_WITH_IDENTITY' is enabled - * and scanning is ongoing. The scanner is using a public identity address. - * - * Constraints: - * - Options 'BT_LE_ADV_OPT_CONN' bit isn't set - * - * Expected behaviour: - * - Scanning is not disabled. - * - The advertiser doesn't attempt to change the identity addr with bt_id_set_adv_private_addr() - * - The advertiser uses the same identity address as the scanner. - */ -ZTEST(bt_id_set_adv_own_addr, test_set_adv_own_addr_while_scanning_with_identity_public) -{ - uint32_t options = 0; - struct bt_le_ext_adv adv = {0}; - int err; - uint8_t scan_own_addr_type = BT_ADDR_LE_ANONYMOUS; - uint8_t adv_own_addr_type = BT_ADDR_LE_ANONYMOUS; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_PRIVACY); - Z_TEST_SKIP_IFDEF(CONFIG_BT_EXT_ADV); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_OBSERVER); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_SCAN_WITH_IDENTITY); - - options &= ~BT_LE_ADV_OPT_CONN; - - bt_addr_le_copy(&bt_dev.id_addr[BT_ID_DEFAULT], BT_LE_ADDR); - - err = bt_id_set_scan_own_addr(false, &scan_own_addr_type); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_true(scan_own_addr_type == BT_HCI_OWN_ADDR_PUBLIC, - "Address type reference was incorrectly set"); - - atomic_set_bit(bt_dev.flags, BT_DEV_SCANNING); - - bt_id_set_adv_own_addr(&adv, options, true, &adv_own_addr_type); - zassert_true(adv_own_addr_type == BT_HCI_OWN_ADDR_PUBLIC, - "Address type reference was incorrectly set"); - - expect_call_count_bt_le_scan_set_enable(0, NULL); -} diff --git a/tests/bluetooth/host/id/bt_id_set_adv_own_addr/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/id/bt_id_set_adv_own_addr/src/test_suite_invalid_inputs.c deleted file mode 100644 index a5c7feaf5c1d0..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_adv_own_addr/src/test_suite_invalid_inputs.c +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" -#include "mocks/crypto.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include - -ZTEST_SUITE(bt_id_set_adv_own_addr_invalid_inputs, NULL, NULL, NULL, NULL, NULL); - -/* - * Test passing NULL value for advertise parameters reference - * - * Constraints: - * - Advertise parameters reference is passed as NULL - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_id_set_adv_own_addr_invalid_inputs, test_null_advertise_parameters_reference) -{ - uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; - - expect_assert(); - bt_id_set_adv_own_addr(NULL, 0x00, false, &own_addr_type); -} - -/* - * Test passing NULL value for address type reference - * - * Constraints: - * - Address type reference is passed as NULL - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_id_set_adv_own_addr_invalid_inputs, test_null_address_type_reference) -{ - struct bt_le_ext_adv adv; - - expect_assert(); - bt_id_set_adv_own_addr(&adv, 0x00, false, NULL); -} - -/* - * Test that operation not supported to use RPA with directed advertisement with connectable - * advertisement if privacy feature bit 'BT_LE_FEAT_BIT_PRIVACY' isn't enabled - * - * Constraints: - * - Directed advertising flag is set - * - 'BT_LE_FEAT_BIT_PRIVACY' bit isn't set - * - Options 'BT_LE_ADV_OPT_CONN' bit is set - * - Options 'BT_LE_ADV_OPT_DIR_ADDR_RPA' bit is set - * - * Expected behaviour: - * - 'ENOTSUP' error is returned - */ -ZTEST(bt_id_set_adv_own_addr_invalid_inputs, test_dir_adv_with_rpa_no_privacy) -{ - int err; - uint32_t options = 0; - struct bt_le_ext_adv adv = {0}; - uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; - - options |= BT_LE_ADV_OPT_CONN; - options |= BT_LE_ADV_OPT_DIR_ADDR_RPA; - - bt_dev.le.features[(BT_LE_FEAT_BIT_PRIVACY) >> 3] &= ~BIT((BT_LE_FEAT_BIT_PRIVACY)&7); - - err = bt_id_set_adv_own_addr(&adv, options, true, &own_addr_type); - - zassert_true(err == -ENOTSUP, "Unexpected error code '%d' was returned", err); -} - -/* - * Test setting the advertising private address through bt_id_set_adv_private_addr() if - * privacy is enabled and 'BT_LE_ADV_OPT_USE_IDENTITY' options bit isn't set. - * Operation fails if bt_id_set_adv_private_addr() failed and a negative error code is returned. - * - * Constraints: - * - Options 'BT_LE_ADV_OPT_CONN' bit is set - * - Options 'BT_LE_ADV_OPT_USE_IDENTITY' bit isn't set - * - 'CONFIG_BT_PRIVACY' is enabled - * - bt_id_set_adv_private_addr() fails and returns a negative error code (failure) - * - * Expected behaviour: - * - bt_id_set_adv_own_addr() returns a negative error code (failure) - */ -ZTEST(bt_id_set_adv_own_addr_invalid_inputs, test_bt_id_set_adv_private_addr_fails) -{ - int err; - uint32_t options = 0; - struct bt_le_ext_adv adv = {0}; - uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - - options |= BT_LE_ADV_OPT_CONN; - - err = bt_id_set_adv_own_addr(&adv, options, true, &own_addr_type); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); - zassert_true(own_addr_type == BT_ADDR_LE_ANONYMOUS, - "Address type reference was unexpectedly modified"); -} - -/* - * Test setting the advertising private address with a static random address through - * bt_id_set_adv_random_addr() if privacy isn't enabled. - * Operation fails if bt_id_set_adv_random_addr() failed and a negative error code is returned. - * - * Constraints: - * - Options 'BT_LE_ADV_OPT_CONN' bit is set - * - 'CONFIG_BT_PRIVACY' isn't enabled - * - bt_id_set_adv_random_addr() fails and returns a negative error code (failure) - * - * Expected behaviour: - * - bt_id_set_adv_own_addr() returns a negative error code (failure) - */ -ZTEST(bt_id_set_adv_own_addr_invalid_inputs, test_bt_id_set_adv_random_addr_fails_adv_connectable) -{ - int err; - uint32_t options = 0; - struct bt_le_ext_adv adv = {0}; - uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_PRIVACY); - /* If 'CONFIG_BT_EXT_ADV' is defined, it changes bt_id_set_adv_random_addr() behaviour */ - Z_TEST_SKIP_IFDEF(CONFIG_BT_EXT_ADV); - - options |= BT_LE_ADV_OPT_CONN; - - adv.id = 0; - bt_addr_le_copy(&bt_dev.id_addr[adv.id], BT_RPA_LE_ADDR); - - err = bt_id_set_adv_own_addr(&adv, options, true, &own_addr_type); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); - zassert_true(own_addr_type == BT_ADDR_LE_ANONYMOUS, - "Address type reference was unexpectedly modified"); -} - -/* - * Test setting the advertising private address with a static random address through - * bt_id_set_adv_random_addr() when device isn't advertising as a connectable device (i.e. - * BT_LE_ADV_OPT_CONN bit in options isn't set) and the advertisement is using the device - * identity (i.e. BT_LE_ADV_OPT_USE_IDENTITY bit is set in options). - * - * Operation fails if bt_id_set_adv_random_addr() failed and a negative error code is returned. - * - * Constraints: - * - Options 'BT_LE_ADV_OPT_USE_IDENTITY' bit is set - * - Options 'BT_LE_ADV_OPT_CONN' bit isn't set - * - bt_id_set_adv_random_addr() fails and returns a negative error code (failure) - * - * Expected behaviour: - * - bt_id_set_adv_own_addr() returns a negative error code (failure) - */ -ZTEST(bt_id_set_adv_own_addr_invalid_inputs, test_bt_id_set_adv_random_addr_fails_not_connectable) -{ - int err; - uint32_t options = 0; - struct bt_le_ext_adv adv = {0}; - uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; - - /* If 'CONFIG_BT_EXT_ADV' is defined, it changes bt_id_set_adv_random_addr() behaviour */ - Z_TEST_SKIP_IFDEF(CONFIG_BT_EXT_ADV); - - options |= BT_LE_ADV_OPT_USE_IDENTITY; - options &= ~BT_LE_ADV_OPT_CONN; - - adv.id = 0; - bt_addr_le_copy(&bt_dev.id_addr[adv.id], BT_RPA_LE_ADDR); - - err = bt_id_set_adv_own_addr(&adv, options, true, &own_addr_type); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); -} - -/* - * Test setting the advertising private address through bt_id_set_adv_private_addr() if - * 'BT_LE_ADV_OPT_USE_IDENTITY' and 'BT_LE_ADV_OPT_USE_IDENTITY' options bits aren't set. - * Operation fails if bt_id_set_adv_private_addr() failed and a negative error code is returned. - * - * Constraints: - * - Options 'BT_LE_ADV_OPT_CONN' bit isn't set - * - Options 'BT_LE_ADV_OPT_USE_IDENTITY' bit isn't set - * - bt_id_set_adv_private_addr() fails and returns a negative error code (failure) - * - * Expected behaviour: - * - bt_id_set_adv_own_addr() returns a negative error code (failure) - */ -ZTEST(bt_id_set_adv_own_addr_invalid_inputs, test_bt_id_set_adv_private_addr_fails_not_connectable) -{ - int err; - uint32_t options = 0; - struct bt_le_ext_adv adv = {0}; - uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; - - options &= ~BT_LE_ADV_OPT_CONN; - options &= ~BT_LE_ADV_OPT_USE_IDENTITY; - - /* This will cause bt_id_set_adv_private_addr() to return a negative error code */ - bt_rand_fake.return_val = -1; - - err = bt_id_set_adv_own_addr(&adv, options, true, &own_addr_type); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); -} diff --git a/tests/bluetooth/host/id/bt_id_set_adv_own_addr/testcase.yaml b/tests/bluetooth/host/id/bt_id_set_adv_own_addr/testcase.yaml deleted file mode 100644 index d5ab3e4ef8581..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_adv_own_addr/testcase.yaml +++ /dev/null @@ -1,20 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_id_set_adv_own_addr.default: - type: unit - bluetooth.host.bt_id_set_adv_own_addr.default_ext_adv_enabled: - type: unit - extra_configs: - - CONFIG_BT_EXT_ADV=y - bluetooth.host.bt_id_set_adv_own_addr.privacy_enabled: - type: unit - extra_configs: - - CONFIG_BT_SMP=y - - CONFIG_BT_PRIVACY=y - bluetooth.host.bt_id_set_adv_own_addr.scan_with_identity: - type: unit - extra_configs: - - CONFIG_BT_SCAN_WITH_IDENTITY=y diff --git a/tests/bluetooth/host/id/bt_id_set_adv_private_addr/CMakeLists.txt b/tests/bluetooth/host/id/bt_id_set_adv_private_addr/CMakeLists.txt deleted file mode 100644 index dc3205b1d2904..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_adv_private_addr/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -project(bt_id_set_adv_private_addr) - -# Suppress the format-zero-length error if GNUC is used -if (CMAKE_C_COMPILER_ID MATCHES "GNU") -add_compile_options(-Wno-error=format-zero-length -Wno-format-zero-length) -endif() - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_invalid_cases.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/id.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -) diff --git a/tests/bluetooth/host/id/bt_id_set_adv_private_addr/prj.conf b/tests/bluetooth/host/id/bt_id_set_adv_private_addr/prj.conf deleted file mode 100644 index 5f8cdcef01788..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_adv_private_addr/prj.conf +++ /dev/null @@ -1,8 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_ID_MAX=2 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/id/bt_id_set_adv_private_addr/src/main.c b/tests/bluetooth/host/id/bt_id_set_adv_private_addr/src/main.c deleted file mode 100644 index 73f51ad4bf2e9..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_adv_private_addr/src/main.c +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/crypto.h" -#include "mocks/crypto_expects.h" -#include "mocks/hci_core.h" -#include "mocks/rpa.h" -#include "mocks/rpa_expects.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include - -DEFINE_FFF_GLOBALS; - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - bt_addr_le_copy(&bt_dev.random_addr, &bt_addr_le_none); -#if defined(CONFIG_BT_RPA_SHARING) - bt_addr_copy(&bt_dev.rpa[BT_ID_DEFAULT], BT_ADDR_NONE); -#endif - - RPA_FFF_FAKES_LIST(RESET_FAKE); - CRYPTO_FFF_FAKES_LIST(RESET_FAKE); - HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(bt_id_set_adv_private_addr, NULL, NULL, NULL, NULL, NULL); - -static int bt_rand_custom_fake(void *buf, size_t len) -{ - __ASSERT_NO_MSG(buf != NULL); - __ASSERT_NO_MSG(len == sizeof(BT_ADDR->val)); - - /* This will make set_random_address() succeeds and returns 0 */ - memcpy(buf, &BT_ADDR->val, len); - bt_addr_copy(&bt_dev.random_addr.a, BT_ADDR); - - return 0; -} - -static int bt_rpa_create_custom_fake(const uint8_t irk[16], bt_addr_t *rpa) -{ - __ASSERT_NO_MSG(irk != NULL); - __ASSERT_NO_MSG(rpa != NULL); - - /* This will make set_random_address() succeeds and returns 0 */ - bt_addr_copy(rpa, &BT_RPA_LE_ADDR->a); - bt_addr_copy(&bt_dev.random_addr.a, &BT_RPA_LE_ADDR->a); - - return 0; -} - -/* - * Test setting advertising private address with a valid advertise parameters reference while - * 'CONFIG_BT_PRIVACY' is enabled and 'CONFIG_BT_EXT_ADV' isn't enabled - * - * Constraints: - * - A valid advertise parameters ID is used (<= CONFIG_BT_ID_MAX) - * - 'CONFIG_BT_PRIVACY' is enabled - * - 'CONFIG_BT_EXT_ADV' isn't enabled - * - * Expected behaviour: - * - bt_id_set_adv_private_addr() returns 0 (success) - */ -ZTEST(bt_id_set_adv_private_addr, test_set_adv_private_address_with_valid_ref_privacy_succeeds) -{ - int err; - struct bt_le_ext_adv adv_param = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - Z_TEST_SKIP_IFDEF(CONFIG_BT_EXT_ADV); - - bt_rpa_create_fake.custom_fake = bt_rpa_create_custom_fake; - - err = bt_id_set_adv_private_addr(&adv_param); - -#if defined(CONFIG_BT_PRIVACY) - expect_single_call_bt_rpa_create(bt_dev.irk[adv_param.id]); -#endif - - zassert_true(atomic_test_bit(bt_dev.flags, BT_DEV_RPA_VALID), - "Flags were not correctly set"); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); -} - -/* - * Test setting advertising private address with a valid advertise parameters reference while - * 'CONFIG_BT_PRIVACY' and 'CONFIG_BT_EXT_ADV' are enabled - * - * Constraints: - * - A valid advertise parameters ID is used (<= CONFIG_BT_ID_MAX) - * - 'CONFIG_BT_PRIVACY' is enabled - * - 'CONFIG_BT_EXT_ADV' is enabled - * - * Expected behaviour: - * - bt_id_set_adv_private_addr() returns 0 (success) - */ -ZTEST(bt_id_set_adv_private_addr, test_set_adv_private_address_with_valid_ref_priv_ext_adv_succeeds) -{ - int err; - struct bt_le_ext_adv adv_param = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_EXT_ADV); - - bt_rpa_create_fake.custom_fake = bt_rpa_create_custom_fake; - - err = bt_id_set_adv_private_addr(&adv_param); - -#if defined(CONFIG_BT_PRIVACY) - expect_single_call_bt_rpa_create(bt_dev.irk[adv_param.id]); -#endif - -#if defined(CONFIG_BT_EXT_ADV) - zassert_true(atomic_test_bit(adv_param.flags, BT_ADV_RANDOM_ADDR_PENDING), - "Flags were not correctly set"); - - zassert_mem_equal(&adv_param.random_addr, BT_RPA_LE_ADDR, sizeof(bt_addr_le_t), - "Incorrect address was set"); -#endif - - zassert_true(atomic_test_bit(adv_param.flags, BT_ADV_RPA_VALID), - "Flags were not correctly set"); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); -} - -/* - * Test setting advertising private address with a valid advertise parameters reference after it - * was set previously while 'CONFIG_BT_PRIVACY' and 'CONFIG_BT_EXT_ADV' are enabled - * - * Constraints: - * - A valid advertise parameters ID is used (<= CONFIG_BT_ID_MAX) - * - 'CONFIG_BT_PRIVACY' is enabled - * - 'CONFIG_BT_EXT_ADV' is enabled - * - 'BT_ADV_RPA_VALID' flag in advertise parameters reference is set - * - * Expected behaviour: - * - bt_id_set_adv_private_addr() returns 0 (success) - */ -ZTEST(bt_id_set_adv_private_addr, test_set_adv_private_address_with_valid_ref_priv_ext_adv_again) -{ - int err; - struct bt_le_ext_adv adv_param = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_EXT_ADV); - - atomic_set_bit(adv_param.flags, BT_ADV_RPA_VALID); - - err = bt_id_set_adv_private_addr(&adv_param); - - expect_not_called_bt_rpa_create(); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); -} - -/* - * Test setting advertising private address with a valid advertise parameters reference while - * 'CONFIG_BT_PRIVACY' isn't enabled - * - * Constraints: - * - 'CONFIG_BT_PRIVACY' isn't enabled - * - * Expected behaviour: - * - bt_id_set_adv_private_addr() returns 0 (success) - */ -ZTEST(bt_id_set_adv_private_addr, test_set_adv_private_address_with_valid_ref_succeeds) -{ - int err; - struct bt_le_ext_adv adv_param; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_PRIVACY); - - bt_rand_fake.custom_fake = bt_rand_custom_fake; - - err = bt_id_set_adv_private_addr(&adv_param); - - expect_not_called_bt_rpa_create(); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); -} diff --git a/tests/bluetooth/host/id/bt_id_set_adv_private_addr/src/test_suite_invalid_cases.c b/tests/bluetooth/host/id/bt_id_set_adv_private_addr/src/test_suite_invalid_cases.c deleted file mode 100644 index 1fd7fe2c18533..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_adv_private_addr/src/test_suite_invalid_cases.c +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" -#include "mocks/crypto.h" -#include "mocks/hci_core.h" -#include "mocks/rpa.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include - -ZTEST_SUITE(bt_id_set_adv_private_addr_invalid_cases, NULL, NULL, NULL, NULL, NULL); - -/* - * Test setting advertise private random address while passing a NULL value as a reference to - * the advertise parameters. - * - * Constraints: - * - A NULL value is passed to the function as a reference - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_id_set_adv_private_addr_invalid_cases, test_set_adv_address_with_null_reference) -{ - expect_assert(); - bt_id_set_adv_private_addr(NULL); -} - -/* - * Test setting advertise private random address with a valid reference, but bt_rand() fails - * - * Constraints: - * - A valid advertise parameters reference is used - * - bt_rand() fails and returns a negative error code (failure) - * - * Expected behaviour: - * - bt_id_set_adv_private_addr() returns a negative error code (failure) - */ -ZTEST(bt_id_set_adv_private_addr_invalid_cases, test_set_adv_address_bt_rand_fails) -{ - int err; - struct bt_le_ext_adv adv_param; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_PRIVACY); - - bt_rand_fake.return_val = -1; - - err = bt_id_set_adv_private_addr(&adv_param); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); -} - -static int bt_rand_custom_fake(void *buf, size_t len) -{ - __ASSERT_NO_MSG(buf != NULL); - __ASSERT_NO_MSG(len == sizeof(BT_ADDR->val)); - - return 0; -} - -/* - * Test setting advertise private random address with a valid reference, but bt_rand() fails - * - * Constraints: - * - A valid advertise parameters reference is used - * - bt_id_set_adv_random_addr() fails and returns a negative error code (failure) - * - * Expected behaviour: - * - bt_id_set_adv_private_addr() returns a negative error code (failure) - */ -ZTEST(bt_id_set_adv_private_addr_invalid_cases, test_set_adv_address_set_adv_random_addr_fails) -{ - int err; - struct bt_le_ext_adv adv_param; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_PRIVACY); - - bt_rand_fake.custom_fake = bt_rand_custom_fake; - /* This will make set_random_address() returns a negative number error code */ - bt_hci_cmd_alloc_fake.return_val = NULL; - - err = bt_id_set_adv_private_addr(&adv_param); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); -} - -/* - * Test setting advertising private address with a valid advertise parameters reference while - * 'CONFIG_BT_PRIVACY' and 'CONFIG_BT_EXT_ADV' are enabled, but bt_rpa_create() fails - * - * Constraints: - * - A valid advertise parameters ID is used (<= CONFIG_BT_ID_MAX) - * - bt_rpa_create() fails and returns a negative error code (failure) - * - 'CONFIG_BT_PRIVACY' is enabled - * - 'CONFIG_BT_EXT_ADV' is enabled - * - * Expected behaviour: - * - bt_id_set_adv_private_addr() returns a negative error code (failure) - */ -ZTEST(bt_id_set_adv_private_addr_invalid_cases, test_set_adv_address_bt_rpa_create_fails) -{ - int err; - struct bt_le_ext_adv adv_param = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_EXT_ADV); - - bt_rpa_create_fake.return_val = -1; - - err = bt_id_set_adv_private_addr(&adv_param); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); -} - -static int bt_rpa_create_custom_fake(const uint8_t irk[16], bt_addr_t *rpa) -{ - __ASSERT_NO_MSG(irk != NULL); - __ASSERT_NO_MSG(rpa != NULL); - - /* This will make set_random_address() succeeds and returns 0 */ - bt_addr_copy(rpa, &BT_RPA_LE_ADDR->a); - bt_addr_copy(&bt_dev.random_addr.a, &BT_RPA_LE_ADDR->a); - - return 0; -} - -/* - * Test setting advertising private address with a valid advertise parameters reference while - * 'CONFIG_BT_PRIVACY' and 'CONFIG_BT_EXT_ADV' are enabled, but bt_id_set_adv_random_addr() fails - * - * Constraints: - * - A valid advertise parameters ID is used (<= CONFIG_BT_ID_MAX) - * - 'CONFIG_BT_PRIVACY' is enabled - * - 'CONFIG_BT_EXT_ADV' is enabled - * - bt_id_set_adv_random_addr() fails and returns a negative error code (failure) - * - * Expected behaviour: - * - bt_id_set_adv_private_addr() returns a negative error code (failure) - */ -ZTEST(bt_id_set_adv_private_addr_invalid_cases, test_set_adv_address_if_set_adv_random_addr_fails) -{ - int err; - struct bt_le_ext_adv adv_param = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_EXT_ADV); - - bt_rpa_create_fake.custom_fake = bt_rpa_create_custom_fake; - - /* This will make bt_id_set_adv_random_addr() returns a negative number error code */ - atomic_set_bit(adv_param.flags, BT_ADV_PARAMS_SET); - bt_hci_cmd_alloc_fake.return_val = NULL; - - err = bt_id_set_adv_private_addr(&adv_param); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); -} diff --git a/tests/bluetooth/host/id/bt_id_set_adv_private_addr/testcase.yaml b/tests/bluetooth/host/id/bt_id_set_adv_private_addr/testcase.yaml deleted file mode 100644 index 983c9ae2976c7..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_adv_private_addr/testcase.yaml +++ /dev/null @@ -1,18 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_id_set_adv_private_addr.default: - type: unit - bluetooth.host.bt_id_set_adv_private_addr.bt_privacy_enabled: - type: unit - extra_configs: - - CONFIG_BT_SMP=y - - CONFIG_BT_PRIVACY=y - bluetooth.host.bt_id_set_adv_private_addr.bt_privacy_ext_adv_enabled: - type: unit - extra_configs: - - CONFIG_BT_SMP=y - - CONFIG_BT_PRIVACY=y - - CONFIG_BT_EXT_ADV=y diff --git a/tests/bluetooth/host/id/bt_id_set_adv_random_addr/CMakeLists.txt b/tests/bluetooth/host/id/bt_id_set_adv_random_addr/CMakeLists.txt deleted file mode 100644 index 428c656de33cb..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_adv_random_addr/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -project(bt_id_set_adv_random_addr) - -# Suppress the format-zero-length error if GNUC is used -if (CMAKE_C_COMPILER_ID MATCHES "GNU") -add_compile_options(-Wno-error=format-zero-length -Wno-format-zero-length) -endif() - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_invalid_cases.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/id.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -) diff --git a/tests/bluetooth/host/id/bt_id_set_adv_random_addr/prj.conf b/tests/bluetooth/host/id/bt_id_set_adv_random_addr/prj.conf deleted file mode 100644 index 5f8cdcef01788..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_adv_random_addr/prj.conf +++ /dev/null @@ -1,8 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_ID_MAX=2 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/id/bt_id_set_adv_random_addr/src/main.c b/tests/bluetooth/host/id/bt_id_set_adv_random_addr/src/main.c deleted file mode 100644 index aeef2b1fc23dd..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_adv_random_addr/src/main.c +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/hci_core.h" -#include "mocks/hci_core_expects.h" -#include "mocks/net_buf.h" -#include "mocks/net_buf_expects.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include - -DEFINE_FFF_GLOBALS; - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - - HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(bt_id_set_adv_random_addr, NULL, NULL, NULL, NULL, NULL); - -/* - * Test setting advertising random address while 'CONFIG_BT_EXT_ADV' isn't enabled - * - * Constraints: - * - set_random_address() returns 0 (success) - * - 'CONFIG_BT_EXT_ADV' isn't enabled - * - * Expected behaviour: - * - bt_id_set_adv_random_addr() returns 0 (success) - */ -ZTEST(bt_id_set_adv_random_addr, test_no_ext_adv) -{ - int err; - struct bt_le_ext_adv adv_param = {0}; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_EXT_ADV); - - /* This will make set_random_address() succeeds and returns 0 */ - bt_addr_copy(&bt_dev.random_addr.a, &BT_RPA_LE_ADDR->a); - - err = bt_id_set_adv_random_addr(&adv_param, &BT_RPA_LE_ADDR->a); - - expect_not_called_bt_hci_cmd_alloc(); - expect_not_called_bt_hci_cmd_send_sync(); - expect_not_called_net_buf_simple_add(); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); -} - -/* - * Test setting advertising random address while 'CONFIG_BT_EXT_ADV' is enabled - * - * Constraints: - * - 'CONFIG_BT_EXT_ADV' is enabled - * - 'BT_ADV_PARAMS_SET' flag in advertising parameters reference isn't set - * - * Expected behaviour: - * - bt_id_set_adv_random_addr() returns 0 (success) - * - Random address field in advertising parameters reference is loaded with the address - * - 'BT_ADV_RANDOM_ADDR_PENDING' flag is set - */ -ZTEST(bt_id_set_adv_random_addr, test_ext_adv_enabled) -{ - int err; - struct bt_le_ext_adv adv_param = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_EXT_ADV); - - atomic_clear_bit(adv_param.flags, BT_ADV_PARAMS_SET); - - err = bt_id_set_adv_random_addr(&adv_param, &BT_RPA_LE_ADDR->a); - - expect_not_called_bt_hci_cmd_alloc(); - expect_not_called_bt_hci_cmd_send_sync(); - expect_not_called_net_buf_simple_add(); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - - zassert_true(atomic_test_bit(adv_param.flags, BT_ADV_RANDOM_ADDR_PENDING), - "Flags were not correctly set"); - - zassert_mem_equal(&adv_param.random_addr, BT_RPA_LE_ADDR, sizeof(bt_addr_le_t), - "Incorrect address was set"); -} - -/* - * Test setting advertising random address while 'CONFIG_BT_EXT_ADV' is enabled - * and 'BT_ADV_PARAMS_SET' flag in advertising parameters reference is set. - * - * Constraints: - * - 'CONFIG_BT_EXT_ADV' is enabled - * - 'BT_ADV_PARAMS_SET' flag in advertising parameters reference is set - * - bt_hci_cmd_alloc() returns a valid buffer pointer - * - bt_hci_cmd_send_sync() returns 0 (success) - * - * Expected behaviour: - * - bt_id_set_adv_random_addr() returns 0 (success) - */ -ZTEST(bt_id_set_adv_random_addr, test_ext_adv_enabled_hci_set_adv_set_random_addr) -{ - int err; - struct net_buf net_buff; - struct bt_hci_cp_le_set_adv_set_random_addr cp; - struct bt_le_ext_adv adv_param = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_EXT_ADV); - - atomic_set_bit(adv_param.flags, BT_ADV_PARAMS_SET); - - net_buf_simple_add_fake.return_val = &cp; - bt_hci_cmd_alloc_fake.return_val = &net_buff; - bt_hci_cmd_send_sync_fake.return_val = 0; - - err = bt_id_set_adv_random_addr(&adv_param, &BT_RPA_LE_ADDR->a); - - expect_single_call_net_buf_simple_add(&net_buff.b, sizeof(cp)); - expect_single_call_bt_hci_cmd_alloc(); - expect_single_call_bt_hci_cmd_send_sync(BT_HCI_OP_LE_SET_ADV_SET_RANDOM_ADDR); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_equal(cp.handle, adv_param.handle, "Incorrect handle value was set"); - zassert_mem_equal(&cp.bdaddr, &BT_RPA_LE_ADDR->a, sizeof(bt_addr_t), - "Incorrect address was set"); - zassert_mem_equal(&adv_param.random_addr, BT_RPA_LE_ADDR, sizeof(bt_addr_le_t), - "Incorrect address was set"); -} diff --git a/tests/bluetooth/host/id/bt_id_set_adv_random_addr/src/test_suite_invalid_cases.c b/tests/bluetooth/host/id/bt_id_set_adv_random_addr/src/test_suite_invalid_cases.c deleted file mode 100644 index b9df7be3f9b49..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_adv_random_addr/src/test_suite_invalid_cases.c +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" -#include "mocks/hci_core.h" -#include "mocks/net_buf.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include - -ZTEST_SUITE(bt_id_set_adv_random_addr_invalid_cases, NULL, NULL, NULL, NULL, NULL); - -/* - * Test setting advertise random address while passing a NULL value as a reference to - * the advertise parameters. - * - * Constraints: - * - A NULL value is passed to the function as a reference - * - A valid address pointer is used - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_id_set_adv_random_addr_invalid_cases, test_null_adv_params_reference) -{ - expect_assert(); - bt_id_set_adv_random_addr(NULL, &BT_RPA_LE_ADDR->a); -} - -/* - * Test setting advertise random address while passing a NULL value as an address reference - * - * Constraints: - * - A valid value is passed to the function as a reference for advertise parameters - * - A NULL address pointer is used - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_id_set_adv_random_addr_invalid_cases, test_null_address_reference) -{ - struct bt_le_ext_adv adv_param = {0}; - - expect_assert(); - bt_id_set_adv_random_addr(&adv_param, NULL); -} - -/* - * Test setting advertise random address while passing a NULL value for the advertise parameters - * and the address - * - * Constraints: - * - A NULL value is passed to the function as a reference - * - A NULL address pointer is used - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_id_set_adv_random_addr_invalid_cases, test_null_arguments) -{ - expect_assert(); - bt_id_set_adv_random_addr(NULL, NULL); -} - -/* - * Test setting advertising random address while 'CONFIG_BT_EXT_ADV' is enabled - * and 'BT_ADV_PARAMS_SET' flag in advertising parameters reference is set. - * bt_hci_cmd_alloc() fails to allocate buffers and returns NULL. - * - * Constraints: - * - 'CONFIG_BT_EXT_ADV' is enabled - * - 'BT_ADV_PARAMS_SET' flag in advertising parameters reference is set - * - bt_hci_cmd_alloc() returns null - * - * Expected behaviour: - * - bt_id_set_adv_random_addr() returns a negative error code (failure) - */ -ZTEST(bt_id_set_adv_random_addr_invalid_cases, test_bt_hci_cmd_alloc_returns_null) -{ - int err; - struct bt_le_ext_adv adv_param = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_EXT_ADV); - - atomic_set_bit(adv_param.flags, BT_ADV_PARAMS_SET); - - bt_hci_cmd_alloc_fake.return_val = NULL; - - err = bt_id_set_adv_random_addr(&adv_param, &BT_RPA_LE_ADDR->a); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); -} - -/* - * Test setting advertising random address while 'CONFIG_BT_EXT_ADV' is enabled - * and 'BT_ADV_PARAMS_SET' flag in advertising parameters reference is set. - * bt_hci_cmd_send_sync() fails and returns a negative error code. - * - * Constraints: - * - 'CONFIG_BT_EXT_ADV' is enabled - * - 'BT_ADV_PARAMS_SET' flag in advertising parameters reference is set - * - bt_hci_cmd_alloc() returns a valid buffer pointer - * - bt_hci_cmd_send_sync() fails and returns a negative error code. - * - * Expected behaviour: - * - bt_id_set_adv_random_addr() returns a negative error code (failure) - */ -ZTEST(bt_id_set_adv_random_addr_invalid_cases, test_bt_hci_cmd_send_sync_fails) -{ - int err; - struct net_buf net_buff; - struct bt_hci_cp_le_set_adv_set_random_addr cp; - struct bt_le_ext_adv adv_param = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_EXT_ADV); - - atomic_set_bit(adv_param.flags, BT_ADV_PARAMS_SET); - - net_buf_simple_add_fake.return_val = &cp; - bt_hci_cmd_alloc_fake.return_val = &net_buff; - bt_hci_cmd_send_sync_fake.return_val = -1; - - err = bt_id_set_adv_random_addr(&adv_param, &BT_RPA_LE_ADDR->a); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); -} diff --git a/tests/bluetooth/host/id/bt_id_set_adv_random_addr/testcase.yaml b/tests/bluetooth/host/id/bt_id_set_adv_random_addr/testcase.yaml deleted file mode 100644 index db52f7c2518a3..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_adv_random_addr/testcase.yaml +++ /dev/null @@ -1,11 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_id_set_adv_random_addr.default: - type: unit - bluetooth.host.bt_id_set_adv_random_addr.bt_ext_adv_enabled: - type: unit - extra_configs: - - CONFIG_BT_EXT_ADV=y diff --git a/tests/bluetooth/host/id/bt_id_set_create_conn_own_addr/CMakeLists.txt b/tests/bluetooth/host/id/bt_id_set_create_conn_own_addr/CMakeLists.txt deleted file mode 100644 index ea91e43c60941..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_create_conn_own_addr/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -project(bt_id_set_create_conn_own_addr) - -# Suppress the format-zero-length error if GNUC is used -if (CMAKE_C_COMPILER_ID MATCHES "GNU") -add_compile_options(-Wno-error=format-zero-length -Wno-format-zero-length) -endif() - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_invalid_inputs.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/id.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -) diff --git a/tests/bluetooth/host/id/bt_id_set_create_conn_own_addr/prj.conf b/tests/bluetooth/host/id/bt_id_set_create_conn_own_addr/prj.conf deleted file mode 100644 index 2682cec05b5aa..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_create_conn_own_addr/prj.conf +++ /dev/null @@ -1,9 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_SMP=y -CONFIG_BT_ID_MAX=4 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/id/bt_id_set_create_conn_own_addr/src/main.c b/tests/bluetooth/host/id/bt_id_set_create_conn_own_addr/src/main.c deleted file mode 100644 index b9e60a71c65a4..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_create_conn_own_addr/src/main.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/hci_core.h" -#include "mocks/rpa.h" -#include "testing_common_defs.h" - -#include -#include -#include -#include - -#include -#include - -DEFINE_FFF_GLOBALS; - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - - RPA_FFF_FAKES_LIST(RESET_FAKE); - HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(bt_id_set_create_conn_own_addr, NULL, NULL, NULL, NULL, NULL); - -/* - * Test setting connection own address while 'CONFIG_BT_PRIVACY' isn't enabled. - * If the default identity has a non-random address like 'BT_ADDR_LE_PUBLIC', set_random_address() - * isn't called and address type reference is updated upon success. - * - * Constraints: - * - Default identity has an address with the type 'BT_ADDR_LE_PUBLIC' - * - 'CONFIG_BT_PRIVACY' isn't enabled - * - * Expected behaviour: - * - bt_id_set_create_conn_own_addr() returns 0 - * - Address type reference is updated - */ -ZTEST(bt_id_set_create_conn_own_addr, test_setting_conn_own_public_address_no_privacy) -{ - int err; - uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_PRIVACY); - - bt_addr_le_copy(&bt_dev.id_addr[BT_ID_DEFAULT], BT_LE_ADDR); - - err = bt_id_set_create_conn_own_addr(false, &own_addr_type); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_true(own_addr_type == BT_HCI_OWN_ADDR_PUBLIC, - "Address type reference was incorrectly set"); -} - -/* - * Test setting connection own address while 'CONFIG_BT_PRIVACY' isn't enabled. - * If the default identity has an RPA address of type 'BT_HCI_OWN_ADDR_RANDOM', - * set_random_address() is called and address type reference is updated upon success. - * - * Constraints: - * - Default identity has an address with the type 'BT_HCI_OWN_ADDR_RANDOM' - * - 'CONFIG_BT_PRIVACY' isn't enabled - * - set_random_address() succeeds and returns 0 - * - * Expected behaviour: - * - bt_id_set_create_conn_own_addr() returns 0 - * - Address type reference is updated - */ -ZTEST(bt_id_set_create_conn_own_addr, test_setting_conn_own_rpa_address_no_privacy) -{ - int err; - uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_PRIVACY); - - bt_addr_le_copy(&bt_dev.id_addr[BT_ID_DEFAULT], BT_RPA_LE_ADDR); - - /* This will make set_random_address() succeeds and returns 0 */ - bt_addr_copy(&bt_dev.random_addr.a, &BT_RPA_LE_ADDR->a); - - err = bt_id_set_create_conn_own_addr(false, &own_addr_type); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_true(own_addr_type == BT_HCI_OWN_ADDR_RANDOM, - "Address type reference was incorrectly set"); -} - -/* - * Test setting connection own address while 'CONFIG_BT_PRIVACY' is enabled and privacy features - * 'BT_LE_FEAT_BIT_PRIVACY' bit isn't set. - * bt_id_set_private_addr() is called with 'BT_ID_DEFAULT' as the ID and address type reference is - * updated upon success. - * - * Constraints: - * - 'CONFIG_BT_PRIVACY' is enabled - * - 'BT_LE_FEAT_BIT_PRIVACY' bit isn't set. - * - bt_id_set_private_addr() succeeds and returns 0 - * - * Expected behaviour: - * - bt_id_set_create_conn_own_addr() returns 0 - * - Address type reference is updated with the value 'BT_HCI_OWN_ADDR_RANDOM' - */ -ZTEST(bt_id_set_create_conn_own_addr, test_setting_conn_own_address_privacy_enabled) -{ - int err; - uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - - /* This will cause bt_id_set_private_addr() to return 0 (success) */ - atomic_set_bit(bt_dev.flags, BT_DEV_RPA_VALID); - - err = bt_id_set_create_conn_own_addr(true, &own_addr_type); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_true(own_addr_type == BT_HCI_OWN_ADDR_RANDOM, - "Address type reference was incorrectly set"); -} - -/* - * Test setting connection own address while 'CONFIG_BT_PRIVACY' is enabled and privacy features - * 'BT_LE_FEAT_BIT_PRIVACY' bit is set. - * bt_id_set_private_addr() is called with 'BT_ID_DEFAULT' as the ID and address type reference - * is updated upon success. - * - * Constraints: - * - 'CONFIG_BT_PRIVACY' is enabled - * - 'BT_LE_FEAT_BIT_PRIVACY' bit is set. - * - bt_id_set_private_addr() succeeds and returns 0 - * - * Expected behaviour: - * - bt_id_set_create_conn_own_addr() returns 0 - * - Address type reference is updated with the value 'BT_HCI_OWN_ADDR_RPA_OR_RANDOM' - */ -ZTEST(bt_id_set_create_conn_own_addr, test_setting_conn_own_address_privacy_features_set) -{ - int err; - uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - - /* This will cause bt_id_set_private_addr() to return 0 (success) */ - atomic_set_bit(bt_dev.flags, BT_DEV_RPA_VALID); - - bt_dev.le.features[(BT_LE_FEAT_BIT_PRIVACY) >> 3] |= BIT((BT_LE_FEAT_BIT_PRIVACY)&7); - - err = bt_id_set_create_conn_own_addr(true, &own_addr_type); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_true(own_addr_type == BT_HCI_OWN_ADDR_RPA_OR_RANDOM, - "Address type reference was incorrectly set"); -} diff --git a/tests/bluetooth/host/id/bt_id_set_create_conn_own_addr/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/id/bt_id_set_create_conn_own_addr/src/test_suite_invalid_inputs.c deleted file mode 100644 index adc035eed4b44..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_create_conn_own_addr/src/test_suite_invalid_inputs.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" -#include "mocks/hci_core.h" -#include "mocks/rpa.h" -#include "mocks/rpa_expects.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include - -ZTEST_SUITE(bt_id_set_create_conn_own_addr_invalid_inputs, NULL, NULL, NULL, NULL, NULL); - -/* - * Test passing NULL value for address type reference - * - * Constraints: - * - Address type reference is passed as NULL - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_id_set_create_conn_own_addr_invalid_inputs, test_null_address_type_reference) -{ - expect_assert(); - bt_id_set_create_conn_own_addr(false, NULL); -} - -/* - * Test setting connection own address while 'CONFIG_BT_PRIVACY' isn't enabled. - * If the default identity has an address of type 'BT_ADDR_LE_RANDOM', set_random_address() - * is called, but execution fails and it returns an error. - * - * Constraints: - * - Default identity has an address with the type 'BT_ADDR_LE_RANDOM' - * - 'CONFIG_BT_PRIVACY' isn't enabled - * - set_random_address() fails and returns a negative error - * - * Expected behaviour: - * - bt_id_set_create_conn_own_addr() fails and returns the same error code returned by - * set_random_address() - * - Address type reference isn't set - */ -ZTEST(bt_id_set_create_conn_own_addr_invalid_inputs, test_set_random_address_fails) -{ - int err; - uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_PRIVACY); - - bt_addr_le_copy(&bt_dev.id_addr[BT_ID_DEFAULT], BT_RPA_LE_ADDR); - - /* This will cause set_random_address() to return (-ENOBUFS) */ - bt_hci_cmd_alloc_fake.return_val = NULL; - - err = bt_id_set_create_conn_own_addr(false, &own_addr_type); - - zassert_true(err == -ENOBUFS, "Unexpected error code '%d' was returned", err); - zassert_true(own_addr_type == BT_ADDR_LE_ANONYMOUS, - "Address type reference was unexpectedly modified"); -} - -/* - * Test setting connection own address while 'CONFIG_BT_PRIVACY' is enabled. - * bt_id_set_private_addr() is called with 'BT_ID_DEFAULT' as the ID, but it fails and returns - * a negative error code. - * - * Constraints: - * - 'CONFIG_BT_PRIVACY' is enabled - * - bt_id_set_private_addr() fails and returns a negative error - * - * Expected behaviour: - * - bt_id_set_create_conn_own_addr() fails and returns the same error code returned by - * bt_id_set_private_addr() - * - Address type reference isn't set - */ -ZTEST(bt_id_set_create_conn_own_addr, test_bt_id_set_private_addr_fails) -{ - int err; - uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - - atomic_clear_bit(bt_dev.flags, BT_DEV_RPA_VALID); - - /* This will cause bt_id_set_private_addr() to fail */ - bt_rpa_create_fake.return_val = -1; - - err = bt_id_set_create_conn_own_addr(true, &own_addr_type); - -#if defined(CONFIG_BT_PRIVACY) - expect_single_call_bt_rpa_create(bt_dev.irk[BT_ID_DEFAULT]); -#endif - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); - zassert_true(own_addr_type == BT_ADDR_LE_ANONYMOUS, - "Address type reference was unexpectedly modified"); -} diff --git a/tests/bluetooth/host/id/bt_id_set_create_conn_own_addr/testcase.yaml b/tests/bluetooth/host/id/bt_id_set_create_conn_own_addr/testcase.yaml deleted file mode 100644 index 0b1600bd317ae..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_create_conn_own_addr/testcase.yaml +++ /dev/null @@ -1,12 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_id_set_create_conn_own_addr.default: - type: unit - bluetooth.host.bt_id_set_create_conn_own_addr.privacy_enabled: - type: unit - extra_configs: - - CONFIG_BT_SMP=y - - CONFIG_BT_PRIVACY=y diff --git a/tests/bluetooth/host/id/bt_id_set_private_addr/CMakeLists.txt b/tests/bluetooth/host/id/bt_id_set_private_addr/CMakeLists.txt deleted file mode 100644 index d1a023d1cd869..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_private_addr/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -project(bt_id_set_private_addr) - -# Suppress the format-zero-length error if GNUC is used -if (CMAKE_C_COMPILER_ID MATCHES "GNU") -add_compile_options(-Wno-error=format-zero-length -Wno-format-zero-length) -endif() - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_invalid_cases.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/id.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -) diff --git a/tests/bluetooth/host/id/bt_id_set_private_addr/prj.conf b/tests/bluetooth/host/id/bt_id_set_private_addr/prj.conf deleted file mode 100644 index 5f8cdcef01788..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_private_addr/prj.conf +++ /dev/null @@ -1,8 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_ID_MAX=2 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/id/bt_id_set_private_addr/src/main.c b/tests/bluetooth/host/id/bt_id_set_private_addr/src/main.c deleted file mode 100644 index d36987582309a..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_private_addr/src/main.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/crypto.h" -#include "mocks/crypto_expects.h" -#include "mocks/hci_core.h" -#include "mocks/rpa.h" -#include "mocks/rpa_expects.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include - -DEFINE_FFF_GLOBALS; - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - bt_addr_le_copy(&bt_dev.random_addr, &bt_addr_le_none); - - RPA_FFF_FAKES_LIST(RESET_FAKE); - CRYPTO_FFF_FAKES_LIST(RESET_FAKE); - HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(bt_id_set_private_addr, NULL, NULL, NULL, NULL, NULL); - -static int bt_rand_custom_fake(void *buf, size_t len) -{ - __ASSERT_NO_MSG(buf != NULL); - __ASSERT_NO_MSG(len == sizeof(BT_ADDR->val)); - - /* This will make set_random_address() succeeds and returns 0 */ - memcpy(buf, &BT_ADDR->val, len); - bt_addr_copy(&bt_dev.random_addr.a, BT_ADDR); - - return 0; -} - -static int bt_rpa_create_custom_fake(const uint8_t irk[16], bt_addr_t *rpa) -{ - __ASSERT_NO_MSG(irk != NULL); - __ASSERT_NO_MSG(rpa != NULL); - - /* This will make set_random_address() succeeds and returns 0 */ - bt_addr_copy(rpa, &BT_RPA_LE_ADDR->a); - bt_addr_copy(&bt_dev.random_addr.a, &BT_RPA_LE_ADDR->a); - - return 0; -} - -/* - * Test setting private address with a valid 'id' - * - * Constraints: - * - A valid ID value should be used (<= CONFIG_BT_ID_MAX) - * - * Expected behaviour: - * - bt_id_set_private_addr() returns 0 (success) - */ -ZTEST(bt_id_set_private_addr, test_setting_address_with_valid_id_succeeds) -{ - int err; - uint8_t id = BT_ID_DEFAULT; - - if (!IS_ENABLED(CONFIG_BT_PRIVACY)) { - bt_rand_fake.custom_fake = bt_rand_custom_fake; - } else { - bt_rpa_create_fake.custom_fake = bt_rpa_create_custom_fake; - } - - err = bt_id_set_private_addr(id); - - if (!IS_ENABLED(CONFIG_BT_PRIVACY)) { - expect_not_called_bt_rpa_create(); - } else { -#if defined(CONFIG_BT_PRIVACY) - expect_single_call_bt_rpa_create(bt_dev.irk[id]); -#endif - zassert_true(atomic_test_bit(bt_dev.flags, BT_DEV_RPA_VALID), - "Flags were not correctly set"); - } - - zassert_ok(err, "Unexpected error code '%d' was returned", err); -} - -/* - * Test setting private address with a valid 'id' after it has been set before. - * - * Constraints: - * - A valid ID value should be used (<= CONFIG_BT_ID_MAX) - * - 'BT_DEV_RPA_VALID' flag in bt_dev.flags is set - * - * Expected behaviour: - * - bt_id_set_private_addr() returns 0 (success) without completing the procedure - */ -ZTEST(bt_id_set_private_addr, test_setting_address_do_nothing_when_it_was_previously_set) -{ - int err; - uint8_t id = BT_ID_DEFAULT; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - - atomic_set_bit(bt_dev.flags, BT_DEV_RPA_VALID); - - err = bt_id_set_private_addr(id); - - expect_not_called_bt_rpa_create(); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); -} diff --git a/tests/bluetooth/host/id/bt_id_set_private_addr/src/test_suite_invalid_cases.c b/tests/bluetooth/host/id/bt_id_set_private_addr/src/test_suite_invalid_cases.c deleted file mode 100644 index fba9f9af9f710..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_private_addr/src/test_suite_invalid_cases.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" -#include "mocks/crypto.h" -#include "mocks/hci_core.h" -#include "mocks/rpa.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include - -ZTEST_SUITE(bt_id_set_private_addr_invalid_cases, NULL, NULL, NULL, NULL, NULL); - -/* - * Test setting private address with invalid id - * - * Constraints: - * - Non-valid 'id' should be used (>= CONFIG_BT_ID_MAX) - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_id_set_private_addr_invalid_cases, test_setting_address_with_invalid_id) -{ - expect_assert(); - bt_id_set_private_addr(0xff); -} - -/* - * Test setting private address, while CONFIG_BT_PRIVACY isn't enabled, but bt_rand() fails - * - * Constraints: - * - Any ID value can be used - * - bt_rand() fails and returns a negative error code (failure) - * - 'CONFIG_BT_PRIVACY' isn't enabled - * - * Expected behaviour: - * - bt_id_set_private_addr() returns a negative error code (failure) - */ -ZTEST(bt_id_set_private_addr_invalid_cases, test_setting_address_bt_rand_fails) -{ - int err; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_PRIVACY); - - bt_rand_fake.return_val = -1; - - err = bt_id_set_private_addr(BT_ID_DEFAULT); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); -} - -/* - * Test setting private address, while CONFIG_BT_PRIVACY is enabled, but bt_rpa_create() fails - * - * Constraints: - * - Any ID value can be used - * - bt_rpa_create() fails and returns a negative error code (failure) - * - 'CONFIG_BT_PRIVACY' is enabled - * - * Expected behaviour: - * - bt_id_set_private_addr() returns a negative error code (failure) - */ -ZTEST(bt_id_set_private_addr_invalid_cases, test_setting_address_bt_rpa_create_fails) -{ - int err; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - - bt_rpa_create_fake.return_val = -1; - - err = bt_id_set_private_addr(BT_ID_DEFAULT); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); -} - -static int bt_rand_custom_fake(void *buf, size_t len) -{ - __ASSERT_NO_MSG(buf != NULL); - __ASSERT_NO_MSG(len == sizeof(BT_ADDR->val)); - - return 0; -} - -/* - * Test setting private address, but set_random_address() fails - * - * Constraints: - * - Any ID value can be used - * - bt_rand() returns 0 (success) - * - set_random_address() fails and returns a negative error code (failure) - * - * Expected behaviour: - * - bt_id_set_private_addr() returns a negative error code (failure) - */ -ZTEST(bt_id_set_private_addr_invalid_cases, test_setting_address_set_random_address_fails) -{ - int err; - - if (!IS_ENABLED(CONFIG_BT_PRIVACY)) { - bt_rand_fake.custom_fake = bt_rand_custom_fake; - } - - /* This will make set_random_address() returns a negative number error code */ - bt_hci_cmd_alloc_fake.return_val = NULL; - - err = bt_id_set_private_addr(BT_ID_DEFAULT); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); -} diff --git a/tests/bluetooth/host/id/bt_id_set_private_addr/testcase.yaml b/tests/bluetooth/host/id/bt_id_set_private_addr/testcase.yaml deleted file mode 100644 index 1227efe37a76d..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_private_addr/testcase.yaml +++ /dev/null @@ -1,12 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_id_set_private_addr.default: - type: unit - bluetooth.host.bt_id_set_private_addr.bt_privacy_enabled: - type: unit - extra_configs: - - CONFIG_BT_SMP=y - - CONFIG_BT_PRIVACY=y diff --git a/tests/bluetooth/host/id/bt_id_set_scan_own_addr/CMakeLists.txt b/tests/bluetooth/host/id/bt_id_set_scan_own_addr/CMakeLists.txt deleted file mode 100644 index a376e2f69e5ea..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_scan_own_addr/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -project(bt_id_set_scan_own_addr) - -# Suppress the format-zero-length error if GNUC is used -if (CMAKE_C_COMPILER_ID MATCHES "GNU") -add_compile_options(-Wno-error=format-zero-length -Wno-format-zero-length) -endif() - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_invalid_inputs.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/id.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -) diff --git a/tests/bluetooth/host/id/bt_id_set_scan_own_addr/prj.conf b/tests/bluetooth/host/id/bt_id_set_scan_own_addr/prj.conf deleted file mode 100644 index 2682cec05b5aa..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_scan_own_addr/prj.conf +++ /dev/null @@ -1,9 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_SMP=y -CONFIG_BT_ID_MAX=4 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/id/bt_id_set_scan_own_addr/src/main.c b/tests/bluetooth/host/id/bt_id_set_scan_own_addr/src/main.c deleted file mode 100644 index 2c1fbc675d71c..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_scan_own_addr/src/main.c +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/crypto.h" -#include "mocks/hci_core.h" -#include "mocks/rpa.h" -#include "mocks/adv.h" -#include "mocks/adv_expects.h" -#include "testing_common_defs.h" - -#include -#include -#include -#include - -#include -#include - -DEFINE_FFF_GLOBALS; - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - - RPA_FFF_FAKES_LIST(RESET_FAKE); - CRYPTO_FFF_FAKES_LIST(RESET_FAKE); - HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(bt_id_set_scan_own_addr, NULL, NULL, NULL, NULL, NULL); - -static int bt_rand_custom_fake(void *buf, size_t len) -{ - __ASSERT_NO_MSG(buf != NULL); - __ASSERT_NO_MSG(len == sizeof(BT_ADDR->val)); - - /* This will make set_random_address() succeeds and returns 0 */ - memcpy(buf, &BT_ADDR->val, len); - bt_addr_copy(&bt_dev.random_addr.a, BT_ADDR); - - return 0; -} - -/* - * Test setting scan own address while 'CONFIG_BT_PRIVACY' isn't enabled. - * bt_id_set_private_addr() is called to generate a NRPA and passed to set_random_address(). - * Address type reference is updated upon success. - * - * Constraints: - * - bt_id_set_private_addr() succeeds and returns 0 - * - 'CONFIG_BT_SCAN_WITH_IDENTITY' isn't enabled - * - 'CONFIG_BT_PRIVACY' isn't enabled - * - * Expected behaviour: - * - bt_id_set_scan_own_addr() returns 0 - * - Address type reference is updated - */ -ZTEST(bt_id_set_scan_own_addr, test_set_nrpa_scan_address_no_privacy) -{ - int err; - uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_PRIVACY); - Z_TEST_SKIP_IFDEF(CONFIG_BT_SCAN_WITH_IDENTITY); - - bt_rand_fake.custom_fake = bt_rand_custom_fake; - - err = bt_id_set_scan_own_addr(false, &own_addr_type); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_true(own_addr_type == BT_HCI_OWN_ADDR_RANDOM, - "Address type reference was incorrectly set"); -} - -/* - * Test setting scan own address while 'CONFIG_BT_PRIVACY' isn't enabled. - * Advertising is ongoing and uses a random device address. - * - * Constraints: - * - bt_id_set_private_addr() succeeds and returns 0 - * - 'CONFIG_BT_SCAN_WITH_IDENTITY' isn't enabled - * - 'CONFIG_BT_PRIVACY' isn't enabled - * - * Expected behaviour: - * - bt_id_set_scan_own_addr() returns 0 - * - Address type reference is updated - */ -ZTEST(bt_id_set_scan_own_addr, test_set_nrpa_scan_address_no_privacy_adv_ongoing_random_identity) -{ - int err; - struct bt_le_ext_adv *adv = &bt_dev.adv; - uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_PRIVACY); - Z_TEST_SKIP_IFDEF(CONFIG_BT_SCAN_WITH_IDENTITY); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_BROADCASTER); - - bt_rand_fake.custom_fake = bt_rand_custom_fake; - bt_le_adv_lookup_legacy_fake.return_val = adv; - - bt_addr_le_copy(&bt_dev.id_addr[BT_ID_DEFAULT], BT_STATIC_RANDOM_LE_ADDR_1); - - atomic_set_bit(adv->flags, BT_ADV_ENABLED); - - err = bt_id_set_scan_own_addr(false, &own_addr_type); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_true(own_addr_type == BT_HCI_OWN_ADDR_RANDOM, - "Address type reference was incorrectly set"); -} - -/* - * Test setting scan own address while 'CONFIG_BT_PRIVACY' isn't enabled. - * Advertising is ongoing and uses a public device address. - * - * Constraints: - * - bt_id_set_private_addr() succeeds and returns 0 - * - 'CONFIG_BT_SCAN_WITH_IDENTITY' isn't enabled - * - 'CONFIG_BT_PRIVACY' isn't enabled - * - * Expected behaviour: - * - bt_id_set_scan_own_addr() returns 0 - * - Address type reference is updated - */ -ZTEST(bt_id_set_scan_own_addr, test_set_nrpa_scan_address_no_privacy_adv_ongoing_public_identity) -{ - int err; - struct bt_le_ext_adv *adv = &bt_dev.adv; - uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_PRIVACY); - Z_TEST_SKIP_IFDEF(CONFIG_BT_SCAN_WITH_IDENTITY); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_BROADCASTER); - - bt_rand_fake.custom_fake = bt_rand_custom_fake; - bt_le_adv_lookup_legacy_fake.return_val = adv; - - bt_addr_le_copy(&bt_dev.id_addr[BT_ID_DEFAULT], BT_LE_ADDR); - - atomic_set_bit(adv->flags, BT_ADV_ENABLED); - atomic_set_bit(adv->flags, BT_ADV_USE_IDENTITY); - - err = bt_id_set_scan_own_addr(false, &own_addr_type); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_true(own_addr_type == BT_HCI_OWN_ADDR_PUBLIC, - "Address type reference was incorrectly set"); -} - -/* - * Test setting scan own address while 'CONFIG_BT_PRIVACY' isn't enabled. - * If 'CONFIG_BT_SCAN_WITH_IDENTITY' is enabled and the default identity has an RPA address of type - * 'BT_HCI_OWN_ADDR_RANDOM', set_random_address() is called and address type reference is updated - * upon success. - * - * Constraints: - * - Default identity has an address with the type 'BT_HCI_OWN_ADDR_RANDOM' - * - 'CONFIG_BT_PRIVACY' isn't enabled - * - 'CONFIG_BT_SCAN_WITH_IDENTITY' is enabled - * - set_random_address() succeeds and returns 0 - * - * Expected behaviour: - * - bt_id_set_scan_own_addr() returns 0 - * - Address type reference is updated - */ -ZTEST(bt_id_set_scan_own_addr, test_setting_scan_own_rpa_address_no_privacy) -{ - int err; - uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_PRIVACY); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_SCAN_WITH_IDENTITY); - - bt_addr_le_copy(&bt_dev.id_addr[BT_ID_DEFAULT], BT_RPA_LE_ADDR); - - /* This will make set_random_address() succeeds and returns 0 */ - bt_addr_copy(&bt_dev.random_addr.a, &BT_RPA_LE_ADDR->a); - - err = bt_id_set_scan_own_addr(false, &own_addr_type); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_true(own_addr_type == BT_HCI_OWN_ADDR_RANDOM, - "Address type reference was incorrectly set"); -} - -/* - * Test setting scan own address while 'CONFIG_BT_PRIVACY' is enabled and privacy features - * 'BT_LE_FEAT_BIT_PRIVACY' bit isn't set. - * bt_id_set_private_addr() is called with 'BT_ID_DEFAULT' as the ID and address type reference is - * updated upon success. - * - * Constraints: - * - 'CONFIG_BT_PRIVACY' is enabled - * - 'BT_LE_FEAT_BIT_PRIVACY' bit isn't set. - * - bt_id_set_private_addr() succeeds and returns 0 - * - * Expected behaviour: - * - bt_id_set_scan_own_addr() returns 0 - * - Address type reference is updated with the value 'BT_HCI_OWN_ADDR_RANDOM' - */ -ZTEST(bt_id_set_scan_own_addr, test_setting_scan_own_address_privacy_enabled) -{ - int err; - uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - - /* This will cause bt_id_set_private_addr() to return 0 (success) */ - atomic_set_bit(bt_dev.flags, BT_DEV_RPA_VALID); - - err = bt_id_set_scan_own_addr(true, &own_addr_type); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_true(own_addr_type == BT_HCI_OWN_ADDR_RANDOM, - "Address type reference was incorrectly set"); -} - -/* - * Test setting scan own address while 'CONFIG_BT_PRIVACY' is enabled and privacy features - * 'BT_LE_FEAT_BIT_PRIVACY' bit is set. - * bt_id_set_private_addr() is called with 'BT_ID_DEFAULT' as the ID and address type reference - * is updated upon success. - * - * Constraints: - * - 'CONFIG_BT_PRIVACY' is enabled - * - 'BT_LE_FEAT_BIT_PRIVACY' bit is set. - * - bt_id_set_private_addr() succeeds and returns 0 - * - * Expected behaviour: - * - bt_id_set_scan_own_addr() returns 0 - * - Address type reference is updated with the value 'BT_HCI_OWN_ADDR_RPA_OR_RANDOM' - */ -ZTEST(bt_id_set_scan_own_addr, test_setting_scan_own_address_privacy_features_set) -{ - int err; - uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - - /* This will cause bt_id_set_private_addr() to return 0 (success) */ - atomic_set_bit(bt_dev.flags, BT_DEV_RPA_VALID); - - bt_dev.le.features[(BT_LE_FEAT_BIT_PRIVACY) >> 3] |= BIT((BT_LE_FEAT_BIT_PRIVACY)&7); - - err = bt_id_set_scan_own_addr(true, &own_addr_type); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_true(own_addr_type == BT_HCI_OWN_ADDR_RPA_OR_RANDOM, - "Address type reference was incorrectly set"); -} diff --git a/tests/bluetooth/host/id/bt_id_set_scan_own_addr/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/id/bt_id_set_scan_own_addr/src/test_suite_invalid_inputs.c deleted file mode 100644 index 0942ae9ca17d2..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_scan_own_addr/src/test_suite_invalid_inputs.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" -#include "mocks/crypto.h" -#include "mocks/hci_core.h" -#include "mocks/rpa.h" -#include "mocks/rpa_expects.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include - -ZTEST_SUITE(bt_id_set_scan_own_addr_invalid_inputs, NULL, NULL, NULL, NULL, NULL); - -/* - * Test passing NULL value for address type reference - * - * Constraints: - * - Address type reference is passed as NULL - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_id_set_scan_own_addr_invalid_inputs, test_null_address_type_reference) -{ - expect_assert(); - bt_id_set_scan_own_addr(false, NULL); -} - -/* - * Test setting scan own address while 'CONFIG_BT_PRIVACY' isn't enabled. - * bt_id_set_private_addr() is called to generate a NRPA, but execution fails - * and it returns an error. - * - * Constraints: - * - 'CONFIG_BT_PRIVACY' isn't enabled - * - 'CONFIG_BT_SCAN_WITH_IDENTITY' isn't enabled - * - bt_id_set_private_addr() fails and returns a negative error - * - * Expected behaviour: - * - bt_id_set_scan_own_addr() fails and returns the same error code returned by - * bt_id_set_private_addr() - */ -ZTEST(bt_id_set_scan_own_addr_invalid_inputs, test_bt_id_set_private_addr_fails_no_privacy) -{ - int err; - uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_PRIVACY); - Z_TEST_SKIP_IFDEF(CONFIG_BT_SCAN_WITH_IDENTITY); - - bt_rand_fake.return_val = -1; - - err = bt_id_set_scan_own_addr(false, &own_addr_type); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); -} - -/* - * Test setting scan own address while 'CONFIG_BT_PRIVACY' isn't enabled. - * If 'CONFIG_BT_SCAN_WITH_IDENTITY' is enabled and the default identity has an RPA address of type - * 'BT_ADDR_LE_RANDOM', set_random_address() is called, but execution fails and a negative error - * code is returned. - * - * Constraints: - * - Default identity has an address with the type 'BT_ADDR_LE_RANDOM' - * - 'CONFIG_BT_PRIVACY' isn't enabled - * - 'CONFIG_BT_SCAN_WITH_IDENTITY' is enabled - * - set_random_address() fails and returns a negative error - * - * Expected behaviour: - * - bt_id_set_scan_own_addr() fails and returns the same error code returned by - * set_random_address() - */ -ZTEST(bt_id_set_scan_own_addr_invalid_inputs, test_set_random_address_fails) -{ - int err; - uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_PRIVACY); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_SCAN_WITH_IDENTITY); - - bt_addr_le_copy(&bt_dev.id_addr[BT_ID_DEFAULT], BT_RPA_LE_ADDR); - - /* This will cause set_random_address() to return (-ENOBUFS) */ - bt_hci_cmd_alloc_fake.return_val = NULL; - - err = bt_id_set_scan_own_addr(false, &own_addr_type); - - zassert_true(err == -ENOBUFS, "Unexpected error code '%d' was returned", err); -} - -/* - * Test setting scan own address while 'CONFIG_BT_PRIVACY' is enabled. - * bt_id_set_private_addr() is called with 'BT_ID_DEFAULT' as the ID, but it fails and returns - * a negative error code. - * - * Constraints: - * - 'CONFIG_BT_PRIVACY' is enabled - * - bt_id_set_private_addr() fails and returns a negative error - * - * Expected behaviour: - * - bt_id_set_scan_own_addr() fails and returns the same error code returned by - * bt_id_set_private_addr() - */ -ZTEST(bt_id_set_scan_own_addr_invalid_inputs, test_bt_id_set_private_addr_fails_privacy_enabled) -{ - int err; - uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - - atomic_clear_bit(bt_dev.flags, BT_DEV_RPA_VALID); - - /* This will cause bt_id_set_private_addr() to fail */ - bt_rpa_create_fake.return_val = -1; - - err = bt_id_set_scan_own_addr(true, &own_addr_type); - -#if defined(CONFIG_BT_PRIVACY) - expect_single_call_bt_rpa_create(bt_dev.irk[BT_ID_DEFAULT]); -#endif - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); -} diff --git a/tests/bluetooth/host/id/bt_id_set_scan_own_addr/testcase.yaml b/tests/bluetooth/host/id/bt_id_set_scan_own_addr/testcase.yaml deleted file mode 100644 index 7e3cab5ce37e0..0000000000000 --- a/tests/bluetooth/host/id/bt_id_set_scan_own_addr/testcase.yaml +++ /dev/null @@ -1,26 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_id_set_scan_own_addr.default: - type: unit - bluetooth.host.bt_id_set_scan_own_addr.privacy_enabled: - type: unit - extra_configs: - - CONFIG_BT_SMP=y - - CONFIG_BT_PRIVACY=y - bluetooth.host.bt_id_set_scan_own_addr.default_scan_with_identity: - type: unit - extra_configs: - - CONFIG_BT_SCAN_WITH_IDENTITY=y - bluetooth.host.bt_id_set_scan_own_addr.privacy_scan_with_identity_enabled: - type: unit - extra_configs: - - CONFIG_BT_SCAN_WITH_IDENTITY=y - - CONFIG_BT_SMP=y - - CONFIG_BT_PRIVACY=y - bluetooth.host.bt_id_set_scan_own_addr.scan_while_advertising: - type: unit - extra_configs: - - CONFIG_BT_BROADCASTER=y diff --git a/tests/bluetooth/host/id/bt_le_ext_adv_oob_get_local/CMakeLists.txt b/tests/bluetooth/host/id/bt_le_ext_adv_oob_get_local/CMakeLists.txt deleted file mode 100644 index 5c0777539f1f2..0000000000000 --- a/tests/bluetooth/host/id/bt_le_ext_adv_oob_get_local/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -project(bt_le_ext_adv_oob_get_local) - -# Suppress the format-zero-length error if GNUC is used -if (CMAKE_C_COMPILER_ID MATCHES "GNU") -add_compile_options(-Wno-error=format-zero-length -Wno-format-zero-length) -endif() - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_invalid_inputs.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/id.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -) diff --git a/tests/bluetooth/host/id/bt_le_ext_adv_oob_get_local/prj.conf b/tests/bluetooth/host/id/bt_le_ext_adv_oob_get_local/prj.conf deleted file mode 100644 index 7041a2b047e4f..0000000000000 --- a/tests/bluetooth/host/id/bt_le_ext_adv_oob_get_local/prj.conf +++ /dev/null @@ -1,10 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_EXT_ADV=y -CONFIG_BT_SMP=y -CONFIG_BT_ID_MAX=4 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/id/bt_le_ext_adv_oob_get_local/src/main.c b/tests/bluetooth/host/id/bt_le_ext_adv_oob_get_local/src/main.c deleted file mode 100644 index a9a99698a52a6..0000000000000 --- a/tests/bluetooth/host/id/bt_le_ext_adv_oob_get_local/src/main.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -DEFINE_FFF_GLOBALS; - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - - SMP_FFF_FAKES_LIST(RESET_FAKE); - CONN_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(bt_le_ext_adv_oob_get_local, NULL, NULL, NULL, NULL, NULL); - -/* - * Get LE local Out Of Band information while privacy isn't enabled - * - * Constraints: - * - Valid references are used for the advertise parameters and the OOB references - * - 'CONFIG_BT_PRIVACY' bit isn't enabled - * - * Expected behaviour: - * - Address is copied to the passed OOB reference - */ -ZTEST(bt_le_ext_adv_oob_get_local, test_get_local_out_of_band_information_no_privacy) -{ - int err; - struct bt_le_oob oob = {0}; - struct bt_le_ext_adv adv = {0}; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_PRIVACY); - - atomic_set_bit(bt_dev.flags, BT_DEV_READY); - - /* ENOTSUP error should not affect the return value of bt_le_ext_adv_oob_get_local() */ - bt_smp_le_oob_generate_sc_data_fake.return_val = -ENOTSUP; - - bt_addr_le_copy(&bt_dev.id_addr[BT_ID_DEFAULT], BT_RPA_LE_ADDR); - - err = bt_le_ext_adv_oob_get_local(&adv, &oob); - - if (IS_ENABLED(CONFIG_BT_SMP)) { - expect_single_call_bt_smp_le_oob_generate_sc_data(&oob.le_sc_data); - } - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_mem_equal(&oob.addr, BT_RPA_LE_ADDR, sizeof(bt_addr_le_t), - "Incorrect address was set"); -} - -/* - * Get LE local Out Of Band information while privacy is enabled - * - * Constraints: - * - Valid references are used for the advertise parameters and the OOB references - * - 'CONFIG_BT_PRIVACY' bit is enabled - * - * Expected behaviour: - * - Address is copied to the passed OOB reference - */ -ZTEST(bt_le_ext_adv_oob_get_local, test_get_local_out_of_band_information_privacy_enabled) -{ - int err; - struct bt_le_oob oob = {0}; - struct bt_le_ext_adv adv = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - - /* ENOTSUP error should not affect the return value of bt_le_ext_adv_oob_get_local() */ - bt_smp_le_oob_generate_sc_data_fake.return_val = -ENOTSUP; - - atomic_set_bit(bt_dev.flags, BT_DEV_READY); - atomic_clear_bit(adv.flags, BT_ADV_USE_IDENTITY); - bt_addr_le_copy(&adv.random_addr, BT_RPA_LE_ADDR); - - err = bt_le_ext_adv_oob_get_local(&adv, &oob); - - if (IS_ENABLED(CONFIG_BT_SMP)) { - expect_single_call_bt_smp_le_oob_generate_sc_data(&oob.le_sc_data); - } - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_mem_equal(&oob.addr, BT_RPA_LE_ADDR, sizeof(bt_addr_le_t), - "Incorrect address was set"); -} diff --git a/tests/bluetooth/host/id/bt_le_ext_adv_oob_get_local/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/id/bt_le_ext_adv_oob_get_local/src/test_suite_invalid_inputs.c deleted file mode 100644 index e3df224932896..0000000000000 --- a/tests/bluetooth/host/id/bt_le_ext_adv_oob_get_local/src/test_suite_invalid_inputs.c +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -ZTEST_SUITE(bt_le_ext_adv_oob_get_local_invalid_inputs, NULL, NULL, NULL, NULL, NULL); - -/* - * Test passing NULL reference for the OOB reference argument - * - * Constraints: - * - NULL reference is used for the advertise parameters reference - * - Valid reference is used for OOB reference - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_le_ext_adv_oob_get_local_invalid_inputs, test_null_adv_reference) -{ - struct bt_le_oob oob = {0}; - - expect_assert(); - bt_le_ext_adv_oob_get_local(NULL, &oob); -} - -/* - * Test passing NULL reference for the OOB reference argument - * - * Constraints: - * - Valid reference is used for the advertise parameters reference - * - NULL reference is used as an argument for the OOB reference - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_le_ext_adv_oob_get_local_invalid_inputs, test_null_oob_reference) -{ - struct bt_le_ext_adv adv = {0}; - - expect_assert(); - bt_le_ext_adv_oob_get_local(&adv, NULL); -} - -/* - * Test trying to get the local LE Out of Band (OOB) information while the device ready flag - * 'BT_DEV_READY' bit isn't set - * - * Constraints: - * - Valid references are used for the advertise parameters and the OOB references - * - 'BT_DEV_READY' bit isn't set in bt_dev.flags - * - * Expected behaviour: - * - '-EAGAIN' error code is returned representing invalid values were used. - */ -ZTEST(bt_le_ext_adv_oob_get_local_invalid_inputs, test_dev_ready_flag_not_set) -{ - int err; - struct bt_le_oob oob = {0}; - struct bt_le_ext_adv adv = {0}; - - atomic_clear_bit(bt_dev.flags, BT_DEV_READY); - - err = bt_le_ext_adv_oob_get_local(&adv, &oob); - - zassert_true(err == -EAGAIN, "Unexpected error code '%d' was returned", err); -} - -/* - * Test RPA can't be updated while a connection is being established - * - * Constraints: - * - Valid references are used for the advertise parameters and the OOB references - * - 'BT_DEV_READY' bit is set in bt_dev.flags - * - 'CONFIG_BT_PRIVACY' bit is enabled - * - 'CONFIG_BT_CENTRAL' bit is enabled - * - 'BT_DEV_INITIATING' bit is set in bt_dev.flags - * - * Expected behaviour: - * - '-EINVAL' error code is returned representing invalid values were used. - */ -ZTEST(bt_le_ext_adv_oob_get_local_invalid_inputs, test_updating_rpa_fails_while_connecting) -{ - int err; - struct bt_conn conn = {0}; - struct bt_le_oob oob = {0}; - struct bt_le_ext_adv adv = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_CENTRAL); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - - atomic_set_bit(bt_dev.flags, BT_DEV_READY); - atomic_set_bit(bt_dev.flags, BT_DEV_INITIATING); - - atomic_clear_bit(adv.flags, BT_ADV_LIMITED); - atomic_clear_bit(adv.flags, BT_ADV_USE_IDENTITY); - - bt_conn_lookup_state_le_fake.return_val = &conn; - - err = bt_le_ext_adv_oob_get_local(&adv, &oob); - - expect_single_call_bt_conn_lookup_state_le(BT_ID_DEFAULT, NULL, - BT_CONN_SCAN_BEFORE_INITIATING); - - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); -} - -/* - * Get LE local Out Of Band information returns an error if bt_smp_le_oob_generate_sc_data() - * failed while privacy isn't enabled - * - * Constraints: - * - Valid references are used for the advertise parameters and the OOB references - * - 'CONFIG_BT_SMP' bit is enabled - * - 'CONFIG_BT_PRIVACY' bit isn't enabled - * - bt_smp_le_oob_generate_sc_data() returns a negative error code other than (-ENOTSUP) - * - * Expected behaviour: - * - bt_le_ext_adv_oob_get_local() returns a negative error code (failure) - */ -ZTEST(bt_le_ext_adv_oob_get_local_invalid_inputs, test_get_local_oob_information_no_privacy) -{ - int err; - struct bt_le_oob oob = {0}; - struct bt_le_ext_adv adv = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_SMP); - Z_TEST_SKIP_IFDEF(CONFIG_BT_PRIVACY); - - atomic_set_bit(bt_dev.flags, BT_DEV_READY); - - bt_smp_le_oob_generate_sc_data_fake.return_val = -1; - - bt_addr_le_copy(&bt_dev.id_addr[BT_ID_DEFAULT], BT_RPA_LE_ADDR); - - err = bt_le_ext_adv_oob_get_local(&adv, &oob); - - expect_single_call_bt_smp_le_oob_generate_sc_data(&oob.le_sc_data); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); - zassert_mem_equal(&oob.addr, BT_RPA_LE_ADDR, sizeof(bt_addr_le_t), - "Incorrect address was set"); -} - -/* - * Get LE local Out Of Band information returns an error if bt_smp_le_oob_generate_sc_data() - * failed while privacy is enabled - * - * Constraints: - * - Valid references are used for the advertise parameters and the OOB references - * - 'CONFIG_BT_SMP' bit is enabled - * - 'CONFIG_BT_PRIVACY' bit is enabled - * - bt_smp_le_oob_generate_sc_data() returns a negative error code other than (-ENOTSUP) - * - * Expected behaviour: - * - bt_le_ext_adv_oob_get_local() returns a negative error code (failure) - */ -ZTEST(bt_le_ext_adv_oob_get_local_invalid_inputs, test_get_local_oob_information_privacy_enabled) -{ - int err; - struct bt_le_oob oob = {0}; - struct bt_le_ext_adv adv = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_SMP); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - - bt_smp_le_oob_generate_sc_data_fake.return_val = -1; - - atomic_set_bit(bt_dev.flags, BT_DEV_READY); - atomic_clear_bit(adv.flags, BT_ADV_USE_IDENTITY); - bt_addr_le_copy(&adv.random_addr, BT_RPA_LE_ADDR); - - err = bt_le_ext_adv_oob_get_local(&adv, &oob); - - expect_single_call_bt_smp_le_oob_generate_sc_data(&oob.le_sc_data); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); - zassert_mem_equal(&oob.addr, BT_RPA_LE_ADDR, sizeof(bt_addr_le_t), - "Incorrect address was set"); -} diff --git a/tests/bluetooth/host/id/bt_le_ext_adv_oob_get_local/testcase.yaml b/tests/bluetooth/host/id/bt_le_ext_adv_oob_get_local/testcase.yaml deleted file mode 100644 index c6ccc3e238253..0000000000000 --- a/tests/bluetooth/host/id/bt_le_ext_adv_oob_get_local/testcase.yaml +++ /dev/null @@ -1,12 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_le_ext_adv_oob_get_local.default: - type: unit - bluetooth.host.bt_le_ext_adv_oob_get_local.bt_privacy_enabled: - type: unit - extra_configs: - - CONFIG_BT_SMP=y - - CONFIG_BT_PRIVACY=y diff --git a/tests/bluetooth/host/id/bt_le_oob_get_local/CMakeLists.txt b/tests/bluetooth/host/id/bt_le_oob_get_local/CMakeLists.txt deleted file mode 100644 index 456273cf99e87..0000000000000 --- a/tests/bluetooth/host/id/bt_le_oob_get_local/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -project(bt_le_oob_get_local) - -# Suppress the format-zero-length error if GNUC is used -if (CMAKE_C_COMPILER_ID MATCHES "GNU") -add_compile_options(-Wno-error=format-zero-length -Wno-format-zero-length) -endif() - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_invalid_inputs.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/id.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -) diff --git a/tests/bluetooth/host/id/bt_le_oob_get_local/prj.conf b/tests/bluetooth/host/id/bt_le_oob_get_local/prj.conf deleted file mode 100644 index 2682cec05b5aa..0000000000000 --- a/tests/bluetooth/host/id/bt_le_oob_get_local/prj.conf +++ /dev/null @@ -1,9 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_SMP=y -CONFIG_BT_ID_MAX=4 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/id/bt_le_oob_get_local/src/main.c b/tests/bluetooth/host/id/bt_le_oob_get_local/src/main.c deleted file mode 100644 index c42d20803e716..0000000000000 --- a/tests/bluetooth/host/id/bt_le_oob_get_local/src/main.c +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -DEFINE_FFF_GLOBALS; - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - - ADV_FFF_FAKES_LIST(RESET_FAKE); - SMP_FFF_FAKES_LIST(RESET_FAKE); - CONN_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(bt_le_oob_get_local, NULL, NULL, NULL, NULL, NULL); - -/* - * Get LE local Out Of Band information while privacy isn't enabled - * - * Constraints: - * - Use a valid reference - * - 'CONFIG_BT_PRIVACY' bit isn't enabled - * - * Expected behaviour: - * - Address is copied to the passed OOB reference - */ -ZTEST(bt_le_oob_get_local, test_get_local_out_of_band_information_no_privacy) -{ - int err; - struct bt_le_oob oob; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_PRIVACY); - - atomic_set_bit(bt_dev.flags, BT_DEV_READY); - - /* Not supported error should not affect the return value of bt_le_oob_get_local() */ - bt_smp_le_oob_generate_sc_data_fake.return_val = -ENOTSUP; - - for (size_t i = 0; i < CONFIG_BT_ID_MAX; i++) { - - SMP_FFF_FAKES_LIST(RESET_FAKE); - memset(bt_dev.id_addr, 0x00, sizeof(bt_dev.id_addr)); - bt_addr_le_copy(&bt_dev.id_addr[i], BT_RPA_LE_ADDR); - - err = bt_le_oob_get_local(i, &oob); - - if (IS_ENABLED(CONFIG_BT_SMP)) { - expect_single_call_bt_smp_le_oob_generate_sc_data(&oob.le_sc_data); - } - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_mem_equal(&oob.addr, BT_RPA_LE_ADDR, sizeof(bt_addr_le_t), - "Incorrect address was set"); - } -} - -/* - * Get LE local Out Of Band information while privacy is enabled - * - * Constraints: - * - Use a valid reference - * - 'CONFIG_BT_PRIVACY' bit is enabled - * - * Expected behaviour: - * - Address is copied to the passed OOB reference - */ -ZTEST(bt_le_oob_get_local, test_get_local_out_of_band_information_privacy_enabled) -{ - int err; - struct bt_le_oob oob; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - - /* Not supported error should not affect the return value of bt_le_oob_get_local() */ - bt_smp_le_oob_generate_sc_data_fake.return_val = -ENOTSUP; - - atomic_set_bit(bt_dev.flags, BT_DEV_READY); - bt_addr_le_copy(&bt_dev.random_addr, BT_RPA_LE_ADDR); - - err = bt_le_oob_get_local(BT_ID_DEFAULT, &oob); - - if (IS_ENABLED(CONFIG_BT_SMP)) { - expect_single_call_bt_smp_le_oob_generate_sc_data(&oob.le_sc_data); - } - - zassert_ok(err, "Unexpected error code '%d' was returned", err); - zassert_mem_equal(&oob.addr, BT_RPA_LE_ADDR, sizeof(bt_addr_le_t), - "Incorrect address was set"); -} diff --git a/tests/bluetooth/host/id/bt_le_oob_get_local/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/id/bt_le_oob_get_local/src/test_suite_invalid_inputs.c deleted file mode 100644 index 477c1ac002446..0000000000000 --- a/tests/bluetooth/host/id/bt_le_oob_get_local/src/test_suite_invalid_inputs.c +++ /dev/null @@ -1,520 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -ZTEST_SUITE(bt_le_oob_get_local_invalid_inputs, NULL, NULL, NULL, NULL, NULL); - -/* - * Test passing NULL reference for the OOB reference argument - * - * Constraints: - * - NULL reference is used as an argument for the OOB reference - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_le_oob_get_local_invalid_inputs, test_null_oob_reference) -{ - expect_assert(); - bt_le_oob_get_local(0x00, NULL); -} - -/* - * Test trying to get the local LE Out of Band (OOB) information while the device ready flag - * 'BT_DEV_READY' bit isn't set - * - * Constraints: - * - A valid reference is used as an argument for the OOB information reference - * - 'BT_DEV_READY' bit isn't set in bt_dev.flags - * - * Expected behaviour: - * - '-EAGAIN' error code is returned representing invalid values were used. - */ -ZTEST(bt_le_oob_get_local_invalid_inputs, test_dev_ready_flag_not_set) -{ - int err; - struct bt_le_oob oob = {0}; - - atomic_clear_bit(bt_dev.flags, BT_DEV_READY); - - err = bt_le_oob_get_local(0x00, &oob); - - zassert_true(err == -EAGAIN, "Unexpected error code '%d' was returned", err); -} - -/* - * Test trying to get the local LE Out of Band (OOB) information if the ID used is out of range. - * - * Constraints: - * - A valid reference is used as an argument for the OOB information reference - * - ID used is out of range or exceeds the maximum value defined by 'CONFIG_BT_ID_MAX' - * - 'BT_DEV_READY' bit is set in bt_dev.flags - * - * Expected behaviour: - * - '-EINVAL' error code is returned representing invalid values were used. - */ -ZTEST(bt_le_oob_get_local_invalid_inputs, test_out_of_range_id_value) -{ - int err; - struct bt_le_oob oob = {0}; - - atomic_set_bit(bt_dev.flags, BT_DEV_READY); - - err = bt_le_oob_get_local(CONFIG_BT_ID_MAX, &oob); - - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); -} - -/* - * Test RPA can't be updated while a connection is being established - * - * Constraints: - * - A valid reference is used as an argument for the OOB information reference - * - ID used is valid - * - 'BT_DEV_READY' bit is set in bt_dev.flags - * - 'CONFIG_BT_PRIVACY' bit is enabled - * - 'CONFIG_BT_CENTRAL' bit is enabled - * - 'BT_DEV_INITIATING' bit is set in bt_dev.flags - * - * Expected behaviour: - * - '-EINVAL' error code is returned representing invalid values were used. - */ -ZTEST(bt_le_oob_get_local_invalid_inputs, test_updating_rpa_fails_while_establishing_connection) -{ - int err; - struct bt_conn conn = {0}; - struct bt_le_oob oob = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_CENTRAL); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - - atomic_set_bit(bt_dev.flags, BT_DEV_READY); - atomic_set_bit(bt_dev.flags, BT_DEV_INITIATING); - - bt_conn_lookup_state_le_fake.return_val = &conn; - - err = bt_le_oob_get_local(BT_ID_DEFAULT, &oob); - - expect_single_call_bt_conn_lookup_state_le(BT_ID_DEFAULT, NULL, - BT_CONN_SCAN_BEFORE_INITIATING); - - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); -} - -/* - * Verify that bt_conn_lookup_state_le() is used to lookup if a connection is being - * established if: - * - Advertise parameters reference is NULL - * - * Constraints: - * - A valid reference is used as an argument for the OOB information reference - * - ID used is valid - * - 'BT_DEV_READY' bit is set in bt_dev.flags - * - 'CONFIG_BT_BROADCASTER' bit is enabled - * - 'CONFIG_BT_PRIVACY' bit is enabled - * - 'CONFIG_BT_CENTRAL' bit is enabled - * - 'BT_DEV_INITIATING' bit is set in bt_dev.flags - * - bt_le_adv_lookup_legacy() returns NULL - * - * Expected behaviour: - * - '-EINVAL' error code is returned representing invalid values were used. - */ -ZTEST(bt_le_oob_get_local_invalid_inputs, test_conn_state_checked_with_null_adv) -{ - int err; - struct bt_conn conn = {0}; - struct bt_le_oob oob = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_BROADCASTER); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_CENTRAL); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - - atomic_set_bit(bt_dev.flags, BT_DEV_READY); - atomic_set_bit(bt_dev.flags, BT_DEV_INITIATING); - - /* This will set the advertise parameters reference to NULL */ - bt_le_adv_lookup_legacy_fake.return_val = NULL; - bt_conn_lookup_state_le_fake.return_val = &conn; - - err = bt_le_oob_get_local(BT_ID_DEFAULT, &oob); - - expect_single_call_bt_le_adv_lookup_legacy(); - expect_single_call_bt_conn_lookup_state_le(BT_ID_DEFAULT, NULL, - BT_CONN_SCAN_BEFORE_INITIATING); - - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); -} - -/* - * Verify that bt_conn_lookup_state_le() is used to lookup if a connection is being - * established if: - * - Advertise parameters reference isn't NULL - * - Advertise parameters reference ID doesn't match the one passed to bt_le_oob_get_local() - * - * Constraints: - * - A valid reference is used as an argument for the OOB information reference - * - ID used is valid - * - 'BT_DEV_READY' bit is set in bt_dev.flags - * - 'CONFIG_BT_BROADCASTER' bit is enabled - * - 'CONFIG_BT_PRIVACY' bit is enabled - * - 'CONFIG_BT_CENTRAL' bit is enabled - * - 'BT_DEV_INITIATING' bit is set in bt_dev.flags - * - bt_le_adv_lookup_legacy() returns a valid advertise parameters reference - * - * Expected behaviour: - * - '-EINVAL' error code is returned representing invalid values were used. - */ -ZTEST(bt_le_oob_get_local_invalid_inputs, test_conn_state_checked_non_matched_id) -{ - int err; - struct bt_conn conn = {0}; - struct bt_le_oob oob = {0}; - struct bt_le_ext_adv adv = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_BROADCASTER); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_CENTRAL); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - - atomic_set_bit(bt_dev.flags, BT_DEV_READY); - atomic_set_bit(bt_dev.flags, BT_DEV_INITIATING); - - adv.id = 1; - atomic_set_bit(adv.flags, BT_ADV_ENABLED); - atomic_set_bit(adv.flags, BT_ADV_USE_IDENTITY); - bt_addr_le_copy(&bt_dev.id_addr[BT_ID_DEFAULT], BT_RPA_LE_ADDR); - - bt_le_adv_lookup_legacy_fake.return_val = &adv; - bt_conn_lookup_state_le_fake.return_val = &conn; - - err = bt_le_oob_get_local(BT_ID_DEFAULT, &oob); - - expect_single_call_bt_le_adv_lookup_legacy(); - expect_single_call_bt_conn_lookup_state_le(BT_ID_DEFAULT, NULL, - BT_CONN_SCAN_BEFORE_INITIATING); - - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); -} - -/* - * Verify that bt_conn_lookup_state_le() is used to lookup if a connection is being - * established if: - * - Advertise parameters reference isn't NULL - * - Advertise parameters reference ID matches the one passed to bt_le_oob_get_local() - * - 'BT_ADV_ENABLED' flags isn't set in advertise parameters reference - * - 'BT_ADV_USE_IDENTITY' flags is set in advertise parameters reference - * - Address type loaded to bt_dev.id_addr[BT_ID_DEFAULT] is random - * - * Constraints: - * - A valid reference is used as an argument for the OOB information reference - * - ID used is valid - * - 'BT_DEV_READY' bit is set in bt_dev.flags - * - 'CONFIG_BT_BROADCASTER' bit is enabled - * - 'CONFIG_BT_PRIVACY' bit is enabled - * - 'CONFIG_BT_CENTRAL' bit is enabled - * - 'BT_DEV_INITIATING' bit is set in bt_dev.flags - * - bt_le_adv_lookup_legacy() returns a valid advertise parameters reference - * - * Expected behaviour: - * - '-EINVAL' error code is returned representing invalid values were used. - */ -ZTEST(bt_le_oob_get_local_invalid_inputs, test_conn_state_checked_adv_enable_not_set) -{ - int err; - struct bt_conn conn = {0}; - struct bt_le_oob oob = {0}; - struct bt_le_ext_adv adv = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_BROADCASTER); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_CENTRAL); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - - atomic_set_bit(bt_dev.flags, BT_DEV_READY); - atomic_set_bit(bt_dev.flags, BT_DEV_INITIATING); - - adv.id = BT_ID_DEFAULT; - atomic_clear_bit(adv.flags, BT_ADV_ENABLED); - atomic_set_bit(adv.flags, BT_ADV_USE_IDENTITY); - bt_addr_le_copy(&bt_dev.id_addr[BT_ID_DEFAULT], BT_RPA_LE_ADDR); - - bt_le_adv_lookup_legacy_fake.return_val = &adv; - bt_conn_lookup_state_le_fake.return_val = &conn; - - err = bt_le_oob_get_local(BT_ID_DEFAULT, &oob); - - expect_single_call_bt_le_adv_lookup_legacy(); - expect_single_call_bt_conn_lookup_state_le(BT_ID_DEFAULT, NULL, - BT_CONN_SCAN_BEFORE_INITIATING); - - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); -} - -/* - * Verify that bt_conn_lookup_state_le() is used to lookup if a connection is being - * established if: - * - Advertise parameters reference isn't NULL - * - Advertise parameters reference ID matches the one passed to bt_le_oob_get_local() - * - 'BT_ADV_ENABLED' flags is set in advertise parameters reference - * - 'BT_ADV_USE_IDENTITY' flags isn't set in advertise parameters reference - * - Address type loaded to bt_dev.id_addr[BT_ID_DEFAULT] is random - * - * Constraints: - * - A valid reference is used as an argument for the OOB information reference - * - ID used is valid - * - 'BT_DEV_READY' bit is set in bt_dev.flags - * - 'CONFIG_BT_BROADCASTER' bit is enabled - * - 'CONFIG_BT_PRIVACY' bit is enabled - * - 'CONFIG_BT_CENTRAL' bit is enabled - * - 'BT_DEV_INITIATING' bit is set in bt_dev.flags - * - bt_le_adv_lookup_legacy() returns a valid advertise parameters reference - * - * Expected behaviour: - * - '-EINVAL' error code is returned representing invalid values were used. - */ -ZTEST(bt_le_oob_get_local_invalid_inputs, test_conn_state_checked_adv_use_identity_not_set) -{ - int err; - struct bt_conn conn = {0}; - struct bt_le_oob oob = {0}; - struct bt_le_ext_adv adv = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_BROADCASTER); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_CENTRAL); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - - atomic_set_bit(bt_dev.flags, BT_DEV_READY); - atomic_set_bit(bt_dev.flags, BT_DEV_INITIATING); - - adv.id = BT_ID_DEFAULT; - atomic_set_bit(adv.flags, BT_ADV_ENABLED); - atomic_clear_bit(adv.flags, BT_ADV_USE_IDENTITY); - bt_addr_le_copy(&bt_dev.id_addr[BT_ID_DEFAULT], BT_RPA_LE_ADDR); - - bt_le_adv_lookup_legacy_fake.return_val = &adv; - bt_conn_lookup_state_le_fake.return_val = &conn; - - err = bt_le_oob_get_local(BT_ID_DEFAULT, &oob); - - expect_single_call_bt_le_adv_lookup_legacy(); - expect_single_call_bt_conn_lookup_state_le(BT_ID_DEFAULT, NULL, - BT_CONN_SCAN_BEFORE_INITIATING); - - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); -} - -/* - * Verify that bt_conn_lookup_state_le() is used to lookup if a connection is being - * established if: - * - Advertise parameters reference isn't NULL - * - Advertise parameters reference ID matches the one passed to bt_le_oob_get_local() - * - 'BT_ADV_ENABLED' flags is set in advertise parameters reference - * - 'BT_ADV_USE_IDENTITY' flags is set in advertise parameters reference - * - Address type loaded to bt_dev.id_addr[BT_ID_DEFAULT] isn't random - * - * Constraints: - * - A valid reference is used as an argument for the OOB information reference - * - ID used is valid - * - 'BT_DEV_READY' bit is set in bt_dev.flags - * - 'CONFIG_BT_BROADCASTER' bit is enabled - * - 'CONFIG_BT_PRIVACY' bit is enabled - * - 'CONFIG_BT_CENTRAL' bit is enabled - * - 'BT_DEV_INITIATING' bit is set in bt_dev.flags - * - bt_le_adv_lookup_legacy() returns a valid advertise parameters reference - * - * Expected behaviour: - * - '-EINVAL' error code is returned representing invalid values were used. - */ -ZTEST(bt_le_oob_get_local_invalid_inputs, test_conn_state_checked_public_dev_address) -{ - int err; - struct bt_conn conn = {0}; - struct bt_le_oob oob = {0}; - struct bt_le_ext_adv adv = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_BROADCASTER); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_CENTRAL); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - - atomic_set_bit(bt_dev.flags, BT_DEV_READY); - atomic_set_bit(bt_dev.flags, BT_DEV_INITIATING); - - adv.id = BT_ID_DEFAULT; - atomic_set_bit(adv.flags, BT_ADV_ENABLED); - atomic_set_bit(adv.flags, BT_ADV_USE_IDENTITY); - bt_addr_le_copy(&bt_dev.id_addr[BT_ID_DEFAULT], BT_LE_ADDR); - - bt_le_adv_lookup_legacy_fake.return_val = &adv; - bt_conn_lookup_state_le_fake.return_val = &conn; - - err = bt_le_oob_get_local(BT_ID_DEFAULT, &oob); - - expect_single_call_bt_le_adv_lookup_legacy(); - expect_single_call_bt_conn_lookup_state_le(BT_ID_DEFAULT, NULL, - BT_CONN_SCAN_BEFORE_INITIATING); - - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); -} - -/* - * Test RPA can't be updated while advertising with random static identity address for a different - * identity. - * - * Constraints: - * - A valid reference is used as an argument for the OOB information reference - * - ID used is valid but different from the one used in advertising - * - 'BT_DEV_READY' bit is set in bt_dev.flags - * - 'CONFIG_BT_PRIVACY' bit is enabled - * - 'CONFIG_BT_BROADCASTER' bit is enabled - * - * Expected behaviour: - * - '-EINVAL' error code is returned representing invalid values were used. - */ -ZTEST(bt_le_oob_get_local_invalid_inputs, test_updating_rpa_fails_while_advertising_random_identity) -{ - int err; - struct bt_le_oob oob = {0}; - struct bt_le_ext_adv adv = {0}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_BROADCASTER); - - atomic_set_bit(bt_dev.flags, BT_DEV_READY); - - adv.id = 1; - atomic_set_bit(adv.flags, BT_ADV_ENABLED); - atomic_set_bit(adv.flags, BT_ADV_USE_IDENTITY); - bt_addr_le_copy(&bt_dev.id_addr[BT_ID_DEFAULT], BT_RPA_LE_ADDR); - - bt_le_adv_lookup_legacy_fake.return_val = &adv; - - err = bt_le_oob_get_local(BT_ID_DEFAULT, &oob); - - expect_single_call_bt_le_adv_lookup_legacy(); - - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); -} - -/* - * Test RPA can't be updated if observer role is enabled and the device is scanning or initiating - * a connection - * - * Constraints: - * - A valid reference is used as an argument for the OOB information reference - * - ID used is valid but different from the one used in advertising - * - 'BT_DEV_READY' bit is set in bt_dev.flags - * - 'CONFIG_BT_PRIVACY' bit is enabled - * - 'CONFIG_BT_OBSERVER' bit is enabled - * - * Expected behaviour: - * - '-EINVAL' error code is returned representing invalid values were used. - */ -ZTEST(bt_le_oob_get_local_invalid_inputs, test_updating_rpa_fails_if_observer_scanning_connecting) -{ - int err; - struct bt_le_oob oob = {0}; - uint32_t testing_flags[] = {BT_DEV_SCANNING, BT_DEV_INITIATING}; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_OBSERVER); - - atomic_set_bit(bt_dev.flags, BT_DEV_READY); - - for (size_t i = 0; i < ARRAY_SIZE(testing_flags); i++) { - atomic_clear_bit(bt_dev.flags, BT_DEV_SCANNING); - atomic_clear_bit(bt_dev.flags, BT_DEV_INITIATING); - - atomic_set_bit(bt_dev.flags, testing_flags[i]); - - err = bt_le_oob_get_local(1, &oob); - - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); - } -} - -/* - * Get LE local Out Of Band information returns an error if bt_smp_le_oob_generate_sc_data() - * failed while privacy isn't enabled - * - * Constraints: - * - Use a valid reference - * - 'CONFIG_BT_SMP' bit is enabled - * - 'CONFIG_BT_PRIVACY' bit isn't enabled - * - bt_smp_le_oob_generate_sc_data() returns a negative error code other than (-ENOTSUP) - * - * Expected behaviour: - * - bt_le_oob_get_local() returns a negative error code (failure) - */ -ZTEST(bt_le_oob_get_local_invalid_inputs, test_get_local_out_of_band_information_no_privacy) -{ - int err; - struct bt_le_oob oob; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_SMP); - Z_TEST_SKIP_IFDEF(CONFIG_BT_PRIVACY); - - atomic_set_bit(bt_dev.flags, BT_DEV_READY); - - bt_smp_le_oob_generate_sc_data_fake.return_val = -1; - - bt_addr_le_copy(&bt_dev.id_addr[BT_ID_DEFAULT], BT_RPA_LE_ADDR); - - err = bt_le_oob_get_local(BT_ID_DEFAULT, &oob); - - expect_single_call_bt_smp_le_oob_generate_sc_data(&oob.le_sc_data); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); - zassert_mem_equal(&oob.addr, BT_RPA_LE_ADDR, sizeof(bt_addr_le_t), - "Incorrect address was set"); -} - -/* - * Get LE local Out Of Band information returns an error if bt_smp_le_oob_generate_sc_data() - * failed while privacy is enabled - * - * Constraints: - * - Use a valid reference - * - 'CONFIG_BT_SMP' bit is enabled - * - 'CONFIG_BT_PRIVACY' bit is enabled - * - bt_smp_le_oob_generate_sc_data() returns a negative error code other than (-ENOTSUP) - * - * Expected behaviour: - * - bt_le_oob_get_local() returns a negative error code (failure) - */ -ZTEST(bt_le_oob_get_local_invalid_inputs, test_get_local_out_of_band_information_privacy_enabled) -{ - int err; - struct bt_le_oob oob; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_SMP); - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - - bt_smp_le_oob_generate_sc_data_fake.return_val = -1; - - atomic_set_bit(bt_dev.flags, BT_DEV_READY); - bt_addr_le_copy(&bt_dev.random_addr, BT_RPA_LE_ADDR); - - err = bt_le_oob_get_local(BT_ID_DEFAULT, &oob); - - expect_single_call_bt_smp_le_oob_generate_sc_data(&oob.le_sc_data); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); - zassert_mem_equal(&oob.addr, BT_RPA_LE_ADDR, sizeof(bt_addr_le_t), - "Incorrect address was set"); -} diff --git a/tests/bluetooth/host/id/bt_le_oob_get_local/testcase.yaml b/tests/bluetooth/host/id/bt_le_oob_get_local/testcase.yaml deleted file mode 100644 index 944bf4fab1af2..0000000000000 --- a/tests/bluetooth/host/id/bt_le_oob_get_local/testcase.yaml +++ /dev/null @@ -1,18 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_le_oob_get_local.default: - type: unit - bluetooth.host.bt_le_oob_get_local.bt_privacy_enabled: - type: unit - extra_configs: - - CONFIG_BT_SMP=y - - CONFIG_BT_PRIVACY=y - bluetooth.host.bt_le_oob_get_local.bt_broadcaster_privacy_enabled: - type: unit - extra_configs: - - CONFIG_BT_SMP=y - - CONFIG_BT_PRIVACY=y - - CONFIG_BT_BROADCASTER=y diff --git a/tests/bluetooth/host/id/bt_le_oob_get_sc_data/CMakeLists.txt b/tests/bluetooth/host/id/bt_le_oob_get_sc_data/CMakeLists.txt deleted file mode 100644 index 53af31acb993f..0000000000000 --- a/tests/bluetooth/host/id/bt_le_oob_get_sc_data/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -project(bt_le_oob_get_sc_data) - -# Suppress the format-zero-length error if GNUC is used -if (CMAKE_C_COMPILER_ID MATCHES "GNU") -add_compile_options(-Wno-error=format-zero-length -Wno-format-zero-length) -endif() - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_invalid_inputs.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/id.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -) diff --git a/tests/bluetooth/host/id/bt_le_oob_get_sc_data/prj.conf b/tests/bluetooth/host/id/bt_le_oob_get_sc_data/prj.conf deleted file mode 100644 index 7041a2b047e4f..0000000000000 --- a/tests/bluetooth/host/id/bt_le_oob_get_sc_data/prj.conf +++ /dev/null @@ -1,10 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_EXT_ADV=y -CONFIG_BT_SMP=y -CONFIG_BT_ID_MAX=4 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/id/bt_le_oob_get_sc_data/src/main.c b/tests/bluetooth/host/id/bt_le_oob_get_sc_data/src/main.c deleted file mode 100644 index fabc600dc9655..0000000000000 --- a/tests/bluetooth/host/id/bt_le_oob_get_sc_data/src/main.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -#include -#include -#include -#include -#include - -DEFINE_FFF_GLOBALS; - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - - SMP_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(bt_le_oob_get_sc_data, NULL, NULL, NULL, NULL, NULL); - -/* - * Test getting OOB information and verify that input arguments are passed correctly to - * bt_smp_le_oob_get_sc_data(). - * - * Constraints: - * - Valid references are used for input parameters - * - 'BT_DEV_READY' bit isn't set in bt_dev.flags - * - bt_smp_le_oob_get_sc_data() returns 0 (success) - * - * Expected behaviour: - * - bt_le_oob_get_sc_data() returns 0 (success) - */ -ZTEST(bt_le_oob_get_sc_data, test_passing_arguments_correctly) -{ - int err; - struct bt_conn conn = {0}; - const struct bt_le_oob_sc_data *oobd_local = {0}; - const struct bt_le_oob_sc_data *oobd_remote = {0}; - - atomic_set_bit(bt_dev.flags, BT_DEV_READY); - bt_smp_le_oob_get_sc_data_fake.return_val = 0; - - err = bt_le_oob_get_sc_data(&conn, &oobd_local, &oobd_remote); - - expect_single_call_bt_smp_le_oob_get_sc_data(&conn, &oobd_local, &oobd_remote); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); -} - -/* - * Test getting OOB information and verify it fails when bt_smp_le_oob_get_sc_data() fails. - * - * Constraints: - * - Valid references are used for input parameters - * - 'BT_DEV_READY' bit isn't set in bt_dev.flags - * - bt_smp_le_oob_get_sc_data() returns '-EINVAL' (failure) - * - * Expected behaviour: - * - bt_le_oob_get_sc_data() returns '-EINVAL' (failure) - */ -ZTEST(bt_le_oob_get_sc_data, test_bt_smp_le_oob_get_sc_data_fails) -{ - int err; - struct bt_conn conn = {0}; - const struct bt_le_oob_sc_data *oobd_local = {0}; - const struct bt_le_oob_sc_data *oobd_remote = {0}; - - atomic_set_bit(bt_dev.flags, BT_DEV_READY); - bt_smp_le_oob_get_sc_data_fake.return_val = -EINVAL; - - err = bt_le_oob_get_sc_data(&conn, &oobd_local, &oobd_remote); - - expect_single_call_bt_smp_le_oob_get_sc_data(&conn, &oobd_local, &oobd_remote); - - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); -} diff --git a/tests/bluetooth/host/id/bt_le_oob_get_sc_data/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/id/bt_le_oob_get_sc_data/src/test_suite_invalid_inputs.c deleted file mode 100644 index 0c4b14d8e0748..0000000000000 --- a/tests/bluetooth/host/id/bt_le_oob_get_sc_data/src/test_suite_invalid_inputs.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" - -#include -#include -#include - -#include -#include -#include - -ZTEST_SUITE(bt_le_oob_get_sc_data_invalid_inputs, NULL, NULL, NULL, NULL, NULL); - -/* - * Test passing NULL reference for the connection reference argument - * - * Constraints: - * - NULL reference is used for the connection reference - * - Valid references are used for other parameters - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_le_oob_get_sc_data_invalid_inputs, test_null_conn_reference) -{ - const struct bt_le_oob_sc_data *oobd_local = {0}; - const struct bt_le_oob_sc_data *oobd_remote = {0}; - - expect_assert(); - bt_le_oob_get_sc_data(NULL, &oobd_local, &oobd_remote); -} - -/* - * Test trying to set OOB data while the device ready flag 'BT_DEV_READY' bit isn't set - * - * Constraints: - * - Valid references are used for input parameters - * - 'BT_DEV_READY' bit isn't set in bt_dev.flags - * - * Expected behaviour: - * - '-EAGAIN' error code is returned representing invalid values were used. - */ -ZTEST(bt_le_oob_get_sc_data_invalid_inputs, test_dev_ready_flag_not_set) -{ - int err; - struct bt_conn conn = {0}; - const struct bt_le_oob_sc_data *oobd_local = {0}; - const struct bt_le_oob_sc_data *oobd_remote = {0}; - - atomic_clear_bit(bt_dev.flags, BT_DEV_READY); - - err = bt_le_oob_get_sc_data(&conn, &oobd_local, &oobd_remote); - - zassert_true(err == -EAGAIN, "Unexpected error code '%d' was returned", err); -} diff --git a/tests/bluetooth/host/id/bt_le_oob_get_sc_data/testcase.yaml b/tests/bluetooth/host/id/bt_le_oob_get_sc_data/testcase.yaml deleted file mode 100644 index 0ebe88f17946b..0000000000000 --- a/tests/bluetooth/host/id/bt_le_oob_get_sc_data/testcase.yaml +++ /dev/null @@ -1,9 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_le_oob_get_sc_data.default: - type: unit - extra_configs: - - CONFIG_BT_SMP=y diff --git a/tests/bluetooth/host/id/bt_le_oob_set_legacy_tk/CMakeLists.txt b/tests/bluetooth/host/id/bt_le_oob_set_legacy_tk/CMakeLists.txt deleted file mode 100644 index 962893f903ccc..0000000000000 --- a/tests/bluetooth/host/id/bt_le_oob_set_legacy_tk/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -project(bt_le_oob_set_legacy_tk) - -# Suppress the format-zero-length error if GNUC is used -if (CMAKE_C_COMPILER_ID MATCHES "GNU") -add_compile_options(-Wno-error=format-zero-length -Wno-format-zero-length) -endif() - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_invalid_inputs.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/id.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -) diff --git a/tests/bluetooth/host/id/bt_le_oob_set_legacy_tk/prj.conf b/tests/bluetooth/host/id/bt_le_oob_set_legacy_tk/prj.conf deleted file mode 100644 index e390d293d14b6..0000000000000 --- a/tests/bluetooth/host/id/bt_le_oob_set_legacy_tk/prj.conf +++ /dev/null @@ -1,11 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_EXT_ADV=y -CONFIG_BT_SMP=y -CONFIG_BT_SMP_SC_PAIR_ONLY=n -CONFIG_BT_ID_MAX=4 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/id/bt_le_oob_set_legacy_tk/src/main.c b/tests/bluetooth/host/id/bt_le_oob_set_legacy_tk/src/main.c deleted file mode 100644 index 1113ec1ee0cb7..0000000000000 --- a/tests/bluetooth/host/id/bt_le_oob_set_legacy_tk/src/main.c +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -#include -#include -#include -#include -#include - -DEFINE_FFF_GLOBALS; - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - - SMP_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(bt_le_oob_set_legacy_tk, NULL, NULL, NULL, NULL, NULL); - -/* - * Test setting OOB Temporary Key to be used for pairing and verify that input arguments are - * passed correctly to bt_smp_le_oob_set_tk(). - * - * Constraints: - * - Valid references are used for the connection and TK references - * - bt_smp_le_oob_set_tk() returns 0 (success) - * - * Expected behaviour: - * - bt_le_oob_set_legacy_tk() returns 0 (success) - */ -ZTEST(bt_le_oob_set_legacy_tk, test_passing_arguments_correctly) -{ - int err; - struct bt_conn conn = {0}; - const uint8_t tk[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - - bt_smp_le_oob_set_tk_fake.return_val = 0; - - err = bt_le_oob_set_legacy_tk(&conn, tk); - - expect_single_call_bt_smp_le_oob_set_tk(&conn, tk); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); -} - -/* - * Test setting OOB Temporary Key to be used for pairing and verify it fails when - * bt_smp_le_oob_set_tk() fails. - * - * Constraints: - * - Valid references are used for the connection and TK references - * - bt_smp_le_oob_set_tk() returns '-EINVAL' (failure) - * - * Expected behaviour: - * - bt_le_oob_set_legacy_tk() returns '-EINVAL' (failure) - */ -ZTEST(bt_le_oob_set_legacy_tk, test_bt_smp_le_oob_set_tk_fails) -{ - int err; - struct bt_conn conn = {0}; - const uint8_t tk[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - - bt_smp_le_oob_set_tk_fake.return_val = -EINVAL; - - err = bt_le_oob_set_legacy_tk(&conn, tk); - - expect_single_call_bt_smp_le_oob_set_tk(&conn, tk); - - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); -} diff --git a/tests/bluetooth/host/id/bt_le_oob_set_legacy_tk/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/id/bt_le_oob_set_legacy_tk/src/test_suite_invalid_inputs.c deleted file mode 100644 index 8697272ab0a94..0000000000000 --- a/tests/bluetooth/host/id/bt_le_oob_set_legacy_tk/src/test_suite_invalid_inputs.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" - -#include -#include -#include - -#include -#include -#include - -ZTEST_SUITE(bt_le_oob_set_legacy_tk_invalid_inputs, NULL, NULL, NULL, NULL, NULL); - -/* - * Test passing NULL reference for the connection reference argument - * - * Constraints: - * - NULL reference is used for the connection reference - * - Valid reference is used for the 'TK' reference - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_le_oob_set_legacy_tk_invalid_inputs, test_null_conn_reference) -{ - const uint8_t tk[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - - expect_assert(); - bt_le_oob_set_legacy_tk(NULL, tk); -} - -/* - * Test passing NULL reference for the 'TK' reference argument - * - * Constraints: - * - Valid reference is used for the connection reference - * - NULL reference is used as an argument for the 'TK' reference - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_le_oob_set_legacy_tk_invalid_inputs, test_null_tk_reference) -{ - struct bt_conn conn = {0}; - - expect_assert(); - bt_le_oob_set_legacy_tk(&conn, NULL); -} diff --git a/tests/bluetooth/host/id/bt_le_oob_set_legacy_tk/testcase.yaml b/tests/bluetooth/host/id/bt_le_oob_set_legacy_tk/testcase.yaml deleted file mode 100644 index 84710668650cf..0000000000000 --- a/tests/bluetooth/host/id/bt_le_oob_set_legacy_tk/testcase.yaml +++ /dev/null @@ -1,9 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_le_oob_set_legacy_tk.default: - type: unit - extra_configs: - - CONFIG_BT_SMP=y diff --git a/tests/bluetooth/host/id/bt_le_oob_set_sc_data/CMakeLists.txt b/tests/bluetooth/host/id/bt_le_oob_set_sc_data/CMakeLists.txt deleted file mode 100644 index 3331c67154df7..0000000000000 --- a/tests/bluetooth/host/id/bt_le_oob_set_sc_data/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -project(bt_le_oob_set_sc_data) - -# Suppress the format-zero-length error if GNUC is used -if (CMAKE_C_COMPILER_ID MATCHES "GNU") -add_compile_options(-Wno-error=format-zero-length -Wno-format-zero-length) -endif() - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_invalid_inputs.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/id.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -) diff --git a/tests/bluetooth/host/id/bt_le_oob_set_sc_data/prj.conf b/tests/bluetooth/host/id/bt_le_oob_set_sc_data/prj.conf deleted file mode 100644 index 7041a2b047e4f..0000000000000 --- a/tests/bluetooth/host/id/bt_le_oob_set_sc_data/prj.conf +++ /dev/null @@ -1,10 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_EXT_ADV=y -CONFIG_BT_SMP=y -CONFIG_BT_ID_MAX=4 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/id/bt_le_oob_set_sc_data/src/main.c b/tests/bluetooth/host/id/bt_le_oob_set_sc_data/src/main.c deleted file mode 100644 index 73c60813b9212..0000000000000 --- a/tests/bluetooth/host/id/bt_le_oob_set_sc_data/src/main.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -#include -#include -#include -#include -#include - -DEFINE_FFF_GLOBALS; - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - - SMP_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(bt_le_oob_set_sc_data, NULL, NULL, NULL, NULL, NULL); - -/* - * Test setting OOB information and verify that input arguments are passed correctly to - * bt_smp_le_oob_set_sc_data(). - * - * Constraints: - * - Valid references are used for input parameters - * - 'BT_DEV_READY' bit isn't set in bt_dev.flags - * - bt_smp_le_oob_set_sc_data() returns 0 (success) - * - * Expected behaviour: - * - bt_le_oob_set_sc_data() returns 0 (success) - */ -ZTEST(bt_le_oob_set_sc_data, test_passing_arguments_correctly) -{ - int err; - struct bt_conn conn = {0}; - const struct bt_le_oob_sc_data oobd_local = {0}; - const struct bt_le_oob_sc_data oobd_remote = {0}; - - atomic_set_bit(bt_dev.flags, BT_DEV_READY); - bt_smp_le_oob_set_sc_data_fake.return_val = 0; - - err = bt_le_oob_set_sc_data(&conn, &oobd_local, &oobd_remote); - - expect_single_call_bt_smp_le_oob_set_sc_data(&conn, &oobd_local, &oobd_remote); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); -} - -/* - * Test setting OOB information and verify it fails when bt_smp_le_oob_set_sc_data() fails. - * - * Constraints: - * - Valid references are used for input parameters - * - 'BT_DEV_READY' bit isn't set in bt_dev.flags - * - bt_smp_le_oob_set_sc_data() returns '-EINVAL' (failure) - * - * Expected behaviour: - * - bt_le_oob_set_sc_data() returns '-EINVAL' (failure) - */ -ZTEST(bt_le_oob_set_sc_data, test_bt_smp_le_oob_set_sc_data_fails) -{ - int err; - struct bt_conn conn = {0}; - const struct bt_le_oob_sc_data oobd_local = {0}; - const struct bt_le_oob_sc_data oobd_remote = {0}; - - atomic_set_bit(bt_dev.flags, BT_DEV_READY); - bt_smp_le_oob_set_sc_data_fake.return_val = -EINVAL; - - err = bt_le_oob_set_sc_data(&conn, &oobd_local, &oobd_remote); - - expect_single_call_bt_smp_le_oob_set_sc_data(&conn, &oobd_local, &oobd_remote); - - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); -} diff --git a/tests/bluetooth/host/id/bt_le_oob_set_sc_data/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/id/bt_le_oob_set_sc_data/src/test_suite_invalid_inputs.c deleted file mode 100644 index 5152b002e7f20..0000000000000 --- a/tests/bluetooth/host/id/bt_le_oob_set_sc_data/src/test_suite_invalid_inputs.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" - -#include -#include -#include - -#include -#include -#include - -ZTEST_SUITE(bt_le_oob_set_sc_data_invalid_inputs, NULL, NULL, NULL, NULL, NULL); - -/* - * Test passing NULL reference for the connection reference argument - * - * Constraints: - * - NULL reference is used for the connection reference - * - Valid references are used for other parameters - * - * Expected behaviour: - * - An assertion is raised and execution stops - */ -ZTEST(bt_le_oob_set_sc_data_invalid_inputs, test_null_conn_reference) -{ - const struct bt_le_oob_sc_data oobd_local = {0}; - const struct bt_le_oob_sc_data oobd_remote = {0}; - - expect_assert(); - bt_le_oob_set_sc_data(NULL, &oobd_local, &oobd_remote); -} - -/* - * Test trying to set OOB data while the device ready flag 'BT_DEV_READY' bit isn't set - * - * Constraints: - * - Valid references are used for input parameters - * - 'BT_DEV_READY' bit isn't set in bt_dev.flags - * - * Expected behaviour: - * - '-EAGAIN' error code is returned representing invalid values were used. - */ -ZTEST(bt_le_oob_set_sc_data_invalid_inputs, test_dev_ready_flag_not_set) -{ - int err; - struct bt_conn conn = {0}; - const struct bt_le_oob_sc_data oobd_local = {0}; - const struct bt_le_oob_sc_data oobd_remote = {0}; - - atomic_clear_bit(bt_dev.flags, BT_DEV_READY); - - err = bt_le_oob_set_sc_data(&conn, &oobd_local, &oobd_remote); - - zassert_true(err == -EAGAIN, "Unexpected error code '%d' was returned", err); -} diff --git a/tests/bluetooth/host/id/bt_le_oob_set_sc_data/testcase.yaml b/tests/bluetooth/host/id/bt_le_oob_set_sc_data/testcase.yaml deleted file mode 100644 index da350f82e96d4..0000000000000 --- a/tests/bluetooth/host/id/bt_le_oob_set_sc_data/testcase.yaml +++ /dev/null @@ -1,9 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_le_oob_set_sc_data.default: - type: unit - extra_configs: - - CONFIG_BT_SMP=y diff --git a/tests/bluetooth/host/id/bt_lookup_id_addr/CMakeLists.txt b/tests/bluetooth/host/id/bt_lookup_id_addr/CMakeLists.txt deleted file mode 100644 index 272ea5df17da2..0000000000000 --- a/tests/bluetooth/host/id/bt_lookup_id_addr/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -project(bt_lookup_id_addr) - -# Suppress the format-zero-length error if GNUC is used -if (CMAKE_C_COMPILER_ID MATCHES "GNU") -add_compile_options(-Wno-error=format-zero-length -Wno-format-zero-length) -endif() - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_bt_lookup_id_addr_invalid_inputs.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/id.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -) diff --git a/tests/bluetooth/host/id/bt_lookup_id_addr/prj.conf b/tests/bluetooth/host/id/bt_lookup_id_addr/prj.conf deleted file mode 100644 index 5f8cdcef01788..0000000000000 --- a/tests/bluetooth/host/id/bt_lookup_id_addr/prj.conf +++ /dev/null @@ -1,8 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_ID_MAX=2 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/id/bt_lookup_id_addr/src/main.c b/tests/bluetooth/host/id/bt_lookup_id_addr/src/main.c deleted file mode 100644 index 8bdead277cbfb..0000000000000 --- a/tests/bluetooth/host/id/bt_lookup_id_addr/src/main.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/keys.h" -#include "mocks/keys_expects.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include - -DEFINE_FFF_GLOBALS; - -/* Hold data representing HCI command response for command BT_HCI_OP_READ_BD_ADDR */ -static struct bt_keys resolving_key; - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - memset(&resolving_key, 0x00, sizeof(struct bt_keys)); - - KEYS_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(bt_lookup_id_addr, NULL, NULL, NULL, NULL, NULL); - -/* - * Test returning the same address pointer passed when 'CONFIG_BT_SMP' isn't enabled - * - * Constraints: - * - A valid ID (< CONFIG_BT_ID_MAX) is used - * - A valid address reference is used - * - 'CONFIG_BT_SMP' isn't enabled - * - * Expected behaviour: - * - bt_lookup_id_addr() returns the same address pointer used as an argument - */ -ZTEST(bt_lookup_id_addr, test_config_bt_smp_not_enabled) -{ - uint8_t id = 0x00; - const bt_addr_le_t *addr = BT_RPA_LE_ADDR; - const bt_addr_le_t *returned_addr; - - Z_TEST_SKIP_IFDEF(CONFIG_BT_SMP); - - returned_addr = bt_lookup_id_addr(id, addr); - - expect_not_called_bt_keys_find_irk(); - - zassert_true(returned_addr == addr, "Incorrect address was returned"); -} - -/* - * Test returning the same address pointer passed when 'CONFIG_BT_SMP' is enabled, but the - * address couldn't be resolved by bt_keys_find_irk(). - * - * Constraints: - * - A valid ID (< CONFIG_BT_ID_MAX) is used - * - A valid address reference is used - * - bt_keys_find_irk() returns NULL (which represents that address couldn't be resolved) - * - 'CONFIG_BT_SMP' is enabled - * - * Expected behaviour: - * - bt_lookup_id_addr() returns the same address pointer used as an argument - */ -ZTEST(bt_lookup_id_addr, test_config_bt_smp_enabled_address_resolving_fails) -{ - uint8_t id = 0x00; - const bt_addr_le_t *addr = BT_RPA_LE_ADDR; - const bt_addr_le_t *returned_addr; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_SMP); - - bt_keys_find_irk_fake.return_val = NULL; - - returned_addr = bt_lookup_id_addr(id, addr); - - expect_single_call_bt_keys_find_irk(id, addr); - - zassert_true(returned_addr == addr, "Incorrect address was returned"); -} - -static struct bt_keys *bt_keys_find_irk_custom_fake(uint8_t id, const bt_addr_le_t *addr) -{ - return &resolving_key; -} - -/* - * Test returning a pointer to the resolved address for the address passed. - * 'CONFIG_BT_SMP' is enabled and address is resolved by bt_keys_find_irk(). - * - * Constraints: - * - A valid ID (< CONFIG_BT_ID_MAX) is used - * - A valid address reference is used - * - bt_keys_find_irk() returns a valid key reference - * - 'CONFIG_BT_SMP' is enabled - * - * Expected behaviour: - * - bt_lookup_id_addr() returns the resolved address instead of the input address - */ -ZTEST(bt_lookup_id_addr, test_config_bt_smp_enabled_address_resolving_succeeds) -{ - uint8_t id = 0x00; - const bt_addr_le_t *addr = BT_RPA_LE_ADDR; - const bt_addr_le_t *returned_addr; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_SMP); - - bt_keys_find_irk_fake.custom_fake = bt_keys_find_irk_custom_fake; - - returned_addr = bt_lookup_id_addr(id, addr); - - expect_single_call_bt_keys_find_irk(id, addr); - - zassert_true(returned_addr == &resolving_key.addr, "Incorrect address was returned"); -} diff --git a/tests/bluetooth/host/id/bt_lookup_id_addr/src/test_suite_bt_lookup_id_addr_invalid_inputs.c b/tests/bluetooth/host/id/bt_lookup_id_addr/src/test_suite_bt_lookup_id_addr_invalid_inputs.c deleted file mode 100644 index 0b4b67dff3a8a..0000000000000 --- a/tests/bluetooth/host/id/bt_lookup_id_addr/src/test_suite_bt_lookup_id_addr_invalid_inputs.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include - -ZTEST_SUITE(bt_lookup_id_addr_invalid_inputs, NULL, NULL, NULL, NULL, NULL); - -/* - * Test function with invalid ID ( >= CONFIG_BT_ID_MAX) - * - * Constraints: - * - An invalid ID value is used - * - A valid address reference is used - * - * Expected behaviour: - * - An assertion fails and execution stops - */ -ZTEST(bt_lookup_id_addr_invalid_inputs, test_invalid_id_address) -{ - const bt_addr_le_t *addr = BT_RPA_LE_ADDR; - - expect_assert(); - bt_lookup_id_addr(CONFIG_BT_ID_MAX, addr); -} - -/* - * Test function with NULL address - * - * Constraints: - * - Any ID value can be used - * - Address is passed as NULL - * - * Expected behaviour: - * - An assertion fails and execution stops - */ -ZTEST(bt_lookup_id_addr_invalid_inputs, test_null_device_address) -{ - expect_assert(); - bt_lookup_id_addr(0x00, NULL); -} diff --git a/tests/bluetooth/host/id/bt_lookup_id_addr/testcase.yaml b/tests/bluetooth/host/id/bt_lookup_id_addr/testcase.yaml deleted file mode 100644 index b75ca2be8757d..0000000000000 --- a/tests/bluetooth/host/id/bt_lookup_id_addr/testcase.yaml +++ /dev/null @@ -1,11 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_lookup_id_addr.default: - type: unit - bluetooth.host.bt_lookup_id_addr.bt_smp_enabled: - type: unit - extra_configs: - - CONFIG_BT_SMP=y diff --git a/tests/bluetooth/host/id/bt_setup_public_id_addr/CMakeLists.txt b/tests/bluetooth/host/id/bt_setup_public_id_addr/CMakeLists.txt deleted file mode 100644 index 402c9ffbb9309..0000000000000 --- a/tests/bluetooth/host/id/bt_setup_public_id_addr/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -project(bt_setup_public_id_addr) - -# Suppress the format-zero-length error if GNUC is used -if (CMAKE_C_COMPILER_ID MATCHES "GNU") -add_compile_options(-Wno-error=format-zero-length -Wno-format-zero-length) -endif() - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_bt_privacy_enabled.c - src/test_suite_bt_settings_enabled.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/id.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -) diff --git a/tests/bluetooth/host/id/bt_setup_public_id_addr/prj.conf b/tests/bluetooth/host/id/bt_setup_public_id_addr/prj.conf deleted file mode 100644 index 42703d413005e..0000000000000 --- a/tests/bluetooth/host/id/bt_setup_public_id_addr/prj.conf +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/id/bt_setup_public_id_addr/src/main.c b/tests/bluetooth/host/id/bt_setup_public_id_addr/src/main.c deleted file mode 100644 index 8c0a65b33b6c5..0000000000000 --- a/tests/bluetooth/host/id/bt_setup_public_id_addr/src/main.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/hci_core.h" -#include "mocks/hci_core_expects.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include - -DEFINE_FFF_GLOBALS; - -/* Hold data representing HCI command response for command BT_HCI_OP_READ_BD_ADDR */ -static struct net_buf hci_cmd_rsp; - -/* Hold data representing response data for HCI command BT_HCI_OP_READ_BD_ADDR */ -static struct bt_hci_rp_read_bd_addr hci_rp_read_bd_addr; - -static void tc_setup(void *f) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - memset(&hci_cmd_rsp, 0x00, sizeof(struct net_buf)); - memset(&hci_rp_read_bd_addr, 0x00, sizeof(struct bt_hci_rp_read_bd_addr)); - - HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); -} - -/* Default test cases to run under all configuration */ -ZTEST_SUITE(bt_setup_public_id_addr_default, NULL, NULL, tc_setup, NULL, NULL); - -/* - * Test reading controller public address fails - * - * Constraints: - * - bt_id_read_public_addr() returns zero - * - * Expected behaviour: - * - ID count is set to 0 and bt_setup_public_id_addr() returns 0 - */ -ZTEST(bt_setup_public_id_addr_default, test_bt_id_read_public_addr_returns_zero) -{ - int err; - - /* This will force bt_id_read_public_addr() to fail */ - bt_hci_cmd_send_sync_fake.return_val = 1; - - err = bt_setup_public_id_addr(); - - zassert_true(bt_dev.id_count == 0, "Incorrect value '%d' was set to bt_dev.id_count", - bt_dev.id_count); - zassert_true(err == 0, "Unexpected error code '%d' was returned", err); -} - -static int bt_hci_cmd_send_sync_custom_fake(uint16_t opcode, struct net_buf *buf, - struct net_buf **rsp) -{ - const char *func_name = "bt_hci_cmd_send_sync"; - - zassert_equal(opcode, BT_HCI_OP_READ_BD_ADDR, "'%s()' was called with incorrect '%s' value", - func_name, "opcode"); - zassert_is_null(buf, "'%s()' was called with incorrect '%s' value", func_name, "buf"); - zassert_not_null(rsp, "'%s()' was called with incorrect '%s' value", func_name, "rsp"); - - *rsp = &hci_cmd_rsp; - hci_cmd_rsp.data = (void *)&hci_rp_read_bd_addr; - - return 0; -} - -/* - * Test reading controller public address through bt_hci_cmd_send_sync(). - * bt_hci_cmd_send_sync() return value is success and response data contains a valid BT address. - * - * Constraints: - * - bt_hci_cmd_send_sync() returns zero - * - Response data contains a valid address - * - * Expected behaviour: - * - Return value is 0 - * - Public address is loaded to bt_dev.id_addr[] - */ -ZTEST(bt_setup_public_id_addr_default, test_bt_id_read_public_addr_returns_valid_id_count) -{ - int err; - struct bt_hci_rp_read_bd_addr *rp = (void *)&hci_rp_read_bd_addr; - - bt_addr_copy(&rp->bdaddr, BT_ADDR); - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - err = bt_setup_public_id_addr(); - - zassert_true(err == 0, "Unexpected error code '%d' was returned", err); - zassert_mem_equal(&bt_dev.id_addr[BT_ID_DEFAULT], BT_LE_ADDR, sizeof(bt_addr_le_t), - "Incorrect address was set"); - zassert_true(bt_dev.id_count == 1, "Incorrect value '%d' was set to bt_dev.id_count", - bt_dev.id_count); -} diff --git a/tests/bluetooth/host/id/bt_setup_public_id_addr/src/test_suite_bt_privacy_enabled.c b/tests/bluetooth/host/id/bt_setup_public_id_addr/src/test_suite_bt_privacy_enabled.c deleted file mode 100644 index 9632a226fc362..0000000000000 --- a/tests/bluetooth/host/id/bt_setup_public_id_addr/src/test_suite_bt_privacy_enabled.c +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#if defined(CONFIG_BT_PRIVACY) - -#include "mocks/crypto.h" -#include "mocks/crypto_expects.h" -#include "mocks/hci_core.h" -#include "mocks/hci_core_expects.h" -#include "mocks/smp.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include - -/* Hold data representing HCI command response for command BT_HCI_OP_READ_BD_ADDR */ -static struct net_buf hci_cmd_rsp; - -/* Hold data representing response data for HCI command BT_HCI_OP_READ_BD_ADDR */ -static struct bt_hci_rp_read_bd_addr hci_rp_read_bd_addr; - -static uint8_t testing_irk_value[16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15}; - -static void tc_setup(void *f) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - memset(&hci_cmd_rsp, 0x00, sizeof(struct net_buf)); - memset(&hci_rp_read_bd_addr, 0x00, sizeof(struct bt_hci_rp_read_bd_addr)); - - SMP_FFF_FAKES_LIST(RESET_FAKE); - CRYPTO_FFF_FAKES_LIST(RESET_FAKE); - HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_SUITE(bt_setup_public_id_addr_privacy_enabled, NULL, NULL, tc_setup, NULL, NULL); - -static int bt_hci_cmd_send_sync_custom_fake(uint16_t opcode, struct net_buf *buf, - struct net_buf **rsp) -{ - const char *func_name = "bt_hci_cmd_send_sync"; - - zassert_equal(opcode, BT_HCI_OP_READ_BD_ADDR, "'%s()' was called with incorrect '%s' value", - func_name, "opcode"); - zassert_is_null(buf, "'%s()' was called with incorrect '%s' value", func_name, "buf"); - zassert_not_null(rsp, "'%s()' was called with incorrect '%s' value", func_name, "rsp"); - - *rsp = &hci_cmd_rsp; - hci_cmd_rsp.data = (void *)&hci_rp_read_bd_addr; - - return 0; -} - -/* - * Test reading controller public address through bt_hci_cmd_send_sync(). - * bt_hci_cmd_send_sync() return value is success and response data contains a valid BT address. - * IRK isn't set by bt_smp_irk_get() and bt_rand() succeeds. - * - * Constraints: - * - bt_hci_cmd_send_sync() returns zero - * - Response data contains a valid address - * - bt_smp_irk_get() returns an error - * - bt_rand() succeeds - * - 'CONFIG_BT_PRIVACY' is enabled - * - * Expected behaviour: - * - Return value is 0 - */ -ZTEST(bt_setup_public_id_addr_privacy_enabled, test_create_default_id_irk_null) -{ - int err; - struct bt_hci_rp_read_bd_addr *rp = (void *)&hci_rp_read_bd_addr; - - bt_addr_copy(&rp->bdaddr, BT_ADDR); - bt_rand_fake.return_val = 0; - bt_smp_irk_get_fake.return_val = -1; - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - err = bt_setup_public_id_addr(); - - expect_single_call_bt_rand(&bt_dev.irk[BT_ID_DEFAULT], 16); - - zassert_true(err == 0, "Unexpected error code '%d' was returned", err); -} - -/* - * Test reading controller public address through bt_hci_cmd_send_sync(). - * bt_hci_cmd_send_sync() return value is success and response data contains a valid BT address. - * As IRK isn't set by bt_smp_irk_get() and bt_rand() fails, an error is returned. - * - * Constraints: - * - bt_hci_cmd_send_sync() returns zero - * - Response data contains a valid address - * - bt_smp_irk_get() returns an error - * - bt_rand() returns an error - * - 'CONFIG_BT_PRIVACY' is enabled - * - * Expected behaviour: - * - Return value isn't 0 and equal to the error returned by bt_rand() - */ -ZTEST(bt_setup_public_id_addr_privacy_enabled, test_create_default_id_irk_null_bt_rand_fails) -{ - int err; - struct bt_hci_rp_read_bd_addr *rp = (void *)&hci_rp_read_bd_addr; - - bt_addr_copy(&rp->bdaddr, BT_ADDR); - bt_rand_fake.return_val = -1; - bt_smp_irk_get_fake.return_val = -1; - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - err = bt_setup_public_id_addr(); - - expect_single_call_bt_rand(&bt_dev.irk[BT_ID_DEFAULT], 16); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); -} - -static int bt_smp_irk_get_fill_zero_irk_custom_fake(uint8_t *ir, uint8_t *irk) -{ - __ASSERT_NO_MSG(ir != NULL); - __ASSERT_NO_MSG(irk != NULL); - - memset(irk, 0x00, 16); - - return 0; -} - -/* - * Test reading controller public address through bt_hci_cmd_send_sync(). - * bt_hci_cmd_send_sync() return value is success and response data contains a valid BT address. - * IRK isn't set by bt_smp_irk_get() and bt_rand() succeeds. - * - * Constraints: - * - bt_hci_cmd_send_sync() returns zero - * - Response data contains a valid address - * - bt_smp_irk_get() succeeds - * - bt_rand() succeeds - * - 'CONFIG_BT_PRIVACY' is enabled - * - * Expected behaviour: - * - Return value is 0 - */ -ZTEST(bt_setup_public_id_addr_privacy_enabled, test_create_default_id_irk_not_null_but_cleared) -{ - int err; - struct bt_hci_rp_read_bd_addr *rp = (void *)&hci_rp_read_bd_addr; - - bt_addr_copy(&rp->bdaddr, BT_ADDR); - bt_rand_fake.return_val = 0; - bt_smp_irk_get_fake.custom_fake = bt_smp_irk_get_fill_zero_irk_custom_fake; - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - err = bt_setup_public_id_addr(); - - expect_single_call_bt_rand(&bt_dev.irk[BT_ID_DEFAULT], 16); - - zassert_true(err == 0, "Unexpected error code '%d' was returned", err); -} - -static int bt_smp_irk_get_non_zero_irk_custom_fake(uint8_t *ir, uint8_t *irk) -{ - __ASSERT_NO_MSG(ir != NULL); - __ASSERT_NO_MSG(irk != NULL); - - memcpy(irk, testing_irk_value, 16); - - return 0; -} - -/* - * Test reading controller public address through bt_hci_cmd_send_sync(). - * bt_hci_cmd_send_sync() return value is success and response data contains a valid BT address. - * IRK is set by bt_smp_irk_get() - * - * Constraints: - * - bt_hci_cmd_send_sync() returns zero - * - Response data contains a valid address - * - bt_smp_irk_get() succeeds - * - 'CONFIG_BT_PRIVACY' is enabled - * - * Expected behaviour: - * - Return value is 0 - * - IRK is loaded to bt_dev.irk[] - */ -ZTEST(bt_setup_public_id_addr_privacy_enabled, test_create_default_id_irk_not_null_and_filled) -{ - int err; - struct bt_hci_rp_read_bd_addr *rp = (void *)&hci_rp_read_bd_addr; - - bt_addr_copy(&rp->bdaddr, BT_ADDR); - bt_smp_irk_get_fake.custom_fake = bt_smp_irk_get_non_zero_irk_custom_fake; - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - err = bt_setup_public_id_addr(); - - expect_not_called_bt_rand(); - - zassert_true(err == 0, "Unexpected error code '%d' was returned", err); - zassert_mem_equal(&bt_dev.irk[BT_ID_DEFAULT], testing_irk_value, sizeof(testing_irk_value), - "Incorrect IRK value was set"); -} -#endif diff --git a/tests/bluetooth/host/id/bt_setup_public_id_addr/src/test_suite_bt_settings_enabled.c b/tests/bluetooth/host/id/bt_setup_public_id_addr/src/test_suite_bt_settings_enabled.c deleted file mode 100644 index 77313336f2a4e..0000000000000 --- a/tests/bluetooth/host/id/bt_setup_public_id_addr/src/test_suite_bt_settings_enabled.c +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/hci_core.h" -#include "mocks/hci_core_expects.h" -#include "mocks/settings.h" -#include "mocks/settings_expects.h" -#include "mocks/smp.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include -#include - -/* Hold data representing HCI command response for command BT_HCI_OP_READ_BD_ADDR */ -static struct net_buf hci_cmd_rsp; - -/* Hold data representing response data for HCI command BT_HCI_OP_READ_BD_ADDR */ -static struct bt_hci_rp_read_bd_addr hci_rp_read_bd_addr; - -static void tc_setup(void *f) -{ - Z_TEST_SKIP_IFNDEF(CONFIG_BT_SETTINGS); - - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - memset(&hci_cmd_rsp, 0x00, sizeof(struct net_buf)); - memset(&hci_rp_read_bd_addr, 0x00, sizeof(struct bt_hci_rp_read_bd_addr)); - - HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); - SETTINGS_FFF_FAKES_LIST(RESET_FAKE); - - if (IS_ENABLED(CONFIG_BT_PRIVACY)) { - SMP_FFF_FAKES_LIST(RESET_FAKE); - } -} - -ZTEST_SUITE(bt_setup_public_id_addr_bt_settings_enabled, NULL, NULL, tc_setup, NULL, NULL); - -/* - * Test reading controller public address fails and no attempt to store settings. - * - * Constraints: - * - bt_id_read_public_addr() returns zero - * - * Expected behaviour: - * - ID count is set to 0 and bt_setup_public_id_addr() returns 0 - * - No expected calls to bt_settings_store_id() - */ -ZTEST(bt_setup_public_id_addr_bt_settings_enabled, test_bt_id_read_public_addr_returns_zero) -{ - int err; - - /* This will force bt_id_read_public_addr() to fail */ - bt_hci_cmd_send_sync_fake.return_val = 1; - - err = bt_setup_public_id_addr(); - - expect_not_called_bt_settings_store_id(); - - zassert_true(bt_dev.id_count == 0, "Incorrect value '%d' was set to bt_dev.id_count", - bt_dev.id_count); - zassert_true(err == 0, "Unexpected error code '%d' was returned", err); -} - -static int bt_hci_cmd_send_sync_custom_fake(uint16_t opcode, struct net_buf *buf, - struct net_buf **rsp) -{ - const char *func_name = "bt_hci_cmd_send_sync"; - - zassert_equal(opcode, BT_HCI_OP_READ_BD_ADDR, "'%s()' was called with incorrect '%s' value", - func_name, "opcode"); - zassert_is_null(buf, "'%s()' was called with incorrect '%s' value", func_name, "buf"); - zassert_not_null(rsp, "'%s()' was called with incorrect '%s' value", func_name, "rsp"); - - *rsp = &hci_cmd_rsp; - hci_cmd_rsp.data = (void *)&hci_rp_read_bd_addr; - - return 0; -} - -/* - * Test reading controller public address through bt_hci_cmd_send_sync(). - * Even if the operation succeeded, bt_settings_store_id() shouldn't be called to - * store settings as the 'BT_DEV_READY' bit isn't set. - * - * Constraints: - * - bt_hci_cmd_send_sync() returns zero - * - Response data contains a valid address - * - BT_DEV_READY bit isn't set in bt_dev.flags - * - * Expected behaviour: - * - Return value is 0 - * - Public address is loaded to bt_dev.id_addr[] - * - No expected calls to bt_settings_save_id() - */ -ZTEST(bt_setup_public_id_addr_bt_settings_enabled, - test_bt_id_read_public_addr_succeeds_bt_dev_ready_cleared) -{ - int err; - struct bt_hci_rp_read_bd_addr *rp = (void *)&hci_rp_read_bd_addr; - - bt_addr_copy(&rp->bdaddr, BT_ADDR); - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - atomic_clear_bit(bt_dev.flags, BT_DEV_READY); - - err = bt_setup_public_id_addr(); - - expect_not_called_bt_settings_store_id(); - - zassert_true(err == 0, "Unexpected error code '%d' was returned", err); - zassert_mem_equal(&bt_dev.id_addr[BT_ID_DEFAULT], BT_LE_ADDR, sizeof(bt_addr_le_t), - "Incorrect address was set"); - zassert_true(bt_dev.id_count == 1, "Incorrect value '%d' was set to bt_dev.id_count", - bt_dev.id_count); -} - -/* - * Test reading controller public address through bt_hci_cmd_send_sync(). With - * the 'BT_DEV_READY' bit set, bt_settings_store_id() should be called to store - * settings to persistent memory. - * - * Constraints: - * - bt_hci_cmd_send_sync() returns zero - * - Response data contains a valid address - * - BT_DEV_READY bit isn't set in bt_dev.flags - * - * Expected behaviour: - * - Return value is 0 - * - Public address is loaded to bt_dev.id_addr[] - * - No expected calls to bt_settings_save_id() - */ -ZTEST(bt_setup_public_id_addr_bt_settings_enabled, - test_bt_id_read_public_addr_succeeds_bt_dev_ready_set) -{ - int err; - struct bt_hci_rp_read_bd_addr *rp = (void *)&hci_rp_read_bd_addr; - - bt_addr_copy(&rp->bdaddr, BT_ADDR); - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - atomic_set_bit(bt_dev.flags, BT_DEV_READY); - - err = bt_setup_public_id_addr(); - - expect_single_call_bt_settings_store_id(); - - zassert_true(err == 0, "Unexpected error code '%d' was returned", err); - zassert_mem_equal(&bt_dev.id_addr[BT_ID_DEFAULT], BT_LE_ADDR, sizeof(bt_addr_le_t), - "Incorrect address was set"); - zassert_true(bt_dev.id_count == 1, "Incorrect value '%d' was set to bt_dev.id_count", - bt_dev.id_count); -} - -/* - * Test reading controller public address through bt_hci_cmd_send_sync(). - * 'BT_DEV_STORE_ID' should be set when IRK isn't set. - * - * Constraints: - * - bt_hci_cmd_send_sync() returns zero - * - Response data contains a valid address - * - CONFIG_BT_PRIVACY is enabled - * - * Expected behaviour: - * - Return value is 0 - * - 'BT_DEV_STORE_ID' bit is set inside bt_dev.flags - */ -ZTEST(bt_setup_public_id_addr_bt_settings_enabled, test_store_flag_set_correctly) -{ - int err; - struct bt_hci_rp_read_bd_addr *rp = (void *)&hci_rp_read_bd_addr; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - - bt_addr_copy(&rp->bdaddr, BT_ADDR); - bt_smp_irk_get_fake.return_val = 1; - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - err = bt_setup_public_id_addr(); - - zassert_true(err == 0, "Unexpected error code '%d' was returned", err); - zassert_true(atomic_test_bit(bt_dev.flags, BT_DEV_STORE_ID), - "Flags were not correctly set"); -} diff --git a/tests/bluetooth/host/id/bt_setup_public_id_addr/testcase.yaml b/tests/bluetooth/host/id/bt_setup_public_id_addr/testcase.yaml deleted file mode 100644 index c3ce438cb3eff..0000000000000 --- a/tests/bluetooth/host/id/bt_setup_public_id_addr/testcase.yaml +++ /dev/null @@ -1,24 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_setup_public_id_addr.default: - type: unit - bluetooth.host.bt_setup_public_id_addr.default_bt_settings_enabled: - type: unit - extra_configs: - - CONFIG_SETTINGS=y - - CONFIG_BT_SETTINGS=y - bluetooth.host.bt_setup_public_id_addr.bt_privacy_enabled: - type: unit - extra_configs: - - CONFIG_BT_SMP=y - - CONFIG_BT_PRIVACY=y - bluetooth.host.bt_setup_public_id_addr.bt_privacy_settings_enabled: - type: unit - extra_configs: - - CONFIG_BT_SMP=y - - CONFIG_BT_PRIVACY=y - - CONFIG_SETTINGS=y - - CONFIG_BT_SETTINGS=y diff --git a/tests/bluetooth/host/id/bt_setup_random_id_addr/CMakeLists.txt b/tests/bluetooth/host/id/bt_setup_random_id_addr/CMakeLists.txt deleted file mode 100644 index f1622b9ae6025..0000000000000 --- a/tests/bluetooth/host/id/bt_setup_random_id_addr/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -project(bt_setup_random_id_addr) - -# Suppress the format-zero-length error if GNUC is used -if (CMAKE_C_COMPILER_ID MATCHES "GNU") -add_compile_options(-Wno-error=format-zero-length -Wno-format-zero-length) -endif() - -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/id/mocks mocks) - -include_directories(BEFORE - ${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks -) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_invalid_cases.c - src/test_suite_bt_privacy_enabled.c - src/test_suite_bt_settings_enabled.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/id.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -) diff --git a/tests/bluetooth/host/id/bt_setup_random_id_addr/prj.conf b/tests/bluetooth/host/id/bt_setup_random_id_addr/prj.conf deleted file mode 100644 index 42703d413005e..0000000000000 --- a/tests/bluetooth/host/id/bt_setup_random_id_addr/prj.conf +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/id/bt_setup_random_id_addr/src/main.c b/tests/bluetooth/host/id/bt_setup_random_id_addr/src/main.c deleted file mode 100644 index 2dfef10f45c26..0000000000000 --- a/tests/bluetooth/host/id/bt_setup_random_id_addr/src/main.c +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/hci_core.h" -#include "mocks/hci_core_expects.h" -#include "mocks/net_buf.h" -#include "mocks/net_buf_expects.h" -#include "testing_common_defs.h" - -#include -#include -#include -#include - -#include -#include - -DEFINE_FFF_GLOBALS; - -/* Hold data representing HCI command response for command BT_HCI_OP_VS_READ_STATIC_ADDRS */ -static struct net_buf hci_cmd_rsp; - -/* Hold data representing response data for HCI command BT_HCI_OP_VS_READ_STATIC_ADDRS */ -static struct custom_bt_hci_rp_vs_read_static_addrs { - struct bt_hci_rp_vs_read_static_addrs hci_rp_vs_read_static_addrs; - struct bt_hci_vs_static_addr hci_vs_static_addr[CONFIG_BT_ID_MAX]; -} __packed hci_cmd_rsp_data; - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - - NET_BUF_FFF_FAKES_LIST(RESET_FAKE); - HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -static void tc_setup(void *f) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - memset(&hci_cmd_rsp, 0x00, sizeof(struct net_buf)); - memset(&hci_cmd_rsp_data, 0x00, sizeof(struct custom_bt_hci_rp_vs_read_static_addrs)); - - NET_BUF_FFF_FAKES_LIST(RESET_FAKE); - HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_SUITE(bt_setup_random_id_addr, NULL, NULL, tc_setup, NULL, NULL); - -static int bt_hci_cmd_send_sync_custom_fake(uint16_t opcode, struct net_buf *buf, - struct net_buf **rsp) -{ - const char *func_name = "bt_hci_cmd_send_sync"; - - zassert_equal(opcode, BT_HCI_OP_VS_READ_STATIC_ADDRS, - "'%s()' was called with incorrect '%s' value", func_name, "opcode"); - zassert_is_null(buf, "'%s()' was called with incorrect '%s' value", func_name, "buf"); - zassert_not_null(rsp, "'%s()' was called with incorrect '%s' value", func_name, "rsp"); - - *rsp = &hci_cmd_rsp; - hci_cmd_rsp.data = (void *)&hci_cmd_rsp_data.hci_rp_vs_read_static_addrs; - - return 0; -} - -/* - * Test reading controller static random address through bt_hci_cmd_send_sync(). - * bt_hci_cmd_send_sync() returns 0 (success), the returned number of addresses - * is 1, and actual addresses information exists in the response. - * - * Response size should follow the formula - * hci_cmd_rsp.len = sizeof(struct bt_hci_rp_vs_read_static_addrs) + - * rp->num_addrs * sizeof(struct bt_hci_vs_static_addr); - * - * Response length is properly configured, and response data contains a valid identity - * information. - * - * Constraints: - * - bt_hci_cmd_send_sync() returns 0 (success) - * - bt_hci_cmd_send_sync() response contains single identity address - * - * Expected behaviour: - * - Non-zero positive number equals to the number of addresses in the response - */ -ZTEST(bt_setup_random_id_addr, test_bt_hci_cmd_send_sync_returns_single_identity) -{ - int err; - uint16_t *vs_commands = (uint16_t *)bt_dev.vs_commands; - struct bt_hci_rp_vs_read_static_addrs *rp = - (void *)&hci_cmd_rsp_data.hci_rp_vs_read_static_addrs; - struct bt_hci_vs_static_addr *static_addr = (void *)&hci_cmd_rsp_data.hci_vs_static_addr; - - *vs_commands = (1 << BT_VS_CMD_BIT_READ_STATIC_ADDRS); - - rp->num_addrs = 1; - bt_addr_copy(&static_addr[0].bdaddr, &BT_STATIC_RANDOM_LE_ADDR_1->a); - - hci_cmd_rsp.len = sizeof(struct bt_hci_rp_vs_read_static_addrs) + - rp->num_addrs * sizeof(struct bt_hci_vs_static_addr); - - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - err = bt_setup_random_id_addr(); - - expect_single_call_bt_hci_cmd_send_sync(BT_HCI_OP_VS_READ_STATIC_ADDRS); - expect_single_call_net_buf_unref(&hci_cmd_rsp); - - zassert_true(err == 0, "Unexpected error code '%d' was returned", err); - - zassert_true(bt_dev.id_count == 1, "Incorrect value '%d' was set to bt_dev.id_count", - bt_dev.id_count); - - zassert_mem_equal(&bt_dev.id_addr[0], BT_STATIC_RANDOM_LE_ADDR_1, sizeof(bt_addr_le_t), - "Incorrect address was set"); -} - -#if CONFIG_BT_ID_MAX > 1 - -/* - * Test reading controller static random address through bt_hci_cmd_send_sync(). - * bt_hci_cmd_send_sync() returns 0 (success), the returned number of addresses - * is 2, and actual addresses information exists in the response. - * - * Response size should follow the formula - * hci_cmd_rsp.len = sizeof(struct bt_hci_rp_vs_read_static_addrs) + - * rp->num_addrs * sizeof(struct bt_hci_vs_static_addr); - * - * Response length is properly configured, and response data contains a mixed data with - * 2 identities. - * - * Constraints: - * - bt_hci_cmd_send_sync() returns 0 (success) - * - bt_hci_cmd_send_sync() response contains multiple identities, but only one is a static - * random address and the other should be discarded - * - * Expected behaviour: - * - Non-zero positive number equals to the number of addresses in the response - */ -ZTEST(bt_setup_random_id_addr, test_bt_hci_cmd_send_sync_returns_single_valid_identity) -{ - int err; - uint16_t *vs_commands = (uint16_t *)bt_dev.vs_commands; - struct bt_hci_rp_vs_read_static_addrs *rp = - (void *)&hci_cmd_rsp_data.hci_rp_vs_read_static_addrs; - struct bt_hci_vs_static_addr *static_addr = (void *)&hci_cmd_rsp_data.hci_vs_static_addr; - - *vs_commands = (1 << BT_VS_CMD_BIT_READ_STATIC_ADDRS); - - rp->num_addrs = 2; - bt_addr_copy(&static_addr[0].bdaddr, &BT_STATIC_RANDOM_LE_ADDR_1->a); - bt_addr_copy(&static_addr[1].bdaddr, BT_ADDR); - - hci_cmd_rsp.len = sizeof(struct bt_hci_rp_vs_read_static_addrs) + - rp->num_addrs * sizeof(struct bt_hci_vs_static_addr); - - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - err = bt_setup_random_id_addr(); - - expect_single_call_bt_hci_cmd_send_sync(BT_HCI_OP_VS_READ_STATIC_ADDRS); - expect_single_call_net_buf_unref(&hci_cmd_rsp); - - zassert_true(err == 0, "Unexpected error code '%d' was returned", err); - - zassert_true(bt_dev.id_count == 2, "Incorrect value '%d' was set to bt_dev.id_count", - bt_dev.id_count); - - zassert_mem_equal(&bt_dev.id_addr[0], BT_STATIC_RANDOM_LE_ADDR_1, sizeof(bt_addr_le_t), - "Incorrect address was set"); - zassert_mem_equal(&bt_dev.id_addr[1].a, BT_ADDR, sizeof(bt_addr_t), - "Incorrect address was set"); - zassert_equal(bt_dev.id_addr[1].type, BT_ADDR_LE_RANDOM, "Incorrect address was set"); -} - -/* - * Test reading controller static random address through bt_hci_cmd_send_sync(). - * bt_hci_cmd_send_sync() returns 0 (success), the returned number of addresses - * is 2, and actual addresses information exists in the response. - * - * Response size should follow the formula - * hci_cmd_rsp.len = sizeof(struct bt_hci_rp_vs_read_static_addrs) + - * rp->num_addrs * sizeof(struct bt_hci_vs_static_addr); - * - * Response length is properly configured, and response data contains 2 valid identities. - * - * Constraints: - * - bt_hci_cmd_send_sync() returns 0 (success) - * - bt_hci_cmd_send_sync() response contains multiple identity addresses - * - * Expected behaviour: - * - Non-zero positive number equals to the number of addresses in the response - */ -ZTEST(bt_setup_random_id_addr, test_bt_hci_cmd_send_sync_returns_multiple_identities) -{ - int err; - uint16_t *vs_commands = (uint16_t *)bt_dev.vs_commands; - struct bt_hci_rp_vs_read_static_addrs *rp = - (void *)&hci_cmd_rsp_data.hci_rp_vs_read_static_addrs; - struct bt_hci_vs_static_addr *static_addr = (void *)&hci_cmd_rsp_data.hci_vs_static_addr; - - *vs_commands = (1 << BT_VS_CMD_BIT_READ_STATIC_ADDRS); - - rp->num_addrs = 2; - bt_addr_copy(&static_addr[0].bdaddr, &BT_STATIC_RANDOM_LE_ADDR_1->a); - bt_addr_copy(&static_addr[1].bdaddr, &BT_STATIC_RANDOM_LE_ADDR_2->a); - - hci_cmd_rsp.len = sizeof(struct bt_hci_rp_vs_read_static_addrs) + - rp->num_addrs * sizeof(struct bt_hci_vs_static_addr); - - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - err = bt_setup_random_id_addr(); - - expect_single_call_bt_hci_cmd_send_sync(BT_HCI_OP_VS_READ_STATIC_ADDRS); - expect_single_call_net_buf_unref(&hci_cmd_rsp); - - zassert_true(err == 0, "Unexpected error code '%d' was returned", err); - - zassert_true(bt_dev.id_count == 2, "Incorrect value '%d' was set to bt_dev.id_count", - bt_dev.id_count); - - zassert_mem_equal(&bt_dev.id_addr[0], BT_STATIC_RANDOM_LE_ADDR_1, sizeof(bt_addr_le_t), - "Incorrect address was set"); - zassert_mem_equal(&bt_dev.id_addr[1], BT_STATIC_RANDOM_LE_ADDR_2, sizeof(bt_addr_le_t), - "Incorrect address was set"); -} -#endif /* CONFIG_BT_ID_MAX > 1 */ diff --git a/tests/bluetooth/host/id/bt_setup_random_id_addr/src/test_suite_bt_privacy_enabled.c b/tests/bluetooth/host/id/bt_setup_random_id_addr/src/test_suite_bt_privacy_enabled.c deleted file mode 100644 index 4d7d7e2674bf4..0000000000000 --- a/tests/bluetooth/host/id/bt_setup_random_id_addr/src/test_suite_bt_privacy_enabled.c +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#if defined(CONFIG_BT_PRIVACY) - -#include "mocks/crypto.h" -#include "mocks/crypto_expects.h" -#include "mocks/hci_core.h" -#include "mocks/hci_core_expects.h" -#include "mocks/smp.h" -#include "testing_common_defs.h" - -#include -#include -#include -#include - -#include -#include - -/* Hold data representing HCI command response for command BT_HCI_OP_VS_READ_STATIC_ADDRS */ -static struct net_buf hci_cmd_rsp; - -/* Hold data representing response data for HCI command BT_HCI_OP_VS_READ_STATIC_ADDRS */ -static struct custom_bt_hci_rp_vs_read_static_addrs { - struct bt_hci_rp_vs_read_static_addrs hci_rp_vs_read_static_addrs; - struct bt_hci_vs_static_addr hci_vs_static_addr[CONFIG_BT_ID_MAX]; -} __packed hci_cmd_rsp_data; - -static uint8_t testing_irk_value[16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15}; - -static void tc_setup(void *f) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - memset(&hci_cmd_rsp, 0x00, sizeof(struct net_buf)); - memset(&hci_cmd_rsp_data, 0x00, sizeof(struct custom_bt_hci_rp_vs_read_static_addrs)); - - SMP_FFF_FAKES_LIST(RESET_FAKE); - CRYPTO_FFF_FAKES_LIST(RESET_FAKE); - HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_SUITE(bt_setup_random_id_addr_privacy_enabled, NULL, NULL, tc_setup, NULL, NULL); - -static int bt_hci_cmd_send_sync_custom_fake(uint16_t opcode, struct net_buf *buf, - struct net_buf **rsp) -{ - const char *func_name = "bt_hci_cmd_send_sync"; - - zassert_equal(opcode, BT_HCI_OP_VS_READ_STATIC_ADDRS, - "'%s()' was called with incorrect '%s' value", func_name, "opcode"); - zassert_is_null(buf, "'%s()' was called with incorrect '%s' value", func_name, "buf"); - zassert_not_null(rsp, "'%s()' was called with incorrect '%s' value", func_name, "rsp"); - - *rsp = &hci_cmd_rsp; - hci_cmd_rsp.data = (void *)&hci_cmd_rsp_data.hci_rp_vs_read_static_addrs; - - return 0; -} - -/* - * Test reading controller random address through bt_hci_cmd_send_sync(). - * bt_hci_cmd_send_sync() return value is success and response data contains a valid BT address. - * IRK isn't set by bt_smp_irk_get() and bt_rand() succeeds. - * - * Constraints: - * - bt_hci_cmd_send_sync() returns zero - * - Response data contains a valid address - * - bt_smp_irk_get() returns an error - * - bt_rand() succeeds - * - 'CONFIG_BT_PRIVACY' is enabled - * - * Expected behaviour: - * - Return value is 0 - */ -ZTEST(bt_setup_random_id_addr_privacy_enabled, test_create_id_irk_null) -{ - int err; - uint16_t *vs_commands = (uint16_t *)bt_dev.vs_commands; - struct bt_hci_rp_vs_read_static_addrs *rp = - (void *)&hci_cmd_rsp_data.hci_rp_vs_read_static_addrs; - struct bt_hci_vs_static_addr *static_addr = (void *)&hci_cmd_rsp_data.hci_vs_static_addr; - - *vs_commands = (1 << BT_VS_CMD_BIT_READ_STATIC_ADDRS); - - rp->num_addrs = 1; - bt_addr_copy(&static_addr[0].bdaddr, &BT_STATIC_RANDOM_LE_ADDR_1->a); - - hci_cmd_rsp.len = sizeof(struct bt_hci_rp_vs_read_static_addrs) + - rp->num_addrs * sizeof(struct bt_hci_vs_static_addr); - - bt_rand_fake.return_val = 0; - bt_smp_irk_get_fake.return_val = -1; - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - err = bt_setup_random_id_addr(); - - expect_single_call_bt_rand(&bt_dev.irk[0], 16); - - zassert_true(err == 0, "Unexpected error code '%d' was returned", err); -} - -/* - * Test reading controller random address through bt_hci_cmd_send_sync(). - * bt_hci_cmd_send_sync() return value is success and response data contains a valid BT address. - * As IRK isn't set by bt_smp_irk_get() and bt_rand() fails, an error is returned. - * - * Constraints: - * - bt_hci_cmd_send_sync() returns zero - * - Response data contains a valid address - * - bt_smp_irk_get() returns an error - * - bt_rand() returns an error - * - 'CONFIG_BT_PRIVACY' is enabled - * - * Expected behaviour: - * - Return value isn't 0 and equal to the error returned by bt_rand() - */ -ZTEST(bt_setup_random_id_addr_privacy_enabled, test_create_id_irk_null_bt_rand_fails) -{ - int err; - uint16_t *vs_commands = (uint16_t *)bt_dev.vs_commands; - struct bt_hci_rp_vs_read_static_addrs *rp = - (void *)&hci_cmd_rsp_data.hci_rp_vs_read_static_addrs; - struct bt_hci_vs_static_addr *static_addr = (void *)&hci_cmd_rsp_data.hci_vs_static_addr; - - *vs_commands = (1 << BT_VS_CMD_BIT_READ_STATIC_ADDRS); - - rp->num_addrs = 1; - bt_addr_copy(&static_addr[0].bdaddr, &BT_STATIC_RANDOM_LE_ADDR_1->a); - - hci_cmd_rsp.len = sizeof(struct bt_hci_rp_vs_read_static_addrs) + - rp->num_addrs * sizeof(struct bt_hci_vs_static_addr); - - bt_rand_fake.return_val = -1; - bt_smp_irk_get_fake.return_val = -1; - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - err = bt_setup_random_id_addr(); - - expect_single_call_bt_rand(&bt_dev.irk[0], 16); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); -} - -static int bt_smp_irk_get_fill_zero_irk_custom_fake(uint8_t *ir, uint8_t *irk) -{ - __ASSERT_NO_MSG(ir != NULL); - __ASSERT_NO_MSG(irk != NULL); - - memset(irk, 0x00, 16); - - return 0; -} - -/* - * Test reading controller random address through bt_hci_cmd_send_sync(). - * bt_hci_cmd_send_sync() return value is success and response data contains a valid BT address. - * IRK is set by bt_smp_irk_get() and bt_rand() succeeds. - * - * Constraints: - * - bt_hci_cmd_send_sync() returns zero - * - Response data contains a valid address - * - bt_smp_irk_get() succeeds - * - bt_rand() succeeds - * - 'CONFIG_BT_PRIVACY' is enabled - * - * Expected behaviour: - * - Return value is 0 - */ -ZTEST(bt_setup_random_id_addr_privacy_enabled, test_create_id_irk_not_null_but_cleared) -{ - int err; - uint16_t *vs_commands = (uint16_t *)bt_dev.vs_commands; - struct bt_hci_rp_vs_read_static_addrs *rp = - (void *)&hci_cmd_rsp_data.hci_rp_vs_read_static_addrs; - struct bt_hci_vs_static_addr *static_addr = (void *)&hci_cmd_rsp_data.hci_vs_static_addr; - - *vs_commands = (1 << BT_VS_CMD_BIT_READ_STATIC_ADDRS); - - rp->num_addrs = 1; - bt_addr_copy(&static_addr[0].bdaddr, &BT_STATIC_RANDOM_LE_ADDR_1->a); - - hci_cmd_rsp.len = sizeof(struct bt_hci_rp_vs_read_static_addrs) + - rp->num_addrs * sizeof(struct bt_hci_vs_static_addr); - - bt_rand_fake.return_val = 0; - bt_smp_irk_get_fake.custom_fake = bt_smp_irk_get_fill_zero_irk_custom_fake; - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - err = bt_setup_random_id_addr(); - - expect_single_call_bt_rand(&bt_dev.irk[0], 16); - - zassert_true(err == 0, "Unexpected error code '%d' was returned", err); -} - -static int bt_smp_irk_get_non_zero_irk_custom_fake(uint8_t *ir, uint8_t *irk) -{ - __ASSERT_NO_MSG(ir != NULL); - __ASSERT_NO_MSG(irk != NULL); - - memcpy(irk, testing_irk_value, 16); - - return 0; -} - -/* - * Test reading controller random address through bt_hci_cmd_send_sync(). - * bt_hci_cmd_send_sync() return value is success and response data contains a valid BT address. - * IRK is set by bt_smp_irk_get() and non-zero filled IRK is loaded. - * - * Constraints: - * - bt_hci_cmd_send_sync() returns zero - * - Response data contains a valid address - * - bt_smp_irk_get() succeeds - * - 'CONFIG_BT_PRIVACY' is enabled - * - * Expected behaviour: - * - Return value is 0 - * - IRK is loaded to bt_dev.irk[] - */ -ZTEST(bt_setup_random_id_addr_privacy_enabled, test_create_id_irk_not_null_and_filled) -{ - int err; - uint16_t *vs_commands = (uint16_t *)bt_dev.vs_commands; - struct bt_hci_rp_vs_read_static_addrs *rp = - (void *)&hci_cmd_rsp_data.hci_rp_vs_read_static_addrs; - struct bt_hci_vs_static_addr *static_addr = (void *)&hci_cmd_rsp_data.hci_vs_static_addr; - - *vs_commands = (1 << BT_VS_CMD_BIT_READ_STATIC_ADDRS); - - rp->num_addrs = 1; - bt_addr_copy(&static_addr[0].bdaddr, &BT_STATIC_RANDOM_LE_ADDR_1->a); - - hci_cmd_rsp.len = sizeof(struct bt_hci_rp_vs_read_static_addrs) + - rp->num_addrs * sizeof(struct bt_hci_vs_static_addr); - - bt_smp_irk_get_fake.custom_fake = bt_smp_irk_get_non_zero_irk_custom_fake; - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - err = bt_setup_random_id_addr(); - - expect_not_called_bt_rand(); - - zassert_true(err == 0, "Unexpected error code '%d' was returned", err); - zassert_mem_equal(&bt_dev.irk[0], testing_irk_value, sizeof(testing_irk_value), - "Incorrect IRK value was set"); -} -#endif diff --git a/tests/bluetooth/host/id/bt_setup_random_id_addr/src/test_suite_bt_settings_enabled.c b/tests/bluetooth/host/id/bt_setup_random_id_addr/src/test_suite_bt_settings_enabled.c deleted file mode 100644 index bc843b5d9cabd..0000000000000 --- a/tests/bluetooth/host/id/bt_setup_random_id_addr/src/test_suite_bt_settings_enabled.c +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/hci_core.h" -#include "mocks/hci_core_expects.h" -#include "mocks/settings.h" -#include "mocks/settings_expects.h" -#include "mocks/smp.h" -#include "testing_common_defs.h" - -#include -#include -#include -#include - -#include -#include - -/* Hold data representing HCI command response for command BT_HCI_OP_VS_READ_STATIC_ADDRS */ -static struct net_buf hci_cmd_rsp; - -/* Hold data representing response data for HCI command BT_HCI_OP_VS_READ_STATIC_ADDRS */ -static struct custom_bt_hci_rp_vs_read_static_addrs { - struct bt_hci_rp_vs_read_static_addrs hci_rp_vs_read_static_addrs; - struct bt_hci_vs_static_addr hci_vs_static_addr[CONFIG_BT_ID_MAX]; -} __packed hci_cmd_rsp_data; - -static void tc_setup(void *f) -{ - Z_TEST_SKIP_IFNDEF(CONFIG_BT_SETTINGS); - - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - memset(&hci_cmd_rsp, 0x00, sizeof(struct net_buf)); - memset(&hci_cmd_rsp_data, 0x00, sizeof(struct custom_bt_hci_rp_vs_read_static_addrs)); - - HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); - SETTINGS_FFF_FAKES_LIST(RESET_FAKE); - - if (IS_ENABLED(CONFIG_BT_PRIVACY)) { - SMP_FFF_FAKES_LIST(RESET_FAKE); - } -} - -ZTEST_SUITE(bt_setup_random_id_addr_bt_settings_enabled, NULL, NULL, tc_setup, NULL, NULL); - -/* - * Test reading controller static random address fails and no attempt to store settings. - * - * Constraints: - * - vs_read_static_addr() returns zero - * - * Expected behaviour: - * - ID count is set to 0 and bt_setup_random_id_addr() returns a negative error code - * - No expected calls to bt_settings_store_id() - */ -ZTEST(bt_setup_random_id_addr_bt_settings_enabled, test_bt_read_static_addr_returns_zero) -{ - int err; - - /* This will force vs_read_static_addr() to fail */ - bt_hci_cmd_send_sync_fake.return_val = 1; - - err = bt_setup_random_id_addr(); - - expect_not_called_bt_settings_store_id(); - - zassert_true(bt_dev.id_count == 0, "Incorrect value '%d' was set to bt_dev.id_count", - bt_dev.id_count); - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); -} - -static int bt_hci_cmd_send_sync_custom_fake(uint16_t opcode, struct net_buf *buf, - struct net_buf **rsp) -{ - const char *func_name = "bt_hci_cmd_send_sync"; - - zassert_equal(opcode, BT_HCI_OP_VS_READ_STATIC_ADDRS, - "'%s()' was called with incorrect '%s' value", func_name, "opcode"); - zassert_is_null(buf, "'%s()' was called with incorrect '%s' value", func_name, "buf"); - zassert_not_null(rsp, "'%s()' was called with incorrect '%s' value", func_name, "rsp"); - - *rsp = &hci_cmd_rsp; - hci_cmd_rsp.data = (void *)&hci_cmd_rsp_data.hci_rp_vs_read_static_addrs; - - return 0; -} - -/* - * Test reading controller static random address through bt_hci_cmd_send_sync(). - * Even if the operation succeeded, bt_settings_store_id() shouldn't be called to - * store settings as the 'BT_DEV_READY' bit isn't set. - * - * Constraints: - * - bt_hci_cmd_send_sync() returns zero - * - Response data contains a valid address - * - BT_DEV_READY bit isn't set in bt_dev.flags - * - * Expected behaviour: - * - Return value is 0 - * - Static random address is loaded to bt_dev.id_addr[] - * - No expected calls to bt_settings_store_id() - */ -ZTEST(bt_setup_random_id_addr_bt_settings_enabled, - test_bt_read_static_addr_succeeds_bt_dev_ready_cleared) -{ - int err; - uint16_t *vs_commands = (uint16_t *)bt_dev.vs_commands; - struct bt_hci_rp_vs_read_static_addrs *rp = - (void *)&hci_cmd_rsp_data.hci_rp_vs_read_static_addrs; - struct bt_hci_vs_static_addr *static_addr = (void *)&hci_cmd_rsp_data.hci_vs_static_addr; - - *vs_commands = (1 << BT_VS_CMD_BIT_READ_STATIC_ADDRS); - - rp->num_addrs = 1; - bt_addr_copy(&static_addr[0].bdaddr, &BT_STATIC_RANDOM_LE_ADDR_1->a); - - hci_cmd_rsp.len = sizeof(struct bt_hci_rp_vs_read_static_addrs) + - rp->num_addrs * sizeof(struct bt_hci_vs_static_addr); - - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - atomic_clear_bit(bt_dev.flags, BT_DEV_READY); - - err = bt_setup_random_id_addr(); - - expect_not_called_bt_settings_store_id(); - - zassert_true(err == 0, "Unexpected error code '%d' was returned", err); - zassert_mem_equal(&bt_dev.id_addr[0], BT_STATIC_RANDOM_LE_ADDR_1, sizeof(bt_addr_le_t), - "Incorrect address was set"); - zassert_true(bt_dev.id_count == 1, "Incorrect value '%d' was set to bt_dev.id_count", - bt_dev.id_count); -} - -/* - * Test reading controller static random address through - * bt_hci_cmd_send_sync(). With the 'BT_DEV_READY' bit set, - * bt_settings_store_id() and bt_settings_store_irk() should be called to store - * settings to persistent memory. - * - * Constraints: - * - bt_hci_cmd_send_sync() returns zero - * - Response data contains a valid address - * - BT_DEV_READY bit isn't set in bt_dev.flags - * - * Expected behaviour: - * - Return value is 0 - * - Static random address is loaded to bt_dev.id_addr[] - * - No expected calls to bt_settings_store_id() - */ -ZTEST(bt_setup_random_id_addr_bt_settings_enabled, - test_bt_read_static_addr_succeeds_bt_dev_ready_set) -{ - int err; - uint16_t *vs_commands = (uint16_t *)bt_dev.vs_commands; - struct bt_hci_rp_vs_read_static_addrs *rp = - (void *)&hci_cmd_rsp_data.hci_rp_vs_read_static_addrs; - struct bt_hci_vs_static_addr *static_addr = (void *)&hci_cmd_rsp_data.hci_vs_static_addr; - - *vs_commands = (1 << BT_VS_CMD_BIT_READ_STATIC_ADDRS); - - rp->num_addrs = 1; - bt_addr_copy(&static_addr[0].bdaddr, &BT_STATIC_RANDOM_LE_ADDR_1->a); - - hci_cmd_rsp.len = sizeof(struct bt_hci_rp_vs_read_static_addrs) + - rp->num_addrs * sizeof(struct bt_hci_vs_static_addr); - - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - atomic_set_bit(bt_dev.flags, BT_DEV_READY); - - err = bt_setup_random_id_addr(); - - expect_single_call_bt_settings_store_id(); - expect_single_call_bt_settings_store_irk(); - - zassert_true(err == 0, "Unexpected error code '%d' was returned", err); - zassert_mem_equal(&bt_dev.id_addr[0], BT_STATIC_RANDOM_LE_ADDR_1, sizeof(bt_addr_le_t), - "Incorrect address was set"); - zassert_true(bt_dev.id_count == 1, "Incorrect value '%d' was set to bt_dev.id_count", - bt_dev.id_count); -} - -/* - * Test reading controller static random address through bt_hci_cmd_send_sync(). - * 'BT_DEV_STORE_ID' should be set when IRK isn't set. - * - * Constraints: - * - bt_hci_cmd_send_sync() returns zero - * - Response data contains a valid address - * - CONFIG_BT_PRIVACY is enabled - * - * Expected behaviour: - * - Return value is 0 - * - 'BT_DEV_STORE_ID' bit is set inside bt_dev.flags - */ -ZTEST(bt_setup_random_id_addr_bt_settings_enabled, test_store_flag_set_correctly) -{ - int err; - uint16_t *vs_commands = (uint16_t *)bt_dev.vs_commands; - struct bt_hci_rp_vs_read_static_addrs *rp = - (void *)&hci_cmd_rsp_data.hci_rp_vs_read_static_addrs; - struct bt_hci_vs_static_addr *static_addr = (void *)&hci_cmd_rsp_data.hci_vs_static_addr; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_PRIVACY); - - *vs_commands = (1 << BT_VS_CMD_BIT_READ_STATIC_ADDRS); - - rp->num_addrs = 1; - bt_addr_copy(&static_addr[0].bdaddr, &BT_STATIC_RANDOM_LE_ADDR_1->a); - - hci_cmd_rsp.len = sizeof(struct bt_hci_rp_vs_read_static_addrs) + - rp->num_addrs * sizeof(struct bt_hci_vs_static_addr); - - bt_smp_irk_get_fake.return_val = 1; - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - err = bt_setup_random_id_addr(); - - zassert_true(err == 0, "Unexpected error code '%d' was returned", err); - zassert_true(atomic_test_bit(bt_dev.flags, BT_DEV_STORE_ID), - "Flags were not correctly set"); -} diff --git a/tests/bluetooth/host/id/bt_setup_random_id_addr/src/test_suite_invalid_cases.c b/tests/bluetooth/host/id/bt_setup_random_id_addr/src/test_suite_invalid_cases.c deleted file mode 100644 index 2c754ecebe9bf..0000000000000 --- a/tests/bluetooth/host/id/bt_setup_random_id_addr/src/test_suite_invalid_cases.c +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/hci_core.h" -#include "mocks/hci_core_expects.h" -#include "mocks/net_buf.h" -#include "mocks/net_buf_expects.h" -#include "testing_common_defs.h" - -#include -#include -#include -#include - -#include -#include - -/* Hold data representing HCI command response for command BT_HCI_OP_VS_READ_STATIC_ADDRS */ -static struct net_buf hci_cmd_rsp; - -/* Hold data representing response data for HCI command BT_HCI_OP_VS_READ_STATIC_ADDRS */ -static struct custom_bt_hci_rp_vs_read_static_addrs { - struct bt_hci_rp_vs_read_static_addrs hci_rp_vs_read_static_addrs; - struct bt_hci_vs_static_addr hci_vs_static_addr[CONFIG_BT_ID_MAX]; -} __packed hci_cmd_rsp_data; - -static void tc_setup(void *f) -{ - memset(&bt_dev, 0x00, sizeof(struct bt_dev)); - memset(&hci_cmd_rsp, 0x00, sizeof(struct net_buf)); - memset(&hci_cmd_rsp_data, 0x00, sizeof(struct custom_bt_hci_rp_vs_read_static_addrs)); - - NET_BUF_FFF_FAKES_LIST(RESET_FAKE); - HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_SUITE(bt_setup_random_id_addr_invalid_cases, NULL, NULL, tc_setup, NULL, NULL); - -/* - * Testing setting up device random address while VS command for reading static address isn't - * enabled, so reading static address fails. - * - * Constraints: - * - VS command for reading static address isn't enabled - * - No identity exists and bt_dev.id_count equals 0 - * - * Expected behaviour: - * - A negative error code is returned by bt_id_create(). - */ -ZTEST(bt_setup_random_id_addr_invalid_cases, test_vs_reading_static_address_fails) -{ - int err; - - bt_dev.id_count = 0; - - err = bt_setup_random_id_addr(); - - zassert_true(err != 0, "Unexpected error code '%d' was returned", err); -} - -/* - * Test reading controller static random address through bt_hci_cmd_send_sync(). - * bt_hci_cmd_send_sync() fails and returns a non-success error code. - * - * Constraints: - * - bt_hci_cmd_send_sync() returns a non-zero error code - * - * Expected behaviour: - * - A negative error code is returned by bt_id_create(). - */ -ZTEST(bt_setup_random_id_addr_invalid_cases, test_bt_hci_cmd_send_sync_returns_err) -{ - int err; - uint16_t *vs_commands = (uint16_t *)bt_dev.vs_commands; - - *vs_commands = (1 << BT_VS_CMD_BIT_READ_STATIC_ADDRS); - bt_hci_cmd_send_sync_fake.return_val = 1; - - err = bt_setup_random_id_addr(); - - expect_single_call_bt_hci_cmd_send_sync(BT_HCI_OP_VS_READ_STATIC_ADDRS); - expect_not_called_net_buf_unref(); - - zassert_true(err != 0, "Unexpected error code '%d' was returned", err); -} - -static int bt_hci_cmd_send_sync_custom_fake(uint16_t opcode, struct net_buf *buf, - struct net_buf **rsp) -{ - const char *func_name = "bt_hci_cmd_send_sync"; - - zassert_equal(opcode, BT_HCI_OP_VS_READ_STATIC_ADDRS, - "'%s()' was called with incorrect '%s' value", func_name, "opcode"); - zassert_is_null(buf, "'%s()' was called with incorrect '%s' value", func_name, "buf"); - zassert_not_null(rsp, "'%s()' was called with incorrect '%s' value", func_name, "rsp"); - - *rsp = &hci_cmd_rsp; - hci_cmd_rsp.data = (void *)&hci_cmd_rsp_data.hci_rp_vs_read_static_addrs; - - return 0; -} - -/* - * Test reading controller static random address through bt_hci_cmd_send_sync(). - * bt_hci_cmd_send_sync() returns 0 (success) and the returned number of addresses is 0. - * - * Response size should follow the formula - * hci_cmd_rsp.len = sizeof(struct bt_hci_rp_vs_read_static_addrs) + - * rp->num_addrs * sizeof(struct bt_hci_vs_static_addr); - * - * The response size set is less than the expected response size,so response should be - * discarded and operation fails. - * - * Constraints: - * - bt_hci_cmd_send_sync() returns 0 (success) - * - bt_hci_cmd_send_sync() response header size is less than expected - * - * Expected behaviour: - * - A negative error code is returned by bt_id_create(). - */ -ZTEST(bt_setup_random_id_addr_invalid_cases, test_bt_hci_cmd_send_sync_response_incomplete_1) -{ - int err; - uint16_t *vs_commands = (uint16_t *)bt_dev.vs_commands; - struct bt_hci_rp_vs_read_static_addrs *rp = - (void *)&hci_cmd_rsp_data.hci_rp_vs_read_static_addrs; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_HCI_VS_EXT_DETECT); - - *vs_commands = (1 << BT_VS_CMD_BIT_READ_STATIC_ADDRS); - - hci_cmd_rsp.len = sizeof(struct bt_hci_rp_vs_read_static_addrs) - 1; - rp->num_addrs = 0; - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - err = bt_setup_random_id_addr(); - - expect_single_call_bt_hci_cmd_send_sync(BT_HCI_OP_VS_READ_STATIC_ADDRS); - expect_single_call_net_buf_unref(&hci_cmd_rsp); - - zassert_true(err != 0, "Unexpected error code '%d' was returned", err); -} - -/* - * Test reading controller static random address through bt_hci_cmd_send_sync(). - * bt_hci_cmd_send_sync() returns 0 (success) and the returned number of addresses is 1, but no - * actual data exists in the response. - * - * Response size should follow the formula - * hci_cmd_rsp.len = sizeof(struct bt_hci_rp_vs_read_static_addrs) + - * rp->num_addrs * sizeof(struct bt_hci_vs_static_addr); - * - * The response size set is less than the expected response header size plus the size of the data - * holding the returned addresses information, so response should be discarded and operation fails. - * - * Constraints: - * - bt_hci_cmd_send_sync() returns 0 (success) - * - bt_hci_cmd_send_sync() response size is less than expected - * - * Expected behaviour: - * - A negative error code is returned by bt_id_create(). - */ -ZTEST(bt_setup_random_id_addr_invalid_cases, test_bt_hci_cmd_send_sync_response_incomplete_2) -{ - int err; - uint16_t *vs_commands = (uint16_t *)bt_dev.vs_commands; - struct bt_hci_rp_vs_read_static_addrs *rp = - (void *)&hci_cmd_rsp_data.hci_rp_vs_read_static_addrs; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_HCI_VS_EXT_DETECT); - - *vs_commands = (1 << BT_VS_CMD_BIT_READ_STATIC_ADDRS); - - hci_cmd_rsp.len = sizeof(struct bt_hci_rp_vs_read_static_addrs); - rp->num_addrs = 1; - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - err = bt_setup_random_id_addr(); - - expect_single_call_bt_hci_cmd_send_sync(BT_HCI_OP_VS_READ_STATIC_ADDRS); - expect_single_call_net_buf_unref(&hci_cmd_rsp); - - zassert_true(err != 0, "Unexpected error code '%d' was returned", err); -} - -/* - * Test reading controller static random address through bt_hci_cmd_send_sync(). - * bt_hci_cmd_send_sync() returns 0 (success) and the returned number of addresses is 0. - * - * Response size should follow the formula - * hci_cmd_rsp.len = sizeof(struct bt_hci_rp_vs_read_static_addrs) + - * rp->num_addrs * sizeof(struct bt_hci_vs_static_addr); - * - * Even if the response size follows the formula, as the returned addresses - * count is 0, the response should be discarded and operation fails as the returned number of - * addresses is 0. - * - * Constraints: - * - bt_hci_cmd_send_sync() returns 0 (success) - * - bt_hci_cmd_send_sync() response contains no addresses and count is set to 0 - * - * Expected behaviour: - * - A negative error code is returned by bt_id_create(). - */ -ZTEST(bt_setup_random_id_addr_invalid_cases, test_bt_hci_cmd_send_sync_response_zero_id_addresses) -{ - int err; - uint16_t *vs_commands = (uint16_t *)bt_dev.vs_commands; - struct bt_hci_rp_vs_read_static_addrs *rp = - (void *)&hci_cmd_rsp_data.hci_rp_vs_read_static_addrs; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_HCI_VS_EXT_DETECT); - - *vs_commands = (1 << BT_VS_CMD_BIT_READ_STATIC_ADDRS); - - hci_cmd_rsp.len = sizeof(struct bt_hci_rp_vs_read_static_addrs); - rp->num_addrs = 0; - bt_hci_cmd_send_sync_fake.custom_fake = bt_hci_cmd_send_sync_custom_fake; - - err = bt_setup_random_id_addr(); - - expect_single_call_bt_hci_cmd_send_sync(BT_HCI_OP_VS_READ_STATIC_ADDRS); - expect_single_call_net_buf_unref(&hci_cmd_rsp); - - zassert_true(err != 0, "Unexpected error code '%d' was returned", err); -} - -/* - * Testing setting up device random address while there is an identity exists. - * - * Constraints: - * - An identity exists and bt_dev.id_count > 0 - * - * Expected behaviour: - * - A negative error code is returned by bt_id_create(). - */ -ZTEST(bt_setup_random_id_addr_invalid_cases, test_set_up_random_address_fails_when_identity_exists) -{ - int err; - - bt_dev.id_count = 1; - - err = bt_setup_random_id_addr(); - - zassert_true(err != 0, "Unexpected error code '%d' was returned", err); -} diff --git a/tests/bluetooth/host/id/bt_setup_random_id_addr/testcase.yaml b/tests/bluetooth/host/id/bt_setup_random_id_addr/testcase.yaml deleted file mode 100644 index 23571cc22c805..0000000000000 --- a/tests/bluetooth/host/id/bt_setup_random_id_addr/testcase.yaml +++ /dev/null @@ -1,39 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_random_idcreate.default: - type: unit - extra_configs: - - CONFIG_BT_ID_MAX=1 - bluetooth.host.bt_random_idcreate.multiple_identities: - type: unit - extra_configs: - - CONFIG_BT_ID_MAX=4 - bluetooth.host.bt_random_idcreate.hci_vs_ext_detect: - type: unit - extra_configs: - - CONFIG_BT_ID_MAX=1 - - CONFIG_BT_HCI_VS_EXT_DETECT=y - bluetooth.host.bt_random_idcreate.multiple_identities_hci_vs_ext_detect: - type: unit - extra_configs: - - CONFIG_BT_ID_MAX=4 - - CONFIG_BT_HCI_VS_EXT_DETECT=y - bluetooth.host.bt_random_idcreate.multiple_identities_hci_vs_ext_detect_privacy_enabled: - type: unit - extra_configs: - - CONFIG_BT_ID_MAX=4 - - CONFIG_BT_HCI_VS_EXT_DETECT=y - - CONFIG_BT_SMP=y - - CONFIG_BT_PRIVACY=y - bluetooth.host.bt_random_idcreate.multiple_identities_hci_vs_ext_detect_privacy_settings_enabled: - type: unit - extra_configs: - - CONFIG_BT_ID_MAX=4 - - CONFIG_BT_HCI_VS_EXT_DETECT=y - - CONFIG_BT_SMP=y - - CONFIG_BT_PRIVACY=y - - CONFIG_SETTINGS=y - - CONFIG_BT_SETTINGS=y diff --git a/tests/bluetooth/host/id/mocks/CMakeLists.txt b/tests/bluetooth/host/id/mocks/CMakeLists.txt deleted file mode 100644 index d74a7fdc21866..0000000000000 --- a/tests/bluetooth/host/id/mocks/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -# -# CMakeLists.txt file for creating of mocks library. -# - -add_library(mocks STATIC - addr.c - addr_expects.c - adv.c - adv_expects.c - conn.c - conn_expects.c - crypto.c - crypto_expects.c - hci_core.c - hci_core_expects.c - kernel.c - kernel_expects.c - keys.c - keys_expects.c - net_buf.c - net_buf_expects.c - rpa.c - rpa_expects.c - scan.c - scan_expects.c - settings.c - settings_expects.c - smp.c - smp_expects.c -) - -target_include_directories(mocks PUBLIC - .. - ${ZEPHYR_BASE}/subsys/bluetooth - ${ZEPHYR_BASE}/subsys/bluetooth/host - ${ZEPHYR_BASE}/tests/bluetooth/host - ${ZEPHYR_BASE}/tests/bluetooth/host/id/mocks -) - -target_link_libraries(mocks PRIVATE test_interface) diff --git a/tests/bluetooth/host/id/mocks/addr.c b/tests/bluetooth/host/id/mocks/addr.c deleted file mode 100644 index 0c967d90c013c..0000000000000 --- a/tests/bluetooth/host/id/mocks/addr.c +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include - -DEFINE_FAKE_VALUE_FUNC(int, bt_addr_le_create_static, bt_addr_le_t *); diff --git a/tests/bluetooth/host/id/mocks/addr.h b/tests/bluetooth/host/id/mocks/addr.h deleted file mode 100644 index e01061980991c..0000000000000 --- a/tests/bluetooth/host/id/mocks/addr.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -/* List of fakes used by this unit tester */ -#define ADDR_FFF_FAKES_LIST(FAKE) FAKE(bt_addr_le_create_static) - -DECLARE_FAKE_VALUE_FUNC(int, bt_addr_le_create_static, bt_addr_le_t *); diff --git a/tests/bluetooth/host/id/mocks/addr_expects.c b/tests/bluetooth/host/id/mocks/addr_expects.c deleted file mode 100644 index 84faf53dfaf7f..0000000000000 --- a/tests/bluetooth/host/id/mocks/addr_expects.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/addr.h" -#include "mocks/addr_expects.h" - -#include - -void expect_call_count_bt_addr_le_create_static(int call_count) -{ - const char *func_name = "bt_addr_le_create_static"; - - zassert_equal(bt_addr_le_create_static_fake.call_count, call_count, - "'%s()' was called more than once", func_name); - - zassert_not_null(bt_addr_le_create_static_fake.arg0_val, - "'%s()' was called with incorrect '%s' value", func_name, "buf"); -} - -void expect_not_called_bt_addr_le_create_static(void) -{ - const char *func_name = "bt_addr_le_create_static"; - - zassert_equal(bt_addr_le_create_static_fake.call_count, 0, "'%s()' was called unexpectedly", - func_name); -} diff --git a/tests/bluetooth/host/id/mocks/addr_expects.h b/tests/bluetooth/host/id/mocks/addr_expects.h deleted file mode 100644 index de50e2a9650e8..0000000000000 --- a/tests/bluetooth/host/id/mocks/addr_expects.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -/* - * Validate expected behaviour when bt_addr_le_create_static() is called - * - * Expected behaviour: - * - bt_addr_le_create_static() to be called once with correct parameters - */ -void expect_call_count_bt_addr_le_create_static(int call_count); - -/* - * Validate expected behaviour when bt_addr_le_create_static() isn't called - * - * Expected behaviour: - * - bt_addr_le_create_static() isn't called at all - */ -void expect_not_called_bt_addr_le_create_static(void); diff --git a/tests/bluetooth/host/id/mocks/adv.c b/tests/bluetooth/host/id/mocks/adv.c deleted file mode 100644 index 2c2d4f3f3c7a4..0000000000000 --- a/tests/bluetooth/host/id/mocks/adv.c +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/adv.h" - -#include - -DEFINE_FAKE_VALUE_FUNC(int, bt_le_adv_set_enable, struct bt_le_ext_adv *, bool); -DEFINE_FAKE_VALUE_FUNC(struct bt_le_ext_adv *, bt_le_adv_lookup_legacy); -DEFINE_FAKE_VALUE_FUNC(uint8_t, bt_le_ext_adv_get_index, struct bt_le_ext_adv *); -DEFINE_FAKE_VALUE_FUNC(int, bt_le_adv_set_enable_legacy, struct bt_le_ext_adv *, bool); -DEFINE_FAKE_VALUE_FUNC(int, bt_le_adv_set_enable_ext, struct bt_le_ext_adv *, bool, - const struct bt_le_ext_adv_start_param *); -DEFINE_FAKE_VOID_FUNC(bt_le_ext_adv_foreach, bt_le_ext_adv_foreach_cb, void *); diff --git a/tests/bluetooth/host/id/mocks/adv.h b/tests/bluetooth/host/id/mocks/adv.h deleted file mode 100644 index bfb744001596b..0000000000000 --- a/tests/bluetooth/host/id/mocks/adv.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -#include - -typedef void (*bt_le_ext_adv_foreach_cb)(struct bt_le_ext_adv *adv, void *data); - -/* List of fakes used by this unit tester */ -#define ADV_FFF_FAKES_LIST(FAKE) \ - FAKE(bt_le_adv_set_enable) \ - FAKE(bt_le_adv_lookup_legacy) \ - FAKE(bt_le_ext_adv_get_index) \ - FAKE(bt_le_adv_set_enable_ext) \ - FAKE(bt_le_ext_adv_foreach) - -DECLARE_FAKE_VALUE_FUNC(int, bt_le_adv_set_enable, struct bt_le_ext_adv *, bool); -DECLARE_FAKE_VALUE_FUNC(struct bt_le_ext_adv *, bt_le_adv_lookup_legacy); -DECLARE_FAKE_VALUE_FUNC(uint8_t, bt_le_ext_adv_get_index, struct bt_le_ext_adv *); -DECLARE_FAKE_VALUE_FUNC(int, bt_le_adv_set_enable_legacy, struct bt_le_ext_adv *, bool); -DECLARE_FAKE_VALUE_FUNC(int, bt_le_adv_set_enable_ext, struct bt_le_ext_adv *, bool, - const struct bt_le_ext_adv_start_param *); -DECLARE_FAKE_VOID_FUNC(bt_le_ext_adv_foreach, bt_le_ext_adv_foreach_cb, void *); diff --git a/tests/bluetooth/host/id/mocks/adv_expects.c b/tests/bluetooth/host/id/mocks/adv_expects.c deleted file mode 100644 index 6f5e811610c28..0000000000000 --- a/tests/bluetooth/host/id/mocks/adv_expects.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/adv.h" -#include "mocks/adv_expects.h" - -#include - -void expect_single_call_bt_le_adv_lookup_legacy(void) -{ - const char *func_name = "bt_le_adv_lookup_legacy"; - - zassert_equal(bt_le_adv_lookup_legacy_fake.call_count, 1, - "'%s()' was called more than once", func_name); -} - -void expect_not_called_bt_le_adv_lookup_legacy(void) -{ - const char *func_name = "bt_le_adv_lookup_legacy"; - - zassert_equal(bt_le_adv_lookup_legacy_fake.call_count, 0, "'%s()' was called unexpectedly", - func_name); -} - -void expect_single_call_bt_le_ext_adv_foreach(void) -{ - const char *func_name = "bt_le_ext_adv_foreach"; - - zassert_equal(bt_le_ext_adv_foreach_fake.call_count, 1, "'%s()' was called more than once", - func_name); - - zassume_not_null(bt_le_ext_adv_foreach_fake.arg0_val, - "'%s()' was called with incorrect '%s' value", func_name, "func"); -} - -void expect_not_called_bt_le_ext_adv_foreach(void) -{ - const char *func_name = "bt_le_ext_adv_foreach"; - - zassert_equal(bt_le_ext_adv_foreach_fake.call_count, 0, "'%s()' was called unexpectedly", - func_name); -} diff --git a/tests/bluetooth/host/id/mocks/adv_expects.h b/tests/bluetooth/host/id/mocks/adv_expects.h deleted file mode 100644 index 519b5d9c1ea6a..0000000000000 --- a/tests/bluetooth/host/id/mocks/adv_expects.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -/* - * Validate expected behaviour when bt_le_adv_lookup_legacy() is called - * - * Expected behaviour: - * - bt_le_adv_lookup_legacy() to be called once with correct parameters - */ -void expect_single_call_bt_le_adv_lookup_legacy(void); - -/* - * Validate expected behaviour when bt_le_adv_lookup_legacy() isn't called - * - * Expected behaviour: - * - bt_le_adv_lookup_legacy() isn't called at all - */ -void expect_not_called_bt_le_adv_lookup_legacy(void); - -/* - * Validate expected behaviour when bt_le_ext_adv_foreach() is called - * - * Expected behaviour: - * - bt_le_ext_adv_foreach() to be called once with correct parameters - */ -void expect_single_call_bt_le_ext_adv_foreach(void); - -/* - * Validate expected behaviour when bt_le_ext_adv_foreach() isn't called - * - * Expected behaviour: - * - bt_le_ext_adv_foreach() isn't called at all - */ -void expect_not_called_bt_le_ext_adv_foreach(void); diff --git a/tests/bluetooth/host/id/mocks/conn.c b/tests/bluetooth/host/id/mocks/conn.c deleted file mode 100644 index 99796076e01bb..0000000000000 --- a/tests/bluetooth/host/id/mocks/conn.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2022-2025 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -#include "mocks/conn.h" - -DEFINE_FAKE_VOID_FUNC(bt_conn_unref, struct bt_conn *); -DEFINE_FAKE_VALUE_FUNC(int, bt_le_create_conn_cancel); -DEFINE_FAKE_VALUE_FUNC(struct bt_conn *, bt_conn_lookup_state_le, uint8_t, const bt_addr_le_t *, - const bt_conn_state_t); - -bool bt_conn_is_type(const struct bt_conn *conn, enum bt_conn_type type) -{ - return true; -} diff --git a/tests/bluetooth/host/id/mocks/conn.h b/tests/bluetooth/host/id/mocks/conn.h deleted file mode 100644 index 1d2da0a4106b0..0000000000000 --- a/tests/bluetooth/host/id/mocks/conn.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2022-2025 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -#include - -/* List of fakes used by this unit tester */ -#define CONN_FFF_FAKES_LIST(FAKE) \ - FAKE(bt_conn_unref) \ - FAKE(bt_le_create_conn_cancel) \ - FAKE(bt_conn_lookup_state_le) - -DECLARE_FAKE_VOID_FUNC(bt_conn_unref, struct bt_conn *); -DECLARE_FAKE_VALUE_FUNC(int, bt_le_create_conn_cancel); -DECLARE_FAKE_VALUE_FUNC(struct bt_conn *, bt_conn_lookup_state_le, uint8_t, const bt_addr_le_t *, - const bt_conn_state_t); -DECLARE_FAKE_VALUE_FUNC(bool, bt_conn_is_type, const struct bt_conn *, enum bt_conn_type); diff --git a/tests/bluetooth/host/id/mocks/conn_expects.c b/tests/bluetooth/host/id/mocks/conn_expects.c deleted file mode 100644 index 71ea0bf0997aa..0000000000000 --- a/tests/bluetooth/host/id/mocks/conn_expects.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/conn.h" -#include "mocks/conn_expects.h" - -#include - -void expect_single_call_bt_conn_lookup_state_le(uint8_t id, const bt_addr_le_t *peer, - const bt_conn_state_t state) -{ - const char *func_name = "bt_conn_lookup_state_le"; - - zassert_equal(bt_conn_lookup_state_le_fake.call_count, 1, - "'%s()' was called more than once", func_name); - - zassert_equal(bt_conn_lookup_state_le_fake.arg0_val, id, - "'%s()' was called with incorrect '%s' value", func_name, "id"); - zassert_equal_ptr(bt_conn_lookup_state_le_fake.arg1_val, peer, - "'%s()' was called with incorrect '%s' value", func_name, "peer"); - zassert_equal(bt_conn_lookup_state_le_fake.arg2_val, state, - "'%s()' was called with incorrect '%s' value", func_name, "state"); -} - -void expect_not_called_bt_conn_lookup_state_le(void) -{ - const char *func_name = "bt_conn_lookup_state_le"; - - zassert_equal(bt_conn_lookup_state_le_fake.call_count, 0, "'%s()' was called unexpectedly", - func_name); -} - -void expect_single_call_bt_conn_unref(struct bt_conn *conn) -{ - const char *func_name = "bt_conn_unref"; - - zassert_equal(bt_conn_unref_fake.call_count, 1, "'%s()' was called more than once", - func_name); - - zassert_equal_ptr(bt_conn_unref_fake.arg0_val, conn, - "'%s()' was called with incorrect '%s' value", func_name, "conn"); -} - -void expect_not_called_bt_conn_unref(void) -{ - const char *func_name = "bt_conn_unref"; - - zassert_equal(bt_conn_unref_fake.call_count, 0, "'%s()' was called unexpectedly", - func_name); -} diff --git a/tests/bluetooth/host/id/mocks/conn_expects.h b/tests/bluetooth/host/id/mocks/conn_expects.h deleted file mode 100644 index 3eda3d39c381a..0000000000000 --- a/tests/bluetooth/host/id/mocks/conn_expects.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -/* - * Validate expected behaviour when bt_conn_lookup_state_le() is called - * - * Expected behaviour: - * - bt_conn_lookup_state_le() to be called once with correct parameters - */ -void expect_single_call_bt_conn_lookup_state_le(uint8_t id, const bt_addr_le_t *peer, - const bt_conn_state_t state); - -/* - * Validate expected behaviour when bt_conn_lookup_state_le() isn't called - * - * Expected behaviour: - * - bt_conn_lookup_state_le() isn't called at all - */ -void expect_not_called_bt_conn_lookup_state_le(void); - -/* - * Validate expected behaviour when bt_conn_unref() is called - * - * Expected behaviour: - * - bt_conn_unref() to be called once with correct parameters - */ -void expect_single_call_bt_conn_unref(struct bt_conn *conn); - -/* - * Validate expected behaviour when bt_conn_unref() isn't called - * - * Expected behaviour: - * - bt_conn_unref() isn't called at all - */ -void expect_not_called_bt_conn_unref(void); diff --git a/tests/bluetooth/host/id/mocks/crypto.c b/tests/bluetooth/host/id/mocks/crypto.c deleted file mode 100644 index cfb3ff2a691d6..0000000000000 --- a/tests/bluetooth/host/id/mocks/crypto.c +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include - -DEFINE_FAKE_VALUE_FUNC(int, bt_rand, void *, size_t); diff --git a/tests/bluetooth/host/id/mocks/crypto.h b/tests/bluetooth/host/id/mocks/crypto.h deleted file mode 100644 index be2905d0662dc..0000000000000 --- a/tests/bluetooth/host/id/mocks/crypto.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -/* List of fakes used by this unit tester */ -#define CRYPTO_FFF_FAKES_LIST(FAKE) FAKE(bt_rand) - -DECLARE_FAKE_VALUE_FUNC(int, bt_rand, void *, size_t); diff --git a/tests/bluetooth/host/id/mocks/crypto_expects.c b/tests/bluetooth/host/id/mocks/crypto_expects.c deleted file mode 100644 index 6f9d790ea3959..0000000000000 --- a/tests/bluetooth/host/id/mocks/crypto_expects.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/crypto.h" -#include "mocks/crypto_expects.h" - -#include - -void expect_single_call_bt_rand(void *buf, size_t len) -{ - const char *func_name = "bt_rand"; - - zassert_equal(bt_rand_fake.call_count, 1, "'%s()' was called more than once", func_name); - - zassert_equal(bt_rand_fake.arg0_val, buf, "'%s()' was called with incorrect '%s' value", - func_name, "buf"); - zassert_equal(bt_rand_fake.arg1_val, len, "'%s()' was called with incorrect '%s' value", - func_name, "len"); -} - -void expect_not_called_bt_rand(void) -{ - const char *func_name = "bt_rand"; - - zassert_equal(bt_rand_fake.call_count, 0, "'%s()' was called unexpectedly", func_name); -} diff --git a/tests/bluetooth/host/id/mocks/crypto_expects.h b/tests/bluetooth/host/id/mocks/crypto_expects.h deleted file mode 100644 index e8663181e8ab2..0000000000000 --- a/tests/bluetooth/host/id/mocks/crypto_expects.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -/* - * Validate expected behaviour when bt_rand() is called - * - * Expected behaviour: - * - bt_rand() to be called once with correct parameters - */ -void expect_single_call_bt_rand(void *buf, size_t len); - -/* - * Validate expected behaviour when bt_rand() isn't called - * - * Expected behaviour: - * - bt_rand() isn't called at all - */ -void expect_not_called_bt_rand(void); diff --git a/tests/bluetooth/host/id/mocks/hci_core.c b/tests/bluetooth/host/id/mocks/hci_core.c deleted file mode 100644 index dedaf5f9dc192..0000000000000 --- a/tests/bluetooth/host/id/mocks/hci_core.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/hci_core.h" - -#include -#include - -#include - -struct bt_dev bt_dev = { - .manufacturer = 0x1234, -}; - -DEFINE_FAKE_VALUE_FUNC(int, bt_unpair, uint8_t, const bt_addr_le_t *); -DEFINE_FAKE_VALUE_FUNC(struct net_buf *, bt_hci_cmd_alloc, k_timeout_t); -DEFINE_FAKE_VALUE_FUNC(int, bt_hci_cmd_send_sync, uint16_t, struct net_buf *, struct net_buf **); diff --git a/tests/bluetooth/host/id/mocks/hci_core.h b/tests/bluetooth/host/id/mocks/hci_core.h deleted file mode 100644 index 94de9ca882e69..0000000000000 --- a/tests/bluetooth/host/id/mocks/hci_core.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -/* List of fakes used by this unit tester */ -#define HCI_CORE_FFF_FAKES_LIST(FAKE) \ - FAKE(bt_unpair) \ - FAKE(bt_hci_cmd_alloc) \ - FAKE(bt_hci_cmd_send_sync) - -DECLARE_FAKE_VALUE_FUNC(int, bt_unpair, uint8_t, const bt_addr_le_t *); -DECLARE_FAKE_VALUE_FUNC(struct net_buf *, bt_hci_cmd_alloc, k_timeout_t); -DECLARE_FAKE_VALUE_FUNC(int, bt_hci_cmd_send_sync, uint16_t, struct net_buf *, struct net_buf **); diff --git a/tests/bluetooth/host/id/mocks/hci_core_expects.c b/tests/bluetooth/host/id/mocks/hci_core_expects.c deleted file mode 100644 index af8a1ea13cd3c..0000000000000 --- a/tests/bluetooth/host/id/mocks/hci_core_expects.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/hci_core.h" -#include "mocks/hci_core_expects.h" - -#include -#include - -void expect_single_call_bt_unpair(uint8_t id, const bt_addr_le_t *addr) -{ - const char *func_name = "bt_unpair"; - - zassert_equal(bt_unpair_fake.call_count, 1, "'%s()' was called more than once", func_name); - - zassert_equal(bt_unpair_fake.arg0_val, id, "'%s()' was called with incorrect '%s' value", - func_name, "id"); - - if (addr) { - zassert_mem_equal(bt_unpair_fake.arg1_val, addr, sizeof(bt_addr_le_t), - "'%s()' was called with incorrect '%s' value", func_name, "addr"); - } else { - zassert_equal(bt_unpair_fake.arg1_val, addr, - "'%s()' was called with incorrect '%s' value", func_name, "addr"); - } -} - -void expect_not_called_bt_unpair(void) -{ - const char *func_name = "bt_unpair"; - - zassert_equal(bt_unpair_fake.call_count, 0, "'%s()' was called unexpectedly", func_name); -} - -void expect_single_call_bt_hci_cmd_alloc(void) -{ - const char *func_name = "bt_hci_cmd_alloc"; - - zassert_equal(bt_hci_cmd_alloc_fake.call_count, 1, "'%s()' was called more than once", - func_name); -} - -void expect_not_called_bt_hci_cmd_alloc(void) -{ - const char *func_name = "bt_hci_cmd_alloc"; - - zassert_equal(bt_hci_cmd_alloc_fake.call_count, 0, "'%s()' was called unexpectedly", - func_name); -} - -void expect_single_call_bt_hci_cmd_send_sync(uint16_t opcode) -{ - const char *func_name = "bt_hci_cmd_send_sync"; - - zassert_equal(bt_hci_cmd_send_sync_fake.call_count, 1, "'%s()' was called more than once", - func_name); - - zassert_equal(bt_hci_cmd_send_sync_fake.arg0_val, opcode, - "'%s()' was called with incorrect '%s' value", func_name, "opcode"); -} - -void expect_not_called_bt_hci_cmd_send_sync(void) -{ - const char *func_name = "bt_hci_cmd_send_sync"; - - zassert_equal(bt_hci_cmd_send_sync_fake.call_count, 0, "'%s()' was called unexpectedly", - func_name); -} diff --git a/tests/bluetooth/host/id/mocks/hci_core_expects.h b/tests/bluetooth/host/id/mocks/hci_core_expects.h deleted file mode 100644 index 018747837c00d..0000000000000 --- a/tests/bluetooth/host/id/mocks/hci_core_expects.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -/* - * Validate expected behaviour when bt_unpair() is called - * - * Expected behaviour: - * - bt_unpair() to be called once with correct parameters - */ -void expect_single_call_bt_unpair(uint8_t id, const bt_addr_le_t *addr); - -/* - * Validate expected behaviour when bt_unpair() isn't called - * - * Expected behaviour: - * - bt_unpair() isn't called at all - */ -void expect_not_called_bt_unpair(void); - -/* - * Validate expected behaviour when bt_hci_cmd_alloc() is called - * - * Expected behaviour: - * - bt_hci_cmd_alloc() to be called once with correct parameters - */ -void expect_single_call_bt_hci_cmd_alloc(void); - -/* - * Validate expected behaviour when bt_hci_cmd_alloc() isn't called - * - * Expected behaviour: - * - bt_hci_cmd_alloc() isn't called at all - */ -void expect_not_called_bt_hci_cmd_alloc(void); - -/* - * Validate expected behaviour when bt_hci_cmd_send_sync() is called - * - * Expected behaviour: - * - bt_hci_cmd_send_sync() to be called once with correct parameters - */ -void expect_single_call_bt_hci_cmd_send_sync(uint16_t opcode); - -/* - * Validate expected behaviour when bt_hci_cmd_send_sync() isn't called - * - * Expected behaviour: - * - bt_hci_cmd_send_sync() isn't called at all - */ -void expect_not_called_bt_hci_cmd_send_sync(void); diff --git a/tests/bluetooth/host/id/mocks/kernel.c b/tests/bluetooth/host/id/mocks/kernel.c deleted file mode 100644 index 889f826668005..0000000000000 --- a/tests/bluetooth/host/id/mocks/kernel.c +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/kernel.h" - -#include - -DEFINE_FAKE_VALUE_FUNC(k_ticks_t, z_timeout_remaining, const struct _timeout *); -DEFINE_FAKE_VALUE_FUNC(int, k_work_schedule, struct k_work_delayable *, k_timeout_t); -DEFINE_FAKE_VALUE_FUNC(bool, k_work_cancel_delayable_sync, struct k_work_delayable *, - struct k_work_sync *); -DEFINE_FAKE_VOID_FUNC(k_work_init_delayable, struct k_work_delayable *, k_work_handler_t); -DEFINE_FAKE_VALUE_FUNC(int, k_work_submit, struct k_work *); diff --git a/tests/bluetooth/host/id/mocks/kernel.h b/tests/bluetooth/host/id/mocks/kernel.h deleted file mode 100644 index 35a51d5709297..0000000000000 --- a/tests/bluetooth/host/id/mocks/kernel.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -/* List of fakes used by this unit tester */ -#define KERNEL_FFF_FAKES_LIST(FAKE) \ - FAKE(z_timeout_remaining) \ - FAKE(k_work_schedule) \ - FAKE(k_work_cancel_delayable_sync) \ - FAKE(k_work_init_delayable) - -DECLARE_FAKE_VALUE_FUNC(k_ticks_t, z_timeout_remaining, const struct _timeout *); -DECLARE_FAKE_VALUE_FUNC(int, k_work_schedule, struct k_work_delayable *, k_timeout_t); -DECLARE_FAKE_VALUE_FUNC(bool, k_work_cancel_delayable_sync, struct k_work_delayable *, - struct k_work_sync *); -DECLARE_FAKE_VOID_FUNC(k_work_init_delayable, struct k_work_delayable *, k_work_handler_t); -DECLARE_FAKE_VALUE_FUNC(int, k_work_submit, struct k_work *); diff --git a/tests/bluetooth/host/id/mocks/kernel_expects.c b/tests/bluetooth/host/id/mocks/kernel_expects.c deleted file mode 100644 index 235e8834ce3f8..0000000000000 --- a/tests/bluetooth/host/id/mocks/kernel_expects.c +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/kernel.h" -#include "mocks/kernel_expects.h" - -#include - -void expect_single_call_k_work_init_delayable(struct k_work_delayable *dwork) -{ - const char *func_name = "k_work_init_delayable"; - - zassert_equal(k_work_init_delayable_fake.call_count, 1, "'%s()' was called more than once", - func_name); - zassert_equal(k_work_init_delayable_fake.arg0_val, dwork, - "'%s()' was called with incorrect '%s' value", func_name, "dwork"); - zassert_not_null(k_work_init_delayable_fake.arg1_val, - "'%s()' was called with incorrect '%s' value", func_name, "handler"); -} diff --git a/tests/bluetooth/host/id/mocks/kernel_expects.h b/tests/bluetooth/host/id/mocks/kernel_expects.h deleted file mode 100644 index 3bc8249164dd2..0000000000000 --- a/tests/bluetooth/host/id/mocks/kernel_expects.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -/* - * Validate expected behaviour when k_work_init_delayable() is called - * - * Expected behaviour: - * - k_work_init_delayable() to be called once with correct parameters - */ -void expect_single_call_k_work_init_delayable(struct k_work_delayable *dwork); diff --git a/tests/bluetooth/host/id/mocks/keys.c b/tests/bluetooth/host/id/mocks/keys.c deleted file mode 100644 index f885ab875c0fc..0000000000000 --- a/tests/bluetooth/host/id/mocks/keys.c +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include - -DEFINE_FAKE_VALUE_FUNC(struct bt_keys *, bt_keys_find_irk, uint8_t, const bt_addr_le_t *); -DEFINE_FAKE_VOID_FUNC(bt_keys_foreach_type, enum bt_keys_type, bt_keys_foreach_type_cb, void *); diff --git a/tests/bluetooth/host/id/mocks/keys.h b/tests/bluetooth/host/id/mocks/keys.h deleted file mode 100644 index b6901e315ab99..0000000000000 --- a/tests/bluetooth/host/id/mocks/keys.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -#include - -typedef void (*bt_keys_foreach_type_cb)(struct bt_keys *keys, void *data); - -/* List of fakes used by this unit tester */ -#define KEYS_FFF_FAKES_LIST(FAKE) \ - FAKE(bt_keys_find_irk) \ - FAKE(bt_keys_foreach_type) - -DECLARE_FAKE_VALUE_FUNC(struct bt_keys *, bt_keys_find_irk, uint8_t, const bt_addr_le_t *); -DECLARE_FAKE_VOID_FUNC(bt_keys_foreach_type, enum bt_keys_type, bt_keys_foreach_type_cb, void *); diff --git a/tests/bluetooth/host/id/mocks/keys_expects.c b/tests/bluetooth/host/id/mocks/keys_expects.c deleted file mode 100644 index c991b56f1b676..0000000000000 --- a/tests/bluetooth/host/id/mocks/keys_expects.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/keys.h" -#include "mocks/keys_expects.h" - -#include - -void expect_single_call_bt_keys_find_irk(uint8_t id, const bt_addr_le_t *addr) -{ - const char *func_name = "bt_keys_find_irk"; - - zassert_equal(bt_keys_find_irk_fake.call_count, 1, "'%s()' was called more than once", - func_name); - - zassert_equal(bt_keys_find_irk_fake.arg0_val, id, - "'%s()' was called with incorrect '%s' value", func_name, "id"); - zassert_equal(bt_keys_find_irk_fake.arg1_val, addr, - "'%s()' was called with incorrect '%s' value", func_name, "addr"); -} - -void expect_not_called_bt_keys_find_irk(void) -{ - const char *func_name = "bt_keys_find_irk"; - - zassert_equal(bt_keys_find_irk_fake.call_count, 0, "'%s()' was called unexpectedly", - func_name); -} - -void expect_single_call_bt_keys_foreach_type(enum bt_keys_type type) -{ - const char *func_name = "bt_keys_foreach_type"; - - zassert_equal(bt_keys_foreach_type_fake.call_count, 1, "'%s()' was called more than once", - func_name); - - zassert_equal(bt_keys_foreach_type_fake.arg0_val, type, - "'%s()' was called with incorrect '%s' value", func_name, "type"); - zassert_not_null(bt_keys_foreach_type_fake.arg1_val, - "'%s()' was called with incorrect '%s' value", func_name, "func"); -} - -void expect_not_called_bt_keys_foreach_type(void) -{ - const char *func_name = "bt_keys_foreach_type"; - - zassert_equal(bt_keys_foreach_type_fake.call_count, 0, "'%s()' was called unexpectedly", - func_name); -} diff --git a/tests/bluetooth/host/id/mocks/keys_expects.h b/tests/bluetooth/host/id/mocks/keys_expects.h deleted file mode 100644 index fe2941565dae8..0000000000000 --- a/tests/bluetooth/host/id/mocks/keys_expects.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -/* - * Validate expected behaviour when bt_keys_find_irk() is called - * - * Expected behaviour: - * - bt_keys_find_irk() to be called once with correct parameters - */ -void expect_single_call_bt_keys_find_irk(uint8_t id, const bt_addr_le_t *addr); - -/* - * Validate expected behaviour when bt_keys_find_irk() isn't called - * - * Expected behaviour: - * - bt_keys_find_irk() isn't called at all - */ -void expect_not_called_bt_keys_find_irk(void); - -/* - * Validate expected behaviour when bt_keys_foreach_type() is called - * - * Expected behaviour: - * - bt_keys_foreach_type() to be called once with correct parameters - */ -void expect_single_call_bt_keys_foreach_type(enum bt_keys_type type); - -/* - * Validate expected behaviour when bt_keys_foreach_type() isn't called - * - * Expected behaviour: - * - bt_keys_foreach_type() isn't called at all - */ -void expect_not_called_bt_keys_foreach_type(void); diff --git a/tests/bluetooth/host/id/mocks/net_buf.c b/tests/bluetooth/host/id/mocks/net_buf.c deleted file mode 100644 index 187da686ee871..0000000000000 --- a/tests/bluetooth/host/id/mocks/net_buf.c +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -#include - -DEFINE_FAKE_VOID_FUNC(net_buf_unref, struct net_buf *); -DEFINE_FAKE_VALUE_FUNC(void *, net_buf_simple_add, struct net_buf_simple *, size_t); -DEFINE_FAKE_VALUE_FUNC(uint8_t *, net_buf_simple_add_u8, struct net_buf_simple *, uint8_t); -DEFINE_FAKE_VALUE_FUNC(void *, net_buf_simple_add_mem, struct net_buf_simple *, const void *, - size_t); diff --git a/tests/bluetooth/host/id/mocks/net_buf.h b/tests/bluetooth/host/id/mocks/net_buf.h deleted file mode 100644 index b10e2bd327079..0000000000000 --- a/tests/bluetooth/host/id/mocks/net_buf.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -/* List of fakes used by this unit tester */ -#define NET_BUF_FFF_FAKES_LIST(FAKE) \ - FAKE(net_buf_unref) \ - FAKE(net_buf_simple_add) \ - FAKE(net_buf_simple_add_u8) \ - FAKE(net_buf_simple_add_mem) - -DECLARE_FAKE_VOID_FUNC(net_buf_unref, struct net_buf *); -DECLARE_FAKE_VALUE_FUNC(void *, net_buf_simple_add, struct net_buf_simple *, size_t); -DECLARE_FAKE_VALUE_FUNC(uint8_t *, net_buf_simple_add_u8, struct net_buf_simple *, uint8_t); -DECLARE_FAKE_VALUE_FUNC(void *, net_buf_simple_add_mem, struct net_buf_simple *, const void *, - size_t); diff --git a/tests/bluetooth/host/id/mocks/net_buf_expects.c b/tests/bluetooth/host/id/mocks/net_buf_expects.c deleted file mode 100644 index 28cada82e54c7..0000000000000 --- a/tests/bluetooth/host/id/mocks/net_buf_expects.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/net_buf.h" -#include "mocks/net_buf_expects.h" - -#include -#include - -void expect_single_call_net_buf_unref(struct net_buf *buf) -{ - const char *func_name = "net_buf_unref"; - - zassert_equal(net_buf_unref_fake.call_count, 1, "'%s()' was called more than once", - func_name); - - zassert_equal(net_buf_unref_fake.arg0_val, buf, - "'%s()' was called with incorrect '%s' value", func_name, "buf"); -} - -void expect_not_called_net_buf_unref(void) -{ - const char *func_name = "net_buf_unref"; - - zassert_equal(net_buf_unref_fake.call_count, 0, "'%s()' was called unexpectedly", - func_name); -} - -void expect_single_call_net_buf_simple_add(struct net_buf_simple *buf, size_t len) -{ - const char *func_name = "net_buf_simple_add"; - - zassert_equal(net_buf_simple_add_fake.call_count, 1, "'%s()' was called more than once", - func_name); - - zassert_equal(net_buf_simple_add_fake.arg0_val, buf, - "'%s()' was called with incorrect '%s' value", func_name, "buf"); - zassert_equal(net_buf_simple_add_fake.arg1_val, len, - "'%s()' was called with incorrect '%s' value", func_name, "len"); -} - -void expect_not_called_net_buf_simple_add(void) -{ - const char *func_name = "net_buf_simple_add"; - - zassert_equal(net_buf_simple_add_fake.call_count, 0, "'%s()' was called unexpectedly", - func_name); -} diff --git a/tests/bluetooth/host/id/mocks/net_buf_expects.h b/tests/bluetooth/host/id/mocks/net_buf_expects.h deleted file mode 100644 index 4e64ad7c715ff..0000000000000 --- a/tests/bluetooth/host/id/mocks/net_buf_expects.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -/* - * Validate expected behaviour when net_buf_unref() is called - * - * Expected behaviour: - * - net_buf_unref() to be called once with correct parameters - */ -void expect_single_call_net_buf_unref(struct net_buf *buf); - -/* - * Validate expected behaviour when net_buf_unref() isn't called - * - * Expected behaviour: - * - net_buf_unref() isn't called at all - */ -void expect_not_called_net_buf_unref(void); - -/* - * Validate expected behaviour when net_buf_simple_add() is called - * - * Expected behaviour: - * - net_buf_simple_add() to be called once with correct parameters - */ -void expect_single_call_net_buf_simple_add(struct net_buf_simple *buf, size_t len); - -/* - * Validate expected behaviour when net_buf_simple_add() isn't called - * - * Expected behaviour: - * - net_buf_simple_add() isn't called at all - */ -void expect_not_called_net_buf_simple_add(void); diff --git a/tests/bluetooth/host/id/mocks/rpa.c b/tests/bluetooth/host/id/mocks/rpa.c deleted file mode 100644 index 3d10be98f4b5e..0000000000000 --- a/tests/bluetooth/host/id/mocks/rpa.c +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/rpa.h" - -#include - -DEFINE_FAKE_VALUE_FUNC(int, bt_rpa_create, const uint8_t *, bt_addr_t *); diff --git a/tests/bluetooth/host/id/mocks/rpa.h b/tests/bluetooth/host/id/mocks/rpa.h deleted file mode 100644 index 6315c10c33a6d..0000000000000 --- a/tests/bluetooth/host/id/mocks/rpa.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -/* List of fakes used by this unit tester */ -#define RPA_FFF_FAKES_LIST(FAKE) FAKE(bt_rpa_create) - -DECLARE_FAKE_VALUE_FUNC(int, bt_rpa_create, const uint8_t *, bt_addr_t *); diff --git a/tests/bluetooth/host/id/mocks/rpa_expects.c b/tests/bluetooth/host/id/mocks/rpa_expects.c deleted file mode 100644 index 6921cf673fa85..0000000000000 --- a/tests/bluetooth/host/id/mocks/rpa_expects.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/rpa.h" -#include "mocks/rpa_expects.h" - -#include - -void expect_single_call_bt_rpa_create(const uint8_t irk[16]) -{ - const char *func_name = "bt_rpa_create"; - - zassert_equal(bt_rpa_create_fake.call_count, 1, "'%s()' was called more than once", - func_name); - zassert_equal(bt_rpa_create_fake.arg0_val, irk, - "'%s()' was called with incorrect '%s' value", func_name, "irk"); - zassert_not_null(bt_rpa_create_fake.arg1_val, "'%s()' was called with incorrect '%s' value", - func_name, "rpa"); -} - -void expect_not_called_bt_rpa_create(void) -{ - const char *func_name = "bt_rpa_create"; - - zassert_equal(bt_rpa_create_fake.call_count, 0, "'%s()' was called unexpectedly", - func_name); -} diff --git a/tests/bluetooth/host/id/mocks/rpa_expects.h b/tests/bluetooth/host/id/mocks/rpa_expects.h deleted file mode 100644 index 83a08f452779e..0000000000000 --- a/tests/bluetooth/host/id/mocks/rpa_expects.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -/* - * Validate expected behaviour when bt_rpa_create() is called - * - * Expected behaviour: - * - bt_rpa_create() to be called once with correct parameters - */ -void expect_single_call_bt_rpa_create(const uint8_t irk[16]); - -/* - * Validate expected behaviour when bt_rpa_create() isn't called - * - * Expected behaviour: - * - bt_rpa_create() isn't called at all - */ -void expect_not_called_bt_rpa_create(void); diff --git a/tests/bluetooth/host/id/mocks/scan.c b/tests/bluetooth/host/id/mocks/scan.c deleted file mode 100644 index d9921e6f0b175..0000000000000 --- a/tests/bluetooth/host/id/mocks/scan.c +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include - -DEFINE_FAKE_VALUE_FUNC(int, bt_le_scan_set_enable, uint8_t); -DEFINE_FAKE_VALUE_FUNC(bool, bt_le_scan_active_scanner_running); diff --git a/tests/bluetooth/host/id/mocks/scan.h b/tests/bluetooth/host/id/mocks/scan.h deleted file mode 100644 index a54d43b643c02..0000000000000 --- a/tests/bluetooth/host/id/mocks/scan.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -/* List of fakes used by this unit tester */ -#define SCAN_FFF_FAKES_LIST(FAKE) FAKE(bt_le_scan_set_enable) - -DECLARE_FAKE_VALUE_FUNC(int, bt_le_scan_set_enable, uint8_t); -DECLARE_FAKE_VALUE_FUNC(bool, bt_le_scan_active_scanner_running); diff --git a/tests/bluetooth/host/id/mocks/scan_expects.c b/tests/bluetooth/host/id/mocks/scan_expects.c deleted file mode 100644 index f88af4428aa57..0000000000000 --- a/tests/bluetooth/host/id/mocks/scan_expects.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/scan.h" -#include "mocks/scan_expects.h" - -#include - -void expect_call_count_bt_le_scan_set_enable(int call_count, uint8_t args_history[]) -{ - const char *func_name = "bt_le_scan_set_enable"; - - zassert_equal(bt_le_scan_set_enable_fake.call_count, call_count, - "'%s()' was called more than once", func_name); - - for (size_t i = 0; i < call_count; i++) { - zassert_equal(bt_le_scan_set_enable_fake.arg0_history[i], args_history[i], - "'%s()' was called with incorrect '%s' value", func_name, "enable"); - } -} - -void expect_not_called_bt_le_scan_set_enable(void) -{ - const char *func_name = "bt_le_scan_set_enable"; - - zassert_equal(bt_le_scan_set_enable_fake.call_count, 0, "'%s()' was called unexpectedly", - func_name); -} diff --git a/tests/bluetooth/host/id/mocks/scan_expects.h b/tests/bluetooth/host/id/mocks/scan_expects.h deleted file mode 100644 index 9801805c54180..0000000000000 --- a/tests/bluetooth/host/id/mocks/scan_expects.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -/* - * Validate expected behaviour when bt_le_scan_set_enable() is called - * - * Expected behaviour: - * - bt_le_scan_set_enable() to be called once with correct parameters - */ -void expect_call_count_bt_le_scan_set_enable(int call_count, uint8_t args_history[]); - -/* - * Validate expected behaviour when bt_le_scan_set_enable() isn't called - * - * Expected behaviour: - * - bt_le_scan_set_enable() isn't called at all - */ -void expect_not_called_bt_le_scan_set_enable(void); diff --git a/tests/bluetooth/host/id/mocks/settings.c b/tests/bluetooth/host/id/mocks/settings.c deleted file mode 100644 index c690d7bd329f3..0000000000000 --- a/tests/bluetooth/host/id/mocks/settings.c +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/settings.h" - -#include - -DEFINE_FAKE_VOID_FUNC(bt_settings_store_id); -DEFINE_FAKE_VOID_FUNC(bt_settings_delete_id); -DEFINE_FAKE_VOID_FUNC(bt_settings_store_irk); -DEFINE_FAKE_VOID_FUNC(bt_settings_delete_irk); diff --git a/tests/bluetooth/host/id/mocks/settings.h b/tests/bluetooth/host/id/mocks/settings.h deleted file mode 100644 index 07630479eaa17..0000000000000 --- a/tests/bluetooth/host/id/mocks/settings.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -/* List of fakes used by this unit tester */ -#define SETTINGS_FFF_FAKES_LIST(FAKE) \ - FAKE(bt_settings_store_id) \ - FAKE(bt_settings_delete_id) \ - FAKE(bt_settings_store_irk) \ - FAKE(bt_settings_delete_irk) - -DECLARE_FAKE_VOID_FUNC(bt_settings_store_id); -DECLARE_FAKE_VOID_FUNC(bt_settings_delete_id); -DECLARE_FAKE_VOID_FUNC(bt_settings_store_irk); -DECLARE_FAKE_VOID_FUNC(bt_settings_delete_irk); diff --git a/tests/bluetooth/host/id/mocks/settings_expects.c b/tests/bluetooth/host/id/mocks/settings_expects.c deleted file mode 100644 index 71bca4d12d5b2..0000000000000 --- a/tests/bluetooth/host/id/mocks/settings_expects.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/settings.h" -#include "mocks/settings_expects.h" - -#include - -void expect_single_call_bt_settings_store_id(void) -{ - const char *func_name = "bt_settings_store_id"; - - zassert_equal(bt_settings_store_id_fake.call_count, 1, "'%s()' was called more than once", - func_name); -} - -void expect_not_called_bt_settings_store_id(void) -{ - const char *func_name = "bt_settings_store_id"; - - zassert_equal(bt_settings_store_id_fake.call_count, 0, "'%s()' was called unexpectedly", - func_name); -} - -void expect_single_call_bt_settings_store_irk(void) -{ - const char *func_name = "bt_settings_store_irk"; - - zassert_equal(bt_settings_store_irk_fake.call_count, 1, "'%s()' was called more than once", - func_name); -} - -void expect_not_called_bt_settings_store_irk(void) -{ - const char *func_name = "bt_settings_store_irk"; - - zassert_equal(bt_settings_store_irk_fake.call_count, 0, "'%s()' was called unexpectedly", - func_name); -} diff --git a/tests/bluetooth/host/id/mocks/settings_expects.h b/tests/bluetooth/host/id/mocks/settings_expects.h deleted file mode 100644 index c96b8f77393b2..0000000000000 --- a/tests/bluetooth/host/id/mocks/settings_expects.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -/* - * Validate expected behaviour when bt_settings_store_id() is called - * - * Expected behaviour: - * - bt_settings_store_id() to be called once with correct parameters - */ -void expect_single_call_bt_settings_store_id(void); - -/* - * Validate expected behaviour when bt_settings_store_id() isn't called - * - * Expected behaviour: - * - bt_settings_store_id() isn't called at all - */ -void expect_not_called_bt_settings_store_id(void); - -/* - * Validate expected behaviour when bt_settings_store_irk() is called - * - * Expected behaviour: - * - bt_settings_store_irk() to be called once with correct parameters - */ -void expect_single_call_bt_settings_store_irk(void); - -/* - * Validate expected behaviour when bt_settings_store_irk) isn't called - * - * Expected behaviour: - * - bt_settings_store_irk() isn't called at all - */ -void expect_not_called_bt_settings_store_irk(void); diff --git a/tests/bluetooth/host/id/mocks/smp.c b/tests/bluetooth/host/id/mocks/smp.c deleted file mode 100644 index 4143962a8fc35..0000000000000 --- a/tests/bluetooth/host/id/mocks/smp.c +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/smp.h" - -#include - -DEFINE_FAKE_VALUE_FUNC(int, bt_smp_irk_get, uint8_t *, uint8_t *); -DEFINE_FAKE_VALUE_FUNC(int, bt_smp_le_oob_set_tk, struct bt_conn *, const uint8_t *); -DEFINE_FAKE_VALUE_FUNC(int, bt_smp_le_oob_generate_sc_data, struct bt_le_oob_sc_data *); -DEFINE_FAKE_VALUE_FUNC(int, bt_smp_le_oob_set_sc_data, struct bt_conn *, - const struct bt_le_oob_sc_data *, const struct bt_le_oob_sc_data *); -DEFINE_FAKE_VALUE_FUNC(int, bt_smp_le_oob_get_sc_data, struct bt_conn *, - const struct bt_le_oob_sc_data **, const struct bt_le_oob_sc_data **); diff --git a/tests/bluetooth/host/id/mocks/smp.h b/tests/bluetooth/host/id/mocks/smp.h deleted file mode 100644 index 3a7da4cbea221..0000000000000 --- a/tests/bluetooth/host/id/mocks/smp.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include - -#include - -/* List of fakes used by this unit tester */ -#define SMP_FFF_FAKES_LIST(FAKE) \ - FAKE(bt_smp_irk_get) \ - FAKE(bt_smp_le_oob_set_tk) \ - FAKE(bt_smp_le_oob_generate_sc_data) \ - FAKE(bt_smp_le_oob_set_sc_data) \ - FAKE(bt_smp_le_oob_get_sc_data) - -DECLARE_FAKE_VALUE_FUNC(int, bt_smp_irk_get, uint8_t *, uint8_t *); -DECLARE_FAKE_VALUE_FUNC(int, bt_smp_le_oob_set_tk, struct bt_conn *, const uint8_t *); -DECLARE_FAKE_VALUE_FUNC(int, bt_smp_le_oob_generate_sc_data, struct bt_le_oob_sc_data *); -DECLARE_FAKE_VALUE_FUNC(int, bt_smp_le_oob_set_sc_data, struct bt_conn *, - const struct bt_le_oob_sc_data *, const struct bt_le_oob_sc_data *); -DECLARE_FAKE_VALUE_FUNC(int, bt_smp_le_oob_get_sc_data, struct bt_conn *, - const struct bt_le_oob_sc_data **, const struct bt_le_oob_sc_data **); diff --git a/tests/bluetooth/host/id/mocks/smp_expects.c b/tests/bluetooth/host/id/mocks/smp_expects.c deleted file mode 100644 index db1f6509ef45a..0000000000000 --- a/tests/bluetooth/host/id/mocks/smp_expects.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/smp.h" -#include "mocks/smp_expects.h" - -#include - -void expect_single_call_bt_smp_le_oob_generate_sc_data(struct bt_le_oob_sc_data *le_sc_oob) -{ - const char *func_name = "bt_smp_le_oob_generate_sc_data"; - - zassert_equal(bt_smp_le_oob_generate_sc_data_fake.call_count, 1, - "'%s()' was called more than once", func_name); -} - -void expect_not_called_bt_smp_le_oob_generate_sc_data(void) -{ - const char *func_name = "bt_smp_le_oob_generate_sc_data"; - - zassert_equal(bt_smp_le_oob_generate_sc_data_fake.call_count, 0, - "'%s()' was called unexpectedly", func_name); -} - -void expect_single_call_bt_smp_le_oob_set_tk(struct bt_conn *conn, const uint8_t *tk) -{ - const char *func_name = "bt_smp_le_oob_set_tk"; - - zassert_equal(bt_smp_le_oob_set_tk_fake.call_count, 1, "'%s()' was called more than once", - func_name); - - zassert_equal_ptr(bt_smp_le_oob_set_tk_fake.arg0_val, conn, - "'%s()' was called with incorrect '%s' value", func_name, "conn"); - zassert_equal_ptr(bt_smp_le_oob_set_tk_fake.arg1_val, tk, - "'%s()' was called with incorrect '%s' value", func_name, "tk"); -} - -void expect_single_call_bt_smp_le_oob_set_sc_data(struct bt_conn *conn, - const struct bt_le_oob_sc_data *oobd_local, - const struct bt_le_oob_sc_data *oobd_remote) -{ - const char *func_name = "bt_smp_le_oob_set_sc_data"; - - zassert_equal(bt_smp_le_oob_set_sc_data_fake.call_count, 1, - "'%s()' was called more than once", func_name); - - zassert_equal_ptr(bt_smp_le_oob_set_sc_data_fake.arg0_val, conn, - "'%s()' was called with incorrect '%s' value", func_name, "conn"); - zassert_equal_ptr(bt_smp_le_oob_set_sc_data_fake.arg1_val, oobd_local, - "'%s()' was called with incorrect '%s' value", func_name, "oobd_local"); - zassert_equal_ptr(bt_smp_le_oob_set_sc_data_fake.arg2_val, oobd_remote, - "'%s()' was called with incorrect '%s' value", func_name, "oobd_remote"); -} - -void expect_single_call_bt_smp_le_oob_get_sc_data(struct bt_conn *conn, - const struct bt_le_oob_sc_data **oobd_local, - const struct bt_le_oob_sc_data **oobd_remote) -{ - const char *func_name = "bt_smp_le_oob_get_sc_data"; - - zassert_equal(bt_smp_le_oob_get_sc_data_fake.call_count, 1, - "'%s()' was called more than once", func_name); - - zassert_equal_ptr(bt_smp_le_oob_get_sc_data_fake.arg0_val, conn, - "'%s()' was called with incorrect '%s' value", func_name, "conn"); - zassert_equal_ptr(bt_smp_le_oob_get_sc_data_fake.arg1_val, oobd_local, - "'%s()' was called with incorrect '%s' value", func_name, "oobd_local"); - zassert_equal_ptr(bt_smp_le_oob_get_sc_data_fake.arg2_val, oobd_remote, - "'%s()' was called with incorrect '%s' value", func_name, "oobd_remote"); -} diff --git a/tests/bluetooth/host/id/mocks/smp_expects.h b/tests/bluetooth/host/id/mocks/smp_expects.h deleted file mode 100644 index 111890905b072..0000000000000 --- a/tests/bluetooth/host/id/mocks/smp_expects.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -/* - * Validate expected behaviour when bt_smp_le_oob_generate_sc_data() is called - * - * Expected behaviour: - * - bt_smp_le_oob_generate_sc_data() to be called once with correct parameters - */ -void expect_single_call_bt_smp_le_oob_generate_sc_data(struct bt_le_oob_sc_data *le_sc_oob); - -/* - * Validate expected behaviour when bt_smp_le_oob_generate_sc_data() isn't called - * - * Expected behaviour: - * - bt_smp_le_oob_generate_sc_data() isn't called at all - */ -void expect_not_called_bt_smp_le_oob_generate_sc_data(void); - -/* - * Validate expected behaviour when bt_smp_le_oob_set_tk() is called - * - * Expected behaviour: - * - bt_smp_le_oob_set_tk() to be called once with correct parameters - */ -void expect_single_call_bt_smp_le_oob_set_tk(struct bt_conn *conn, const uint8_t *tk); - -/* - * Validate expected behaviour when bt_smp_le_oob_set_sc_data() is called - * - * Expected behaviour: - * - bt_smp_le_oob_set_sc_data() to be called once with correct parameters - */ -void expect_single_call_bt_smp_le_oob_set_sc_data(struct bt_conn *conn, - const struct bt_le_oob_sc_data *oobd_local, - const struct bt_le_oob_sc_data *oobd_remote); - -/* - * Validate expected behaviour when bt_smp_le_oob_get_sc_data() is called - * - * Expected behaviour: - * - bt_smp_le_oob_get_sc_data() to be called once with correct parameters - */ -void expect_single_call_bt_smp_le_oob_get_sc_data(struct bt_conn *conn, - const struct bt_le_oob_sc_data **oobd_local, - const struct bt_le_oob_sc_data **oobd_remote); diff --git a/tests/bluetooth/host/id/mocks/zephyr/devicetree_generated.h b/tests/bluetooth/host/id/mocks/zephyr/devicetree_generated.h deleted file mode 100644 index db591a5b5e530..0000000000000 --- a/tests/bluetooth/host/id/mocks/zephyr/devicetree_generated.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/* - * Dummy header file to avoid compiler errors - * intentionally left blank - */ diff --git a/tests/bluetooth/host/id/mocks/zephyr/linker/linker-defs.h b/tests/bluetooth/host/id/mocks/zephyr/linker/linker-defs.h deleted file mode 100644 index 7bd7faa79350f..0000000000000 --- a/tests/bluetooth/host/id/mocks/zephyr/linker/linker-defs.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/* Undefine definitons that conflict in the unit_testing board build. */ - -#ifdef DT_NODE_HAS_STATUS -#undef DT_NODE_HAS_STATUS -#endif - -#ifdef DT_NODE_HAS_STATUS_OKAY -#undef DT_NODE_HAS_STATUS_OKAY -#endif - -#ifdef DT_FOREACH_OKAY_HELPER -#undef DT_FOREACH_OKAY_HELPER -#endif - -#define DT_FOREACH_OKAY_HELPER(x) diff --git a/tests/bluetooth/host/id/mocks/zephyr/syscalls/device.h b/tests/bluetooth/host/id/mocks/zephyr/syscalls/device.h deleted file mode 100644 index db591a5b5e530..0000000000000 --- a/tests/bluetooth/host/id/mocks/zephyr/syscalls/device.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/* - * Dummy header file to avoid compiler errors - * intentionally left blank - */ diff --git a/tests/bluetooth/host/id/mocks/zephyr/syscalls/mem_manage.h b/tests/bluetooth/host/id/mocks/zephyr/syscalls/mem_manage.h deleted file mode 100644 index db591a5b5e530..0000000000000 --- a/tests/bluetooth/host/id/mocks/zephyr/syscalls/mem_manage.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/* - * Dummy header file to avoid compiler errors - * intentionally left blank - */ diff --git a/tests/bluetooth/host/id/testing_common_defs.h b/tests/bluetooth/host/id/testing_common_defs.h deleted file mode 100644 index c66931ed56b96..0000000000000 --- a/tests/bluetooth/host/id/testing_common_defs.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/** Bluetooth device "test" addresses */ -#define BT_ADDR ((bt_addr_t[]){{{0x0A, 0x89, 0x67, 0x45, 0x23, 0x01}}}) - -/** Bluetooth LE public device "test" addresses */ -#define BT_LE_ADDR ((bt_addr_le_t[]){{BT_ADDR_LE_PUBLIC, {{0x0A, 0x89, 0x67, 0x45, 0x23, 0x01}}}}) - -/** Bluetooth LE device "test" static random addresses */ -#define BT_STATIC_RANDOM_LE_ADDR_1 \ - ((bt_addr_le_t[]){{BT_ADDR_LE_RANDOM, {{0x0A, 0x89, 0x67, 0x45, 0x23, 0xC1}}}}) -#define BT_STATIC_RANDOM_LE_ADDR_2 \ - ((bt_addr_le_t[]){{BT_ADDR_LE_RANDOM, {{0x0B, 0x89, 0x67, 0x45, 0x23, 0xC1}}}}) - -/** Bluetooth LE device "test" random resolvable private addresses */ -#define BT_RPA_LE_ADDR \ - ((bt_addr_le_t[]){{BT_ADDR_LE_RANDOM, {{0x0A, 0x89, 0x67, 0x45, 0x23, 0x41}}}}) diff --git a/tests/bluetooth/host/keys/bt_keys_add_type/CMakeLists.txt b/tests/bluetooth/host/keys/bt_keys_add_type/CMakeLists.txt deleted file mode 100644 index d484bfe7d60d8..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_add_type/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -project(bt_keys_add_type) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/keys/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_add_type_invalid_inputs.c - - # Unit under test - ${ZEPHYR_BASE}/subsys/bluetooth/host/keys.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c -) diff --git a/tests/bluetooth/host/keys/bt_keys_add_type/prj.conf b/tests/bluetooth/host/keys/bt_keys_add_type/prj.conf deleted file mode 100644 index 419fdcd6047df..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_add_type/prj.conf +++ /dev/null @@ -1,10 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_MAX_PAIRED=11 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y - -CONFIG_LOG=n -CONFIG_TEST_LOGGING_DEFAULTS=n diff --git a/tests/bluetooth/host/keys/bt_keys_add_type/src/main.c b/tests/bluetooth/host/keys/bt_keys_add_type/src/main.c deleted file mode 100644 index fc5363ac7c977..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_add_type/src/main.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -#include - -DEFINE_FFF_GLOBALS; - -/* This LUT contains different key types */ -static const int testing_type_lut[] = {BT_KEYS_PERIPH_LTK, BT_KEYS_IRK, BT_KEYS_LTK, - BT_KEYS_LOCAL_CSRK, BT_KEYS_REMOTE_CSRK, BT_KEYS_LTK_P256, - BT_KEYS_ALL}; - -ZTEST_SUITE(bt_keys_add_type_set_and_verify_type_value, NULL, NULL, NULL, NULL, NULL); - -/* - * Set key type and verify that the value is set correctly - * - * Constraints: - * - Valid key reference is used - * - * Expected behaviour: - * - The key type value is set correctly - */ -ZTEST(bt_keys_add_type_set_and_verify_type_value, test_set_type_value_correctly) -{ - for (size_t it = 0; it < ARRAY_SIZE(testing_type_lut); it++) { - struct bt_keys key_ref; - int type = testing_type_lut[it]; - - memset(&key_ref, 0x00, sizeof(struct bt_keys)); - bt_keys_add_type(&key_ref, type); - - zassert_true(key_ref.keys == type, - "bt_keys_add_type() set incorrect key type value"); - } -} - -/* - * Set key type to all valid types and verify that the value is set correctly - * - * Constraints: - * - Valid key reference is used - * - * Expected behaviour: - * - The key type value is set correctly - */ -ZTEST(bt_keys_add_type_set_and_verify_type_value, test_set_type_value_all_valid_correctly) -{ - int expected_value = BT_KEYS_PERIPH_LTK | BT_KEYS_IRK | BT_KEYS_LTK | BT_KEYS_LOCAL_CSRK | - BT_KEYS_REMOTE_CSRK | BT_KEYS_LTK_P256; - - struct bt_keys key_ref; - int type = BT_KEYS_ALL; - - memset(&key_ref, 0x00, sizeof(struct bt_keys)); - bt_keys_add_type(&key_ref, type); - - zassert_true(key_ref.keys == expected_value, - "bt_keys_add_type() set incorrect key type value"); -} - -/* - * Mask the key type with zero and verify that it has no effect - * - * Constraints: - * - Valid key reference is used - * - * Expected behaviour: - * - The key type value isn't changed - */ -ZTEST(bt_keys_add_type_set_and_verify_type_value, test_set_type_value_with_zero_mask_has_no_effect) -{ - int expected_value = BT_KEYS_PERIPH_LTK | BT_KEYS_IRK | BT_KEYS_LTK | BT_KEYS_LOCAL_CSRK | - BT_KEYS_REMOTE_CSRK | BT_KEYS_LTK_P256; - - struct bt_keys key_ref; - int type = BT_KEYS_ALL; - - memset(&key_ref, 0x00, sizeof(struct bt_keys)); - bt_keys_add_type(&key_ref, type); - bt_keys_add_type(&key_ref, 0x00); - - zassert_true(key_ref.keys == expected_value, - "bt_keys_add_type() set incorrect key type value"); -} diff --git a/tests/bluetooth/host/keys/bt_keys_add_type/src/test_suite_add_type_invalid_inputs.c b/tests/bluetooth/host/keys/bt_keys_add_type/src/test_suite_add_type_invalid_inputs.c deleted file mode 100644 index af185e453d62f..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_add_type/src/test_suite_add_type_invalid_inputs.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" - -#include -#include - -#include - -ZTEST_SUITE(bt_keys_add_type_invalid_inputs, NULL, NULL, NULL, NULL, NULL); - -/* - * Test function with NULL key reference - * - * Constraints: - * - Any key type can be used - * - Key reference is passed as NULL - * - * Expected behaviour: - * - An assertion fails and execution stops - */ -ZTEST(bt_keys_add_type_invalid_inputs, test_null_key_reference) -{ - expect_assert(); - bt_keys_add_type(NULL, 0x00); -} diff --git a/tests/bluetooth/host/keys/bt_keys_add_type/testcase.yaml b/tests/bluetooth/host/keys/bt_keys_add_type/testcase.yaml deleted file mode 100644 index c52e922caa501..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_add_type/testcase.yaml +++ /dev/null @@ -1,7 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_keys_add_type.default: - type: unit diff --git a/tests/bluetooth/host/keys/bt_keys_clear/CMakeLists.txt b/tests/bluetooth/host/keys/bt_keys_clear/CMakeLists.txt deleted file mode 100644 index 05f9e35395742..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_clear/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -project(bt_keys_clear) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/keys/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_bt_settings.c - src/test_suite_clear_invalid_inputs.c - - # Unit under test - ${ZEPHYR_BASE}/subsys/bluetooth/host/keys.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c -) diff --git a/tests/bluetooth/host/keys/bt_keys_clear/prj.conf b/tests/bluetooth/host/keys/bt_keys_clear/prj.conf deleted file mode 100644 index 419fdcd6047df..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_clear/prj.conf +++ /dev/null @@ -1,10 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_MAX_PAIRED=11 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y - -CONFIG_LOG=n -CONFIG_TEST_LOGGING_DEFAULTS=n diff --git a/tests/bluetooth/host/keys/bt_keys_clear/src/main.c b/tests/bluetooth/host/keys/bt_keys_clear/src/main.c deleted file mode 100644 index 5744c50339b81..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_clear/src/main.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/id.h" -#include "mocks/id_expects.h" -#include "mocks/keys_help_utils.h" -#include "testing_common_defs.h" - -#include -#include -#include - -DEFINE_FFF_GLOBALS; - -static void tc_setup(void *f) -{ - /* Clear keys pool */ - clear_key_pool(); - - /* Register resets */ - ID_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_SUITE(bt_keys_clear_keys_with_state_not_set, NULL, NULL, tc_setup, NULL, NULL); -ZTEST_SUITE(bt_keys_clear_keys_with_state_set, NULL, NULL, tc_setup, NULL, NULL); - -/* - * Clear an existing key and verify the result while 'BT_KEYS_ID_ADDED' state isn't set. - * As 'BT_KEYS_ID_ADDED' isn't set, bt_id_del() shouldn't be called. - * - * Constraints: - * - Key reference points to a valid item - * - * Expected behaviour: - * - The key content is cleared - * - bt_id_del() isn't called - */ -ZTEST(bt_keys_clear_keys_with_state_not_set, test_key_cleared_bt_id_del_not_called) -{ - struct bt_keys empty_key; - struct bt_keys *key_ref_to_clear, *find_returned_ref; - uint8_t id = BT_ADDR_ID_0; - bt_addr_le_t *addr = BT_ADDR_LE_1; - - if (IS_ENABLED(CONFIG_BT_SETTINGS)) { - ztest_test_skip(); - } - - memset(&empty_key, 0x00, sizeof(struct bt_keys)); - - /* Add custom item to the keys pool */ - key_ref_to_clear = bt_keys_get_addr(id, addr); - zassert_true(key_ref_to_clear != NULL, "bt_keys_get_addr() returned a non-valid reference"); - - /* Ensure that item exists in the keys pool */ - find_returned_ref = bt_keys_find_addr(id, addr); - zassert_true(find_returned_ref != NULL, "bt_keys_find_addr() returned a NULL reference"); - - bt_keys_clear(key_ref_to_clear); - - expect_not_called_bt_id_del(); - - /* Verify that memory was cleared */ - zassert_mem_equal(key_ref_to_clear, &empty_key, sizeof(struct bt_keys), - "Key content wasn't cleared by 'bt_keys_clear()'"); - - /* Ensure that item doesn't exist in the keys pool after calling bt_keys_clear() */ - find_returned_ref = bt_keys_find_addr(id, addr); - zassert_true(find_returned_ref == NULL, - "bt_keys_find_addr() returned a non-NULL reference"); -} - -/* - * Clear an existing key and verify the result while 'BT_KEYS_ID_ADDED' state is set. - * As 'BT_KEYS_ID_ADDED' is set, bt_id_del() should be called. - * - * Constraints: - * - Key reference points to a valid item - * - * Expected behaviour: - * - The key content is cleared - * - bt_id_del() is called with correct key reference - */ -ZTEST(bt_keys_clear_keys_with_state_set, test_key_cleared_bt_id_del_called) -{ - struct bt_keys empty_key; - struct bt_keys *key_ref_to_clear, *find_returned_ref; - uint8_t id = BT_ADDR_ID_0; - bt_addr_le_t *addr = BT_ADDR_LE_1; - - if (IS_ENABLED(CONFIG_BT_SETTINGS)) { - ztest_test_skip(); - } - - memset(&empty_key, 0x00, sizeof(struct bt_keys)); - - /* Add custom item to the keys pool */ - key_ref_to_clear = bt_keys_get_addr(id, addr); - zassert_true(key_ref_to_clear != NULL, "bt_keys_get_addr() returned a non-valid reference"); - - /* Ensure that item exists in the keys pool */ - find_returned_ref = bt_keys_find_addr(id, addr); - zassert_true(find_returned_ref != NULL, "bt_keys_find_addr() returned a NULL reference"); - - key_ref_to_clear->state = BT_KEYS_ID_ADDED; - - bt_keys_clear(key_ref_to_clear); - - expect_single_call_bt_id_del(key_ref_to_clear); - - /* Verify that memory was cleared */ - zassert_mem_equal(key_ref_to_clear, &empty_key, sizeof(struct bt_keys), - "Key content wasn't cleared by 'bt_keys_clear()'"); - - /* Ensure that item doesn't exist in the keys pool after calling bt_keys_clear() */ - find_returned_ref = bt_keys_find_addr(id, addr); - zassert_true(find_returned_ref == NULL, - "bt_keys_find_addr() returned a non-NULL reference"); -} diff --git a/tests/bluetooth/host/keys/bt_keys_clear/src/test_suite_bt_settings.c b/tests/bluetooth/host/keys/bt_keys_clear/src/test_suite_bt_settings.c deleted file mode 100644 index 52418e266ba87..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_clear/src/test_suite_bt_settings.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/keys_help_utils.h" -#include "mocks/settings.h" -#include "mocks/settings_expects.h" -#include "mocks/settings_store.h" -#include "mocks/settings_store_expects.h" -#include "mocks/util.h" -#include "mocks/util_expects.h" -#include "testing_common_defs.h" - -#include -#include - -#include - -static void tc_setup(void *f) -{ - /* Clear keys pool */ - clear_key_pool(); - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_SETTINGS); - - /* Register resets */ - UTIL_FFF_FAKES_LIST(RESET_FAKE); - SETTINGS_FFF_FAKES_LIST(RESET_FAKE); - SETTINGS_STORE_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_SUITE(bt_keys_clear_bt_settings_enabled, NULL, NULL, tc_setup, NULL, NULL); - -/* - * Clear an existing key (ID = 0) and verify the result - * - * Constraints: - * - Key reference points to a valid item - * - Item ID is set to 0 - * - * Expected behaviour: - * - The key content is cleared and removed from persistent memory - */ -ZTEST(bt_keys_clear_bt_settings_enabled, test_clear_key_with_id_equal_0) -{ - struct bt_keys empty_key; - struct bt_keys *returned_key, *find_returned_ref; - uint8_t id = BT_ADDR_ID_0; - bt_addr_le_t *addr = BT_ADDR_LE_1; - - memset(&empty_key, 0x00, sizeof(struct bt_keys)); - - /* Add custom item to the keys pool */ - returned_key = bt_keys_get_addr(id, addr); - zassert_true(returned_key != NULL, "bt_keys_get_addr() returned a non-valid reference"); - - /* Request to clear the key */ - bt_keys_clear(returned_key); - - /* Verify that memory was cleared */ - zassert_mem_equal(returned_key, &empty_key, sizeof(struct bt_keys), - "Key content wasn't cleared by 'bt_keys_clear()'"); - - /* Ensure that item doesn't exist in the keys pool after calling bt_keys_clear() */ - find_returned_ref = bt_keys_find_addr(id, addr); - zassert_true(find_returned_ref == NULL, - "bt_keys_find_addr() returned a non-NULL reference"); - - expect_single_call_bt_settings_delete_keys(); -} - -/* - * Clear an existing key (ID != 0) and verify the result - * - * Constraints: - * - Key reference points to a valid item - * - Item ID isn't set to 0 - * - * Expected behaviour: - * - The key content is cleared and removed from persistent memory - */ -ZTEST(bt_keys_clear_bt_settings_enabled, test_clear_key_with_id_not_equal_0) -{ - struct bt_keys empty_key; - struct bt_keys *returned_key, *find_returned_ref; - uint8_t id = BT_ADDR_ID_1; - bt_addr_le_t *addr = BT_ADDR_LE_1; - - memset(&empty_key, 0x00, sizeof(struct bt_keys)); - - /* Add custom item to the keys pool */ - returned_key = bt_keys_get_addr(id, addr); - zassert_true(returned_key != NULL, "bt_keys_get_addr() returned a non-valid reference"); - - /* Request to clear the key */ - bt_keys_clear(returned_key); - - /* Verify that memory was cleared */ - zassert_mem_equal(returned_key, &empty_key, sizeof(struct bt_keys), - "Key content wasn't cleared by 'bt_keys_clear()'"); - - /* Ensure that item doesn't exist in the keys pool after calling bt_keys_clear() */ - find_returned_ref = bt_keys_find_addr(id, addr); - zassert_true(find_returned_ref == NULL, - "bt_keys_find_addr() returned a non-NULL reference"); - - expect_single_call_bt_settings_delete_keys(); -} diff --git a/tests/bluetooth/host/keys/bt_keys_clear/src/test_suite_clear_invalid_inputs.c b/tests/bluetooth/host/keys/bt_keys_clear/src/test_suite_clear_invalid_inputs.c deleted file mode 100644 index c411dcf48decd..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_clear/src/test_suite_clear_invalid_inputs.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" - -#include -#include - -#include - -ZTEST_SUITE(bt_keys_clear_invalid_inputs, NULL, NULL, NULL, NULL, NULL); - -/* - * Test function with NULL key reference - * - * Constraints: - * - Key reference is passed as NULL - * - * Expected behaviour: - * - An assertion fails and execution stops - */ -ZTEST(bt_keys_clear_invalid_inputs, test_null_key_reference) -{ - expect_assert(); - bt_keys_clear(NULL); -} diff --git a/tests/bluetooth/host/keys/bt_keys_clear/testcase.yaml b/tests/bluetooth/host/keys/bt_keys_clear/testcase.yaml deleted file mode 100644 index 7ed8aa925ec03..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_clear/testcase.yaml +++ /dev/null @@ -1,12 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_keys_clear.default: - type: unit - bluetooth.host.bt_keys_clear.settings_enabled: - type: unit - extra_configs: - - CONFIG_SETTINGS=y - - CONFIG_BT_SETTINGS=y diff --git a/tests/bluetooth/host/keys/bt_keys_find/CMakeLists.txt b/tests/bluetooth/host/keys/bt_keys_find/CMakeLists.txt deleted file mode 100644 index 2403151d284ce..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_find/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -project(bt_keys_find) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/keys/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_find_invalid_inputs.c - - # Unit under test - ${ZEPHYR_BASE}/subsys/bluetooth/host/keys.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c -) diff --git a/tests/bluetooth/host/keys/bt_keys_find/prj.conf b/tests/bluetooth/host/keys/bt_keys_find/prj.conf deleted file mode 100644 index b7101de0bf012..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_find/prj.conf +++ /dev/null @@ -1,10 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_MAX_PAIRED=7 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y - -CONFIG_LOG=n -CONFIG_TEST_LOGGING_DEFAULTS=n diff --git a/tests/bluetooth/host/keys/bt_keys_find/src/main.c b/tests/bluetooth/host/keys/bt_keys_find/src/main.c deleted file mode 100644 index 21facd4494587..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_find/src/main.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/keys_help_utils.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include - -DEFINE_FFF_GLOBALS; - -/* This LUT contains different combinations of ID, Address and key type. - * Item in this list will be used to fill keys pool. - */ -static const struct id_addr_type testing_id_addr_type_lut[] = { - {BT_ADDR_ID_1, BT_ADDR_LE_1, BT_KEYS_PERIPH_LTK}, - {BT_ADDR_ID_1, BT_ADDR_LE_2, BT_KEYS_IRK}, - {BT_ADDR_ID_2, BT_ADDR_LE_1, BT_KEYS_LTK}, - {BT_ADDR_ID_2, BT_ADDR_LE_2, BT_KEYS_LOCAL_CSRK}, - {BT_ADDR_ID_3, BT_ADDR_LE_1, BT_KEYS_REMOTE_CSRK}, - {BT_ADDR_ID_3, BT_ADDR_LE_2, BT_KEYS_LTK_P256}, - {BT_ADDR_ID_4, BT_ADDR_LE_1, BT_KEYS_ALL}}; - -/* This list will hold returned references while filling keys pool */ -static struct bt_keys *returned_keys_refs[CONFIG_BT_MAX_PAIRED]; - -BUILD_ASSERT(ARRAY_SIZE(testing_id_addr_type_lut) == CONFIG_BT_MAX_PAIRED); -BUILD_ASSERT(ARRAY_SIZE(testing_id_addr_type_lut) == ARRAY_SIZE(returned_keys_refs)); - -static void *empty_list_ts_setup(void) -{ - clear_key_pool(); - - return NULL; -} - -ZTEST_SUITE(bt_keys_find_initially_empty_list, NULL, empty_list_ts_setup, NULL, NULL, NULL); - -/* - * Test calling bt_keys_find() with non-existing item - * - * Constraints: - * - Valid values of non-existing items are used - * - * Expected behaviour: - * - NULL reference is returned - */ -ZTEST(bt_keys_find_initially_empty_list, test_find_non_existing_item) -{ - for (uint32_t i = 0; i < ARRAY_SIZE(testing_id_addr_type_lut); i++) { - struct bt_keys *returned_ref; - struct id_addr_type const *params_vector = &testing_id_addr_type_lut[i]; - int type = params_vector->type; - uint8_t id = params_vector->id; - const bt_addr_le_t *addr = params_vector->addr; - - returned_ref = bt_keys_find(type, id, addr); - zassert_true(returned_ref == NULL, "bt_keys_find() returned a non-NULL reference"); - } -} - -static void *filled_list_ts_setup(void) -{ - clear_key_pool(); - int rv = fill_key_pool_by_id_addr_type( - testing_id_addr_type_lut, ARRAY_SIZE(testing_id_addr_type_lut), returned_keys_refs); - - zassert_true(rv == 0, "Failed to fill keys pool list, error code %d", -rv); - - return NULL; -} - -ZTEST_SUITE(bt_keys_find_initially_filled_list, NULL, filled_list_ts_setup, NULL, NULL, NULL); - -/* - * Test calling bt_keys_find() with existing items - * - * Constraints: - * - Keys pool list is filled - * - Valid values of existing items are used - * - * Expected behaviour: - * - Valid reference pointer is returned and matches the correct reference - */ -ZTEST(bt_keys_find_initially_filled_list, test_find_existing_item) -{ - int type; - uint8_t id; - const bt_addr_le_t *addr; - struct bt_keys *returned_ref, *expected_key_ref; - - for (size_t it = 0; it < ARRAY_SIZE(testing_id_addr_type_lut); it++) { - - type = testing_id_addr_type_lut[it].type; - id = testing_id_addr_type_lut[it].id; - addr = testing_id_addr_type_lut[it].addr; - - expected_key_ref = returned_keys_refs[it]; - - returned_ref = bt_keys_find(type, id, addr); - - zassert_true(returned_ref != NULL, "bt_keys_find() returned a NULL reference"); - zassert_equal_ptr(returned_ref, expected_key_ref, - "bt_keys_find() returned unexpected reference"); - } -} diff --git a/tests/bluetooth/host/keys/bt_keys_find/src/test_suite_find_invalid_inputs.c b/tests/bluetooth/host/keys/bt_keys_find/src/test_suite_find_invalid_inputs.c deleted file mode 100644 index c8bf0e0b0df73..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_find/src/test_suite_find_invalid_inputs.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" - -#include -#include - -#include - -ZTEST_SUITE(bt_keys_find_invalid_inputs, NULL, NULL, NULL, NULL, NULL); - -/* - * Test calling bt_keys_find() with NULL address - * - * Constraints: - * - Any key type can be used - * - Any ID value can be used - * - Address is passed as NULL - * - * Expected behaviour: - * - An assertion fails and execution stops - */ -ZTEST(bt_keys_find_invalid_inputs, test_null_device_address) -{ - expect_assert(); - bt_keys_find(0x00, 0x00, NULL); -} diff --git a/tests/bluetooth/host/keys/bt_keys_find/testcase.yaml b/tests/bluetooth/host/keys/bt_keys_find/testcase.yaml deleted file mode 100644 index 0492c26a16fbc..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_find/testcase.yaml +++ /dev/null @@ -1,7 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_keys_find.default: - type: unit diff --git a/tests/bluetooth/host/keys/bt_keys_find_addr/CMakeLists.txt b/tests/bluetooth/host/keys/bt_keys_find_addr/CMakeLists.txt deleted file mode 100644 index 48db7b76b4f8e..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_find_addr/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -project(bt_keys_find_addr) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/keys/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_find_addr_invalid_inputs.c - - # Unit under test - ${ZEPHYR_BASE}/subsys/bluetooth/host/keys.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c -) diff --git a/tests/bluetooth/host/keys/bt_keys_find_addr/prj.conf b/tests/bluetooth/host/keys/bt_keys_find_addr/prj.conf deleted file mode 100644 index 419fdcd6047df..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_find_addr/prj.conf +++ /dev/null @@ -1,10 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_MAX_PAIRED=11 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y - -CONFIG_LOG=n -CONFIG_TEST_LOGGING_DEFAULTS=n diff --git a/tests/bluetooth/host/keys/bt_keys_find_addr/src/main.c b/tests/bluetooth/host/keys/bt_keys_find_addr/src/main.c deleted file mode 100644 index a586faeb7e437..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_find_addr/src/main.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/keys_help_utils.h" -#include "mocks/rpa.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include - -DEFINE_FFF_GLOBALS; - -/* This LUT contains different combinations of ID, Address and key type. - * Item in this list will be used to fill keys pool. - */ -static const struct id_addr_pair testing_id_addr_pair_lut[] = { - - {BT_ADDR_ID_1, BT_ADDR_LE_1}, {BT_ADDR_ID_1, BT_RPA_ADDR_LE_1}, - {BT_ADDR_ID_1, BT_RPA_ADDR_LE_2}, {BT_ADDR_ID_1, BT_ADDR_LE_3}, - - {BT_ADDR_ID_2, BT_ADDR_LE_1}, {BT_ADDR_ID_2, BT_RPA_ADDR_LE_2}, - {BT_ADDR_ID_2, BT_RPA_ADDR_LE_3}, {BT_ADDR_ID_2, BT_ADDR_LE_2}, - - {BT_ADDR_ID_3, BT_ADDR_LE_1}, {BT_ADDR_ID_3, BT_ADDR_LE_2}, - - {BT_ADDR_ID_4, BT_ADDR_LE_1}}; - -/* This list will hold returned references while filling keys pool */ -static struct bt_keys *returned_keys_refs[CONFIG_BT_MAX_PAIRED]; - -BUILD_ASSERT(ARRAY_SIZE(testing_id_addr_pair_lut) == CONFIG_BT_MAX_PAIRED); -BUILD_ASSERT(ARRAY_SIZE(testing_id_addr_pair_lut) == ARRAY_SIZE(returned_keys_refs)); - -static void *empty_list_ts_setup(void) -{ - clear_key_pool(); - - return NULL; -} - -ZTEST_SUITE(bt_keys_find_addr_initially_empty_list, NULL, empty_list_ts_setup, NULL, NULL, NULL); - -/* - * Find a non-existing key reference for ID and Address pair - * - * Constraints: - * - Empty keys pool list - * - * Expected behaviour: - * - A NULL value is returned - */ -ZTEST(bt_keys_find_addr_initially_empty_list, test_find_non_existing_key) -{ - for (uint32_t i = 0; i < ARRAY_SIZE(testing_id_addr_pair_lut); i++) { - struct bt_keys *returned_ref; - struct id_addr_pair const *params_vector = &testing_id_addr_pair_lut[i]; - uint8_t id = params_vector->id; - const bt_addr_le_t *addr = params_vector->addr; - - returned_ref = bt_keys_find_addr(id, addr); - - zassert_true(returned_ref == NULL, "bt_keys_find() returned a non-NULL reference"); - } -} - -static void *filled_list_ts_setup(void) -{ - clear_key_pool(); - int rv = fill_key_pool_by_id_addr(testing_id_addr_pair_lut, - ARRAY_SIZE(testing_id_addr_pair_lut), returned_keys_refs); - - zassert_true(rv == 0, "Failed to fill keys pool list, error code %d", -rv); - - return NULL; -} - -ZTEST_SUITE(bt_keys_find_addr_initially_filled_list, NULL, filled_list_ts_setup, NULL, NULL, NULL); - -/* - * Find an existing key reference by ID and Address - * - * Constraints: - * - ID and address pair does exist in keys pool - * - * Expected behaviour: - * - A valid reference value is returned - */ -ZTEST(bt_keys_find_addr_initially_filled_list, test_find_existing_key_by_id_and_address) -{ - for (uint32_t i = 0; i < ARRAY_SIZE(testing_id_addr_pair_lut); i++) { - struct bt_keys *returned_ref, *expected_key_ref; - struct id_addr_pair const *params_vector = &testing_id_addr_pair_lut[i]; - uint8_t id = params_vector->id; - const bt_addr_le_t *addr = params_vector->addr; - - expected_key_ref = returned_keys_refs[i]; - - returned_ref = bt_keys_find_addr(id, addr); - - zassert_true(returned_ref != NULL, "bt_keys_find_addr() returned a NULL reference"); - zassert_equal_ptr(returned_ref, expected_key_ref, - "bt_keys_find_addr() returned unexpected reference"); - } -} diff --git a/tests/bluetooth/host/keys/bt_keys_find_addr/src/test_suite_find_addr_invalid_inputs.c b/tests/bluetooth/host/keys/bt_keys_find_addr/src/test_suite_find_addr_invalid_inputs.c deleted file mode 100644 index 6c0492bd7133c..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_find_addr/src/test_suite_find_addr_invalid_inputs.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" - -#include -#include - -#include - -ZTEST_SUITE(bt_keys_find_addr_invalid_inputs, NULL, NULL, NULL, NULL, NULL); - -/* - * Test function with NULL address - * - * Constraints: - * - Any ID value can be used - * - Address is passed as NULL - * - * Expected behaviour: - * - An assertion fails and execution stops - */ -ZTEST(bt_keys_find_addr_invalid_inputs, test_null_device_address) -{ - expect_assert(); - bt_keys_find_addr(0x00, NULL); -} diff --git a/tests/bluetooth/host/keys/bt_keys_find_addr/testcase.yaml b/tests/bluetooth/host/keys/bt_keys_find_addr/testcase.yaml deleted file mode 100644 index 4875b89ff978e..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_find_addr/testcase.yaml +++ /dev/null @@ -1,7 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_keys_find_addr.default: - type: unit diff --git a/tests/bluetooth/host/keys/bt_keys_find_irk/CMakeLists.txt b/tests/bluetooth/host/keys/bt_keys_find_irk/CMakeLists.txt deleted file mode 100644 index 0de5468018017..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_find_irk/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -project(bt_keys_find_irk) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/keys/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_find_irk_invalid_inputs.c - - # Unit under test - ${ZEPHYR_BASE}/subsys/bluetooth/host/keys.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c -) diff --git a/tests/bluetooth/host/keys/bt_keys_find_irk/prj.conf b/tests/bluetooth/host/keys/bt_keys_find_irk/prj.conf deleted file mode 100644 index 419fdcd6047df..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_find_irk/prj.conf +++ /dev/null @@ -1,10 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_MAX_PAIRED=11 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y - -CONFIG_LOG=n -CONFIG_TEST_LOGGING_DEFAULTS=n diff --git a/tests/bluetooth/host/keys/bt_keys_find_irk/src/main.c b/tests/bluetooth/host/keys/bt_keys_find_irk/src/main.c deleted file mode 100644 index 1c467224c0af2..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_find_irk/src/main.c +++ /dev/null @@ -1,328 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/keys_help_utils.h" -#include "mocks/rpa.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include - -DEFINE_FFF_GLOBALS; - -/* This LUT contains different combinations of ID, Address and key type. - * Item in this list will be used to fill keys pool. - */ -static const struct id_addr_type testing_id_addr_type_lut[] = { - - {BT_ADDR_ID_1, BT_ADDR_LE_1, BT_KEYS_PERIPH_LTK}, - {BT_ADDR_ID_1, BT_RPA_ADDR_LE_1, BT_KEYS_PERIPH_LTK}, - {BT_ADDR_ID_1, BT_RPA_ADDR_LE_2, BT_KEYS_IRK}, - {BT_ADDR_ID_1, BT_ADDR_LE_3, BT_KEYS_IRK}, - - {BT_ADDR_ID_2, BT_ADDR_LE_1, BT_KEYS_LTK}, - {BT_ADDR_ID_2, BT_RPA_ADDR_LE_3, BT_KEYS_IRK}, - {BT_ADDR_ID_2, BT_RPA_ADDR_LE_4, BT_KEYS_IRK}, - {BT_ADDR_ID_2, BT_ADDR_LE_2, BT_KEYS_LOCAL_CSRK}, - - {BT_ADDR_ID_3, BT_ADDR_LE_1, BT_KEYS_REMOTE_CSRK}, - {BT_ADDR_ID_3, BT_ADDR_LE_2, BT_KEYS_LTK_P256}, - - {BT_ADDR_ID_4, BT_ADDR_LE_1, BT_KEYS_ALL}}; - -/* Global iterator to iterate over the ID, Address and type LUT */ -static uint8_t params_it; - -/* Pointer to the current set of testing parameters */ -static struct id_addr_type const *current_params_vector; - -/* This list will hold returned references while filling keys pool */ -static struct bt_keys *returned_keys_refs[CONFIG_BT_MAX_PAIRED]; - -BUILD_ASSERT(ARRAY_SIZE(testing_id_addr_type_lut) == CONFIG_BT_MAX_PAIRED); -BUILD_ASSERT(ARRAY_SIZE(testing_id_addr_type_lut) == ARRAY_SIZE(returned_keys_refs)); - -/* Check if a Bluetooth LE random address is resolvable private address. */ -#define BT_ADDR_IS_RPA(a) (((a)->val[5] & 0xc0) == 0x40) - -static bool check_if_addr_is_rpa(const bt_addr_le_t *addr) -{ - if (addr->type != BT_ADDR_LE_RANDOM) { - return false; - } - - return BT_ADDR_IS_RPA(&addr->a); -} - -static bool bt_rpa_irk_matches_unreachable_custom_fake(const uint8_t irk[16], const bt_addr_t *addr) -{ - zassert_unreachable("Unexpected call to 'bt_rpa_irk_matches()' occurred"); - return true; -} - -static bool bt_rpa_irk_matches_custom_fake(const uint8_t irk[16], const bt_addr_t *addr) -{ - if (irk[0] != (params_it) && bt_addr_eq(¤t_params_vector->addr->a, addr)) { - return false; - } - - return true; -} - -static void *empty_list_ts_setup(void) -{ - clear_key_pool(); - - return NULL; -} - -ZTEST_SUITE(bt_keys_find_irk_initially_empty_list, NULL, empty_list_ts_setup, NULL, NULL, NULL); - -/* - * Find a non-existing key reference for ID and Address of type 'BT_KEYS_IRK' - * - * Constraints: - * - Empty keys pool list - * - * Expected behaviour: - * - A NULL value is returned - */ -ZTEST(bt_keys_find_irk_initially_empty_list, test_find_non_existing_key_reference) -{ - uint8_t id; - const bt_addr_le_t *addr; - struct bt_keys *returned_ref; - struct id_addr_type const *params_vector; - - for (size_t i = 0; i < ARRAY_SIZE(testing_id_addr_type_lut); i++) { - - params_vector = &testing_id_addr_type_lut[i]; - id = params_vector->id; - addr = params_vector->addr; - - returned_ref = bt_keys_find_irk(id, addr); - - zassert_true(returned_ref == NULL, - "bt_keys_find_irk() returned a non-valid reference"); - } -} - -static void rpa_resolving_ts_setup(void *f) -{ - clear_key_pool(); - int rv = fill_key_pool_by_id_addr_type( - testing_id_addr_type_lut, ARRAY_SIZE(testing_id_addr_type_lut), returned_keys_refs); - - zassert_true(rv == 0, "Failed to fill keys pool list, error code %d", -rv); - - /* Set the index to the IRK value to recognize row index during bt_rpa_irk_matches() - * callback - */ - for (size_t it = 0; it < ARRAY_SIZE(returned_keys_refs); it++) { - returned_keys_refs[it]->irk.val[0] = it; - } - - RPA_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_SUITE(bt_keys_find_irk_rpa_resolving, NULL, NULL, rpa_resolving_ts_setup, NULL, NULL); - -/* - * Try to resolve an RPA address using IRK by finding an existing key reference for ID and Address - * of type 'BT_KEYS_IRK'. Matching the address with existing IRKs fails. - * - * Constraints: - * - Full keys pool list - * - IRK value and device address don't match - * - * Expected behaviour: - * - A NULL value is returned - */ -ZTEST(bt_keys_find_irk_rpa_resolving, test_resolving_rpa_address_by_irk_but_matching_fails) -{ - uint8_t id; - const bt_addr_le_t *addr; - struct bt_keys *returned_ref; - struct id_addr_type const *params_vector; - - bt_rpa_irk_matches_fake.return_val = false; - - for (size_t i = 0; i < ARRAY_SIZE(testing_id_addr_type_lut); i++) { - - params_vector = &testing_id_addr_type_lut[i]; - id = params_vector->id; - addr = params_vector->addr; - - returned_ref = bt_keys_find_irk(id, addr); - - zassert_true(returned_ref == NULL, - "bt_keys_find_irk() returned a non-valid reference"); - } -} - -/* - * Try to resolve an RPA address using IRK by finding an existing key reference for ID and Address - * of type 'BT_KEYS_IRK'. Matching the address with existing IRKs fails. - * - * Constraints: - * - Full keys pool list - * - IRK value and device address match - * - * Expected behaviour: - * - A valid reference value is returned - */ -ZTEST(bt_keys_find_irk_rpa_resolving, test_resolving_rpa_address_by_irk_and_matching_succeeds) -{ - int type; - uint8_t id; - const bt_addr_le_t *addr; - struct id_addr_type const *params_vector; - struct bt_keys *returned_ref, *expected_key_ref; - - bt_rpa_irk_matches_fake.custom_fake = bt_rpa_irk_matches_custom_fake; - - for (size_t it = 0; it < ARRAY_SIZE(testing_id_addr_type_lut); it++) { - - params_vector = &testing_id_addr_type_lut[it]; - type = params_vector->type; - id = params_vector->id; - addr = params_vector->addr; - - /* Set global variables to be used within bt_rpa_irk_matches_custom_fake() */ - params_it = it; - current_params_vector = params_vector; - - expected_key_ref = returned_keys_refs[it]; - - /* - * Try to resolve the current testing vector address. - * Address will be considered resolvable if: - * - The current testing vector address is an RPA - * - The current testing vector key type is an IRK - */ - returned_ref = bt_keys_find_irk(id, addr); - - if (check_if_addr_is_rpa(addr) && (type & BT_KEYS_IRK)) { - - zassert_true(returned_ref != NULL, - "bt_keys_find_irk() returned a NULL reference %d", it); - - zassert_equal_ptr(returned_ref, expected_key_ref, - "bt_keys_find_irk() returned unexpected reference"); - - /* Check if address has been stored */ - zassert_mem_equal(&returned_ref->irk.rpa, &addr->a, sizeof(bt_addr_t), - "Incorrect address was stored by 'bt_keys_find_irk()'"); - } else { - zassert_true(returned_ref == NULL, - "bt_keys_find_irk() returned a non-valid reference %d", it); - } - } -} - -static void *no_resolving_ts_setup(void) -{ - int type; - const bt_addr_le_t *addr; - struct id_addr_type const *params_vector; - - clear_key_pool(); - int rv = fill_key_pool_by_id_addr_type( - testing_id_addr_type_lut, ARRAY_SIZE(testing_id_addr_type_lut), returned_keys_refs); - - zassert_true(rv == 0, "Failed to fill keys pool list, error code %d", -rv); - - /* Set the index to the IRK value to recognize row index during bt_rpa_irk_matches() - * callback - */ - for (size_t it = 0; it < ARRAY_SIZE(returned_keys_refs); it++) { - returned_keys_refs[it]->irk.val[0] = it; - } - - /* Copy the address as if was previously resolved using IRK */ - for (size_t it = 0; it < ARRAY_SIZE(returned_keys_refs); it++) { - - params_vector = &testing_id_addr_type_lut[it]; - type = params_vector->type; - addr = params_vector->addr; - - if (check_if_addr_is_rpa(addr) && (type & BT_KEYS_IRK)) { - bt_addr_copy(&returned_keys_refs[it]->irk.rpa, &addr->a); - } - } - - return NULL; -} - -ZTEST_SUITE(bt_keys_find_irk_no_resolving, NULL, no_resolving_ts_setup, NULL, NULL, NULL); - -/* - * Find an existing key reference for ID and Address of type 'BT_KEYS_IRK' - * while the address has been resolved previously using the IRK - * - * Constraints: - * - Full keys pool list - * - IRK address and device address match - * - * Expected behaviour: - * - A valid reference value is returned - */ -ZTEST(bt_keys_find_irk_no_resolving, test_find_key_of_previously_resolved_address) -{ - int type; - uint8_t id; - const bt_addr_le_t *addr; - struct id_addr_type const *params_vector; - struct bt_keys *returned_ref, *expected_key_ref; - - for (size_t it = 0; it < ARRAY_SIZE(testing_id_addr_type_lut); it++) { - - params_vector = &testing_id_addr_type_lut[it]; - type = params_vector->type; - id = params_vector->id; - addr = params_vector->addr; - - /* Set global variables to be used within bt_rpa_irk_matches_custom_fake() */ - params_it = it; - current_params_vector = params_vector; - - /* - * Now, as the address under test should have been resolved before, - * bt_rpa_irk_matches() isn't expected to be called for an RPA. - * - * But, for other records, which won't be resolved, a call to bt_rpa_irk_matches() - * is expected simulating the attempt to resolve it - */ - if (check_if_addr_is_rpa(addr) && (type & BT_KEYS_IRK)) { - bt_rpa_irk_matches_fake.custom_fake = - bt_rpa_irk_matches_unreachable_custom_fake; - } else { - bt_rpa_irk_matches_fake.custom_fake = bt_rpa_irk_matches_custom_fake; - } - - expected_key_ref = returned_keys_refs[it]; - - returned_ref = bt_keys_find_irk(id, addr); - - if (check_if_addr_is_rpa(addr) && (type & BT_KEYS_IRK)) { - - zassert_true(returned_ref != NULL, - "bt_keys_find_irk() returned a NULL reference"); - zassert_equal_ptr(returned_ref, expected_key_ref, - "bt_keys_find_irk() returned unexpected reference"); - - /* Check if address has been stored */ - zassert_mem_equal(&returned_ref->irk.rpa, &addr->a, sizeof(bt_addr_t), - "Incorrect address was stored by 'bt_keys_find_irk()'"); - } else { - zassert_true(returned_ref == NULL, - "bt_keys_find_irk() returned a non-valid reference"); - } - } -} diff --git a/tests/bluetooth/host/keys/bt_keys_find_irk/src/test_suite_find_irk_invalid_inputs.c b/tests/bluetooth/host/keys/bt_keys_find_irk/src/test_suite_find_irk_invalid_inputs.c deleted file mode 100644 index 32b5d21992fa4..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_find_irk/src/test_suite_find_irk_invalid_inputs.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" - -#include -#include - -#include - -ZTEST_SUITE(bt_keys_find_irk_invalid_inputs, NULL, NULL, NULL, NULL, NULL); - -/* - * Test function with NULL address - * - * Constraints: - * - Any ID value can be used - * - Address is passed as NULL - * - * Expected behaviour: - * - An assertion fails and execution stops - */ -ZTEST(bt_keys_find_irk_invalid_inputs, test_null_device_address) -{ - expect_assert(); - bt_keys_find_irk(0x00, NULL); -} diff --git a/tests/bluetooth/host/keys/bt_keys_find_irk/testcase.yaml b/tests/bluetooth/host/keys/bt_keys_find_irk/testcase.yaml deleted file mode 100644 index 45f32163c08d4..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_find_irk/testcase.yaml +++ /dev/null @@ -1,7 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_keys_find_irk.default: - type: unit diff --git a/tests/bluetooth/host/keys/bt_keys_foreach_bond/CMakeLists.txt b/tests/bluetooth/host/keys/bt_keys_foreach_bond/CMakeLists.txt deleted file mode 100644 index f6920e233a3ce..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_foreach_bond/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -project(bt_keys_foreach_bond) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/keys/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_foreach_bond_invalid_inputs.c - - # Unit under test - ${ZEPHYR_BASE}/subsys/bluetooth/host/keys.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c -) diff --git a/tests/bluetooth/host/keys/bt_keys_foreach_bond/prj.conf b/tests/bluetooth/host/keys/bt_keys_foreach_bond/prj.conf deleted file mode 100644 index d50176dd3d3d9..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_foreach_bond/prj.conf +++ /dev/null @@ -1,9 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_MAX_PAIRED=4 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_LOG=n -CONFIG_TEST_LOGGING_DEFAULTS=n diff --git a/tests/bluetooth/host/keys/bt_keys_foreach_bond/src/main.c b/tests/bluetooth/host/keys/bt_keys_foreach_bond/src/main.c deleted file mode 100644 index 06b3195558ae8..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_foreach_bond/src/main.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include -#include -#include "mocks/keys_help_utils.h" -#include "testing_common_defs.h" - -DEFINE_FFF_GLOBALS; - -/* This LUT contains different combinations of ID and Address pairs */ -const struct id_addr_pair testing_id_addr_pair_lut[] = { - { BT_ADDR_ID_1, BT_ADDR_LE_1 }, - { BT_ADDR_ID_1, BT_ADDR_LE_2 }, - { BT_ADDR_ID_2, BT_ADDR_LE_1 }, - { BT_ADDR_ID_2, BT_ADDR_LE_2 } -}; - -/* This list will hold returned references while filling keys pool */ -static struct bt_keys *returned_keys_refs[CONFIG_BT_MAX_PAIRED]; - -BUILD_ASSERT(ARRAY_SIZE(testing_id_addr_pair_lut) == CONFIG_BT_MAX_PAIRED); -BUILD_ASSERT(ARRAY_SIZE(testing_id_addr_pair_lut) == ARRAY_SIZE(returned_keys_refs)); - -static void *type_not_set_ts_setup(void) -{ - clear_key_pool(); - int rv = fill_key_pool_by_id_addr(testing_id_addr_pair_lut, - ARRAY_SIZE(testing_id_addr_pair_lut), returned_keys_refs); - - zassert_true(rv == 0, "Failed to fill keys pool list, error code %d", -rv); - - return NULL; -} - -ZTEST_SUITE(bt_keys_foreach_bond_keys_type_not_set, NULL, type_not_set_ts_setup, NULL, NULL, NULL); - -/* Callback to be used when no calls are expected by bt_foreach_bond() */ -static void bt_foreach_bond_unreachable_cb(const struct bt_bond_info *info, void *user_data) -{ - zassert_unreachable("Unexpected call to '%s()' occurred", __func__); -} - -/* - * Test calling bt_foreach_bond() with a valid ID that exists - * in the keys pool but the keys type isn't set - * - * Constraints: - * - Keys pool has been filled - * - Keys type isn't set - * - * Expected behaviour: - * - Callback should never be called - */ -ZTEST(bt_keys_foreach_bond_keys_type_not_set, test_existing_id_type_is_not_set) -{ - struct id_addr_pair const *current_params_vector; - uint8_t id; - - for (size_t i = 0; i < ARRAY_SIZE(testing_id_addr_pair_lut); i++) { - - current_params_vector = &testing_id_addr_pair_lut[i]; - id = current_params_vector->id; - - bt_foreach_bond(id, bt_foreach_bond_unreachable_cb, NULL); - } -} - -static void *type_set_ts_setup(void) -{ - clear_key_pool(); - int rv = fill_key_pool_by_id_addr(testing_id_addr_pair_lut, - ARRAY_SIZE(testing_id_addr_pair_lut), returned_keys_refs); - - zassert_true(rv == 0, "Failed to fill keys pool list, error code %d", -rv); - - for (uint32_t i = 0; i < ARRAY_SIZE(returned_keys_refs); i++) { - returned_keys_refs[i]->keys |= BT_KEYS_ALL; - } - - return NULL; -} - -ZTEST_SUITE(bt_keys_foreach_bond_keys_type_set, NULL, type_set_ts_setup, NULL, NULL, NULL); - -/* Callback to be used when calls are expected by bt_foreach_bond() */ -static void bt_foreach_bond_expected_cb(const struct bt_bond_info *info, void *user_data) -{ - uint32_t *call_counter = (uint32_t *)user_data; - - zassert_true(info != NULL, "Unexpected NULL reference pointer for parameter '%s'", "info"); - zassert_true(user_data != NULL, "Unexpected NULL reference pointer for parameter '%s'", - "user_data"); - - (*call_counter)++; -} - -/* - * Test calling bt_foreach_bond() with a valid ID that exists - * in the keys pool while the keys type is set - * - * Constraints: - * - Keys pool has been filled - * - Keys type is set - * - * Expected behaviour: - * - Callback should be called for each occurrence - */ -ZTEST(bt_keys_foreach_bond_keys_type_set, test_existing_id_type_is_set) -{ - uint32_t call_counter = 0; - struct id_addr_pair const *current_params_vector; - uint8_t id; - - for (size_t i = 0; i < ARRAY_SIZE(testing_id_addr_pair_lut); i++) { - - current_params_vector = &testing_id_addr_pair_lut[i]; - id = current_params_vector->id; - - /* Each ID was registered in the list with 2 different addresses */ - bt_foreach_bond(id, bt_foreach_bond_expected_cb, (void *)&call_counter); - zassert_true(call_counter == 2, - "Incorrect call counter for 'bt_foreach_bond_expected_cb()'"); - - call_counter = 0; - } -} diff --git a/tests/bluetooth/host/keys/bt_keys_foreach_bond/src/test_suite_foreach_bond_invalid_inputs.c b/tests/bluetooth/host/keys/bt_keys_foreach_bond/src/test_suite_foreach_bond_invalid_inputs.c deleted file mode 100644 index 2abdcdabab0a9..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_foreach_bond/src/test_suite_foreach_bond_invalid_inputs.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include "host_mocks/assert.h" -#include "mocks/keys_help_utils.h" - -/* This LUT contains different combinations of ID and Address pairs */ -extern const struct id_addr_pair testing_id_addr_pair_lut[CONFIG_BT_MAX_PAIRED]; - -static void test_case_setup(void *f) -{ - clear_key_pool(); -} - -ZTEST_SUITE(bt_keys_foreach_bond_invalid_inputs, NULL, NULL, test_case_setup, NULL, NULL); - -/* - * Test callback function is set to NULL - * - * Constraints: - * - Any ID value can be used - * - Callback function pointer is set to NULL - * - * Expected behaviour: - * - An assertion fails and execution stops - */ -ZTEST(bt_keys_foreach_bond_invalid_inputs, test_null_callback) -{ - expect_assert(); - bt_foreach_bond(0x00, NULL, NULL); -} - -/* Callback to be used when no calls are expected by bt_foreach_bond() */ -static void bt_foreach_bond_unreachable_cb(const struct bt_bond_info *info, void *user_data) -{ - zassert_unreachable("Unexpected call to '%s()' occurred", __func__); -} - -/* - * Test if the callback will be called if the ID doesn't exist with a NULL value for the user data. - * - * Constraints: - * - Empty keys pool list - * - ID doesn't exist in the list - * - NULL value is used for the user data - * - Valid callback is passed to bt_keys_foreach_bond() - * - * Expected behaviour: - * - Callback should never be called - */ -ZTEST(bt_keys_foreach_bond_invalid_inputs, test_callback_non_existing_id_with_null_user_data) -{ - bt_foreach_bond(0x00, bt_foreach_bond_unreachable_cb, NULL); -} - -/* - * Test if the callback will be called if the ID doesn't exist with a valid value for the user - * data. - * - * Constraints: - * - Empty keys pool list - * - ID doesn't exist in the list - * - Valid value is used for the user data - * - Valid callback is passed to bt_keys_foreach_bond() - * - * Expected behaviour: - * - Callback should never be called - */ -ZTEST(bt_keys_foreach_bond_invalid_inputs, test_callback_non_existing_id_with_valid_user_data) -{ - size_t user_data; - - for (size_t i = 0; i < ARRAY_SIZE(testing_id_addr_pair_lut); i++) { - uint8_t id = testing_id_addr_pair_lut[i].id; - - bt_foreach_bond(id, bt_foreach_bond_unreachable_cb, &user_data); - } -} diff --git a/tests/bluetooth/host/keys/bt_keys_foreach_bond/testcase.yaml b/tests/bluetooth/host/keys/bt_keys_foreach_bond/testcase.yaml deleted file mode 100644 index 5058fae1c4caa..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_foreach_bond/testcase.yaml +++ /dev/null @@ -1,7 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_keys_foreach_bond.default: - type: unit diff --git a/tests/bluetooth/host/keys/bt_keys_foreach_type/CMakeLists.txt b/tests/bluetooth/host/keys/bt_keys_foreach_type/CMakeLists.txt deleted file mode 100644 index f48a2d2428053..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_foreach_type/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -project(bt_keys_foreach_type) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/keys/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_foreach_type_invalid_inputs.c - - # Unit under test - ${ZEPHYR_BASE}/subsys/bluetooth/host/keys.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c -) diff --git a/tests/bluetooth/host/keys/bt_keys_foreach_type/prj.conf b/tests/bluetooth/host/keys/bt_keys_foreach_type/prj.conf deleted file mode 100644 index b650eff88e57a..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_foreach_type/prj.conf +++ /dev/null @@ -1,9 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_MAX_PAIRED=7 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_LOG=n -CONFIG_TEST_LOGGING_DEFAULTS=n diff --git a/tests/bluetooth/host/keys/bt_keys_foreach_type/src/main.c b/tests/bluetooth/host/keys/bt_keys_foreach_type/src/main.c deleted file mode 100644 index e00e331fd3a1f..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_foreach_type/src/main.c +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include -#include -#include "mocks/keys_help_utils.h" -#include "testing_common_defs.h" - -DEFINE_FFF_GLOBALS; - -/* This LUT contains different combinations of ID, Address with no key type */ -static const struct id_addr_type testing_id_addr_type_no_type_lut[] = { - { BT_ADDR_ID_1, BT_ADDR_LE_1, 0x00 }, - { BT_ADDR_ID_1, BT_ADDR_LE_2, 0x00 }, - { BT_ADDR_ID_2, BT_ADDR_LE_1, 0x00 }, - { BT_ADDR_ID_2, BT_ADDR_LE_2, 0x00 }, - { BT_ADDR_ID_3, BT_ADDR_LE_1, 0x00 }, - { BT_ADDR_ID_3, BT_ADDR_LE_2, 0x00 }, - { BT_ADDR_ID_4, BT_ADDR_LE_1, 0x00 } -}; - -/* This LUT contains different combinations of ID, Address and key type */ -const struct id_addr_type testing_id_addr_type_lut[] = { - { BT_ADDR_ID_1, BT_ADDR_LE_1, BT_KEYS_PERIPH_LTK }, - { BT_ADDR_ID_1, BT_ADDR_LE_2, BT_KEYS_IRK }, - { BT_ADDR_ID_2, BT_ADDR_LE_1, BT_KEYS_LTK }, - { BT_ADDR_ID_2, BT_ADDR_LE_2, BT_KEYS_LOCAL_CSRK }, - { BT_ADDR_ID_3, BT_ADDR_LE_1, BT_KEYS_REMOTE_CSRK }, - { BT_ADDR_ID_3, BT_ADDR_LE_2, BT_KEYS_LTK_P256 }, - { BT_ADDR_ID_4, BT_ADDR_LE_1, BT_KEYS_ALL } -}; - -/* This list will hold returned references while filling keys pool */ -static struct bt_keys *returned_keys_refs[CONFIG_BT_MAX_PAIRED]; - -BUILD_ASSERT(ARRAY_SIZE(testing_id_addr_type_lut) == CONFIG_BT_MAX_PAIRED); -BUILD_ASSERT(ARRAY_SIZE(testing_id_addr_type_lut) == ARRAY_SIZE(returned_keys_refs)); -BUILD_ASSERT(ARRAY_SIZE(testing_id_addr_type_no_type_lut) == CONFIG_BT_MAX_PAIRED); -BUILD_ASSERT(ARRAY_SIZE(testing_id_addr_type_no_type_lut) == ARRAY_SIZE(returned_keys_refs)); - -static void *type_not_set_ts_setup(void) -{ - clear_key_pool(); - int rv = fill_key_pool_by_id_addr_type(testing_id_addr_type_no_type_lut, - ARRAY_SIZE(testing_id_addr_type_no_type_lut), - returned_keys_refs); - - zassert_true(rv == 0, "Failed to fill keys pool list, error code %d", -rv); - - return NULL; -} - -ZTEST_SUITE(bt_keys_foreach_type_keys_type_not_set, NULL, type_not_set_ts_setup, NULL, NULL, NULL); - -/* Callback to be used when no calls are expected by bt_keys_foreach_type() */ -static void bt_keys_foreach_type_unreachable_cb(struct bt_keys *keys, void *data) -{ - zassert_unreachable("Unexpected call to '%s()' occurred", __func__); -} - -/* - * Test calling bt_keys_foreach_type() with a valid key type while the keys type isn't set - * - * Constraints: - * - Keys pool has been filled - * - Keys type isn't set - * - * Expected behaviour: - * - Callback should never be called - */ -ZTEST(bt_keys_foreach_type_keys_type_not_set, test_existing_id_type_is_not_set) -{ - struct id_addr_type const *current_params_vector; - int type; - - for (size_t i = 0; i < ARRAY_SIZE(testing_id_addr_type_lut); i++) { - - current_params_vector = &testing_id_addr_type_lut[i]; - type = current_params_vector->type; - - bt_keys_foreach_type(type, bt_keys_foreach_type_unreachable_cb, NULL); - } -} - -static void *type_set_ts_setup(void) -{ - clear_key_pool(); - int rv = fill_key_pool_by_id_addr_type(testing_id_addr_type_lut, - ARRAY_SIZE(testing_id_addr_type_lut), returned_keys_refs); - - zassert_true(rv == 0, "Failed to fill keys pool list, error code %d", -rv); - - return NULL; -} - -ZTEST_SUITE(bt_keys_foreach_type_keys_type_set, NULL, type_set_ts_setup, NULL, NULL, NULL); - -/* Callback to be used when calls are expected by bt_keys_foreach_type() */ -void bt_keys_foreach_type_expected_cb(struct bt_keys *keys, void *data) -{ - uint32_t *call_counter = (uint32_t *)data; - - zassert_true(keys != NULL, "Unexpected NULL reference pointer for parameter '%s'", "keys"); - zassert_true(data != NULL, "Unexpected NULL reference pointer for parameter '%s'", "data"); - - (*call_counter)++; -} - -/* - * Test calling bt_keys_foreach_type() with a valid key type while the keys type is set - * - * Constraints: - * - Keys pool has been filled - * - Keys type is set - * - * Expected behaviour: - * - Callback should be called for each occurrence - */ -ZTEST(bt_keys_foreach_type_keys_type_set, test_existing_id_type_is_set) -{ - uint32_t call_counter = 0; - struct id_addr_type const *current_params_vector; - int type; - int expected_call_count; - - for (size_t i = 0; i < ARRAY_SIZE(testing_id_addr_type_lut); i++) { - - current_params_vector = &testing_id_addr_type_lut[i]; - type = current_params_vector->type; - expected_call_count = (type != BT_KEYS_ALL) ? 2 : CONFIG_BT_MAX_PAIRED; - - /* Because the keys pool list contains a record that matches the argument 'type' and - * a record with the value 'BT_KEYS_ALL', Callback should be called twice for each - * type except when key type is BT_KEYS_ALL which will cause the callback to be - * called as many times as the list size - */ - bt_keys_foreach_type(type, bt_keys_foreach_type_expected_cb, (void *)&call_counter); - zassert_true(call_counter == expected_call_count, - "Incorrect calls count for 'bt_keys_foreach_type_expected_cb()'"); - - call_counter = 0; - } -} diff --git a/tests/bluetooth/host/keys/bt_keys_foreach_type/src/test_suite_foreach_type_invalid_inputs.c b/tests/bluetooth/host/keys/bt_keys_foreach_type/src/test_suite_foreach_type_invalid_inputs.c deleted file mode 100644 index 568affb58ad95..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_foreach_type/src/test_suite_foreach_type_invalid_inputs.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include "host_mocks/assert.h" -#include "mocks/keys_help_utils.h" - -/* This LUT contains different combinations of ID, Address and key type. - * It is defined in main.c. - */ -extern const struct id_addr_type testing_id_addr_type_lut[CONFIG_BT_MAX_PAIRED]; - -static void test_case_setup(void *f) -{ - clear_key_pool(); -} - -ZTEST_SUITE(bt_keys_foreach_type_invalid_inputs, NULL, NULL, test_case_setup, NULL, NULL); - -/* - * Test callback function is set to NULL - * - * Constraints: - * - Any key type can be used - * - Callback function pointer is set to NULL - * - * Expected behaviour: - * - An assertion fails and execution stops - */ -ZTEST(bt_keys_foreach_type_invalid_inputs, test_null_callback) -{ - expect_assert(); - bt_keys_foreach_type(0x00, NULL, NULL); -} - -/* Callback to be used when no calls are expected by bt_keys_foreach_type() */ -static void bt_keys_foreach_type_unreachable_cb(struct bt_keys *keys, void *data) -{ - zassert_unreachable("Unexpected call to '%s()' occurred", __func__); -} - -/* - * Test empty keys pool list with no key type set and a NULL value for the user data. - * - * Constraints: - * - Empty keys pool list - * - Valid value is used for the key type - * - NULL value is used for the user data - * - Valid callback is passed to bt_keys_foreach_type() - * - * Expected behaviour: - * - Callback should never be called - */ -ZTEST(bt_keys_foreach_type_invalid_inputs, test_empty_list_no_type_set_with_null_user_data) -{ - bt_keys_foreach_type(0x00, bt_keys_foreach_type_unreachable_cb, NULL); -} - -/* - * Test empty keys pool list with no key type set and a valid value for the user data. - * - * Constraints: - * - Empty keys pool list - * - Valid value is used for the key type - * - Valid value is used for the user data - * - Valid callback is passed to bt_keys_foreach_type() - * - * Expected behaviour: - * - Callback should never be called - */ -ZTEST(bt_keys_foreach_type_invalid_inputs, test_empty_list_no_type_set_with_valid_user_data) -{ - size_t user_data; - - for (size_t i = 0; i < ARRAY_SIZE(testing_id_addr_type_lut); i++) { - int type = testing_id_addr_type_lut[i].type; - - bt_keys_foreach_type(type, bt_keys_foreach_type_unreachable_cb, &user_data); - } -} diff --git a/tests/bluetooth/host/keys/bt_keys_foreach_type/testcase.yaml b/tests/bluetooth/host/keys/bt_keys_foreach_type/testcase.yaml deleted file mode 100644 index eaa875ee96247..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_foreach_type/testcase.yaml +++ /dev/null @@ -1,7 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_keys_foreach_type.default: - type: unit diff --git a/tests/bluetooth/host/keys/bt_keys_get_addr/CMakeLists.txt b/tests/bluetooth/host/keys/bt_keys_get_addr/CMakeLists.txt deleted file mode 100644 index 9f0e0d4d4a0aa..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_get_addr/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(bt_keys_get_addr) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/keys/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_full_list_invalid_values.c - src/test_suite_full_list_no_overwrite.c - src/test_suite_full_list_overwrite_oldest.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c - - # Unit under test - ${ZEPHYR_BASE}/subsys/bluetooth/host/keys.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c -) diff --git a/tests/bluetooth/host/keys/bt_keys_get_addr/prj.conf b/tests/bluetooth/host/keys/bt_keys_get_addr/prj.conf deleted file mode 100644 index d50176dd3d3d9..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_get_addr/prj.conf +++ /dev/null @@ -1,9 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_MAX_PAIRED=4 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_LOG=n -CONFIG_TEST_LOGGING_DEFAULTS=n diff --git a/tests/bluetooth/host/keys/bt_keys_get_addr/src/main.c b/tests/bluetooth/host/keys/bt_keys_get_addr/src/main.c deleted file mode 100644 index cebbf1923e918..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_get_addr/src/main.c +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include -#include "mocks/conn.h" -#include "mocks/hci_core.h" -#include "mocks/keys_help_utils.h" -#include "testing_common_defs.h" -#include "common/bt_str.h" - -DEFINE_FFF_GLOBALS; - -/* This LUT contains different combinations of ID and Address pairs */ -const struct id_addr_pair testing_id_addr_pair_lut[] = { - { BT_ADDR_ID_1, BT_ADDR_LE_1 }, - { BT_ADDR_ID_1, BT_ADDR_LE_2 }, - { BT_ADDR_ID_2, BT_ADDR_LE_1 }, - { BT_ADDR_ID_2, BT_ADDR_LE_2 } -}; - -/* This list will hold returned references while filling keys pool */ -struct bt_keys *returned_keys_refs[CONFIG_BT_MAX_PAIRED]; - -static bool all_startup_checks_executed; - -BUILD_ASSERT(ARRAY_SIZE(testing_id_addr_pair_lut) == CONFIG_BT_MAX_PAIRED); -BUILD_ASSERT(ARRAY_SIZE(testing_id_addr_pair_lut) == ARRAY_SIZE(returned_keys_refs)); - -static bool startup_suite_predicate(const void *global_state) -{ - return (all_startup_checks_executed == false); -} - -ZTEST_SUITE(bt_keys_get_addr_startup, startup_suite_predicate, NULL, NULL, NULL, NULL); - -/* - * Check if the keys pool list is empty after starting up - * - * Constraints: - * - Check is executed after starting up, prior to adding any keys - * - * Expected behaviour: - * - Keys pool list is empty - */ -ZTEST(bt_keys_get_addr_startup, test_keys_pool_list_is_empty_at_startup) -{ - zassert_true(check_key_pool_is_empty(), - "List isn't empty, make sure to run this test just after a fresh start"); -} - -ZTEST_SUITE(bt_keys_get_addr_populate_non_existing_keys, NULL, NULL, NULL, NULL, NULL); - -/* - * Test filling the keys pool with (ID, Address) pairs - * - * Constraints: - * - Keys pool list is empty after starting up - * - * Expected behaviour: - * - A valid reference is returned by bt_keys_get_addr() - * - ID value matches the one passed to bt_keys_get_addr() - * - Address value matches the one passed to bt_keys_get_addr() - */ -ZTEST(bt_keys_get_addr_populate_non_existing_keys, test_populate_key_pool) -{ - struct id_addr_pair const *current_params_vector; - struct bt_keys *returned_key; - uint8_t id; - bt_addr_le_t *addr; - - for (size_t i = 0; i < ARRAY_SIZE(testing_id_addr_pair_lut); i++) { - - current_params_vector = &testing_id_addr_pair_lut[i]; - id = current_params_vector->id; - addr = current_params_vector->addr; - - returned_key = bt_keys_get_addr(id, addr); - returned_keys_refs[i] = returned_key; - - zassert_true(returned_key != NULL, - "bt_keys_get_addr() failed to add key %d to the keys pool", i); - zassert_true(returned_key->id == id, - "bt_keys_get_addr() returned a reference with an incorrect ID"); - zassert_true(!bt_addr_le_cmp(&returned_key->addr, addr), - "bt_keys_get_addr() set incorrect address %s value, expected %s", - bt_addr_le_str(&returned_key->addr), bt_addr_le_str(addr)); - } -} - -/* - * Test no equal references returned by bt_keys_get_addr() - * - * Constraints: - * - Keys pool has been filled - * - * Expected behaviour: - * - All returned references are different from each other - */ -ZTEST(bt_keys_get_addr_populate_non_existing_keys, test_no_equal_references) -{ - struct bt_keys *keys_pool = bt_keys_get_key_pool(); - - for (uint32_t i = 0; i < ARRAY_SIZE(returned_keys_refs); i++) { - struct bt_keys *returned_ref = returned_keys_refs[i]; - - zassert_equal_ptr(keys_pool + i, returned_ref, - "bt_keys_get_addr() returned unexpected reference at slot %u", i); - } -} - -/* Setup test variables */ -static void test_case_setup(void *f) -{ - clear_key_pool(); - - int rv = fill_key_pool_by_id_addr(testing_id_addr_pair_lut, - ARRAY_SIZE(testing_id_addr_pair_lut), returned_keys_refs); - - zassert_true(rv == 0, "Failed to fill keys pool list, error code %d", -rv); -} - -ZTEST_SUITE(bt_keys_get_addr_get_existing_keys, NULL, NULL, test_case_setup, NULL, NULL); - -/* - * Test getting a valid key reference by a matching ID and address pair - * - * Constraints: - * - ID and address pairs has been inserted in the list - * - * Expected behaviour: - * - A valid reference is returned by bt_keys_get_addr() that - * matches the one returned after adding the ID and address pair - * - ID value matches the one passed to bt_keys_get_addr() - * - Address value matches the one passed to bt_keys_get_addr() - */ -ZTEST(bt_keys_get_addr_get_existing_keys, test_get_key_by_matched_id_and_address) -{ - struct bt_keys *returned_key, *expected_key_ref; - struct id_addr_pair const *current_params_vector; - uint8_t id; - bt_addr_le_t *addr; - - for (size_t i = 0; i < ARRAY_SIZE(testing_id_addr_pair_lut); i++) { - current_params_vector = &testing_id_addr_pair_lut[i]; - id = current_params_vector->id; - addr = current_params_vector->addr; - - returned_key = bt_keys_get_addr(id, addr); - expected_key_ref = returned_keys_refs[i]; - - zassert_true(returned_key != NULL, - "bt_keys_get_addr() failed to add key %d to the keys pool", i); - zassert_equal_ptr(returned_key, expected_key_ref, - "bt_keys_get_addr() returned unexpected reference"); - } -} - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - - /* Skip tests if not all startup suite hasn't been executed */ - if (strcmp(test->test_suite_name, "bt_keys_get_addr_startup")) { - if (all_startup_checks_executed != true) { - ztest_test_skip(); - } - } - - CONN_FFF_FAKES_LIST(RESET_FAKE); - HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -void test_main(void) -{ - /* Only startup suite will run. */ - all_startup_checks_executed = false; - ztest_run_all(NULL, false, 1, 1); - - /* All other suites, except startup suite, will run. */ - all_startup_checks_executed = true; - ztest_run_all(NULL, false, 1, 1); - - /* Check that all the suites in this binary ran at least once. */ - ztest_verify_all_test_suites_ran(); -} diff --git a/tests/bluetooth/host/keys/bt_keys_get_addr/src/test_suite_full_list_invalid_values.c b/tests/bluetooth/host/keys/bt_keys_get_addr/src/test_suite_full_list_invalid_values.c deleted file mode 100644 index af0190f8a146f..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_get_addr/src/test_suite_full_list_invalid_values.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include "mocks/conn.h" -#include "mocks/hci_core.h" -#include "mocks/keys_help_utils.h" -#include "mocks/hci_core_expects.h" -#include "host_mocks/assert.h" -#include "testing_common_defs.h" - -/* This LUT contains different combinations of ID and Address pairs */ -extern const struct id_addr_pair testing_id_addr_pair_lut[CONFIG_BT_MAX_PAIRED]; - -/* This list holds returned references while filling keys pool */ -extern struct bt_keys *returned_keys_refs[CONFIG_BT_MAX_PAIRED]; - -static int bt_unpair_unreachable_custom_fake(uint8_t id, const bt_addr_le_t *addr) -{ - ARG_UNUSED(id); - ARG_UNUSED(addr); - zassert_unreachable("Unexpected call to 'bt_unpair()' occurred"); - return 0; -} - -static void bt_conn_foreach_conn_ref_null_custom_fake(enum bt_conn_type type, - bt_conn_foreach_cb func, void *data) -{ - func(NULL, data); -} - -static void bt_conn_foreach_data_ref_null_custom_fake(enum bt_conn_type type, - bt_conn_foreach_cb func, void *data) -{ - struct bt_conn conn; - - func(&conn, NULL); -} - -/* Setup test variables */ -static void test_case_setup(void *f) -{ - clear_key_pool(); - - int rv = fill_key_pool_by_id_addr(testing_id_addr_pair_lut, - ARRAY_SIZE(testing_id_addr_pair_lut), returned_keys_refs); - - zassert_true(rv == 0, "Failed to fill keys pool list, error code %d", -rv); -} - -ZTEST_SUITE(bt_keys_find_key_in_use_invalid_cases, NULL, NULL, test_case_setup, NULL, NULL); - -/* - * Test adding extra (ID, Address) pair while the keys pool list is full, but while looking - * for the keys in use, find_key_in_use() receives an invalid NULL connection reference. - * - * Constraints: - * - Keys pool list is full - * - CONFIG_BT_KEYS_OVERWRITE_OLDEST is enabled - * - * Expected behaviour: - * - Internal function find_key_in_use() receives a NULL connection reference - * - An assertion fails at find_key_in_use() and execution stops - */ -ZTEST(bt_keys_find_key_in_use_invalid_cases, test_find_key_in_use_receives_null_conn_ref) -{ - uint8_t id = BT_ADDR_ID_5; - bt_addr_le_t *addr = BT_ADDR_LE_5; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_KEYS_OVERWRITE_OLDEST); - - bt_unpair_fake.custom_fake = bt_unpair_unreachable_custom_fake; - bt_conn_foreach_fake.custom_fake = bt_conn_foreach_conn_ref_null_custom_fake; - - expect_assert(); - bt_keys_get_addr(id, addr); - - /* Should not reach this point */ - zassert_unreachable(NULL); -} - -/* - * Test adding extra (ID, Address) pair while the keys pool list is full, but while looking - * for the keys in use, find_key_in_use() receives an invalid NULL data reference. - * - * Constraints: - * - Keys pool list is full - * - CONFIG_BT_KEYS_OVERWRITE_OLDEST is enabled - * - * Expected behaviour: - * - Internal function find_key_in_use() receives a NULL data reference - * - An assertion fails at find_key_in_use() and execution stops - */ -ZTEST(bt_keys_find_key_in_use_invalid_cases, test_find_key_in_use_receives_null_data_ref) -{ - uint8_t id = BT_ADDR_ID_5; - bt_addr_le_t *addr = BT_ADDR_LE_5; - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_KEYS_OVERWRITE_OLDEST); - - bt_unpair_fake.custom_fake = bt_unpair_unreachable_custom_fake; - bt_conn_foreach_fake.custom_fake = bt_conn_foreach_data_ref_null_custom_fake; - - expect_assert(); - bt_keys_get_addr(id, addr); - - /* Should not reach this point */ - zassert_unreachable(NULL); -} - -ZTEST_SUITE(bt_keys_get_addr_null_reference, NULL, NULL, NULL, NULL, NULL); - -/* - * Test invalid (NULL) BT address reference - * - * Constraints: - * - Address value is NULL - * - * Expected behaviour: - * - An assertion fails and execution stops - */ -ZTEST(bt_keys_get_addr_null_reference, test_null_address_reference) -{ - expect_assert(); - bt_keys_get_addr(0x00, NULL); -} diff --git a/tests/bluetooth/host/keys/bt_keys_get_addr/src/test_suite_full_list_no_overwrite.c b/tests/bluetooth/host/keys/bt_keys_get_addr/src/test_suite_full_list_no_overwrite.c deleted file mode 100644 index 96ea3643e9053..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_get_addr/src/test_suite_full_list_no_overwrite.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include "mocks/keys_help_utils.h" -#include "mocks/hci_core_expects.h" -#include "testing_common_defs.h" - -/* This LUT contains different combinations of ID and Address pairs */ -extern const struct id_addr_pair testing_id_addr_pair_lut[CONFIG_BT_MAX_PAIRED]; - -/* This list holds returned references while filling keys pool */ -extern struct bt_keys *returned_keys_refs[CONFIG_BT_MAX_PAIRED]; - -/* Setup test variables */ -static void test_case_setup(void *f) -{ - Z_TEST_SKIP_IFDEF(CONFIG_BT_KEYS_OVERWRITE_OLDEST); - - clear_key_pool(); - - int rv = fill_key_pool_by_id_addr(testing_id_addr_pair_lut, - ARRAY_SIZE(testing_id_addr_pair_lut), returned_keys_refs); - - zassert_true(rv == 0, "Failed to fill keys pool list, error code %d", -rv); -} - -ZTEST_SUITE(bt_keys_get_addr_full_list_no_overwrite, NULL, NULL, test_case_setup, NULL, NULL); - -/* - * Test adding extra (ID, Address) pair while the keys pool list is full. - * As 'CONFIG_BT_KEYS_OVERWRITE_OLDEST' isn't enabled, no (ID, Address) pairs can be added while - * the list is full. - * - * Constraints: - * - Keys pool list is full - * - CONFIG_BT_KEYS_OVERWRITE_OLDEST isn't enabled - * - * Expected behaviour: - * - NULL reference pointer is returned - */ -ZTEST(bt_keys_get_addr_full_list_no_overwrite, test_adding_new_pair_to_full_list) -{ - struct bt_keys *returned_key; - uint8_t id = BT_ADDR_ID_3; - bt_addr_le_t *addr = BT_ADDR_LE_3; - - returned_key = bt_keys_get_addr(id, addr); - - expect_not_called_bt_unpair(); - - zassert_true(returned_key == NULL, "bt_keys_get_addr() returned a non-NULL reference"); -} diff --git a/tests/bluetooth/host/keys/bt_keys_get_addr/src/test_suite_full_list_overwrite_oldest.c b/tests/bluetooth/host/keys/bt_keys_get_addr/src/test_suite_full_list_overwrite_oldest.c deleted file mode 100644 index 2e06ae21731f3..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_get_addr/src/test_suite_full_list_overwrite_oldest.c +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include "mocks/conn.h" -#include "mocks/hci_core.h" -#include "mocks/keys_help_utils.h" -#include "mocks/hci_core_expects.h" -#include "testing_common_defs.h" - -/* This LUT contains different combinations of ID and Address pairs */ -extern const struct id_addr_pair testing_id_addr_pair_lut[CONFIG_BT_MAX_PAIRED]; - -/* This list holds returned references while filling keys pool */ -extern struct bt_keys *returned_keys_refs[CONFIG_BT_MAX_PAIRED]; - -/* Pointer to the current set of oldest testing parameter */ -struct id_addr_pair const *oldest_params_vector; - -static int bt_unpair_custom_fake(uint8_t id, const bt_addr_le_t *addr) -{ - struct bt_keys *keys = NULL; - - /* Find the key slot with matched id and address */ - keys = bt_keys_find_addr(id, addr); - if (keys) { - bt_keys_clear(keys); - } - - /* This check is used here because bt_unpair() is called with a local variable address */ - expect_single_call_bt_unpair(oldest_params_vector->id, oldest_params_vector->addr); - - return 0; -} - -static int bt_unpair_unreachable_custom_fake(uint8_t id, const bt_addr_le_t *addr) -{ - ARG_UNUSED(id); - ARG_UNUSED(addr); - zassert_unreachable("Unexpected call to 'bt_unpair()' occurred"); - return 0; -} - -static void bt_conn_foreach_key_slot_0_in_use_custom_fake(enum bt_conn_type type, - bt_conn_foreach_cb func, void *data) -{ - struct bt_conn conn; - - /* This will make the effect as if there is a disconnection */ - conn.state = BT_CONN_DISCONNECTED; - conn.id = 0x9E; - func(&conn, data); - - /* This will make the effect as if there is a connection with no key */ - conn.state = BT_CONN_CONNECTED; - conn.id = 0xFF; - bt_addr_le_copy(&conn.le.dst, (const bt_addr_le_t *)BT_ADDR_LE_ANY); - bt_conn_get_dst_fake.return_val = &conn.le.dst; - func(&conn, data); - - /* This will make the effect as if key at slot 0 is in use with a connection */ - conn.state = BT_CONN_CONNECTED; - conn.id = testing_id_addr_pair_lut[0].id; - bt_addr_le_copy(&conn.le.dst, testing_id_addr_pair_lut[0].addr); - bt_conn_get_dst_fake.return_val = &conn.le.dst; - func(&conn, data); -} - -static void bt_conn_foreach_all_keys_in_use_custom_fake(enum bt_conn_type type, - bt_conn_foreach_cb func, void *data) -{ - struct bt_conn conn; - - /* This will make the effect as if key at slot 'x' is in use with a connection */ - for (size_t i = 0; i < ARRAY_SIZE(testing_id_addr_pair_lut); i++) { - conn.state = BT_CONN_CONNECTED; - conn.id = testing_id_addr_pair_lut[i].id; - bt_addr_le_copy(&conn.le.dst, testing_id_addr_pair_lut[i].addr); - bt_conn_get_dst_fake.return_val = &conn.le.dst; - func(&conn, data); - } -} - -static void bt_conn_foreach_no_keys_in_use_custom_fake(enum bt_conn_type type, - bt_conn_foreach_cb func, void *data) -{ - struct bt_conn conn; - - /* This will make the effect as if key at slot 'x' is in use with a connection */ - for (size_t i = 0; i < ARRAY_SIZE(testing_id_addr_pair_lut); i++) { - conn.state = BT_CONN_DISCONNECTED; - conn.id = testing_id_addr_pair_lut[i].id; - bt_addr_le_copy(&conn.le.dst, testing_id_addr_pair_lut[i].addr); - bt_conn_get_dst_fake.return_val = &conn.le.dst; - func(&conn, data); - } -} - -/* Setup test variables */ -static void test_case_setup(void *f) -{ - Z_TEST_SKIP_IFNDEF(CONFIG_BT_KEYS_OVERWRITE_OLDEST); - - clear_key_pool(); - - int rv = fill_key_pool_by_id_addr(testing_id_addr_pair_lut, - ARRAY_SIZE(testing_id_addr_pair_lut), returned_keys_refs); - - zassert_true(rv == 0, "Failed to fill keys pool list, error code %d", -rv); -} - -ZTEST_SUITE(bt_keys_get_addr_full_list_overwrite_oldest, NULL, NULL, test_case_setup, NULL, NULL); - -/* - * Test adding extra (ID, Address) pair while the keys pool list is full while all keys are in - * use with connections so that no more (ID, Address) pairs can be added. - * - * Constraints: - * - Keys pool list is full - * - All Keys are used with a connection - * - CONFIG_BT_KEYS_OVERWRITE_OLDEST is enabled - * - * Expected behaviour: - * - NULL pointer is returned as there is no room - */ -ZTEST(bt_keys_get_addr_full_list_overwrite_oldest, test_full_list_all_keys_in_use) -{ - struct bt_keys *returned_key; - uint8_t id = BT_ADDR_ID_3; - bt_addr_le_t *addr = BT_ADDR_LE_3; - - bt_unpair_fake.custom_fake = bt_unpair_unreachable_custom_fake; - bt_conn_foreach_fake.custom_fake = bt_conn_foreach_all_keys_in_use_custom_fake; - - returned_key = bt_keys_get_addr(id, addr); - - zassert_true(returned_key == NULL, "bt_keys_get_addr() returned a non-NULL reference"); -} - -/* - * Test adding extra (ID, Address) pair while the keys pool list is full, but no keys are used with - * connections. New (ID, Address) pairs can be added by replacing the oldest pair. - * - * Constraints: - * - Keys pool list is full - * - All Keys are not used with a connection - * - CONFIG_BT_KEYS_OVERWRITE_OLDEST is enabled - * - * Expected behaviour: - * - A valid pointer in the keys pool is returned, matching the one previously assigned to the - * oldest key (index 0). - */ -ZTEST(bt_keys_get_addr_full_list_overwrite_oldest, test_full_list_no_keys_in_use) -{ - struct bt_keys *returned_key; - uint8_t id = BT_ADDR_ID_3; - bt_addr_le_t *addr = BT_ADDR_LE_3; - uint32_t expected_oldest_params_ref_idx; - - expected_oldest_params_ref_idx = 0; - oldest_params_vector = &testing_id_addr_pair_lut[expected_oldest_params_ref_idx]; - bt_unpair_fake.custom_fake = bt_unpair_custom_fake; - bt_conn_foreach_fake.custom_fake = bt_conn_foreach_no_keys_in_use_custom_fake; - - returned_key = bt_keys_get_addr(id, addr); - - zassert_true(returned_key != NULL, "bt_keys_get_addr() returned a NULL reference"); - zassert_true(returned_key == returned_keys_refs[expected_oldest_params_ref_idx], - "bt_keys_get_addr() returned reference doesn't match expected one"); -} - -/* - * Test adding extra (ID, Address) pair while the keys pool list is full when the oldest key slot - * is in use with a connection but others keys aren't. - * New (ID, address) pair should replace the oldest one that's not in use. - * - * Constraints: - * - Keys pool list is full - * - Oldest key at slot 0 is used with a connection - * - Next oldest key (slot 1) isn't used with a connection - * - CONFIG_BT_KEYS_OVERWRITE_OLDEST is enabled - * - * Expected behaviour: - * - A valid pointer in the keys pool is returned, matching the one previously assigned to the - * oldest key (index 1). - */ -ZTEST(bt_keys_get_addr_full_list_overwrite_oldest, test_full_list_key_0_in_use_key_1_oldest) -{ - struct bt_keys *returned_key; - uint8_t id = BT_ADDR_ID_4; - bt_addr_le_t *addr = BT_ADDR_LE_4; - uint32_t expected_oldest_params_ref_idx; - - expected_oldest_params_ref_idx = 1; - oldest_params_vector = &testing_id_addr_pair_lut[expected_oldest_params_ref_idx]; - bt_unpair_fake.custom_fake = bt_unpair_custom_fake; - bt_conn_foreach_fake.custom_fake = bt_conn_foreach_key_slot_0_in_use_custom_fake; - - returned_key = bt_keys_get_addr(id, addr); - - zassert_true(returned_key != NULL, "bt_keys_get_addr() returned a NULL reference"); - zassert_true(returned_key == returned_keys_refs[expected_oldest_params_ref_idx], - "bt_keys_get_addr() returned reference doesn't match expected one"); -} - -/* - * Test adding extra (ID, Address) pair while the keys pool list is full when the oldest key slot - * is in use with a connection but others keys aren't. - * New (ID, address) pair should replace the oldest one that's not in use. - * - * Constraints: - * - Keys pool list is full - * - Key at slot 0 is used with a connection - * - oldest key (slot 2) isn't used with a connection - * - CONFIG_BT_KEYS_OVERWRITE_OLDEST is enabled - * - * Expected behaviour: - * - A valid pointer in the keys pool is returned, matching the one previously assigned to the - * oldest key (index 2). - */ -ZTEST(bt_keys_get_addr_full_list_overwrite_oldest, test_full_list_key_0_in_use_key_2_oldest) -{ - struct bt_keys *returned_key; - uint8_t id = BT_ADDR_ID_5; - bt_addr_le_t *addr = BT_ADDR_LE_5; - uint32_t expected_oldest_params_ref_idx; - -#if defined(CONFIG_BT_KEYS_OVERWRITE_OLDEST) - /* Normally first items inserted in the list are the oldest. - * For this particular test, we need to override that by setting - * the 'aging_counter' - */ - returned_keys_refs[1]->aging_counter = bt_keys_get_aging_counter_val(); -#endif - - expected_oldest_params_ref_idx = 2; - oldest_params_vector = &testing_id_addr_pair_lut[expected_oldest_params_ref_idx]; - bt_unpair_fake.custom_fake = bt_unpair_custom_fake; - bt_conn_foreach_fake.custom_fake = bt_conn_foreach_key_slot_0_in_use_custom_fake; - - returned_key = bt_keys_get_addr(id, addr); - - zassert_true(returned_key != NULL, "bt_keys_get_addr() returned a NULL reference"); - zassert_true(returned_key == returned_keys_refs[expected_oldest_params_ref_idx], - "bt_keys_get_addr() returned reference doesn't match expected one"); -} diff --git a/tests/bluetooth/host/keys/bt_keys_get_addr/testcase.yaml b/tests/bluetooth/host/keys/bt_keys_get_addr/testcase.yaml deleted file mode 100644 index ce14a0aa9076d..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_get_addr/testcase.yaml +++ /dev/null @@ -1,12 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_keys_get_addr.default: - type: unit - bluetooth.host.bt_keys_get_addr.keys_overwrite_oldest: - type: unit - extra_configs: - - CONFIG_BT_SMP=y - - CONFIG_BT_KEYS_OVERWRITE_OLDEST=y diff --git a/tests/bluetooth/host/keys/bt_keys_get_type/CMakeLists.txt b/tests/bluetooth/host/keys/bt_keys_get_type/CMakeLists.txt deleted file mode 100644 index ec1b6a84e625c..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_get_type/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -project(bt_keys_get_type) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/keys/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_get_type_invalid_inputs.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c - - # Unit under test - ${ZEPHYR_BASE}/subsys/bluetooth/host/keys.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c -) diff --git a/tests/bluetooth/host/keys/bt_keys_get_type/prj.conf b/tests/bluetooth/host/keys/bt_keys_get_type/prj.conf deleted file mode 100644 index b7101de0bf012..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_get_type/prj.conf +++ /dev/null @@ -1,10 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_MAX_PAIRED=7 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y - -CONFIG_LOG=n -CONFIG_TEST_LOGGING_DEFAULTS=n diff --git a/tests/bluetooth/host/keys/bt_keys_get_type/src/main.c b/tests/bluetooth/host/keys/bt_keys_get_type/src/main.c deleted file mode 100644 index c25310d3a8b0f..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_get_type/src/main.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "common/bt_str.h" - -#include "mocks/keys_help_utils.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include - -DEFINE_FFF_GLOBALS; - -/* This LUT contains different combinations of ID, Address and key type. - * Item in this list will be used to fill keys pool. - */ -static const struct id_addr_type testing_id_addr_type_lut[] = { - {BT_ADDR_ID_1, BT_ADDR_LE_1, BT_KEYS_PERIPH_LTK}, - {BT_ADDR_ID_1, BT_ADDR_LE_2, BT_KEYS_IRK}, - {BT_ADDR_ID_2, BT_ADDR_LE_1, BT_KEYS_LTK}, - {BT_ADDR_ID_2, BT_ADDR_LE_2, BT_KEYS_LOCAL_CSRK}, - {BT_ADDR_ID_3, BT_ADDR_LE_1, BT_KEYS_REMOTE_CSRK}, - {BT_ADDR_ID_3, BT_ADDR_LE_2, BT_KEYS_LTK_P256}, - {BT_ADDR_ID_4, BT_ADDR_LE_1, BT_KEYS_ALL}}; - -/* This list will hold returned references while filling keys pool */ -static struct bt_keys *returned_keys_refs[CONFIG_BT_MAX_PAIRED]; - -BUILD_ASSERT(ARRAY_SIZE(testing_id_addr_type_lut) == CONFIG_BT_MAX_PAIRED); -BUILD_ASSERT(ARRAY_SIZE(testing_id_addr_type_lut) == ARRAY_SIZE(returned_keys_refs)); - -static void *empty_list_ts_setup(void) -{ - clear_key_pool(); - - return NULL; -} - -ZTEST_SUITE(bt_keys_get_type_initially_empty_list, NULL, empty_list_ts_setup, NULL, NULL, NULL); - -static void *full_list_ts_setup(void) -{ - clear_key_pool(); - int rv = fill_key_pool_by_id_addr_type( - testing_id_addr_type_lut, ARRAY_SIZE(testing_id_addr_type_lut), returned_keys_refs); - - zassert_true(rv == 0, "Failed to fill keys pool list, error code %d", -rv); - - return NULL; -} - -ZTEST_SUITE(bt_keys_get_type_initially_filled_list, NULL, full_list_ts_setup, NULL, NULL, NULL); - -/* - * Test getting a non-existing key reference with type, ID and Address while the list isn't full. - * - * Constraints: - * - Keys pool list isn't full - * - ID and address pair used doesn't exist in the keys pool list - * - * Expected behaviour: - * - A key slot is reserved and data type, ID and Address are stored - * - A valid reference is returned by bt_keys_get_type() - * - ID value matches the one passed to bt_keys_get_type() - * - Address value matches the one passed to bt_keys_get_type() - * - Key type value matches the one passed to bt_keys_get_type() - */ -ZTEST(bt_keys_get_type_initially_empty_list, test_get_non_existing_key_reference) -{ - struct bt_keys *returned_key; - int type; - uint8_t id; - bt_addr_le_t *addr; - struct id_addr_type const *params_vector; - - for (size_t i = 0; i < ARRAY_SIZE(testing_id_addr_type_lut); i++) { - - params_vector = &testing_id_addr_type_lut[i]; - type = params_vector->type; - id = params_vector->id; - addr = params_vector->addr; - - returned_key = bt_keys_get_type(type, id, addr); - returned_keys_refs[i] = returned_key; - - zassert_true(returned_key != NULL, - "bt_keys_get_type() failed to add key %d to the keys pool", i); - zassert_true(returned_key->id == id, - "bt_keys_get_type() returned a reference with an incorrect ID"); - zassert_true(returned_key->keys == type, - "bt_keys_get_type() returned a reference with an incorrect key type"); - zassert_true(!bt_addr_le_cmp(&returned_key->addr, addr), - "bt_keys_get_type() returned incorrect address %s value, expected %s", - bt_addr_le_str(&returned_key->addr), bt_addr_le_str(addr)); - } -} - -/* - * Test getting a non-existing key reference with type, ID and Address while the list is full. - * - * Constraints: - * - Keys pool list is filled with items different from the ones used for testing - * - * Expected behaviour: - * - A NULL value is returned by bt_keys_get_type() - */ -ZTEST(bt_keys_get_type_initially_filled_list, test_get_non_existing_key_reference_full_list) -{ - struct bt_keys *returned_key; - int type = BT_KEYS_IRK; - uint8_t id = BT_ADDR_ID_5; - const bt_addr_le_t *addr = BT_ADDR_LE_5; - - returned_key = bt_keys_get_type(type, id, addr); - - zassert_true(returned_key == NULL, "bt_keys_get_type() returned a non-NULL reference"); -} - -/* - * Test getting an existing key reference with type, ID and Address while the list is full. - * - * Constraints: - * - Keys pool list is filled with the ID and address pairs used - * - * Expected behaviour: - * - A valid reference is returned by bt_keys_get_type() - * - Key reference returned matches the previously returned one - * when it was firstly inserted in the list - */ -ZTEST(bt_keys_get_type_initially_filled_list, test_get_existing_key_reference) -{ - struct bt_keys *returned_key, *expected_key_ref; - int type; - uint8_t id; - bt_addr_le_t *addr; - struct id_addr_type const *params_vector; - - for (size_t i = 0; i < ARRAY_SIZE(testing_id_addr_type_lut); i++) { - - params_vector = &testing_id_addr_type_lut[i]; - type = params_vector->type; - id = params_vector->id; - addr = params_vector->addr; - - returned_key = bt_keys_get_type(type, id, addr); - expected_key_ref = returned_keys_refs[i]; - - zassert_true(returned_key != NULL, - "bt_keys_get_type() failed to add key %d to the keys pool", i); - zassert_equal_ptr(returned_key, expected_key_ref, - "bt_keys_get_type() returned unexpected reference"); - } -} diff --git a/tests/bluetooth/host/keys/bt_keys_get_type/src/test_suite_get_type_invalid_inputs.c b/tests/bluetooth/host/keys/bt_keys_get_type/src/test_suite_get_type_invalid_inputs.c deleted file mode 100644 index 0e7ad17f1b555..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_get_type/src/test_suite_get_type_invalid_inputs.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" - -#include -#include - -#include - -ZTEST_SUITE(bt_keys_get_type_invalid_inputs, NULL, NULL, NULL, NULL, NULL); - -/* - * Test function with NULL address - * - * Constraints: - * - Any key type can be used - * - Any ID value can be used - * - Address is passed as NULL - * - * Expected behaviour: - * - An assertion fails and execution stops - */ -ZTEST(bt_keys_get_type_invalid_inputs, test_null_device_address) -{ - expect_assert(); - bt_keys_get_type(0x00, 0x00, NULL); -} diff --git a/tests/bluetooth/host/keys/bt_keys_get_type/testcase.yaml b/tests/bluetooth/host/keys/bt_keys_get_type/testcase.yaml deleted file mode 100644 index 21c6d73220c1c..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_get_type/testcase.yaml +++ /dev/null @@ -1,7 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_keys_get_type.default: - type: unit diff --git a/tests/bluetooth/host/keys/bt_keys_store/CMakeLists.txt b/tests/bluetooth/host/keys/bt_keys_store/CMakeLists.txt deleted file mode 100644 index 34704ffc3b165..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_store/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -project(bt_keys_store) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/keys/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_store_invalid_inputs.c - - # Unit under test - ${ZEPHYR_BASE}/subsys/bluetooth/host/keys.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c -) diff --git a/tests/bluetooth/host/keys/bt_keys_store/prj.conf b/tests/bluetooth/host/keys/bt_keys_store/prj.conf deleted file mode 100644 index 419fdcd6047df..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_store/prj.conf +++ /dev/null @@ -1,10 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_MAX_PAIRED=11 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y - -CONFIG_LOG=n -CONFIG_TEST_LOGGING_DEFAULTS=n diff --git a/tests/bluetooth/host/keys/bt_keys_store/src/main.c b/tests/bluetooth/host/keys/bt_keys_store/src/main.c deleted file mode 100644 index e4a5f4e1952e5..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_store/src/main.c +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/keys_help_utils.h" -#include "mocks/settings.h" -#include "mocks/settings_expects.h" -#include "mocks/settings_store.h" -#include "mocks/settings_store_expects.h" -#include "mocks/util.h" -#include "mocks/util_expects.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include - -DEFINE_FFF_GLOBALS; - -static void tc_setup(void *f) -{ - /* Clear keys pool */ - clear_key_pool(); - - /* Register resets */ - UTIL_FFF_FAKES_LIST(RESET_FAKE); - SETTINGS_FFF_FAKES_LIST(RESET_FAKE); - SETTINGS_STORE_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_SUITE(bt_keys_store_key_bt_settings_enabled, NULL, NULL, tc_setup, NULL, NULL); - -/* - * Store an existing key (ID = 0) and verify the result. - * bt_settings_store_keys() returns 0 which represents success. - * - * Constraints: - * - Key reference points to a valid item - * - Item ID is set to 0 - * - Return value from bt_settings_store_keys() is 0 - * - * Expected behaviour: - * - bt_keys_store() returns 0 which represent success - */ -ZTEST(bt_keys_store_key_bt_settings_enabled, test_id_equal_0_with_no_error) -{ - int returned_code; - struct bt_keys *returned_key; - uint8_t id = BT_ADDR_ID_0; - bt_addr_le_t *addr = BT_ADDR_LE_1; - - /* Add custom item to the keys pool */ - returned_key = bt_keys_get_addr(id, addr); - zassert_true(returned_key != NULL, "bt_keys_get_addr() returned a non-valid reference"); - - bt_settings_store_keys_fake.return_val = 0; - - /* Store the key */ - returned_code = bt_keys_store(returned_key); - - zassert_true(returned_code == 0, "bt_keys_store() returned a non-zero code"); - - expect_single_call_bt_settings_store_keys(returned_key->storage_start); -} - -/* - * Store an existing key (ID = 0) and verify the result. - * bt_settings_store_keys() returns a negative value of -1 which represents - * failure. - * - * Constraints: - * - Key reference points to a valid item - * - Item ID is set to 0 - * - Return value from bt_settings_store_keys() is -1 - * - * Expected behaviour: - * - bt_keys_store() returns a negative error code of -1 - */ -ZTEST(bt_keys_store_key_bt_settings_enabled, test_id_equal_0_with_error) -{ - int returned_code; - struct bt_keys *returned_key; - uint8_t id = BT_ADDR_ID_0; - bt_addr_le_t *addr = BT_ADDR_LE_1; - - /* Add custom item to the keys pool */ - returned_key = bt_keys_get_addr(id, addr); - zassert_true(returned_key != NULL, "bt_keys_get_addr() returned a non-valid reference"); - - bt_settings_store_keys_fake.return_val = -1; - - /* Store the key */ - returned_code = bt_keys_store(returned_key); - - zassert_true(returned_code == -1, "bt_keys_store() returned a non-zero code"); - - expect_single_call_bt_settings_store_keys(returned_key->storage_start); -} - -/* - * Store an existing key (ID != 0) and verify the result. - * bt_settings_store_keys() returns 0 which represents success. - * - * Constraints: - * - Key reference points to a valid item - * - Item ID isn't set to 0 - * - Return value from bt_settings_store_keys() is 0 - * - * Expected behaviour: - * - bt_keys_store() returns 0 which represent success - */ -ZTEST(bt_keys_store_key_bt_settings_enabled, test_id_not_equal_0_with_no_error) -{ - int returned_code; - struct bt_keys *returned_key; - uint8_t id = BT_ADDR_ID_1; - bt_addr_le_t *addr = BT_ADDR_LE_1; - - /* Add custom item to the keys pool */ - returned_key = bt_keys_get_addr(id, addr); - zassert_true(returned_key != NULL, "bt_keys_get_addr() returned a non-valid reference"); - - bt_settings_store_keys_fake.return_val = 0; - - /* Store the key */ - returned_code = bt_keys_store(returned_key); - - zassert_true(returned_code == 0, "bt_keys_store() returned a non-zero code"); - - expect_single_call_bt_settings_store_keys(returned_key->storage_start); -} - -/* - * Store an existing key (ID != 0) and verify the result - * bt_settings_store_keys() returns a negative value of -1 which represents - * failure. - * - * Constraints: - * - Key reference points to a valid item - * - Item ID isn't set to 0 - * - Return value from settings_save_one() is -1 - * - * Expected behaviour: - * - bt_keys_store() returns a negative error code of -1 - */ -ZTEST(bt_keys_store_key_bt_settings_enabled, test_id_not_equal_0_with_error) -{ - int returned_code; - struct bt_keys *returned_key; - uint8_t id = BT_ADDR_ID_1; - bt_addr_le_t *addr = BT_ADDR_LE_1; - - /* Add custom item to the keys pool */ - returned_key = bt_keys_get_addr(id, addr); - zassert_true(returned_key != NULL, "bt_keys_get_addr() returned a non-valid reference"); - - bt_settings_store_keys_fake.return_val = -1; - - /* Store the key */ - returned_code = bt_keys_store(returned_key); - - zassert_true(returned_code == -1, "bt_keys_store() returned a non-zero code"); - - expect_single_call_bt_settings_store_keys(returned_key->storage_start); -} diff --git a/tests/bluetooth/host/keys/bt_keys_store/src/test_suite_store_invalid_inputs.c b/tests/bluetooth/host/keys/bt_keys_store/src/test_suite_store_invalid_inputs.c deleted file mode 100644 index 399ba4af85205..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_store/src/test_suite_store_invalid_inputs.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" - -#include -#include - -#include - -ZTEST_SUITE(bt_keys_store_invalid_inputs, NULL, NULL, NULL, NULL, NULL); - -/* - * Test function with NULL key reference - * - * Constraints: - * - Key reference is passed as NULL - * - * Expected behaviour: - * - An assertion fails and execution stops - */ -ZTEST(bt_keys_store_invalid_inputs, test_null_key_reference) -{ - expect_assert(); - bt_keys_store(NULL); -} diff --git a/tests/bluetooth/host/keys/bt_keys_store/testcase.yaml b/tests/bluetooth/host/keys/bt_keys_store/testcase.yaml deleted file mode 100644 index 85aeece3b370c..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_store/testcase.yaml +++ /dev/null @@ -1,10 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_keys_store.default: - type: unit - extra_configs: - - CONFIG_SETTINGS=y - - CONFIG_BT_SETTINGS=y diff --git a/tests/bluetooth/host/keys/bt_keys_update_usage/CMakeLists.txt b/tests/bluetooth/host/keys/bt_keys_update_usage/CMakeLists.txt deleted file mode 100644 index da19d1217ff0b..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_update_usage/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -project(bt_keys_update_usage) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/keys/mocks mocks) - -target_link_libraries(testbinary PRIVATE mocks host_mocks) - -target_sources(testbinary - PRIVATE - src/main.c - src/test_suite_save_aging_counter.c - src/test_suite_update_usage_invalid_inputs.c - - # Unit under test - ${ZEPHYR_BASE}/subsys/bluetooth/host/keys.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c -) diff --git a/tests/bluetooth/host/keys/bt_keys_update_usage/prj.conf b/tests/bluetooth/host/keys/bt_keys_update_usage/prj.conf deleted file mode 100644 index 419fdcd6047df..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_update_usage/prj.conf +++ /dev/null @@ -1,10 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_MAX_PAIRED=11 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y - -CONFIG_LOG=n -CONFIG_TEST_LOGGING_DEFAULTS=n diff --git a/tests/bluetooth/host/keys/bt_keys_update_usage/src/main.c b/tests/bluetooth/host/keys/bt_keys_update_usage/src/main.c deleted file mode 100644 index 0e38719b2b6af..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_update_usage/src/main.c +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/keys_help_utils.h" -#include "mocks/settings_store_expects.h" -#include "testing_common_defs.h" - -#include -#include -#include - -#include - -DEFINE_FFF_GLOBALS; - -/* This LUT contains different combinations of ID, Address and key type. - * Item in this list will be used to fill keys pool. - */ -const struct id_addr_pair testing_id_addr_pair_lut[] = { - - {BT_ADDR_ID_1, BT_ADDR_LE_1}, {BT_ADDR_ID_1, BT_RPA_ADDR_LE_1}, - {BT_ADDR_ID_1, BT_RPA_ADDR_LE_2}, {BT_ADDR_ID_1, BT_ADDR_LE_3}, - - {BT_ADDR_ID_2, BT_ADDR_LE_1}, {BT_ADDR_ID_2, BT_RPA_ADDR_LE_2}, - {BT_ADDR_ID_2, BT_RPA_ADDR_LE_3}, {BT_ADDR_ID_2, BT_ADDR_LE_2}, - - {BT_ADDR_ID_3, BT_ADDR_LE_1}, {BT_ADDR_ID_3, BT_ADDR_LE_2}, - - {BT_ADDR_ID_4, BT_ADDR_LE_1}}; - -/* This list will hold returned references while filling keys pool */ -struct bt_keys *returned_keys_refs[CONFIG_BT_MAX_PAIRED]; - -/* Holds the last key reference updated */ -static struct bt_keys *last_keys_updated; - -BUILD_ASSERT(ARRAY_SIZE(testing_id_addr_pair_lut) == CONFIG_BT_MAX_PAIRED); -BUILD_ASSERT(ARRAY_SIZE(testing_id_addr_pair_lut) == ARRAY_SIZE(returned_keys_refs)); - -static void tc_setup(void *f) -{ - clear_key_pool(); - int rv = fill_key_pool_by_id_addr(testing_id_addr_pair_lut, - ARRAY_SIZE(testing_id_addr_pair_lut), returned_keys_refs); - - zassert_true(rv == 0, "Failed to fill keys pool list, error code %d", -rv); - - last_keys_updated = returned_keys_refs[CONFIG_BT_MAX_PAIRED - 1]; -} - -ZTEST_SUITE(bt_keys_update_usage_overwrite_oldest_enabled, NULL, NULL, tc_setup, NULL, NULL); - -/* - * Request updating non-existing item in the keys pool list - * - * Constraints: - * - Keys pool list is filled with items that are different from the testing ID and address pair - * used - * - * Expected behaviour: - * - Last updated key reference isn't changed - */ -ZTEST(bt_keys_update_usage_overwrite_oldest_enabled, test_update_non_existing_key) -{ - uint8_t id = BT_ADDR_ID_5; - bt_addr_le_t *addr = BT_ADDR_LE_5; - - bt_keys_update_usage(id, addr); - - zassert_equal_ptr(bt_keys_get_last_keys_updated(), last_keys_updated, - "bt_keys_update_usage() changed last updated key reference unexpectedly"); -} - -/* - * Request updating the latest key reference - * - * Constraints: - * - Keys pool list is filled with items - * - ID and address pair used are the last added pair to the list - * - * Expected behaviour: - * - Last updated key reference isn't changed - */ -ZTEST(bt_keys_update_usage_overwrite_oldest_enabled, test_update_latest_reference) -{ - uint8_t id = testing_id_addr_pair_lut[CONFIG_BT_MAX_PAIRED - 1].id; - bt_addr_le_t *addr = testing_id_addr_pair_lut[CONFIG_BT_MAX_PAIRED - 1].addr; - - bt_keys_update_usage(id, addr); - - zassert_equal_ptr(bt_keys_get_last_keys_updated(), last_keys_updated, - "bt_keys_update_usage() changed last updated key reference unexpectedly"); -} - -/* - * Request updating existing items aging counter - * - * Constraints: - * - Keys pool list is filled with items - * - ID and address used exist in the keys pool list - * - CONFIG_BT_KEYS_SAVE_AGING_COUNTER_ON_PAIRING isn't enabled - * - * Expected behaviour: - * - Last updated key reference matches the last updated key reference - */ -ZTEST(bt_keys_update_usage_overwrite_oldest_enabled, test_update_non_latest_reference) -{ - uint8_t id; - uint32_t old_aging_counter; - bt_addr_le_t *addr; - struct bt_keys *expected_updated_keys; - struct id_addr_pair const *params_vector; - - if (IS_ENABLED(CONFIG_BT_KEYS_SAVE_AGING_COUNTER_ON_PAIRING)) { - ztest_test_skip(); - } - - for (size_t it = 0; it < ARRAY_SIZE(testing_id_addr_pair_lut); it++) { - params_vector = &testing_id_addr_pair_lut[it]; - id = params_vector->id; - addr = params_vector->addr; - expected_updated_keys = returned_keys_refs[it]; - old_aging_counter = expected_updated_keys->aging_counter; - - bt_keys_update_usage(id, addr); - - zassert_true(expected_updated_keys->aging_counter > (old_aging_counter), - "bt_keys_update_usage() set incorrect aging counter"); - - zassert_equal_ptr( - bt_keys_get_last_keys_updated(), expected_updated_keys, - "bt_keys_update_usage() changed last updated key reference unexpectedly"); - - expect_not_called_bt_settings_store_keys(); - } -} diff --git a/tests/bluetooth/host/keys/bt_keys_update_usage/src/test_suite_save_aging_counter.c b/tests/bluetooth/host/keys/bt_keys_update_usage/src/test_suite_save_aging_counter.c deleted file mode 100644 index bfe1486790bad..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_update_usage/src/test_suite_save_aging_counter.c +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/keys_help_utils.h" -#include "mocks/settings_store.h" -#include "mocks/settings_store_expects.h" -#include "testing_common_defs.h" - -#include -#include - -#include - -/* This LUT contains different combinations of ID and Address pairs. - * It is defined in main.c. - */ -extern const struct id_addr_pair testing_id_addr_pair_lut[CONFIG_BT_MAX_PAIRED]; - -/* This list holds returned references while filling keys pool. - * It is defined in main.c. - */ -extern struct bt_keys *returned_keys_refs[CONFIG_BT_MAX_PAIRED]; - -static void tc_setup(void *f) -{ - Z_TEST_SKIP_IFNDEF(CONFIG_BT_KEYS_SAVE_AGING_COUNTER_ON_PAIRING); - - clear_key_pool(); - int rv = fill_key_pool_by_id_addr(testing_id_addr_pair_lut, - ARRAY_SIZE(testing_id_addr_pair_lut), returned_keys_refs); - - zassert_true(rv == 0, "Failed to fill keys pool list, error code %d", -rv); -} - -ZTEST_SUITE(bt_keys_update_usage_save_aging_counter, NULL, NULL, tc_setup, NULL, NULL); - -/* - * Request updating existing items aging counter - * - * Constraints: - * - Keys pool list is filled with items - * - ID and address used exist in the keys pool list - * - CONFIG_BT_KEYS_SAVE_AGING_COUNTER_ON_PAIRING is enabled - * - * Expected behaviour: - * - Last updated key reference matches the last updated key reference - * - bt_keys_store() is called once with the correct parameters - */ -ZTEST(bt_keys_update_usage_save_aging_counter, test_update_usage_and_save_aging_counter) -{ - uint8_t id; - uint32_t old_aging_counter; - bt_addr_le_t *addr; - struct bt_keys *expected_updated_keys; - struct id_addr_pair const *params_vector; - - for (size_t it = 0; it < ARRAY_SIZE(testing_id_addr_pair_lut); it++) { - params_vector = &testing_id_addr_pair_lut[it]; - id = params_vector->id; - addr = params_vector->addr; - expected_updated_keys = returned_keys_refs[it]; - old_aging_counter = expected_updated_keys->aging_counter; - - /* Reset fake functions call counter */ - SETTINGS_STORE_FFF_FAKES_LIST(RESET_FAKE); - - bt_keys_update_usage(id, addr); - - zassert_true(expected_updated_keys->aging_counter > (old_aging_counter), - "bt_keys_update_usage() set incorrect aging counter"); - - zassert_equal_ptr( - bt_keys_get_last_keys_updated(), expected_updated_keys, - "bt_keys_update_usage() changed last updated key reference unexpectedly"); - - /* Check if bt_keys_store() was called */ - expect_single_call_bt_settings_store_keys(expected_updated_keys->storage_start); - } -} diff --git a/tests/bluetooth/host/keys/bt_keys_update_usage/src/test_suite_update_usage_invalid_inputs.c b/tests/bluetooth/host/keys/bt_keys_update_usage/src/test_suite_update_usage_invalid_inputs.c deleted file mode 100644 index 5776f83a464cb..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_update_usage/src/test_suite_update_usage_invalid_inputs.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" - -#include -#include - -#include - -ZTEST_SUITE(bt_keys_update_usage_invalid_inputs, NULL, NULL, NULL, NULL, NULL); - -/* - * Test function with NULL address - * - * Constraints: - * - Any ID value can be used - * - Address is passed as NULL - * - * Expected behaviour: - * - An assertion fails and execution stops - */ -ZTEST(bt_keys_update_usage_invalid_inputs, test_null_device_address) -{ - expect_assert(); - bt_keys_update_usage(0x00, NULL); -} diff --git a/tests/bluetooth/host/keys/bt_keys_update_usage/testcase.yaml b/tests/bluetooth/host/keys/bt_keys_update_usage/testcase.yaml deleted file mode 100644 index df9697629c54d..0000000000000 --- a/tests/bluetooth/host/keys/bt_keys_update_usage/testcase.yaml +++ /dev/null @@ -1,18 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.bt_keys_update_usage.default: - type: unit - extra_configs: - - CONFIG_BT_SMP=y - - CONFIG_BT_KEYS_OVERWRITE_OLDEST=y - bluetooth.host.bt_keys_update_usage.save_aging_counter: - type: unit - extra_configs: - - CONFIG_SETTINGS=y - - CONFIG_BT_SETTINGS=y - - CONFIG_BT_SMP=y - - CONFIG_BT_KEYS_OVERWRITE_OLDEST=y - - CONFIG_BT_KEYS_SAVE_AGING_COUNTER_ON_PAIRING=y diff --git a/tests/bluetooth/host/keys/mocks/CMakeLists.txt b/tests/bluetooth/host/keys/mocks/CMakeLists.txt deleted file mode 100644 index a5834b0ef73b3..0000000000000 --- a/tests/bluetooth/host/keys/mocks/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -# -# CMakeLists.txt file for creating of mocks library. -# - -add_library(mocks STATIC - id.c - id_expects.c - rpa.c - conn.c - hci_core.c - hci_core_expects.c - keys_help_utils.c - util.c - util_expects.c - settings.c - settings_store.c - settings_expects.c - settings_store_expects.c -) - -target_include_directories(mocks PUBLIC - .. - ${ZEPHYR_BASE}/tests/bluetooth/host - ${ZEPHYR_BASE}/subsys/bluetooth - ${ZEPHYR_BASE}/subsys/bluetooth/host -) - -target_link_libraries(mocks PRIVATE test_interface) diff --git a/tests/bluetooth/host/keys/mocks/conn.c b/tests/bluetooth/host/keys/mocks/conn.c deleted file mode 100644 index 0045f3b787fe6..0000000000000 --- a/tests/bluetooth/host/keys/mocks/conn.c +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "mocks/conn.h" - -DEFINE_FAKE_VOID_FUNC(bt_conn_foreach, enum bt_conn_type, bt_conn_foreach_cb, void *); -DEFINE_FAKE_VALUE_FUNC(const bt_addr_le_t *, bt_conn_get_dst, const struct bt_conn *); diff --git a/tests/bluetooth/host/keys/mocks/conn.h b/tests/bluetooth/host/keys/mocks/conn.h deleted file mode 100644 index 98ef8cc1e3d74..0000000000000 --- a/tests/bluetooth/host/keys/mocks/conn.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include - -typedef void (*bt_conn_foreach_cb) (struct bt_conn *conn, void *data); - -/* List of fakes used by this unit tester */ -#define CONN_FFF_FAKES_LIST(FAKE) \ - FAKE(bt_conn_foreach) \ - FAKE(bt_conn_get_dst) \ - -DECLARE_FAKE_VOID_FUNC(bt_conn_foreach, enum bt_conn_type, bt_conn_foreach_cb, void *); -DECLARE_FAKE_VALUE_FUNC(const bt_addr_le_t *, bt_conn_get_dst, const struct bt_conn *); diff --git a/tests/bluetooth/host/keys/mocks/hci_core.c b/tests/bluetooth/host/keys/mocks/hci_core.c deleted file mode 100644 index d469c02cef2f5..0000000000000 --- a/tests/bluetooth/host/keys/mocks/hci_core.c +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "mocks/hci_core.h" - -DEFINE_FAKE_VALUE_FUNC(int, bt_unpair, uint8_t, const bt_addr_le_t *); -DEFINE_FAKE_VOID_FUNC(bt_id_add, struct bt_keys *); diff --git a/tests/bluetooth/host/keys/mocks/hci_core.h b/tests/bluetooth/host/keys/mocks/hci_core.h deleted file mode 100644 index cd8f33491ed2a..0000000000000 --- a/tests/bluetooth/host/keys/mocks/hci_core.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -/* List of fakes used by this unit tester */ -#define HCI_CORE_FFF_FAKES_LIST(FAKE) \ - FAKE(bt_unpair) \ - FAKE(bt_id_add) \ - -DECLARE_FAKE_VALUE_FUNC(int, bt_unpair, uint8_t, const bt_addr_le_t *); -DECLARE_FAKE_VOID_FUNC(bt_id_add, struct bt_keys *); diff --git a/tests/bluetooth/host/keys/mocks/hci_core_expects.c b/tests/bluetooth/host/keys/mocks/hci_core_expects.c deleted file mode 100644 index eb897cb6d52cb..0000000000000 --- a/tests/bluetooth/host/keys/mocks/hci_core_expects.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include "mocks/hci_core.h" -#include "mocks/hci_core_expects.h" - -void expect_single_call_bt_unpair(uint8_t id, const bt_addr_le_t *addr) -{ - const char *func_name = "bt_unpair"; - - zassert_equal(bt_unpair_fake.call_count, 1, "'%s()' was called more than once", - func_name); - - zassert_equal(bt_unpair_fake.arg0_val, id, - "'%s()' was called with incorrect '%s' value", func_name, "id"); - zassert_mem_equal(bt_unpair_fake.arg1_val, addr, sizeof(bt_addr_le_t), - "'%s()' was called with incorrect '%s' value", func_name, "addr"); -} - -void expect_not_called_bt_unpair(void) -{ - const char *func_name = "bt_unpair"; - - zassert_equal(bt_unpair_fake.call_count, 0, "'%s()' was called unexpectedly", - func_name); -} diff --git a/tests/bluetooth/host/keys/mocks/hci_core_expects.h b/tests/bluetooth/host/keys/mocks/hci_core_expects.h deleted file mode 100644 index 67fb380afc969..0000000000000 --- a/tests/bluetooth/host/keys/mocks/hci_core_expects.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -/* - * Validate expected behaviour when bt_unpair() is called - * - * Expected behaviour: - * - bt_unpair() to be called once with correct parameters - */ -void expect_single_call_bt_unpair(uint8_t id, const bt_addr_le_t *addr); - -/* - * Validate expected behaviour when bt_unpair() isn't called - * - * Expected behaviour: - * - bt_unpair() isn't called at all - */ -void expect_not_called_bt_unpair(void); diff --git a/tests/bluetooth/host/keys/mocks/id.c b/tests/bluetooth/host/keys/mocks/id.c deleted file mode 100644 index e48adefb9fb6e..0000000000000 --- a/tests/bluetooth/host/keys/mocks/id.c +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "mocks/id.h" - -DEFINE_FAKE_VOID_FUNC(bt_id_del, struct bt_keys *); -DEFINE_FAKE_VOID_FUNC(bt_id_pending_keys_update); -DEFINE_FAKE_VOID_FUNC(bt_id_pending_keys_update_set, struct bt_keys *, uint8_t); -DEFINE_FAKE_VALUE_FUNC(int, k_work_submit, struct k_work *); diff --git a/tests/bluetooth/host/keys/mocks/id.h b/tests/bluetooth/host/keys/mocks/id.h deleted file mode 100644 index 3efe45384f7d9..0000000000000 --- a/tests/bluetooth/host/keys/mocks/id.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include - -/* List of fakes used by this unit tester */ -#define ID_FFF_FAKES_LIST(FAKE) \ - FAKE(bt_id_del) \ - FAKE(bt_id_pending_keys_update) \ - FAKE(bt_id_pending_keys_update_set) \ - FAKE(k_work_submit) - -DECLARE_FAKE_VOID_FUNC(bt_id_del, struct bt_keys *); -DECLARE_FAKE_VOID_FUNC(bt_id_pending_keys_update); -DECLARE_FAKE_VOID_FUNC(bt_id_pending_keys_update_set, struct bt_keys *, uint8_t); -DECLARE_FAKE_VALUE_FUNC(int, k_work_submit, struct k_work *); diff --git a/tests/bluetooth/host/keys/mocks/id_expects.c b/tests/bluetooth/host/keys/mocks/id_expects.c deleted file mode 100644 index 17414786ec98d..0000000000000 --- a/tests/bluetooth/host/keys/mocks/id_expects.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include "mocks/id.h" -#include "mocks/id_expects.h" - -void expect_single_call_bt_id_del(struct bt_keys *keys) -{ - const char *func_name = "bt_id_del"; - - zassert_equal(bt_id_del_fake.call_count, 1, "'%s()' was called more than once", - func_name); - - zassert_equal(bt_id_del_fake.arg0_val, keys, - "'%s()' was called with incorrect '%s' value", func_name, "keys"); -} - -void expect_not_called_bt_id_del(void) -{ - const char *func_name = "bt_id_del"; - - zassert_equal(bt_id_del_fake.call_count, 0, "'%s()' was called unexpectedly", - func_name); -} diff --git a/tests/bluetooth/host/keys/mocks/id_expects.h b/tests/bluetooth/host/keys/mocks/id_expects.h deleted file mode 100644 index 44c769f0dc933..0000000000000 --- a/tests/bluetooth/host/keys/mocks/id_expects.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -/* - * Validate expected behaviour when bt_id_del() is called - * - * Expected behaviour: - * - bt_id_del() to be called once with correct parameters - */ -void expect_single_call_bt_id_del(struct bt_keys *keys); - -/* - * Validate expected behaviour when bt_id_del() isn't called - * - * Expected behaviour: - * - bt_id_del() isn't called at all - */ -void expect_not_called_bt_id_del(void); diff --git a/tests/bluetooth/host/keys/mocks/keys_help_utils.c b/tests/bluetooth/host/keys/mocks/keys_help_utils.c deleted file mode 100644 index 58709f5815732..0000000000000 --- a/tests/bluetooth/host/keys/mocks/keys_help_utils.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include "keys_help_utils.h" - -void clear_key_pool(void) -{ - struct bt_keys *key_pool; - - key_pool = bt_keys_get_key_pool(); - memset(key_pool, 0x00, sizeof(struct bt_keys) * CONFIG_BT_MAX_PAIRED); -} - -int fill_key_pool_by_id_addr(const struct id_addr_pair src[], int size, struct bt_keys *refs[]) -{ - uint8_t id; - bt_addr_le_t *addr; - struct id_addr_pair const *params_vector; - - if (!check_key_pool_is_empty()) { - printk("'%s' Error ! Keys pool isn't empty\n", __func__); - return -ENOSR; - } - - for (size_t it = 0; it < size; it++) { - params_vector = &src[it]; - id = params_vector->id; - addr = params_vector->addr; - refs[it] = bt_keys_get_addr(id, addr); - if (refs[it] == NULL) { - printk("'%s' Failed to add key %d to the keys pool\n", __func__, it); - return -ENOBUFS; - } - } - - return 0; -} - -int fill_key_pool_by_id_addr_type(const struct id_addr_type src[], int size, struct bt_keys *refs[]) -{ - int type; - uint8_t id; - bt_addr_le_t *addr; - struct id_addr_type const *params_vector; - - if (!check_key_pool_is_empty()) { - printk("'%s' Error ! Keys pool isn't empty\n", __func__); - return -ENOSR; - } - - for (size_t it = 0; it < size; it++) { - params_vector = &src[it]; - type = params_vector->type; - id = params_vector->id; - addr = params_vector->addr; - refs[it] = bt_keys_get_type(type, id, addr); - if (refs[it] == NULL) { - printk("'%s' Failed to add key %d to the keys pool\n", __func__, it); - return -ENOBUFS; - } - } - - return 0; -} - -bool check_key_pool_is_empty(void) -{ - int i; - struct bt_keys *keys, *key_pool; - - key_pool = bt_keys_get_key_pool(); - for (i = 0; i < CONFIG_BT_MAX_PAIRED; i++) { - keys = &key_pool[i]; - if (bt_addr_le_cmp(&keys->addr, BT_ADDR_LE_ANY)) { - return false; - } - } - - return true; -} diff --git a/tests/bluetooth/host/keys/mocks/keys_help_utils.h b/tests/bluetooth/host/keys/mocks/keys_help_utils.h deleted file mode 100644 index a04ba0bc89d30..0000000000000 --- a/tests/bluetooth/host/keys/mocks/keys_help_utils.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -/* BT (ID, Address) pair */ -struct id_addr_pair { - uint8_t id; /* ID */ - bt_addr_le_t *addr; /* Pointer to the address */ -}; - -/* BT Key (ID, Address, type) info */ -struct id_addr_type { - uint8_t id; /* ID */ - bt_addr_le_t *addr; /* Pointer to the address */ - int type; /* Key type */ -}; - -/* keys.c declarations */ -struct bt_keys *bt_keys_get_key_pool(void); -#if defined(CONFIG_BT_KEYS_OVERWRITE_OLDEST) -uint32_t bt_keys_get_aging_counter_val(void); -struct bt_keys *bt_keys_get_last_keys_updated(void); -#endif - -/* keys_help_utils.c declarations */ -void clear_key_pool(void); -int fill_key_pool_by_id_addr(const struct id_addr_pair src[], int size, struct bt_keys *refs[]); -int fill_key_pool_by_id_addr_type(const struct id_addr_type src[], int size, - struct bt_keys *refs[]); -bool check_key_pool_is_empty(void); diff --git a/tests/bluetooth/host/keys/mocks/rpa.c b/tests/bluetooth/host/keys/mocks/rpa.c deleted file mode 100644 index 1b2356c8f3df0..0000000000000 --- a/tests/bluetooth/host/keys/mocks/rpa.c +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "mocks/rpa.h" - -DEFINE_FAKE_VALUE_FUNC(bool, bt_rpa_irk_matches, const uint8_t *, const bt_addr_t *); diff --git a/tests/bluetooth/host/keys/mocks/rpa.h b/tests/bluetooth/host/keys/mocks/rpa.h deleted file mode 100644 index 7349d83496162..0000000000000 --- a/tests/bluetooth/host/keys/mocks/rpa.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -/* List of fakes used by this unit tester */ -#define RPA_FFF_FAKES_LIST(FAKE) \ - FAKE(bt_rpa_irk_matches) \ - -DECLARE_FAKE_VALUE_FUNC(bool, bt_rpa_irk_matches, const uint8_t *, const bt_addr_t *); diff --git a/tests/bluetooth/host/keys/mocks/settings.c b/tests/bluetooth/host/keys/mocks/settings.c deleted file mode 100644 index 1faaaf50f6db5..0000000000000 --- a/tests/bluetooth/host/keys/mocks/settings.c +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "mocks/settings.h" - -DEFINE_FAKE_VOID_FUNC(bt_settings_encode_key, char *, size_t, const char *, - const bt_addr_le_t *, const char *); -DEFINE_FAKE_VALUE_FUNC(int, bt_settings_decode_key, const char *, bt_addr_le_t *); -DEFINE_FAKE_VALUE_FUNC(int, settings_name_next, const char *, const char **); diff --git a/tests/bluetooth/host/keys/mocks/settings.h b/tests/bluetooth/host/keys/mocks/settings.h deleted file mode 100644 index ce765f7f50912..0000000000000 --- a/tests/bluetooth/host/keys/mocks/settings.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -/* List of fakes used by this unit tester */ -#define SETTINGS_FFF_FAKES_LIST(FAKE) \ - FAKE(bt_settings_encode_key) \ - FAKE(bt_settings_decode_key) \ - FAKE(settings_name_next) \ - -DECLARE_FAKE_VOID_FUNC(bt_settings_encode_key, char *, size_t, const char *, - const bt_addr_le_t *, const char *); -DECLARE_FAKE_VALUE_FUNC(int, bt_settings_decode_key, const char *, bt_addr_le_t *); -DECLARE_FAKE_VALUE_FUNC(int, settings_name_next, const char *, const char **); diff --git a/tests/bluetooth/host/keys/mocks/settings_expects.c b/tests/bluetooth/host/keys/mocks/settings_expects.c deleted file mode 100644 index f69b466b657d8..0000000000000 --- a/tests/bluetooth/host/keys/mocks/settings_expects.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include "mocks/settings.h" -#include "mocks/settings_expects.h" - -void expect_single_call_bt_settings_encode_key_with_not_null_key(const bt_addr_le_t *addr) -{ - const char *func_name = "bt_settings_encode_key"; - - zassert_equal(bt_settings_encode_key_fake.call_count, 1, "'%s()' was called more than once", - func_name); - zassert_not_null(bt_settings_encode_key_fake.arg0_val, - "'%s()' was called with incorrect '%s' value", func_name, "path"); - zassert_true(bt_settings_encode_key_fake.arg1_val != 0, - "'%s()' was called with incorrect '%s' value", func_name, "path_size"); - zassert_not_null(bt_settings_encode_key_fake.arg2_val, - "'%s()' was called with incorrect '%s' value", func_name, "subsys"); - zassert_equal_ptr(bt_settings_encode_key_fake.arg3_val, addr, - "'%s()' was called with incorrect '%s' value", func_name, "addr"); - zassert_not_null(bt_settings_encode_key_fake.arg4_val, - "'%s()' was called with incorrect '%s' value", func_name, "key"); -} - -void expect_single_call_bt_settings_encode_key_with_null_key(const bt_addr_le_t *addr) -{ - const char *func_name = "bt_settings_encode_key"; - - zassert_equal(bt_settings_encode_key_fake.call_count, 1, - "'%s()' was called more than once (%d)", func_name, - bt_settings_encode_key_fake.call_count); - zassert_not_null(bt_settings_encode_key_fake.arg0_val, - "'%s()' was called with incorrect '%s' value", func_name, "path"); - zassert_true(bt_settings_encode_key_fake.arg1_val != 0, - "'%s()' was called with incorrect '%s' value", func_name, "path_size"); - zassert_not_null(bt_settings_encode_key_fake.arg2_val, - "'%s()' was called with incorrect '%s' value", func_name, "subsys"); - zassert_equal_ptr(bt_settings_encode_key_fake.arg3_val, addr, - "'%s()' was called with incorrect '%s' value", func_name, "addr"); - zassert_equal_ptr(bt_settings_encode_key_fake.arg4_val, NULL, - "'%s()' was called with incorrect '%s' value", func_name, "key"); -} - -void expect_not_called_bt_settings_encode_key(void) -{ - const char *func_name = "bt_settings_encode_key"; - - zassert_equal(bt_settings_encode_key_fake.call_count, 0, "'%s()' was called unexpectedly", - func_name); -} diff --git a/tests/bluetooth/host/keys/mocks/settings_expects.h b/tests/bluetooth/host/keys/mocks/settings_expects.h deleted file mode 100644 index 17f391aef48d9..0000000000000 --- a/tests/bluetooth/host/keys/mocks/settings_expects.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -/* - * Validate expected behaviour when bt_settings_encode_key() is called - * - * Expected behaviour: - * - bt_settings_encode_key() to be called once with correct parameters - * - 'Keys' argument isn't NULL - */ -void expect_single_call_bt_settings_encode_key_with_not_null_key(const bt_addr_le_t *addr); - -/* - * Validate expected behaviour when bt_settings_encode_key() is called - * - * Expected behaviour: - * - bt_settings_encode_key() to be called once with correct parameters - * - 'Keys' argument is NULL - */ -void expect_single_call_bt_settings_encode_key_with_null_key(const bt_addr_le_t *addr); - -/* - * Validate expected behaviour when bt_settings_encode_key() isn't called - * - * Expected behaviour: - * - bt_settings_encode_key() isn't called at all - */ -void expect_not_called_bt_settings_encode_key(void); diff --git a/tests/bluetooth/host/keys/mocks/settings_store.c b/tests/bluetooth/host/keys/mocks/settings_store.c deleted file mode 100644 index b38a0a9cc3cda..0000000000000 --- a/tests/bluetooth/host/keys/mocks/settings_store.c +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "mocks/settings_store.h" - -DEFINE_FAKE_VALUE_FUNC(int, bt_settings_store_keys, uint8_t, struct bt_addr_le_t *, const void *, - size_t); -DEFINE_FAKE_VALUE_FUNC(int, bt_settings_delete_keys, uint8_t, struct bt_addr_le_t *); diff --git a/tests/bluetooth/host/keys/mocks/settings_store.h b/tests/bluetooth/host/keys/mocks/settings_store.h deleted file mode 100644 index 2049b36ce24ad..0000000000000 --- a/tests/bluetooth/host/keys/mocks/settings_store.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -/* List of fakes used by this unit tester */ -#define SETTINGS_STORE_FFF_FAKES_LIST(FAKE) \ - FAKE(bt_settings_store_keys) \ - FAKE(bt_settings_delete_keys) - -DECLARE_FAKE_VALUE_FUNC(int, bt_settings_store_keys, uint8_t, struct bt_addr_le_t *, const void *, - size_t); -DECLARE_FAKE_VALUE_FUNC(int, bt_settings_delete_keys, uint8_t, struct bt_addr_le_t *); diff --git a/tests/bluetooth/host/keys/mocks/settings_store_expects.c b/tests/bluetooth/host/keys/mocks/settings_store_expects.c deleted file mode 100644 index c4eb4204f22f4..0000000000000 --- a/tests/bluetooth/host/keys/mocks/settings_store_expects.c +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include "mocks/settings_store.h" -#include "mocks/settings_store_expects.h" - -void expect_single_call_bt_settings_delete_keys(void) -{ - const char *func_name = "bt_settings_delete_keys"; - - zassert_equal(bt_settings_delete_keys_fake.call_count, 1, - "'%s()' was called more than once", func_name); -} - -void expect_single_call_bt_settings_store_keys(const void *value) -{ - const char *func_name = "bt_settings_store_keys"; - - zassert_equal(bt_settings_store_keys_fake.call_count, 1, "'%s()' was called more than once", - func_name); - - zassert_equal(bt_settings_store_keys_fake.arg2_val, value, - "'%s()' was called with incorrect '%s' value", func_name, "value"); - zassert_equal(bt_settings_store_keys_fake.arg3_val, BT_KEYS_STORAGE_LEN, - "'%s()' was called with incorrect '%s' value", func_name, "val_len"); -} - -void expect_not_called_bt_settings_store_keys(void) -{ - const char *func_name = "bt_settings_store_keys"; - - zassert_equal(bt_settings_store_keys_fake.call_count, 0, "'%s()' was called unexpectedly", - func_name); -} diff --git a/tests/bluetooth/host/keys/mocks/settings_store_expects.h b/tests/bluetooth/host/keys/mocks/settings_store_expects.h deleted file mode 100644 index 2cd2035b1f026..0000000000000 --- a/tests/bluetooth/host/keys/mocks/settings_store_expects.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -/* - * Validate expected behaviour when bt_settings_delete_keys() is called - * - * Expected behaviour: - * - bt_settings_delete_keys() to be called once with correct parameters - */ -void expect_single_call_bt_settings_delete_keys(void); - -/* - * Validate expected behaviour when bt_settings_store_keys() is called - * - * Expected behaviour: - * - bt_settings_store_keys() to be called once with correct parameters - */ -void expect_single_call_bt_settings_store_keys(const void *value); - -/* - * Validate expected behaviour when bt_settings_store_keys() isn't called - * - * Expected behaviour: - * - bt_settings_store_keys() isn't called at all - */ -void expect_not_called_bt_settings_store_keys(void); diff --git a/tests/bluetooth/host/keys/mocks/util.c b/tests/bluetooth/host/keys/mocks/util.c deleted file mode 100644 index a574f35a457bb..0000000000000 --- a/tests/bluetooth/host/keys/mocks/util.c +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "mocks/util.h" - -DEFINE_FAKE_VALUE_FUNC(uint8_t, u8_to_dec, char *, uint8_t, uint8_t); diff --git a/tests/bluetooth/host/keys/mocks/util.h b/tests/bluetooth/host/keys/mocks/util.h deleted file mode 100644 index 71b34409bed13..0000000000000 --- a/tests/bluetooth/host/keys/mocks/util.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -/* List of fakes used by this unit tester */ -#define UTIL_FFF_FAKES_LIST(FAKE) \ - FAKE(u8_to_dec) \ - -DECLARE_FAKE_VALUE_FUNC(uint8_t, u8_to_dec, char *, uint8_t, uint8_t); diff --git a/tests/bluetooth/host/keys/mocks/util_expects.c b/tests/bluetooth/host/keys/mocks/util_expects.c deleted file mode 100644 index 7a78370b11919..0000000000000 --- a/tests/bluetooth/host/keys/mocks/util_expects.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include "mocks/util.h" -#include "mocks/util_expects.h" - -void expect_single_call_u8_to_dec(uint8_t value) -{ - const char *func_name = "u8_to_dec"; - - zassert_equal(u8_to_dec_fake.call_count, 1, "'%s()' was called more than once", - func_name); - - zassert_not_null(u8_to_dec_fake.arg0_val, "'%s()' was called with incorrect '%s' value", - func_name, "buf"); - zassert_true(u8_to_dec_fake.arg1_val != 0, "'%s()' was called with incorrect '%s' value", - func_name, "buflen"); - zassert_equal(u8_to_dec_fake.arg2_val, value, "'%s()' was called with incorrect '%s' value", - func_name, "value"); -} - -void expect_not_called_u8_to_dec(void) -{ - const char *func_name = "u8_to_dec"; - - zassert_equal(u8_to_dec_fake.call_count, 0, "'%s()' was called unexpectedly", - func_name); -} diff --git a/tests/bluetooth/host/keys/mocks/util_expects.h b/tests/bluetooth/host/keys/mocks/util_expects.h deleted file mode 100644 index f371c6ae9db1c..0000000000000 --- a/tests/bluetooth/host/keys/mocks/util_expects.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -/* - * Validate expected behaviour when u8_to_dec() is called - * - * Expected behaviour: - * - u8_to_dec() to be called once with correct parameters - */ -void expect_single_call_u8_to_dec(uint8_t value); - -/* - * Validate expected behaviour when u8_to_dec() isn't called - * - * Expected behaviour: - * - u8_to_dec() isn't called at all - */ -void expect_not_called_u8_to_dec(void); diff --git a/tests/bluetooth/host/keys/testing_common_defs.h b/tests/bluetooth/host/keys/testing_common_defs.h deleted file mode 100644 index 5a357e8ad8fd6..0000000000000 --- a/tests/bluetooth/host/keys/testing_common_defs.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/** Keys "test" IDs associated with a BT address */ -#define BT_ADDR_ID_0 (0x00) -#define BT_ADDR_ID_1 (0x55) -#define BT_ADDR_ID_2 (0xAA) -#define BT_ADDR_ID_3 (0xA5) -#define BT_ADDR_ID_4 (0x5A) -#define BT_ADDR_ID_5 (0xAC) - -/** Bluetooth LE device "test" addresses */ -#define BT_ADDR_LE_1 ((bt_addr_le_t[]){{BT_ADDR_LE_PUBLIC, {{0x0A, 0x89, 0x67, 0x45, 0x23, 0x01}}}}) -#define BT_ADDR_LE_2 ((bt_addr_le_t[]){{BT_ADDR_LE_PUBLIC, {{0x0B, 0x89, 0x67, 0x45, 0x23, 0x01}}}}) -#define BT_ADDR_LE_3 ((bt_addr_le_t[]){{BT_ADDR_LE_PUBLIC, {{0x0C, 0x89, 0x67, 0x45, 0x23, 0x01}}}}) -#define BT_ADDR_LE_4 ((bt_addr_le_t[]){{BT_ADDR_LE_PUBLIC, {{0x0D, 0x89, 0x67, 0x45, 0x23, 0x01}}}}) -#define BT_ADDR_LE_5 ((bt_addr_le_t[]){{BT_ADDR_LE_PUBLIC, {{0x0E, 0x89, 0x67, 0x45, 0x23, 0x01}}}}) - -/** Bluetooth LE device "test" random addresses */ -#define BT_RPA_ADDR_LE_1 \ - ((bt_addr_le_t[]){{BT_ADDR_LE_RANDOM, {{0x0A, 0x89, 0x67, 0x45, 0x23, 0x41}}}}) -#define BT_RPA_ADDR_LE_2 \ - ((bt_addr_le_t[]){{BT_ADDR_LE_RANDOM, {{0x0B, 0x89, 0x67, 0x45, 0x23, 0x41}}}}) -#define BT_RPA_ADDR_LE_3 \ - ((bt_addr_le_t[]){{BT_ADDR_LE_RANDOM, {{0x0C, 0x89, 0x67, 0x45, 0x23, 0x41}}}}) -#define BT_RPA_ADDR_LE_4 \ - ((bt_addr_le_t[]){{BT_ADDR_LE_RANDOM, {{0x0D, 0x89, 0x67, 0x45, 0x23, 0x41}}}}) -#define BT_RPA_ADDR_LE_5 \ - ((bt_addr_le_t[]){{BT_ADDR_LE_RANDOM, {{0x0E, 0x89, 0x67, 0x45, 0x23, 0x41}}}})