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/13 04:45:10 UTC

incubator-mynewt-larva git commit: Basic GAP test with running OS.

Repository: incubator-mynewt-larva
Updated Branches:
  refs/heads/master 23fe06693 -> 069e95db7


Basic GAP test with running OS.


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/069e95db
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/069e95db
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/069e95db

Branch: refs/heads/master
Commit: 069e95db76d513ef5f3b479dcd8e6e5c6fa01868
Parents: 23fe066
Author: Christopher Collins <cc...@gmail.com>
Authored: Thu Nov 12 19:44:36 2015 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Thu Nov 12 19:44:36 2015 -0800

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_hs.h        |  2 +-
 net/nimble/host/include/host/ble_hs_test.h   |  1 +
 net/nimble/host/src/ble_hs.c                 | 17 +++-
 net/nimble/host/src/ble_hs_work.c            |  4 +
 net/nimble/host/src/test/ble_gap_test.c      | 95 +++++++++++++++++++++++
 net/nimble/host/src/test/ble_host_hci_test.c |  4 +-
 net/nimble/host/src/test/ble_hs_att_test.c   |  4 +-
 net/nimble/host/src/test/ble_hs_conn_test.c  |  6 +-
 net/nimble/host/src/test/ble_hs_test.c       |  1 +
 net/nimble/host/src/test/ble_l2cap_test.c    |  2 +-
 10 files changed, 125 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/069e95db/net/nimble/host/include/host/ble_hs.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_hs.h b/net/nimble/host/include/host/ble_hs.h
index 885ecb7..fcdd3d2 100644
--- a/net/nimble/host/include/host/ble_hs.h
+++ b/net/nimble/host/include/host/ble_hs.h
@@ -21,6 +21,6 @@
 
 void ble_hs_task_handler(void *arg);
 void ble_hs_kick(void);
-int ble_hs_init(void);
+int ble_hs_init(uint8_t prio);
 
 #endif /* _BLE_HOST_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/069e95db/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 b436601..cd4b396 100644
--- a/net/nimble/host/include/host/ble_hs_test.h
+++ b/net/nimble/host/include/host/ble_hs_test.h
@@ -21,6 +21,7 @@ int l2cap_test_all(void);
 int ble_hs_att_test_all(void);
 int ble_host_hci_test_all(void);
 int ble_hs_conn_test_all(void);
+int ble_gap_test_all(void);
 
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/069e95db/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 d50ef0c..9e5d47f 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -24,6 +24,16 @@
 #include "ble_hs_work.h"
 #include "ble_gap_conn.h"
 
+#ifdef ARCH_sim
+#define BLE_HS_STACK_SIZE   (1024)
+#else
+#define BLE_HS_STACK_SIZE   (128)
+#endif
+
+struct os_task ble_hs_task;
+os_stack_t ble_hs_stack[BLE_HS_STACK_SIZE];
+
+
 #define HCI_CMD_BUFS        (8)
 #define HCI_CMD_BUF_SIZE    (260)       /* XXX: temporary, Fix later */
 struct os_mempool g_hci_cmd_pool;
@@ -71,7 +81,7 @@ ble_hs_task_handler(void *arg)
             break;
         }
 
-        /* If a work event is not already in progress, and there is another
+        /* If a work event is not already in progress and there is another
          * event pending, begin processing it.
          */
         if (!ble_hs_work_busy) {
@@ -93,7 +103,7 @@ ble_hs_kick(void)
  * Initializes the host portion of the BLE stack.
  */
 int
-ble_hs_init(void)
+ble_hs_init(uint8_t prio)
 {
     int rc;
 
@@ -145,5 +155,8 @@ ble_hs_init(void)
     ble_hs_kick_ev.ev_type = BLE_HS_KICK_EVENT;
     ble_hs_kick_ev.ev_arg = NULL;
 
+    os_task_init(&ble_hs_task, "ble_hs", ble_hs_task_handler, NULL, prio,
+                 OS_WAIT_FOREVER, ble_hs_stack, BLE_HS_STACK_SIZE);
+
     return 0;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/069e95db/net/nimble/host/src/ble_hs_work.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_work.c b/net/nimble/host/src/ble_hs_work.c
index 5098420..ed54027 100644
--- a/net/nimble/host/src/ble_hs_work.c
+++ b/net/nimble/host/src/ble_hs_work.c
@@ -18,6 +18,7 @@
 #include <assert.h>
 #include <errno.h>
 #include "os/os.h"
+#include "host/ble_hs.h"
 #include "ble_gap_conn.h"
 #include "ble_hs_work.h"
 
@@ -42,6 +43,7 @@ void
 ble_hs_work_enqueue(struct ble_hs_work_entry *entry)
 {
     STAILQ_INSERT_TAIL(&ble_hs_work_queue, entry, bwe_next);
+    ble_hs_kick();
 }
 
 void
@@ -57,6 +59,8 @@ ble_hs_work_process_next(void)
         return;
     }
 
+    STAILQ_REMOVE_HEAD(&ble_hs_work_queue, bwe_next);
+
     switch (entry->bwe_type) {
     case BLE_HS_WORK_TYPE_DIRECT_CONNECT:
         rc = ble_gap_conn_direct_connect(

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/069e95db/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
new file mode 100644
index 0000000..ad15aeb
--- /dev/null
+++ b/net/nimble/host/src/test/ble_gap_test.c
@@ -0,0 +1,95 @@
+#include <string.h>
+#include "os/os.h"
+#include "testutil/testutil.h"
+#include "nimble/hci_common.h"
+#include "nimble/hci_transport.h"
+#include "host/ble_hs.h"
+#include "host/ble_hs_test.h"
+#include "ble_hs_test_util.h"
+#include "ble_hs_conn.h"
+#include "ble_hs_work.h"
+#include "ble_gap_conn.h"
+#include "ble_gap.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 void
+ble_gap_test_misc_rx_ack(uint16_t ocf, uint8_t status)
+{
+    uint16_t opcode;
+    uint8_t buf[BLE_HCI_EVENT_CMD_STATUS_LEN];
+    int rc;
+
+    opcode = (BLE_HCI_OGF_LE << 10) | ocf;
+    ble_hs_test_util_build_cmd_status(buf, sizeof buf, status, 1, opcode);
+
+    rc = ble_hci_transport_ctlr_event_send(buf);
+    TEST_ASSERT(rc == 0);
+}
+
+static void 
+ble_gap_test_task_handler(void *arg) 
+{
+    struct hci_le_conn_complete evt;
+    uint8_t addr[6] = { 1, 2, 3, 4, 5, 6 };
+    int rc;
+
+    TEST_ASSERT(!ble_hs_work_busy);
+    TEST_ASSERT(ble_hs_conn_first() == NULL);
+
+    ble_gap_direct_connection_establishment(0, addr);
+    TEST_ASSERT(ble_hs_work_busy);
+    TEST_ASSERT(ble_hs_conn_first() == NULL);
+
+    ble_gap_test_misc_rx_ack(BLE_HCI_OCF_LE_CREATE_CONN, 0);
+    TEST_ASSERT(!ble_hs_work_busy);
+    TEST_ASSERT(ble_hs_conn_first() == NULL);
+
+    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);
+
+    TEST_ASSERT(ble_hs_conn_find(2) != NULL);
+
+    tu_restart();
+}
+
+TEST_CASE(ble_gap_test_case)
+{
+    os_init();
+
+    os_task_init(&ble_gap_test_task, "ble_gap_test_task",
+                 ble_gap_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));
+
+    ble_hs_init(BLE_GAP_TEST_HS_PRIO);
+
+    os_start();
+}
+
+TEST_SUITE(ble_gap_test_suite)
+{
+    ble_gap_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/069e95db/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
index bf15a68..1b3fd74 100644
--- a/net/nimble/host/src/test/ble_host_hci_test.c
+++ b/net/nimble/host/src/test/ble_host_hci_test.c
@@ -45,7 +45,7 @@ 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();
+    rc = ble_hs_init(10);
     TEST_ASSERT_FATAL(rc == 0);
 
     /*** Unsent OCF. */
@@ -78,7 +78,7 @@ TEST_CASE(ble_host_hci_test_event_cmd_status)
     uint8_t buf[BLE_HCI_EVENT_CMD_STATUS_LEN];
     int rc;
 
-    rc = ble_hs_init();
+    rc = ble_hs_init(10);
     TEST_ASSERT_FATAL(rc == 0);
 
     /*** Unsent OCF. */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/069e95db/net/nimble/host/src/test/ble_hs_att_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_att_test.c b/net/nimble/host/src/test/ble_hs_att_test.c
index b33a3bb..dbd5624 100644
--- a/net/nimble/host/src/test/ble_hs_att_test.c
+++ b/net/nimble/host/src/test/ble_hs_att_test.c
@@ -145,7 +145,7 @@ TEST_CASE(ble_hs_att_test_read)
     uint8_t uuid[16] = {0};
     int rc;
 
-    rc = ble_hs_init();
+    rc = ble_hs_init(10);
     TEST_ASSERT_FATAL(rc == 0);
 
     ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
@@ -208,7 +208,7 @@ TEST_CASE(ble_hs_att_test_write)
     uint8_t uuid[16] = {0};
     int rc;
 
-    rc = ble_hs_init();
+    rc = ble_hs_init(10);
     TEST_ASSERT_FATAL(rc == 0);
 
     ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/069e95db/net/nimble/host/src/test/ble_hs_conn_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_conn_test.c b/net/nimble/host/src/test/ble_hs_conn_test.c
index ad2cbb1..e1e4108 100644
--- a/net/nimble/host/src/test/ble_hs_conn_test.c
+++ b/net/nimble/host/src/test/ble_hs_conn_test.c
@@ -36,7 +36,7 @@ TEST_CASE(ble_hs_conn_test_master_direct_success)
     uint8_t addr[6] = { 1, 2, 3, 4, 5, 6 };
     int rc;
 
-    rc = ble_hs_init();
+    rc = ble_hs_init(10);
     TEST_ASSERT_FATAL(rc == 0);
 
     /* Ensure no current or pending connections. */
@@ -75,7 +75,7 @@ TEST_CASE(ble_hs_conn_test_master_direct_hci_errors)
     uint8_t addr[6] = { 1, 2, 3, 4, 5, 6 };
     int rc;
 
-    rc = ble_hs_init();
+    rc = ble_hs_init(10);
     TEST_ASSERT_FATAL(rc == 0);
 
     /* Ensure no current or pending connections. */
@@ -116,7 +116,7 @@ TEST_CASE(ble_hs_conn_test_slave_direct_success)
     uint8_t addr[6] = { 1, 2, 3, 4, 5, 6 };
     int rc;
 
-    rc = ble_hs_init();
+    rc = ble_hs_init(10);
     TEST_ASSERT_FATAL(rc == 0);
 
     /* Ensure no current or pending connections. */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/069e95db/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 b013044..74338be 100644
--- a/net/nimble/host/src/test/ble_hs_test.c
+++ b/net/nimble/host/src/test/ble_hs_test.c
@@ -29,6 +29,7 @@ main(void)
     ble_hs_att_test_all();
     ble_host_hci_test_all();
     ble_hs_conn_test_all();
+    ble_gap_test_all();
 
     return tu_any_failed;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/069e95db/net/nimble/host/src/test/ble_l2cap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_l2cap_test.c b/net/nimble/host/src/test/ble_l2cap_test.c
index a1dd785..3162348 100644
--- a/net/nimble/host/src/test/ble_l2cap_test.c
+++ b/net/nimble/host/src/test/ble_l2cap_test.c
@@ -32,7 +32,7 @@ TEST_CASE(l2cap_test_bad_header)
     uint8_t pkt[8];
     int rc;
 
-    rc = ble_hs_init();
+    rc = ble_hs_init(10);
     TEST_ASSERT_FATAL(rc == 0);
 
     ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));