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 2017/05/18 23:59:17 UTC
[5/9] incubator-mynewt-core git commit: MYNEWT-754 BLE Host - Basic
store util unit tests.
MYNEWT-754 BLE Host - Basic store util unit tests.
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/fd6da967
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/fd6da967
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/fd6da967
Branch: refs/heads/master
Commit: fd6da967a98574e0593508217b1eca8c26f97ac5
Parents: 507773f
Author: Christopher Collins <cc...@apache.org>
Authored: Thu May 11 17:16:16 2017 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu May 11 18:04:41 2017 -0700
----------------------------------------------------------------------
net/nimble/host/include/host/ble_hs_test.h | 1 +
net/nimble/host/test/src/ble_hs_test.c | 3 +-
net/nimble/host/test/src/ble_store_test.c | 172 ++++++++++++++++++++++++
3 files changed, 175 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fd6da967/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 4e15ffd..da4a5b8 100644
--- a/net/nimble/host/include/host/ble_hs_test.h
+++ b/net/nimble/host/include/host/ble_hs_test.h
@@ -48,6 +48,7 @@ int ble_os_test_all(void);
int ble_sm_lgcy_test_suite(void);
int ble_sm_sc_test_suite(void);
int ble_sm_test_all(void);
+int ble_store_test_all(void);
int ble_uuid_test_all(void);
#ifdef __cplusplus
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fd6da967/net/nimble/host/test/src/ble_hs_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_hs_test.c b/net/nimble/host/test/src/ble_hs_test.c
index 132efb7..4e232f0 100644
--- a/net/nimble/host/test/src/ble_hs_test.c
+++ b/net/nimble/host/test/src/ble_hs_test.c
@@ -47,12 +47,13 @@ main(int argc, char **argv)
ble_gatts_notify_test_all();
ble_gatts_read_test_suite();
ble_gatts_reg_test_all();
- ble_hs_hci_test_all();
ble_hs_adv_test_all();
ble_hs_conn_test_all();
+ ble_hs_hci_test_all();
ble_l2cap_test_all();
ble_os_test_all();
ble_sm_test_all();
+ ble_store_test_all();
ble_uuid_test_all();
return tu_any_failed;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fd6da967/net/nimble/host/test/src/ble_store_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_store_test.c b/net/nimble/host/test/src/ble_store_test.c
new file mode 100644
index 0000000..d89a66d
--- /dev/null
+++ b/net/nimble/host/test/src/ble_store_test.c
@@ -0,0 +1,172 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 "testutil/testutil.h"
+#include "host/ble_hs_test.h"
+#include "ble_hs_test_util.h"
+
+static void
+ble_store_test_util_verify_peer_deleted(const ble_addr_t *addr)
+{
+ union ble_store_value value;
+ union ble_store_key key;
+ ble_addr_t addrs[64];
+ int num_addrs;
+ int rc;
+ int i;
+
+ memset(&key, 0, sizeof key);
+ key.sec.peer_addr = *addr;
+ rc = ble_store_read(BLE_STORE_OBJ_TYPE_OUR_SEC, &key, &value);
+ TEST_ASSERT(rc == BLE_HS_ENOENT);
+ rc = ble_store_read(BLE_STORE_OBJ_TYPE_PEER_SEC, &key, &value);
+ TEST_ASSERT(rc == BLE_HS_ENOENT);
+
+ memset(&key, 0, sizeof key);
+ key.cccd.peer_addr = *addr;
+ rc = ble_store_read(BLE_STORE_OBJ_TYPE_CCCD, &key, &value);
+ TEST_ASSERT(rc == BLE_HS_ENOENT);
+
+ rc = ble_store_util_bonded_peers(addrs, &num_addrs,
+ sizeof addrs / sizeof addrs[0]);
+ TEST_ASSERT_FATAL(rc == 0);
+ for (i = 0; i < num_addrs; i++) {
+ TEST_ASSERT(ble_addr_cmp(addr, addrs + i) != 0);
+ }
+}
+
+TEST_CASE(ble_store_test_peers)
+{
+ struct ble_store_value_sec secs[4] = {
+ {
+ .peer_addr = { BLE_ADDR_PUBLIC, { 1, 2, 3, 4, 5, 6 } },
+ .ltk_present = 1,
+ },
+ {
+ /* Address value is a duplicate of above, but type differs. */
+ .peer_addr = { BLE_ADDR_RANDOM, { 1, 2, 3, 4, 5, 6 } },
+ .ltk_present = 1,
+ },
+ {
+ .peer_addr = { BLE_ADDR_PUBLIC, { 2, 3, 4, 5, 6, 7 } },
+ .ltk_present = 1,
+ },
+ {
+ .peer_addr = { BLE_ADDR_RANDOM, { 3, 4, 5, 6, 7, 8 } },
+ .ltk_present = 1,
+ },
+ };
+ ble_addr_t peer_addrs[4];
+ int num_addrs;
+ int rc;
+ int i;
+
+ for (i = 0; i < sizeof secs / sizeof secs[0]; i++) {
+ rc = ble_store_write_our_sec(secs + i);
+ TEST_ASSERT_FATAL(rc == 0);
+ rc = ble_store_write_peer_sec(secs + i);
+ TEST_ASSERT_FATAL(rc == 0);
+ }
+
+ rc = ble_store_util_bonded_peers(peer_addrs, &num_addrs,
+ sizeof peer_addrs / sizeof peer_addrs[0]);
+ TEST_ASSERT_FATAL(rc == 0);
+
+ TEST_ASSERT(num_addrs == sizeof secs / sizeof secs[0]);
+ for (i = 0; i < num_addrs; i++) {
+ TEST_ASSERT(ble_addr_cmp(&peer_addrs[i], &secs[i].peer_addr) == 0);
+ }
+}
+
+TEST_CASE(ble_store_test_delete_peer)
+{
+ struct ble_store_value_sec secs[2] = {
+ {
+ .peer_addr = { BLE_ADDR_PUBLIC, { 1, 2, 3, 4, 5, 6 } },
+ .ltk_present = 1,
+ },
+ {
+ /* Address value is a duplicate of above, but type differs. */
+ .peer_addr = { BLE_ADDR_RANDOM, { 1, 2, 3, 4, 5, 6 } },
+ .ltk_present = 1,
+ },
+ };
+ struct ble_store_value_cccd cccds[3] = {
+ /* First two belong to first peer. */
+ {
+ .peer_addr = secs[0].peer_addr,
+ .chr_val_handle = 5,
+ },
+ {
+ .peer_addr = secs[0].peer_addr,
+ .chr_val_handle = 8,
+ },
+
+ /* Last belongs to second peer. */
+ {
+ .peer_addr = secs[1].peer_addr,
+ .chr_val_handle = 5,
+ },
+ };
+
+ int rc;
+ int i;
+
+ for (i = 0; i < sizeof secs / sizeof secs[0]; i++) {
+ rc = ble_store_write_our_sec(secs + i);
+ TEST_ASSERT_FATAL(rc == 0);
+ rc = ble_store_write_peer_sec(secs + i);
+ TEST_ASSERT_FATAL(rc == 0);
+ }
+
+ for (i = 0; i < sizeof cccds / sizeof cccds[0]; i++) {
+ rc = ble_store_write_cccd(cccds + i);
+ TEST_ASSERT_FATAL(rc == 0);
+ }
+
+ /* Delete first peer. */
+ rc = ble_store_util_delete_peer(&secs[0].peer_addr);
+ TEST_ASSERT_FATAL(rc == 0);
+
+ /* Ensure all traces of first peer have been removed. */
+ ble_store_test_util_verify_peer_deleted(&secs[0].peer_addr);
+
+ /* Delete second peer. */
+ rc = ble_store_util_delete_peer(&secs[1].peer_addr);
+ TEST_ASSERT_FATAL(rc == 0);
+
+ /* Ensure all traces of first peer have been removed. */
+ ble_store_test_util_verify_peer_deleted(&secs[1].peer_addr);
+}
+
+TEST_SUITE(ble_store_suite)
+{
+ tu_suite_set_post_test_cb(ble_hs_test_util_post_test, NULL);
+
+ ble_store_test_peers();
+ ble_store_test_delete_peer();
+}
+
+int
+ble_store_test_all(void)
+{
+ ble_store_suite();
+
+ return tu_any_failed;
+}