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 2015/12/17 21:04:55 UTC
[2/3] incubator-mynewt-larva git commit: Rename ble_gap_test to
ble_os_test.
Rename ble_gap_test to ble_os_test.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/abed8b72
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/abed8b72
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/abed8b72
Branch: refs/heads/master
Commit: abed8b723cf7c28231c693bca7b7695ce6dbff13
Parents: fcc4065
Author: Christopher Collins <cc...@gmail.com>
Authored: Wed Dec 16 17:02:23 2015 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Thu Dec 17 12:04:07 2015 -0800
----------------------------------------------------------------------
net/nimble/host/include/host/ble_hs_test.h | 2 +-
net/nimble/host/src/test/ble_gap_test.c | 348 ------------------------
net/nimble/host/src/test/ble_hs_test.c | 2 +-
net/nimble/host/src/test/ble_os_test.c | 348 ++++++++++++++++++++++++
4 files changed, 350 insertions(+), 350 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/abed8b72/net/nimble/host/include/host/ble_hs_test.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_hs_test.h b/net/nimble/host/include/host/ble_hs_test.h
index 60d80d3..12014ff 100644
--- a/net/nimble/host/include/host/ble_hs_test.h
+++ b/net/nimble/host/include/host/ble_hs_test.h
@@ -26,7 +26,7 @@ int ble_att_svr_test_all(void);
int ble_att_clt_test_all(void);
int ble_host_hci_test_all(void);
int ble_hs_conn_test_all(void);
-int ble_gap_test_all(void);
+int ble_os_test_all(void);
int ble_hs_uuid_test_all(void);
int ble_gatt_disc_s_test_all(void);
int ble_gatt_disc_c_test_all(void);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/abed8b72/net/nimble/host/src/test/ble_gap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gap_test.c b/net/nimble/host/src/test/ble_gap_test.c
deleted file mode 100644
index 4728046..0000000
--- a/net/nimble/host/src/test/ble_gap_test.c
+++ /dev/null
@@ -1,348 +0,0 @@
-/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <string.h>
-#include "os/os.h"
-#include "testutil/testutil.h"
-#include "nimble/hci_common.h"
-#include "nimble/hci_transport.h"
-#include "ble_hs_priv.h"
-#include "host/ble_hs_test.h"
-#include "host/ble_gap.h"
-#include "ble_hs_test_util.h"
-#include "ble_hs_conn.h"
-#include "ble_gap_conn.h"
-
-#ifdef ARCH_sim
-#define BLE_GAP_TEST_STACK_SIZE 1024
-#else
-#define BLE_GAP_TEST_STACK_SIZE 256
-#endif
-
-#define BLE_GAP_TEST_HS_PRIO 10
-
-static struct os_task ble_gap_test_task;
-static os_stack_t ble_gap_test_stack[OS_STACK_ALIGN(BLE_GAP_TEST_STACK_SIZE)];
-
-static uint8_t ble_gap_test_peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
-
-static void
-ble_gap_test_misc_rx_ack(uint8_t ogf, uint8_t ocf, uint8_t status)
-{
- uint16_t opcode;
- uint8_t *cmd;
- int rc;
-
- cmd = os_memblock_get(&g_hci_cmd_pool);
- TEST_ASSERT_FATAL(cmd != NULL);
-
- opcode = (ogf << 10) | ocf;
- ble_hs_test_util_build_cmd_status(cmd, BLE_HCI_EVENT_CMD_STATUS_LEN,
- status, 1, opcode);
-
- rc = ble_hci_transport_ctlr_event_send(cmd);
- TEST_ASSERT(rc == 0);
-}
-
-static void
-ble_gap_test_misc_rx_le_ack(uint16_t ocf, uint8_t status)
-{
- ble_gap_test_misc_rx_ack(BLE_HCI_OGF_LE, ocf, status);
-}
-
-static void
-ble_gap_direct_connect_test_connect_cb(struct ble_gap_conn_event *event,
- void *arg)
-{
- int *cb_called;
-
- cb_called = arg;
- *cb_called = 1;
-
- TEST_ASSERT(event->type == BLE_GAP_CONN_EVENT_TYPE_CONNECT);
- TEST_ASSERT(event->conn.status == BLE_ERR_SUCCESS);
- TEST_ASSERT(event->conn.handle == 2);
- TEST_ASSERT(memcmp(event->conn.peer_addr, ble_gap_test_peer_addr, 6) ==
- 0);
-}
-
-static void
-ble_gap_direct_connect_test_task_handler(void *arg)
-{
- struct hci_le_conn_complete evt;
- uint8_t addr[6] = { 1, 2, 3, 4, 5, 6 };
- int cb_called;
- int rc;
-
- /* Receive acknowledgements for the startup sequence. We sent the
- * corresponding requests when the host task was started.
- */
- ble_hs_test_util_rx_startup_acks();
-
- /* Set the connect callback so we can verify that it gets called with the
- * proper arguments.
- */
- cb_called = 0;
- ble_gap_conn_set_cb(ble_gap_direct_connect_test_connect_cb, &cb_called);
-
- /* Make sure there are no created connections and no connections in
- * progress.
- */
- TEST_ASSERT(ble_hs_conn_first() == NULL);
-
- /* Initiate a direct connection. */
- ble_gap_conn_direct_connect(0, addr);
- TEST_ASSERT(ble_hs_conn_first() == NULL);
- TEST_ASSERT(!cb_called);
-
- /* Receive an ack for the HCI create-connection command. */
- ble_gap_test_misc_rx_le_ack(BLE_HCI_OCF_LE_CREATE_CONN, 0);
- TEST_ASSERT(ble_hs_conn_first() == NULL);
- TEST_ASSERT(!cb_called);
-
- /* Receive an HCI connection-complete event. */
- memset(&evt, 0, sizeof evt);
- evt.subevent_code = BLE_HCI_LE_SUBEV_CONN_COMPLETE;
- evt.status = BLE_ERR_SUCCESS;
- evt.connection_handle = 2;
- memcpy(evt.peer_addr, addr, 6);
- rc = ble_gap_conn_rx_conn_complete(&evt);
- TEST_ASSERT(rc == 0);
-
- /* The connection should now be created. */
- TEST_ASSERT(ble_hs_conn_find(2) != NULL);
- TEST_ASSERT(cb_called);
-
- tu_restart();
-}
-
-TEST_CASE(ble_gap_direct_connect_test_case)
-{
- os_init();
-
- ble_hs_test_util_init();
-
- os_task_init(&ble_gap_test_task,
- "ble_gap_direct_connect_test_task",
- ble_gap_direct_connect_test_task_handler, NULL,
- BLE_GAP_TEST_HS_PRIO + 1, OS_WAIT_FOREVER, ble_gap_test_stack,
- OS_STACK_ALIGN(BLE_GAP_TEST_STACK_SIZE));
-
- os_start();
-}
-
-static void
-ble_gap_gen_disc_test_connect_cb(struct ble_gap_conn_event *event, void *arg)
-{
- int *cb_called;
-
- cb_called = arg;
- *cb_called = 1;
-
- TEST_ASSERT(event->type == BLE_GAP_CONN_EVENT_TYPE_SCAN_DONE);
-}
-
-static void
-ble_gap_gen_disc_test_task_handler(void *arg)
-{
- int cb_called;
-
- /* Receive acknowledgements for the startup sequence. We sent the
- * corresponding requests when the host task was started.
- */
- ble_hs_test_util_rx_startup_acks();
-
- /* Set the connect callback so we can verify that it gets called with the
- * proper arguments.
- */
- cb_called = 0;
- ble_gap_conn_set_cb(ble_gap_gen_disc_test_connect_cb, &cb_called);
-
- /* Make sure there are no created connections and no connections in
- * progress.
- */
- TEST_ASSERT(ble_hs_conn_first() == NULL);
- TEST_ASSERT(!ble_gap_conn_master_in_progress());
-
- /* Initiate the general discovery procedure with a 200 ms timeout. */
- ble_gap_conn_gen_disc(200);
- TEST_ASSERT(ble_hs_conn_first() == NULL);
- TEST_ASSERT(ble_gap_conn_master_in_progress());
- TEST_ASSERT(!cb_called);
-
- /* Receive acks from the controller. */
- ble_gap_test_misc_rx_le_ack(BLE_HCI_OCF_LE_SET_SCAN_PARAMS, 0);
- ble_gap_test_misc_rx_le_ack(BLE_HCI_OCF_LE_SET_SCAN_ENABLE, 0);
- TEST_ASSERT(ble_hs_conn_first() == NULL);
- TEST_ASSERT(ble_gap_conn_master_in_progress());
- TEST_ASSERT(!cb_called);
-
- /* Wait 100 ms; verify scan still in progress. */
- os_time_delay(100 * OS_TICKS_PER_SEC / 1000);
- TEST_ASSERT(ble_hs_conn_first() == NULL);
- TEST_ASSERT(ble_gap_conn_master_in_progress());
- TEST_ASSERT(!cb_called);
-
- /* Wait 150 more ms; verify scan completed. */
- os_time_delay(150 * OS_TICKS_PER_SEC / 1000);
- TEST_ASSERT(ble_hs_conn_first() == NULL);
- TEST_ASSERT(!ble_gap_conn_master_in_progress());
- TEST_ASSERT(cb_called);
-
- tu_restart();
-}
-
-TEST_CASE(ble_gap_gen_disc_test_case)
-{
- os_init();
-
- ble_hs_test_util_init();
-
- os_task_init(&ble_gap_test_task,
- "ble_gap_gen_disc_test_task",
- ble_gap_gen_disc_test_task_handler, NULL,
- BLE_GAP_TEST_HS_PRIO + 1, OS_WAIT_FOREVER, ble_gap_test_stack,
- OS_STACK_ALIGN(BLE_GAP_TEST_STACK_SIZE));
-
- os_start();
-}
-
-static void
-ble_gap_terminate_cb(struct ble_gap_conn_event *event, void *arg)
-{
- int *disconn_handle;
-
- if (event->type != BLE_GAP_CONN_EVENT_TYPE_TERMINATE) {
- return;
- }
-
- disconn_handle = arg;
-
- TEST_ASSERT(event->term.status == 0);
- TEST_ASSERT(event->term.reason == BLE_ERR_REM_USER_CONN_TERM);
-
- *disconn_handle = event->term.handle;
-}
-
-
-static void
-ble_gap_terminate_test_task_handler(void *arg)
-{
- struct hci_disconn_complete disconn_evt;
- struct hci_le_conn_complete conn_evt;
- uint8_t addr1[6] = { 1, 2, 3, 4, 5, 6 };
- uint8_t addr2[6] = { 2, 3, 4, 5, 6, 7 };
- int disconn_handle;;
- int rc;
-
- /* Receive acknowledgements for the startup sequence. We sent the
- * corresponding requests when the host task was started.
- */
- ble_hs_test_util_rx_startup_acks();
-
- /* Set the connect callback so we can verify that it gets called with the
- * proper arguments.
- */
- disconn_handle = 0;
- ble_gap_conn_set_cb(ble_gap_terminate_cb, &disconn_handle);
-
- /* Make sure there are no created connections and no connections in
- * progress.
- */
- TEST_ASSERT(ble_hs_conn_first() == NULL);
- TEST_ASSERT(!ble_gap_conn_master_in_progress());
-
- /* Create two direct connections. */
- ble_gap_conn_direct_connect(0, addr1);
- ble_gap_test_misc_rx_le_ack(BLE_HCI_OCF_LE_CREATE_CONN, 0);
- memset(&conn_evt, 0, sizeof conn_evt);
- conn_evt.subevent_code = BLE_HCI_LE_SUBEV_CONN_COMPLETE;
- conn_evt.status = BLE_ERR_SUCCESS;
- conn_evt.connection_handle = 1;
- memcpy(conn_evt.peer_addr, addr1, 6);
- rc = ble_gap_conn_rx_conn_complete(&conn_evt);
- TEST_ASSERT(rc == 0);
-
- ble_gap_conn_direct_connect(0, addr2);
- ble_gap_test_misc_rx_le_ack(BLE_HCI_OCF_LE_CREATE_CONN, 0);
- memset(&conn_evt, 0, sizeof conn_evt);
- conn_evt.subevent_code = BLE_HCI_LE_SUBEV_CONN_COMPLETE;
- conn_evt.status = BLE_ERR_SUCCESS;
- conn_evt.connection_handle = 2;
- memcpy(conn_evt.peer_addr, addr2, 6);
- rc = ble_gap_conn_rx_conn_complete(&conn_evt);
- TEST_ASSERT(rc == 0);
-
- TEST_ASSERT_FATAL(ble_hs_conn_find(1) != NULL);
- TEST_ASSERT_FATAL(ble_hs_conn_find(2) != NULL);
-
- /* Terminate the first one. */
- rc = ble_gap_conn_terminate(1);
- TEST_ASSERT(rc == 0);
- ble_gap_test_misc_rx_ack(BLE_HCI_OGF_LINK_CTRL, BLE_HCI_OCF_DISCONNECT_CMD,
- 0);
- disconn_evt.connection_handle = 1;
- disconn_evt.status = 0;
- disconn_evt.reason = BLE_ERR_REM_USER_CONN_TERM;
- ble_gap_conn_rx_disconn_complete(&disconn_evt);
- TEST_ASSERT(disconn_handle == 1);
- TEST_ASSERT(ble_hs_conn_find(1) == NULL);
- TEST_ASSERT(ble_hs_conn_find(2) != NULL);
-
- /* Terminate the second one. */
- rc = ble_gap_conn_terminate(2);
- TEST_ASSERT(rc == 0);
- ble_gap_test_misc_rx_ack(BLE_HCI_OGF_LINK_CTRL, BLE_HCI_OCF_DISCONNECT_CMD,
- 0);
- disconn_evt.connection_handle = 2;
- disconn_evt.status = 0;
- disconn_evt.reason = BLE_ERR_REM_USER_CONN_TERM;
- ble_gap_conn_rx_disconn_complete(&disconn_evt);
- TEST_ASSERT(disconn_handle == 2);
- TEST_ASSERT(ble_hs_conn_find(1) == NULL);
- TEST_ASSERT(ble_hs_conn_find(2) == NULL);
-
- tu_restart();
-}
-
-TEST_CASE(ble_gap_terminate_test_case)
-{
- os_init();
-
- ble_hs_test_util_init();
-
- os_task_init(&ble_gap_test_task,
- "ble_gap_terminate_test_task",
- ble_gap_terminate_test_task_handler, NULL,
- BLE_GAP_TEST_HS_PRIO + 1, OS_WAIT_FOREVER, ble_gap_test_stack,
- OS_STACK_ALIGN(BLE_GAP_TEST_STACK_SIZE));
-
- os_start();
-}
-
-TEST_SUITE(ble_gap_test_suite)
-{
- ble_gap_gen_disc_test_case();
- ble_gap_direct_connect_test_case();
- ble_gap_terminate_test_case();
-}
-
-int
-ble_gap_test_all(void)
-{
- ble_gap_test_suite();
- return tu_any_failed;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/abed8b72/net/nimble/host/src/test/ble_hs_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test.c b/net/nimble/host/src/test/ble_hs_test.c
index dfcf0f8..464c4cd 100644
--- a/net/nimble/host/src/test/ble_hs_test.c
+++ b/net/nimble/host/src/test/ble_hs_test.c
@@ -45,7 +45,7 @@ main(void)
ble_att_clt_test_all();
ble_host_hci_test_all();
ble_hs_conn_test_all();
- ble_gap_test_all();
+ ble_os_test_all();
ble_hs_uuid_test_all();
ble_gatt_disc_s_test_all();
ble_gatt_disc_c_test_all();
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/abed8b72/net/nimble/host/src/test/ble_os_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_os_test.c b/net/nimble/host/src/test/ble_os_test.c
new file mode 100644
index 0000000..18e8ada
--- /dev/null
+++ b/net/nimble/host/src/test/ble_os_test.c
@@ -0,0 +1,348 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string.h>
+#include "os/os.h"
+#include "testutil/testutil.h"
+#include "nimble/hci_common.h"
+#include "nimble/hci_transport.h"
+#include "ble_hs_priv.h"
+#include "host/ble_hs_test.h"
+#include "host/ble_gap.h"
+#include "ble_hs_test_util.h"
+#include "ble_hs_conn.h"
+#include "ble_gap_conn.h"
+
+#ifdef ARCH_sim
+#define BLE_OS_TEST_STACK_SIZE 1024
+#else
+#define BLE_OS_TEST_STACK_SIZE 256
+#endif
+
+#define BLE_OS_TEST_HS_PRIO 10
+
+static struct os_task ble_os_test_task;
+static os_stack_t ble_os_test_stack[OS_STACK_ALIGN(BLE_OS_TEST_STACK_SIZE)];
+
+static uint8_t ble_os_test_peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
+
+static void
+ble_os_test_misc_rx_ack(uint8_t ogf, uint8_t ocf, uint8_t status)
+{
+ uint16_t opcode;
+ uint8_t *cmd;
+ int rc;
+
+ cmd = os_memblock_get(&g_hci_cmd_pool);
+ TEST_ASSERT_FATAL(cmd != NULL);
+
+ opcode = (ogf << 10) | ocf;
+ ble_hs_test_util_build_cmd_status(cmd, BLE_HCI_EVENT_CMD_STATUS_LEN,
+ status, 1, opcode);
+
+ rc = ble_hci_transport_ctlr_event_send(cmd);
+ TEST_ASSERT(rc == 0);
+}
+
+static void
+ble_os_test_misc_rx_le_ack(uint16_t ocf, uint8_t status)
+{
+ ble_os_test_misc_rx_ack(BLE_HCI_OGF_LE, ocf, status);
+}
+
+static void
+ble_gap_direct_connect_test_connect_cb(struct ble_gap_conn_event *event,
+ void *arg)
+{
+ int *cb_called;
+
+ cb_called = arg;
+ *cb_called = 1;
+
+ TEST_ASSERT(event->type == BLE_GAP_CONN_EVENT_TYPE_CONNECT);
+ TEST_ASSERT(event->conn.status == BLE_ERR_SUCCESS);
+ TEST_ASSERT(event->conn.handle == 2);
+ TEST_ASSERT(memcmp(event->conn.peer_addr, ble_os_test_peer_addr, 6) ==
+ 0);
+}
+
+static void
+ble_gap_direct_connect_test_task_handler(void *arg)
+{
+ struct hci_le_conn_complete evt;
+ uint8_t addr[6] = { 1, 2, 3, 4, 5, 6 };
+ int cb_called;
+ int rc;
+
+ /* Receive acknowledgements for the startup sequence. We sent the
+ * corresponding requests when the host task was started.
+ */
+ ble_hs_test_util_rx_startup_acks();
+
+ /* Set the connect callback so we can verify that it gets called with the
+ * proper arguments.
+ */
+ cb_called = 0;
+ ble_gap_conn_set_cb(ble_gap_direct_connect_test_connect_cb, &cb_called);
+
+ /* Make sure there are no created connections and no connections in
+ * progress.
+ */
+ TEST_ASSERT(ble_hs_conn_first() == NULL);
+
+ /* Initiate a direct connection. */
+ ble_gap_conn_direct_connect(0, addr);
+ TEST_ASSERT(ble_hs_conn_first() == NULL);
+ TEST_ASSERT(!cb_called);
+
+ /* Receive an ack for the HCI create-connection command. */
+ ble_os_test_misc_rx_le_ack(BLE_HCI_OCF_LE_CREATE_CONN, 0);
+ TEST_ASSERT(ble_hs_conn_first() == NULL);
+ TEST_ASSERT(!cb_called);
+
+ /* Receive an HCI connection-complete event. */
+ memset(&evt, 0, sizeof evt);
+ evt.subevent_code = BLE_HCI_LE_SUBEV_CONN_COMPLETE;
+ evt.status = BLE_ERR_SUCCESS;
+ evt.connection_handle = 2;
+ memcpy(evt.peer_addr, addr, 6);
+ rc = ble_gap_conn_rx_conn_complete(&evt);
+ TEST_ASSERT(rc == 0);
+
+ /* The connection should now be created. */
+ TEST_ASSERT(ble_hs_conn_find(2) != NULL);
+ TEST_ASSERT(cb_called);
+
+ tu_restart();
+}
+
+TEST_CASE(ble_gap_direct_connect_test_case)
+{
+ os_init();
+
+ ble_hs_test_util_init();
+
+ os_task_init(&ble_os_test_task,
+ "ble_gap_direct_connect_test_task",
+ ble_gap_direct_connect_test_task_handler, NULL,
+ BLE_OS_TEST_HS_PRIO + 1, OS_WAIT_FOREVER, ble_os_test_stack,
+ OS_STACK_ALIGN(BLE_OS_TEST_STACK_SIZE));
+
+ os_start();
+}
+
+static void
+ble_gap_gen_disc_test_connect_cb(struct ble_gap_conn_event *event, void *arg)
+{
+ int *cb_called;
+
+ cb_called = arg;
+ *cb_called = 1;
+
+ TEST_ASSERT(event->type == BLE_GAP_CONN_EVENT_TYPE_SCAN_DONE);
+}
+
+static void
+ble_gap_gen_disc_test_task_handler(void *arg)
+{
+ int cb_called;
+
+ /* Receive acknowledgements for the startup sequence. We sent the
+ * corresponding requests when the host task was started.
+ */
+ ble_hs_test_util_rx_startup_acks();
+
+ /* Set the connect callback so we can verify that it gets called with the
+ * proper arguments.
+ */
+ cb_called = 0;
+ ble_gap_conn_set_cb(ble_gap_gen_disc_test_connect_cb, &cb_called);
+
+ /* Make sure there are no created connections and no connections in
+ * progress.
+ */
+ TEST_ASSERT(ble_hs_conn_first() == NULL);
+ TEST_ASSERT(!ble_gap_conn_master_in_progress());
+
+ /* Initiate the general discovery procedure with a 200 ms timeout. */
+ ble_gap_conn_gen_disc(200);
+ TEST_ASSERT(ble_hs_conn_first() == NULL);
+ TEST_ASSERT(ble_gap_conn_master_in_progress());
+ TEST_ASSERT(!cb_called);
+
+ /* Receive acks from the controller. */
+ ble_os_test_misc_rx_le_ack(BLE_HCI_OCF_LE_SET_SCAN_PARAMS, 0);
+ ble_os_test_misc_rx_le_ack(BLE_HCI_OCF_LE_SET_SCAN_ENABLE, 0);
+ TEST_ASSERT(ble_hs_conn_first() == NULL);
+ TEST_ASSERT(ble_gap_conn_master_in_progress());
+ TEST_ASSERT(!cb_called);
+
+ /* Wait 100 ms; verify scan still in progress. */
+ os_time_delay(100 * OS_TICKS_PER_SEC / 1000);
+ TEST_ASSERT(ble_hs_conn_first() == NULL);
+ TEST_ASSERT(ble_gap_conn_master_in_progress());
+ TEST_ASSERT(!cb_called);
+
+ /* Wait 150 more ms; verify scan completed. */
+ os_time_delay(150 * OS_TICKS_PER_SEC / 1000);
+ TEST_ASSERT(ble_hs_conn_first() == NULL);
+ TEST_ASSERT(!ble_gap_conn_master_in_progress());
+ TEST_ASSERT(cb_called);
+
+ tu_restart();
+}
+
+TEST_CASE(ble_gap_gen_disc_test_case)
+{
+ os_init();
+
+ ble_hs_test_util_init();
+
+ os_task_init(&ble_os_test_task,
+ "ble_gap_gen_disc_test_task",
+ ble_gap_gen_disc_test_task_handler, NULL,
+ BLE_OS_TEST_HS_PRIO + 1, OS_WAIT_FOREVER, ble_os_test_stack,
+ OS_STACK_ALIGN(BLE_OS_TEST_STACK_SIZE));
+
+ os_start();
+}
+
+static void
+ble_gap_terminate_cb(struct ble_gap_conn_event *event, void *arg)
+{
+ int *disconn_handle;
+
+ if (event->type != BLE_GAP_CONN_EVENT_TYPE_TERMINATE) {
+ return;
+ }
+
+ disconn_handle = arg;
+
+ TEST_ASSERT(event->term.status == 0);
+ TEST_ASSERT(event->term.reason == BLE_ERR_REM_USER_CONN_TERM);
+
+ *disconn_handle = event->term.handle;
+}
+
+
+static void
+ble_gap_terminate_test_task_handler(void *arg)
+{
+ struct hci_disconn_complete disconn_evt;
+ struct hci_le_conn_complete conn_evt;
+ uint8_t addr1[6] = { 1, 2, 3, 4, 5, 6 };
+ uint8_t addr2[6] = { 2, 3, 4, 5, 6, 7 };
+ int disconn_handle;;
+ int rc;
+
+ /* Receive acknowledgements for the startup sequence. We sent the
+ * corresponding requests when the host task was started.
+ */
+ ble_hs_test_util_rx_startup_acks();
+
+ /* Set the connect callback so we can verify that it gets called with the
+ * proper arguments.
+ */
+ disconn_handle = 0;
+ ble_gap_conn_set_cb(ble_gap_terminate_cb, &disconn_handle);
+
+ /* Make sure there are no created connections and no connections in
+ * progress.
+ */
+ TEST_ASSERT(ble_hs_conn_first() == NULL);
+ TEST_ASSERT(!ble_gap_conn_master_in_progress());
+
+ /* Create two direct connections. */
+ ble_gap_conn_direct_connect(0, addr1);
+ ble_os_test_misc_rx_le_ack(BLE_HCI_OCF_LE_CREATE_CONN, 0);
+ memset(&conn_evt, 0, sizeof conn_evt);
+ conn_evt.subevent_code = BLE_HCI_LE_SUBEV_CONN_COMPLETE;
+ conn_evt.status = BLE_ERR_SUCCESS;
+ conn_evt.connection_handle = 1;
+ memcpy(conn_evt.peer_addr, addr1, 6);
+ rc = ble_gap_conn_rx_conn_complete(&conn_evt);
+ TEST_ASSERT(rc == 0);
+
+ ble_gap_conn_direct_connect(0, addr2);
+ ble_os_test_misc_rx_le_ack(BLE_HCI_OCF_LE_CREATE_CONN, 0);
+ memset(&conn_evt, 0, sizeof conn_evt);
+ conn_evt.subevent_code = BLE_HCI_LE_SUBEV_CONN_COMPLETE;
+ conn_evt.status = BLE_ERR_SUCCESS;
+ conn_evt.connection_handle = 2;
+ memcpy(conn_evt.peer_addr, addr2, 6);
+ rc = ble_gap_conn_rx_conn_complete(&conn_evt);
+ TEST_ASSERT(rc == 0);
+
+ TEST_ASSERT_FATAL(ble_hs_conn_find(1) != NULL);
+ TEST_ASSERT_FATAL(ble_hs_conn_find(2) != NULL);
+
+ /* Terminate the first one. */
+ rc = ble_gap_conn_terminate(1);
+ TEST_ASSERT(rc == 0);
+ ble_os_test_misc_rx_ack(BLE_HCI_OGF_LINK_CTRL, BLE_HCI_OCF_DISCONNECT_CMD,
+ 0);
+ disconn_evt.connection_handle = 1;
+ disconn_evt.status = 0;
+ disconn_evt.reason = BLE_ERR_REM_USER_CONN_TERM;
+ ble_gap_conn_rx_disconn_complete(&disconn_evt);
+ TEST_ASSERT(disconn_handle == 1);
+ TEST_ASSERT(ble_hs_conn_find(1) == NULL);
+ TEST_ASSERT(ble_hs_conn_find(2) != NULL);
+
+ /* Terminate the second one. */
+ rc = ble_gap_conn_terminate(2);
+ TEST_ASSERT(rc == 0);
+ ble_os_test_misc_rx_ack(BLE_HCI_OGF_LINK_CTRL, BLE_HCI_OCF_DISCONNECT_CMD,
+ 0);
+ disconn_evt.connection_handle = 2;
+ disconn_evt.status = 0;
+ disconn_evt.reason = BLE_ERR_REM_USER_CONN_TERM;
+ ble_gap_conn_rx_disconn_complete(&disconn_evt);
+ TEST_ASSERT(disconn_handle == 2);
+ TEST_ASSERT(ble_hs_conn_find(1) == NULL);
+ TEST_ASSERT(ble_hs_conn_find(2) == NULL);
+
+ tu_restart();
+}
+
+TEST_CASE(ble_gap_terminate_test_case)
+{
+ os_init();
+
+ ble_hs_test_util_init();
+
+ os_task_init(&ble_os_test_task,
+ "ble_gap_terminate_test_task",
+ ble_gap_terminate_test_task_handler, NULL,
+ BLE_OS_TEST_HS_PRIO + 1, OS_WAIT_FOREVER, ble_os_test_stack,
+ OS_STACK_ALIGN(BLE_OS_TEST_STACK_SIZE));
+
+ os_start();
+}
+
+TEST_SUITE(ble_os_test_suite)
+{
+ ble_gap_gen_disc_test_case();
+ ble_gap_direct_connect_test_case();
+ ble_gap_terminate_test_case();
+}
+
+int
+ble_os_test_all(void)
+{
+ ble_os_test_suite();
+ return tu_any_failed;
+}