mynewt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vipulrah...@apache.org
Subject [22/50] [abbrv] incubator-mynewt-core git commit: Merge branch 'develop' into sterly_refactor
Date Mon, 10 Oct 2016 19:26:38 GMT
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c5901fcc/libs/bootutil/test/src/boot_test.c
----------------------------------------------------------------------
diff --cc libs/bootutil/test/src/boot_test.c
index b86ca82,0000000..94c8554
mode 100644,000000..100644
--- a/libs/bootutil/test/src/boot_test.c
+++ b/libs/bootutil/test/src/boot_test.c
@@@ -1,1170 -1,0 +1,1203 @@@
 +/**
 + * 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 },
++    [7] = { 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) {
++#if 0
 +                TEST_ASSERT(buf[i] == 0xff);
++#endif
 +            }
 +        }
 +
 +        addr += chunk_sz;
 +    }
 +}
 +
 +static void
 +boot_test_util_verify_status_clear(void)
 +{
-     struct fs_file *file;
++    struct boot_img_trailer bit;
++    const struct flash_area *fap;
 +    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);
++    rc = flash_area_open(FLASH_AREA_IMAGE_0, &fap);
 +    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 = flash_area_read(fap, fap->fa_size - sizeof(bit), &bit, sizeof(bit));
++    TEST_ASSERT(rc == 0);
 +
-     rc = fs_open(BOOT_PATH_STATUS, FS_ACCESS_READ, &file);
-     TEST_ASSERT(rc == FS_ENOENT);
++    TEST_ASSERT(bit.bit_copy_start != BOOT_IMG_MAGIC ||
++      bit.bit_copy_done != 0xff);
 +}
 +
 +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,
++        .br_img_sz = (384 * 1024),
 +    };
 +
 +    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,
++        .br_img_sz = (384 * 1024),
 +    };
 +
 +    boot_test_util_init_flash();
 +    boot_test_util_write_image(&hdr, 1);
 +    boot_test_util_write_hash(&hdr, 1);
 +
++    boot_vect_write_test(FLASH_AREA_IMAGE_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,
++        .br_img_sz = (384 * 1024),
 +    };
 +
 +    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,
++        .br_img_sz = (384 * 1024),
 +    };
 +
 +    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,
++        .br_img_sz = (384 * 1024),
 +    };
 +
 +    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);
++    rc = boot_vect_write_test(FLASH_AREA_IMAGE_1);
 +    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,
++        .br_img_sz = (384 * 1024),
 +    };
 +
 +    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,
++        .br_img_sz = (384 * 1024),
 +    };
 +
 +    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);
++    rc = boot_vect_write_test(FLASH_AREA_IMAGE_1);
 +    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,
++        .br_img_sz = (384 * 1024),
 +    };
 +
 +    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);
++    rc = boot_vect_write_test(FLASH_AREA_IMAGE_1);
 +    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,
++        .br_img_sz = (384 * 1024),
 +    };
 +
 +    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);
- 
++#if 0
 +    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();
- 
++#else
++    (void)status;
++#endif
 +    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,
++        .br_img_sz = (384 * 1024),
 +    };
 +
 +    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],
++    rc = boot_vect_write_test(FLASH_AREA_IMAGE_1);
++    boot_test_util_copy_area(5,
 +      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;
-     }
++    boot_req_set(&req);
++    status.idx = 0;
++    status.elem_sz = 1;
 +    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,
++        .br_img_sz = (384 * 1024),
 +    };
 +
 +    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]);
++    rc = boot_vect_write_test(FLASH_AREA_IMAGE_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;
++    boot_test_util_swap_areas(2, 5);
++
++    status.idx = 1;
++    status.elem_sz = 1;
++    status.state = 0;
 +
 +    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)
 +{
++    const struct flash_area *fap;
++    struct boot_img_trailer bit;
 +    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,
++        .br_img_sz = (384 * 1024),
 +    };
 +
 +    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_image(&hdr1, 1);
 +    boot_test_util_write_hash(&hdr1, 1);
 +
-     rc = boot_vect_write_main(&hdr0.ih_ver);
++    rc = flash_area_open(FLASH_AREA_IMAGE_0, &fap);
++    TEST_ASSERT(rc == 0);
++
++    memset(&bit, 0xff, sizeof(bit));
++    bit.bit_copy_start = BOOT_IMG_MAGIC;
++    bit.bit_copy_done = 0;
++    bit.bit_img_ok = 1;
++
++    rc = flash_area_write(fap, fap->fa_size - sizeof(bit), &bit, sizeof(bit));
 +    TEST_ASSERT(rc == 0);
 +
-     rc = boot_vect_write_test(&hdr1.ih_ver);
++    rc = boot_vect_write_test(FLASH_AREA_IMAGE_1);
 +    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();
++        boot_vect_write_main();
 +    }
 +}
 +
 +TEST_CASE(boot_test_no_hash)
 +{
 +    struct boot_rsp rsp;
 +    int rc;
 +
-     struct image_header hdr = {
++    struct image_header hdr0 = {
 +        .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 0,
++        .ih_tlv_size = 4 + 32,
 +        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
 +        .ih_img_size = 12 * 1024,
-         .ih_flags = 0,
++        .ih_flags = IMAGE_F_SHA256,
 +        .ih_ver = { 0, 2, 3, 4 },
 +    };
++    struct image_header hdr1 = {
++        .ih_magic = IMAGE_MAGIC,
++        .ih_tlv_size = 0,
++        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
++        .ih_img_size = 32 * 1024,
++        .ih_flags = 0,
++        .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,
++        .br_img_sz = (384 * 1024),
 +    };
 +
 +    boot_test_util_init_flash();
-     boot_test_util_write_image(&hdr, 0);
++    boot_test_util_write_image(&hdr0, 0);
++    boot_test_util_write_hash(&hdr0, 0);
++    boot_test_util_write_image(&hdr1, 1);
++
++    rc = boot_vect_write_test(FLASH_AREA_IMAGE_1);
++    TEST_ASSERT(rc == 0);
 +
 +    rc = boot_go(&req, &rsp);
-     TEST_ASSERT(rc != 0);
++    TEST_ASSERT(rc == 0);
 +
-     boot_test_util_verify_flash(&hdr, 0, NULL, 0xff);
++    TEST_ASSERT(memcmp(rsp.br_hdr, &hdr0, sizeof hdr0) == 0);
++
++    boot_test_util_verify_flash(&hdr0, 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 = {
++    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 = 0,
++        .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 = 32 * 1024,
++        .ih_flags = 0,
++        .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,
++        .br_img_sz = (384 * 1024),
 +    };
 +
 +    boot_test_util_init_flash();
-     boot_test_util_write_image(&hdr, 0);
-     boot_test_util_write_hash(&hdr, 0);
++    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_test(FLASH_AREA_IMAGE_1);
++    TEST_ASSERT(rc == 0);
 +
 +    rc = boot_go(&req, &rsp);
-     TEST_ASSERT(rc != 0);
++    TEST_ASSERT(rc == 0);
 +
-     boot_test_util_verify_flash(&hdr, 0, NULL, 0xff);
++    TEST_ASSERT(memcmp(rsp.br_hdr, &hdr0, sizeof hdr0) == 0);
++
++    boot_test_util_verify_flash(&hdr0, 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 = {
++    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 = 32 * 1024,
++        .ih_flags = 0,
++        .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,
++        .br_img_sz = (384 * 1024),
 +    };
 +
 +    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,
++    boot_test_util_write_image(&hdr0, 0);
++    boot_test_util_write_hash(&hdr0, 0);
++    boot_test_util_write_image(&hdr1, 1);
++    rc = hal_flash_write(boot_test_img_addrs[1].flash_id,
++      boot_test_img_addrs[1].address + hdr1.ih_hdr_size + hdr1.ih_img_size,
 +      &tlv, sizeof(tlv));
 +    TEST_ASSERT(rc == 0);
 +
++    rc = boot_vect_write_test(FLASH_AREA_IMAGE_1);
++    TEST_ASSERT(rc == 0);
++
 +    rc = boot_go(&req, &rsp);
-     TEST_ASSERT(rc != 0);
++    TEST_ASSERT(rc == 0);
 +
-     boot_test_util_verify_flash(&hdr, 0, NULL, 0xff);
++    TEST_ASSERT(memcmp(rsp.br_hdr, &hdr0, sizeof hdr0) == 0);
++
++    boot_test_util_verify_flash(&hdr0, 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)
++main(int argc, char **argv)
 +{
 +    tu_config.tc_print_results = 1;
++    tu_parse_args(argc, argv);
++
 +    tu_init();
 +
 +    boot_test_all();
 +
 +    return tu_any_failed;
 +}
 +
 +#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c5901fcc/libs/console/full/src/cons_tty.c
----------------------------------------------------------------------
diff --cc libs/console/full/src/cons_tty.c
index 49dfefc,83bc843..db8c88e
--- a/libs/console/full/src/cons_tty.c
+++ b/libs/console/full/src/cons_tty.c
@@@ -18,13 -18,15 +18,15 @@@
   */
  
  #include <inttypes.h>
 +#include <assert.h>
 +#include "sysinit/sysinit.h"
  #include "os/os.h"
 -#include "hal/hal_uart.h"
 +#include "uart/uart.h"
  #include "bsp/bsp.h"
+ 
  #include "console/console.h"
+ #include "console/prompt.h"
  
 -int g_console_is_init;
 -
  /** Indicates whether the previous line of output was completed. */
  int console_is_midline;
  
@@@ -376,40 -374,28 +379,42 @@@ in
  console_init(console_rx_cb rx_cb)
  {
      struct console_tty *ct = &console_tty;
 -    int rc;
 +    struct uart_conf uc = {
 +        .uc_speed = CONSOLE_UART_SPEED,
 +        .uc_databits = 8,
 +        .uc_stopbits = 1,
 +        .uc_parity = UART_PARITY_NONE,
 +        .uc_flow_ctl = UART_FLOW_CTL_NONE,
 +        .uc_tx_char = console_tx_char,
 +        .uc_rx_char = console_rx_char,
 +        .uc_cb_arg = ct
 +    };
  
 -    rc = hal_uart_init_cbs(CONSOLE_UART, console_tx_char, NULL,
 -            console_rx_char, ct);
 -    if (rc) {
 -        return rc;
 -    }
 -    ct->ct_tx.cr_size = CONSOLE_TX_BUF_SZ;
 -    ct->ct_tx.cr_buf = ct->ct_tx_buf;
 -    ct->ct_rx.cr_size = CONSOLE_RX_BUF_SZ;
 -    ct->ct_rx.cr_buf = ct->ct_rx_buf;
      ct->ct_rx_cb = rx_cb;
 -    ct->ct_write_char = console_queue_char;
 -
 -    rc = hal_uart_config(CONSOLE_UART, 115200, 8, 1, HAL_UART_PARITY_NONE,
 -      HAL_UART_FLOW_CTL_NONE);
 -    if (rc) {
 -        return rc;
 +    if (!ct->ct_dev) {
 +        ct->ct_tx.cr_size = CONSOLE_TX_BUF_SZ;
 +        ct->ct_tx.cr_buf = ct->ct_tx_buf;
 +        ct->ct_rx.cr_size = CONSOLE_RX_BUF_SZ;
 +        ct->ct_rx.cr_buf = ct->ct_rx_buf;
 +        ct->ct_write_char = console_queue_char;
 +
 +        ct->ct_dev = (struct uart_dev *)os_dev_open(CONSOLE_UART,
 +          OS_TIMEOUT_NEVER, &uc);
 +        if (!ct->ct_dev) {
 +            return -1;
 +        }
      }
  
 -    g_console_is_init = 1;
+     console_print_prompt();
+     
      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/c5901fcc/libs/imgmgr/include/imgmgr/imgmgr.h
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c5901fcc/libs/imgmgr/pkg.yml
----------------------------------------------------------------------
diff --cc libs/imgmgr/pkg.yml
index ff7812e,dc214c1..5194768
--- a/libs/imgmgr/pkg.yml
+++ b/libs/imgmgr/pkg.yml
@@@ -24,23 -24,18 +24,28 @@@ pkg.homepage: "http://mynewt.apache.org
  pkg.keywords:
  
  pkg.deps:
-     - libs/newtmgr
      - libs/bootutil
      - libs/util
 -pkg.deps.FS:
 +
 +pkg.deps.IMGMGR_FS:
      - fs/fs
 -pkg.cflags.FS: -DFS_PRESENT
 -pkg.req_apis:
 -    - newtmgr
  
 -pkg.deps.COREDUMP:
 +pkg.deps.IMGMGR_COREDUMP:
      - sys/coredump
 -pkg.cflags.COREDUMP: -DCOREDUMP_PRESENT
  
 -pkg.deps.SHELL:
++pkg.deps.IMGMGR_SHELL:
+     - libs/shell
 -pkg.cflags.SHELL: -DSHELL_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'
++    IMGMGR_CLI:
++        description: 'TBD'
++        value: 'MYNEWT_PKG_LIBS_SHELL'

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c5901fcc/libs/imgmgr/src/imgmgr.c
----------------------------------------------------------------------
diff --cc libs/imgmgr/src/imgmgr.c
index 0cb7bc4,9a9b884..d204cc4
--- a/libs/imgmgr/src/imgmgr.c
+++ b/libs/imgmgr/src/imgmgr.c
@@@ -21,14 -21,14 +21,13 @@@
  #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 <bootutil/bootutil_misc.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"
@@@ -48,11 -47,11 +46,11 @@@ static const struct nmgr_handler imgr_n
          .nh_write = imgr_upload
      },
      [IMGMGR_NMGR_OP_BOOT] = {
-         .nh_read = imgr_boot_read,
-         .nh_write = imgr_boot_write
+         .nh_read = imgr_noop,
+         .nh_write = imgr_noop
      },
      [IMGMGR_NMGR_OP_FILE] = {
 -#ifdef FS_PRESENT
 +#if MYNEWT_VAL(IMGMGR_FS)
          .nh_read = imgr_file_download,
          .nh_write = imgr_file_upload
  #else
@@@ -494,5 -461,14 +460,12 @@@ imgmgr_module_init(void
      int rc;
  
      rc = nmgr_group_register(&imgr_nmgr_group);
 -    assert(rc == 0);
 +    SYSINIT_PANIC_ASSERT(rc == 0);
+ 
 -#ifdef SHELL_PRESENT
++#if MYNEWT_VAL(IMGMGR_CLI)
+     rc = imgr_cli_register();
 -    assert(rc == 0);
++    SYSINIT_PANIC_ASSERT(rc == 0);
+ #endif
+ 
+     boot_vect_write_main();
 -
 -    return rc;
  }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c5901fcc/libs/imgmgr/src/imgmgr_priv.h
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c5901fcc/libs/json/test/src/test_json_simple.c
----------------------------------------------------------------------
diff --cc libs/json/test/src/test_json_simple.c
index 55d50f4,0000000..0f9e10e
mode 100644,000000..100644
--- a/libs/json/test/src/test_json_simple.c
+++ b/libs/json/test/src/test_json_simple.c
@@@ -1,360 -1,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);
++   TEST_ASSERT(uintarr[2] == 4294967295ULL);
++   TEST_ASSERT(uintarr[3] == 8589934590ULL);
++   TEST_ASSERT(uintarr[4] == 3451257ULL);
 +
 +    /*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/c5901fcc/libs/newtmgr/include/newtmgr/newtmgr.h
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c5901fcc/libs/newtmgr/pkg.yml
----------------------------------------------------------------------
diff --cc libs/newtmgr/pkg.yml
index 2dbdb71,93fbae7..0afb997
--- a/libs/newtmgr/pkg.yml
+++ b/libs/newtmgr/pkg.yml
@@@ -27,24 -27,17 +27,28 @@@ pkg.deps
      - hw/hal
      - libs/os
      - libs/json
+     - libs/newtmgr/nmgr_os
      - libs/util
 -    - libs/testutil
      - libs/shell
      - sys/reboot
  
  pkg.deps.BLE_HOST:
      - libs/newtmgr/transport/ble
  
+ pkg.apis:
+     - newtmgr
+ 
 -pkg.features:
 -    - NEWTMGR
 +pkg.init_function: nmgr_pkg_init
 +pkg.init_stage: 5
 +
 +pkg.syscfg_defs:
 +    NEWTMGR_TASK_PRIO:
 +        description: 'TBD'
 +        type: 'task_priority'
 +        value: 'any'
 +    NEWTMGR_STACK_SIZE:
 +        description: 'TBD'
 +        value: 512
 +    NEWTMGR_BLE_HOST:
 +        description: 'TBD'
 +        value: 'MYNEWT_PKG_NET_NIMBLE_HOST'

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c5901fcc/libs/newtmgr/src/newtmgr.c
----------------------------------------------------------------------
diff --cc libs/newtmgr/src/newtmgr.c
index 9b0d696,8ff2ea3..3697ae7
--- a/libs/newtmgr/src/newtmgr.c
+++ b/libs/newtmgr/src/newtmgr.c
@@@ -20,18 -20,12 +20,16 @@@
  #include <assert.h>
  #include <string.h>
  
 -#include <shell/shell.h>
 -#include <newtmgr/newtmgr.h>
 -#include <nmgr_os/nmgr_os.h>
 +#include "syscfg/syscfg.h"
 +#include "sysinit/sysinit.h"
 +#include "os/os.h"
 +#include "os/endian.h"
 +
 +#include "shell/shell.h"
- #include "console/console.h"
 +#include "newtmgr/newtmgr.h"
- 
- #include "newtmgr_priv.h"
++#include "nmgr_os/nmgr_os.h"
 +
 +os_stack_t newtmgr_stack[OS_STACK_ALIGN(MYNEWT_VAL(NEWTMGR_STACK_SIZE))];
  
  struct nmgr_transport g_nmgr_shell_transport;
  
@@@ -606,29 -526,8 +530,8 @@@ err
  }
  
  
- static int
- nmgr_default_groups_register(void)
- {
-     int rc;
- 
-     NMGR_GROUP_SET_HANDLERS(&nmgr_def_group,
-       (struct nmgr_handler *)nmgr_def_group_handlers);
-     nmgr_def_group.ng_group_id = NMGR_GROUP_ID_DEFAULT;
-     nmgr_def_group.ng_handlers_count =
-       sizeof(nmgr_def_group_handlers) / sizeof(nmgr_def_group_handlers[0]);
- 
-     rc = nmgr_group_register(&nmgr_def_group);
-     if (rc != 0) {
-         goto err;
-     }
- 
-     return (0);
- err:
-     return (rc);
- }
- 
  int
 -nmgr_task_init(uint8_t prio, os_stack_t *stack_ptr, uint16_t stack_len)
 +nmgr_task_init(void)
  {
      int rc;
  

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c5901fcc/libs/os/test/src/eventq_test.c
----------------------------------------------------------------------
diff --cc libs/os/test/src/eventq_test.c
index cb1ed94,0000000..3fceb0e
mode 100644,000000..100644
--- a/libs/os/test/src/eventq_test.c
+++ b/libs/os/test/src/eventq_test.c
@@@ -1,416 -1,0 +1,416 @@@
 +/**
 + * 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 <string.h>
 +#include "testutil/testutil.h"
 +#include "os/os.h"
 +#include "os_test_priv.h"
 +#include "os/os_eventq.h"
 +
 +#define MY_STACK_SIZE        (5120)
 +#define POLL_STACK_SIZE        (4096)
 +/* Task 1 sending task */
 +/* Define task stack and task object */
 +#define SEND_TASK_PRIO        (1)
 +struct os_task eventq_task_s;
 +os_stack_t eventq_task_stack_s[MY_STACK_SIZE];
 +
 +/* Task 2 receiving task */
 +#define RECEIVE_TASK_PRIO     (2)
 +struct os_task eventq_task_r;
 +os_stack_t eventq_task_stack_r[MY_STACK_SIZE];
 +
 +struct os_eventq my_eventq;
 +
 +#define SIZE_MULTI_EVENT        (4)
 +struct os_eventq multi_eventq[SIZE_MULTI_EVENT];
 +
 +/* This is to set the events we will use below */
 +struct os_event g_event;
 +struct os_event m_event[SIZE_MULTI_EVENT];
 +
 +/* Setting the event to send and receive multiple data */
 +uint8_t my_event_type = 1;
 +
 +/* Setting up data for the poll */
 +/* Define the task stack for the eventq_task_poll_send */
 +#define SEND_TASK_POLL_PRIO        (3)
 +struct os_task eventq_task_poll_s;
 +os_stack_t eventq_task_stack_poll_s[POLL_STACK_SIZE];
 +
 +/* Define the task stack for the eventq_task_poll_receive */
 +#define RECEIVE_TASK_POLL_PRIO     (4)
 +struct os_task eventq_task_poll_r;
 +os_stack_t eventq_task_stack_poll_r[POLL_STACK_SIZE ];
 +
 +/* Setting the data for the poll timeout */
 +/* Define the task stack for the eventq_task_poll_timeout_send */
 +#define SEND_TASK_POLL_TIMEOUT_PRIO        (5)
 +struct os_task eventq_task_poll_timeout_s;
 +os_stack_t eventq_task_stack_poll_timeout_s[POLL_STACK_SIZE];
 +
 +/* Define the task stack for the eventq_task_poll_receive */
 +#define RECEIVE_TASK_POLL_TIMEOUT_PRIO     (6)
 +struct os_task eventq_task_poll_timeout_r;
 +os_stack_t eventq_task_stack_poll_timeout_r[POLL_STACK_SIZE];
 +
 +/* Setting the data for the poll single */
 +/* Define the task stack for the eventq_task_poll_single_send */
 +#define SEND_TASK_POLL_SINGLE_PRIO        (7)
 +struct os_task eventq_task_poll_single_s;
 +os_stack_t eventq_task_stack_poll_single_s[POLL_STACK_SIZE];
 +
 +/* Define the task stack for the eventq_task_poll_single_receive */
 +#define RECEIVE_TASK_POLL_SINGLE_PRIO     (8)
 +struct os_task eventq_task_poll_single_r;
 +os_stack_t eventq_task_stack_poll_single_r[POLL_STACK_SIZE];
 +
 +/* This is the task function  to send data */
 +void
 +eventq_task_send(void *arg)
 +{
 +    int i;
 +
 +    g_event.ev_queued = 0;
 +    g_event.ev_type = my_event_type;
 +    g_event.ev_arg = NULL;
 +
 +    os_eventq_put(&my_eventq, &g_event);
 +
 +    os_time_delay(OS_TICKS_PER_SEC / 2);
 +
 +    for (i = 0; i < SIZE_MULTI_EVENT; i++){
 +        m_event[i].ev_type = i + 2;
 +        m_event[i].ev_arg = NULL;
 +
 +        /* Put and send */
 +        os_eventq_put(&multi_eventq[i], &m_event[i]);
 +        os_time_delay(OS_TICKS_PER_SEC / 2);
 +    }
 +
 +    /* This task sleeps until the receive task completes the test. */
 +    os_time_delay(1000000);
 +}
 +
 +/* This is the task function is the receiving function */
 +void
 +eventq_task_receive(void *arg)
 +{
 +    struct os_event *event;
 +    int i;
 +
 +    event = os_eventq_get(&my_eventq);
 +    TEST_ASSERT(event->ev_type == my_event_type);
 +
 +    /* Receiving multi event from the send task */
 +    for (i = 0; i < SIZE_MULTI_EVENT; i++) {
 +        event = os_eventq_get(&multi_eventq[i]);
 +        TEST_ASSERT(event->ev_type == i + 2);
 +    }
 +
 +    /* Finishes the test when OS has been started */
 +    os_test_restart();
 +}
 +
 +void
 +eventq_task_poll_send(void *arg)
 +{
 +    struct os_eventq *eventqs[SIZE_MULTI_EVENT];
 +    int i;
 +
 +    for (i = 0; i < SIZE_MULTI_EVENT; i++){
 +        eventqs[i] = &multi_eventq[i];
 +    }
 +
 +    for (i = 0; i < SIZE_MULTI_EVENT; i++){
 +        m_event[i].ev_type = i + 10;
 +        m_event[i].ev_arg = NULL;
 +
 +        /* Put and send */
 +        os_eventq_put(eventqs[i], &m_event[i]);
 +        os_time_delay(OS_TICKS_PER_SEC / 2);
 +    }
 +
 +    /* This task sleeps until the receive task completes the test. */
 +    os_time_delay(1000000);
 +}
 +
 +void
 +eventq_task_poll_receive(void *arg)
 +{
 +    struct os_eventq *eventqs[SIZE_MULTI_EVENT];
 +    struct os_event *event;
 +    int i;
 +
 +    for (i = 0; i < SIZE_MULTI_EVENT; i++){
 +        eventqs[i] = &multi_eventq[i];
 +    }
 +
 +    /* Recieving using the os_eventq_poll*/
 +    for (i = 0; i < SIZE_MULTI_EVENT; i++) {
 +        event = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, OS_WAIT_FOREVER);
 +        TEST_ASSERT(event->ev_type == i +10);
 +    }
 +
 +    /* Finishes the test when OS has been started */
 +    os_test_restart();
 +
 +}
 +
 +/* Sending with a time failure */
 +void
 +eventq_task_poll_timeout_send(void *arg)
 +{
 +    struct os_eventq *eventqs[SIZE_MULTI_EVENT];
 +    int i;
 +
 +    for (i = 0; i < SIZE_MULTI_EVENT; i++){
 +        eventqs[i] = &multi_eventq[i];
 +    }
 +
 +    for (i = 0; i < SIZE_MULTI_EVENT; i++){
-          os_time_delay(1000);
++         os_time_delay(OS_TICKS_PER_SEC);
 +
 +        /* Put and send */
 +        os_eventq_put(eventqs[i], &m_event[i]);
 +        os_time_delay(OS_TICKS_PER_SEC / 2);
 +    }
 +
 +    /* This task sleeps until the receive task completes the test. */
 +    os_time_delay(1000000);
 +    
 +}
 +
 +/* Receiving multiple event queues with a time failure */
 +void
 +eventq_task_poll_timeout_receive(void *arg)
 +{
 +    struct os_eventq *eventqs[SIZE_MULTI_EVENT];
 +    struct os_event *event;
 +    int i;
 +
 +    for (i = 0; i < SIZE_MULTI_EVENT; i++){
 +        eventqs[i] = &multi_eventq[i];
 +    }
 +
 +    /* Recieving using the os_eventq_poll_timeout*/
 +    for (i = 0; i < SIZE_MULTI_EVENT; i++) {
-         event = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, 200);
++        event = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, OS_TICKS_PER_SEC / 5);
 +        TEST_ASSERT(event == NULL);
 +    }
 +
 +    /* Finishes the test when OS has been started */
 +    os_test_restart();
 +
 +}
 +
 +/* Sending a single event to poll */
 +void
 +eventq_task_poll_single_send(void *arg)
 +{
 +    struct os_eventq *eventqs[SIZE_MULTI_EVENT];
 +    int i;
 +    int position = 2;
 +
 +    for (i = 0; i < SIZE_MULTI_EVENT; i++){
 +        eventqs[i] = &multi_eventq[i];
 +    }
 +
 +    /* Put and send */
 +    os_eventq_put(eventqs[position], &m_event[position]);
 +    os_time_delay(OS_TICKS_PER_SEC / 2);
 +
 +    /* This task sleeps until the receive task completes the test. */
 +    os_time_delay(1000000);
 +}
 +
 +/* Recieving the single event */
 +void
 +eventq_task_poll_single_receive(void *arg)
 +{
 +    struct os_eventq *eventqs[SIZE_MULTI_EVENT];
 +    struct os_event *event;
 +    int i;
 +
 +    for (i = 0; i < SIZE_MULTI_EVENT; i++){
 +        eventqs[i] = &multi_eventq[i];
 +    }
 +
 +    /* Recieving using the os_eventq_poll*/
 +    event = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, OS_WAIT_FOREVER);
 +    TEST_ASSERT(event->ev_type == 20);
 +
 +    /* Finishes the test when OS has been started */
 +    os_test_restart();
 +}
 +
 +TEST_CASE(event_test_sr)
 +{
 +    int i;
 +
 +    /* Initializing the OS */
 +    os_init();
 +    /* Initialize the task */
 +    os_task_init(&eventq_task_s, "eventq_task_s", eventq_task_send, NULL,
 +        SEND_TASK_PRIO, OS_WAIT_FOREVER, eventq_task_stack_s, MY_STACK_SIZE);
 +
 +    /* Receive events and check whether the eevnts are correctly received */
 +    os_task_init(&eventq_task_r, "eventq_task_r", eventq_task_receive, NULL,
 +        RECEIVE_TASK_PRIO, OS_WAIT_FOREVER, eventq_task_stack_r,
 +        MY_STACK_SIZE);
 +
 +    os_eventq_init(&my_eventq);
 +
 +    for (i = 0; i < SIZE_MULTI_EVENT; i++){
 +        os_eventq_init(&multi_eventq[i]);
 +    }
 +
 +    /* Does not return until OS_restart is called */
 +    os_start();
 +
 +}
 +
 +/* To test for the basic function of os_eventq_poll() */
 +TEST_CASE(event_test_poll_sr)
 +{
 +    int i;
 +
 +    /* Initializing the OS */
 +    os_init();
 +    /* Initialize the task */
 +    os_task_init(&eventq_task_poll_s, "eventq_task_poll_s", eventq_task_poll_send,
 +        NULL, SEND_TASK_POLL_PRIO, OS_WAIT_FOREVER, eventq_task_stack_poll_s, 
 +        POLL_STACK_SIZE);
 +
 +    /* Receive events and check whether the eevnts are correctly received */
 +    os_task_init(&eventq_task_poll_r, "eventq_task_r", eventq_task_poll_receive,
 +        NULL, RECEIVE_TASK_POLL_PRIO, OS_WAIT_FOREVER, eventq_task_stack_poll_r,
 +        POLL_STACK_SIZE);
 +
 +    /* Initializing the eventqs. */
 +    for (i = 0; i < SIZE_MULTI_EVENT; i++){
 +        os_eventq_init(&multi_eventq[i]);
 +    }
 +
 +    /* Does not return until OS_restart is called */
 +    os_start();
 +
 +}
 +
 +/* Test case for poll timeout */
 +TEST_CASE(event_test_poll_timeout_sr)
 +{
 +    int i;
 +
 +    /* Initializing the OS */
 +    os_init();
 +    /* Initialize the task */
 +    os_task_init(&eventq_task_poll_timeout_s, "eventq_task_poll_timeout_s", 
 +        eventq_task_poll_timeout_send, NULL, SEND_TASK_POLL_TIMEOUT_PRIO,
 +        OS_WAIT_FOREVER, eventq_task_stack_poll_timeout_s, POLL_STACK_SIZE);
 +
 +    /* Receive events and check whether the eevnts are correctly received */
 +    os_task_init(&eventq_task_poll_timeout_r, "eventq_task_timeout_r",
 +        eventq_task_poll_timeout_receive, NULL, RECEIVE_TASK_POLL_TIMEOUT_PRIO,
 +        OS_WAIT_FOREVER, eventq_task_stack_poll_timeout_r, POLL_STACK_SIZE);
 +
 +    /* Initializing the eventqs. */
 +    for (i = 0; i < SIZE_MULTI_EVENT; i++){
 +        os_eventq_init(&multi_eventq[i]);
 +
 +        m_event[i].ev_type = i + 10;
 +        m_event[i].ev_arg = NULL;
 +    }
 +
 +    /* Does not return until OS_restart is called */
 +    os_start();
 +
 +}
 +
 +/* The case for poll single */
 +/* Test case for poll timeout */
 +TEST_CASE(event_test_poll_single_sr)
 +{
 +    int i;
 +
 +    /* Initializing the OS */
 +    os_init();
 +    /* Initialize the task */
 +    os_task_init(&eventq_task_poll_single_s, "eventq_task_poll_single_s", 
 +        eventq_task_poll_single_send, NULL, SEND_TASK_POLL_SINGLE_PRIO,
 +        OS_WAIT_FOREVER, eventq_task_stack_poll_single_s, POLL_STACK_SIZE);
 +
 +    /* Receive events and check whether the eevnts are correctly received */
 +    os_task_init(&eventq_task_poll_single_r, "eventq_task_single_r",
 +        eventq_task_poll_single_receive, NULL, RECEIVE_TASK_POLL_SINGLE_PRIO,
 +        OS_WAIT_FOREVER, eventq_task_stack_poll_single_r, POLL_STACK_SIZE);
 +
 +    for (i = 0; i < SIZE_MULTI_EVENT; i++){
 +        os_eventq_init(&multi_eventq[i]);
 +
 +        m_event[i].ev_type = 10 * i;
 +        m_event[i].ev_arg = NULL;
 +    }
 +
 +    /* Does not return until OS_restart is called */
 +    os_start();
 +
 +}
 +
 +/**
 + * Tests eventq_poll() with a timeout of 0.  This should not involve the
 + * scheduler at all, so it should work without starting the OS.
 + */
 +TEST_CASE(event_test_poll_0timo)
 +{
 +    struct os_eventq *eventqs[SIZE_MULTI_EVENT];
 +    struct os_event *evp;
 +    struct os_event ev;
 +    int i;
 +
 +    for (i = 0; i < SIZE_MULTI_EVENT; i++){
 +        os_eventq_init(&multi_eventq[i]);
 +        eventqs[i] = &multi_eventq[i];
 +    }
 +
 +    evp = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, 0);
 +    TEST_ASSERT(evp == NULL);
 +
 +    /* Ensure no eventq thinks a task is waiting on it. */
 +    for (i = 0; i < SIZE_MULTI_EVENT; i++) {
 +        TEST_ASSERT(eventqs[i]->evq_task == NULL);
 +    }
 +
 +    /* Put an event on one of the queues. */
 +    memset(&ev, 0, sizeof ev);
 +    ev.ev_type = 1;
 +    os_eventq_put(eventqs[3], &ev);
 +
 +    evp = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, 0);
 +    TEST_ASSERT(evp == &ev);
 +}
 +
 +TEST_SUITE(os_eventq_test_suite)
 +{
 +    event_test_sr();
 +    event_test_poll_sr();
 +    event_test_poll_timeout_sr();
 +    event_test_poll_single_sr();
 +    event_test_poll_0timo();
 +}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c5901fcc/libs/os/test/src/mutex_test.c
----------------------------------------------------------------------
diff --cc libs/os/test/src/mutex_test.c
index ef6a08d,0000000..d23f099
mode 100644,000000..100644
--- a/libs/os/test/src/mutex_test.c
+++ b/libs/os/test/src/mutex_test.c
@@@ -1,407 -1,0 +1,407 @@@
 +/**
 + * 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 <assert.h>
 +#include <sys/time.h>
 +#include "testutil/testutil.h"
 +#include "os/os.h"
 +#include "os/os_test.h"
 +#include "os/os_cfg.h"
 +#include "os/os_mutex.h"
 +#include "os_test_priv.h"
 +
 +#ifdef ARCH_sim
 +#define MUTEX_TEST_STACK_SIZE   1024
 +#else
 +#define MUTEX_TEST_STACK_SIZE   256
 +#endif
 +
 +struct os_task task14;
 +os_stack_t stack14[OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)];
 +
 +struct os_task task15;
 +os_stack_t stack15[OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)];
 +
 +struct os_task task16;
 +os_stack_t stack16[OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)];
 +
 +struct os_task task17;
 +os_stack_t stack17[OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)];
 +
 +#define TASK14_PRIO (4)
 +#define TASK15_PRIO (5)
 +#define TASK16_PRIO (6)
 +#define TASK17_PRIO (7)
 +
 +volatile int g_task14_val;
 +volatile int g_task15_val;
 +volatile int g_task16_val;
 +volatile int g_task17_val;
 +struct os_mutex g_mutex1;
 +struct os_mutex g_mutex2;
 +
 +static volatile int g_mutex_test;
 +
 +/**
 + * mutex test basic 
 + *  
 + * Basic mutex tests
 + * 
 + * @return int 
 + */
 +static void
 +mutex_test_basic_handler(void *arg)
 +{
 +    struct os_mutex *mu;
 +    struct os_task *t;
 +    os_error_t err;
 +
 +    mu = &g_mutex1;
 +    t = os_sched_get_current_task();
 +
 +    /* Test some error cases */
 +    TEST_ASSERT(os_mutex_init(NULL)     == OS_INVALID_PARM);
 +    TEST_ASSERT(os_mutex_release(NULL)  == OS_INVALID_PARM);
 +    TEST_ASSERT(os_mutex_pend(NULL, 0)  == OS_INVALID_PARM);
 +
 +    /* Get the mutex */
 +    err = os_mutex_pend(mu, 0);
 +    TEST_ASSERT(err == 0,
 +                "Did not get free mutex immediately (err=%d)", err);
 +
 +    /* Check mutex internals */
 +    TEST_ASSERT(mu->mu_owner == t && mu->mu_level == 1 &&
 +                mu->mu_prio == t->t_prio && SLIST_EMPTY(&mu->mu_head),
 +                "Mutex internals not correct after getting mutex\n"
 +                "Mutex: owner=%p prio=%u level=%u head=%p\n"
 +                "Task: task=%p prio=%u",
 +                mu->mu_owner, mu->mu_prio, mu->mu_level, 
 +                SLIST_FIRST(&mu->mu_head),
 +                t, t->t_prio);
 +
 +    /* Get the mutex again; should be level 2 */
 +    err = os_mutex_pend(mu, 0);
 +    TEST_ASSERT(err == 0, "Did not get my mutex immediately (err=%d)", err);
 +
 +    /* Check mutex internals */
 +    TEST_ASSERT(mu->mu_owner == t && mu->mu_level == 2 &&
 +                mu->mu_prio == t->t_prio && SLIST_EMPTY(&mu->mu_head),
 +                "Mutex internals not correct after getting mutex\n"
 +                "Mutex: owner=%p prio=%u level=%u head=%p\n"
 +                "Task: task=%p prio=%u",
 +                mu->mu_owner, mu->mu_prio, mu->mu_level, 
 +                SLIST_FIRST(&mu->mu_head), t, t->t_prio);
 +
 +    /* Release mutex */
 +    err = os_mutex_release(mu);
 +    TEST_ASSERT(err == 0, "Could not release mutex I own (err=%d)", err);
 +
 +    /* Check mutex internals */
 +    TEST_ASSERT(mu->mu_owner == t && mu->mu_level == 1 &&
 +                mu->mu_prio == t->t_prio && SLIST_EMPTY(&mu->mu_head),
 +                "Error: mutex internals not correct after getting mutex\n"
 +                "Mutex: owner=%p prio=%u level=%u head=%p\n"
 +                "Task: task=%p prio=%u",
 +                mu->mu_owner, mu->mu_prio, mu->mu_level, 
 +                SLIST_FIRST(&mu->mu_head), t, t->t_prio);
 +
 +    /* Release it again */
 +    err = os_mutex_release(mu);
 +    TEST_ASSERT(err == 0, "Could not release mutex I own (err=%d)", err);
 +
 +    /* Check mutex internals */
 +    TEST_ASSERT(mu->mu_owner == NULL && mu->mu_level == 0 &&
 +                mu->mu_prio == t->t_prio && SLIST_EMPTY(&mu->mu_head),
 +                "Mutex internals not correct after getting mutex\n"
 +                "Mutex: owner=%p prio=%u level=%u head=%p\n"
 +                "Task: task=%p prio=%u",
 +                mu->mu_owner, mu->mu_prio, mu->mu_level, 
 +                SLIST_FIRST(&mu->mu_head), t, t->t_prio);
 +
 +    os_test_restart();
 +}
 +
 +static void 
 +mutex_test1_task14_handler(void *arg)
 +{
 +    os_error_t err;
 +    struct os_task *t;
 +    int iters;
 +
 +    t = os_sched_get_current_task();
 +    TEST_ASSERT(t->t_func == mutex_test1_task14_handler);
 +
 +    for (iters = 0; iters < 3; iters++) {
-         os_time_delay(100);
++        os_time_delay(OS_TICKS_PER_SEC / 10);
 +
 +        g_task14_val = 1;
 +
-         err = os_mutex_pend(&g_mutex1, 100);
++        err = os_mutex_pend(&g_mutex1, OS_TICKS_PER_SEC / 10);
 +        TEST_ASSERT(err == OS_OK);
 +        TEST_ASSERT(g_task16_val == 1);
 +
-         os_time_delay(100);
++        os_time_delay(OS_TICKS_PER_SEC / 10);
 +    }
 +
 +    os_test_restart();
 +}
 +
 +static void 
 +mutex_test2_task14_handler(void *arg)
 +{
 +    os_error_t err;
 +    struct os_task *t;
 +    int iters;
 +
 +    t = os_sched_get_current_task();
 +    TEST_ASSERT(t->t_func == mutex_test2_task14_handler);
 +
 +    for (iters = 0; iters < 3; iters++) {
 +        err = os_mutex_pend(&g_mutex1, 0);
 +        TEST_ASSERT(err == OS_OK, "err=%d", err);
 +
 +        g_task14_val = 1;
-         os_time_delay(100);
++        os_time_delay(OS_TICKS_PER_SEC / 10);
 +
 +        /* 
 +         * Task17 should have its mutex wait flag set; at least the first time
 +         * through!
 +         */
 +        if (iters == 0) {
 +            TEST_ASSERT(task17.t_flags & OS_TASK_FLAG_MUTEX_WAIT);
 +        }
 +
 +        if (g_mutex_test == 4) {
 +            os_time_delay(150);
 +        }
 +
 +        os_mutex_release(&g_mutex1);
-         os_time_delay(100);
++        os_time_delay(OS_TICKS_PER_SEC / 10);
 +    }
 +
 +    os_test_restart();
 +}
 +
 +static void 
 +task15_handler(void *arg) 
 +{
 +    os_error_t err;
 +    struct os_task *t;
 +
 +    if (g_mutex_test == 1) {
 +        while (1) {
 +            t = os_sched_get_current_task();
 +            TEST_ASSERT(t->t_func == task15_handler);
 +
-             os_time_delay(50);
++            os_time_delay(OS_TICKS_PER_SEC / 20);
 +            while (1) {
 +                /* Wait here forever */
 +            }
 +        }
 +    } else {
 +        if (g_mutex_test == 2) {
 +            /* Sleep for 3 seconds */
 +            t = os_sched_get_current_task();
-             os_time_delay(500);
++            os_time_delay(OS_TICKS_PER_SEC / 2);
 +        } else if (g_mutex_test == 3) {
 +            /* Sleep for 3 seconds */
 +            t = os_sched_get_current_task();
-             os_time_delay(30);
++            os_time_delay(OS_TICKS_PER_SEC / 33);
 +        }
 +
 +        while (1) {
 +            t = os_sched_get_current_task();
 +            TEST_ASSERT(t->t_func == task15_handler);
 +
-             err = os_mutex_pend(&g_mutex1, 10000);
++            err = os_mutex_pend(&g_mutex1, OS_TICKS_PER_SEC * 10);
 +            if (g_mutex_test == 4) {
 +                TEST_ASSERT(err == OS_TIMEOUT);
 +            } else {
 +                TEST_ASSERT(err == OS_OK);
 +            }
 +
-             os_time_delay(100);
++            os_time_delay(OS_TICKS_PER_SEC / 10);
 +        }
 +    }
 +}
 +
 +static void 
 +task16_handler(void *arg) 
 +{
 +    os_error_t err;
 +    struct os_task *t;
 +
 +    if (g_mutex_test == 1) {
 +        while (1) {
 +            t = os_sched_get_current_task();
 +            TEST_ASSERT(t->t_func == task16_handler);
 +
 +            /* Get mutex 1 */
-             err = os_mutex_pend(&g_mutex1, 0xFFFFFFFF);
++            err = os_mutex_pend(&g_mutex1, OS_TIMEOUT_NEVER);
 +            TEST_ASSERT(err == OS_OK);
 +
 +            while (g_task14_val != 1) {
 +                /* Wait till task 1 wakes up and sets val. */
 +            }
 +
 +            g_task16_val = 1;
 +
 +            err = os_mutex_release(&g_mutex1);
 +            TEST_ASSERT(err == OS_OK);
 +        }
 +    } else {
 +        if (g_mutex_test == 2) {
 +            /* Sleep for 3 seconds */
 +            t = os_sched_get_current_task();
-             os_time_delay(30);
++            os_time_delay(OS_TICKS_PER_SEC / 33);
 +        } else if (g_mutex_test == 3) {
 +            /* Sleep for 3 seconds */
 +            t = os_sched_get_current_task();
-             os_time_delay(50);
++            os_time_delay(OS_TICKS_PER_SEC / 20);
 +        }
 +
 +        while (1) {
 +            t = os_sched_get_current_task();
 +            TEST_ASSERT(t->t_func == task16_handler);
 +
-             err = os_mutex_pend(&g_mutex1, 10000);
++            err = os_mutex_pend(&g_mutex1, OS_TICKS_PER_SEC * 10);
 +            if (g_mutex_test == 4) {
 +                TEST_ASSERT(err == OS_TIMEOUT);
 +            } else {
 +                TEST_ASSERT(err == OS_OK);
 +            }
 +
 +            if (err == OS_OK) {
 +                err = os_mutex_release(&g_mutex1);
 +                TEST_ASSERT(err == OS_OK);
 +            }
 +
-             os_time_delay(10000);
++            os_time_delay(OS_TICKS_PER_SEC * 10);
 +        }
 +    }
 +}
 +
 +static void 
 +task17_handler(void *arg)
 +{
 +    os_error_t err;
 +    struct os_task *t;
 +
 +    while (1) {
 +        t = os_sched_get_current_task();
 +        TEST_ASSERT(t->t_func == task17_handler);
 +
 +        if (g_mutex_test == 5) {
-             err = os_mutex_pend(&g_mutex1, 10);
++            err = os_mutex_pend(&g_mutex1, OS_TICKS_PER_SEC / 10);
 +        } else {
-             err = os_mutex_pend(&g_mutex1, 10000);
++            err = os_mutex_pend(&g_mutex1, OS_TICKS_PER_SEC * 10);
 +            TEST_ASSERT((t->t_flags & OS_TASK_FLAG_MUTEX_WAIT) == 0);
 +        }
 +
 +        if (g_mutex_test == 4 || g_mutex_test == 5) {
 +            TEST_ASSERT(err == OS_TIMEOUT);
 +        } else {
 +            TEST_ASSERT(err == OS_OK);
 +        }
 +
 +        if (err == OS_OK) {
 +            err = os_mutex_release(&g_mutex1);
 +            TEST_ASSERT(err == OS_OK);
 +        }
 +
-         os_time_delay(10000);
++        os_time_delay(OS_TICKS_PER_SEC * 10);
 +    }
 +}
 +
 +TEST_CASE(os_mutex_test_basic)
 +{
 +    os_init();
 +
 +    os_mutex_init(&g_mutex1);
 +
 +    os_task_init(&task14, "task14", mutex_test_basic_handler, NULL,
 +                 TASK14_PRIO, OS_WAIT_FOREVER, stack14,
 +                 OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
 +
 +    os_start();
 +}
 +
 +TEST_CASE(os_mutex_test_case_1)
 +{
 +    int rc;
 +
 +    os_init();
 +
 +    g_mutex_test = 1;
 +    g_task14_val = 0;
 +    g_task15_val = 0;
 +    g_task16_val = 0;
 +
 +    rc = os_mutex_init(&g_mutex1);
 +    TEST_ASSERT(rc == 0);
 +    rc = os_mutex_init(&g_mutex2);
 +    TEST_ASSERT(rc == 0);
 +
 +    os_task_init(&task14, "task14", mutex_test1_task14_handler, NULL,
 +                 TASK14_PRIO, OS_WAIT_FOREVER, stack14,
 +                 OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
 +
 +    os_task_init(&task15, "task15", task15_handler, NULL, TASK15_PRIO, 
 +            OS_WAIT_FOREVER, stack15, OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
 +
 +    os_task_init(&task16, "task16", task16_handler, NULL, TASK16_PRIO, 
 +            OS_WAIT_FOREVER, stack16, OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
 +
 +    os_start();
 +}
 +
 +TEST_CASE(os_mutex_test_case_2)
 +{
 +    os_init();
 +
 +    g_mutex_test = 2;
 +    g_task14_val = 0;
 +    g_task15_val = 0;
 +    g_task16_val = 0;
 +    os_mutex_init(&g_mutex1);
 +    os_mutex_init(&g_mutex2);
 +
 +    os_task_init(&task14, "task14", mutex_test2_task14_handler, NULL,
 +                 TASK14_PRIO, OS_WAIT_FOREVER, stack14,
 +                 OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
 +
 +    os_task_init(&task15, "task15", task15_handler, NULL, TASK15_PRIO, 
 +            OS_WAIT_FOREVER, stack15, OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
 +
 +    os_task_init(&task16, "task16", task16_handler, NULL, TASK16_PRIO, 
 +            OS_WAIT_FOREVER, stack16, OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
 +
 +    os_task_init(&task17, "task17", task17_handler, NULL, TASK17_PRIO, 
 +            OS_WAIT_FOREVER, stack17, OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
 + 
 +    os_start();
 +}
 +
 +TEST_SUITE(os_mutex_test_suite)
 +{
 +    os_mutex_test_basic();
 +    os_mutex_test_case_1();
 +    os_mutex_test_case_2();
 +}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c5901fcc/libs/os/test/src/os_test.c
----------------------------------------------------------------------
diff --cc libs/os/test/src/os_test.c
index 809ab9f,0000000..e9d041b
mode 100644,000000..100644
--- a/libs/os/test/src/os_test.c
+++ b/libs/os/test/src/os_test.c
@@@ -1,53 -1,0 +1,53 @@@
 +/**
 + * 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 "syscfg/syscfg.h"
 +#include "testutil/testutil.h"
 +#include "os/os_test.h"
 +#include "os_test_priv.h"
 +
 +int
 +os_test_all(void)
 +{
 +    os_mempool_test_suite();
 +    os_mutex_test_suite();
 +    os_sem_test_suite();
 +    os_mbuf_test_suite();
 +    os_eventq_test_suite();
-     
++    os_callout_test_suite();
 +
 +    return tu_case_failed;
 +}
 +
 +#if MYNEWT_VAL(SELFTEST)
 +
 +int
 +main(int argc, char **argv)
 +{
 +    tu_config.tc_print_results = 1;
 +    tu_init();
 +
 +    os_test_all();
 +
 +    return tu_any_failed;
 +}
 +
 +#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c5901fcc/libs/os/test/src/os_test_priv.h
----------------------------------------------------------------------
diff --cc libs/os/test/src/os_test_priv.h
index 5193c33,0000000..e923a6f
mode 100644,000000..100644
--- a/libs/os/test/src/os_test_priv.h
+++ b/libs/os/test/src/os_test_priv.h
@@@ -1,32 -1,0 +1,32 @@@
 +/**
 + * 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_OS_TEST_PRIV_
 +#define H_OS_TEST_PRIV_
 +
 +void os_test_restart(void);
 +
 +int os_mempool_test_suite(void);
 +int os_mbuf_test_suite(void);
 +int os_mutex_test_suite(void);
 +int os_sem_test_suite(void);
 +int os_eventq_test_suite(void);
- 
++int os_callout_test_suite(void);
 +
 +#endif



Mime
View raw message