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/11/10 04:11:49 UTC
incubator-mynewt-larva git commit: Some basic unit tests for HCI
events.
Repository: incubator-mynewt-larva
Updated Branches:
refs/heads/master 43f639ff2 -> ed3c9be5d
Some basic unit tests for HCI events.
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/ed3c9be5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/ed3c9be5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/ed3c9be5
Branch: refs/heads/master
Commit: ed3c9be5d2a2490fa2e919ad6ac6df153dafc67b
Parents: 43f639f
Author: Christopher Collins <cc...@gmail.com>
Authored: Mon Nov 9 19:11:13 2015 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Mon Nov 9 19:11:13 2015 -0800
----------------------------------------------------------------------
net/nimble/host/include/host/ble_hs_test.h | 1 +
net/nimble/host/include/host/host_hci.h | 3 +-
net/nimble/host/src/ble_hs.c | 2 +-
net/nimble/host/src/host_hci.c | 25 +++--
net/nimble/host/src/test/ble_host_hci_test.c | 120 ++++++++++++++++++++++
net/nimble/host/src/test/ble_hs_test.c | 1 +
6 files changed, 143 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ed3c9be5/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 e1d67fc..5d2b484 100644
--- a/net/nimble/host/include/host/ble_hs_test.h
+++ b/net/nimble/host/include/host/ble_hs_test.h
@@ -19,6 +19,7 @@
int l2cap_test_all(void);
int ble_hs_att_test_all(void);
+int ble_host_hci_test_all(void);
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ed3c9be5/net/nimble/host/include/host/host_hci.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/host_hci.h b/net/nimble/host/include/host/host_hci.h
index ec8b36b..27c0d34 100644
--- a/net/nimble/host/include/host/host_hci.h
+++ b/net/nimble/host/include/host/host_hci.h
@@ -19,7 +19,8 @@
#include "nimble/hci_common.h"
-void host_hci_event_proc(struct os_event *ev);
+int host_hci_os_event_proc(struct os_event *ev);
+int host_hci_event_rx(uint8_t *data);
int host_hci_cmd_le_set_scan_rsp_data(uint8_t *data, uint8_t len);
int host_hci_cmd_le_set_adv_data(uint8_t *data, uint8_t len);
int host_hci_cmd_le_set_adv_params(struct hci_adv_params *adv);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ed3c9be5/net/nimble/host/src/ble_hs.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs.c b/net/nimble/host/src/ble_hs.c
index d929491..505b1d7 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -91,7 +91,7 @@ ble_hs_task_handler(void *arg)
break;
case BLE_HOST_HCI_EVENT_CTLR_EVENT:
/* Process HCI event from controller */
- host_hci_event_proc(ev);
+ host_hci_os_event_proc(ev);
break;
default:
assert(0);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ed3c9be5/net/nimble/host/src/host_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_hci.c b/net/nimble/host/src/host_hci.c
index 164c7ad..a8f938c 100644
--- a/net/nimble/host/src/host_hci.c
+++ b/net/nimble/host/src/host_hci.c
@@ -172,20 +172,17 @@ host_hci_rx_cmd_status(uint8_t event_code, uint8_t *data, int len)
return 0;
}
-void
-host_hci_event_proc(struct os_event *ev)
+int
+host_hci_event_rx(uint8_t *data)
{
struct host_hci_event_dispatch_entry *entry;
- os_error_t err;
- uint8_t *data;
uint8_t event_code;
uint8_t param_len;
+ int rc;
/* Count events received */
++g_host_hci_stats.events_rxd;
- data = ev->ev_arg;
-
/* Display to console */
host_hci_dbg_event_disp(data);
@@ -195,10 +192,22 @@ host_hci_event_proc(struct os_event *ev)
entry = host_hci_dispatch_entry_find(event_code);
if (entry == NULL) {
++g_host_hci_stats.unknown_events_rxd;
+ rc = ENOTSUP;
} else {
- entry->hed_fn(event_code, data, param_len + 2);
+ rc = entry->hed_fn(event_code, data, param_len + 2);
}
+ return rc;
+}
+
+int
+host_hci_os_event_proc(struct os_event *ev)
+{
+ os_error_t err;
+ int rc;
+
+ rc = host_hci_event_rx(ev->ev_arg);
+
/* Free the command buffer */
err = os_memblock_put(&g_hci_cmd_pool, ev->ev_arg);
assert(err == OS_OK);
@@ -206,6 +215,8 @@ host_hci_event_proc(struct os_event *ev)
/* Free the event */
err = os_memblock_put(&g_hci_os_event_pool, ev);
assert(err == OS_OK);
+
+ return rc;
}
/* XXX: For now, put this here */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ed3c9be5/net/nimble/host/src/test/ble_host_hci_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_host_hci_test.c b/net/nimble/host/src/test/ble_host_hci_test.c
new file mode 100644
index 0000000..81d5890
--- /dev/null
+++ b/net/nimble/host/src/test/ble_host_hci_test.c
@@ -0,0 +1,120 @@
+/**
+ * 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 <stddef.h>
+#include <errno.h>
+#include <string.h>
+#include "nimble/hci_common.h"
+#include "host/host_hci.h"
+#include "host/ble_hs.h"
+#include "host/ble_hs_test.h"
+#include "ble_l2cap.h"
+#include "ble_hs_conn.h"
+#include "ble_hs_att.h"
+#include "ble_hs_att_cmd.h"
+#include "testutil/testutil.h"
+
+static void
+ble_host_hci_test_misc_build_cmd_complete(uint8_t *dst, int len,
+ uint8_t param_len, uint8_t num_pkts,
+ uint16_t opcode)
+{
+ TEST_ASSERT(len >= BLE_HCI_EVENT_CMD_COMPLETE_HDR_LEN);
+
+ dst[0] = BLE_HCI_EVCODE_COMMAND_COMPLETE;
+ dst[1] = 5 + param_len;
+ dst[2] = num_pkts;
+ htole16(dst + 3, opcode);
+}
+
+static void
+ble_host_hci_test_misc_build_cmd_status(uint8_t *dst, int len,
+ uint8_t status, uint8_t num_pkts,
+ uint16_t opcode)
+{
+ TEST_ASSERT(len >= BLE_HCI_EVENT_CMD_STATUS_LEN);
+
+ dst[0] = BLE_HCI_EVCODE_COMMAND_STATUS;
+ dst[1] = BLE_HCI_EVENT_CMD_STATUS_LEN;
+ dst[2] = num_pkts;
+ htole16(dst + 3, opcode);
+}
+
+TEST_CASE(ble_host_hci_test_event_bad)
+{
+ uint8_t buf[2];
+ int rc;
+
+ /*** Invalid event code. */
+ buf[0] = 0xff;
+ buf[1] = 0;
+ rc = host_hci_event_rx(buf);
+ TEST_ASSERT(rc == ENOTSUP);
+}
+
+TEST_CASE(ble_host_hci_test_event_cmd_complete)
+{
+ uint8_t buf[BLE_HCI_EVENT_CMD_COMPLETE_HDR_LEN];
+ int rc;
+
+ rc = ble_hs_init();
+ TEST_ASSERT_FATAL(rc == 0);
+
+ /*** Unsent OCF. */
+ ble_host_hci_test_misc_build_cmd_complete(buf, sizeof buf, 1, 1, 12345);
+ rc = host_hci_event_rx(buf);
+ TEST_ASSERT(rc == ENOENT);
+
+ /*** No error on NOP. */
+ ble_host_hci_test_misc_build_cmd_complete(buf, sizeof buf, 1, 1,
+ BLE_HCI_OPCODE_NOP);
+ rc = host_hci_event_rx(buf);
+ TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(ble_host_hci_test_event_cmd_status)
+{
+ uint8_t buf[BLE_HCI_EVENT_CMD_STATUS_LEN];
+ int rc;
+
+ rc = ble_hs_init();
+ TEST_ASSERT_FATAL(rc == 0);
+
+ /*** Unsent OCF. */
+ ble_host_hci_test_misc_build_cmd_status(buf, sizeof buf, 0, 1, 12345);
+ rc = host_hci_event_rx(buf);
+ TEST_ASSERT(rc == ENOENT);
+
+ /*** No error on NOP. */
+ ble_host_hci_test_misc_build_cmd_complete(buf, sizeof buf, 0, 1,
+ BLE_HCI_OPCODE_NOP);
+ rc = host_hci_event_rx(buf);
+ TEST_ASSERT(rc == 0);
+}
+
+TEST_SUITE(ble_host_hci_suite)
+{
+ ble_host_hci_test_event_bad();
+ ble_host_hci_test_event_cmd_complete();
+ ble_host_hci_test_event_cmd_status();
+}
+
+int
+ble_host_hci_test_all(void)
+{
+ ble_host_hci_suite();
+ return tu_any_failed;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ed3c9be5/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 a2ba713..3d517b1 100644
--- a/net/nimble/host/src/test/ble_hs_test.c
+++ b/net/nimble/host/src/test/ble_hs_test.c
@@ -27,6 +27,7 @@ main(void)
l2cap_test_all();
ble_hs_att_test_all();
+ ble_host_hci_test_all();
return tu_any_failed;
}