You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/11/17 02:31:56 UTC
[4/5] incubator-mynewt-core git commit: BLE Host - Unit tests for
GATT timeouts.
BLE Host - Unit tests for GATT timeouts.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/85e6f3ca
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/85e6f3ca
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/85e6f3ca
Branch: refs/heads/develop
Commit: 85e6f3ca290c42ce1893837710676507d9b13746
Parents: d0cc833
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Nov 16 18:11:35 2016 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Wed Nov 16 18:31:44 2016 -0800
----------------------------------------------------------------------
net/nimble/host/src/ble_hs_hci_cmd.c | 2 +-
net/nimble/host/test/src/ble_gatt_conn_test.c | 159 ++++++++++++++++++++-
net/nimble/host/test/src/ble_hs_test_util.c | 32 ++++-
net/nimble/host/test/src/ble_hs_test_util.h | 3 +
4 files changed, 188 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/85e6f3ca/net/nimble/host/src/ble_hs_hci_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_hci_cmd.c b/net/nimble/host/src/ble_hs_hci_cmd.c
index 923bcc9..0f2d981 100644
--- a/net/nimble/host/src/ble_hs_hci_cmd.c
+++ b/net/nimble/host/src/ble_hs_hci_cmd.c
@@ -391,7 +391,7 @@ ble_hs_hci_cmd_build_disconnect(uint16_t handle, uint8_t reason,
dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_DISCONNECT_CMD_LEN);
ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LINK_CTRL, BLE_HCI_OCF_DISCONNECT_CMD,
- BLE_HCI_DISCONNECT_CMD_LEN, dst);
+ BLE_HCI_DISCONNECT_CMD_LEN, dst);
dst += BLE_HCI_CMD_HDR_LEN;
ble_hs_hci_cmd_body_disconnect(handle, reason, dst);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/85e6f3ca/net/nimble/host/test/src/ble_gatt_conn_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_gatt_conn_test.c b/net/nimble/host/test/src/ble_gatt_conn_test.c
index 50f661d..d4c941b 100644
--- a/net/nimble/host/test/src/ble_gatt_conn_test.c
+++ b/net/nimble/host/test/src/ble_gatt_conn_test.c
@@ -517,17 +517,172 @@ TEST_CASE(ble_gatt_conn_test_disconnect)
TEST_ASSERT(write_rel_arg.called == 1);
}
-TEST_SUITE(ble_gatt_break_suite)
+static void
+ble_gatt_conn_test_util_timeout(uint16_t conn_handle)
+{
+ int32_t ticks_from_now;
+
+ ticks_from_now = ble_gattc_timer();
+ TEST_ASSERT(ticks_from_now == 30 * OS_TICKS_PER_SEC);
+
+ os_time_advance(29 * OS_TICKS_PER_SEC);
+ ticks_from_now = ble_gattc_timer();
+ TEST_ASSERT(ticks_from_now == 1 * OS_TICKS_PER_SEC);
+
+ ble_hs_test_util_set_ack_disconnect(0);
+ os_time_advance(1 * OS_TICKS_PER_SEC);
+ ticks_from_now = ble_gattc_timer();
+ TEST_ASSERT(ticks_from_now == BLE_HS_FOREVER);
+
+ /* Ensure connection was terminated due to proecedure timeout. */
+ ble_hs_test_util_verify_tx_disconnect(conn_handle,
+ BLE_ERR_REM_USER_CONN_TERM);
+ ble_hs_test_util_rx_disconn_complete(conn_handle,
+ BLE_ERR_REM_USER_CONN_TERM);
+}
+
+TEST_CASE(ble_gatt_conn_test_timeout)
+{
+ static const uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
+ struct ble_gatt_attr attr;
+ int32_t ticks_from_now;
+ uint16_t attr_handle;
+ int rc;
+
+ ble_hs_test_util_init();
+
+ ticks_from_now = ble_gattc_timer();
+ TEST_ASSERT(ticks_from_now == BLE_HS_FOREVER);
+
+ /*** Register an attribute to allow indicatations to be sent. */
+ rc = ble_att_svr_register(BLE_UUID16(0x1212), BLE_ATT_F_READ,
+ &attr_handle,
+ ble_gatt_conn_test_attr_cb, NULL);
+ TEST_ASSERT(rc == 0);
+
+ /*** MTU. */
+ ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
+ rc = ble_gattc_exchange_mtu(1, ble_gatt_conn_test_mtu_cb, NULL);
+ TEST_ASSERT_FATAL(rc == 0);
+ ble_gatt_conn_test_util_timeout(1);
+
+ /*** Discover all services. */
+ ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
+ rc = ble_gattc_disc_all_svcs(1, ble_gatt_conn_test_disc_all_svcs_cb, NULL);
+ TEST_ASSERT_FATAL(rc == 0);
+ ble_gatt_conn_test_util_timeout(1);
+
+ /*** Discover services by UUID. */
+ ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
+ rc = ble_gattc_disc_svc_by_uuid(1, BLE_UUID16(0x1111),
+ ble_gatt_conn_test_disc_svc_uuid_cb, NULL);
+ TEST_ASSERT_FATAL(rc == 0);
+ ble_gatt_conn_test_util_timeout(1);
+
+ /*** Find included services. */
+ ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
+ rc = ble_gattc_find_inc_svcs(1, 1, 0xffff,
+ ble_gatt_conn_test_find_inc_svcs_cb, NULL);
+ TEST_ASSERT_FATAL(rc == 0);
+ ble_gatt_conn_test_util_timeout(1);
+
+ /*** Discover all characteristics. */
+ ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
+ rc = ble_gattc_disc_all_chrs(1, 1, 0xffff,
+ ble_gatt_conn_test_disc_all_chrs_cb, NULL);
+ TEST_ASSERT_FATAL(rc == 0);
+ ble_gatt_conn_test_util_timeout(1);
+
+ /*** Discover all descriptors. */
+ ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
+ rc = ble_gattc_disc_all_dscs(1, 3, 0xffff,
+ ble_gatt_conn_test_disc_all_dscs_cb, NULL);
+ TEST_ASSERT_FATAL(rc == 0);
+ ble_gatt_conn_test_util_timeout(1);
+
+ /*** Discover characteristics by UUID. */
+ ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
+ rc = ble_gattc_disc_chrs_by_uuid(1, 2, 0xffff, BLE_UUID16(0x2222),
+ ble_gatt_conn_test_disc_chr_uuid_cb,
+ NULL);
+ TEST_ASSERT_FATAL(rc == 0);
+ ble_gatt_conn_test_util_timeout(1);
+
+ /*** Read. */
+ ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
+ rc = ble_gattc_read(1, BLE_GATT_BREAK_TEST_READ_ATTR_HANDLE,
+ ble_gatt_conn_test_read_cb, NULL);
+ TEST_ASSERT_FATAL(rc == 0);
+ ble_gatt_conn_test_util_timeout(1);
+
+ /*** Read by UUID. */
+ ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
+ rc = ble_gattc_read_by_uuid(1, 1, 0xffff, BLE_UUID16(0x3333),
+ ble_gatt_conn_test_read_uuid_cb, NULL);
+ TEST_ASSERT_FATAL(rc == 0);
+ ble_gatt_conn_test_util_timeout(1);
+
+ /*** Read long. */
+ ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
+ rc = ble_gattc_read_long(1, BLE_GATT_BREAK_TEST_READ_ATTR_HANDLE,
+ ble_gatt_conn_test_read_long_cb, NULL);
+ TEST_ASSERT_FATAL(rc == 0);
+ ble_gatt_conn_test_util_timeout(1);
+
+ /*** Read multiple. */
+ ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
+ rc = ble_gattc_read_mult(1, ((uint16_t[3]){5,6,7}), 3,
+ ble_gatt_conn_test_read_mult_cb, NULL);
+ TEST_ASSERT_FATAL(rc == 0);
+ ble_gatt_conn_test_util_timeout(1);
+
+ /*** Write. */
+ ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
+ rc = ble_hs_test_util_gatt_write_flat(
+ 1, BLE_GATT_BREAK_TEST_WRITE_ATTR_HANDLE,
+ ble_gatt_conn_test_write_value, sizeof ble_gatt_conn_test_write_value,
+ ble_gatt_conn_test_write_cb, NULL);
+ TEST_ASSERT_FATAL(rc == 0);
+ ble_gatt_conn_test_util_timeout(1);
+
+ /*** Write long. */
+ ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
+ rc = ble_hs_test_util_gatt_write_long_flat(
+ 1, BLE_GATT_BREAK_TEST_WRITE_ATTR_HANDLE,
+ ble_gatt_conn_test_write_value, sizeof ble_gatt_conn_test_write_value,
+ ble_gatt_conn_test_write_long_cb, NULL);
+ TEST_ASSERT_FATAL(rc == 0);
+ ble_gatt_conn_test_util_timeout(1);
+
+ /*** Write reliable. */
+ ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
+ attr.handle = 8;
+ attr.offset = 0;
+ attr.om = os_msys_get_pkthdr(0, 0);
+ rc = ble_gattc_write_reliable(
+ 1, &attr, 1, ble_gatt_conn_test_write_rel_cb, NULL);
+ TEST_ASSERT_FATAL(rc == 0);
+ ble_gatt_conn_test_util_timeout(1);
+
+ /*** Indication. */
+ ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
+ rc = ble_gattc_indicate(1, attr_handle);
+ TEST_ASSERT_FATAL(rc == 0);
+ ble_gatt_conn_test_util_timeout(1);
+}
+
+TEST_SUITE(ble_gatt_conn_suite)
{
tu_suite_set_post_test_cb(ble_hs_test_util_post_test, NULL);
ble_gatt_conn_test_disconnect();
+ ble_gatt_conn_test_timeout();
}
int
ble_gatt_conn_test_all(void)
{
- ble_gatt_break_suite();
+ ble_gatt_conn_suite();
return tu_any_failed;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/85e6f3ca/net/nimble/host/test/src/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_hs_test_util.c b/net/nimble/host/test/src/ble_hs_test_util.c
index 55528dd..0e9ef43 100644
--- a/net/nimble/host/test/src/ble_hs_test_util.c
+++ b/net/nimble/host/test/src/ble_hs_test_util.c
@@ -445,6 +445,21 @@ ble_hs_test_util_hcc_from_conn_params(
}
void
+ble_hs_test_util_verify_tx_disconnect(uint16_t handle, uint8_t reason)
+{
+ uint8_t param_len;
+ uint8_t *param;
+
+ param = ble_hs_test_util_verify_tx_hci(BLE_HCI_OGF_LINK_CTRL,
+ BLE_HCI_OCF_DISCONNECT_CMD,
+ ¶m_len);
+ TEST_ASSERT(param_len == BLE_HCI_DISCONNECT_CMD_LEN);
+
+ TEST_ASSERT(le16toh(param + 0) == handle);
+ TEST_ASSERT(param[2] == reason);
+}
+
+void
ble_hs_test_util_verify_tx_create_conn(const struct hci_create_conn *exp)
{
uint8_t param_len;
@@ -559,19 +574,26 @@ ble_hs_test_util_conn_terminate(uint16_t conn_handle, uint8_t hci_status)
}
void
-ble_hs_test_util_conn_disconnect(uint16_t conn_handle)
+ble_hs_test_util_rx_disconn_complete(uint16_t conn_handle, uint8_t reason)
{
struct hci_disconn_complete evt;
+
+ evt.connection_handle = conn_handle;
+ evt.status = 0;
+ evt.reason = BLE_ERR_CONN_TERM_LOCAL;
+ ble_gap_rx_disconn_complete(&evt);
+}
+
+void
+ble_hs_test_util_conn_disconnect(uint16_t conn_handle)
+{
int rc;
rc = ble_hs_test_util_conn_terminate(conn_handle, 0);
TEST_ASSERT_FATAL(rc == 0);
/* Receive disconnection complete event. */
- evt.connection_handle = conn_handle;
- evt.status = 0;
- evt.reason = BLE_ERR_CONN_TERM_LOCAL;
- ble_gap_rx_disconn_complete(&evt);
+ ble_hs_test_util_rx_disconn_complete(conn_handle, BLE_ERR_CONN_TERM_LOCAL);
}
int
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/85e6f3ca/net/nimble/host/test/src/ble_hs_test_util.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_hs_test_util.h b/net/nimble/host/test/src/ble_hs_test_util.h
index 923be22..ab9b708 100644
--- a/net/nimble/host/test/src/ble_hs_test_util.h
+++ b/net/nimble/host/test/src/ble_hs_test_util.h
@@ -100,6 +100,8 @@ int ble_hs_test_util_conn_cancel(uint8_t ack_status);
void ble_hs_test_util_conn_cancel_full(void);
void ble_hs_test_util_set_ack_disconnect(uint8_t hci_status);
int ble_hs_test_util_conn_terminate(uint16_t conn_handle, uint8_t hci_status);
+void ble_hs_test_util_rx_disconn_complete(uint16_t conn_handle,
+ uint8_t reason);
void ble_hs_test_util_conn_disconnect(uint16_t conn_handle);
int ble_hs_test_util_exp_hci_status(int cmd_idx, int fail_idx,
uint8_t fail_status);
@@ -108,6 +110,7 @@ int ble_hs_test_util_disc(uint8_t own_addr_type, int32_t duration_ms,
ble_gap_event_fn *cb, void *cb_arg, int fail_idx,
uint8_t fail_status);
int ble_hs_test_util_disc_cancel(uint8_t ack_status);
+void ble_hs_test_util_verify_tx_disconnect(uint16_t handle, uint8_t reason);
void ble_hs_test_util_verify_tx_create_conn(const struct hci_create_conn *exp);
int ble_hs_test_util_adv_set_fields(struct ble_hs_adv_fields *adv_fields,
uint8_t hci_status);