[04/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/test/src/ble_sm_test_util.c
--
diff --git a/net/nimble/host/test/src/ble_sm_test_util.c 
b/net/nimble/host/test/src/ble_sm_test_util.c
new file mode 100644
index 000..51dde82
--- /dev/null
+++ b/net/nimble/host/test/src/ble_sm_test_util.c
@@ -0,0 +1,2410 @@
+/**
+ * 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 
+#include 
+#include 
+#include "testutil/testutil.h"
+#include "nimble/hci_common.h"
+#include "nimble/nimble_opt.h"
+#include "host/ble_sm.h"
+#include "host/ble_hs_test.h"
+#include "host/ble_hs_id.h"
+#include "ble_hs_test_util.h"
+#include "ble_sm_test_util.h"
+
+int ble_sm_test_gap_event_type;
+int ble_sm_test_gap_status;
+struct ble_gap_sec_state ble_sm_test_sec_state;
+
+int ble_sm_test_store_obj_type;
+union ble_store_key ble_sm_test_store_key;
+union ble_store_value ble_sm_test_store_value;
+
+static ble_store_read_fn ble_sm_test_util_store_read;
+static ble_store_write_fn ble_sm_test_util_store_write;
+
+struct ble_sm_test_util_entity {
+uint8_t addr_type;
+uint8_t id_addr_type;
+uint8_t *id_addr;
+uint8_t *rpa;
+
+struct ble_sm_pair_cmd *pair_cmd;
+struct ble_sm_pair_confirm *confirms;
+struct ble_sm_pair_random *randoms;
+struct ble_sm_id_info *id_info;
+struct ble_sm_id_addr_info *id_addr_info;
+struct ble_sm_sign_info *sign_info;
+uint8_t *ltk;
+
+uint8_t key_dist;
+
+/*** Secure connections fields. */
+struct ble_sm_public_key *public_key;
+struct ble_sm_dhkey_check *dhkey_check;
+
+/*** Legacy fields. */
+struct ble_sm_enc_info *enc_info;
+struct ble_sm_master_id *master_id;
+uint64_t rand_num;
+uint16_t ediv;
+};
+
+#define BLE_SM_TEST_UTIL_HCI_HDR(handle, pb, len) \
+((struct hci_data_hdr) {\
+.hdh_handle_pb_bc = ((handle)  << 0) |  \
+((pb)  << 12),  \
+.hdh_len = (len)\
+})
+
+static int
+ble_sm_test_util_store_read(int obj_type, union ble_store_key *key,
+  union ble_store_value *val)
+{
+ble_sm_test_store_obj_type = obj_type;
+ble_sm_test_store_key = *key;
+
+return ble_hs_test_util_store_read(obj_type, key, val);
+}
+
+static int
+ble_sm_test_util_store_write(int obj_type, union ble_store_value *val)
+{
+ble_sm_test_store_obj_type = obj_type;
+ble_sm_test_store_value = *val;
+
+return ble_hs_test_util_store_write(obj_type, val);
+}
+
+void
+ble_sm_test_util_init(void)
+{
+ble_hs_test_util_init();
+ble_hs_test_util_store_init(10, 10, 10);
+ble_hs_cfg.store_read_cb = ble_sm_test_util_store_read;
+ble_hs_cfg.store_write_cb = ble_sm_test_util_store_write;
+
+ble_sm_test_store_obj_type = -1;
+ble_sm_test_gap_event_type = -1;
+ble_sm_test_gap_status = -1;
+
+memset(_sm_test_sec_state, 0xff, sizeof ble_sm_test_sec_state);
+}
+
+static void
+ble_sm_test_util_params_to_entity(struct ble_sm_test_params *params,
+  int initiator,
+  struct ble_sm_test_util_entity *out_entity)
+{
+int sc;
+
+memset(out_entity, 0, sizeof *out_entity);
+
+sc = params->pair_req.authreq & BLE_SM_PAIR_AUTHREQ_SC &&
+ params->pair_rsp.authreq & BLE_SM_PAIR_AUTHREQ_SC;
+
+if (initiator) {
+out_entity->key_dist = params->pair_rsp.init_key_dist;
+
+out_entity->addr_type = params->init_addr_type;
+out_entity->id_addr = params->init_id_addr;
+out_entity->rpa = params->init_rpa;
+
+out_entity->pair_cmd = >pair_req;
+out_entity->confirms = params->confirm_req;
+out_entity->randoms = params->random_req;
+out_entity->id_info = >id_info_rsp;
+out_entity->id_addr_info = >id_addr_info_rsp;
+out_entity->sign_info = >sign_info_rsp;
+
+if (sc) {
+out_entity->ltk = params->ltk;
+out_entity->public_key = >public_key_req;
+out_entity->dhkey_check = >dhkey_check_req;
+} else {
+

[28/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/os/src/test/sem_test.c
--
diff --git a/libs/os/src/test/sem_test.c b/libs/os/src/test/sem_test.c
deleted file mode 100644
index ec79185..000
--- a/libs/os/src/test/sem_test.c
+++ /dev/null
@@ -1,401 +0,0 @@
-/**
- * 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 
-#include 
-#include "testutil/testutil.h"
-#include "os/os.h"
-#include "os/os_cfg.h"
-#include "os/os_sem.h"
-#include "os_test_priv.h"
-
-#ifdef ARCH_sim
-#define SEM_TEST_STACK_SIZE 1024
-#else 
-#define SEM_TEST_STACK_SIZE 512
-#endif
-
-struct os_task task1;
-os_stack_t stack1[OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)];
-
-struct os_task task2;
-os_stack_t stack2[OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)];
-
-struct os_task task3;
-os_stack_t stack3[OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)];
-
-struct os_task task4;
-os_stack_t stack4[OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)];
-
-#define TASK1_PRIO (1) 
-#define TASK2_PRIO (2) 
-#define TASK3_PRIO (3) 
-#define TASK4_PRIO (4) 
-
-struct os_sem g_sem1;
-
-/* 
- * TEST NUMBERS:
- *  10: In this test we have the highest priority task getting the semaphore
- *  then sleeping. Two lower priority tasks then wake up and attempt to get
- *  the semaphore. They are blocked until the higher priority task releases
- *  the semaphore, at which point the lower priority tasks should wake up in
- *  order, get the semaphore, then release it and go back to sleep.
- * 
- */
-
-/**
- * sem test disp sem
- *  
- * Display semaphore contents 
- * 
- * @param sem 
- */
-static const char *
-sem_test_sem_to_s(const struct os_sem *sem)
-{
-static char buf[128];
-
-snprintf(buf, sizeof buf, "\tSemaphore: tokens=%u head=%p",
- sem->sem_tokens, SLIST_FIRST(>sem_head));
-
-return buf;
-}
-
-static void 
-sem_test_sleep_task_handler(void *arg)
-{
-struct os_task *t;
-
-t = os_sched_get_current_task();
-TEST_ASSERT(t->t_func == sem_test_sleep_task_handler);
-
-os_time_delay(2000);
-os_test_restart();
-}
-
-static void
-sem_test_pend_release_loop(int delay, int timeout, int itvl)
-{
-os_error_t err;
-
-os_time_delay(delay);
-
-while (1) {
-err = os_sem_pend(_sem1, timeout);
-TEST_ASSERT((err == OS_OK) || (err == OS_TIMEOUT));
-
-err = os_sem_release(_sem1);
-TEST_ASSERT(err == OS_OK);
-
-os_time_delay(itvl);
-}
-}
-
-/**
- * sem test basic 
- *  
- * Basic semaphore tests
- * 
- * @return int 
- */
-static void 
-sem_test_basic_handler(void *arg)
-{
-struct os_task *t;
-struct os_sem *sem;
-os_error_t err;
-
-sem = _sem1;
-t = os_sched_get_current_task();
-
-/* Test some error cases */
-TEST_ASSERT(os_sem_init(NULL, 1)== OS_INVALID_PARM);
-TEST_ASSERT(os_sem_release(NULL)== OS_INVALID_PARM);
-TEST_ASSERT(os_sem_pend(NULL, 1)== OS_INVALID_PARM);
-
-/* Get the semaphore */
-err = os_sem_pend(sem, 0);
-TEST_ASSERT(err == 0,
-"Did not get free semaphore immediately (err=%d)", err);
-
-/* Check semaphore internals */
-TEST_ASSERT(sem->sem_tokens == 0 && SLIST_EMPTY(>sem_head),
-"Semaphore internals wrong after getting semaphore\n"
-"%s\n"
-"Task: task=%p prio=%u", sem_test_sem_to_s(sem), t, t->t_prio);
-
-/* Get the semaphore again; should fail */
-err = os_sem_pend(sem, 0);
-TEST_ASSERT(err == OS_TIMEOUT,
-"Did not time out waiting for semaphore (err=%d)", err);
-
-/* Check semaphore internals */
-TEST_ASSERT(sem->sem_tokens == 0 && SLIST_EMPTY(>sem_head),
-"Semaphore internals wrong after getting semaphore\n"
-"%s\n"
-"Task: task=%p prio=%u\n", sem_test_sem_to_s(sem), t,
-t->t_prio);
-
-/* Release semaphore */
-err = os_sem_release(sem);
-TEST_ASSERT(err == 0,
-"Could not release semaphore I own (err=%d)", err);
-
-/* Check semaphore internals */
-TEST_ASSERT(sem->sem_tokens == 1 && SLIST_EMPTY(>sem_head),
-"Semaphore internals wrong after 

[17/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/test/ble_sm_sc_test.c
--
diff --git a/net/nimble/host/src/test/ble_sm_sc_test.c 
b/net/nimble/host/src/test/ble_sm_sc_test.c
deleted file mode 100644
index 518720c..000
--- a/net/nimble/host/src/test/ble_sm_sc_test.c
+++ /dev/null
@@ -1,4910 +0,0 @@
-/**
- * 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 
-#include 
-#include 
-#include "testutil/testutil.h"
-#include "nimble/hci_common.h"
-#include "nimble/nimble_opt.h"
-#include "host/ble_sm.h"
-#include "host/ble_hs_test.h"
-#include "ble_hs_test_util.h"
-#include "ble_sm_test_util.h"
-
-#if NIMBLE_OPT(SM)
-
-/**
- * Secure connections pairing
- * Master: peer
- * Pair algorithm: just works
- * Initiator IO capabilities: 3
- * Responder IO capabilities: 3
- * Bonding: true
- * Initiator address type: 0
- * Responder address type: 0
- * Initiator key distribution: 5
- * Responder key distribution: 7
- */
-TEST_CASE(ble_sm_sc_peer_jw_iio3_rio3_b1_iat0_rat0_ik5_rk7)
-{
-struct ble_sm_test_params params;
-
-params = (struct ble_sm_test_params) {
-.init_id_addr = {
-0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0,
-},
-.resp_id_addr = {
-0x33, 0x22, 0x11, 0x00, 0x45, 0x0a,
-},
-.pair_req = {
-.io_cap = 0x03,
-.oob_data_flag = 0x00,
-.authreq = 0x09,
-.max_enc_key_size = 0x10,
-.init_key_dist = 0x0d,
-.resp_key_dist = 0x0f,
-},
-.pair_rsp = {
-.io_cap = 0x03,
-.oob_data_flag = 0x00,
-.authreq = 0x09,
-.max_enc_key_size = 0x10,
-.init_key_dist = 0x05,
-.resp_key_dist = 0x07,
-},
-.our_priv_key = {
-0x54, 0x8d, 0x20, 0xb8, 0x97, 0x0b, 0xbc, 0x43,
-0x9a, 0xad, 0x10, 0x6f, 0x60, 0x74, 0xd4, 0x6a,
-0x55, 0xc1, 0x7a, 0x17, 0x8b, 0x60, 0xe0, 0xb4,
-0x5a, 0xe6, 0x58, 0xf1, 0xea, 0x12, 0xd9, 0xfb,
-},
-.public_key_req = {
-.x = {
-0xbc, 0xf2, 0xd8, 0xa5, 0xdb, 0xa3, 0x95, 0x6c,
-0x99, 0xf9, 0x11, 0x0d, 0x4d, 0x2e, 0xf0, 0xbd,
-0xee, 0x9b, 0x69, 0xb6, 0xcd, 0x88, 0x74, 0xbe,
-0x40, 0xe8, 0xe5, 0xcc, 0xdc, 0x88, 0x44, 0x53,
-},
-.y = {
-0xbf, 0xa9, 0x82, 0x0e, 0x18, 0x7a, 0x14, 0xf8,
-0x77, 0xfd, 0x8e, 0x92, 0x2a, 0xf8, 0x5d, 0x39,
-0xd1, 0x6d, 0x92, 0x1f, 0x38, 0x74, 0x99, 0xdc,
-0x6c, 0x2c, 0x94, 0x23, 0xf9, 0x72, 0x56, 0xab,
-},
-},
-.public_key_rsp = {
-.x = {
-0x72, 0x8c, 0xd1, 0x88, 0xd7, 0xbe, 0x49, 0xb2,
-0xc5, 0x5c, 0x95, 0xb3, 0x64, 0xe0, 0x12, 0x32,
-0xb6, 0xc9, 0x47, 0x63, 0x37, 0x38, 0x5b, 0x9c,
-0x1e, 0x1b, 0x1a, 0x06, 0x09, 0xe2, 0x31, 0x85,
-},
-.y = {
-0x19, 0x3a, 0x29, 0x69, 0x62, 0xd6, 0x30, 0xe7,
-0xe8, 0x48, 0x63, 0xdc, 0x00, 0x73, 0x0a, 0x70,
-0x7d, 0x2e, 0x29, 0xcc, 0x91, 0x77, 0x71, 0xb1,
-0x75, 0xb8, 0xf7, 0xdc, 0xb0, 0xe2, 0x91, 0x10,
-},
-},
-.confirm_rsp[0] = {
-.value = {
-0x82, 0xed, 0xd0, 0x62, 0x91, 0x3d, 0x96, 0x7f,
-0x13, 0xc5, 0x0d, 0x02, 0x2b, 0x5e, 0x43, 0x16,
-},
-},
-.random_req[0] = {
-.value = {
-0xa4, 0x34, 0x5f, 0xb3, 0xaf, 0x73, 0x43, 0x64,
-0xcd, 0x19, 0x1b, 0x5b, 0x87, 0x58, 0x31, 0x66,
-},
-},
-.random_rsp[0] = {
-.value = {
-0xc0, 0x91, 0xfb, 0xb3, 0x77, 0xa2, 0x02, 0x0b,
-0xc6, 0xcd, 0x6c, 0x04, 0x51, 0x45, 0x45, 0x39,
-},
-},
-.dhkey_check_req = {
-.value = {
-0x82, 0x65, 0x1d, 0x02, 0xed, 0x89, 0x13, 0x44,
-0x04, 0x1a, 0x14, 0x7c, 0x32, 0x9a, 0x1e, 0x7d,
- 

[41/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
syscfg / sysinit


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

Branch: refs/heads/sterly_refactor
Commit: d98ddc1c5e877d18e5ac68b6d342cf39ba068b20
Parents: fdd134d
Author: Christopher Collins 
Authored: Mon Sep 12 19:49:17 2016 -0700
Committer: Christopher Collins 
Committed: Mon Sep 12 20:39:09 2016 -0700

--
 apps/blecent/pkg.yml|4 +-
 apps/blecent/src/main.c |   94 +-
 apps/blehci/src/main.c  |   52 +-
 apps/bleprph/pkg.yml|   20 +-
 apps/bleprph/src/bleprph.h  |2 +-
 apps/bleprph/src/gatt_svr.c |4 +-
 apps/bleprph/src/main.c |  125 +-
 apps/bletest/pkg.yml|4 +
 apps/bletest/src/bletest_hci.c  |6 +-
 apps/bletest/src/bletest_priv.h |2 +-
 apps/bletest/src/main.c |  129 +-
 apps/bletiny/pkg.yml|   12 +-
 apps/bletiny/src/bletiny.h  |4 +-
 apps/bletiny/src/cmd.c  |4 +-
 apps/bletiny/src/gatt_svr.c |4 +-
 apps/bletiny/src/main.c |  123 +-
 apps/bleuart/pkg.yml|6 +-
 apps/bleuart/src/main.c |  101 +-
 apps/blinky/src/main.c  |  114 +-
 apps/boot/pkg.yml   |   36 +-
 apps/boot/src/boot.c|   16 +-
 apps/ffs2native/src/main.c  |   14 +-
 apps/luatest/src/main.c |   55 +-
 apps/sblinky/pkg.yml|   12 -
 apps/sblinky/src/main.c |   72 +-
 apps/slinky/pkg.yml |   10 +-
 apps/slinky/src/main.c  |  117 +-
 apps/test/pkg.yml   |2 -
 drivers/adc/adc_nrf51/pkg.yml   |7 +-
 drivers/adc/adc_nrf52/pkg.yml   |7 +-
 drivers/adc/pkg.yml |4 -
 drivers/uart/pkg.yml|1 -
 fs/fs/pkg.yml   |   12 +-
 fs/fs/src/fs_cli.c  |6 +-
 fs/fs/src/fs_mount.c|8 +-
 fs/fs/src/fs_priv.h |6 +-
 fs/nffs/include/nffs/nffs.h |3 +
 fs/nffs/pkg.yml |   10 +-
 fs/nffs/src/nffs.c  |   54 +-
 fs/nffs/src/nffs_misc.c |   70 +
 fs/nffs/src/nffs_priv.h |3 +
 fs/nffs/src/nffs_restore.c  |2 +-
 fs/nffs/src/test/arch/cortex_m4/nffs_test.c |   27 -
 fs/nffs/src/test/arch/sim/nffs_test.c   | 3250 -
 fs/nffs/src/test/arch/sim/nffs_test_priv.h  |   42 -
 fs/nffs/src/test/arch/sim/nffs_test_system_01.c | 6537 --
 fs/nffs/test/pkg.yml|   30 +
 fs/nffs/test/src/arch/cortex_m4/nffs_test.c |   27 +
 fs/nffs/test/src/arch/sim/nffs_test.c   | 3251 +
 fs/nffs/test/src/arch/sim/nffs_test_priv.h  |   42 +
 fs/nffs/test/src/arch/sim/nffs_test_system_01.c | 6537 ++
 hw/bsp/arduino_primo_nrf52/pkg.yml  |   59 +-
 hw/bsp/bmd300eval/pkg.yml   |   57 +-
 hw/bsp/native/pkg.yml   |3 +-
 hw/bsp/native/src/hal_bsp.c |   75 -
 hw/bsp/nrf51-arduino_101/pkg.yml|   55 +-
 hw/bsp/nrf51-blenano/pkg.yml|   55 +-
 hw/bsp/nrf51dk-16kbram/pkg.yml  |   56 +-
 hw/bsp/nrf51dk/pkg.yml  |   52 +-
 hw/bsp/nrf52dk/pkg.yml  |   60 +-
 hw/bsp/nrf52dk/src/os_bsp.c |   78 +-
 hw/bsp/nrf52pdk/pkg.yml |   58 +-
 hw/bsp/olimex_stm32-e407_devboard/pkg.yml   |   45 +-
 hw/hal/include/hal/flash_map.h  |5 +-
 hw/hal/include/hal/hal_bsp.h|1 +
 hw/hal/pkg.yml  |3 -
 hw/hal/src/flash_map.c  |   76 +-
 hw/hal/src/test/flash_map_test.c|  169 -
 hw/hal/test/pkg.yml |   30 +
 hw/hal/test/src/flash_map_test.c|  170 +
 hw/mcu/native/include/mcu/mcu_hal.h |2 -
 hw/mcu/native/src/hal_adc.c |4 +-
 

[24/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/test/ble_att_svr_test.c
--
diff --git a/net/nimble/host/src/test/ble_att_svr_test.c 
b/net/nimble/host/src/test/ble_att_svr_test.c
deleted file mode 100644
index 1509b41..000
--- a/net/nimble/host/src/test/ble_att_svr_test.c
+++ /dev/null
@@ -1,2314 +0,0 @@
-/**
- * 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 
-#include 
-#include 
-#include "testutil/testutil.h"
-#include "nimble/hci_common.h"
-#include "host/ble_hs_test.h"
-#include "host/ble_uuid.h"
-#include "ble_hs_test_util.h"
-
-static uint8_t *ble_att_svr_test_attr_r_1;
-static uint16_t ble_att_svr_test_attr_r_1_len;
-static uint8_t *ble_att_svr_test_attr_r_2;
-static uint16_t ble_att_svr_test_attr_r_2_len;
-
-static uint8_t ble_att_svr_test_attr_w_1[1024];
-static uint16_t ble_att_svr_test_attr_w_1_len;
-static uint8_t ble_att_svr_test_attr_w_2[1024];
-static uint16_t ble_att_svr_test_attr_w_2_len;
-
-static uint16_t ble_att_svr_test_n_conn_handle;
-static uint16_t ble_att_svr_test_n_attr_handle;
-static uint8_t ble_att_svr_test_attr_n[1024];
-static uint16_t ble_att_svr_test_attr_n_len;
-
-static int
-ble_att_svr_test_misc_gap_cb(struct ble_gap_event *event, void *arg)
-{
-switch (event->type) {
-case BLE_GAP_EVENT_NOTIFY_RX:
-ble_att_svr_test_n_conn_handle = event->notify_rx.conn_handle;
-ble_att_svr_test_n_attr_handle = event->notify_rx.attr_handle;
-TEST_ASSERT_FATAL(OS_MBUF_PKTLEN(event->notify_rx.om) <=
-  sizeof ble_att_svr_test_attr_n);
-ble_att_svr_test_attr_n_len = OS_MBUF_PKTLEN(event->notify_rx.om);
-os_mbuf_copydata(event->notify_rx.om, 0, ble_att_svr_test_attr_n_len,
- ble_att_svr_test_attr_n);
-break;
-
-default:
-break;
-}
-
-return 0;
-}
-
-/**
- * @return  The handle of the new test connection.
- */
-static uint16_t
-ble_att_svr_test_misc_init(uint16_t mtu)
-{
-struct ble_l2cap_chan *chan;
-struct ble_hs_conn *conn;
-int rc;
-
-ble_hs_test_util_init();
-
-ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
- ble_att_svr_test_misc_gap_cb, NULL);
-
-ble_hs_lock();
-
-rc = ble_hs_misc_conn_chan_find(2, BLE_L2CAP_CID_ATT, , );
-TEST_ASSERT_FATAL(rc == 0);
-
-if (mtu != 0) {
-chan->blc_my_mtu = mtu;
-chan->blc_peer_mtu = mtu;
-chan->blc_flags |= BLE_L2CAP_CHAN_F_TXED_MTU;
-}
-
-ble_hs_unlock();
-
-ble_att_svr_test_attr_r_1_len = 0;
-ble_att_svr_test_attr_r_2_len = 0;
-ble_att_svr_test_attr_w_1_len = 0;
-
-return 2;
-}
-
-static int
-ble_att_svr_test_misc_attr_fn_r_1(uint16_t conn_handle, uint16_t attr_handle,
-  uint8_t op, uint16_t offset,
-  struct os_mbuf **om, void *arg)
-{
-switch (op) {
-case BLE_ATT_ACCESS_OP_READ:
-if (offset > ble_att_svr_test_attr_r_1_len) {
-return BLE_ATT_ERR_INVALID_OFFSET;
-}
-
-os_mbuf_append(*om, ble_att_svr_test_attr_r_1 + offset,
-   ble_att_svr_test_attr_r_1_len - offset);
-return 0;
-
-default:
-return -1;
-}
-}
-
-static int
-ble_att_svr_test_misc_attr_fn_r_2(uint16_t conn_handle, uint16_t attr_handle,
-  uint8_t op, uint16_t offset,
-  struct os_mbuf **om, void *arg)
-{
-
-switch (op) {
-case BLE_ATT_ACCESS_OP_READ:
-if (offset > ble_att_svr_test_attr_r_2_len) {
-return BLE_ATT_ERR_INVALID_OFFSET;
-}
-
-os_mbuf_append(*om, ble_att_svr_test_attr_r_2 + offset,
-   ble_att_svr_test_attr_r_2_len - offset);
-return 0;
-
-default:
-return -1;
-}
-}
-
-#define BLE_ATT_SVR_TEST_LAST_SVC  11
-#define BLE_ATT_SVR_TEST_LAST_ATTR 24
-
-static int
-ble_att_svr_test_misc_attr_fn_r_group(uint16_t conn_handle,
-  uint16_t attr_handle,
-  

[18/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/test/ble_os_test.c
--
diff --git a/net/nimble/host/src/test/ble_os_test.c 
b/net/nimble/host/src/test/ble_os_test.c
deleted file mode 100644
index a9c28ea..000
--- a/net/nimble/host/src/test/ble_os_test.c
+++ /dev/null
@@ -1,401 +0,0 @@
-/**
- * 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 
-#include "os/os.h"
-#include "testutil/testutil.h"
-#include "nimble/hci_common.h"
-#include "nimble/ble_hci_trans.h"
-#include "host/ble_hs_test.h"
-#include "host/ble_gap.h"
-#include "ble_hs_test_util.h"
-
-#define BLE_OS_TEST_STACK_SIZE  256
-#define BLE_OS_TEST_APP_STACK_SIZE  256
-
-#define BLE_OS_TEST_APP_PRIO 9
-#define BLE_OS_TEST_TASK_PRIO10
-
-static struct os_task ble_os_test_task;
-static struct os_task ble_os_test_app_task;
-static os_stack_t ble_os_test_stack[OS_STACK_ALIGN(BLE_OS_TEST_STACK_SIZE)];
-
-static os_stack_t
-ble_os_test_app_stack[OS_STACK_ALIGN(BLE_OS_TEST_APP_STACK_SIZE)];
-
-static uint8_t ble_os_test_peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
-
-static void ble_os_test_app_task_handler(void *arg);
-
-static int ble_os_test_gap_event_type;
-
-static void
-ble_os_test_init_app_task(void)
-{
-int rc;
-
-rc = os_task_init(_os_test_app_task,
-  "ble_gap_terminate_test_task",
-  ble_os_test_app_task_handler, NULL,
-  BLE_OS_TEST_APP_PRIO, OS_WAIT_FOREVER,
-  ble_os_test_app_stack,
-  OS_STACK_ALIGN(BLE_OS_TEST_APP_STACK_SIZE));
-TEST_ASSERT_FATAL(rc == 0);
-}
-
-static void
-ble_os_test_misc_init(void)
-{
-ble_hs_test_util_init();
-
-/* Receive acknowledgements for the startup sequence.  We sent the
- * corresponding requests when the host task was started.
- */
-ble_hs_test_util_set_startup_acks();
-
-ble_os_test_init_app_task();
-}
-
-static int
-ble_os_test_misc_conn_exists(uint16_t conn_handle)
-{
-struct ble_hs_conn *conn;
-
-ble_hs_lock();
-
-if (conn_handle == BLE_HS_CONN_HANDLE_NONE) {
-conn = ble_hs_conn_first();
-} else {
-conn = ble_hs_conn_find(conn_handle);
-}
-
-ble_hs_unlock();
-
-return conn != NULL;
-}
-
-static int
-ble_gap_direct_connect_test_connect_cb(struct ble_gap_event *event, void *arg)
-{
-struct ble_gap_conn_desc desc;
-int *cb_called;
-int rc;
-
-cb_called = arg;
-*cb_called = 1;
-
-TEST_ASSERT(event->type == BLE_GAP_EVENT_CONNECT);
-TEST_ASSERT(event->connect.status == 0);
-TEST_ASSERT(event->connect.conn_handle == 2);
-
-rc = ble_gap_conn_find(event->connect.conn_handle, );
-TEST_ASSERT_FATAL(rc == 0);
-TEST_ASSERT(desc.peer_id_addr_type == BLE_ADDR_TYPE_PUBLIC);
-TEST_ASSERT(memcmp(desc.peer_id_addr, ble_os_test_peer_addr, 6) == 0);
-
-return 0;
-}
-
-static void
-ble_gap_direct_connect_test_task_handler(void *arg)
-{
-struct hci_le_conn_complete evt;
-uint8_t addr[6] = { 1, 2, 3, 4, 5, 6 };
-int cb_called;
-int rc;
-
-/* Set the connect callback so we can verify that it gets called with the
- * proper arguments.
- */
-cb_called = 0;
-
-/* Make sure there are no created connections and no connections in
- * progress.
- */
-TEST_ASSERT(!ble_os_test_misc_conn_exists(BLE_HS_CONN_HANDLE_NONE));
-
-/* Initiate a direct connection. */
-ble_hs_test_util_connect(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
- addr, 0, NULL,
- ble_gap_direct_connect_test_connect_cb,
- _called, 0);
-TEST_ASSERT(!ble_os_test_misc_conn_exists(BLE_HS_CONN_HANDLE_NONE));
-TEST_ASSERT(!cb_called);
-
-/* Receive an HCI connection-complete event. */
-memset(, 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_rx_conn_complete();
-TEST_ASSERT(rc == 0);
-
-/* The connection should now be created. */
-

[27/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/util/src/test/cbmem_test.c
--
diff --git a/libs/util/src/test/cbmem_test.c b/libs/util/src/test/cbmem_test.c
deleted file mode 100644
index b486334..000
--- a/libs/util/src/test/cbmem_test.c
+++ /dev/null
@@ -1,176 +0,0 @@
-/**
- * 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 
-#include 
-
-#include "testutil/testutil.h"
-#include "util/cbmem.h" 
-
-#define CBMEM1_BUF_SIZE (64 * 1024)
-
-struct cbmem cbmem1;
-uint8_t cbmem1_buf[CBMEM1_BUF_SIZE];
-uint8_t cbmem1_entry[1024];
-
-/*
- * Things to test.
- *
- * - Wrap of the circular buffer.  
- * - Reading through all entries.
- */
-
-static void
-setup_cbmem1(void)
-{
-int i;
-int rc;
-
-rc = cbmem_init(, cbmem1_buf, CBMEM1_BUF_SIZE);
-TEST_ASSERT_FATAL(rc == 0, "cbmem_init() failed, non-zero RC = %d", rc);
-
-memset(cbmem1_entry, 0xff, sizeof(cbmem1_entry));
-
-/* Insert 65 1024 entries, and overflow buffer.  
- * This should overflow two entries, because the buffer is sized for 64 
- * entries, and then the headers themselves will eat into one of the 
entries, 
- * so there should be a total of 63 entries.
- * Ensure no data corruption.
- */
-for (i = 0; i < 65; i++) {
-cbmem1_entry[0] = i;
-rc = cbmem_append(, cbmem1_entry, sizeof(cbmem1_entry));
-TEST_ASSERT_FATAL(rc == 0, "Could not append entry %d, rc = %d", i, 
rc);
-}
-}
-
-static int 
-cbmem_test_case_1_walk(struct cbmem *cbmem, struct cbmem_entry_hdr *hdr, 
-void *arg)
-{
-uint8_t expected;
-uint8_t actual;
-int rc;
-
-expected = *(uint8_t *) arg;
-
-rc = cbmem_read(cbmem, hdr, , 0, sizeof(actual));
-TEST_ASSERT_FATAL(rc == 1, "Couldn't read 1 byte from cbmem");
-TEST_ASSERT_FATAL(actual == expected, 
-"Actual doesn't equal expected (%d = %d)", actual, expected);
-
-*(uint8_t *) arg = ++expected;
-
-return (0);
-}
-
-TEST_CASE(cbmem_test_case_1) 
-{
-int i;
-int rc;
-
-/* i starts at 2, for the 2 overwritten entries. */
-i = 2;
-rc = cbmem_walk(, cbmem_test_case_1_walk, );
-TEST_ASSERT_FATAL(rc == 0, "Could not walk cbmem tree!  rc = %d", rc);
-TEST_ASSERT_FATAL(i == 65, 
-"Did not go through every element of walk, %d processed", i - 2);
-
-}
-
-TEST_CASE(cbmem_test_case_2)
-{
-struct cbmem_entry_hdr *hdr;
-struct cbmem_iter iter;
-uint8_t i;
-uint8_t val;
-int rc;
-
-i = 2;
-cbmem_iter_start(, );
-while (1) {
-hdr = cbmem_iter_next(, );
-if (hdr == NULL) {
-break;
-}
-
-rc = cbmem_read(, hdr, , 0, sizeof(val));
-TEST_ASSERT_FATAL(rc == 1, "Couldn't read 1 byte from cbmem");
-TEST_ASSERT_FATAL(val == i, "Entry index does not match %d vs %d", 
-val, i);
-
-i++;
-}
-
-/* i starts at 2, for the 2 overwritten entries */
-TEST_ASSERT_FATAL(i == 65, 
-"Did not iterate through all 63 elements of CBMEM1, processed %d", 
-i - 2);
-}
-
-TEST_CASE(cbmem_test_case_3)
-{
-struct cbmem_entry_hdr *hdr;
-struct cbmem_iter iter;
-uint16_t off;
-uint16_t len;
-uint8_t buf[128];
-int i;
-int rc;
-
-i = 0;
-cbmem_iter_start(, );
-while (1) {
-hdr = cbmem_iter_next(, );
-if (hdr == NULL) {
-break;
-}
-
-/* first ensure we can read the entire entry */
-off = 0;
-len = 0;
-while (1) {
-rc = cbmem_read(, hdr, buf, off, sizeof(buf));
-TEST_ASSERT_FATAL(rc >= 0,
-"Error reading from buffer rc=%d, off=%d,len=%d", rc, off, 
-sizeof(buf));
-if (rc == 0) {
-break;
-}
-off += rc;
-len += rc;
-}
-TEST_ASSERT_FATAL(len == 1024, 
-"Couldn't read full entry, expected %d got %d", 1024, len);
-i++;
-
-/* go apesh*t, and read data out of bounds, see what we get. */
-rc = cbmem_read(, hdr, buf, 2048, 

[33/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/fs/nffs/test/src/arch/sim/nffs_test_system_01.c
--
diff --git a/fs/nffs/test/src/arch/sim/nffs_test_system_01.c 
b/fs/nffs/test/src/arch/sim/nffs_test_system_01.c
new file mode 100644
index 000..cd30544
--- /dev/null
+++ b/fs/nffs/test/src/arch/sim/nffs_test_system_01.c
@@ -0,0 +1,6537 @@
+/**
+ * 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.
+ */
+
+
+/** Generated by makefs.rb */
+
+#include 
+#include "nffs_test_priv.h"
+
+const struct nffs_test_file_desc *nffs_test_system_01 =
+(struct nffs_test_file_desc[]) {
+{
+.filename = "",
+.is_dir = 1,
+.children = (struct nffs_test_file_desc[]) {
+ {
+ .filename = "lvl1dir-",
+ .is_dir = 1,
+ .children = (struct nffs_test_file_desc[]) {
+  {
+  .filename = "lvl2dir-",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+{
+.filename = "lvl4file-",
+.contents = "0",
+.contents_len = 1,
+},
+{
+.filename = "lvl4file-0001",
+.contents = "1",
+.contents_len = 1,
+},
+{
+.filename = "lvl4file-0002",
+.contents = "2",
+.contents_len = 1,
+},
+{
+.filename = "lvl4file-0003",
+.contents = "3",
+.contents_len = 1,
+},
+{
+.filename = "lvl4file-0004",
+.contents = "4",
+.contents_len = 1,
+},
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+{
+.filename = "lvl4file-",
+.contents = "0",
+.contents_len = 1,
+},
+{
+.filename = "lvl4file-0001",
+.contents = "1",
+.contents_len = 1,
+},
+{
+.filename = "lvl4file-0002",
+.contents = "2",
+.contents_len = 1,
+},
+{
+.filename = "lvl4file-0003",
+.contents = "3",
+.contents_len = 1,
+},
+{
+.filename = "lvl4file-0004",
+.contents = "4",
+.contents_len = 1,
+},
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+{
+.filename = "lvl4file-",
+.contents = "0",
+.contents_len = 1,
+},
+{
+.filename = "lvl4file-0001",
+.contents = "1",
+.contents_len = 1,
+},
+{
+.filename = "lvl4file-0002",
+.contents = "2",
+.contents_len = 1,
+},
+{
+.filename = "lvl4file-0003",
+.contents = "3",
+.contents_len = 1,
+},
+{
+.filename = "lvl4file-0004",
+.contents = "4",
+.contents_len = 1,
+},
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+{
+.filename = "lvl4file-",
+.contents = "0",
+.contents_len = 1,
+},
+{
+.filename = "lvl4file-0001",
+.contents = "1",
+.contents_len = 1,
+},
+{
+.filename = "lvl4file-0002",
+.contents = "2",
+.contents_len = 1,
+},
+{
+.filename = "lvl4file-0003",
+.contents = "3",
+.contents_len = 1,
+},
+{
+.filename = "lvl4file-0004",
+.contents = "4",
+.contents_len = 1,
+},
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+{
+.filename = "lvl4file-",
+.contents = "0",
+.contents_len = 1,
+},
+{
+.filename = "lvl4file-0001",
+.contents = "1",
+.contents_len = 1,
+},
+{
+.filename = "lvl4file-0002",
+.contents = "2",
+.contents_len = 1,
+},
+{
+.filename = "lvl4file-0003",
+.contents = "3",
+.contents_len = 1,
+},
+{
+.filename = "lvl4file-0004",
+.contents = "4",
+.contents_len = 1,
+},
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+  {
+  .filename = "lvl2dir-0001",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-",
+   .is_dir = 1,
+   .children = (struct 

[08/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/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
new file mode 100644
index 000..eed1262
--- /dev/null
+++ b/net/nimble/host/test/src/ble_hs_test_util.c
@@ -0,0 +1,1404 @@
+/**
+ * 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 
+#include 
+#include "stats/stats.h"
+#include "testutil/testutil.h"
+#include "nimble/ble.h"
+#include "nimble/hci_common.h"
+#include "nimble/ble_hci_trans.h"
+#include "host/ble_hs_adv.h"
+#include "host/ble_hs_id.h"
+#include "transport/ram/ble_hci_ram.h"
+#include "ble_hs_test_util.h"
+
+/* Our global device address. */
+uint8_t g_dev_addr[BLE_DEV_ADDR_LEN];
+
+#define BLE_HS_TEST_UTIL_PUB_ADDR_VAL { 0x0a, 0x54, 0xab, 0x49, 0x7f, 0x06 }
+
+static const uint8_t ble_hs_test_util_pub_addr[BLE_DEV_ADDR_LEN] =
+BLE_HS_TEST_UTIL_PUB_ADDR_VAL;
+
+#define BLE_HS_TEST_UTIL_LE_OPCODE(ocf) \
+ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE, (ocf))
+
+struct os_eventq ble_hs_test_util_evq;
+
+static STAILQ_HEAD(, os_mbuf_pkthdr) ble_hs_test_util_prev_tx_queue;
+struct os_mbuf *ble_hs_test_util_prev_tx_cur;
+
+#define BLE_HS_TEST_UTIL_PREV_HCI_TX_CNT  64
+static uint8_t
+ble_hs_test_util_prev_hci_tx[BLE_HS_TEST_UTIL_PREV_HCI_TX_CNT][260];
+int ble_hs_test_util_num_prev_hci_txes;
+
+uint8_t ble_hs_test_util_cur_hci_tx[260];
+
+const struct ble_gap_adv_params ble_hs_test_util_adv_params = {
+.conn_mode = BLE_GAP_CONN_MODE_UND,
+.disc_mode = BLE_GAP_DISC_MODE_GEN,
+
+.itvl_min = 0,
+.itvl_max = 0,
+.channel_map = 0,
+.filter_policy = 0,
+.high_duty_cycle = 0,
+};
+
+void
+ble_hs_test_util_prev_tx_enqueue(struct os_mbuf *om)
+{
+struct os_mbuf_pkthdr *omp;
+
+assert(OS_MBUF_IS_PKTHDR(om));
+
+omp = OS_MBUF_PKTHDR(om);
+if (STAILQ_EMPTY(_hs_test_util_prev_tx_queue)) {
+STAILQ_INSERT_HEAD(_hs_test_util_prev_tx_queue, omp, omp_next);
+} else {
+STAILQ_INSERT_TAIL(_hs_test_util_prev_tx_queue, omp, omp_next);
+}
+}
+
+static struct os_mbuf *
+ble_hs_test_util_prev_tx_dequeue_once(struct hci_data_hdr *out_hci_hdr)
+{
+struct os_mbuf_pkthdr *omp;
+struct os_mbuf *om;
+int rc;
+
+omp = STAILQ_FIRST(_hs_test_util_prev_tx_queue);
+if (omp == NULL) {
+return NULL;
+}
+STAILQ_REMOVE_HEAD(_hs_test_util_prev_tx_queue, omp_next);
+
+om = OS_MBUF_PKTHDR_TO_MBUF(omp);
+
+rc = ble_hs_hci_util_data_hdr_strip(om, out_hci_hdr);
+TEST_ASSERT_FATAL(rc == 0);
+TEST_ASSERT_FATAL(out_hci_hdr->hdh_len == OS_MBUF_PKTLEN(om));
+
+return om;
+}
+
+struct os_mbuf *
+ble_hs_test_util_prev_tx_dequeue(void)
+{
+struct ble_l2cap_hdr l2cap_hdr;
+struct hci_data_hdr hci_hdr;
+struct os_mbuf *om;
+uint8_t pb;
+int rc;
+
+os_mbuf_free_chain(ble_hs_test_util_prev_tx_cur);
+
+om = ble_hs_test_util_prev_tx_dequeue_once(_hdr);
+if (om != NULL) {
+pb = BLE_HCI_DATA_PB(hci_hdr.hdh_handle_pb_bc);
+TEST_ASSERT_FATAL(pb == BLE_HCI_PB_FIRST_NON_FLUSH);
+
+rc = ble_l2cap_parse_hdr(om, 0, _hdr);
+TEST_ASSERT_FATAL(rc == 0);
+
+os_mbuf_adj(om, BLE_L2CAP_HDR_SZ);
+
+ble_hs_test_util_prev_tx_cur = om;
+while (OS_MBUF_PKTLEN(ble_hs_test_util_prev_tx_cur) <
+   l2cap_hdr.blh_len) {
+
+om = ble_hs_test_util_prev_tx_dequeue_once(_hdr);
+TEST_ASSERT_FATAL(om != NULL);
+
+pb = BLE_HCI_DATA_PB(hci_hdr.hdh_handle_pb_bc);
+TEST_ASSERT_FATAL(pb == BLE_HCI_PB_MIDDLE);
+
+os_mbuf_concat(ble_hs_test_util_prev_tx_cur, om);
+}
+} else {
+ble_hs_test_util_prev_tx_cur = NULL;
+}
+
+return ble_hs_test_util_prev_tx_cur;
+}
+
+struct os_mbuf *
+ble_hs_test_util_prev_tx_dequeue_pullup(void)
+{
+struct os_mbuf *om;
+
+om = ble_hs_test_util_prev_tx_dequeue();
+if (om != NULL) {
+om = os_mbuf_pullup(om, OS_MBUF_PKTLEN(om));
+TEST_ASSERT_FATAL(om != NULL);
+ble_hs_test_util_prev_tx_cur = om;
+}
+
+

[09/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/test/src/ble_gatts_reg_test.c
--
diff --git a/net/nimble/host/test/src/ble_gatts_reg_test.c 
b/net/nimble/host/test/src/ble_gatts_reg_test.c
new file mode 100644
index 000..ad5f18f
--- /dev/null
+++ b/net/nimble/host/test/src/ble_gatts_reg_test.c
@@ -0,0 +1,718 @@
+/**
+ * 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 
+#include 
+#include "testutil/testutil.h"
+#include "nimble/ble.h"
+#include "host/ble_uuid.h"
+#include "host/ble_hs_test.h"
+#include "ble_hs_test_util.h"
+
+#define BLE_GATTS_REG_TEST_MAX_ENTRIES  256
+
+struct ble_gatts_reg_test_entry {
+uint8_t op;
+uint8_t uuid128[16];
+uint16_t handle;
+uint16_t val_handle; /* If a characteristic. */
+
+const struct ble_gatt_svc_def *svc;
+const struct ble_gatt_chr_def *chr;
+const struct ble_gatt_dsc_def *dsc;
+};
+
+static struct ble_gatts_reg_test_entry
+ble_gatts_reg_test_entries[BLE_GATTS_REG_TEST_MAX_ENTRIES];
+
+static int ble_gatts_reg_test_num_entries;
+
+static void
+ble_gatts_reg_test_init(void)
+{
+ble_hs_test_util_init();
+ble_gatts_reg_test_num_entries = 0;
+}
+
+static void
+ble_gatts_reg_test_misc_reg_cb(struct ble_gatt_register_ctxt *ctxt, void *arg)
+{
+struct ble_gatts_reg_test_entry *entry;
+
+TEST_ASSERT_FATAL(ble_gatts_reg_test_num_entries <
+  BLE_GATTS_REG_TEST_MAX_ENTRIES);
+
+entry = ble_gatts_reg_test_entries + ble_gatts_reg_test_num_entries++;
+memset(entry, 0, sizeof *entry);
+
+entry->op = ctxt->op;
+switch (ctxt->op) {
+case BLE_GATT_REGISTER_OP_SVC:
+memcpy(entry->uuid128, ctxt->svc.svc_def->uuid128, 16);
+entry->handle = ctxt->svc.handle;
+entry->svc = ctxt->svc.svc_def;
+break;
+
+case BLE_GATT_REGISTER_OP_CHR:
+memcpy(entry->uuid128, ctxt->chr.chr_def->uuid128, 16);
+entry->handle = ctxt->chr.def_handle;
+entry->val_handle = ctxt->chr.val_handle;
+entry->svc = ctxt->chr.svc_def;
+entry->chr = ctxt->chr.chr_def;
+break;
+
+case BLE_GATT_REGISTER_OP_DSC:
+memcpy(entry->uuid128, ctxt->dsc.dsc_def->uuid128, 16);
+entry->handle = ctxt->dsc.handle;
+entry->svc = ctxt->dsc.svc_def;
+entry->chr = ctxt->dsc.chr_def;
+entry->dsc = ctxt->dsc.dsc_def;
+break;
+
+default:
+TEST_ASSERT(0);
+break;
+}
+}
+
+static void
+ble_gatts_reg_test_misc_lookup_good(struct ble_gatts_reg_test_entry *entry)
+{
+uint16_t chr_def_handle;
+uint16_t chr_val_handle;
+uint16_t svc_handle;
+uint16_t dsc_handle;
+int rc;
+
+switch (entry->op) {
+case BLE_GATT_REGISTER_OP_SVC:
+rc = ble_gatts_find_svc(entry->uuid128, _handle);
+TEST_ASSERT_FATAL(rc == 0);
+TEST_ASSERT(svc_handle == entry->handle);
+break;
+
+case BLE_GATT_REGISTER_OP_CHR:
+rc = ble_gatts_find_chr(entry->svc->uuid128, entry->chr->uuid128,
+_def_handle, _val_handle);
+TEST_ASSERT_FATAL(rc == 0);
+TEST_ASSERT(chr_def_handle == entry->handle);
+TEST_ASSERT(chr_val_handle == entry->val_handle);
+break;
+
+case BLE_GATT_REGISTER_OP_DSC:
+rc = ble_gatts_find_dsc(entry->svc->uuid128, entry->chr->uuid128,
+entry->dsc->uuid128, _handle);
+break;
+
+default:
+TEST_ASSERT(0);
+break;
+}
+}
+
+static void
+ble_gatts_reg_test_misc_lookup_bad(struct ble_gatts_reg_test_entry *entry)
+{
+struct ble_gatts_reg_test_entry *cur;
+uint8_t wrong_uuid[16];
+int rc;
+int i;
+
+switch (entry->op) {
+case BLE_GATT_REGISTER_OP_SVC:
+/* Wrong service UUID. */
+memcpy(wrong_uuid, entry->svc->uuid128, 16);
+wrong_uuid[15]++;
+rc = ble_gatts_find_svc(wrong_uuid, NULL);
+TEST_ASSERT(rc == BLE_HS_ENOENT);
+break;
+
+case BLE_GATT_REGISTER_OP_CHR:
+/* Correct service UUID, wrong characteristic UUID. */
+memcpy(wrong_uuid, entry->chr->uuid128, 16);
+ 

[37/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/fs/nffs/src/test/arch/sim/nffs_test_system_01.c
--
diff --git a/fs/nffs/src/test/arch/sim/nffs_test_system_01.c 
b/fs/nffs/src/test/arch/sim/nffs_test_system_01.c
deleted file mode 100644
index cd30544..000
--- a/fs/nffs/src/test/arch/sim/nffs_test_system_01.c
+++ /dev/null
@@ -1,6537 +0,0 @@
-/**
- * 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.
- */
-
-
-/** Generated by makefs.rb */
-
-#include 
-#include "nffs_test_priv.h"
-
-const struct nffs_test_file_desc *nffs_test_system_01 =
-(struct nffs_test_file_desc[]) {
-{
-.filename = "",
-.is_dir = 1,
-.children = (struct nffs_test_file_desc[]) {
- {
- .filename = "lvl1dir-",
- .is_dir = 1,
- .children = (struct nffs_test_file_desc[]) {
-  {
-  .filename = "lvl2dir-",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-{
-.filename = "lvl4file-",
-.contents = "0",
-.contents_len = 1,
-},
-{
-.filename = "lvl4file-0001",
-.contents = "1",
-.contents_len = 1,
-},
-{
-.filename = "lvl4file-0002",
-.contents = "2",
-.contents_len = 1,
-},
-{
-.filename = "lvl4file-0003",
-.contents = "3",
-.contents_len = 1,
-},
-{
-.filename = "lvl4file-0004",
-.contents = "4",
-.contents_len = 1,
-},
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-{
-.filename = "lvl4file-",
-.contents = "0",
-.contents_len = 1,
-},
-{
-.filename = "lvl4file-0001",
-.contents = "1",
-.contents_len = 1,
-},
-{
-.filename = "lvl4file-0002",
-.contents = "2",
-.contents_len = 1,
-},
-{
-.filename = "lvl4file-0003",
-.contents = "3",
-.contents_len = 1,
-},
-{
-.filename = "lvl4file-0004",
-.contents = "4",
-.contents_len = 1,
-},
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-{
-.filename = "lvl4file-",
-.contents = "0",
-.contents_len = 1,
-},
-{
-.filename = "lvl4file-0001",
-.contents = "1",
-.contents_len = 1,
-},
-{
-.filename = "lvl4file-0002",
-.contents = "2",
-.contents_len = 1,
-},
-{
-.filename = "lvl4file-0003",
-.contents = "3",
-.contents_len = 1,
-},
-{
-.filename = "lvl4file-0004",
-.contents = "4",
-.contents_len = 1,
-},
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-{
-.filename = "lvl4file-",
-.contents = "0",
-.contents_len = 1,
-},
-{
-.filename = "lvl4file-0001",
-.contents = "1",
-.contents_len = 1,
-},
-{
-.filename = "lvl4file-0002",
-.contents = "2",
-.contents_len = 1,
-},
-{
-.filename = "lvl4file-0003",
-.contents = "3",
-.contents_len = 1,
-},
-{
-.filename = "lvl4file-0004",
-.contents = "4",
-.contents_len = 1,
-},
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-{
-.filename = "lvl4file-",
-.contents = "0",
-.contents_len = 1,
-},
-{
-.filename = "lvl4file-0001",
-.contents = "1",
-.contents_len = 1,
-},
-{
-.filename = "lvl4file-0002",
-.contents = "2",
-.contents_len = 1,
-},
-{
-.filename = "lvl4file-0003",
-.contents = "3",
-.contents_len = 1,
-},
-{
-.filename = "lvl4file-0004",
-.contents = "4",
-.contents_len = 1,
-},
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
-  {
-  .filename = "lvl2dir-0001",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-",
-   .is_dir = 1,
-   .children = 

[23/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/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
deleted file mode 100644
index 1943d01..000
--- a/net/nimble/host/src/test/ble_gap_test.c
+++ /dev/null
@@ -1,2578 +0,0 @@
-/**
- * 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 
-#include 
-#include "testutil/testutil.h"
-#include "nimble/ble.h"
-#include "nimble/hci_common.h"
-#include "host/ble_hs_adv.h"
-#include "host/ble_hs_test.h"
-#include "ble_hs_test_util.h"
-
-static int ble_gap_test_conn_event_type;
-static int ble_gap_test_conn_status;
-static struct ble_gap_conn_desc ble_gap_test_conn_desc;
-static void *ble_gap_test_conn_arg;
-static struct ble_gap_upd_params ble_gap_test_conn_peer_params;
-static struct ble_gap_upd_params ble_gap_test_conn_self_params;
-
-static int ble_gap_test_disc_event_type;
-static struct ble_gap_disc_desc ble_gap_test_disc_desc;
-static void *ble_gap_test_disc_arg;
-
-/*
- * $misc *
- */
-
-static int
-ble_gap_test_util_update_in_progress(uint16_t conn_handle)
-{
-ble_hs_conn_flags_t conn_flags;
-int rc;
-
-rc = ble_hs_atomic_conn_flags(conn_handle, _flags);
-return rc == 0 && conn_flags & BLE_HS_CONN_F_UPDATE;
-}
-
-static void
-ble_gap_test_util_reset_cb_info(void)
-{
-ble_gap_test_conn_event_type = -1;
-ble_gap_test_conn_status = -1;
-memset(_gap_test_conn_desc, 0xff, sizeof ble_gap_test_conn_desc);
-ble_gap_test_conn_arg = (void *)-1;
-
-ble_gap_test_disc_event_type = -1;
-memset(_gap_test_disc_desc, 0xff, sizeof ble_gap_test_disc_desc);
-ble_gap_test_disc_arg = (void *)-1;
-}
-
-static void
-ble_gap_test_util_init(void)
-{
-ble_hs_test_util_init();
-ble_hs_test_util_set_static_rnd_addr();
-ble_gap_test_util_reset_cb_info();
-}
-
-static int
-ble_gap_test_util_disc_cb(struct ble_gap_event *event, void *arg)
-{
-ble_gap_test_disc_event_type = event->type;
-ble_gap_test_disc_arg = arg;
-
-if (event->type == BLE_GAP_EVENT_DISC) {
-ble_gap_test_disc_desc = event->disc;
-}
-
-return 0;
-}
-
-static int
-ble_gap_test_util_connect_cb(struct ble_gap_event *event, void *arg)
-{
-int *fail_reason;
-
-ble_gap_test_conn_event_type = event->type;
-ble_gap_test_conn_arg = arg;
-
-switch (event->type) {
-case BLE_GAP_EVENT_CONNECT:
-ble_gap_test_conn_status = event->connect.status;
-ble_gap_conn_find(event->connect.conn_handle, _gap_test_conn_desc);
-break;
-
-case BLE_GAP_EVENT_DISCONNECT:
-ble_gap_test_conn_status = event->disconnect.reason;
-ble_gap_test_conn_desc = event->disconnect.conn;
-break;
-
-case BLE_GAP_EVENT_CONN_UPDATE:
-ble_gap_test_conn_status = event->conn_update.status;
-ble_gap_conn_find(event->conn_update.conn_handle,
-  _gap_test_conn_desc);
-break;
-
-case BLE_GAP_EVENT_CONN_CANCEL:
-break;
-
-case BLE_GAP_EVENT_TERM_FAILURE:
-ble_gap_test_conn_status = event->term_failure.status;
-ble_gap_conn_find(event->term_failure.conn_handle,
-  _gap_test_conn_desc);
-break;
-
-case BLE_GAP_EVENT_ADV_COMPLETE:
-ble_gap_test_conn_arg = arg;
-break;
-
-case BLE_GAP_EVENT_CONN_UPDATE_REQ:
-ble_gap_test_conn_peer_params = *event->conn_update_req.peer_params;
-*event->conn_update_req.self_params = ble_gap_test_conn_self_params;
-ble_gap_conn_find(event->conn_update_req.conn_handle,
-  _gap_test_conn_desc);
-
-fail_reason = arg;
-if (fail_reason == NULL) {
-return 0;
-} else {
-return *fail_reason;
-}
-break;
-
-default:
-TEST_ASSERT_FATAL(0);
-break;
-}
-
-return 0;
-}
-
-static 

[35/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/fs/nffs/test/src/arch/sim/nffs_test.c
--
diff --git a/fs/nffs/test/src/arch/sim/nffs_test.c 
b/fs/nffs/test/src/arch/sim/nffs_test.c
new file mode 100644
index 000..87afcfa
--- /dev/null
+++ b/fs/nffs/test/src/arch/sim/nffs_test.c
@@ -0,0 +1,3251 @@
+/**
+ * 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 
+#include 
+#include 
+#include 
+#include 
+#include "syscfg/syscfg.h"
+#include "hal/hal_flash.h"
+#include "testutil/testutil.h"
+#include "fs/fs.h"
+#include "nffs/nffs.h"
+#include "nffs/nffs_test.h"
+#include "nffs_test_priv.h"
+#include "nffs_priv.h"
+
+int flash_native_memset(uint32_t offset, uint8_t c, uint32_t len);
+
+static const struct nffs_area_desc nffs_area_descs[] = {
+{ 0x, 16 * 1024 },
+{ 0x4000, 16 * 1024 },
+{ 0x8000, 16 * 1024 },
+{ 0xc000, 16 * 1024 },
+{ 0x0001, 64 * 1024 },
+{ 0x0002, 128 * 1024 },
+{ 0x0004, 128 * 1024 },
+{ 0x0006, 128 * 1024 },
+{ 0x0008, 128 * 1024 },
+{ 0x000a, 128 * 1024 },
+{ 0x000c, 128 * 1024 },
+{ 0x000e, 128 * 1024 },
+{ 0, 0 },
+};
+
+static void
+nffs_test_util_assert_ent_name(struct fs_dirent *dirent,
+   const char *expected_name)
+{
+char name[NFFS_FILENAME_MAX_LEN + 1];
+uint8_t name_len;
+int rc;
+
+rc = fs_dirent_name(dirent, sizeof name, name, _len);
+TEST_ASSERT(rc == 0);
+if (rc == 0) {
+TEST_ASSERT(strcmp(name, expected_name) == 0);
+}
+}
+
+static void
+nffs_test_util_assert_file_len(struct fs_file *file, uint32_t expected)
+{
+uint32_t len;
+int rc;
+
+rc = fs_filelen(file, );
+TEST_ASSERT(rc == 0);
+TEST_ASSERT(len == expected);
+}
+
+static void
+nffs_test_util_assert_cache_is_sane(const char *filename)
+{
+struct nffs_cache_inode *cache_inode;
+struct nffs_cache_block *cache_block;
+struct fs_file *fs_file;
+struct nffs_file *file;
+uint32_t cache_start;
+uint32_t cache_end;
+uint32_t block_end;
+int rc;
+
+rc = fs_open(filename, FS_ACCESS_READ, _file);
+TEST_ASSERT(rc == 0);
+
+file = (struct nffs_file *)fs_file;
+rc = nffs_cache_inode_ensure(_inode, file->nf_inode_entry);
+TEST_ASSERT(rc == 0);
+
+nffs_cache_inode_range(cache_inode, _start, _end);
+
+if (TAILQ_EMPTY(_inode->nci_block_list)) {
+TEST_ASSERT(cache_start == 0 && cache_end == 0);
+} else {
+block_end = 0;  /* Pacify gcc. */
+TAILQ_FOREACH(cache_block, _inode->nci_block_list, ncb_link) {
+if (cache_block == TAILQ_FIRST(_inode->nci_block_list)) {
+TEST_ASSERT(cache_block->ncb_file_offset == cache_start);
+} else {
+/* Ensure no gap between this block and its predecessor. */
+TEST_ASSERT(cache_block->ncb_file_offset == block_end);
+}
+
+block_end = cache_block->ncb_file_offset +
+cache_block->ncb_block.nb_data_len;
+if (cache_block == TAILQ_LAST(_inode->nci_block_list,
+  nffs_cache_block_list)) {
+
+TEST_ASSERT(block_end == cache_end);
+}
+}
+}
+
+rc = fs_close(fs_file);
+TEST_ASSERT(rc == 0);
+}
+
+static void
+nffs_test_util_assert_contents(const char *filename, const char *contents,
+   int contents_len)
+{
+struct fs_file *file;
+uint32_t bytes_read;
+void *buf;
+int rc;
+
+rc = fs_open(filename, FS_ACCESS_READ, );
+TEST_ASSERT(rc == 0);
+
+buf = malloc(contents_len + 1);
+TEST_ASSERT(buf != NULL);
+
+rc = fs_read(file, contents_len + 1, buf, _read);
+TEST_ASSERT(rc == 0);
+TEST_ASSERT(bytes_read == contents_len);
+TEST_ASSERT(memcmp(buf, contents, contents_len) == 0);
+
+rc = fs_close(file);
+TEST_ASSERT(rc == 0);
+
+free(buf);
+
+nffs_test_util_assert_cache_is_sane(filename);
+}
+
+static int
+nffs_test_util_block_count(const 

[26/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/drivers/nrf52/src/ble_phy.c
--
diff --git a/net/nimble/drivers/nrf52/src/ble_phy.c 
b/net/nimble/drivers/nrf52/src/ble_phy.c
index 7389b20..46bb39a 100644
--- a/net/nimble/drivers/nrf52/src/ble_phy.c
+++ b/net/nimble/drivers/nrf52/src/ble_phy.c
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include "syscfg/syscfg.h"
 #include "os/os.h"
 #include "ble/xcvr.h"
 #include "bsp/cmsis_nvic.h"
@@ -89,7 +90,7 @@ struct ble_phy_obj g_ble_phy_data;
 /* Global transmit/receive buffer */
 static uint32_t g_ble_phy_txrx_buf[(BLE_PHY_MAX_PDU_LEN + 3) / 4];
 
-#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
 /* Make sure word-aligned for faster copies */
 static uint32_t g_ble_phy_enc_buf[(BLE_PHY_MAX_PDU_LEN + 3) / 4];
 #endif
@@ -159,7 +160,7 @@ STATS_NAME_END(ble_phy_stats)
  *  bit in the NVIC just to be sure when we disable the PHY.
  */
 
-#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
 
 /*
  * Per nordic, the number of bytes needed for scratch is 16 + MAX_PKT_SIZE.
@@ -168,7 +169,7 @@ STATS_NAME_END(ble_phy_stats)
  * space for 267 bytes of scratch. I used 268 bytes since not sure if this
  * needs to be aligned and burning a byte is no big deal.
  */
-//#define NRF_ENC_SCRATCH_WORDS (((NIMBLE_OPT_LL_MAX_PKT_SIZE + 16) + 3) / 4)
+//#define NRF_ENC_SCRATCH_WORDS (((MYNEWT_VAL(BLE_LL_MAX_PKT_SIZE) + 16) + 3) 
/ 4)
 #define NRF_ENC_SCRATCH_WORDS   (67)
 
 uint32_t g_nrf_encrypt_scratchpad[NRF_ENC_SCRATCH_WORDS];
@@ -243,7 +244,7 @@ nrf_wait_disabled(void)
 static void
 ble_phy_rx_xcvr_setup(void)
 {
-#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
 if (g_ble_phy_data.phy_encrypted) {
 NRF_RADIO->PACKETPTR = (uint32_t)_ble_phy_enc_buf[0];
 NRF_CCM->INPTR = (uint32_t)_ble_phy_enc_buf[0];
@@ -262,7 +263,7 @@ ble_phy_rx_xcvr_setup(void)
 NRF_RADIO->PACKETPTR = (uint32_t)g_ble_phy_data.rxpdu->om_data;
 #endif
 
-#if (BLE_LL_CFG_FEAT_LL_PRIVACY == 1)
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) == 1)
 if (g_ble_phy_data.phy_privacy) {
 NRF_AAR->ENABLE = AAR_ENABLE_ENABLE_Enabled;
 NRF_AAR->IRKPTR = (uint32_t)_nrf_irk_list[0];
@@ -325,7 +326,7 @@ ble_phy_tx_end_isr(void)
 NRF_RADIO->EVENTS_END = 0;
 wfr_time = NRF_RADIO->SHORTS;
 
-#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
 /*
  * XXX: not sure what to do. We had a HW error during transmission.
  * For now I just count a stat but continue on like all is good.
@@ -403,7 +404,7 @@ ble_phy_rx_end_isr(void)
 } else {
 STATS_INC(ble_phy_stats, rx_valid);
 ble_hdr->rxinfo.flags |= BLE_MBUF_HDR_F_CRC_OK;
-#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
 if (g_ble_phy_data.phy_encrypted) {
 /* Only set MIC failure flag if frame is not zero length */
 if ((dptr[1] != 0) && (NRF_CCM->MICSTATUS == 0)) {
@@ -499,7 +500,7 @@ ble_phy_rx_start_isr(void)
 g_ble_phy_data.phy_rx_started = 1;
 NRF_RADIO->INTENSET = RADIO_INTENSET_END_Msk;
 
-#if (BLE_LL_CFG_FEAT_LL_PRIVACY == 1)
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) == 1)
 /* Must start aar if we need to  */
 if (g_ble_phy_data.phy_privacy) {
 NRF_RADIO->EVENTS_BCMATCH = 0;
@@ -611,14 +612,14 @@ ble_phy_init(void)
 /* Captures tx/rx start in timer0 capture 1 */
 NRF_PPI->CHENSET = PPI_CHEN_CH26_Msk;
 
-#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
 NRF_CCM->INTENCLR = 0x;
 NRF_CCM->SHORTS = CCM_SHORTS_ENDKSGEN_CRYPT_Msk;
 NRF_CCM->EVENTS_ERROR = 0;
 memset(g_nrf_encrypt_scratchpad, 0, sizeof(g_nrf_encrypt_scratchpad));
 #endif
 
-#if (BLE_LL_CFG_FEAT_LL_PRIVACY == 1)
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) == 1)
 g_ble_phy_data.phy_aar_scratch = 0;
 NRF_AAR->IRKPTR = (uint32_t)_nrf_irk_list[0];
 NRF_AAR->INTENCLR = 0x;
@@ -689,7 +690,7 @@ ble_phy_rx(void)
 return 0;
 }
 
-#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
 /**
  * Called to enable encryption at the PHY. Note that this state will persist
  * in the PHY; in other words, if you call this function you have to call
@@ -826,7 +827,7 @@ ble_phy_tx(struct os_mbuf *txpdu, uint8_t end_trans)
 ble_hdr = BLE_MBUF_HDR_PTR(txpdu);
 payload_len = ble_hdr->txinfo.pyld_len;
 
-#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
 if (g_ble_phy_data.phy_encrypted) {
 dptr = (uint8_t *)_ble_phy_enc_buf[0];
 NRF_CCM->SHORTS = 1;
@@ -839,14 +840,14 @@ ble_phy_tx(struct os_mbuf *txpdu, uint8_t end_trans)
 

[06/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/test/src/ble_sm_sc_test.c
--
diff --git a/net/nimble/host/test/src/ble_sm_sc_test.c 
b/net/nimble/host/test/src/ble_sm_sc_test.c
new file mode 100644
index 000..24ecab4
--- /dev/null
+++ b/net/nimble/host/test/src/ble_sm_sc_test.c
@@ -0,0 +1,4910 @@
+/**
+ * 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 
+#include 
+#include 
+#include "testutil/testutil.h"
+#include "nimble/hci_common.h"
+#include "nimble/nimble_opt.h"
+#include "host/ble_sm.h"
+#include "host/ble_hs_test.h"
+#include "ble_hs_test_util.h"
+#include "ble_sm_test_util.h"
+
+#if NIMBLE_BLE_SM
+
+/**
+ * Secure connections pairing
+ * Master: peer
+ * Pair algorithm: just works
+ * Initiator IO capabilities: 3
+ * Responder IO capabilities: 3
+ * Bonding: true
+ * Initiator address type: 0
+ * Responder address type: 0
+ * Initiator key distribution: 5
+ * Responder key distribution: 7
+ */
+TEST_CASE(ble_sm_sc_peer_jw_iio3_rio3_b1_iat0_rat0_ik5_rk7)
+{
+struct ble_sm_test_params params;
+
+params = (struct ble_sm_test_params) {
+.init_id_addr = {
+0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0,
+},
+.resp_id_addr = {
+0x33, 0x22, 0x11, 0x00, 0x45, 0x0a,
+},
+.pair_req = {
+.io_cap = 0x03,
+.oob_data_flag = 0x00,
+.authreq = 0x09,
+.max_enc_key_size = 0x10,
+.init_key_dist = 0x0d,
+.resp_key_dist = 0x0f,
+},
+.pair_rsp = {
+.io_cap = 0x03,
+.oob_data_flag = 0x00,
+.authreq = 0x09,
+.max_enc_key_size = 0x10,
+.init_key_dist = 0x05,
+.resp_key_dist = 0x07,
+},
+.our_priv_key = {
+0x54, 0x8d, 0x20, 0xb8, 0x97, 0x0b, 0xbc, 0x43,
+0x9a, 0xad, 0x10, 0x6f, 0x60, 0x74, 0xd4, 0x6a,
+0x55, 0xc1, 0x7a, 0x17, 0x8b, 0x60, 0xe0, 0xb4,
+0x5a, 0xe6, 0x58, 0xf1, 0xea, 0x12, 0xd9, 0xfb,
+},
+.public_key_req = {
+.x = {
+0xbc, 0xf2, 0xd8, 0xa5, 0xdb, 0xa3, 0x95, 0x6c,
+0x99, 0xf9, 0x11, 0x0d, 0x4d, 0x2e, 0xf0, 0xbd,
+0xee, 0x9b, 0x69, 0xb6, 0xcd, 0x88, 0x74, 0xbe,
+0x40, 0xe8, 0xe5, 0xcc, 0xdc, 0x88, 0x44, 0x53,
+},
+.y = {
+0xbf, 0xa9, 0x82, 0x0e, 0x18, 0x7a, 0x14, 0xf8,
+0x77, 0xfd, 0x8e, 0x92, 0x2a, 0xf8, 0x5d, 0x39,
+0xd1, 0x6d, 0x92, 0x1f, 0x38, 0x74, 0x99, 0xdc,
+0x6c, 0x2c, 0x94, 0x23, 0xf9, 0x72, 0x56, 0xab,
+},
+},
+.public_key_rsp = {
+.x = {
+0x72, 0x8c, 0xd1, 0x88, 0xd7, 0xbe, 0x49, 0xb2,
+0xc5, 0x5c, 0x95, 0xb3, 0x64, 0xe0, 0x12, 0x32,
+0xb6, 0xc9, 0x47, 0x63, 0x37, 0x38, 0x5b, 0x9c,
+0x1e, 0x1b, 0x1a, 0x06, 0x09, 0xe2, 0x31, 0x85,
+},
+.y = {
+0x19, 0x3a, 0x29, 0x69, 0x62, 0xd6, 0x30, 0xe7,
+0xe8, 0x48, 0x63, 0xdc, 0x00, 0x73, 0x0a, 0x70,
+0x7d, 0x2e, 0x29, 0xcc, 0x91, 0x77, 0x71, 0xb1,
+0x75, 0xb8, 0xf7, 0xdc, 0xb0, 0xe2, 0x91, 0x10,
+},
+},
+.confirm_rsp[0] = {
+.value = {
+0x82, 0xed, 0xd0, 0x62, 0x91, 0x3d, 0x96, 0x7f,
+0x13, 0xc5, 0x0d, 0x02, 0x2b, 0x5e, 0x43, 0x16,
+},
+},
+.random_req[0] = {
+.value = {
+0xa4, 0x34, 0x5f, 0xb3, 0xaf, 0x73, 0x43, 0x64,
+0xcd, 0x19, 0x1b, 0x5b, 0x87, 0x58, 0x31, 0x66,
+},
+},
+.random_rsp[0] = {
+.value = {
+0xc0, 0x91, 0xfb, 0xb3, 0x77, 0xa2, 0x02, 0x0b,
+0xc6, 0xcd, 0x6c, 0x04, 0x51, 0x45, 0x45, 0x39,
+},
+},
+.dhkey_check_req = {
+.value = {
+0x82, 0x65, 0x1d, 0x02, 0xed, 0x89, 0x13, 0x44,
+0x04, 0x1a, 0x14, 0x7c, 0x32, 0x9a, 0x1e, 0x7d,
+

[12/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/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
new file mode 100644
index 000..16a7309
--- /dev/null
+++ b/net/nimble/host/test/src/ble_gap_test.c
@@ -0,0 +1,2580 @@
+/**
+ * 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 
+#include 
+#include "testutil/testutil.h"
+#include "nimble/ble.h"
+#include "nimble/hci_common.h"
+#include "host/ble_hs_adv.h"
+#include "host/ble_hs_test.h"
+#include "ble_hs_test_util.h"
+
+static int ble_gap_test_conn_event_type;
+static int ble_gap_test_conn_status;
+static struct ble_gap_conn_desc ble_gap_test_conn_desc;
+static void *ble_gap_test_conn_arg;
+static struct ble_gap_upd_params ble_gap_test_conn_peer_params;
+static struct ble_gap_upd_params ble_gap_test_conn_self_params;
+
+static int ble_gap_test_disc_event_type;
+static struct ble_gap_disc_desc ble_gap_test_disc_desc;
+static void *ble_gap_test_disc_arg;
+
+/*
+ * $misc *
+ */
+
+static int
+ble_gap_test_util_update_in_progress(uint16_t conn_handle)
+{
+ble_hs_conn_flags_t conn_flags;
+int rc;
+
+rc = ble_hs_atomic_conn_flags(conn_handle, _flags);
+return rc == 0 && conn_flags & BLE_HS_CONN_F_UPDATE;
+}
+
+static void
+ble_gap_test_util_reset_cb_info(void)
+{
+ble_gap_test_conn_event_type = -1;
+ble_gap_test_conn_status = -1;
+memset(_gap_test_conn_desc, 0xff, sizeof ble_gap_test_conn_desc);
+ble_gap_test_conn_arg = (void *)-1;
+
+ble_gap_test_disc_event_type = -1;
+memset(_gap_test_disc_desc, 0xff, sizeof ble_gap_test_disc_desc);
+ble_gap_test_disc_arg = (void *)-1;
+}
+
+static void
+ble_gap_test_util_init(void)
+{
+ble_hs_test_util_init();
+ble_hs_test_util_set_static_rnd_addr();
+ble_gap_test_util_reset_cb_info();
+}
+
+static int
+ble_gap_test_util_disc_cb(struct ble_gap_event *event, void *arg)
+{
+ble_gap_test_disc_event_type = event->type;
+ble_gap_test_disc_arg = arg;
+
+if (event->type == BLE_GAP_EVENT_DISC) {
+ble_gap_test_disc_desc = event->disc;
+}
+
+return 0;
+}
+
+static int
+ble_gap_test_util_connect_cb(struct ble_gap_event *event, void *arg)
+{
+int *fail_reason;
+
+ble_gap_test_conn_event_type = event->type;
+ble_gap_test_conn_arg = arg;
+
+switch (event->type) {
+case BLE_GAP_EVENT_CONNECT:
+ble_gap_test_conn_status = event->connect.status;
+ble_gap_conn_find(event->connect.conn_handle, _gap_test_conn_desc);
+break;
+
+case BLE_GAP_EVENT_DISCONNECT:
+ble_gap_test_conn_status = event->disconnect.reason;
+ble_gap_test_conn_desc = event->disconnect.conn;
+break;
+
+case BLE_GAP_EVENT_CONN_UPDATE:
+ble_gap_test_conn_status = event->conn_update.status;
+ble_gap_conn_find(event->conn_update.conn_handle,
+  _gap_test_conn_desc);
+break;
+
+case BLE_GAP_EVENT_CONN_CANCEL:
+break;
+
+case BLE_GAP_EVENT_TERM_FAILURE:
+ble_gap_test_conn_status = event->term_failure.status;
+ble_gap_conn_find(event->term_failure.conn_handle,
+  _gap_test_conn_desc);
+break;
+
+case BLE_GAP_EVENT_ADV_COMPLETE:
+ble_gap_test_conn_arg = arg;
+break;
+
+case BLE_GAP_EVENT_CONN_UPDATE_REQ:
+ble_gap_test_conn_peer_params = *event->conn_update_req.peer_params;
+*event->conn_update_req.self_params = ble_gap_test_conn_self_params;
+ble_gap_conn_find(event->conn_update_req.conn_handle,
+  _gap_test_conn_desc);
+
+fail_reason = arg;
+if (fail_reason == NULL) {
+return 0;
+} else {
+return *fail_reason;
+}
+break;
+
+default:
+TEST_ASSERT_FATAL(0);
+break;
+}
+
+return 0;
+}
+
+static void

[29/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/mbedtls/test/src/mbedtls_test.c
--
diff --git a/libs/mbedtls/test/src/mbedtls_test.c 
b/libs/mbedtls/test/src/mbedtls_test.c
new file mode 100644
index 000..85038f8
--- /dev/null
+++ b/libs/mbedtls/test/src/mbedtls_test.c
@@ -0,0 +1,228 @@
+/**
+ * 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 
+#include 
+
+#include "syscfg/syscfg.h"
+#include "testutil/testutil.h"
+
+#include "mbedtls/mbedtls_test.h"
+#include "mbedtls/sha1.h"
+#include "mbedtls/sha256.h"
+#include "mbedtls/sha512.h"
+#include "mbedtls/aes.h"
+#include "mbedtls/arc4.h"
+#include "mbedtls/bignum.h"
+#include "mbedtls/ccm.h"
+#include "mbedtls/dhm.h"
+#include "mbedtls/ecjpake.h"
+#include "mbedtls/ecp.h"
+#include "mbedtls/entropy.h"
+#include "mbedtls/gcm.h"
+#include "mbedtls/hmac_drbg.h"
+#include "mbedtls/md5.h"
+#include "mbedtls/pkcs5.h"
+#include "mbedtls/ripemd160.h"
+#include "mbedtls/rsa.h"
+#include "mbedtls/x509.h"
+#include "mbedtls/xtea.h"
+
+TEST_CASE(sha1_test)
+{
+int rc;
+
+rc = mbedtls_sha1_self_test(0);
+TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(sha256_test)
+{
+int rc;
+
+rc = mbedtls_sha256_self_test(0);
+TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(sha512_test)
+{
+int rc;
+
+rc = mbedtls_sha512_self_test(1);
+TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(aes_test)
+{
+int rc;
+
+rc = mbedtls_aes_self_test(1);
+TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(arc4_test)
+{
+int rc;
+
+rc = mbedtls_arc4_self_test(1);
+TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(bignum_test)
+{
+int rc;
+
+rc = mbedtls_mpi_self_test(1);
+TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(ccm_test)
+{
+int rc;
+
+rc = mbedtls_ccm_self_test(1);
+TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(dhm_test)
+{
+int rc;
+
+rc = mbedtls_dhm_self_test(1);
+TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(ecp_test)
+{
+int rc;
+
+rc = mbedtls_ecp_self_test(1);
+TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(entropy_test)
+{
+#if 0 /* XXX fix this later, no strong entropy source atm */
+int rc;
+
+rc = mbedtls_entropy_self_test(1);
+TEST_ASSERT(rc == 0);
+#endif
+}
+
+TEST_CASE(gcm_test)
+{
+int rc;
+
+rc = mbedtls_gcm_self_test(1);
+TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(hmac_drbg_test)
+{
+int rc;
+
+rc = mbedtls_hmac_drbg_self_test(1);
+TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(md5_test)
+{
+int rc;
+
+rc = mbedtls_md5_self_test(1);
+TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(pkcs5_test)
+{
+int rc;
+
+rc = mbedtls_pkcs5_self_test(1);
+TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(ripemd160_test)
+{
+int rc;
+
+rc = mbedtls_ripemd160_self_test(1);
+TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(rsa_test)
+{
+int rc;
+
+rc = mbedtls_rsa_self_test(1);
+TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(x509_test)
+{
+int rc;
+
+rc = mbedtls_x509_self_test(1);
+TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(xtea_test)
+{
+int rc;
+
+rc = mbedtls_xtea_self_test(1);
+TEST_ASSERT(rc == 0);
+}
+
+
+TEST_SUITE(mbedtls_test_all)
+{
+sha1_test();
+sha256_test();
+sha512_test();
+aes_test();
+arc4_test();
+bignum_test();
+ccm_test();
+dhm_test();
+ecp_test();
+entropy_test();
+gcm_test();
+hmac_drbg_test();
+md5_test();
+pkcs5_test();
+ripemd160_test();
+rsa_test();
+x509_test();
+xtea_test();
+}
+
+#if MYNEWT_VAL(SELFTEST)
+int
+main(int argc, char **argv)
+{
+tu_config.tc_print_results = 1;
+tu_init();
+
+mbedtls_test_all();
+
+return tu_any_failed;
+}
+
+#endif
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/newtmgr/include/newtmgr/newtmgr.h
--
diff --git a/libs/newtmgr/include/newtmgr/newtmgr.h 
b/libs/newtmgr/include/newtmgr/newtmgr.h
index 0e5637b..00d1b00 100644
--- a/libs/newtmgr/include/newtmgr/newtmgr.h
+++ b/libs/newtmgr/include/newtmgr/newtmgr.h
@@ -127,7 +127,7 @@ struct nmgr_transport {
 };
 
 
-int nmgr_task_init(uint8_t, os_stack_t *, uint16_t);

[21/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/test/ble_gatt_read_test.c
--
diff --git a/net/nimble/host/src/test/ble_gatt_read_test.c 
b/net/nimble/host/src/test/ble_gatt_read_test.c
deleted file mode 100644
index 822de5c..000
--- a/net/nimble/host/src/test/ble_gatt_read_test.c
+++ /dev/null
@@ -1,823 +0,0 @@
-/**
- * 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 
-#include 
-#include 
-#include "testutil/testutil.h"
-#include "nimble/ble.h"
-#include "host/ble_hs_test.h"
-#include "host/ble_uuid.h"
-#include "ble_hs_test_util.h"
-
-struct ble_gatt_read_test_attr {
-uint16_t conn_handle;
-uint16_t handle;
-uint8_t value_len;
-uint8_t value[BLE_ATT_ATTR_MAX_LEN];
-};
-
-#define BLE_GATT_READ_TEST_MAX_ATTRS256
-
-struct ble_gatt_read_test_attr
-ble_gatt_read_test_attrs[BLE_GATT_READ_TEST_MAX_ATTRS];
-int ble_gatt_read_test_num_attrs;
-int ble_gatt_read_test_complete;
-
-uint16_t ble_gatt_read_test_bad_conn_handle;
-int ble_gatt_read_test_bad_status;
-
-static void
-ble_gatt_read_test_misc_init(void)
-{
-ble_hs_test_util_init();
-ble_gatt_read_test_num_attrs = 0;
-ble_gatt_read_test_complete = 0;
-ble_gatt_read_test_bad_conn_handle = 0;
-ble_gatt_read_test_bad_status = 0;
-
-memset(_gatt_read_test_attrs[0], 0,
-   sizeof ble_gatt_read_test_attrs[0]);
-}
-
-static int
-ble_gatt_read_test_cb(uint16_t conn_handle, const struct ble_gatt_error *error,
-  struct ble_gatt_attr *attr, void *arg)
-{
-struct ble_gatt_read_test_attr *dst;
-int *stop_after;
-
-stop_after = arg;
-
-TEST_ASSERT_FATAL(error != NULL);
-
-if (error->status != 0) {
-ble_gatt_read_test_bad_conn_handle = conn_handle;
-ble_gatt_read_test_bad_status = error->status;
-ble_gatt_read_test_complete = 1;
-return 0;
-}
-
-if (attr == NULL) {
-ble_gatt_read_test_complete = 1;
-return 0;
-}
-
-TEST_ASSERT_FATAL(ble_gatt_read_test_num_attrs <
-  BLE_GATT_READ_TEST_MAX_ATTRS);
-dst = ble_gatt_read_test_attrs + ble_gatt_read_test_num_attrs++;
-
-TEST_ASSERT_FATAL(OS_MBUF_PKTLEN(attr->om) <= sizeof dst->value);
-
-dst->conn_handle = conn_handle;
-dst->handle = attr->handle;
-dst->value_len = OS_MBUF_PKTLEN(attr->om);
-os_mbuf_copydata(attr->om, 0, OS_MBUF_PKTLEN(attr->om), dst->value);
-
-if (stop_after != NULL && *stop_after > 0) {
-(*stop_after)--;
-if (*stop_after == 0) {
-ble_gatt_read_test_complete = 1;
-return 1;
-}
-} else {
-ble_gatt_read_test_complete = 1;
-}
-
-return 0;
-}
-
-static int
-ble_gatt_read_test_long_cb(uint16_t conn_handle,
-   const struct ble_gatt_error *error,
-   struct ble_gatt_attr *attr, void *arg)
-{
-struct ble_gatt_read_test_attr *dst;
-int *reads_left;
-
-reads_left = arg;
-
-TEST_ASSERT_FATAL(error != NULL);
-
-if (error->status != 0) {
-ble_gatt_read_test_bad_conn_handle = conn_handle;
-ble_gatt_read_test_bad_status = error->status;
-ble_gatt_read_test_complete = 1;
-return 0;
-}
-
-if (attr == NULL) {
-ble_gatt_read_test_complete = 1;
-return 0;
-}
-
-dst = ble_gatt_read_test_attrs + 0;
-
-TEST_ASSERT_FATAL(OS_MBUF_PKTLEN(attr->om) <=
-dst->value_len + sizeof dst->value);
-TEST_ASSERT(attr->offset == dst->value_len);
-
-if (attr->offset == 0) {
-dst->conn_handle = conn_handle;
-dst->handle = attr->handle;
-} else {
-TEST_ASSERT(conn_handle == dst->conn_handle);
-TEST_ASSERT(attr->handle == dst->handle);
-}
-os_mbuf_copydata(attr->om, 0, OS_MBUF_PKTLEN(attr->om),
- dst->value + dst->value_len);
-dst->value_len += OS_MBUF_PKTLEN(attr->om);
-
-if (reads_left != NULL && *reads_left > 0) {
-(*reads_left)--;
-if (*reads_left == 0) {
-ble_gatt_read_test_complete = 1;
-return 1;
-}
-}
-
-return 0;

[30/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/bootutil/test/src/boot_test.c
--
diff --git a/libs/bootutil/test/src/boot_test.c 
b/libs/bootutil/test/src/boot_test.c
new file mode 100644
index 000..b86ca82
--- /dev/null
+++ b/libs/bootutil/test/src/boot_test.c
@@ -0,0 +1,1170 @@
+/**
+ * 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "syscfg/syscfg.h"
+#include "testutil/testutil.h"
+#include "hal/hal_flash.h"
+#include "hal/flash_map.h"
+#include "fs/fs.h"
+#include "nffs/nffs.h"
+#include "config/config_file.h"
+#include "bootutil/image.h"
+#include "bootutil/loader.h"
+#include "bootutil/bootutil_misc.h"
+#include "../src/bootutil_priv.h"
+
+#include "mbedtls/sha256.h"
+
+#define BOOT_TEST_HEADER_SIZE   0x200
+
+/** Internal flash layout. */
+static struct flash_area boot_test_area_descs[] = {
+[0] = { .fa_off = 0x0002, .fa_size = 128 * 1024 },
+[1] = { .fa_off = 0x0004, .fa_size = 128 * 1024 },
+[2] = { .fa_off = 0x0006, .fa_size = 128 * 1024 },
+[3] = { .fa_off = 0x0008, .fa_size = 128 * 1024 },
+[4] = { .fa_off = 0x000a, .fa_size = 128 * 1024 },
+[5] = { .fa_off = 0x000c, .fa_size = 128 * 1024 },
+[6] = { .fa_off = 0x000e, .fa_size = 128 * 1024 },
+};
+
+static const struct flash_area boot_test_format_descs[] = {
+[0] = { .fa_off = 0x4000, .fa_size = 16 * 1024 },
+[1] = { .fa_off = 0x8000, .fa_size = 16 * 1024 },
+[2] = { .fa_off = 0xc000, .fa_size = 16 * 1024 },
+[3] = { .fa_off = 0, .fa_size = 0 },
+};
+
+/** Areas representing the beginning of image slots. */
+static uint8_t boot_test_slot_areas[] = {
+0, 3,
+};
+
+/** Flash offsets of the two image slots. */
+static struct {
+uint8_t flash_id;
+uint32_t address;
+} boot_test_img_addrs[] = {
+{ 0, 0x2 },
+{ 0, 0x8 },
+};
+
+#define BOOT_TEST_AREA_IDX_SCRATCH 6
+
+#define MY_CONF_PATH "/cfg/run"
+
+static struct conf_file my_conf = {
+.cf_name = MY_CONF_PATH
+};
+
+static uint8_t
+boot_test_util_byte_at(int img_msb, uint32_t image_offset)
+{
+uint32_t u32;
+uint8_t *u8p;
+
+TEST_ASSERT(image_offset < 0x0100);
+u32 = image_offset + (img_msb << 24);
+u8p = (void *)
+return u8p[image_offset % 4];
+}
+
+static void
+boot_test_util_init_flash(void)
+{
+const struct flash_area *area_desc;
+int rc;
+struct nffs_area_desc nffs_descs[32];
+int cnt;
+
+rc = hal_flash_init();
+TEST_ASSERT(rc == 0);
+
+for (area_desc = boot_test_area_descs;
+ area_desc->fa_size != 0;
+ area_desc++) {
+
+rc = flash_area_erase(area_desc, 0, area_desc->fa_size);
+TEST_ASSERT(rc == 0);
+}
+cnt = 32;
+
+rc = nffs_misc_desc_from_flash_area(FLASH_AREA_NFFS, , nffs_descs);
+TEST_ASSERT(rc == 0);
+
+rc = nffs_init();
+TEST_ASSERT(rc == 0);
+rc = nffs_format(nffs_descs);
+TEST_ASSERT(rc == 0);
+
+fs_mkdir("/cfg");
+}
+
+static void
+boot_test_util_copy_area(int from_area_idx, int to_area_idx)
+{
+const struct flash_area *from_area_desc;
+const struct flash_area *to_area_desc;
+void *buf;
+int rc;
+
+from_area_desc = boot_test_area_descs + from_area_idx;
+to_area_desc = boot_test_area_descs + to_area_idx;
+
+TEST_ASSERT(from_area_desc->fa_size == to_area_desc->fa_size);
+
+buf = malloc(from_area_desc->fa_size);
+TEST_ASSERT(buf != NULL);
+
+rc = flash_area_read(from_area_desc, 0, buf,
+ from_area_desc->fa_size);
+TEST_ASSERT(rc == 0);
+
+rc = flash_area_erase(to_area_desc,
+  0,
+  to_area_desc->fa_size);
+TEST_ASSERT(rc == 0);
+
+rc = flash_area_write(to_area_desc, 0, buf,
+  to_area_desc->fa_size);
+TEST_ASSERT(rc == 0);
+
+free(buf);
+}
+
+static void
+boot_test_util_swap_areas(int area_idx1, int area_idx2)
+{
+const struct flash_area *area_desc1;
+const struct flash_area *area_desc2;
+void *buf1;
+void *buf2;
+int rc;
+
+

[22/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/test/ble_gatt_conn_test.c
--
diff --git a/net/nimble/host/src/test/ble_gatt_conn_test.c 
b/net/nimble/host/src/test/ble_gatt_conn_test.c
deleted file mode 100644
index be4a46d..000
--- a/net/nimble/host/src/test/ble_gatt_conn_test.c
+++ /dev/null
@@ -1,533 +0,0 @@
-/**
- * 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 
-#include 
-#include "testutil/testutil.h"
-#include "nimble/ble.h"
-#include "host/ble_hs_test.h"
-#include "ble_hs_test_util.h"
-
-#define BLE_GATT_BREAK_TEST_READ_ATTR_HANDLE0x9383
-#define BLE_GATT_BREAK_TEST_WRITE_ATTR_HANDLE   0x1234
-
-static uint8_t ble_gatt_conn_test_write_value[] = { 1, 3, 64, 21, 6 };
-
-struct ble_gatt_conn_test_cb_arg {
-uint16_t exp_conn_handle;
-int called;
-};
-
-static int
-ble_gatt_conn_test_attr_cb(uint16_t conn_handle, uint16_t attr_handle,
-   uint8_t op, uint16_t offset, struct os_mbuf **om,
-   void *arg)
-{
-uint8_t *buf;
-
-switch (op) {
-case BLE_ATT_ACCESS_OP_READ:
-buf = os_mbuf_extend(*om, 1);
-TEST_ASSERT_FATAL(buf != NULL);
-*buf = 1;
-return 0;
-
-default:
-return -1;
-}
-}
-
-static int
-ble_gatt_conn_test_mtu_cb(uint16_t conn_handle,
-  const struct ble_gatt_error *error,
-  uint16_t mtu, void *arg)
-{
-struct ble_gatt_conn_test_cb_arg *cb_arg;
-
-cb_arg = arg;
-
-TEST_ASSERT(cb_arg->exp_conn_handle == conn_handle);
-TEST_ASSERT(!cb_arg->called);
-TEST_ASSERT_FATAL(error != NULL);
-TEST_ASSERT(error->status == BLE_HS_ENOTCONN);
-TEST_ASSERT(mtu == 0);
-
-cb_arg->called++;
-
-return 0;
-}
-
-static int
-ble_gatt_conn_test_disc_all_svcs_cb(uint16_t conn_handle,
-const struct ble_gatt_error *error,
-const struct ble_gatt_svc *service,
-void *arg)
-{
-struct ble_gatt_conn_test_cb_arg *cb_arg;
-
-cb_arg = arg;
-
-TEST_ASSERT(cb_arg->exp_conn_handle == conn_handle);
-TEST_ASSERT(!cb_arg->called);
-TEST_ASSERT_FATAL(error != NULL);
-TEST_ASSERT(error->status == BLE_HS_ENOTCONN);
-TEST_ASSERT(service == NULL);
-
-cb_arg->called++;
-
-return 0;
-}
-
-static int
-ble_gatt_conn_test_disc_svc_uuid_cb(uint16_t conn_handle,
-const struct ble_gatt_error *error,
-const struct ble_gatt_svc *service,
-void *arg)
-{
-struct ble_gatt_conn_test_cb_arg *cb_arg;
-
-cb_arg = arg;
-
-TEST_ASSERT(cb_arg->exp_conn_handle == conn_handle);
-TEST_ASSERT(!cb_arg->called);
-TEST_ASSERT_FATAL(error != NULL);
-TEST_ASSERT(error->status == BLE_HS_ENOTCONN);
-TEST_ASSERT(service == NULL);
-
-cb_arg->called++;
-
-return 0;
-}
-
-static int
-ble_gatt_conn_test_find_inc_svcs_cb(uint16_t conn_handle,
-const struct ble_gatt_error *error,
-const struct ble_gatt_svc *service,
-void *arg)
-{
-struct ble_gatt_conn_test_cb_arg *cb_arg;
-
-cb_arg = arg;
-
-TEST_ASSERT(cb_arg->exp_conn_handle == conn_handle);
-TEST_ASSERT(!cb_arg->called);
-TEST_ASSERT_FATAL(error != NULL);
-TEST_ASSERT(error->status == BLE_HS_ENOTCONN);
-TEST_ASSERT(service == NULL);
-
-cb_arg->called++;
-
-return 0;
-}
-
-static int
-ble_gatt_conn_test_disc_all_chrs_cb(uint16_t conn_handle,
-const struct ble_gatt_error *error,
-const struct ble_gatt_chr *chr, void *arg)
-{
-struct ble_gatt_conn_test_cb_arg *cb_arg;
-
-cb_arg = arg;
-
-TEST_ASSERT(cb_arg->exp_conn_handle == conn_handle);
-TEST_ASSERT(!cb_arg->called);
-TEST_ASSERT_FATAL(error != NULL);
-TEST_ASSERT(error->status == BLE_HS_ENOTCONN);
-TEST_ASSERT(chr == NULL);
-
-cb_arg->called++;
-
-

[11/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/test/src/ble_gatt_conn_test.c
--
diff --git a/net/nimble/host/test/src/ble_gatt_conn_test.c 
b/net/nimble/host/test/src/ble_gatt_conn_test.c
new file mode 100644
index 000..be4a46d
--- /dev/null
+++ b/net/nimble/host/test/src/ble_gatt_conn_test.c
@@ -0,0 +1,533 @@
+/**
+ * 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 
+#include 
+#include "testutil/testutil.h"
+#include "nimble/ble.h"
+#include "host/ble_hs_test.h"
+#include "ble_hs_test_util.h"
+
+#define BLE_GATT_BREAK_TEST_READ_ATTR_HANDLE0x9383
+#define BLE_GATT_BREAK_TEST_WRITE_ATTR_HANDLE   0x1234
+
+static uint8_t ble_gatt_conn_test_write_value[] = { 1, 3, 64, 21, 6 };
+
+struct ble_gatt_conn_test_cb_arg {
+uint16_t exp_conn_handle;
+int called;
+};
+
+static int
+ble_gatt_conn_test_attr_cb(uint16_t conn_handle, uint16_t attr_handle,
+   uint8_t op, uint16_t offset, struct os_mbuf **om,
+   void *arg)
+{
+uint8_t *buf;
+
+switch (op) {
+case BLE_ATT_ACCESS_OP_READ:
+buf = os_mbuf_extend(*om, 1);
+TEST_ASSERT_FATAL(buf != NULL);
+*buf = 1;
+return 0;
+
+default:
+return -1;
+}
+}
+
+static int
+ble_gatt_conn_test_mtu_cb(uint16_t conn_handle,
+  const struct ble_gatt_error *error,
+  uint16_t mtu, void *arg)
+{
+struct ble_gatt_conn_test_cb_arg *cb_arg;
+
+cb_arg = arg;
+
+TEST_ASSERT(cb_arg->exp_conn_handle == conn_handle);
+TEST_ASSERT(!cb_arg->called);
+TEST_ASSERT_FATAL(error != NULL);
+TEST_ASSERT(error->status == BLE_HS_ENOTCONN);
+TEST_ASSERT(mtu == 0);
+
+cb_arg->called++;
+
+return 0;
+}
+
+static int
+ble_gatt_conn_test_disc_all_svcs_cb(uint16_t conn_handle,
+const struct ble_gatt_error *error,
+const struct ble_gatt_svc *service,
+void *arg)
+{
+struct ble_gatt_conn_test_cb_arg *cb_arg;
+
+cb_arg = arg;
+
+TEST_ASSERT(cb_arg->exp_conn_handle == conn_handle);
+TEST_ASSERT(!cb_arg->called);
+TEST_ASSERT_FATAL(error != NULL);
+TEST_ASSERT(error->status == BLE_HS_ENOTCONN);
+TEST_ASSERT(service == NULL);
+
+cb_arg->called++;
+
+return 0;
+}
+
+static int
+ble_gatt_conn_test_disc_svc_uuid_cb(uint16_t conn_handle,
+const struct ble_gatt_error *error,
+const struct ble_gatt_svc *service,
+void *arg)
+{
+struct ble_gatt_conn_test_cb_arg *cb_arg;
+
+cb_arg = arg;
+
+TEST_ASSERT(cb_arg->exp_conn_handle == conn_handle);
+TEST_ASSERT(!cb_arg->called);
+TEST_ASSERT_FATAL(error != NULL);
+TEST_ASSERT(error->status == BLE_HS_ENOTCONN);
+TEST_ASSERT(service == NULL);
+
+cb_arg->called++;
+
+return 0;
+}
+
+static int
+ble_gatt_conn_test_find_inc_svcs_cb(uint16_t conn_handle,
+const struct ble_gatt_error *error,
+const struct ble_gatt_svc *service,
+void *arg)
+{
+struct ble_gatt_conn_test_cb_arg *cb_arg;
+
+cb_arg = arg;
+
+TEST_ASSERT(cb_arg->exp_conn_handle == conn_handle);
+TEST_ASSERT(!cb_arg->called);
+TEST_ASSERT_FATAL(error != NULL);
+TEST_ASSERT(error->status == BLE_HS_ENOTCONN);
+TEST_ASSERT(service == NULL);
+
+cb_arg->called++;
+
+return 0;
+}
+
+static int
+ble_gatt_conn_test_disc_all_chrs_cb(uint16_t conn_handle,
+const struct ble_gatt_error *error,
+const struct ble_gatt_chr *chr, void *arg)
+{
+struct ble_gatt_conn_test_cb_arg *cb_arg;
+
+cb_arg = arg;
+
+TEST_ASSERT(cb_arg->exp_conn_handle == conn_handle);
+TEST_ASSERT(!cb_arg->called);
+TEST_ASSERT_FATAL(error != NULL);
+TEST_ASSERT(error->status == BLE_HS_ENOTCONN);
+TEST_ASSERT(chr == NULL);
+
+cb_arg->called++;
+
+

[31/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/bootutil/src/test/boot_test.c
--
diff --git a/libs/bootutil/src/test/boot_test.c 
b/libs/bootutil/src/test/boot_test.c
deleted file mode 100644
index e78d2e4..000
--- a/libs/bootutil/src/test/boot_test.c
+++ /dev/null
@@ -1,1169 +0,0 @@
-/**
- * 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 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include "testutil/testutil.h"
-#include "hal/hal_flash.h"
-#include "hal/flash_map.h"
-#include "fs/fs.h"
-#include "nffs/nffs.h"
-#include 
-#include "bootutil/image.h"
-#include "bootutil/loader.h"
-#include "bootutil/bootutil_misc.h"
-#include "../src/bootutil_priv.h"
-
-#include "mbedtls/sha256.h"
-
-#define BOOT_TEST_HEADER_SIZE   0x200
-
-/** Internal flash layout. */
-static struct flash_area boot_test_area_descs[] = {
-[0] = { .fa_off = 0x0002, .fa_size = 128 * 1024 },
-[1] = { .fa_off = 0x0004, .fa_size = 128 * 1024 },
-[2] = { .fa_off = 0x0006, .fa_size = 128 * 1024 },
-[3] = { .fa_off = 0x0008, .fa_size = 128 * 1024 },
-[4] = { .fa_off = 0x000a, .fa_size = 128 * 1024 },
-[5] = { .fa_off = 0x000c, .fa_size = 128 * 1024 },
-[6] = { .fa_off = 0x000e, .fa_size = 128 * 1024 },
-};
-
-static const struct flash_area boot_test_format_descs[] = {
-[0] = { .fa_off = 0x4000, .fa_size = 16 * 1024 },
-[1] = { .fa_off = 0x8000, .fa_size = 16 * 1024 },
-[2] = { .fa_off = 0xc000, .fa_size = 16 * 1024 },
-[3] = { .fa_off = 0, .fa_size = 0 },
-};
-
-/** Areas representing the beginning of image slots. */
-static uint8_t boot_test_slot_areas[] = {
-0, 3,
-};
-
-/** Flash offsets of the two image slots. */
-static struct {
-uint8_t flash_id;
-uint32_t address;
-} boot_test_img_addrs[] = {
-{ 0, 0x2 },
-{ 0, 0x8 },
-};
-
-#define BOOT_TEST_AREA_IDX_SCRATCH 6
-
-#define MY_CONF_PATH "/cfg/run"
-
-static struct conf_file my_conf = {
-.cf_name = MY_CONF_PATH
-};
-
-static uint8_t
-boot_test_util_byte_at(int img_msb, uint32_t image_offset)
-{
-uint32_t u32;
-uint8_t *u8p;
-
-TEST_ASSERT(image_offset < 0x0100);
-u32 = image_offset + (img_msb << 24);
-u8p = (void *)
-return u8p[image_offset % 4];
-}
-
-static void
-boot_test_util_init_flash(void)
-{
-const struct flash_area *area_desc;
-int rc;
-struct nffs_area_desc nffs_descs[32];
-int cnt;
-
-rc = hal_flash_init();
-TEST_ASSERT(rc == 0);
-
-for (area_desc = boot_test_area_descs;
- area_desc->fa_size != 0;
- area_desc++) {
-
-rc = flash_area_erase(area_desc, 0, area_desc->fa_size);
-TEST_ASSERT(rc == 0);
-}
-cnt = 32;
-
-rc = flash_area_to_nffs_desc(FLASH_AREA_NFFS, , nffs_descs);
-TEST_ASSERT(rc == 0);
-
-rc = nffs_init();
-TEST_ASSERT(rc == 0);
-rc = nffs_format(nffs_descs);
-TEST_ASSERT(rc == 0);
-
-fs_mkdir("/cfg");
-}
-
-static void
-boot_test_util_copy_area(int from_area_idx, int to_area_idx)
-{
-const struct flash_area *from_area_desc;
-const struct flash_area *to_area_desc;
-void *buf;
-int rc;
-
-from_area_desc = boot_test_area_descs + from_area_idx;
-to_area_desc = boot_test_area_descs + to_area_idx;
-
-TEST_ASSERT(from_area_desc->fa_size == to_area_desc->fa_size);
-
-buf = malloc(from_area_desc->fa_size);
-TEST_ASSERT(buf != NULL);
-
-rc = flash_area_read(from_area_desc, 0, buf,
- from_area_desc->fa_size);
-TEST_ASSERT(rc == 0);
-
-rc = flash_area_erase(to_area_desc,
-  0,
-  to_area_desc->fa_size);
-TEST_ASSERT(rc == 0);
-
-rc = flash_area_write(to_area_desc, 0, buf,
-  to_area_desc->fa_size);
-TEST_ASSERT(rc == 0);
-
-free(buf);
-}
-
-static void
-boot_test_util_swap_areas(int area_idx1, int area_idx2)
-{
-const struct flash_area *area_desc1;
-const struct flash_area *area_desc2;
-void *buf1;
-void *buf2;
-int rc;
-
-area_desc1 = boot_test_area_descs + area_idx1;
-

[10/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/test/src/ble_gatt_read_test.c
--
diff --git a/net/nimble/host/test/src/ble_gatt_read_test.c 
b/net/nimble/host/test/src/ble_gatt_read_test.c
new file mode 100644
index 000..822de5c
--- /dev/null
+++ b/net/nimble/host/test/src/ble_gatt_read_test.c
@@ -0,0 +1,823 @@
+/**
+ * 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 
+#include 
+#include 
+#include "testutil/testutil.h"
+#include "nimble/ble.h"
+#include "host/ble_hs_test.h"
+#include "host/ble_uuid.h"
+#include "ble_hs_test_util.h"
+
+struct ble_gatt_read_test_attr {
+uint16_t conn_handle;
+uint16_t handle;
+uint8_t value_len;
+uint8_t value[BLE_ATT_ATTR_MAX_LEN];
+};
+
+#define BLE_GATT_READ_TEST_MAX_ATTRS256
+
+struct ble_gatt_read_test_attr
+ble_gatt_read_test_attrs[BLE_GATT_READ_TEST_MAX_ATTRS];
+int ble_gatt_read_test_num_attrs;
+int ble_gatt_read_test_complete;
+
+uint16_t ble_gatt_read_test_bad_conn_handle;
+int ble_gatt_read_test_bad_status;
+
+static void
+ble_gatt_read_test_misc_init(void)
+{
+ble_hs_test_util_init();
+ble_gatt_read_test_num_attrs = 0;
+ble_gatt_read_test_complete = 0;
+ble_gatt_read_test_bad_conn_handle = 0;
+ble_gatt_read_test_bad_status = 0;
+
+memset(_gatt_read_test_attrs[0], 0,
+   sizeof ble_gatt_read_test_attrs[0]);
+}
+
+static int
+ble_gatt_read_test_cb(uint16_t conn_handle, const struct ble_gatt_error *error,
+  struct ble_gatt_attr *attr, void *arg)
+{
+struct ble_gatt_read_test_attr *dst;
+int *stop_after;
+
+stop_after = arg;
+
+TEST_ASSERT_FATAL(error != NULL);
+
+if (error->status != 0) {
+ble_gatt_read_test_bad_conn_handle = conn_handle;
+ble_gatt_read_test_bad_status = error->status;
+ble_gatt_read_test_complete = 1;
+return 0;
+}
+
+if (attr == NULL) {
+ble_gatt_read_test_complete = 1;
+return 0;
+}
+
+TEST_ASSERT_FATAL(ble_gatt_read_test_num_attrs <
+  BLE_GATT_READ_TEST_MAX_ATTRS);
+dst = ble_gatt_read_test_attrs + ble_gatt_read_test_num_attrs++;
+
+TEST_ASSERT_FATAL(OS_MBUF_PKTLEN(attr->om) <= sizeof dst->value);
+
+dst->conn_handle = conn_handle;
+dst->handle = attr->handle;
+dst->value_len = OS_MBUF_PKTLEN(attr->om);
+os_mbuf_copydata(attr->om, 0, OS_MBUF_PKTLEN(attr->om), dst->value);
+
+if (stop_after != NULL && *stop_after > 0) {
+(*stop_after)--;
+if (*stop_after == 0) {
+ble_gatt_read_test_complete = 1;
+return 1;
+}
+} else {
+ble_gatt_read_test_complete = 1;
+}
+
+return 0;
+}
+
+static int
+ble_gatt_read_test_long_cb(uint16_t conn_handle,
+   const struct ble_gatt_error *error,
+   struct ble_gatt_attr *attr, void *arg)
+{
+struct ble_gatt_read_test_attr *dst;
+int *reads_left;
+
+reads_left = arg;
+
+TEST_ASSERT_FATAL(error != NULL);
+
+if (error->status != 0) {
+ble_gatt_read_test_bad_conn_handle = conn_handle;
+ble_gatt_read_test_bad_status = error->status;
+ble_gatt_read_test_complete = 1;
+return 0;
+}
+
+if (attr == NULL) {
+ble_gatt_read_test_complete = 1;
+return 0;
+}
+
+dst = ble_gatt_read_test_attrs + 0;
+
+TEST_ASSERT_FATAL(OS_MBUF_PKTLEN(attr->om) <=
+dst->value_len + sizeof dst->value);
+TEST_ASSERT(attr->offset == dst->value_len);
+
+if (attr->offset == 0) {
+dst->conn_handle = conn_handle;
+dst->handle = attr->handle;
+} else {
+TEST_ASSERT(conn_handle == dst->conn_handle);
+TEST_ASSERT(attr->handle == dst->handle);
+}
+os_mbuf_copydata(attr->om, 0, OS_MBUF_PKTLEN(attr->om),
+ dst->value + dst->value_len);
+dst->value_len += OS_MBUF_PKTLEN(attr->om);
+
+if (reads_left != NULL && *reads_left > 0) {
+(*reads_left)--;
+if (*reads_left == 0) {
+ble_gatt_read_test_complete = 1;
+return 1;
+}
+}
+
+return 0;
+}

[39/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/fs/nffs/src/test/arch/sim/nffs_test.c
--
diff --git a/fs/nffs/src/test/arch/sim/nffs_test.c 
b/fs/nffs/src/test/arch/sim/nffs_test.c
deleted file mode 100644
index a61b4bc..000
--- a/fs/nffs/src/test/arch/sim/nffs_test.c
+++ /dev/null
@@ -1,3250 +0,0 @@
-/**
- * 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 
-#include 
-#include 
-#include 
-#include 
-#include "hal/hal_flash.h"
-#include "testutil/testutil.h"
-#include "fs/fs.h"
-#include "nffs/nffs.h"
-#include "nffs/nffs_test.h"
-#include "nffs_test_priv.h"
-#include "nffs_priv.h"
-
-int flash_native_memset(uint32_t offset, uint8_t c, uint32_t len);
-
-static const struct nffs_area_desc nffs_area_descs[] = {
-{ 0x, 16 * 1024 },
-{ 0x4000, 16 * 1024 },
-{ 0x8000, 16 * 1024 },
-{ 0xc000, 16 * 1024 },
-{ 0x0001, 64 * 1024 },
-{ 0x0002, 128 * 1024 },
-{ 0x0004, 128 * 1024 },
-{ 0x0006, 128 * 1024 },
-{ 0x0008, 128 * 1024 },
-{ 0x000a, 128 * 1024 },
-{ 0x000c, 128 * 1024 },
-{ 0x000e, 128 * 1024 },
-{ 0, 0 },
-};
-
-static void
-nffs_test_util_assert_ent_name(struct fs_dirent *dirent,
-   const char *expected_name)
-{
-char name[NFFS_FILENAME_MAX_LEN + 1];
-uint8_t name_len;
-int rc;
-
-rc = fs_dirent_name(dirent, sizeof name, name, _len);
-TEST_ASSERT(rc == 0);
-if (rc == 0) {
-TEST_ASSERT(strcmp(name, expected_name) == 0);
-}
-}
-
-static void
-nffs_test_util_assert_file_len(struct fs_file *file, uint32_t expected)
-{
-uint32_t len;
-int rc;
-
-rc = fs_filelen(file, );
-TEST_ASSERT(rc == 0);
-TEST_ASSERT(len == expected);
-}
-
-static void
-nffs_test_util_assert_cache_is_sane(const char *filename)
-{
-struct nffs_cache_inode *cache_inode;
-struct nffs_cache_block *cache_block;
-struct fs_file *fs_file;
-struct nffs_file *file;
-uint32_t cache_start;
-uint32_t cache_end;
-uint32_t block_end;
-int rc;
-
-rc = fs_open(filename, FS_ACCESS_READ, _file);
-TEST_ASSERT(rc == 0);
-
-file = (struct nffs_file *)fs_file;
-rc = nffs_cache_inode_ensure(_inode, file->nf_inode_entry);
-TEST_ASSERT(rc == 0);
-
-nffs_cache_inode_range(cache_inode, _start, _end);
-
-if (TAILQ_EMPTY(_inode->nci_block_list)) {
-TEST_ASSERT(cache_start == 0 && cache_end == 0);
-} else {
-block_end = 0;  /* Pacify gcc. */
-TAILQ_FOREACH(cache_block, _inode->nci_block_list, ncb_link) {
-if (cache_block == TAILQ_FIRST(_inode->nci_block_list)) {
-TEST_ASSERT(cache_block->ncb_file_offset == cache_start);
-} else {
-/* Ensure no gap between this block and its predecessor. */
-TEST_ASSERT(cache_block->ncb_file_offset == block_end);
-}
-
-block_end = cache_block->ncb_file_offset +
-cache_block->ncb_block.nb_data_len;
-if (cache_block == TAILQ_LAST(_inode->nci_block_list,
-  nffs_cache_block_list)) {
-
-TEST_ASSERT(block_end == cache_end);
-}
-}
-}
-
-rc = fs_close(fs_file);
-TEST_ASSERT(rc == 0);
-}
-
-static void
-nffs_test_util_assert_contents(const char *filename, const char *contents,
-   int contents_len)
-{
-struct fs_file *file;
-uint32_t bytes_read;
-void *buf;
-int rc;
-
-rc = fs_open(filename, FS_ACCESS_READ, );
-TEST_ASSERT(rc == 0);
-
-buf = malloc(contents_len + 1);
-TEST_ASSERT(buf != NULL);
-
-rc = fs_read(file, contents_len + 1, buf, _read);
-TEST_ASSERT(rc == 0);
-TEST_ASSERT(bytes_read == contents_len);
-TEST_ASSERT(memcmp(buf, contents, contents_len) == 0);
-
-rc = fs_close(file);
-TEST_ASSERT(rc == 0);
-
-free(buf);
-
-nffs_test_util_assert_cache_is_sane(filename);
-}
-
-static int
-nffs_test_util_block_count(const char *filename)
-{
-

[03/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/test/src/ble_sm_test_util.h
--
diff --git a/net/nimble/host/test/src/ble_sm_test_util.h 
b/net/nimble/host/test/src/ble_sm_test_util.h
new file mode 100644
index 000..3323be6
--- /dev/null
+++ b/net/nimble/host/test/src/ble_sm_test_util.h
@@ -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.
+ */
+
+#ifndef H_BLE_SM_TEST_UTIL_
+#define H_BLE_SM_TEST_UTIL_
+
+struct ble_sm_test_passkey_info {
+struct ble_sm_io passkey;
+uint32_t exp_numcmp;
+unsigned io_before_rx:1;
+};
+
+struct ble_sm_test_params {
+uint8_t init_addr_type;
+uint8_t init_id_addr[6];
+uint8_t init_rpa[6];
+uint8_t resp_addr_type;
+uint8_t resp_id_addr[6];
+uint8_t resp_rpa[6];
+struct ble_sm_test_passkey_info passkey_info;
+
+struct ble_sm_sec_req sec_req;
+struct ble_sm_pair_cmd pair_req;
+struct ble_sm_pair_cmd pair_rsp;
+struct ble_sm_pair_confirm confirm_req[20];
+struct ble_sm_pair_confirm confirm_rsp[20];
+struct ble_sm_pair_random random_req[20];
+struct ble_sm_pair_random random_rsp[20];
+struct ble_sm_id_info id_info_req;
+struct ble_sm_id_info id_info_rsp;
+struct ble_sm_id_addr_info id_addr_info_req;
+struct ble_sm_id_addr_info id_addr_info_rsp;
+struct ble_sm_sign_info sign_info_req;
+struct ble_sm_sign_info sign_info_rsp;
+struct ble_sm_pair_fail pair_fail;
+
+int pair_alg;
+unsigned authenticated:1;
+
+/*** Secure connections fields. */
+uint8_t ltk[16];
+uint8_t our_priv_key[32];
+struct ble_sm_public_key public_key_req;
+struct ble_sm_public_key public_key_rsp;
+struct ble_sm_dhkey_check dhkey_check_req;
+struct ble_sm_dhkey_check dhkey_check_rsp;
+
+/*** Legacy fields. */
+uint8_t stk[16];
+struct ble_sm_enc_info enc_info_req;
+struct ble_sm_enc_info enc_info_rsp;
+struct ble_sm_master_id master_id_req;
+struct ble_sm_master_id master_id_rsp;
+};
+
+extern int ble_sm_test_gap_event;
+extern int ble_sm_test_gap_status;
+extern struct ble_gap_sec_state ble_sm_test_sec_state;
+
+extern int ble_sm_test_store_obj_type;
+extern union ble_store_key ble_sm_test_store_key;
+extern union ble_store_value ble_sm_test_store_value;
+
+void ble_sm_test_util_init(void);
+int ble_sm_test_util_conn_cb(struct ble_gap_event *ctxt, void *arg);
+void ble_sm_test_util_io_inject(struct ble_sm_test_passkey_info *passkey_info,
+uint8_t cur_sm_state);
+void ble_sm_test_util_io_inject_bad(uint16_t conn_handle,
+uint8_t correct_io_act);
+void ble_sm_test_util_io_check_pre(
+struct ble_sm_test_passkey_info *passkey_info,
+uint8_t cur_sm_state);
+void ble_sm_test_util_io_check_post(
+struct ble_sm_test_passkey_info *passkey_info,
+uint8_t cur_sm_state);
+void ble_sm_test_util_rx_sec_req(uint16_t conn_handle,
+ struct ble_sm_sec_req *cmd,
+ int exp_status);
+void ble_sm_test_util_verify_tx_pair_fail(struct ble_sm_pair_fail *exp_cmd);
+void ble_sm_test_util_us_lgcy_good(struct ble_sm_test_params *params);
+void ble_sm_test_util_peer_fail_inval(int we_are_master,
+  uint8_t *init_addr,
+  uint8_t *resp_addr,
+  struct ble_sm_pair_cmd *pair_req,
+  struct ble_sm_pair_fail *pair_fail);
+void ble_sm_test_util_peer_lgcy_fail_confirm(
+uint8_t *init_addr,
+uint8_t *resp_addr,
+struct ble_sm_pair_cmd *pair_req,
+struct ble_sm_pair_cmd *pair_rsp,
+struct ble_sm_pair_confirm *confirm_req,
+struct ble_sm_pair_confirm *confirm_rsp,
+struct ble_sm_pair_random *random_req,
+struct ble_sm_pair_random *random_rsp,
+struct ble_sm_pair_fail *fail_rsp);
+
+void ble_sm_test_util_peer_lgcy_good(struct ble_sm_test_params *params);
+void ble_sm_test_util_peer_bonding_bad(uint16_t ediv, uint64_t rand_num);
+void ble_sm_test_util_peer_sc_good(struct ble_sm_test_params 

[05/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/test/src/ble_sm_test.c
--
diff --git a/net/nimble/host/test/src/ble_sm_test.c 
b/net/nimble/host/test/src/ble_sm_test.c
new file mode 100644
index 000..980bb72
--- /dev/null
+++ b/net/nimble/host/test/src/ble_sm_test.c
@@ -0,0 +1,678 @@
+/**
+ * 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 
+#include 
+#include 
+#include "testutil/testutil.h"
+#include "nimble/hci_common.h"
+#include "nimble/nimble_opt.h"
+#include "host/ble_sm.h"
+#include "host/ble_hs_test.h"
+#include "ble_hs_test_util.h"
+#include "ble_sm_test_util.h"
+
+#if NIMBLE_BLE_SM
+
+/*
+ * $misc *
+ */
+
+TEST_CASE(ble_sm_test_case_f4)
+{
+   uint8_t u[32] = { 0xe6, 0x9d, 0x35, 0x0e, 0x48, 0x01, 0x03, 0xcc,
+ 0xdb, 0xfd, 0xf4, 0xac, 0x11, 0x91, 0xf4, 0xef,
+ 0xb9, 0xa5, 0xf9, 0xe9, 0xa7, 0x83, 0x2c, 0x5e,
+ 0x2c, 0xbe, 0x97, 0xf2, 0xd2, 0x03, 0xb0, 0x20 };
+   uint8_t v[32] = { 0xfd, 0xc5, 0x7f, 0xf4, 0x49, 0xdd, 0x4f, 0x6b,
+ 0xfb, 0x7c, 0x9d, 0xf1, 0xc2, 0x9a, 0xcb, 0x59,
+ 0x2a, 0xe7, 0xd4, 0xee, 0xfb, 0xfc, 0x0a, 0x90,
+ 0x9a, 0xbb, 0xf6, 0x32, 0x3d, 0x8b, 0x18, 0x55 };
+   uint8_t x[16] = { 0xab, 0xae, 0x2b, 0x71, 0xec, 0xb2, 0xff, 0xff,
+ 0x3e, 0x73, 0x77, 0xd1, 0x54, 0x84, 0xcb, 0xd5 };
+   uint8_t z = 0x00;
+   uint8_t exp[16] = { 0x2d, 0x87, 0x74, 0xa9, 0xbe, 0xa1, 0xed, 0xf1,
+   0x1c, 0xbd, 0xa9, 0x07, 0xf1, 0x16, 0xc9, 0xf2 };
+   uint8_t res[16];
+   int err;
+
+   err = ble_sm_alg_f4(u, v, x, z, res);
+   TEST_ASSERT_FATAL(err == 0);
+TEST_ASSERT(memcmp(res, exp, 16) == 0);
+}
+
+TEST_CASE(ble_sm_test_case_f5)
+{
+   uint8_t w[32] = { 0x98, 0xa6, 0xbf, 0x73, 0xf3, 0x34, 0x8d, 0x86,
+ 0xf1, 0x66, 0xf8, 0xb4, 0x13, 0x6b, 0x79, 0x99,
+ 0x9b, 0x7d, 0x39, 0x0a, 0xa6, 0x10, 0x10, 0x34,
+ 0x05, 0xad, 0xc8, 0x57, 0xa3, 0x34, 0x02, 0xec };
+   uint8_t n1[16] = { 0xab, 0xae, 0x2b, 0x71, 0xec, 0xb2, 0xff, 0xff,
+  0x3e, 0x73, 0x77, 0xd1, 0x54, 0x84, 0xcb, 0xd5 };
+   uint8_t n2[16] = { 0xcf, 0xc4, 0x3d, 0xff, 0xf7, 0x83, 0x65, 0x21,
+  0x6e, 0x5f, 0xa7, 0x25, 0xcc, 0xe7, 0xe8, 0xa6 };
+uint8_t a1t = 0x00;
+   uint8_t a1[6] = { 0xce, 0xbf, 0x37, 0x37, 0x12, 0x56 };
+uint8_t a2t = 0x00;
+uint8_t a2[6] = { 0xc1, 0xcf, 0x2d, 0x70, 0x13, 0xa7 };
+   uint8_t exp_ltk[16] = { 0x38, 0x0a, 0x75, 0x94, 0xb5, 0x22, 0x05,
+   0x98, 0x23, 0xcd, 0xd7, 0x69, 0x11, 0x79,
+   0x86, 0x69 };
+   uint8_t exp_mackey[16] = { 0x20, 0x6e, 0x63, 0xce, 0x20, 0x6a, 0x3f,
+  0xfd, 0x02, 0x4a, 0x08, 0xa1, 0x76, 0xf1,
+  0x65, 0x29 };
+   uint8_t mackey[16], ltk[16];
+   int err;
+
+   err = ble_sm_alg_f5(w, n1, n2, a1t, a1, a2t, a2, mackey, ltk);
+   TEST_ASSERT_FATAL(err == 0);
+TEST_ASSERT(memcmp(mackey, exp_mackey, 16) == 0);
+TEST_ASSERT(memcmp(ltk, exp_ltk, 16) == 0);
+}
+
+TEST_CASE(ble_sm_test_case_f6)
+{
+   uint8_t w[16] = { 0x20, 0x6e, 0x63, 0xce, 0x20, 0x6a, 0x3f, 0xfd,
+ 0x02, 0x4a, 0x08, 0xa1, 0x76, 0xf1, 0x65, 0x29 };
+   uint8_t n1[16] = { 0xab, 0xae, 0x2b, 0x71, 0xec, 0xb2, 0xff, 0xff,
+  0x3e, 0x73, 0x77, 0xd1, 0x54, 0x84, 0xcb, 0xd5 };
+   uint8_t n2[16] = { 0xcf, 0xc4, 0x3d, 0xff, 0xf7, 0x83, 0x65, 0x21,
+  0x6e, 0x5f, 0xa7, 0x25, 0xcc, 0xe7, 0xe8, 0xa6 };
+   uint8_t r[16] = { 0xc8, 0x0f, 0x2d, 0x0c, 0xd2, 0x42, 0xda, 0x08,
+ 0x54, 0xbb, 0x53, 0xb4, 0x3b, 0x34, 0xa3, 0x12 

[40/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/fs/fs/src/fs_cli.c
--
diff --git a/fs/fs/src/fs_cli.c b/fs/fs/src/fs_cli.c
index 4498d87..d481c6e 100644
--- a/fs/fs/src/fs_cli.c
+++ b/fs/fs/src/fs_cli.c
@@ -17,7 +17,9 @@
  * under the License.
  */
 
-#ifdef SHELL_PRESENT
+#include "syscfg/syscfg.h"
+
+#if MYNEWT_VAL(FS_CLI)
 
 #include 
 #include 
@@ -227,4 +229,4 @@ fs_cli_init(void)
 shell_cmd_register(_mv_struct);
 shell_cmd_register(_cat_struct);
 }
-#endif /* SHELL_PRESENT */
+#endif /* MYNEWT_VAL(FS_CLI) */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/fs/fs/src/fs_mount.c
--
diff --git a/fs/fs/src/fs_mount.c b/fs/fs/src/fs_mount.c
index 9653505..374fa1b 100644
--- a/fs/fs/src/fs_mount.c
+++ b/fs/fs/src/fs_mount.c
@@ -16,8 +16,10 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-#include 
-#include 
+
+#include "syscfg/syscfg.h"
+#include "fs/fs.h"
+#include "fs/fs_if.h"
 #include "fs_priv.h"
 
 const struct fs_ops *fs_root_ops = NULL;
@@ -30,7 +32,7 @@ fs_register(const struct fs_ops *fops)
 }
 fs_root_ops = fops;
 
-#ifdef SHELL_PRESENT
+#if MYNEWT_VAL(FS_CLI)
 fs_cli_init();
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/fs/fs/src/fs_priv.h
--
diff --git a/fs/fs/src/fs_priv.h b/fs/fs/src/fs_priv.h
index af08e2f..f8f092d 100644
--- a/fs/fs/src/fs_priv.h
+++ b/fs/fs/src/fs_priv.h
@@ -19,11 +19,13 @@
 #ifndef __FS_PRIV_H__
 #define __FS_PRIV_H__
 
+#include "syscfg/syscfg.h"
+
 struct fs_ops;
 extern const struct fs_ops *fs_root_ops;
 
-#ifdef SHELL_PRESENT
+#if MYNEWT_VAL(FS_CLI)
 void fs_cli_init(void);
-#endif /* SHELL_PRESENT */
+#endif
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/fs/nffs/include/nffs/nffs.h
--
diff --git a/fs/nffs/include/nffs/nffs.h b/fs/nffs/include/nffs/nffs.h
index 73a0ec1..4a608cb 100644
--- a/fs/nffs/include/nffs/nffs.h
+++ b/fs/nffs/include/nffs/nffs.h
@@ -22,6 +22,7 @@
 
 #include 
 #include 
+#include "fs/fs.h"
 
 #define NFFS_FILENAME_MAX_LEN   256  /* Does not require null terminator. */
 #define NFFS_MAX_AREAS  256
@@ -58,4 +59,6 @@ int nffs_init(void);
 int nffs_detect(const struct nffs_area_desc *area_descs);
 int nffs_format(const struct nffs_area_desc *area_descs);
 
+int nffs_misc_desc_from_flash_area(int idx, int *cnt, struct nffs_area_desc 
*nad);
+
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/fs/nffs/pkg.yml
--
diff --git a/fs/nffs/pkg.yml b/fs/nffs/pkg.yml
index 61e07e0..1a3f11d 100644
--- a/fs/nffs/pkg.yml
+++ b/fs/nffs/pkg.yml
@@ -26,10 +26,18 @@ pkg.keywords:
 - filesystem
 - ffs
 
-pkg.features: NFFS
 pkg.deps:
 - fs/fs
 - hw/hal
 - libs/os
 - libs/testutil
 - sys/log
+- sys/stats
+
+pkg.init_function: nffs_pkg_init
+pkg.init_stage: 2
+
+pkg.syscfg_defs:
+NFFS_DETECT_FAIL:
+description: 'TBD'
+value: 'NFFS_DETECT_FAIL_FORMAT'

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/fs/nffs/src/nffs.c
--
diff --git a/fs/nffs/src/nffs.c b/fs/nffs/src/nffs.c
index 28fdeea..5ee63aa 100644
--- a/fs/nffs/src/nffs.c
+++ b/fs/nffs/src/nffs.c
@@ -21,7 +21,11 @@
 #include 
 #include 
 #include 
+
+#include "sysinit/sysinit.h"
+#include "bsp/bsp.h"
 #include "hal/hal_flash.h"
+#include "hal/flash_map.h"
 #include "os/os_mempool.h"
 #include "os/os_mutex.h"
 #include "os/os_malloc.h"
@@ -686,7 +690,6 @@ nffs_init(void)
 return FS_ENOMEM;
 }
 
-log_init();
 log_console_handler_init(_log_console_handler);
 log_register("nffs", _log, _log_console_handler);
 
@@ -698,3 +701,52 @@ nffs_init(void)
 fs_register(_ops);
 return 0;
 }
+
+void
+nffs_pkg_init(void)
+{
+struct nffs_area_desc descs[NFFS_AREA_MAX + 1];
+int cnt;
+int rc;
+
+/* Initialize nffs's internal state. */
+rc = nffs_init();
+SYSINIT_PANIC_ASSERT(rc == 0);
+
+/* Convert the set of flash blocks we intend to use for nffs into an array
+ * of nffs area descriptors.
+ */
+cnt = NFFS_AREA_MAX;
+rc = nffs_misc_desc_from_flash_area(FLASH_AREA_NFFS, , descs);
+SYSINIT_PANIC_ASSERT(rc == 0);
+
+/* Attempt to restore an existing nffs file system from flash. */
+rc = nffs_detect(descs);
+switch (rc) {
+case 0:
+break;
+
+case FS_ECORRUPT:
+/* No valid nffs instance detected; act based on configued detection
+ * failure policy.
+ */
+switch 

[34/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/fs/nffs/test/src/arch/sim/nffs_test_priv.h
--
diff --git a/fs/nffs/test/src/arch/sim/nffs_test_priv.h 
b/fs/nffs/test/src/arch/sim/nffs_test_priv.h
new file mode 100644
index 000..a3508c1
--- /dev/null
+++ b/fs/nffs/test/src/arch/sim/nffs_test_priv.h
@@ -0,0 +1,42 @@
+/**
+ * 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_NFFS_TEST_PRIV_
+#define H_NFFS_TEST_PRIV_
+
+struct nffs_test_block_desc {
+const char *data;
+int data_len;
+};
+
+struct nffs_test_file_desc {
+const char *filename;
+int is_dir;
+const char *contents;
+int contents_len;
+struct nffs_test_file_desc *children;
+};
+
+int nffs_test(void);
+
+extern const struct nffs_test_file_desc *nffs_test_system_01;
+extern const struct nffs_test_file_desc *nffs_test_system_01_rm_1014_mk10;
+
+#endif
+



[15/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/test/ble_sm_test_util.c
--
diff --git a/net/nimble/host/src/test/ble_sm_test_util.c 
b/net/nimble/host/src/test/ble_sm_test_util.c
deleted file mode 100644
index 5cb1d40..000
--- a/net/nimble/host/src/test/ble_sm_test_util.c
+++ /dev/null
@@ -1,2404 +0,0 @@
-/**
- * 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 
-#include 
-#include 
-#include "testutil/testutil.h"
-#include "nimble/hci_common.h"
-#include "nimble/nimble_opt.h"
-#include "host/ble_sm.h"
-#include "host/ble_hs_test.h"
-#include "host/ble_hs_id.h"
-#include "ble_hs_test_util.h"
-#include "ble_sm_test_util.h"
-
-int ble_sm_test_gap_event_type;
-int ble_sm_test_gap_status;
-struct ble_gap_sec_state ble_sm_test_sec_state;
-
-int ble_sm_test_store_obj_type;
-union ble_store_key ble_sm_test_store_key;
-union ble_store_value ble_sm_test_store_value;
-
-static ble_store_read_fn ble_sm_test_util_store_read;
-static ble_store_write_fn ble_sm_test_util_store_write;
-
-struct ble_sm_test_util_entity {
-uint8_t addr_type;
-uint8_t id_addr_type;
-uint8_t *id_addr;
-uint8_t *rpa;
-
-struct ble_sm_pair_cmd *pair_cmd;
-struct ble_sm_pair_confirm *confirms;
-struct ble_sm_pair_random *randoms;
-struct ble_sm_id_info *id_info;
-struct ble_sm_id_addr_info *id_addr_info;
-struct ble_sm_sign_info *sign_info;
-uint8_t *ltk;
-
-uint8_t key_dist;
-
-/*** Secure connections fields. */
-struct ble_sm_public_key *public_key;
-struct ble_sm_dhkey_check *dhkey_check;
-
-/*** Legacy fields. */
-struct ble_sm_enc_info *enc_info;
-struct ble_sm_master_id *master_id;
-uint64_t rand_num;
-uint16_t ediv;
-};
-
-#define BLE_SM_TEST_UTIL_HCI_HDR(handle, pb, len) \
-((struct hci_data_hdr) {\
-.hdh_handle_pb_bc = ((handle)  << 0) |  \
-((pb)  << 12),  \
-.hdh_len = (len)\
-})
-
-static int
-ble_sm_test_util_store_read(int obj_type, union ble_store_key *key,
-  union ble_store_value *val)
-{
-ble_sm_test_store_obj_type = obj_type;
-ble_sm_test_store_key = *key;
-
-return ble_hs_test_util_store_read(obj_type, key, val);
-}
-
-static int
-ble_sm_test_util_store_write(int obj_type, union ble_store_value *val)
-{
-ble_sm_test_store_obj_type = obj_type;
-ble_sm_test_store_value = *val;
-
-return ble_hs_test_util_store_write(obj_type, val);
-}
-
-void
-ble_sm_test_util_init(void)
-{
-ble_hs_test_util_init();
-ble_hs_test_util_store_init(10, 10, 10);
-ble_hs_cfg.store_read_cb = ble_sm_test_util_store_read;
-ble_hs_cfg.store_write_cb = ble_sm_test_util_store_write;
-
-ble_sm_test_store_obj_type = -1;
-ble_sm_test_gap_event_type = -1;
-ble_sm_test_gap_status = -1;
-
-memset(_sm_test_sec_state, 0xff, sizeof ble_sm_test_sec_state);
-}
-
-static void
-ble_sm_test_util_params_to_entity(struct ble_sm_test_params *params,
-  int initiator,
-  struct ble_sm_test_util_entity *out_entity)
-{
-int sc;
-
-memset(out_entity, 0, sizeof *out_entity);
-
-sc = params->pair_req.authreq & BLE_SM_PAIR_AUTHREQ_SC &&
- params->pair_rsp.authreq & BLE_SM_PAIR_AUTHREQ_SC;
-
-if (initiator) {
-out_entity->key_dist = params->pair_rsp.init_key_dist;
-
-out_entity->addr_type = params->init_addr_type;
-out_entity->id_addr = params->init_id_addr;
-out_entity->rpa = params->init_rpa;
-
-out_entity->pair_cmd = >pair_req;
-out_entity->confirms = params->confirm_req;
-out_entity->randoms = params->random_req;
-out_entity->id_info = >id_info_rsp;
-out_entity->id_addr_info = >id_addr_info_rsp;
-out_entity->sign_info = >sign_info_rsp;
-
-if (sc) {
-out_entity->ltk = params->ltk;
-out_entity->public_key = >public_key_req;
-out_entity->dhkey_check = >dhkey_check_req;
-} else {
-

[07/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/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
new file mode 100644
index 000..2b2da51
--- /dev/null
+++ b/net/nimble/host/test/src/ble_os_test.c
@@ -0,0 +1,401 @@
+/**
+ * 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 
+#include "os/os.h"
+#include "testutil/testutil.h"
+#include "nimble/hci_common.h"
+#include "nimble/ble_hci_trans.h"
+#include "host/ble_hs_test.h"
+#include "host/ble_gap.h"
+#include "ble_hs_test_util.h"
+
+#define BLE_OS_TEST_STACK_SIZE  256
+#define BLE_OS_TEST_APP_STACK_SIZE  256
+
+#define BLE_OS_TEST_APP_PRIO 9
+#define BLE_OS_TEST_TASK_PRIO10
+
+static struct os_task ble_os_test_task;
+static struct os_task ble_os_test_app_task;
+static os_stack_t ble_os_test_stack[OS_STACK_ALIGN(BLE_OS_TEST_STACK_SIZE)];
+
+static os_stack_t
+ble_os_test_app_stack[OS_STACK_ALIGN(BLE_OS_TEST_APP_STACK_SIZE)];
+
+static uint8_t ble_os_test_peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
+
+static void ble_os_test_app_task_handler(void *arg);
+
+static int ble_os_test_gap_event_type;
+
+static void
+ble_os_test_init_app_task(void)
+{
+int rc;
+
+rc = os_task_init(_os_test_app_task,
+  "ble_gap_terminate_test_task",
+  ble_os_test_app_task_handler, NULL,
+  BLE_OS_TEST_APP_PRIO, OS_WAIT_FOREVER,
+  ble_os_test_app_stack,
+  OS_STACK_ALIGN(BLE_OS_TEST_APP_STACK_SIZE));
+TEST_ASSERT_FATAL(rc == 0);
+}
+
+static void
+ble_os_test_misc_init(void)
+{
+ble_hs_test_util_init_no_start();
+
+/* Receive acknowledgements for the startup sequence.  We sent the
+ * corresponding requests when the host task was started.
+ */
+ble_hs_test_util_set_startup_acks();
+
+ble_os_test_init_app_task();
+}
+
+static int
+ble_os_test_misc_conn_exists(uint16_t conn_handle)
+{
+struct ble_hs_conn *conn;
+
+ble_hs_lock();
+
+if (conn_handle == BLE_HS_CONN_HANDLE_NONE) {
+conn = ble_hs_conn_first();
+} else {
+conn = ble_hs_conn_find(conn_handle);
+}
+
+ble_hs_unlock();
+
+return conn != NULL;
+}
+
+static int
+ble_gap_direct_connect_test_connect_cb(struct ble_gap_event *event, void *arg)
+{
+struct ble_gap_conn_desc desc;
+int *cb_called;
+int rc;
+
+cb_called = arg;
+*cb_called = 1;
+
+TEST_ASSERT(event->type == BLE_GAP_EVENT_CONNECT);
+TEST_ASSERT(event->connect.status == 0);
+TEST_ASSERT(event->connect.conn_handle == 2);
+
+rc = ble_gap_conn_find(event->connect.conn_handle, );
+TEST_ASSERT_FATAL(rc == 0);
+TEST_ASSERT(desc.peer_id_addr_type == BLE_ADDR_TYPE_PUBLIC);
+TEST_ASSERT(memcmp(desc.peer_id_addr, ble_os_test_peer_addr, 6) == 0);
+
+return 0;
+}
+
+static void
+ble_gap_direct_connect_test_task_handler(void *arg)
+{
+struct hci_le_conn_complete evt;
+uint8_t addr[6] = { 1, 2, 3, 4, 5, 6 };
+int cb_called;
+int rc;
+
+/* Set the connect callback so we can verify that it gets called with the
+ * proper arguments.
+ */
+cb_called = 0;
+
+/* Make sure there are no created connections and no connections in
+ * progress.
+ */
+TEST_ASSERT(!ble_os_test_misc_conn_exists(BLE_HS_CONN_HANDLE_NONE));
+
+/* Initiate a direct connection. */
+ble_hs_test_util_connect(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
+ addr, 0, NULL,
+ ble_gap_direct_connect_test_connect_cb,
+ _called, 0);
+TEST_ASSERT(!ble_os_test_misc_conn_exists(BLE_HS_CONN_HANDLE_NONE));
+TEST_ASSERT(!cb_called);
+
+/* Receive an HCI connection-complete event. */
+memset(, 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_rx_conn_complete();
+TEST_ASSERT(rc == 0);
+
+/* The connection should now be created. */
+

[13/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/test/src/ble_att_svr_test.c
--
diff --git a/net/nimble/host/test/src/ble_att_svr_test.c 
b/net/nimble/host/test/src/ble_att_svr_test.c
new file mode 100644
index 000..1509b41
--- /dev/null
+++ b/net/nimble/host/test/src/ble_att_svr_test.c
@@ -0,0 +1,2314 @@
+/**
+ * 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 
+#include 
+#include 
+#include "testutil/testutil.h"
+#include "nimble/hci_common.h"
+#include "host/ble_hs_test.h"
+#include "host/ble_uuid.h"
+#include "ble_hs_test_util.h"
+
+static uint8_t *ble_att_svr_test_attr_r_1;
+static uint16_t ble_att_svr_test_attr_r_1_len;
+static uint8_t *ble_att_svr_test_attr_r_2;
+static uint16_t ble_att_svr_test_attr_r_2_len;
+
+static uint8_t ble_att_svr_test_attr_w_1[1024];
+static uint16_t ble_att_svr_test_attr_w_1_len;
+static uint8_t ble_att_svr_test_attr_w_2[1024];
+static uint16_t ble_att_svr_test_attr_w_2_len;
+
+static uint16_t ble_att_svr_test_n_conn_handle;
+static uint16_t ble_att_svr_test_n_attr_handle;
+static uint8_t ble_att_svr_test_attr_n[1024];
+static uint16_t ble_att_svr_test_attr_n_len;
+
+static int
+ble_att_svr_test_misc_gap_cb(struct ble_gap_event *event, void *arg)
+{
+switch (event->type) {
+case BLE_GAP_EVENT_NOTIFY_RX:
+ble_att_svr_test_n_conn_handle = event->notify_rx.conn_handle;
+ble_att_svr_test_n_attr_handle = event->notify_rx.attr_handle;
+TEST_ASSERT_FATAL(OS_MBUF_PKTLEN(event->notify_rx.om) <=
+  sizeof ble_att_svr_test_attr_n);
+ble_att_svr_test_attr_n_len = OS_MBUF_PKTLEN(event->notify_rx.om);
+os_mbuf_copydata(event->notify_rx.om, 0, ble_att_svr_test_attr_n_len,
+ ble_att_svr_test_attr_n);
+break;
+
+default:
+break;
+}
+
+return 0;
+}
+
+/**
+ * @return  The handle of the new test connection.
+ */
+static uint16_t
+ble_att_svr_test_misc_init(uint16_t mtu)
+{
+struct ble_l2cap_chan *chan;
+struct ble_hs_conn *conn;
+int rc;
+
+ble_hs_test_util_init();
+
+ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ ble_att_svr_test_misc_gap_cb, NULL);
+
+ble_hs_lock();
+
+rc = ble_hs_misc_conn_chan_find(2, BLE_L2CAP_CID_ATT, , );
+TEST_ASSERT_FATAL(rc == 0);
+
+if (mtu != 0) {
+chan->blc_my_mtu = mtu;
+chan->blc_peer_mtu = mtu;
+chan->blc_flags |= BLE_L2CAP_CHAN_F_TXED_MTU;
+}
+
+ble_hs_unlock();
+
+ble_att_svr_test_attr_r_1_len = 0;
+ble_att_svr_test_attr_r_2_len = 0;
+ble_att_svr_test_attr_w_1_len = 0;
+
+return 2;
+}
+
+static int
+ble_att_svr_test_misc_attr_fn_r_1(uint16_t conn_handle, uint16_t attr_handle,
+  uint8_t op, uint16_t offset,
+  struct os_mbuf **om, void *arg)
+{
+switch (op) {
+case BLE_ATT_ACCESS_OP_READ:
+if (offset > ble_att_svr_test_attr_r_1_len) {
+return BLE_ATT_ERR_INVALID_OFFSET;
+}
+
+os_mbuf_append(*om, ble_att_svr_test_attr_r_1 + offset,
+   ble_att_svr_test_attr_r_1_len - offset);
+return 0;
+
+default:
+return -1;
+}
+}
+
+static int
+ble_att_svr_test_misc_attr_fn_r_2(uint16_t conn_handle, uint16_t attr_handle,
+  uint8_t op, uint16_t offset,
+  struct os_mbuf **om, void *arg)
+{
+
+switch (op) {
+case BLE_ATT_ACCESS_OP_READ:
+if (offset > ble_att_svr_test_attr_r_2_len) {
+return BLE_ATT_ERR_INVALID_OFFSET;
+}
+
+os_mbuf_append(*om, ble_att_svr_test_attr_r_2 + offset,
+   ble_att_svr_test_attr_r_2_len - offset);
+return 0;
+
+default:
+return -1;
+}
+}
+
+#define BLE_ATT_SVR_TEST_LAST_SVC  11
+#define BLE_ATT_SVR_TEST_LAST_ATTR 24
+
+static int
+ble_att_svr_test_misc_attr_fn_r_group(uint16_t conn_handle,
+  uint16_t attr_handle,
+  uint8_t 

[20/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/test/ble_gatts_reg_test.c
--
diff --git a/net/nimble/host/src/test/ble_gatts_reg_test.c 
b/net/nimble/host/src/test/ble_gatts_reg_test.c
deleted file mode 100644
index ad5f18f..000
--- a/net/nimble/host/src/test/ble_gatts_reg_test.c
+++ /dev/null
@@ -1,718 +0,0 @@
-/**
- * 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 
-#include 
-#include "testutil/testutil.h"
-#include "nimble/ble.h"
-#include "host/ble_uuid.h"
-#include "host/ble_hs_test.h"
-#include "ble_hs_test_util.h"
-
-#define BLE_GATTS_REG_TEST_MAX_ENTRIES  256
-
-struct ble_gatts_reg_test_entry {
-uint8_t op;
-uint8_t uuid128[16];
-uint16_t handle;
-uint16_t val_handle; /* If a characteristic. */
-
-const struct ble_gatt_svc_def *svc;
-const struct ble_gatt_chr_def *chr;
-const struct ble_gatt_dsc_def *dsc;
-};
-
-static struct ble_gatts_reg_test_entry
-ble_gatts_reg_test_entries[BLE_GATTS_REG_TEST_MAX_ENTRIES];
-
-static int ble_gatts_reg_test_num_entries;
-
-static void
-ble_gatts_reg_test_init(void)
-{
-ble_hs_test_util_init();
-ble_gatts_reg_test_num_entries = 0;
-}
-
-static void
-ble_gatts_reg_test_misc_reg_cb(struct ble_gatt_register_ctxt *ctxt, void *arg)
-{
-struct ble_gatts_reg_test_entry *entry;
-
-TEST_ASSERT_FATAL(ble_gatts_reg_test_num_entries <
-  BLE_GATTS_REG_TEST_MAX_ENTRIES);
-
-entry = ble_gatts_reg_test_entries + ble_gatts_reg_test_num_entries++;
-memset(entry, 0, sizeof *entry);
-
-entry->op = ctxt->op;
-switch (ctxt->op) {
-case BLE_GATT_REGISTER_OP_SVC:
-memcpy(entry->uuid128, ctxt->svc.svc_def->uuid128, 16);
-entry->handle = ctxt->svc.handle;
-entry->svc = ctxt->svc.svc_def;
-break;
-
-case BLE_GATT_REGISTER_OP_CHR:
-memcpy(entry->uuid128, ctxt->chr.chr_def->uuid128, 16);
-entry->handle = ctxt->chr.def_handle;
-entry->val_handle = ctxt->chr.val_handle;
-entry->svc = ctxt->chr.svc_def;
-entry->chr = ctxt->chr.chr_def;
-break;
-
-case BLE_GATT_REGISTER_OP_DSC:
-memcpy(entry->uuid128, ctxt->dsc.dsc_def->uuid128, 16);
-entry->handle = ctxt->dsc.handle;
-entry->svc = ctxt->dsc.svc_def;
-entry->chr = ctxt->dsc.chr_def;
-entry->dsc = ctxt->dsc.dsc_def;
-break;
-
-default:
-TEST_ASSERT(0);
-break;
-}
-}
-
-static void
-ble_gatts_reg_test_misc_lookup_good(struct ble_gatts_reg_test_entry *entry)
-{
-uint16_t chr_def_handle;
-uint16_t chr_val_handle;
-uint16_t svc_handle;
-uint16_t dsc_handle;
-int rc;
-
-switch (entry->op) {
-case BLE_GATT_REGISTER_OP_SVC:
-rc = ble_gatts_find_svc(entry->uuid128, _handle);
-TEST_ASSERT_FATAL(rc == 0);
-TEST_ASSERT(svc_handle == entry->handle);
-break;
-
-case BLE_GATT_REGISTER_OP_CHR:
-rc = ble_gatts_find_chr(entry->svc->uuid128, entry->chr->uuid128,
-_def_handle, _val_handle);
-TEST_ASSERT_FATAL(rc == 0);
-TEST_ASSERT(chr_def_handle == entry->handle);
-TEST_ASSERT(chr_val_handle == entry->val_handle);
-break;
-
-case BLE_GATT_REGISTER_OP_DSC:
-rc = ble_gatts_find_dsc(entry->svc->uuid128, entry->chr->uuid128,
-entry->dsc->uuid128, _handle);
-break;
-
-default:
-TEST_ASSERT(0);
-break;
-}
-}
-
-static void
-ble_gatts_reg_test_misc_lookup_bad(struct ble_gatts_reg_test_entry *entry)
-{
-struct ble_gatts_reg_test_entry *cur;
-uint8_t wrong_uuid[16];
-int rc;
-int i;
-
-switch (entry->op) {
-case BLE_GATT_REGISTER_OP_SVC:
-/* Wrong service UUID. */
-memcpy(wrong_uuid, entry->svc->uuid128, 16);
-wrong_uuid[15]++;
-rc = ble_gatts_find_svc(wrong_uuid, NULL);
-TEST_ASSERT(rc == BLE_HS_ENOENT);
-break;
-
-case BLE_GATT_REGISTER_OP_CHR:
-/* Correct service UUID, wrong characteristic UUID. */
-memcpy(wrong_uuid, entry->chr->uuid128, 16);
- 

[16/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/test/ble_sm_test.c
--
diff --git a/net/nimble/host/src/test/ble_sm_test.c 
b/net/nimble/host/src/test/ble_sm_test.c
deleted file mode 100644
index f139ddb..000
--- a/net/nimble/host/src/test/ble_sm_test.c
+++ /dev/null
@@ -1,678 +0,0 @@
-/**
- * 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 
-#include 
-#include 
-#include "testutil/testutil.h"
-#include "nimble/hci_common.h"
-#include "nimble/nimble_opt.h"
-#include "host/ble_sm.h"
-#include "host/ble_hs_test.h"
-#include "ble_hs_test_util.h"
-#include "ble_sm_test_util.h"
-
-#if NIMBLE_OPT(SM)
-
-/*
- * $misc *
- */
-
-TEST_CASE(ble_sm_test_case_f4)
-{
-   uint8_t u[32] = { 0xe6, 0x9d, 0x35, 0x0e, 0x48, 0x01, 0x03, 0xcc,
- 0xdb, 0xfd, 0xf4, 0xac, 0x11, 0x91, 0xf4, 0xef,
- 0xb9, 0xa5, 0xf9, 0xe9, 0xa7, 0x83, 0x2c, 0x5e,
- 0x2c, 0xbe, 0x97, 0xf2, 0xd2, 0x03, 0xb0, 0x20 };
-   uint8_t v[32] = { 0xfd, 0xc5, 0x7f, 0xf4, 0x49, 0xdd, 0x4f, 0x6b,
- 0xfb, 0x7c, 0x9d, 0xf1, 0xc2, 0x9a, 0xcb, 0x59,
- 0x2a, 0xe7, 0xd4, 0xee, 0xfb, 0xfc, 0x0a, 0x90,
- 0x9a, 0xbb, 0xf6, 0x32, 0x3d, 0x8b, 0x18, 0x55 };
-   uint8_t x[16] = { 0xab, 0xae, 0x2b, 0x71, 0xec, 0xb2, 0xff, 0xff,
- 0x3e, 0x73, 0x77, 0xd1, 0x54, 0x84, 0xcb, 0xd5 };
-   uint8_t z = 0x00;
-   uint8_t exp[16] = { 0x2d, 0x87, 0x74, 0xa9, 0xbe, 0xa1, 0xed, 0xf1,
-   0x1c, 0xbd, 0xa9, 0x07, 0xf1, 0x16, 0xc9, 0xf2 };
-   uint8_t res[16];
-   int err;
-
-   err = ble_sm_alg_f4(u, v, x, z, res);
-   TEST_ASSERT_FATAL(err == 0);
-TEST_ASSERT(memcmp(res, exp, 16) == 0);
-}
-
-TEST_CASE(ble_sm_test_case_f5)
-{
-   uint8_t w[32] = { 0x98, 0xa6, 0xbf, 0x73, 0xf3, 0x34, 0x8d, 0x86,
- 0xf1, 0x66, 0xf8, 0xb4, 0x13, 0x6b, 0x79, 0x99,
- 0x9b, 0x7d, 0x39, 0x0a, 0xa6, 0x10, 0x10, 0x34,
- 0x05, 0xad, 0xc8, 0x57, 0xa3, 0x34, 0x02, 0xec };
-   uint8_t n1[16] = { 0xab, 0xae, 0x2b, 0x71, 0xec, 0xb2, 0xff, 0xff,
-  0x3e, 0x73, 0x77, 0xd1, 0x54, 0x84, 0xcb, 0xd5 };
-   uint8_t n2[16] = { 0xcf, 0xc4, 0x3d, 0xff, 0xf7, 0x83, 0x65, 0x21,
-  0x6e, 0x5f, 0xa7, 0x25, 0xcc, 0xe7, 0xe8, 0xa6 };
-uint8_t a1t = 0x00;
-   uint8_t a1[6] = { 0xce, 0xbf, 0x37, 0x37, 0x12, 0x56 };
-uint8_t a2t = 0x00;
-uint8_t a2[6] = { 0xc1, 0xcf, 0x2d, 0x70, 0x13, 0xa7 };
-   uint8_t exp_ltk[16] = { 0x38, 0x0a, 0x75, 0x94, 0xb5, 0x22, 0x05,
-   0x98, 0x23, 0xcd, 0xd7, 0x69, 0x11, 0x79,
-   0x86, 0x69 };
-   uint8_t exp_mackey[16] = { 0x20, 0x6e, 0x63, 0xce, 0x20, 0x6a, 0x3f,
-  0xfd, 0x02, 0x4a, 0x08, 0xa1, 0x76, 0xf1,
-  0x65, 0x29 };
-   uint8_t mackey[16], ltk[16];
-   int err;
-
-   err = ble_sm_alg_f5(w, n1, n2, a1t, a1, a2t, a2, mackey, ltk);
-   TEST_ASSERT_FATAL(err == 0);
-TEST_ASSERT(memcmp(mackey, exp_mackey, 16) == 0);
-TEST_ASSERT(memcmp(ltk, exp_ltk, 16) == 0);
-}
-
-TEST_CASE(ble_sm_test_case_f6)
-{
-   uint8_t w[16] = { 0x20, 0x6e, 0x63, 0xce, 0x20, 0x6a, 0x3f, 0xfd,
- 0x02, 0x4a, 0x08, 0xa1, 0x76, 0xf1, 0x65, 0x29 };
-   uint8_t n1[16] = { 0xab, 0xae, 0x2b, 0x71, 0xec, 0xb2, 0xff, 0xff,
-  0x3e, 0x73, 0x77, 0xd1, 0x54, 0x84, 0xcb, 0xd5 };
-   uint8_t n2[16] = { 0xcf, 0xc4, 0x3d, 0xff, 0xf7, 0x83, 0x65, 0x21,
-  0x6e, 0x5f, 0xa7, 0x25, 0xcc, 0xe7, 0xe8, 0xa6 };
-   uint8_t r[16] = { 0xc8, 0x0f, 0x2d, 0x0c, 0xd2, 0x42, 0xda, 0x08,
- 0x54, 0xbb, 0x53, 0xb4, 0x3b, 0x34, 0xa3, 

[01/41] incubator-mynewt-core git commit: syscfg / sysinit

2016-09-12 Thread ccollins
Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/sterly_refactor fdd134d75 -> d98ddc1c5


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/sys/reboot/src/log_reboot.c
--
diff --git a/sys/reboot/src/log_reboot.c b/sys/reboot/src/log_reboot.c
index 470d300..c7c3bbe 100644
--- a/sys/reboot/src/log_reboot.c
+++ b/sys/reboot/src/log_reboot.c
@@ -17,23 +17,21 @@
  * under the License.
  */
 
-#include 
-#include 
-#include 
-#include "log/log.h"
-#include 
-#include 
-#include 
 #include 
-#include 
-#include 
-#include 
-#include 
 #include 
-
-#ifdef SHELL_PRESENT
-#include 
-#endif
+#include "sysinit/sysinit.h"
+#include "syscfg/syscfg.h"
+#include "os/os.h"
+#include "fcb/fcb.h"
+#include "console/console.h"
+#include "log/log.h"
+#include "bootutil/image.h"
+#include "bootutil/bootutil_misc.h"
+#include "imgmgr/imgmgr.h"
+#include "config/config.h"
+#include "config/config_file.h"
+#include "reboot/log_reboot.h"
+#include "bsp/bsp.h"
 
 static struct log_handler reboot_log_handler;
 static struct fcb fcb;
@@ -202,3 +200,17 @@ reboot_cnt_set(int argc, char **argv, char *val)
 err:
 return OS_ENOENT;
 }
+
+void
+log_reboot_pkg_init(void)
+{
+int rc;
+
+(void)rc;
+
+#if MYNEWT_VAL(REBOOT_LOG_0_TYPE)
+rc = reboot_init_handler(MYNEWT_VAL(REBOOT_LOG_0_TYPE),
+ MYNEWT_VAL(REBOOT_LOG_0_ENTRY_COUNT));
+SYSINIT_PANIC_ASSERT(rc == 0);
+#endif
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/sys/stats/include/stats/stats.h
--
diff --git a/sys/stats/include/stats/stats.h b/sys/stats/include/stats/stats.h
index 078b99a..7e5811e 100644
--- a/sys/stats/include/stats/stats.h
+++ b/sys/stats/include/stats/stats.h
@@ -19,8 +19,9 @@
 #ifndef __UTIL_STATS_H__ 
 #define __UTIL_STATS_H__ 
 
-#include 
 #include 
+#include "syscfg/syscfg.h"
+#include "os/queue.h"
 
 struct stats_name_map {
 uint16_t snm_off;
@@ -32,7 +33,7 @@ struct stats_hdr {
 uint8_t s_size;
 uint8_t s_cnt;
 uint16_t s_pad1;
-#ifdef STATS_NAME_ENABLE
+#if MYNEWT_VAL(STATS_NAMES)
 struct stats_name_map *s_map;
 int s_map_cnt;
 #endif
@@ -72,7 +73,7 @@ STATS_SECT_DECL(__name) {   \
 #define STATS_INCN(__sectvarname, __var, __n)  \
 ((__sectvarname).STATS_SECT_VAR(__var) += (__n))
 
-#ifdef STATS_NAME_ENABLE
+#if MYNEWT_VAL(STATS_NAMES)
 
 #define STATS_NAME_MAP_NAME(__sectname) g_stats_map_ ## __sectname
 
@@ -90,17 +91,16 @@ struct stats_name_map STATS_NAME_MAP_NAME(__sectname)[] = {
 &(STATS_NAME_MAP_NAME(__name)[0]),  \
 (sizeof(STATS_NAME_MAP_NAME(__name)) / sizeof(struct stats_name_map))
 
-#else /* STATS_NAME_ENABLE */
+#else /* MYNEWT_VAL(STATS_NAME) */
 
 #define STATS_NAME_START(__name)
 #define STATS_NAME(__name, __entry)
 #define STATS_NAME_END(__name)
 #define STATS_NAME_INIT_PARMS(__name) NULL, 0
 
-#endif /* STATS_NAME_ENABLE */
+#endif /* MYNEWT_VAL(STATS_NAME) */
 
-int stats_module_init(void);
-void stats_module_reset(void);
+void stats_module_init(void);
 int stats_init(struct stats_hdr *shdr, uint8_t size, uint8_t cnt, 
 struct stats_name_map *map, uint8_t map_cnt);
 int stats_register(char *name, struct stats_hdr *shdr);
@@ -118,10 +118,10 @@ int stats_group_walk(stats_group_walk_func_t, void *);
 struct stats_hdr *stats_group_find(char *name);
 
 /* Private */
-#ifdef NEWTMGR_PRESENT 
+#if MYNEWT_VAL(STATS_NEWTMGR)
 int stats_nmgr_register_group(void);
 #endif 
-#ifdef SHELL_PRESENT
+#if MYNEWT_VAL(STATS_CLI)
 int stats_shell_register(void);
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/sys/stats/pkg.yml
--
diff --git a/sys/stats/pkg.yml b/sys/stats/pkg.yml
index 309dbd6..c23bedc 100644
--- a/sys/stats/pkg.yml
+++ b/sys/stats/pkg.yml
@@ -27,12 +27,21 @@ pkg.keywords:
 pkg.deps:
 - libs/os
 - libs/util
-- libs/testutil
-pkg.deps.SHELL:
+pkg.deps.STATS_CLI:
 - libs/shell
-pkg.deps.NEWTMGR:
+pkg.deps.STATS_NEWTMGR:
 - libs/newtmgr
-pkg.req_apis.SHELL:
-- console
-pkg.cflags.SHELL: -DSHELL_PRESENT
-pkg.cflags.NEWTMGR: -DNEWTMGR_PRESENT 
+
+pkg.init_function: stats_module_init
+pkg.init_stage: 0
+
+pkg.syscfg_defs:
+STATS_NAMES:
+description: 'TBD'
+value: 1
+STATS_CLI:
+description: 'TBD'
+value: 'MYNEWT_PKG_LIBS_SHELL'
+STATS_NEWTMGR:
+description: 'TBD'
+value: 'MYNEWT_PKG_LIBS_NEWTMGR'

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/sys/stats/src/stats.c
--
diff --git a/sys/stats/src/stats.c b/sys/stats/src/stats.c
index a1f785c..d9dea44 100644
--- a/sys/stats/src/stats.c
+++ b/sys/stats/src/stats.c
@@ -17,14 +17,15 @@

incubator-mynewt-core git commit: mn_socket; add mn_inet_ntop().

2016-09-12 Thread marko
Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop d56270d97 -> 77ddfe7fc


mn_socket; add mn_inet_ntop().


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

Branch: refs/heads/develop
Commit: 77ddfe7fc1550ab6e7a25b9394d16528504742a6
Parents: d56270d
Author: Marko Kiiskila 
Authored: Mon Sep 12 14:13:46 2016 -0700
Committer: Marko Kiiskila 
Committed: Mon Sep 12 14:13:46 2016 -0700

--
 sys/mn_socket/include/mn_socket/mn_socket.h | 11 +
 sys/mn_socket/src/mn_socket_aconv.c | 20 +++
 sys/mn_socket/src/test/mn_sock_test.c   | 31 
 3 files changed, 62 insertions(+)
--


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/77ddfe7f/sys/mn_socket/include/mn_socket/mn_socket.h
--
diff --git a/sys/mn_socket/include/mn_socket/mn_socket.h 
b/sys/mn_socket/include/mn_socket/mn_socket.h
index 6b457be..a852dcb 100644
--- a/sys/mn_socket/include/mn_socket/mn_socket.h
+++ b/sys/mn_socket/include/mn_socket/mn_socket.h
@@ -50,6 +50,16 @@
 #define MN_EAGAIN   10
 #define MN_EUNKNOWN 11
 
+/*
+ * Multicast macros
+ */
+#define MN_IN_MULTICAST(a)  \
+(((a) & 0xf000) == 0xe000)
+
+/*  notyet */
+#define MN_IN6_IS_ADDR_MULTICAST(a) \
+0
+
 struct mn_socket;
 struct mn_socket_ops;
 struct mn_sock_cb;
@@ -142,5 +152,6 @@ int mn_close(struct mn_socket *);
  * Address conversion
  */
 int mn_inet_pton(int af, const char *src, void *dst);
+const char *mn_inet_ntop(int af, const void *src, void *dst, int len);
 
 #endif /* __SYS_MN_SOCKET_H_ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/77ddfe7f/sys/mn_socket/src/mn_socket_aconv.c
--
diff --git a/sys/mn_socket/src/mn_socket_aconv.c 
b/sys/mn_socket/src/mn_socket_aconv.c
index 5053eac..23c500b 100644
--- a/sys/mn_socket/src/mn_socket_aconv.c
+++ b/sys/mn_socket/src/mn_socket_aconv.c
@@ -17,6 +17,7 @@
  * under the License.
  */
 #include 
+#include 
 #include 
 #include "mn_socket/mn_socket.h"
 
@@ -55,3 +56,22 @@ mn_inet_pton(int af, const char *src, void *dst)
 return MN_EAFNOSUPPORT;
 }
 }
+
+const char *
+mn_inet_ntop(int af, const void *src_v, void *dst, int len)
+{
+const unsigned char *src = src_v;
+int rc;
+
+if (af == MN_PF_INET) {
+rc = snprintf(dst, len, "%u.%u.%u.%u",
+  src[0], src[1], src[2], src[3]);
+if (rc >= len) {
+return NULL;
+} else {
+return dst;
+}
+} else {
+return NULL;
+}
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/77ddfe7f/sys/mn_socket/src/test/mn_sock_test.c
--
diff --git a/sys/mn_socket/src/test/mn_sock_test.c 
b/sys/mn_socket/src/test/mn_sock_test.c
index a8d9cc2..d49fab0 100644
--- a/sys/mn_socket/src/test/mn_sock_test.c
+++ b/sys/mn_socket/src/test/mn_sock_test.c
@@ -61,9 +61,40 @@ TEST_CASE(inet_pton_test)
 }
 }
 
+TEST_CASE(inet_ntop_test)
+{
+const char *rstr;
+char addr[48];
+struct test_vec {
+char *str;
+uint8_t cmp[4];
+};
+struct test_vec ok_vec[] = {
+{ "1.1.1.1", { 1, 1, 1, 1 } },
+{ "1.2.3.4", { 1, 2, 3, 4 } },
+{ "255.1.255.255", { 255, 1, 255, 255 } },
+{ "1.2.5.6", { 1, 2, 5, 6 } }
+};
+int i;
+
+for (i = 0; i < sizeof(ok_vec) / sizeof(ok_vec[0]); i++) {
+memset(addr, 0xa5, sizeof(addr));
+rstr = mn_inet_ntop(MN_PF_INET, ok_vec[i].cmp, addr, sizeof(addr));
+TEST_ASSERT(rstr);
+TEST_ASSERT(!strcmp(ok_vec[i].str, addr));
+}
+rstr = mn_inet_ntop(MN_PF_INET, ok_vec[0].cmp, addr, 1);
+TEST_ASSERT(rstr == NULL);
+
+/* does not have space to null terminate */
+rstr = mn_inet_ntop(MN_PF_INET, ok_vec[0].cmp, addr, 7);
+TEST_ASSERT(rstr == NULL);
+}
+
 TEST_SUITE(mn_socket_test_all)
 {
 inet_pton_test();
+inet_ntop_test();
 }
 
 #ifdef MYNEWT_SELFTEST



incubator-mynewt-site git commit: autocompletion of newt commands

2016-09-12 Thread aditi
Repository: incubator-mynewt-site
Updated Branches:
  refs/heads/asf-site e5deb3933 -> 106051e2a


autocompletion of newt commands


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/commit/106051e2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/tree/106051e2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/diff/106051e2

Branch: refs/heads/asf-site
Commit: 106051e2a8c8376e58a3143e4bdd3988c64f42b6
Parents: e5deb39
Author: aditihilbert 
Authored: Mon Sep 12 12:57:32 2016 -0700
Committer: aditihilbert 
Committed: Mon Sep 12 12:57:32 2016 -0700

--
 develop/about/index.html  |  1 +
 develop/mkdocs/search_index.json  | 15 ++-
 develop/newt/newt_intro/index.html| 12 
 develop/os/modules/split/split/index.html |  2 +-
 develop/sitemap.xml   | 20 ++--
 latest/sitemap.xml| 20 ++--
 sitemap.xml   | 20 ++--
 v0_9_0/sitemap.xml| 20 ++--
 8 files changed, 64 insertions(+), 46 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/106051e2/develop/about/index.html
--
diff --git a/develop/about/index.html b/develop/about/index.html
index ffd5f13..dbb720c 100644
--- a/develop/about/index.html
+++ b/develop/about/index.html
@@ -191,6 +191,7 @@
 HAL redesign to abstract across a diverse set of chip peripherals (http://mail-archives.apache.org/mod_mbox/incubator-mynewt-dev/201606.mbox/%3C06CB0682-8F67-4C3F-93E4-6A2087A1%40apache.org%3E;>View
 discussion thread)
 HAL for SPI access (master and slave)
 Ability for drivers to turn on/off low power settings automatically
+Support for Wi-Fi controllers via a socket interface
 
  The detailed roadmap is tracked on https://issues.apache.org/jira/browse/MYNEWT/?selectedTab=com.atlassian.jira.jira-projects-plugin:roadmap-panel;>JIRA
 for Mynewt. 
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/106051e2/develop/mkdocs/search_index.json
--
diff --git a/develop/mkdocs/search_index.json b/develop/mkdocs/search_index.json
index 69e52de..b63a85a 100644
--- a/develop/mkdocs/search_index.json
+++ b/develop/mkdocs/search_index.json
@@ -27,12 +27,12 @@
 }, 
 {
 "location": "/about/", 
-"text": "Roadmap\n\n\nSome upcoming features:\n\n\n\n\nHost-only 
BLE stack\n\n\nSerial upgrade of image in bootloader\n\n\nHAL redesign to 
abstract across a diverse set of chip peripherals (\nView discussion 
thread\n)\n\n\nHAL for SPI access (master and slave)\n\n\nAbility for drivers 
to turn on/off low power settings automatically\n\n\n\n\n The detailed roadmap 
is tracked on \nJIRA for Mynewt\n. \n\n\n\n\nFeature Request\n\n\nThe WISHLIST 
at the top of the roadmap on \nJIRA for Mynewt\n features all the new ideas 
awaiting discussion and review. Once the community decides to go ahead with a 
request, it is scheduled into a release. Generally, effort is made to schedule 
a requested feature into a particular version no later than 6 weeks prior to 
the planned release date.\n\n\nIf you have suggestions for a new feature, use 
case, or implementation improvements, file a JIRA ticket with Issue Type set to 
\"Wish\". Introduce it in the \ndev@\n mailing list with a link to the JI
 RA ticket. This assumes you have signed up for an account on JIRA and 
submitted a request to the dev@ mailing list for your JIRA username to be added 
to the Apache Mynewt (MYNEWT) project.\n\n\n\n\nFAQ\n\n\n Questions? \n Click 
\nhere", 
+"text": "Roadmap\n\n\nSome upcoming features:\n\n\n\n\nHost-only 
BLE stack\n\n\nSerial upgrade of image in bootloader\n\n\nHAL redesign to 
abstract across a diverse set of chip peripherals (\nView discussion 
thread\n)\n\n\nHAL for SPI access (master and slave)\n\n\nAbility for drivers 
to turn on/off low power settings automatically\n\n\nSupport for Wi-Fi 
controllers via a socket interface\n\n\n\n\n The detailed roadmap is tracked on 
\nJIRA for Mynewt\n. \n\n\n\n\nFeature Request\n\n\nThe WISHLIST at the top of 
the roadmap on \nJIRA for Mynewt\n features all the new ideas awaiting 
discussion and review. Once the community decides to go ahead with a request, 
it is scheduled into a release. Generally, effort is made to schedule a 
requested feature into a particular version no later than 6 weeks prior to the 
planned release date.\n\n\nIf you have suggestions for a new feature, use case, 
or implementation improvements, file a JIRA ticket 

incubator-mynewt-core git commit: MYNEWT-386: Controller should always send connection complete event

2016-09-12 Thread wes3
Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/master 20e2f38f1 -> 840bb6471


MYNEWT-386: Controller should always send connection complete event

The following changes were made to insure that the controller will
always send a connection complete event to the host. When either
a connection create command is sent or a start advertising command
is sent, the controller will attempt to allocate an event buffer
with which to send the connection complete event. If this fails,
the controller will return an error: BLE_ERR_MEM_CAPACITY. If
this succeeds, the controller will then be able to send the
connection complete event to the host.


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

Branch: refs/heads/master
Commit: 840bb64710b0f576fd39f21ad9dcd62c6fcb322b
Parents: 20e2f38
Author: William San Filippo 
Authored: Mon Sep 12 11:20:13 2016 -0700
Committer: William San Filippo 
Committed: Mon Sep 12 11:25:21 2016 -0700

--
 apps/bletest/src/main.c |  20 ++-
 .../controller/include/controller/ble_ll_adv.h  |   3 +
 net/nimble/controller/src/ble_ll_adv.c  |  51 +++-
 net/nimble/controller/src/ble_ll_conn.c |  40 +-
 net/nimble/controller/src/ble_ll_conn_hci.c | 130 +++
 net/nimble/controller/src/ble_ll_conn_priv.h|   3 +-
 6 files changed, 186 insertions(+), 61 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/840bb647/apps/bletest/src/main.c
--
diff --git a/apps/bletest/src/main.c b/apps/bletest/src/main.c
index d21cc50..066d52e 100755
--- a/apps/bletest/src/main.c
+++ b/apps/bletest/src/main.c
@@ -113,7 +113,7 @@ os_membuf_t g_mbuf_buffer[MBUF_MEMPOOL_SIZE];
 #define BLETEST_CFG_ADV_ITVL(6 / BLE_HCI_ADV_ITVL)
 #define BLETEST_CFG_ADV_TYPEBLE_HCI_ADV_TYPE_ADV_IND
 #define BLETEST_CFG_ADV_FILT_POLICY (BLE_HCI_ADV_FILT_NONE)
-#define BLETEST_CFG_ADV_ADDR_RES_EN (1)
+#define BLETEST_CFG_ADV_ADDR_RES_EN (0)
 
 /* Scan config */
 #define BLETEST_CFG_SCAN_ITVL   (70 / BLE_HCI_SCAN_ITVL)
@@ -170,6 +170,7 @@ uint16_t g_bletest_completed_pkts;
 uint16_t g_bletest_outstanding_pkts;
 uint16_t g_bletest_ltk_reply_handle;
 uint32_t g_bletest_hw_id[4];
+struct hci_create_conn g_cc;
 
 /* --- For LE encryption testing --- */
 /* Key: 0x4C68384139F574D836BCF34E9DFB01BF */
@@ -482,11 +483,10 @@ bletest_init_initiator(void)
 {
 int rc;
 uint8_t rand_addr[BLE_DEV_ADDR_LEN];
-struct hci_create_conn cc;
 struct hci_create_conn *hcc;
 
 /* Enable initiating */
-hcc = 
+hcc = _cc;
 hcc->conn_itvl_max = BLETEST_CFG_CONN_ITVL;
 hcc->conn_itvl_min = BLETEST_CFG_CONN_ITVL;
 hcc->conn_latency = BLETEST_CFG_SLAVE_LATENCY;
@@ -529,8 +529,7 @@ bletest_init_initiator(void)
 }
 #endif
 
-rc = bletest_hci_le_create_connection(hcc);
-assert(rc == 0);
+bletest_hci_le_create_connection(hcc);
 }
 
 void
@@ -573,6 +572,10 @@ bletest_execute_initiator(void)
 bletest_init_initiator();
 }
 }
+} else {
+if (ble_ll_scan_enabled() == 0) {
+bletest_hci_le_create_connection(_cc);
+}
 }
 } else {
 if ((int32_t)(os_time_get() - g_next_os_time) >= 0) {
@@ -716,7 +719,12 @@ bletest_execute_advertiser(void)
 g_bletest_cur_peer_addr[5] += 1;
 g_dev_addr[5] += 1;
 bletest_init_advertising();
-rc = bletest_hci_le_set_adv_enable(1);
+bletest_hci_le_set_adv_enable(1);
+}
+} else {
+/* If we failed to start advertising we should keep trying */
+if (ble_ll_adv_enabled() == 0) {
+bletest_hci_le_set_adv_enable(1);
 }
 }
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/840bb647/net/nimble/controller/include/controller/ble_ll_adv.h
--
diff --git a/net/nimble/controller/include/controller/ble_ll_adv.h 
b/net/nimble/controller/include/controller/ble_ll_adv.h
index 33a73ab..8d9a16d 100644
--- a/net/nimble/controller/include/controller/ble_ll_adv.h
+++ b/net/nimble/controller/include/controller/ble_ll_adv.h
@@ -116,6 +116,9 @@ int ble_ll_adv_set_adv_params(uint8_t *cmd);
 int ble_ll_adv_read_txpwr(uint8_t *rspbuf, uint8_t *rsplen);
 
 /* API used by BLE LL */
+/* Returns 

incubator-mynewt-core git commit: MYNEWT-386: Controller should always send connection complete event

2016-09-12 Thread wes3
Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop 61a210874 -> d56270d97


MYNEWT-386: Controller should always send connection complete event

The following changes were made to insure that the controller will
always send a connection complete event to the host. When either
a connection create command is sent or a start advertising command
is sent, the controller will attempt to allocate an event buffer
with which to send the connection complete event. If this fails,
the controller will return an error: BLE_ERR_MEM_CAPACITY. If
this succeeds, the controller will then be able to send the
connection complete event to the host.


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

Branch: refs/heads/develop
Commit: d56270d97a068e8f0b4116210b66cd01d9c28e20
Parents: 61a2108
Author: William San Filippo 
Authored: Mon Sep 12 11:20:13 2016 -0700
Committer: William San Filippo 
Committed: Mon Sep 12 11:22:56 2016 -0700

--
 apps/bletest/src/main.c |  20 ++-
 .../controller/include/controller/ble_ll_adv.h  |   3 +
 net/nimble/controller/src/ble_ll_adv.c  |  51 +++-
 net/nimble/controller/src/ble_ll_conn.c |  40 +-
 net/nimble/controller/src/ble_ll_conn_hci.c | 130 +++
 net/nimble/controller/src/ble_ll_conn_priv.h|   3 +-
 6 files changed, 186 insertions(+), 61 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d56270d9/apps/bletest/src/main.c
--
diff --git a/apps/bletest/src/main.c b/apps/bletest/src/main.c
index d21cc50..066d52e 100755
--- a/apps/bletest/src/main.c
+++ b/apps/bletest/src/main.c
@@ -113,7 +113,7 @@ os_membuf_t g_mbuf_buffer[MBUF_MEMPOOL_SIZE];
 #define BLETEST_CFG_ADV_ITVL(6 / BLE_HCI_ADV_ITVL)
 #define BLETEST_CFG_ADV_TYPEBLE_HCI_ADV_TYPE_ADV_IND
 #define BLETEST_CFG_ADV_FILT_POLICY (BLE_HCI_ADV_FILT_NONE)
-#define BLETEST_CFG_ADV_ADDR_RES_EN (1)
+#define BLETEST_CFG_ADV_ADDR_RES_EN (0)
 
 /* Scan config */
 #define BLETEST_CFG_SCAN_ITVL   (70 / BLE_HCI_SCAN_ITVL)
@@ -170,6 +170,7 @@ uint16_t g_bletest_completed_pkts;
 uint16_t g_bletest_outstanding_pkts;
 uint16_t g_bletest_ltk_reply_handle;
 uint32_t g_bletest_hw_id[4];
+struct hci_create_conn g_cc;
 
 /* --- For LE encryption testing --- */
 /* Key: 0x4C68384139F574D836BCF34E9DFB01BF */
@@ -482,11 +483,10 @@ bletest_init_initiator(void)
 {
 int rc;
 uint8_t rand_addr[BLE_DEV_ADDR_LEN];
-struct hci_create_conn cc;
 struct hci_create_conn *hcc;
 
 /* Enable initiating */
-hcc = 
+hcc = _cc;
 hcc->conn_itvl_max = BLETEST_CFG_CONN_ITVL;
 hcc->conn_itvl_min = BLETEST_CFG_CONN_ITVL;
 hcc->conn_latency = BLETEST_CFG_SLAVE_LATENCY;
@@ -529,8 +529,7 @@ bletest_init_initiator(void)
 }
 #endif
 
-rc = bletest_hci_le_create_connection(hcc);
-assert(rc == 0);
+bletest_hci_le_create_connection(hcc);
 }
 
 void
@@ -573,6 +572,10 @@ bletest_execute_initiator(void)
 bletest_init_initiator();
 }
 }
+} else {
+if (ble_ll_scan_enabled() == 0) {
+bletest_hci_le_create_connection(_cc);
+}
 }
 } else {
 if ((int32_t)(os_time_get() - g_next_os_time) >= 0) {
@@ -716,7 +719,12 @@ bletest_execute_advertiser(void)
 g_bletest_cur_peer_addr[5] += 1;
 g_dev_addr[5] += 1;
 bletest_init_advertising();
-rc = bletest_hci_le_set_adv_enable(1);
+bletest_hci_le_set_adv_enable(1);
+}
+} else {
+/* If we failed to start advertising we should keep trying */
+if (ble_ll_adv_enabled() == 0) {
+bletest_hci_le_set_adv_enable(1);
 }
 }
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d56270d9/net/nimble/controller/include/controller/ble_ll_adv.h
--
diff --git a/net/nimble/controller/include/controller/ble_ll_adv.h 
b/net/nimble/controller/include/controller/ble_ll_adv.h
index 33a73ab..8d9a16d 100644
--- a/net/nimble/controller/include/controller/ble_ll_adv.h
+++ b/net/nimble/controller/include/controller/ble_ll_adv.h
@@ -116,6 +116,9 @@ int ble_ll_adv_set_adv_params(uint8_t *cmd);
 int ble_ll_adv_read_txpwr(uint8_t *rspbuf, uint8_t *rsplen);
 
 /* API used by BLE LL */
+/* Returns 

incubator-mynewt-newt git commit: MYNEWT-126

2016-09-12 Thread paulfdietrich
Repository: incubator-mynewt-newt
Updated Branches:
  refs/heads/develop 7a57c73b5 -> 0baf3a369


MYNEWT-126

newt new command broke because we were not heeding the error from these 
functions.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/0baf3a36
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/0baf3a36
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/0baf3a36

Branch: refs/heads/develop
Commit: 0baf3a3696b5fa072ceea95433b867cf564f0561
Parents: 7a57c73
Author: Paul Dietrich 
Authored: Mon Sep 12 10:39:57 2016 -0700
Committer: Paul Dietrich 
Committed: Mon Sep 12 10:40:48 2016 -0700

--
 newt/cli/complete_cmd.go | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/0baf3a36/newt/cli/complete_cmd.go
--
diff --git a/newt/cli/complete_cmd.go b/newt/cli/complete_cmd.go
index dd113da..c01410c 100644
--- a/newt/cli/complete_cmd.go
+++ b/newt/cli/complete_cmd.go
@@ -34,8 +34,14 @@ import (
 )
 
 func targetList() []string {
-   _ = project.Initialize()
+   err := project.Initialize()
+
targetNames := []string{}
+
+   if err != nil {
+   return targetNames
+   }
+
for name, _ := range target.GetTargets() {
// Don't display the special unittest target; this is used
// internally by newt, so the user doesn't need to know about 
it.
@@ -50,7 +56,14 @@ func targetList() []string {
 
 /* return a list of all packages */
 func packageList() []string {
+
+   err := project.Initialize()
+
var list []string
+
+   if err != nil {
+   return list
+   }
for _, repoHash := range project.GetProject().PackageList() {
for _, pack := range *repoHash {
lclPack := pack.(*pkg.LocalPackage)