You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2017/04/11 22:45:33 UTC
[04/14] incubator-mynewt-core git commit: nimble/controller: Add
initial unit tests for controller
nimble/controller: Add initial unit tests for controller
This adds unit tests boilerplate and initial unit tests for controller.
Currently only tests for Channel Selection Algorithm #2 are implemented.
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/9cf07fda
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/9cf07fda
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/9cf07fda
Branch: refs/heads/bluetooth5
Commit: 9cf07fda600f04971bb894ff405d07ad80c588f3
Parents: 2566748
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Tue Apr 4 11:58:09 2017 +0200
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Fri Apr 7 13:59:51 2017 +0200
----------------------------------------------------------------------
.../controller/include/controller/ble_ll_conn.h | 3 +
.../controller/include/controller/ble_ll_test.h | 35 ++++++
net/nimble/controller/src/ble_ll_sched.c | 1 +
net/nimble/controller/src/ble_ll_xcvr.c | 1 +
net/nimble/controller/test/pkg.yml | 33 +++++
.../controller/test/src/ble_ll_csa2_test.c | 119 +++++++++++++++++++
net/nimble/controller/test/src/ble_ll_test.c | 40 +++++++
net/nimble/controller/test/syscfg.yml | 21 ++++
8 files changed, 253 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cf07fda/net/nimble/controller/include/controller/ble_ll_conn.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll_conn.h b/net/nimble/controller/include/controller/ble_ll_conn.h
index 041504d..6e6f6d8 100644
--- a/net/nimble/controller/include/controller/ble_ll_conn.h
+++ b/net/nimble/controller/include/controller/ble_ll_conn.h
@@ -284,6 +284,9 @@ struct ble_ll_conn_sm
*/
struct ble_ll_conn_sm *ble_ll_conn_find_active_conn(uint16_t handle);
+/* required for unit testing */
+uint8_t ble_ll_conn_calc_dci_csa2(struct ble_ll_conn_sm *conn);
+
#ifdef __cplusplus
}
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cf07fda/net/nimble/controller/include/controller/ble_ll_test.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll_test.h b/net/nimble/controller/include/controller/ble_ll_test.h
new file mode 100644
index 0000000..32984c6
--- /dev/null
+++ b/net/nimble/controller/include/controller/ble_ll_test.h
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+
+#ifndef H_LL_TEST_
+#define H_LL_TEST_
+
+#include <stddef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int ble_ll_csa2_test_all(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cf07fda/net/nimble/controller/src/ble_ll_sched.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_sched.c b/net/nimble/controller/src/ble_ll_sched.c
index 4713f3d..7637ac9 100644
--- a/net/nimble/controller/src/ble_ll_sched.c
+++ b/net/nimble/controller/src/ble_ll_sched.c
@@ -19,6 +19,7 @@
#include <stdint.h>
#include <assert.h>
#include <string.h>
+#include "bsp/bsp.h"
#include "os/os.h"
#include "os/os_cputime.h"
#include "ble/xcvr.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cf07fda/net/nimble/controller/src/ble_ll_xcvr.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_xcvr.c b/net/nimble/controller/src/ble_ll_xcvr.c
index 5718730..ca420e4 100644
--- a/net/nimble/controller/src/ble_ll_xcvr.c
+++ b/net/nimble/controller/src/ble_ll_xcvr.c
@@ -20,6 +20,7 @@
#include <stdint.h>
#include <stddef.h>
#include <assert.h>
+#include <stddef.h>
#include "syscfg/syscfg.h"
#include "os/os_cputime.h"
#include "controller/ble_phy.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cf07fda/net/nimble/controller/test/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/controller/test/pkg.yml b/net/nimble/controller/test/pkg.yml
new file mode 100644
index 0000000..11fe8ba
--- /dev/null
+++ b/net/nimble/controller/test/pkg.yml
@@ -0,0 +1,33 @@
+# 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.
+#
+pkg.name: net/nimble/controller/test
+pkg.type: unittest
+pkg.description: "NimBLE controller unit tests."
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+
+pkg.deps:
+ - test/testutil
+ - net/nimble/controller
+
+pkg.deps.SELFTEST:
+ - sys/console/stub
+ - sys/log/full
+ - sys/stats/stub
+ - net/nimble/transport/ram
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cf07fda/net/nimble/controller/test/src/ble_ll_csa2_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/test/src/ble_ll_csa2_test.c b/net/nimble/controller/test/src/ble_ll_csa2_test.c
new file mode 100644
index 0000000..3cf8101
--- /dev/null
+++ b/net/nimble/controller/test/src/ble_ll_csa2_test.c
@@ -0,0 +1,119 @@
+/*
+ * 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 <stddef.h>
+#include <string.h>
+#include "testutil/testutil.h"
+#include "controller/ble_ll_test.h"
+#include "controller/ble_ll_conn.h"
+
+TEST_CASE(ble_ll_csa2_test_1)
+{
+ struct ble_ll_conn_sm conn;
+ uint8_t rc;
+
+ /*
+ * Note: This test only verified mapped channel. Sample data also specifies
+ * prn_e and unmapped channel values but those would require extra access
+ * to internal state of algorithm which is not exposed.
+ */
+
+ memset(&conn, 0, sizeof(conn));
+
+ /*
+ * based on sample data from CoreSpec 5.0 Vol 6 Part C 3.1
+ * (all channels used)
+ */
+ conn.channel_id = ((0x8e89bed6 & 0xffff0000) >> 16) ^
+ (0x8e89bed6 & 0x0000ffff);
+
+ conn.num_used_chans = 37;
+ conn.chanmap[0] = 0xff;
+ conn.chanmap[1] = 0xff;
+ conn.chanmap[2] = 0xff;
+ conn.chanmap[3] = 0xff;
+ conn.chanmap[3] = 0x1f;
+
+ conn.event_cntr = 1;
+ rc = ble_ll_conn_calc_dci_csa2(&conn);
+ TEST_ASSERT(rc == 20);
+
+ conn.event_cntr = 2;
+ rc = ble_ll_conn_calc_dci_csa2(&conn);
+ TEST_ASSERT(rc == 6);
+
+ conn.event_cntr = 3;
+ rc = ble_ll_conn_calc_dci_csa2(&conn);
+ TEST_ASSERT(rc == 21);
+}
+
+TEST_CASE(ble_ll_csa2_test_2)
+{
+ struct ble_ll_conn_sm conn;
+ uint8_t rc;
+
+ /*
+ * Note: This test only verified mapped channel. Sample data also specifies
+ * prn_e and unmapped channel values but those would require extra access
+ * to internal state of algorithm which is not exposed.
+ */
+
+ memset(&conn, 0, sizeof(conn));
+
+ /*
+ * based on sample data from CoreSpec 5.0 Vol 6 Part C 3.2
+ * (9 channels used)
+ */
+ conn.channel_id = ((0x8e89bed6 & 0xffff0000) >> 16) ^
+ (0x8e89bed6 & 0x0000ffff);
+
+ conn.num_used_chans = 9;
+ conn.chanmap[0] = 0x00;
+ conn.chanmap[1] = 0x06;
+ conn.chanmap[2] = 0xe0;
+ conn.chanmap[3] = 0x00;
+ conn.chanmap[4] = 0x1e;
+
+ conn.event_cntr = 6;
+ rc = ble_ll_conn_calc_dci_csa2(&conn);
+ TEST_ASSERT(rc == 23);
+
+ conn.event_cntr = 7;
+ rc = ble_ll_conn_calc_dci_csa2(&conn);
+ TEST_ASSERT(rc == 9);
+
+ conn.event_cntr = 8;
+ rc = ble_ll_conn_calc_dci_csa2(&conn);
+ TEST_ASSERT(rc == 34);
+}
+
+TEST_SUITE(ble_ll_csa2_test_suite)
+{
+ ble_ll_csa2_test_1();
+ ble_ll_csa2_test_2();
+}
+
+int
+ble_ll_csa2_test_all(void)
+{
+ ble_ll_csa2_test_1();
+ ble_ll_csa2_test_2();
+
+ return tu_any_failed;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cf07fda/net/nimble/controller/test/src/ble_ll_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/test/src/ble_ll_test.c b/net/nimble/controller/test/src/ble_ll_test.c
new file mode 100644
index 0000000..d18f26a
--- /dev/null
+++ b/net/nimble/controller/test/src/ble_ll_test.c
@@ -0,0 +1,40 @@
+/*
+ * 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 "syscfg/syscfg.h"
+#include "controller/ble_ll_test.h"
+#include "os/os.h"
+#include "testutil/testutil.h"
+
+#if MYNEWT_VAL(SELFTEST)
+
+int
+main(int argc, char **argv)
+{
+ ts_config.ts_print_results = 1;
+ tu_parse_args(argc, argv);
+
+ tu_init();
+
+ ble_ll_csa2_test_all();
+
+ return tu_any_failed;
+}
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cf07fda/net/nimble/controller/test/syscfg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/controller/test/syscfg.yml b/net/nimble/controller/test/syscfg.yml
new file mode 100644
index 0000000..47a61a2
--- /dev/null
+++ b/net/nimble/controller/test/syscfg.yml
@@ -0,0 +1,21 @@
+# 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.
+#
+
+# Package: net/nimble/controller/test
+
+syscfg.vals: