mynewt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ccoll...@apache.org
Subject [20/50] [abbrv] incubator-mynewt-core git commit: BLE host - Fix incorrect expiry issue
Date Thu, 10 Nov 2016 22:39:27 GMT
BLE host - Fix incorrect expiry issue

Sometimes an event expiry would get "dropped"; the event would not
expire at the appropriate time.  Instead, the event would expire late,
simultaneuous with the following event.

The bug was: a relative time was being compared against an absolute
time, yielding an incorrect result.


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

Branch: refs/heads/master
Commit: fcef18f37d3e9dd1c3069351db2093e693e495db
Parents: ed47568
Author: Christopher Collins <ccollins@apache.org>
Authored: Mon Nov 7 17:23:01 2016 -0800
Committer: Christopher Collins <ccollins@apache.org>
Committed: Tue Nov 8 13:28:34 2016 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_hs.c                |  5 ++++-
 net/nimble/host/test/src/ble_gap_test.c     | 14 +++++++-------
 net/nimble/host/test/src/ble_hs_adv_test.c  |  4 ++--
 net/nimble/host/test/src/ble_hs_conn_test.c |  6 ++++--
 net/nimble/host/test/src/ble_hs_test_util.c |  3 ++-
 net/nimble/host/test/src/ble_hs_test_util.h |  1 +
 net/nimble/host/test/src/ble_os_test.c      |  9 +++++++++
 7 files changed, 29 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fcef18f3/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 63b04ed..7f7383b 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -221,6 +221,8 @@ ble_hs_heartbeat_timer_reset(uint32_t ticks)
 void
 ble_hs_heartbeat_sched(int32_t ticks_from_now)
 {
+    os_time_t abs_time;
+
     if (ticks_from_now == BLE_HS_FOREVER) {
         return;
     }
@@ -228,8 +230,9 @@ ble_hs_heartbeat_sched(int32_t ticks_from_now)
     /* Reset heartbeat timer if it is not currently scheduled or if the
      * specified time is sooner than the current expiration time.
      */
+    abs_time = os_time_get() + ticks_from_now;
     if (!os_callout_queued(&ble_hs_heartbeat_timer) ||
-        OS_TIME_TICK_LT(ticks_from_now, ble_hs_heartbeat_timer.c_ticks)) {
+        OS_TIME_TICK_LT(abs_time, ble_hs_heartbeat_timer.c_ticks)) {
 
         ble_hs_heartbeat_timer_reset(ticks_from_now);
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fcef18f3/net/nimble/host/test/src/ble_gap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_gap_test.c b/net/nimble/host/test/src/ble_gap_test.c
index 1b531db..8acf2f2 100644
--- a/net/nimble/host/test/src/ble_gap_test.c
+++ b/net/nimble/host/test/src/ble_gap_test.c
@@ -1359,7 +1359,7 @@ ble_gap_test_util_adv(uint8_t own_addr_type, uint8_t peer_addr_type,
 
     if (fail_status == 0 || cmd_fail_idx >= cmd_idx) {
         rc = ble_hs_test_util_adv_start(own_addr_type, peer_addr_type,
-                                        peer_addr, &adv_params,
+                                        peer_addr, &adv_params, BLE_HS_FOREVER,
                                         ble_gap_test_util_connect_cb, NULL,
                                         cmd_fail_idx - cmd_idx, fail_status);
 
@@ -1433,7 +1433,7 @@ TEST_CASE(ble_gap_test_case_adv_bad_args)
     adv_params = ble_hs_test_util_adv_params;
     adv_params.disc_mode = 43;
     rc = ble_hs_test_util_adv_start(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
-                                    peer_addr, &adv_params,
+                                    peer_addr, &adv_params, BLE_HS_FOREVER,
                                     ble_gap_test_util_connect_cb, NULL, 0, 0);
     TEST_ASSERT(rc == BLE_HS_EINVAL);
     TEST_ASSERT(!ble_gap_adv_active());
@@ -1442,7 +1442,7 @@ TEST_CASE(ble_gap_test_case_adv_bad_args)
     adv_params = ble_hs_test_util_adv_params;
     adv_params.conn_mode = 27;
     rc = ble_hs_test_util_adv_start(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
-                                    peer_addr, &adv_params,
+                                    peer_addr, &adv_params, BLE_HS_FOREVER,
                                     ble_gap_test_util_connect_cb, NULL, 0, 0);
     TEST_ASSERT(rc == BLE_HS_EINVAL);
     TEST_ASSERT(!ble_gap_adv_active());
@@ -1451,7 +1451,7 @@ TEST_CASE(ble_gap_test_case_adv_bad_args)
     adv_params = ble_hs_test_util_adv_params;
     adv_params.conn_mode = BLE_GAP_CONN_MODE_DIR;
     rc = ble_hs_test_util_adv_start(BLE_ADDR_TYPE_PUBLIC, 12,
-                                    peer_addr, &adv_params,
+                                    peer_addr, &adv_params, BLE_HS_FOREVER,
                                     ble_gap_test_util_connect_cb, NULL, 0, 0);
     TEST_ASSERT(rc == BLE_HS_EINVAL);
     TEST_ASSERT(!ble_gap_adv_active());
@@ -1459,13 +1459,13 @@ TEST_CASE(ble_gap_test_case_adv_bad_args)
     /*** Advertising already in progress. */
     adv_params = ble_hs_test_util_adv_params;
     rc = ble_hs_test_util_adv_start(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
-                                    peer_addr, &adv_params,
+                                    peer_addr, &adv_params, BLE_HS_FOREVER,
                                     ble_gap_test_util_connect_cb, NULL, 0, 0);
     TEST_ASSERT(rc == 0);
     TEST_ASSERT(ble_gap_adv_active());
 
     rc = ble_hs_test_util_adv_start(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
-                                    peer_addr, &adv_params,
+                                    peer_addr, &adv_params, BLE_HS_FOREVER,
                                     ble_gap_test_util_connect_cb, NULL, 0, 0);
     TEST_ASSERT(rc == BLE_HS_EALREADY);
     TEST_ASSERT(ble_gap_adv_active());
@@ -1500,7 +1500,7 @@ ble_gap_test_util_adv_verify_dflt_params(uint8_t own_addr_type,
     adv_params.high_duty_cycle = 0;
 
     rc = ble_hs_test_util_adv_start(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
-                                    peer_addr, &adv_params,
+                                    peer_addr, &adv_params, BLE_HS_FOREVER,
                                     ble_gap_test_util_connect_cb, NULL, 0, 0);
     TEST_ASSERT_FATAL(rc == 0);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fcef18f3/net/nimble/host/test/src/ble_hs_adv_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_hs_adv_test.c b/net/nimble/host/test/src/ble_hs_adv_test.c
index beb8417..b441a84 100644
--- a/net/nimble/host/test/src/ble_hs_adv_test.c
+++ b/net/nimble/host/test/src/ble_hs_adv_test.c
@@ -155,7 +155,7 @@ ble_hs_adv_test_misc_tx_and_verify_data(
     TEST_ASSERT_FATAL(rc == 0);
 
     rc = ble_hs_test_util_adv_start(BLE_ADDR_TYPE_PUBLIC, 0, NULL, &adv_params,
-                                    NULL, NULL, 0, 0);
+                                    BLE_HS_FOREVER, NULL, NULL, 0, 0);
     TEST_ASSERT_FATAL(rc == 0);
 
     /* Discard the adv-enable command. */
@@ -169,7 +169,7 @@ ble_hs_adv_test_misc_tx_and_verify_data(
     TEST_ASSERT_FATAL(rc == 0);
 
     rc = ble_hs_test_util_adv_start(BLE_ADDR_TYPE_PUBLIC, 0, NULL, &adv_params,
-                                    NULL, NULL, 0, 0);
+                                    BLE_HS_FOREVER, NULL, NULL, 0, 0);
     TEST_ASSERT_FATAL(rc == 0);
 
     /* Discard the adv-enable command. */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fcef18f3/net/nimble/host/test/src/ble_hs_conn_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_hs_conn_test.c b/net/nimble/host/test/src/ble_hs_conn_test.c
index 0972350..4ba92d2 100644
--- a/net/nimble/host/test/src/ble_hs_conn_test.c
+++ b/net/nimble/host/test/src/ble_hs_conn_test.c
@@ -107,7 +107,8 @@ TEST_CASE(ble_hs_conn_test_direct_connectable_success)
     adv_params = ble_hs_test_util_adv_params;
     adv_params.conn_mode = BLE_GAP_CONN_MODE_DIR;
     rc = ble_hs_test_util_adv_start(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
-                                    addr, &adv_params, NULL, NULL, 0, 0);
+                                    addr, &adv_params, BLE_HS_FOREVER,
+                                    NULL, NULL, 0, 0);
     TEST_ASSERT(rc == 0);
 
     TEST_ASSERT(!ble_gap_master_in_progress());
@@ -167,7 +168,8 @@ TEST_CASE(ble_hs_conn_test_undirect_connectable_success)
     adv_params = ble_hs_test_util_adv_params;
     adv_params.conn_mode = BLE_GAP_CONN_MODE_UND;
     rc = ble_hs_test_util_adv_start(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
-                                    addr, &adv_params, NULL, NULL, 0, 0);
+                                    addr, &adv_params, BLE_HS_FOREVER,
+                                    NULL, NULL, 0, 0);
     TEST_ASSERT(rc == 0);
 
     TEST_ASSERT(!ble_gap_master_in_progress());

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fcef18f3/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 9afd660..58e3345 100644
--- a/net/nimble/host/test/src/ble_hs_test_util.c
+++ b/net/nimble/host/test/src/ble_hs_test_util.c
@@ -666,6 +666,7 @@ int
 ble_hs_test_util_adv_start(uint8_t own_addr_type,
                            uint8_t peer_addr_type, const uint8_t *peer_addr, 
                            const struct ble_gap_adv_params *adv_params,
+                           int32_t duration_ms,
                            ble_gap_event_fn *cb, void *cb_arg,
                            int fail_idx, uint8_t fail_status)
 {
@@ -706,7 +707,7 @@ ble_hs_test_util_adv_start(uint8_t own_addr_type,
     ble_hs_test_util_set_ack_seq(acks);
     
     rc = ble_gap_adv_start(own_addr_type, peer_addr_type, peer_addr, 
-                           BLE_HS_FOREVER, adv_params, cb, cb_arg);
+                           duration_ms, adv_params, cb, cb_arg);
 
     return rc;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fcef18f3/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 db4e94c..923be22 100644
--- a/net/nimble/host/test/src/ble_hs_test_util.h
+++ b/net/nimble/host/test/src/ble_hs_test_util.h
@@ -115,6 +115,7 @@ int ble_hs_test_util_adv_start(uint8_t own_addr_type,
                                uint8_t peer_addr_type,
                                const uint8_t *peer_addr,
                                const struct ble_gap_adv_params *adv_params,
+                               int32_t duration_ms,
                                ble_gap_event_fn *cb, void *cb_arg,
                                int fail_idx, uint8_t fail_status);
 int ble_hs_test_util_adv_stop(uint8_t hci_status);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fcef18f3/net/nimble/host/test/src/ble_os_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_os_test.c b/net/nimble/host/test/src/ble_os_test.c
index 067f0ac..7830242 100644
--- a/net/nimble/host/test/src/ble_os_test.c
+++ b/net/nimble/host/test/src/ble_os_test.c
@@ -62,8 +62,15 @@ ble_os_test_init_app_task(void)
 static void
 ble_os_test_misc_init(void)
 {
+    extern os_time_t g_os_time;
+
     ble_hs_test_util_init_no_start();
 
+    /* Allow the OS to approach tick rollover.  This will help ensure host
+     * timers don't break when the tick counter resets.
+     */
+    g_os_time = UINT32_MAX - 10 * OS_TICKS_PER_SEC;
+
     /* Receive acknowledgements for the startup sequence.  We sent the
      * corresponding requests when the host task was started.
      */
@@ -197,6 +204,8 @@ ble_os_disc_test_task_handler(void *arg)
      */
     cb_called = 0;
 
+    os_time_delay(10);
+
     /* Make sure there are no created connections and no connections in
      * progress.
      */


Mime
View raw message