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 0000000..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 <assert.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#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 = 0x00020000, .fa_size = 128 * 1024 },
+    [1] = { .fa_off = 0x00040000, .fa_size = 128 * 1024 },
+    [2] = { .fa_off = 0x00060000, .fa_size = 128 * 1024 },
+    [3] = { .fa_off = 0x00080000, .fa_size = 128 * 1024 },
+    [4] = { .fa_off = 0x000a0000, .fa_size = 128 * 1024 },
+    [5] = { .fa_off = 0x000c0000, .fa_size = 128 * 1024 },
+    [6] = { .fa_off = 0x000e0000, .fa_size = 128 * 1024 },
+};
+
+static const struct flash_area boot_test_format_descs[] = {
+    [0] = { .fa_off = 0x00004000, .fa_size = 16 * 1024 },
+    [1] = { .fa_off = 0x00008000, .fa_size = 16 * 1024 },
+    [2] = { .fa_off = 0x0000c000, .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, 0x20000 },
+    { 0, 0x80000 },
+};
+
+#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 < 0x01000000);
+    u32 = image_offset + (img_msb << 24);
+    u8p = (void *)&u32;
+    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, &cnt, 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;
+    area_desc2 = boot_test_area_descs + area_idx2;
+
+    TEST_ASSERT(area_desc1->fa_size == area_desc2->fa_size);
+
+    buf1 = malloc(area_desc1->fa_size);
+    TEST_ASSERT(buf1 != NULL);
+
+    buf2 = malloc(area_desc2->fa_size);
+    TEST_ASSERT(buf2 != NULL);
+
+    rc = flash_area_read(area_desc1, 0, buf1, area_desc1->fa_size);
+    TEST_ASSERT(rc == 0);
+
+    rc = flash_area_read(area_desc2, 0, buf2, area_desc2->fa_size);
+    TEST_ASSERT(rc == 0);
+
+    rc = flash_area_erase(area_desc1, 0, area_desc1->fa_size);
+    TEST_ASSERT(rc == 0);
+
+    rc = flash_area_erase(area_desc2, 0, area_desc2->fa_size);
+    TEST_ASSERT(rc == 0);
+
+    rc = flash_area_write(area_desc1, 0, buf2, area_desc1->fa_size);
+    TEST_ASSERT(rc == 0);
+
+    rc = flash_area_write(area_desc2, 0, buf1, area_desc2->fa_size);
+    TEST_ASSERT(rc == 0);
+
+    free(buf1);
+    free(buf2);
+}
+
+static void
+boot_test_util_write_image(const struct image_header *hdr, int slot)
+{
+    uint32_t image_off;
+    uint32_t off;
+    uint8_t flash_id;
+    uint8_t buf[256];
+    int chunk_sz;
+    int rc;
+    int i;
+
+    TEST_ASSERT(slot == 0 || slot == 1);
+
+    flash_id = boot_test_img_addrs[slot].flash_id;
+    off = boot_test_img_addrs[slot].address;
+
+    rc = hal_flash_write(flash_id, off, hdr, sizeof *hdr);
+    TEST_ASSERT(rc == 0);
+
+    off += hdr->ih_hdr_size;
+
+    image_off = 0;
+    while (image_off < hdr->ih_img_size) {
+        if (hdr->ih_img_size - image_off > sizeof buf) {
+            chunk_sz = sizeof buf;
+        } else {
+            chunk_sz = hdr->ih_img_size - image_off;
+        }
+
+        for (i = 0; i < chunk_sz; i++) {
+            buf[i] = boot_test_util_byte_at(slot, image_off + i);
+        }
+
+        rc = hal_flash_write(flash_id, off + image_off, buf, chunk_sz);
+        TEST_ASSERT(rc == 0);
+
+        image_off += chunk_sz;
+    }
+}
+
+static void
+boot_test_util_write_hash(const struct image_header *hdr, int slot)
+{
+    uint8_t tmpdata[1024];
+    uint8_t hash[32];
+    int rc;
+    uint32_t off;
+    uint32_t blk_sz;
+    uint32_t sz;
+    mbedtls_sha256_context ctx;
+    uint8_t flash_id;
+    uint32_t addr;
+    struct image_tlv tlv;
+
+    mbedtls_sha256_init(&ctx);
+    mbedtls_sha256_starts(&ctx, 0);
+
+    flash_id = boot_test_img_addrs[slot].flash_id;
+    addr = boot_test_img_addrs[slot].address;
+
+    sz = hdr->ih_hdr_size + hdr->ih_img_size;
+    for (off = 0; off < sz; off += blk_sz) {
+        blk_sz = sz - off;
+        if (blk_sz > sizeof(tmpdata)) {
+            blk_sz = sizeof(tmpdata);
+        }
+        rc = hal_flash_read(flash_id, addr + off, tmpdata, blk_sz);
+        TEST_ASSERT(rc == 0);
+        mbedtls_sha256_update(&ctx, tmpdata, blk_sz);
+    }
+    mbedtls_sha256_finish(&ctx, hash);
+
+    tlv.it_type = IMAGE_TLV_SHA256;
+    tlv._pad = 0;
+    tlv.it_len = sizeof(hash);
+
+    rc = hal_flash_write(flash_id, addr + off, &tlv, sizeof(tlv));
+    TEST_ASSERT(rc == 0);
+    off += sizeof(tlv);
+    rc = hal_flash_write(flash_id, addr + off, hash, sizeof(hash));
+    TEST_ASSERT(rc == 0);
+}
+
+static void
+boot_test_util_verify_area(const struct flash_area *area_desc,
+                           const struct image_header *hdr,
+                           uint32_t image_addr, int img_msb)
+{
+    struct image_header temp_hdr;
+    uint32_t area_end;
+    uint32_t img_size;
+    uint32_t img_off;
+    uint32_t img_end;
+    uint32_t addr;
+    uint8_t buf[256];
+    int rem_area;
+    int past_image;
+    int chunk_sz;
+    int rem_img;
+    int rc;
+    int i;
+
+    addr = area_desc->fa_off;
+
+    if (hdr != NULL) {
+        img_size = hdr->ih_img_size;
+
+        if (addr == image_addr) {
+            rc = hal_flash_read(area_desc->fa_flash_id, image_addr,
+                                &temp_hdr, sizeof temp_hdr);
+            TEST_ASSERT(rc == 0);
+            TEST_ASSERT(memcmp(&temp_hdr, hdr, sizeof *hdr) == 0);
+
+            addr += hdr->ih_hdr_size;
+        }
+    } else {
+        img_size = 0;
+    }
+
+    area_end = area_desc->fa_off + area_desc->fa_size;
+    img_end = image_addr + img_size;
+    past_image = addr >= img_end;
+
+    while (addr < area_end) {
+        rem_area = area_end - addr;
+        rem_img = img_end - addr;
+
+        if (hdr != NULL) {
+            img_off = addr - image_addr - hdr->ih_hdr_size;
+        } else {
+            img_off = 0;
+        }
+
+        if (rem_area > sizeof buf) {
+            chunk_sz = sizeof buf;
+        } else {
+            chunk_sz = rem_area;
+        }
+
+        rc = hal_flash_read(area_desc->fa_flash_id, addr, buf, chunk_sz);
+        TEST_ASSERT(rc == 0);
+
+        for (i = 0; i < chunk_sz; i++) {
+            if (rem_img > 0) {
+                TEST_ASSERT(buf[i] == boot_test_util_byte_at(img_msb,
+                                                        img_off + i));
+            } else if (past_image) {
+                TEST_ASSERT(buf[i] == 0xff);
+            }
+        }
+
+        addr += chunk_sz;
+    }
+}
+
+static void
+boot_test_util_verify_status_clear(void)
+{
+    struct fs_file *file;
+    int rc;
+    int empty = 1;
+    char *needle = "boot/status=";
+    int nlen = strlen(needle);
+    uint32_t len, hlen;
+    char *haystack, *ptr;
+
+    rc = fs_open(MY_CONF_PATH, FS_ACCESS_READ, &file);
+    if (rc != 0) {
+        return;
+    }
+    rc = fs_filelen(file, &len);
+    TEST_ASSERT(rc == 0);
+
+    haystack = malloc(len + 1);
+    TEST_ASSERT(haystack);
+
+    rc = fs_read(file, len, haystack, &hlen);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(hlen == len);
+    haystack[len] = '\0';
+
+    fs_close(file);
+
+    ptr = haystack;
+    while ((ptr = strstr(ptr, needle))) {
+        if (ptr[nlen] == '\n') {
+            empty = 1;
+        } else {
+            empty = 0;
+        }
+        ptr += nlen;
+    }
+    TEST_ASSERT(empty == 1);
+    free(haystack);
+
+    rc = fs_open(BOOT_PATH_STATUS, FS_ACCESS_READ, &file);
+    TEST_ASSERT(rc == FS_ENOENT);
+}
+
+static void
+boot_test_util_verify_flash(const struct image_header *hdr0, int orig_slot_0,
+                            const struct image_header *hdr1, int orig_slot_1)
+{
+    const struct flash_area *area_desc;
+    int area_idx;
+
+    area_idx = 0;
+
+    while (1) {
+        area_desc = boot_test_area_descs + area_idx;
+        if (area_desc->fa_off == boot_test_img_addrs[1].address &&
+            area_desc->fa_flash_id == boot_test_img_addrs[1].flash_id) {
+            break;
+        }
+
+        boot_test_util_verify_area(area_desc, hdr0,
+                                   boot_test_img_addrs[0].address, 
orig_slot_0);
+        area_idx++;
+    }
+
+    while (1) {
+        if (area_idx == BOOT_TEST_AREA_IDX_SCRATCH) {
+            break;
+        }
+
+        area_desc = boot_test_area_descs + area_idx;
+        boot_test_util_verify_area(area_desc, hdr1,
+                                   boot_test_img_addrs[1].address, 
orig_slot_1);
+        area_idx++;
+    }
+}
+
+TEST_CASE(boot_test_setup)
+{
+    int rc;
+
+    rc = conf_file_src(&my_conf);
+    assert(rc == 0);
+    rc = conf_file_dst(&my_conf);
+    assert(rc == 0);
+
+    bootutil_cfg_register();
+}
+
+TEST_CASE(boot_test_nv_ns_10)
+{
+    struct boot_rsp rsp;
+    int rc;
+
+    struct image_header hdr = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 12 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 0, 2, 3, 4 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr, 0);
+    boot_test_util_write_hash(&hdr, 0);
+
+    rc = boot_go(&req, &rsp);
+    TEST_ASSERT(rc == 0);
+
+    TEST_ASSERT(memcmp(rsp.br_hdr, &hdr, sizeof hdr) == 0);
+    TEST_ASSERT(rsp.br_flash_id == boot_test_img_addrs[0].flash_id);
+    TEST_ASSERT(rsp.br_image_addr == boot_test_img_addrs[0].address);
+
+    boot_test_util_verify_flash(&hdr, 0, NULL, 0xff);
+    boot_test_util_verify_status_clear();
+}
+
+TEST_CASE(boot_test_nv_ns_01)
+{
+    struct boot_rsp rsp;
+    int rc;
+
+
+    struct image_header hdr = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 10 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 1, 2, 3, 432 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr, 1);
+    boot_test_util_write_hash(&hdr, 1);
+
+    rc = boot_go(&req, &rsp);
+    TEST_ASSERT(rc == 0);
+
+    TEST_ASSERT(memcmp(rsp.br_hdr, &hdr, sizeof hdr) == 0);
+    TEST_ASSERT(rsp.br_flash_id == boot_test_img_addrs[0].flash_id);
+    TEST_ASSERT(rsp.br_image_addr == boot_test_img_addrs[0].address);
+
+    boot_test_util_verify_flash(&hdr, 1, NULL, 0xff);
+    boot_test_util_verify_status_clear();
+}
+
+TEST_CASE(boot_test_nv_ns_11)
+{
+    struct boot_rsp rsp;
+    int rc;
+
+    struct image_header hdr0 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 5 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 0, 5, 21, 432 },
+    };
+
+    struct image_header hdr1 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 32 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 1, 2, 3, 432 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr0, 0);
+    boot_test_util_write_hash(&hdr0, 0);
+    boot_test_util_write_image(&hdr1, 1);
+    boot_test_util_write_hash(&hdr1, 1);
+
+    rc = boot_go(&req, &rsp);
+    TEST_ASSERT(rc == 0);
+
+    TEST_ASSERT(memcmp(rsp.br_hdr, &hdr0, sizeof hdr0) == 0);
+    TEST_ASSERT(rsp.br_flash_id == boot_test_img_addrs[0].flash_id);
+    TEST_ASSERT(rsp.br_image_addr == boot_test_img_addrs[0].address);
+
+    boot_test_util_verify_flash(&hdr0, 0, &hdr1, 1);
+    boot_test_util_verify_status_clear();
+}
+
+TEST_CASE(boot_test_vm_ns_10)
+{
+    struct boot_rsp rsp;
+    int rc;
+
+
+    struct image_header hdr = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 12 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 0, 2, 3, 4 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr, 0);
+    boot_test_util_write_hash(&hdr, 0);
+
+    rc = boot_vect_write_main(&hdr.ih_ver);
+    TEST_ASSERT(rc == 0);
+
+    rc = boot_go(&req, &rsp);
+    TEST_ASSERT(rc == 0);
+
+    TEST_ASSERT(memcmp(rsp.br_hdr, &hdr, sizeof hdr) == 0);
+    TEST_ASSERT(rsp.br_flash_id == boot_test_img_addrs[0].flash_id);
+    TEST_ASSERT(rsp.br_image_addr == boot_test_img_addrs[0].address);
+
+    boot_test_util_verify_flash(&hdr, 0, NULL, 0xff);
+    boot_test_util_verify_status_clear();
+}
+
+TEST_CASE(boot_test_vm_ns_01)
+{
+    struct boot_rsp rsp;
+    int rc;
+
+    struct image_header hdr = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 10 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 1, 2, 3, 432 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr, 1);
+    boot_test_util_write_hash(&hdr, 1);
+
+    rc = boot_vect_write_main(&hdr.ih_ver);
+    TEST_ASSERT(rc == 0);
+
+    rc = boot_go(&req, &rsp);
+    TEST_ASSERT(rc == 0);
+
+    TEST_ASSERT(memcmp(rsp.br_hdr, &hdr, sizeof hdr) == 0);
+    TEST_ASSERT(rsp.br_flash_id == boot_test_img_addrs[0].flash_id);
+    TEST_ASSERT(rsp.br_image_addr == boot_test_img_addrs[0].address);
+
+    boot_test_util_verify_flash(&hdr, 1, NULL, 0xff);
+    boot_test_util_verify_status_clear();
+}
+
+TEST_CASE(boot_test_vm_ns_11_a)
+{
+    struct boot_rsp rsp;
+    int rc;
+
+    struct image_header hdr0 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 5 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 0, 5, 21, 432 },
+    };
+
+    struct image_header hdr1 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 32 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 1, 2, 3, 432 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr0, 0);
+    boot_test_util_write_hash(&hdr0, 0);
+    boot_test_util_write_image(&hdr1, 1);
+    boot_test_util_write_hash(&hdr1, 1);
+
+    rc = boot_vect_write_main(&hdr0.ih_ver);
+    TEST_ASSERT(rc == 0);
+
+    rc = boot_go(&req, &rsp);
+    TEST_ASSERT(rc == 0);
+
+    TEST_ASSERT(memcmp(rsp.br_hdr, &hdr0, sizeof hdr0) == 0);
+    TEST_ASSERT(rsp.br_flash_id == boot_test_img_addrs[0].flash_id);
+    TEST_ASSERT(rsp.br_image_addr == boot_test_img_addrs[0].address);
+
+    boot_test_util_verify_flash(&hdr0, 0, &hdr1, 1);
+    boot_test_util_verify_status_clear();
+}
+
+TEST_CASE(boot_test_vm_ns_11_b)
+{
+    struct boot_rsp rsp;
+    int rc;
+
+    struct image_header hdr0 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 5 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 0, 5, 21, 432 },
+    };
+
+    struct image_header hdr1 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 32 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 1, 2, 3, 432 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr0, 0);
+    boot_test_util_write_hash(&hdr0, 0);
+    boot_test_util_write_image(&hdr1, 1);
+    boot_test_util_write_hash(&hdr1, 1);
+
+    rc = boot_vect_write_main(&hdr1.ih_ver);
+    TEST_ASSERT(rc == 0);
+
+    rc = boot_go(&req, &rsp);
+    TEST_ASSERT(rc == 0);
+
+    TEST_ASSERT(memcmp(rsp.br_hdr, &hdr1, sizeof hdr1) == 0);
+    TEST_ASSERT(rsp.br_flash_id == boot_test_img_addrs[0].flash_id);
+    TEST_ASSERT(rsp.br_image_addr == boot_test_img_addrs[0].address);
+
+    boot_test_util_verify_flash(&hdr1, 1, &hdr0, 0);
+    boot_test_util_verify_status_clear();
+}
+
+TEST_CASE(boot_test_vm_ns_11_2areas)
+{
+    struct boot_rsp rsp;
+    int rc;
+
+    struct image_header hdr0 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 5 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 0, 5, 21, 432 },
+    };
+
+    struct image_header hdr1 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 196 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 1, 2, 3, 432 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr0, 0);
+    boot_test_util_write_hash(&hdr0, 0);
+    boot_test_util_write_image(&hdr1, 1);
+    boot_test_util_write_hash(&hdr1, 1);
+
+    rc = boot_vect_write_main(&hdr1.ih_ver);
+    TEST_ASSERT(rc == 0);
+
+    rc = boot_go(&req, &rsp);
+    TEST_ASSERT(rc == 0);
+
+    TEST_ASSERT(memcmp(rsp.br_hdr, &hdr1, sizeof hdr1) == 0);
+    TEST_ASSERT(rsp.br_flash_id == boot_test_img_addrs[0].flash_id);
+    TEST_ASSERT(rsp.br_image_addr == boot_test_img_addrs[0].address);
+
+    boot_test_util_verify_flash(&hdr1, 1, &hdr0, 0);
+    boot_test_util_verify_status_clear();
+}
+
+TEST_CASE(boot_test_nv_bs_10)
+{
+    struct boot_status status;
+    struct boot_rsp rsp;
+    int rc;
+
+    struct image_header hdr = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 12 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 0, 2, 3, 4 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr, 0);
+    boot_test_util_write_hash(&hdr, 0);
+    boot_test_util_swap_areas(boot_test_slot_areas[1],
+      BOOT_TEST_AREA_IDX_SCRATCH);
+
+    status.length = hdr.ih_hdr_size + hdr.ih_img_size + hdr.ih_tlv_size;
+    status.state = 1;
+
+    rc = boot_write_status(&status);
+    TEST_ASSERT(rc == 0);
+    conf_load();
+
+    rc = boot_go(&req, &rsp);
+    TEST_ASSERT(rc == 0);
+
+    TEST_ASSERT(memcmp(rsp.br_hdr, &hdr, sizeof hdr) == 0);
+    TEST_ASSERT(rsp.br_flash_id == boot_test_img_addrs[0].flash_id);
+    TEST_ASSERT(rsp.br_image_addr == boot_test_img_addrs[0].address);
+
+    boot_test_util_verify_flash(&hdr, 0, NULL, 0xff);
+    boot_test_util_verify_status_clear();
+}
+
+TEST_CASE(boot_test_nv_bs_11)
+{
+    struct boot_status status;
+    struct boot_rsp rsp;
+    int len;
+    int rc;
+
+    struct image_header hdr0 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 12 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 0, 2, 3, 4 },
+    };
+
+    struct image_header hdr1 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 17 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 1, 1, 5, 5 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr0, 0);
+    boot_test_util_write_hash(&hdr0, 0);
+    boot_test_util_write_image(&hdr1, 1);
+    boot_test_util_write_hash(&hdr1, 1);
+    boot_test_util_copy_area(boot_test_slot_areas[1],
+      BOOT_TEST_AREA_IDX_SCRATCH);
+
+    status.length = hdr0.ih_hdr_size + hdr0.ih_img_size + hdr0.ih_tlv_size;
+    len = hdr1.ih_hdr_size + hdr1.ih_img_size + hdr1.ih_tlv_size;
+    if (len > status.length) {
+        status.length = len;
+    }
+    status.state = 1;
+
+    rc = boot_write_status(&status);
+    TEST_ASSERT(rc == 0);
+
+    rc = boot_go(&req, &rsp);
+    TEST_ASSERT(rc == 0);
+
+    TEST_ASSERT(memcmp(rsp.br_hdr, &hdr1, sizeof hdr1) == 0);
+    TEST_ASSERT(rsp.br_flash_id == boot_test_img_addrs[0].flash_id);
+    TEST_ASSERT(rsp.br_image_addr == boot_test_img_addrs[0].address);
+
+    boot_test_util_verify_flash(&hdr1, 1, &hdr0, 0);
+    boot_test_util_verify_status_clear();
+}
+
+TEST_CASE(boot_test_nv_bs_11_2areas)
+{
+    struct boot_status status;
+    struct boot_rsp rsp;
+    int rc;
+    int len;
+
+    struct image_header hdr0 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 150 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 0, 5, 21, 432 },
+    };
+
+    struct image_header hdr1 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 190 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 1, 2, 3, 432 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr0, 0);
+    boot_test_util_write_hash(&hdr0, 0);
+    boot_test_util_write_image(&hdr1, 1);
+    boot_test_util_write_hash(&hdr1, 1);
+    boot_test_util_swap_areas(boot_test_slot_areas[0],
+      boot_test_slot_areas[1]);
+
+    status.length = hdr0.ih_hdr_size + hdr0.ih_img_size + hdr0.ih_tlv_size;
+    len = hdr1.ih_hdr_size + hdr1.ih_img_size + hdr1.ih_tlv_size;
+    if (len > status.length) {
+        status.length = len;
+    }
+    status.state = 1 << 8;
+
+    rc = boot_write_status(&status);
+    TEST_ASSERT(rc == 0);
+
+    rc = boot_go(&req, &rsp);
+    TEST_ASSERT(rc == 0);
+
+    TEST_ASSERT(memcmp(rsp.br_hdr, &hdr1, sizeof hdr1) == 0);
+    TEST_ASSERT(rsp.br_flash_id == boot_test_img_addrs[0].flash_id);
+    TEST_ASSERT(rsp.br_image_addr == boot_test_img_addrs[0].address);
+
+    boot_test_util_verify_flash(&hdr1, 1, &hdr0, 0);
+    boot_test_util_verify_status_clear();
+}
+
+TEST_CASE(boot_test_vb_ns_11)
+{
+    struct boot_rsp rsp;
+    int rc;
+    int i;
+
+    struct image_header hdr0 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 5 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 0, 5, 21, 432 },
+    };
+
+    struct image_header hdr1 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 32 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 1, 2, 3, 432 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr0, 0);
+    boot_test_util_write_image(&hdr1, 1);
+    boot_test_util_write_hash(&hdr0, 0);
+    boot_test_util_write_hash(&hdr1, 1);
+
+    rc = boot_vect_write_main(&hdr0.ih_ver);
+    TEST_ASSERT(rc == 0);
+
+    rc = boot_vect_write_test(&hdr1.ih_ver);
+    TEST_ASSERT(rc == 0);
+
+    /* First boot should use the test image. */
+    rc = boot_go(&req, &rsp);
+    TEST_ASSERT(rc == 0);
+
+    TEST_ASSERT(memcmp(rsp.br_hdr, &hdr1, sizeof hdr1) == 0);
+    TEST_ASSERT(rsp.br_flash_id == boot_test_img_addrs[0].flash_id);
+    TEST_ASSERT(rsp.br_image_addr == boot_test_img_addrs[0].address);
+
+    boot_test_util_verify_flash(&hdr1, 1, &hdr0, 0);
+    boot_test_util_verify_status_clear();
+
+    /* Ensure all subsequent boots use the main image. */
+    for (i = 0; i < 10; i++) {
+        rc = boot_go(&req, &rsp);
+        TEST_ASSERT(rc == 0);
+
+        TEST_ASSERT(memcmp(rsp.br_hdr, &hdr0, sizeof hdr0) == 0);
+        TEST_ASSERT(rsp.br_flash_id == boot_test_img_addrs[0].flash_id);
+        TEST_ASSERT(rsp.br_image_addr == boot_test_img_addrs[0].address);
+
+        boot_test_util_verify_flash(&hdr0, 0, &hdr1, 1);
+        boot_test_util_verify_status_clear();
+    }
+}
+
+TEST_CASE(boot_test_no_hash)
+{
+    struct boot_rsp rsp;
+    int rc;
+
+    struct image_header hdr = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 0,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 12 * 1024,
+        .ih_flags = 0,
+        .ih_ver = { 0, 2, 3, 4 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr, 0);
+
+    rc = boot_go(&req, &rsp);
+    TEST_ASSERT(rc != 0);
+
+    boot_test_util_verify_flash(&hdr, 0, NULL, 0xff);
+    boot_test_util_verify_status_clear();
+}
+
+TEST_CASE(boot_test_no_flag_has_hash)
+{
+    struct boot_rsp rsp;
+    int rc;
+
+    struct image_header hdr = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 12 * 1024,
+        .ih_flags = 0,
+        .ih_ver = { 0, 2, 3, 4 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr, 0);
+    boot_test_util_write_hash(&hdr, 0);
+
+    rc = boot_go(&req, &rsp);
+    TEST_ASSERT(rc != 0);
+
+    boot_test_util_verify_flash(&hdr, 0, NULL, 0xff);
+    boot_test_util_verify_status_clear();
+}
+
+TEST_CASE(boot_test_invalid_hash)
+{
+    struct boot_rsp rsp;
+    int rc;
+
+    struct image_header hdr = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 12 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 0, 2, 3, 4 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+    };
+
+    struct image_tlv tlv = {
+        .it_type = IMAGE_TLV_SHA256,
+        .it_len = 32
+    };
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr, 0);
+    rc = hal_flash_write(boot_test_img_addrs[0].flash_id,
+      boot_test_img_addrs[0].address + hdr.ih_hdr_size + hdr.ih_img_size,
+      &tlv, sizeof(tlv));
+    TEST_ASSERT(rc == 0);
+
+    rc = boot_go(&req, &rsp);
+    TEST_ASSERT(rc != 0);
+
+    boot_test_util_verify_flash(&hdr, 0, NULL, 0xff);
+    boot_test_util_verify_status_clear();
+}
+
+TEST_SUITE(boot_test_main)
+{
+    boot_test_setup();
+    boot_test_nv_ns_10();
+    boot_test_nv_ns_01();
+    boot_test_nv_ns_11();
+    boot_test_vm_ns_10();
+    boot_test_vm_ns_01();
+    boot_test_vm_ns_11_a();
+    boot_test_vm_ns_11_b();
+    boot_test_vm_ns_11_2areas();
+    boot_test_nv_bs_10();
+    boot_test_nv_bs_11();
+    boot_test_nv_bs_11_2areas();
+    boot_test_vb_ns_11();
+    boot_test_no_hash();
+    boot_test_no_flag_has_hash();
+    boot_test_invalid_hash();
+}
+
+int
+boot_test_all(void)
+{
+    boot_test_main();
+    return tu_any_failed;
+}
+
+#if MYNEWT_VAL(SELFTEST)
+
+int
+main(void)
+{
+    tu_config.tc_print_results = 1;
+    tu_init();
+
+    boot_test_all();
+
+    return tu_any_failed;
+}
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/console/full/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/console/full/pkg.yml b/libs/console/full/pkg.yml
index 57d6b6f..69e3ddb 100644
--- a/libs/console/full/pkg.yml
+++ b/libs/console/full/pkg.yml
@@ -28,4 +28,6 @@ pkg.deps:
     - libs/os
     - drivers/uart
 pkg.apis: console
-pkg.cflags.BASELIBC: -DBASELIBC_PRESENT
+
+pkg.init_function: console_pkg_init
+pkg.init_stage: 5

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/console/full/src/cons_fmt.c
----------------------------------------------------------------------
diff --git a/libs/console/full/src/cons_fmt.c b/libs/console/full/src/cons_fmt.c
index 10f90e2..2b64c01 100644
--- a/libs/console/full/src/cons_fmt.c
+++ b/libs/console/full/src/cons_fmt.c
@@ -18,12 +18,13 @@
  */
 #include <stdarg.h>
 #include <stdio.h>
-#include <console/console.h>
-#include <os/os_time.h>
+#include "syscfg/syscfg.h"
+#include "console/console.h"
+#include "os/os_time.h"
 
 #define CONS_OUTPUT_MAX_LINE   128
 
-#ifdef BASELIBC_PRESENT
+#if MYNEWT_PKG(LIBS_BASELIBC)
 size_t console_file_write(FILE *p, const char *str, size_t cnt);
 
 static const struct File_methods console_file_ops = {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/console/full/src/cons_tty.c
----------------------------------------------------------------------
diff --git a/libs/console/full/src/cons_tty.c b/libs/console/full/src/cons_tty.c
index e7ccfe8..49dfefc 100644
--- a/libs/console/full/src/cons_tty.c
+++ b/libs/console/full/src/cons_tty.c
@@ -18,9 +18,11 @@
  */
 
 #include <inttypes.h>
-#include <os/os.h>
-#include <uart/uart.h>
-#include <bsp/bsp.h>
+#include <assert.h>
+#include "sysinit/sysinit.h"
+#include "os/os.h"
+#include "uart/uart.h"
+#include "bsp/bsp.h"
 #include "console/console.h"
 
 /** Indicates whether the previous line of output was completed. */
@@ -402,3 +404,12 @@ console_init(console_rx_cb rx_cb)
 
     return 0;
 }
+
+void
+console_pkg_init(void)
+{
+    int rc;
+
+    rc = console_init(NULL);
+    SYSINIT_PANIC_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/crash_test/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/crash_test/pkg.yml b/libs/crash_test/pkg.yml
index 872c029..f823781 100644
--- a/libs/crash_test/pkg.yml
+++ b/libs/crash_test/pkg.yml
@@ -22,15 +22,19 @@ pkg.description: Generate different kinds of faults
 pkg.homepage: "http://mynewt.apache.org/";
 pkg.keywords:
 
-pkg.deps.SHELL:
+pkg.deps.CRASH_TEST_CLI:
     - libs/shell
-pkg.req_apis.SHELL:
+pkg.req_apis.CRASH_TEST_CLI:
     - console
-pkg.cflags.SHELL:
-    - -DSHELL_PRESENT
 
-pkg.deps.NEWTMGR:
+pkg.deps.CRASH_TEST_NEWTMGR:
     - libs/newtmgr
     - libs/json
-pkg.cflags.NEWTMGR:
-    - -DNEWTMGR_PRESENT
+
+pkg.syscfg_defs:
+    CRASH_TEST_CLI:
+        description: 'TBD'
+        value: 1
+    CRASH_TEST_NEWTMGR:
+        description: 'TBD'
+        value: 1

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/crash_test/src/crash_cli.c
----------------------------------------------------------------------
diff --git a/libs/crash_test/src/crash_cli.c b/libs/crash_test/src/crash_cli.c
index db22e13..4d49bef 100644
--- a/libs/crash_test/src/crash_cli.c
+++ b/libs/crash_test/src/crash_cli.c
@@ -16,7 +16,10 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-#ifdef SHELL_PRESENT
+
+#include "syscfg/syscfg.h"
+
+#if MYNEWT_VAL(CRASH_TEST_CLI)
 #include <inttypes.h>
 #include <os/os.h>
 #include <console/console.h>
@@ -43,4 +46,4 @@ crash_cli_cmd(int argc, char **argv)
     return 0;
 }
 
-#endif /* SHELL_PRESENT */
+#endif /* MYNEWT_VAL(CRASH_TEST_CLI) */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/crash_test/src/crash_nmgr.c
----------------------------------------------------------------------
diff --git a/libs/crash_test/src/crash_nmgr.c b/libs/crash_test/src/crash_nmgr.c
index e53fdf8..d9bf4b0 100644
--- a/libs/crash_test/src/crash_nmgr.c
+++ b/libs/crash_test/src/crash_nmgr.c
@@ -17,13 +17,15 @@
  * under the License.
  */
 
-#ifdef NEWTMGR_PRESENT
+#include "syscfg/syscfg.h"
+
+#if MYNEWT_VAL(CRASH_TEST_NEWTMGR)
 
 #include <string.h>
 
-#include <newtmgr/newtmgr.h>
-#include <json/json.h>
-#include <console/console.h>
+#include "newtmgr/newtmgr.h"
+#include "json/json.h"
+#include "console/console.h"
 
 #include "crash_test/crash_test.h"
 #include "crash_test_priv.h"
@@ -70,4 +72,4 @@ crash_test_nmgr_write(struct nmgr_jbuf *njb)
     return 0;
 }
 
-#endif
+#endif /* MYNEWT_VAL(CRASH_TEST_NEWTMGR) */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/crash_test/src/crash_test.c
----------------------------------------------------------------------
diff --git a/libs/crash_test/src/crash_test.c b/libs/crash_test/src/crash_test.c
index 91f1dbd..a6e2ea2 100644
--- a/libs/crash_test/src/crash_test.c
+++ b/libs/crash_test/src/crash_test.c
@@ -17,20 +17,22 @@
  * under the License.
  */
 #include <inttypes.h>
-#include <os/os.h>
-#include <console/console.h>
 #include <stdio.h>
 #include <string.h>
 #include <assert.h>
 
+#include "syscfg/syscfg.h"
+#include "os/os.h"
+#include "console/console.h"
+
 #include "crash_test/crash_test.h"
 #include "crash_test_priv.h"
 
-#ifdef SHELL_PRESENT
-#include <shell/shell.h>
+#if MYNEWT_VAL(CRASH_TEST_CLI)
+#include "shell/shell.h"
 #endif
-#ifdef NEWTMGR_PRESENT
-#include <newtmgr/newtmgr.h>
+#if MYNEWT_VAL(CRASH_TEST_NEWTMGR)
+#include "newtmgr/newtmgr.h"
 #endif
 
 int
@@ -60,10 +62,10 @@ crash_device(char *how)
 int
 crash_test_init(void)
 {
-#ifdef SHELL_PRESENT
+#if MYNEWT_VAL(CRASH_TEST_CLI)
     shell_cmd_register(&crash_cmd_struct);
 #endif
-#ifdef NEWTMGR_PRESENT
+#if MYNEWT_VAL(CRASH_TEST_NEWTMGR)
     nmgr_group_register(&crash_test_nmgr_group);
 #endif
     return 0;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/crash_test/src/crash_test_priv.h
----------------------------------------------------------------------
diff --git a/libs/crash_test/src/crash_test_priv.h 
b/libs/crash_test/src/crash_test_priv.h
index e4af708..09dc5a3 100644
--- a/libs/crash_test/src/crash_test_priv.h
+++ b/libs/crash_test/src/crash_test_priv.h
@@ -19,10 +19,10 @@
 #ifndef __CRASH_TEST_PRIV_H__
 #define __CRASH_TEST_PRIV_H__
 
-#ifdef SHELL_PRESENT
+#if MYNEWT_VAL(CRASH_TEST_CLI)
 extern struct shell_cmd crash_cmd_struct;
 #endif
-#ifdef NEWTMGR_PRESENT
+#if MYNEWT_VAL(CRASH_TEST_NEWTMGR)
 extern struct nmgr_group crash_test_nmgr_group;
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/elua/elua_base/include/elua_base/elua.h
----------------------------------------------------------------------
diff --git a/libs/elua/elua_base/include/elua_base/elua.h 
b/libs/elua/elua_base/include/elua_base/elua.h
index dae75a1..e1396e4 100644
--- a/libs/elua/elua_base/include/elua_base/elua.h
+++ b/libs/elua/elua_base/include/elua_base/elua.h
@@ -22,6 +22,6 @@
 
 int lua_main( int argc, char **argv );
 
-int lua_init(void);
+void lua_init(void);
 
 #endif /* __ELUA_BASE_H__ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/elua/elua_base/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/elua/elua_base/pkg.yml b/libs/elua/elua_base/pkg.yml
index 5180159..9714507 100644
--- a/libs/elua/elua_base/pkg.yml
+++ b/libs/elua/elua_base/pkg.yml
@@ -28,11 +28,23 @@ pkg.keywords:
     - scripting
     - interpreter
 
-pkg.cflags: -DLUA_OPTIMIZE_MEMORY=2 -DLUA_CROSS_COMPILER -DLUA_USE_MKSTEMP 
-DLUA_NUMBER_INTEGRAL -DMYNEWT
+pkg.cflags:
+    - "-DLUA_OPTIMIZE_MEMORY=2"
+    - "-DLUA_CROSS_COMPILER"
+    - "-DLUA_USE_MKSTEMP"
+    - "-DLUA_NUMBER_INTEGRAL"
+    - "-DMYNEWT"
 pkg.req_apis:
     - console
 pkg.deps:
     - fs/fs
-pkg.deps.SHELL:
+pkg.deps.ELUA_CLI:
     - libs/shell
-pkg.cflags.SHELL: -DSHELL_PRESENT
+
+pkg.init_function: lua_init
+pkg.init_stage: 5
+
+pkg.syscfg_defs:
+    ELUA_CLI:
+        description: 'TBD'
+        value: 'MYNEWT_PKG_LIBS_SHELL'

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/elua/elua_base/src/lmynewt.c
----------------------------------------------------------------------
diff --git a/libs/elua/elua_base/src/lmynewt.c 
b/libs/elua/elua_base/src/lmynewt.c
index e7eda1e..bf40a2e 100644
--- a/libs/elua/elua_base/src/lmynewt.c
+++ b/libs/elua/elua_base/src/lmynewt.c
@@ -16,12 +16,16 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-#include <shell/shell.h>
-#include <elua_base/elua.h>
+
+#include <assert.h>
+#include "sysinit/sysinit.h"
+#include "syscfg/syscfg.h"
+#include "shell/shell.h"
+#include "elua_base/elua.h"
 
 #ifdef MYNEWT
 
-#ifdef SHELL_PRESENT
+#if MYNEWT_VAL(ELUA_CLI)
 static int lua_cmd(int argc, char **argv);
 
 static struct shell_cmd lua_shell_cmd = {
@@ -37,13 +41,16 @@ lua_cmd(int argc, char **argv)
 }
 #endif
 
-int
+void
 lua_init(void)
 {
-#ifdef SHELL_PRESENT
-    return shell_cmd_register(&lua_shell_cmd);
-#else
-    return 0;
+    int rc;
+
+    (void)rc;
+
+#if MYNEWT_VAL(ELUA_CLI)
+    rc = shell_cmd_register(&lua_shell_cmd);
+    SYSINIT_PANIC_ASSERT(rc == 0);
 #endif
 }
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/imgmgr/include/imgmgr/imgmgr.h
----------------------------------------------------------------------
diff --git a/libs/imgmgr/include/imgmgr/imgmgr.h 
b/libs/imgmgr/include/imgmgr/imgmgr.h
index 17c9e7f..b6299a0 100644
--- a/libs/imgmgr/include/imgmgr/imgmgr.h
+++ b/libs/imgmgr/include/imgmgr/imgmgr.h
@@ -35,7 +35,7 @@
 
 #define IMGMGR_HASH_LEN                 32
 
-int imgmgr_module_init(void);
+void imgmgr_module_init(void);
 
 struct image_version;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/imgmgr/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/imgmgr/pkg.yml b/libs/imgmgr/pkg.yml
index ed02f32..ff7812e 100644
--- a/libs/imgmgr/pkg.yml
+++ b/libs/imgmgr/pkg.yml
@@ -27,10 +27,20 @@ pkg.deps:
     - libs/newtmgr
     - libs/bootutil
     - libs/util
-pkg.deps.FS:
+
+pkg.deps.IMGMGR_FS:
     - fs/fs
-pkg.cflags.FS: -DFS_PRESENT
 
-pkg.deps.COREDUMP:
+pkg.deps.IMGMGR_COREDUMP:
     - sys/coredump
-pkg.cflags.COREDUMP: -DCOREDUMP_PRESENT
+
+pkg.init_function: imgmgr_module_init
+pkg.init_stage: 5
+
+pkg.syscfg_defs:
+    IMGMGR_FS:
+        description: 'TBD'
+        value: 'MYNEWT_PKG_FS_FS'
+    IMGMGR_COREDUMP:
+        description: 'TBD'
+        value: 'MYNEWT_PKG_SYS_COREDUMP'

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/imgmgr/src/imgmgr.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr.c b/libs/imgmgr/src/imgmgr.c
index 5e8539a..0cb7bc4 100644
--- a/libs/imgmgr/src/imgmgr.c
+++ b/libs/imgmgr/src/imgmgr.c
@@ -21,13 +21,14 @@
 #include <limits.h>
 #include <assert.h>
 #include <string.h>
-#include <hal/hal_bsp.h>
-#include <hal/flash_map.h>
-#include <newtmgr/newtmgr.h>
-#include <json/json.h>
-#include <util/base64.h>
 
-#include <bootutil/image.h>
+#include "sysinit/sysinit.h"
+#include "hal/hal_bsp.h"
+#include "hal/flash_map.h"
+#include "newtmgr/newtmgr.h"
+#include "json/json.h"
+#include "util/base64.h"
+#include "bootutil/image.h"
 
 #include "imgmgr/imgmgr.h"
 #include "imgmgr_priv.h"
@@ -51,7 +52,7 @@ static const struct nmgr_handler imgr_nmgr_handlers[] = {
         .nh_write = imgr_boot_write
     },
     [IMGMGR_NMGR_OP_FILE] = {
-#ifdef FS_PRESENT
+#if MYNEWT_VAL(IMGMGR_FS)
         .nh_read = imgr_file_download,
         .nh_write = imgr_file_upload
 #else
@@ -68,7 +69,7 @@ static const struct nmgr_handler imgr_nmgr_handlers[] = {
         .nh_write = imgr_boot2_write
     },
     [IMGMGR_NMGR_OP_CORELIST] = {
-#ifdef COREDUMP_PRESENT
+#if MYNEWT_VAL(IMGMGR_COREDUMP)
         .nh_read = imgr_core_list,
         .nh_write = imgr_noop,
 #else
@@ -77,7 +78,7 @@ static const struct nmgr_handler imgr_nmgr_handlers[] = {
 #endif
     },
     [IMGMGR_NMGR_OP_CORELOAD] = {
-#ifdef COREDUMP_PRESENT
+#if MYNEWT_VAL(IMGMGR_COREDUMP)
         .nh_read = imgr_core_load,
         .nh_write = imgr_core_erase,
 #else
@@ -487,12 +488,11 @@ err:
     return 0;
 }
 
-int
+void
 imgmgr_module_init(void)
 {
     int rc;
 
     rc = nmgr_group_register(&imgr_nmgr_group);
-    assert(rc == 0);
-    return rc;
+    SYSINIT_PANIC_ASSERT(rc == 0);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/imgmgr/src/imgmgr_coredump.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr_coredump.c 
b/libs/imgmgr/src/imgmgr_coredump.c
index 6f3543b..17c430d 100644
--- a/libs/imgmgr/src/imgmgr_coredump.c
+++ b/libs/imgmgr/src/imgmgr_coredump.c
@@ -16,14 +16,17 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-#ifdef COREDUMP_PRESENT
+
+#include "syscfg/syscfg.h"
+
+#if MYNEWT_VAL(IMGMGR_COREDUMP)
 
 #include <limits.h>
 
-#include <hal/flash_map.h>
-#include <newtmgr/newtmgr.h>
-#include <coredump/coredump.h>
-#include <util/base64.h>
+#include "hal/flash_map.h"
+#include "newtmgr/newtmgr.h"
+#include "coredump/coredump.h"
+#include "util/base64.h"
 
 #include "imgmgr/imgmgr.h"
 #include "imgmgr_priv.h"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/imgmgr/src/imgmgr_fs.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr_fs.c b/libs/imgmgr/src/imgmgr_fs.c
index 0da77de..af4579d 100644
--- a/libs/imgmgr/src/imgmgr_fs.c
+++ b/libs/imgmgr/src/imgmgr_fs.c
@@ -16,21 +16,24 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-#ifdef FS_PRESENT
-#include <os/os.h>
-#include <os/endian.h>
+
+#include "syscfg/syscfg.h"
+
+#if MYNEWT_VAL(IMGMGR_FS)
 
 #include <limits.h>
 #include <assert.h>
 #include <string.h>
 #include <stdio.h>
 
-#include <newtmgr/newtmgr.h>
-#include <bootutil/image.h>
-#include <fs/fs.h>
-#include <json/json.h>
-#include <util/base64.h>
-#include <bsp/bsp.h>
+#include "os/os.h"
+#include "os/endian.h"
+#include "newtmgr/newtmgr.h"
+#include "bootutil/image.h"
+#include "fs/fs.h"
+#include "json/json.h"
+#include "util/base64.h"
+#include "bsp/bsp.h"
 
 #include "imgmgr/imgmgr.h"
 #include "imgmgr_priv.h"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/imgmgr/src/imgmgr_priv.h
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr_priv.h b/libs/imgmgr/src/imgmgr_priv.h
index e8dcde3..0efd688 100644
--- a/libs/imgmgr/src/imgmgr_priv.h
+++ b/libs/imgmgr/src/imgmgr_priv.h
@@ -21,6 +21,7 @@
 #define __IMGMGR_PRIV_H_
 
 #include <stdint.h>
+#include "syscfg/syscfg.h"
 
 #define IMGMGR_MAX_IMGS                2
 
@@ -87,7 +88,7 @@ struct imgr_state {
         uint32_t off;
         uint32_t size;
         const struct flash_area *fa;
-#ifdef FS_PRESENT
+#if MYNEWT_VAL(IMGMGR_FS)
         struct fs_file *file;
 #endif
     } upload;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/inet_def_service/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/inet_def_service/pkg.yml b/libs/inet_def_service/pkg.yml
index 103b0d5..7fb9ff2 100644
--- a/libs/inet_def_service/pkg.yml
+++ b/libs/inet_def_service/pkg.yml
@@ -30,9 +30,6 @@ pkg.deps:
     - sys/mn_socket
     - libs/os
     - libs/util
-    - libs/testutil
 
 pkg.reqs:
     - console
-
-pkg.features:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/json/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/json/pkg.yml b/libs/json/pkg.yml
index 3dc0be6..4944622 100644
--- a/libs/json/pkg.yml
+++ b/libs/json/pkg.yml
@@ -22,7 +22,5 @@ pkg.description: JSON encoding / decoding library.
 pkg.author: "Apache Mynewt <d...@mynewt.incubator.apache.org>"
 pkg.homepage: "http://mynewt.apache.org/";
 pkg.keywords:
-pkg.deps.TEST:
-   - libs/testutil
 
 pkg.cflags.float_user: -DFLOAT_SUPPORT

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/json/src/test/test_json.c
----------------------------------------------------------------------
diff --git a/libs/json/src/test/test_json.c b/libs/json/src/test/test_json.c
deleted file mode 100644
index 80e9abe..0000000
--- a/libs/json/src/test/test_json.c
+++ /dev/null
@@ -1,41 +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 <testutil/testutil.h>
-#include <test_json.h>
-
-
-TEST_SUITE(test_json_suite) {
-    test_json_simple_encode();
-    test_json_simple_decode();
-}
-
-#ifdef MYNEWT_SELFTEST
-
-int
-main(int argc, char **argv)
-{
-    tu_config.tc_print_results = 1;
-    tu_init();
-
-    test_json_suite();
-
-    return tu_any_failed;
-}
-
-#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/json/src/test/test_json.h
----------------------------------------------------------------------
diff --git a/libs/json/src/test/test_json.h b/libs/json/src/test/test_json.h
deleted file mode 100644
index ea5efcf..0000000
--- a/libs/json/src/test/test_json.h
+++ /dev/null
@@ -1,27 +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.
- */
-
-#ifndef TEST_JSON_H
-#define TEST_JSON_H
-
-TEST_CASE_DECL(test_json_simple_encode);
-TEST_CASE_DECL(test_json_simple_decode);
-
-#endif /* TEST_JSON_H */
-

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/json/src/test/test_json_simple.c
----------------------------------------------------------------------
diff --git a/libs/json/src/test/test_json_simple.c 
b/libs/json/src/test/test_json_simple.c
deleted file mode 100644
index 55d50f4..0000000
--- a/libs/json/src/test/test_json_simple.c
+++ /dev/null
@@ -1,360 +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 <assert.h>
-#include <string.h>
-#include "testutil/testutil.h"
-#include "test_json.h"
-#include "json/json.h"
-
-static char *output = "{\"KeyBool\": true,\"KeyInt\": -1234,\"KeyUint\": 
1353214,\"KeyString\": \"foobar\",\"KeyStringN\": \"foobarlong\",\"KeyIntArr\": 
[153,2532,-322]}";
-
-static char *output1 ="{\"KeyBoolArr\": [true, false], \"KeyUintArr\": [0, 
65535, 4294967295, 8589934590, 3451257]}";
-static char *outputboolspace = "{\"KeyBoolArr\": [    true    ,    false,true  
       ]}";
-static char *outputboolempty = "{\"KeyBoolArr\": , \"KeyBoolArr\": [  ]}";
-
-static char bigbuf[512];
-static int buf_index;
-
-static int test_write(void *buf, char* data, int len) {
-    int i;
-    for(i = 0; i < len; i++) {
-        bigbuf[buf_index++] = data[i];
-    }
-    return len;
-}
-
-TEST_CASE(test_json_simple_encode){
-    struct json_encoder encoder;
-    struct json_value value;
-    int rc;
-
-    /* reset the state of the internal test */
-    buf_index = 0;
-    memset(&encoder, 0, sizeof(encoder));
-
-    encoder.je_write = test_write;
-    encoder.je_arg= NULL;
-
-    rc = json_encode_object_start(&encoder);
-    TEST_ASSERT(rc == 0);
-
-    JSON_VALUE_BOOL(&value, 1);
-    rc = json_encode_object_entry(&encoder, "KeyBool", &value);
-    TEST_ASSERT(rc == 0);
-
-    JSON_VALUE_INT(&value, -1234);
-    rc = json_encode_object_entry(&encoder, "KeyInt", &value);
-    TEST_ASSERT(rc == 0);
-
-    JSON_VALUE_UINT(&value, 1353214);
-    rc = json_encode_object_entry(&encoder, "KeyUint", &value);
-    TEST_ASSERT(rc == 0);
-
-    JSON_VALUE_STRING(&value, "foobar");
-    rc = json_encode_object_entry(&encoder, "KeyString", &value);
-    TEST_ASSERT(rc == 0);
-
-    /* we'll decode later differently */
-    JSON_VALUE_STRINGN(&value, "foobarlongstring", 10);
-    rc = json_encode_object_entry(&encoder, "KeyStringN", &value);
-    TEST_ASSERT(rc == 0);
-
-    rc = json_encode_array_name(&encoder, "KeyIntArr");
-    TEST_ASSERT(rc == 0);
-
-    rc = json_encode_array_start(&encoder);
-    TEST_ASSERT(rc == 0);
-
-    JSON_VALUE_INT(&value, 153);
-    rc = json_encode_array_value(&encoder, &value);
-    TEST_ASSERT(rc == 0);
-
-    JSON_VALUE_INT(&value, 2532);
-    rc = json_encode_array_value(&encoder, &value);
-    TEST_ASSERT(rc == 0);
-
-    JSON_VALUE_INT(&value, -322);
-    rc = json_encode_array_value(&encoder, &value);
-    TEST_ASSERT(rc == 0);
-
-    rc = json_encode_array_finish(&encoder);
-    TEST_ASSERT(rc == 0);
-
-    rc = json_encode_object_finish(&encoder);
-    TEST_ASSERT(rc == 0);
-
-    /* does it match what we expect it to */
-    rc = strcmp(bigbuf, output);
-    TEST_ASSERT(rc == 0);
-}
-
-
-/* a test structure to hold the json flat buffer and pass bytes
- * to the decoder */
-struct test_jbuf {
-    /* json_buffer must be first element in the structure */
-    struct json_buffer json_buf;
-    char * start_buf;
-    char * end_buf;
-    int current_position;
-};
-
-
-static char
-test_jbuf_read_next(struct json_buffer *jb) {
-    char c;
-    struct test_jbuf  *ptjb = (struct test_jbuf*) jb;
-
-    if((ptjb->start_buf + ptjb->current_position) <= ptjb->end_buf) {
-        c = *(ptjb->start_buf + ptjb->current_position);
-        ptjb->current_position++;
-        return c;
-    }
-    return '\0';
-}
-
-/* this goes backward in the buffer one character */
-static char
-test_jbuf_read_prev(struct json_buffer *jb) {
-    char c;
-    struct test_jbuf  *ptjb = (struct test_jbuf*) jb;
-    if(ptjb->current_position) {
-       ptjb->current_position--;
-       c = *(ptjb->start_buf + ptjb->current_position);
-       return c;
-    }
-
-    /* can't rewind */
-    return '\0';
-
-}
-
-static int
-test_jbuf_readn(struct json_buffer *jb, char *buf, int size) {
-    struct test_jbuf  *ptjb = (struct test_jbuf*) jb;
-
-    int remlen;
-
-    remlen = ptjb->end_buf - (ptjb->start_buf + ptjb->current_position);
-    if (size > remlen) {
-        size = remlen;
-    }
-
-    memcpy(buf, ptjb->start_buf + ptjb->current_position, size);
-    ptjb->current_position += size;
-    return size;
-}
-
-static void
-test_buf_init(struct test_jbuf *ptjb, char *string) {
-    /* initialize the decode */
-    ptjb->json_buf.jb_read_next = test_jbuf_read_next;
-    ptjb->json_buf.jb_read_prev = test_jbuf_read_prev;
-    ptjb->json_buf.jb_readn = test_jbuf_readn;
-    ptjb->start_buf = string;
-    ptjb->end_buf = string + strlen(string);
-    /* end buf points to the NULL */
-    ptjb->current_position = 0;
-}
-
-/* now test the decode on a string */
-TEST_CASE(test_json_simple_decode){
-    struct test_jbuf tjb;
-    struct test_jbuf tjb1;
-    struct test_jbuf tjbboolspacearr;
-    struct test_jbuf tjbboolemptyarr;
-    long long unsigned int uint_val;
-    long long int int_val;
-    bool bool_val;
-    char string1[16];
-    char string2[16];
-    long long int intarr[8];
-    int rc;
-    int rc1;
-    int rcbsa;
-    int array_count;
-    int array_countemp;
-    bool boolarr[2];
-    unsigned long long uintarr[5];
-    int array_count1;
-    int array_count1u;
-    bool boolspacearr[3];
-    bool boolemptyarr[2];
-    
-    struct json_attr_t test_attr[7] = {
-        [0] = {
-            .attribute = "KeyBool",
-            .type = t_boolean,
-            .addr.boolean = &bool_val,
-            .nodefault = true
-        },
-        [1] = {
-            .attribute = "KeyInt",
-            .type = t_integer,
-            .addr.integer = &int_val,
-            .nodefault = true
-            },
-        [2] = {
-            .attribute = "KeyUint",
-            .type = t_uinteger,
-            .addr.uinteger = &uint_val,
-            .nodefault = true
-            },
-        [3] = {
-            .attribute = "KeyString",
-            .type = t_string,
-            .addr.string = string1,
-            .nodefault = true,
-            .len = sizeof(string1)
-            },
-        [4] = {
-            .attribute = "KeyStringN",
-            .type = t_string,
-            .addr.string = string2,
-            .nodefault = true,
-            .len = sizeof(string2)
-        },
-        [5] = {
-            .attribute = "KeyIntArr",
-            .type = t_array,
-            .addr.array = {
-                .element_type = t_integer,
-                .arr.integers.store = intarr,
-                .maxlen = sizeof intarr / sizeof intarr[0],
-                .count = &array_count,
-            },
-            .nodefault = true,
-            .len = sizeof(intarr)
-        },
-        [6] = {
-            .attribute = NULL
-        }
-    };
-    
-    test_buf_init(&tjb, output);
-
-    rc = json_read_object(&tjb.json_buf, test_attr);
-    TEST_ASSERT(rc==0);
-    TEST_ASSERT(bool_val == 1);
-    TEST_ASSERT(int_val ==  -1234);
-    TEST_ASSERT(uint_val == 1353214);
-
-    rc = memcmp(string1, "foobar", strlen("foobar"));
-    TEST_ASSERT(rc==0);
-
-    rc = memcmp(string2, "foobarlongstring", 10);
-    TEST_ASSERT(rc==0);
-
-    TEST_ASSERT(array_count == 3);
-    TEST_ASSERT(intarr[0] == 153);
-    TEST_ASSERT(intarr[1] == 2532);
-    TEST_ASSERT(intarr[2] == -322);
-
-   /*testing for the boolean*/
-   struct json_attr_t test_attr1[2] = {
-       [0] = {
-           .attribute = "KeyBoolArr",
-           .type = t_array,
-           .addr.array = {
-               .element_type = t_boolean,
-               .arr.booleans.store = boolarr,
-               .maxlen = sizeof boolarr / sizeof boolarr[0],
-               .count =&array_count1,
-           },
-           .nodefault = true,
-           .len = sizeof( boolarr),
-       },
-
-       [1] = {
-           .attribute = "KeyUintArr",
-           .type = t_array,
-           .addr.array = {
-               .element_type = t_uinteger,
-               .arr.uintegers.store = uintarr,
-               .maxlen = sizeof uintarr / sizeof uintarr[0],
-               .count =&array_count1u,
-           },
-           .nodefault = true,
-           .len = sizeof( uintarr),
-       }
-   };
-   
-   test_buf_init(&tjb1, output1);
-
-   rc1 = json_read_object(&tjb1.json_buf, test_attr1);
-   TEST_ASSERT(rc1==0);
-
-   TEST_ASSERT(boolarr[0] == true);
-   TEST_ASSERT(boolarr[1] == false);
-
-   TEST_ASSERT(uintarr[0] == 0);
-   TEST_ASSERT(uintarr[1] == 65535);
-   TEST_ASSERT(uintarr[2] == 4294967295);
-   TEST_ASSERT(uintarr[3] == 8589934590);
-   TEST_ASSERT(uintarr[4] ==  3451257);
-
-    /*testing arrays with empty spaces within the elements*/
-    struct json_attr_t test_boolspacearr[2] = {
-       [0] = {    
-           .attribute = "KeyBoolArr",
-           .type = t_array,
-           .addr.array = {
-               .element_type = t_boolean,
-               .arr.booleans.store = boolspacearr,
-               .maxlen = sizeof boolspacearr / sizeof boolspacearr[0],
-               .count =&array_count1,
-           },
-           .nodefault = true,
-           .len = sizeof( boolspacearr),
-       }
-           
-    };
-    
-    test_buf_init(&tjbboolspacearr, outputboolspace);
-
-    rcbsa = json_read_object(&tjbboolspacearr.json_buf, test_boolspacearr);
-    TEST_ASSERT(rcbsa == 0);
-
-    TEST_ASSERT(boolspacearr[0] == true);
-    TEST_ASSERT(boolspacearr[1] == false);
-    TEST_ASSERT(boolspacearr[2] == true);
-
-    /*testing array with empty value*/
-    struct json_attr_t test_boolemptyarr[2] = {
-        [0] = {
-            .attribute = "KeyBoolArr",
-           .type = t_array,
-           .addr.array = {
-               .element_type = t_boolean,
-               .arr.booleans.store = boolemptyarr,
-               .maxlen = sizeof boolemptyarr / sizeof boolemptyarr[0],
-               .count =&array_countemp,
-           },
-           .nodefault = true,
-           .len = sizeof( boolemptyarr),
-        }
-    };
-   
-   test_buf_init(&tjbboolemptyarr, outputboolempty);
-
-    rcbsa = json_read_object(&tjbboolemptyarr.json_buf, test_boolemptyarr);
-    TEST_ASSERT(rcbsa == 6); 
-    
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/json/test/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/json/test/pkg.yml b/libs/json/test/pkg.yml
new file mode 100644
index 0000000..65f2de0
--- /dev/null
+++ b/libs/json/test/pkg.yml
@@ -0,0 +1,30 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+pkg.name: libs/json/test
+pkg.type: unittest
+pkg.description: "JSON unit tests."
+pkg.author: "Apache Mynewt <d...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/";
+pkg.keywords:
+
+pkg.deps: 
+    - libs/json
+    - libs/testutil
+
+pkg.deps.SELFTEST:
+    - libs/console/stub

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/json/test/src/test_json.c
----------------------------------------------------------------------
diff --git a/libs/json/test/src/test_json.c b/libs/json/test/src/test_json.c
new file mode 100644
index 0000000..dab3f06
--- /dev/null
+++ b/libs/json/test/src/test_json.c
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "syscfg/syscfg.h"
+#include "testutil/testutil.h"
+#include "test_json.h"
+
+
+TEST_SUITE(test_json_suite) {
+    test_json_simple_encode();
+    test_json_simple_decode();
+}
+
+#if MYNEWT_VAL(SELFTEST)
+
+int
+main(int argc, char **argv)
+{
+    tu_config.tc_print_results = 1;
+    tu_init();
+
+    test_json_suite();
+
+    return tu_any_failed;
+}
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/json/test/src/test_json.h
----------------------------------------------------------------------
diff --git a/libs/json/test/src/test_json.h b/libs/json/test/src/test_json.h
new file mode 100644
index 0000000..ea5efcf
--- /dev/null
+++ b/libs/json/test/src/test_json.h
@@ -0,0 +1,27 @@
+/**
+ * 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 TEST_JSON_H
+#define TEST_JSON_H
+
+TEST_CASE_DECL(test_json_simple_encode);
+TEST_CASE_DECL(test_json_simple_decode);
+
+#endif /* TEST_JSON_H */
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/json/test/src/test_json_simple.c
----------------------------------------------------------------------
diff --git a/libs/json/test/src/test_json_simple.c 
b/libs/json/test/src/test_json_simple.c
new file mode 100644
index 0000000..55d50f4
--- /dev/null
+++ b/libs/json/test/src/test_json_simple.c
@@ -0,0 +1,360 @@
+/**
+ * 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 <assert.h>
+#include <string.h>
+#include "testutil/testutil.h"
+#include "test_json.h"
+#include "json/json.h"
+
+static char *output = "{\"KeyBool\": true,\"KeyInt\": -1234,\"KeyUint\": 
1353214,\"KeyString\": \"foobar\",\"KeyStringN\": \"foobarlong\",\"KeyIntArr\": 
[153,2532,-322]}";
+
+static char *output1 ="{\"KeyBoolArr\": [true, false], \"KeyUintArr\": [0, 
65535, 4294967295, 8589934590, 3451257]}";
+static char *outputboolspace = "{\"KeyBoolArr\": [    true    ,    false,true  
       ]}";
+static char *outputboolempty = "{\"KeyBoolArr\": , \"KeyBoolArr\": [  ]}";
+
+static char bigbuf[512];
+static int buf_index;
+
+static int test_write(void *buf, char* data, int len) {
+    int i;
+    for(i = 0; i < len; i++) {
+        bigbuf[buf_index++] = data[i];
+    }
+    return len;
+}
+
+TEST_CASE(test_json_simple_encode){
+    struct json_encoder encoder;
+    struct json_value value;
+    int rc;
+
+    /* reset the state of the internal test */
+    buf_index = 0;
+    memset(&encoder, 0, sizeof(encoder));
+
+    encoder.je_write = test_write;
+    encoder.je_arg= NULL;
+
+    rc = json_encode_object_start(&encoder);
+    TEST_ASSERT(rc == 0);
+
+    JSON_VALUE_BOOL(&value, 1);
+    rc = json_encode_object_entry(&encoder, "KeyBool", &value);
+    TEST_ASSERT(rc == 0);
+
+    JSON_VALUE_INT(&value, -1234);
+    rc = json_encode_object_entry(&encoder, "KeyInt", &value);
+    TEST_ASSERT(rc == 0);
+
+    JSON_VALUE_UINT(&value, 1353214);
+    rc = json_encode_object_entry(&encoder, "KeyUint", &value);
+    TEST_ASSERT(rc == 0);
+
+    JSON_VALUE_STRING(&value, "foobar");
+    rc = json_encode_object_entry(&encoder, "KeyString", &value);
+    TEST_ASSERT(rc == 0);
+
+    /* we'll decode later differently */
+    JSON_VALUE_STRINGN(&value, "foobarlongstring", 10);
+    rc = json_encode_object_entry(&encoder, "KeyStringN", &value);
+    TEST_ASSERT(rc == 0);
+
+    rc = json_encode_array_name(&encoder, "KeyIntArr");
+    TEST_ASSERT(rc == 0);
+
+    rc = json_encode_array_start(&encoder);
+    TEST_ASSERT(rc == 0);
+
+    JSON_VALUE_INT(&value, 153);
+    rc = json_encode_array_value(&encoder, &value);
+    TEST_ASSERT(rc == 0);
+
+    JSON_VALUE_INT(&value, 2532);
+    rc = json_encode_array_value(&encoder, &value);
+    TEST_ASSERT(rc == 0);
+
+    JSON_VALUE_INT(&value, -322);
+    rc = json_encode_array_value(&encoder, &value);
+    TEST_ASSERT(rc == 0);
+
+    rc = json_encode_array_finish(&encoder);
+    TEST_ASSERT(rc == 0);
+
+    rc = json_encode_object_finish(&encoder);
+    TEST_ASSERT(rc == 0);
+
+    /* does it match what we expect it to */
+    rc = strcmp(bigbuf, output);
+    TEST_ASSERT(rc == 0);
+}
+
+
+/* a test structure to hold the json flat buffer and pass bytes
+ * to the decoder */
+struct test_jbuf {
+    /* json_buffer must be first element in the structure */
+    struct json_buffer json_buf;
+    char * start_buf;
+    char * end_buf;
+    int current_position;
+};
+
+
+static char
+test_jbuf_read_next(struct json_buffer *jb) {
+    char c;
+    struct test_jbuf  *ptjb = (struct test_jbuf*) jb;
+
+    if((ptjb->start_buf + ptjb->current_position) <= ptjb->end_buf) {
+        c = *(ptjb->start_buf + ptjb->current_position);
+        ptjb->current_position++;
+        return c;
+    }
+    return '\0';
+}
+
+/* this goes backward in the buffer one character */
+static char
+test_jbuf_read_prev(struct json_buffer *jb) {
+    char c;
+    struct test_jbuf  *ptjb = (struct test_jbuf*) jb;
+    if(ptjb->current_position) {
+       ptjb->current_position--;
+       c = *(ptjb->start_buf + ptjb->current_position);
+       return c;
+    }
+
+    /* can't rewind */
+    return '\0';
+
+}
+
+static int
+test_jbuf_readn(struct json_buffer *jb, char *buf, int size) {
+    struct test_jbuf  *ptjb = (struct test_jbuf*) jb;
+
+    int remlen;
+
+    remlen = ptjb->end_buf - (ptjb->start_buf + ptjb->current_position);
+    if (size > remlen) {
+        size = remlen;
+    }
+
+    memcpy(buf, ptjb->start_buf + ptjb->current_position, size);
+    ptjb->current_position += size;
+    return size;
+}
+
+static void
+test_buf_init(struct test_jbuf *ptjb, char *string) {
+    /* initialize the decode */
+    ptjb->json_buf.jb_read_next = test_jbuf_read_next;
+    ptjb->json_buf.jb_read_prev = test_jbuf_read_prev;
+    ptjb->json_buf.jb_readn = test_jbuf_readn;
+    ptjb->start_buf = string;
+    ptjb->end_buf = string + strlen(string);
+    /* end buf points to the NULL */
+    ptjb->current_position = 0;
+}
+
+/* now test the decode on a string */
+TEST_CASE(test_json_simple_decode){
+    struct test_jbuf tjb;
+    struct test_jbuf tjb1;
+    struct test_jbuf tjbboolspacearr;
+    struct test_jbuf tjbboolemptyarr;
+    long long unsigned int uint_val;
+    long long int int_val;
+    bool bool_val;
+    char string1[16];
+    char string2[16];
+    long long int intarr[8];
+    int rc;
+    int rc1;
+    int rcbsa;
+    int array_count;
+    int array_countemp;
+    bool boolarr[2];
+    unsigned long long uintarr[5];
+    int array_count1;
+    int array_count1u;
+    bool boolspacearr[3];
+    bool boolemptyarr[2];
+    
+    struct json_attr_t test_attr[7] = {
+        [0] = {
+            .attribute = "KeyBool",
+            .type = t_boolean,
+            .addr.boolean = &bool_val,
+            .nodefault = true
+        },
+        [1] = {
+            .attribute = "KeyInt",
+            .type = t_integer,
+            .addr.integer = &int_val,
+            .nodefault = true
+            },
+        [2] = {
+            .attribute = "KeyUint",
+            .type = t_uinteger,
+            .addr.uinteger = &uint_val,
+            .nodefault = true
+            },
+        [3] = {
+            .attribute = "KeyString",
+            .type = t_string,
+            .addr.string = string1,
+            .nodefault = true,
+            .len = sizeof(string1)
+            },
+        [4] = {
+            .attribute = "KeyStringN",
+            .type = t_string,
+            .addr.string = string2,
+            .nodefault = true,
+            .len = sizeof(string2)
+        },
+        [5] = {
+            .attribute = "KeyIntArr",
+            .type = t_array,
+            .addr.array = {
+                .element_type = t_integer,
+                .arr.integers.store = intarr,
+                .maxlen = sizeof intarr / sizeof intarr[0],
+                .count = &array_count,
+            },
+            .nodefault = true,
+            .len = sizeof(intarr)
+        },
+        [6] = {
+            .attribute = NULL
+        }
+    };
+    
+    test_buf_init(&tjb, output);
+
+    rc = json_read_object(&tjb.json_buf, test_attr);
+    TEST_ASSERT(rc==0);
+    TEST_ASSERT(bool_val == 1);
+    TEST_ASSERT(int_val ==  -1234);
+    TEST_ASSERT(uint_val == 1353214);
+
+    rc = memcmp(string1, "foobar", strlen("foobar"));
+    TEST_ASSERT(rc==0);
+
+    rc = memcmp(string2, "foobarlongstring", 10);
+    TEST_ASSERT(rc==0);
+
+    TEST_ASSERT(array_count == 3);
+    TEST_ASSERT(intarr[0] == 153);
+    TEST_ASSERT(intarr[1] == 2532);
+    TEST_ASSERT(intarr[2] == -322);
+
+   /*testing for the boolean*/
+   struct json_attr_t test_attr1[2] = {
+       [0] = {
+           .attribute = "KeyBoolArr",
+           .type = t_array,
+           .addr.array = {
+               .element_type = t_boolean,
+               .arr.booleans.store = boolarr,
+               .maxlen = sizeof boolarr / sizeof boolarr[0],
+               .count =&array_count1,
+           },
+           .nodefault = true,
+           .len = sizeof( boolarr),
+       },
+
+       [1] = {
+           .attribute = "KeyUintArr",
+           .type = t_array,
+           .addr.array = {
+               .element_type = t_uinteger,
+               .arr.uintegers.store = uintarr,
+               .maxlen = sizeof uintarr / sizeof uintarr[0],
+               .count =&array_count1u,
+           },
+           .nodefault = true,
+           .len = sizeof( uintarr),
+       }
+   };
+   
+   test_buf_init(&tjb1, output1);
+
+   rc1 = json_read_object(&tjb1.json_buf, test_attr1);
+   TEST_ASSERT(rc1==0);
+
+   TEST_ASSERT(boolarr[0] == true);
+   TEST_ASSERT(boolarr[1] == false);
+
+   TEST_ASSERT(uintarr[0] == 0);
+   TEST_ASSERT(uintarr[1] == 65535);
+   TEST_ASSERT(uintarr[2] == 4294967295);
+   TEST_ASSERT(uintarr[3] == 8589934590);
+   TEST_ASSERT(uintarr[4] ==  3451257);
+
+    /*testing arrays with empty spaces within the elements*/
+    struct json_attr_t test_boolspacearr[2] = {
+       [0] = {    
+           .attribute = "KeyBoolArr",
+           .type = t_array,
+           .addr.array = {
+               .element_type = t_boolean,
+               .arr.booleans.store = boolspacearr,
+               .maxlen = sizeof boolspacearr / sizeof boolspacearr[0],
+               .count =&array_count1,
+           },
+           .nodefault = true,
+           .len = sizeof( boolspacearr),
+       }
+           
+    };
+    
+    test_buf_init(&tjbboolspacearr, outputboolspace);
+
+    rcbsa = json_read_object(&tjbboolspacearr.json_buf, test_boolspacearr);
+    TEST_ASSERT(rcbsa == 0);
+
+    TEST_ASSERT(boolspacearr[0] == true);
+    TEST_ASSERT(boolspacearr[1] == false);
+    TEST_ASSERT(boolspacearr[2] == true);
+
+    /*testing array with empty value*/
+    struct json_attr_t test_boolemptyarr[2] = {
+        [0] = {
+            .attribute = "KeyBoolArr",
+           .type = t_array,
+           .addr.array = {
+               .element_type = t_boolean,
+               .arr.booleans.store = boolemptyarr,
+               .maxlen = sizeof boolemptyarr / sizeof boolemptyarr[0],
+               .count =&array_countemp,
+           },
+           .nodefault = true,
+           .len = sizeof( boolemptyarr),
+        }
+    };
+   
+   test_buf_init(&tjbboolemptyarr, outputboolempty);
+
+    rcbsa = json_read_object(&tjbboolemptyarr.json_buf, test_boolemptyarr);
+    TEST_ASSERT(rcbsa == 6); 
+    
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/mbedtls/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/mbedtls/pkg.yml b/libs/mbedtls/pkg.yml
index 6d364b6..76a1a7c 100644
--- a/libs/mbedtls/pkg.yml
+++ b/libs/mbedtls/pkg.yml
@@ -25,7 +25,5 @@ pkg.keywords:
     - ssl
     - tls
 
-pkg.cflags: -DMBEDTLS_USER_CONFIG_FILE=\"mbedtls/config_mynewt.h\"
-pkg.deps:
-    - libs/testutil
+pkg.cflags: '-DMBEDTLS_USER_CONFIG_FILE=\"mbedtls/config_mynewt.h\"'
 pkg.cflags.TEST: -DTEST

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/mbedtls/src/test/mbedtls_test.c
----------------------------------------------------------------------
diff --git a/libs/mbedtls/src/test/mbedtls_test.c 
b/libs/mbedtls/src/test/mbedtls_test.c
deleted file mode 100644
index dee9040..0000000
--- a/libs/mbedtls/src/test/mbedtls_test.c
+++ /dev/null
@@ -1,228 +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 <stdio.h>
-#include <string.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();
-}
-
-#ifdef MYNEWT_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/mbedtls/test/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/mbedtls/test/pkg.yml b/libs/mbedtls/test/pkg.yml
new file mode 100644
index 0000000..fd318eb
--- /dev/null
+++ b/libs/mbedtls/test/pkg.yml
@@ -0,0 +1,30 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+pkg.name: libs/mbedtls/test
+pkg.type: unittest
+pkg.description: "mbedtls unit tests."
+pkg.author: "Apache Mynewt <d...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/";
+pkg.keywords:
+
+pkg.deps: 
+    - libs/mbedtls
+    - libs/testutil
+
+pkg.deps.SELFTEST:
+    - libs/console/stub

Reply via email to