Unit test infrastructure

Rework unit test infrastructure to enable target applications to run unit tests.
Unit tests were split up into individual files enabling applications to select 
individual tests across subsystems. Unit test case macros updated to allow
initialization and pre/post callbackas on a per-testcase basis. Test suite 
macros
updated to allow pre/post, pass/fail callbacks on individual testcases in
the suite as well as initialization and completion callbacks for the suite.
The intention is that enable customization of test suites for target devices.

Partial checkin for MYNEWT-139 and MYNEWT-41.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/75101ba4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/75101ba4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/75101ba4

Branch: refs/heads/develop
Commit: 75101ba4f3e9416602ca1ea2344d92c6a0ce3fea
Parents: 2316913
Author: Peter Snyder <g...@peterfs.com>
Authored: Sun Oct 16 20:32:04 2016 -0700
Committer: Peter Snyder <g...@peterfs.com>
Committed: Sun Oct 16 20:32:04 2016 -0700

----------------------------------------------------------------------
 boot/boot_serial/test/src/boot_test.c           |  145 +-
 boot/boot_serial/test/src/boot_test.h           |   49 +
 .../src/testcases/boot_serial_empty_img_msg.c   |   35 +
 .../test/src/testcases/boot_serial_empty_msg.c  |   39 +
 .../test/src/testcases/boot_serial_img_msg.c    |   58 +
 .../test/src/testcases/boot_serial_setup.c      |   24 +
 .../testcases/boot_serial_upload_bigger_image.c |   72 +
 boot/bootutil/test/src/boot_test.c              |  704 +-
 boot/bootutil/test/src/boot_test.h              |   85 +
 boot/bootutil/test/src/boot_test_utils.c        |  361 +
 .../test/src/testcases/boot_test_invalid_hash.c |   67 +
 .../src/testcases/boot_test_no_flag_has_hash.c  |   60 +
 .../test/src/testcases/boot_test_no_hash.c      |   59 +
 .../test/src/testcases/boot_test_nv_bs_10.c     |   47 +
 .../test/src/testcases/boot_test_nv_bs_11.c     |   69 +
 .../src/testcases/boot_test_nv_bs_11_2areas.c   |   71 +
 .../test/src/testcases/boot_test_nv_ns_01.c     |   45 +
 .../test/src/testcases/boot_test_nv_ns_10.c     |   45 +
 .../test/src/testcases/boot_test_nv_ns_11.c     |   56 +
 .../test/src/testcases/boot_test_revert.c       |   59 +
 .../src/testcases/boot_test_revert_continue.c   |   71 +
 .../test/src/testcases/boot_test_vb_ns_11.c     |   61 +
 .../test/src/testcases/boot_test_vm_ns_01.c     |   50 +
 .../test/src/testcases/boot_test_vm_ns_10.c     |   45 +
 .../src/testcases/boot_test_vm_ns_11_2areas.c   |   61 +
 .../test/src/testcases/boot_test_vm_ns_11_a.c   |   56 +
 .../test/src/testcases/boot_test_vm_ns_11_b.c   |   61 +
 crypto/mbedtls/test/src/mbedtls_test.c          |  167 +-
 crypto/mbedtls/test/src/mbedtls_test.h          |   58 +
 crypto/mbedtls/test/src/testcases/aes_test.c    |   27 +
 crypto/mbedtls/test/src/testcases/arc4_test.c   |   27 +
 crypto/mbedtls/test/src/testcases/bignum_test.c |   27 +
 crypto/mbedtls/test/src/testcases/ccm_test.c    |   27 +
 crypto/mbedtls/test/src/testcases/dhm_test.c    |   27 +
 crypto/mbedtls/test/src/testcases/ecp_test.c    |   27 +
 .../mbedtls/test/src/testcases/entropy_test.c   |   29 +
 crypto/mbedtls/test/src/testcases/gcm_test.c    |   27 +
 .../mbedtls/test/src/testcases/hmac_drbg_test.c |   27 +
 crypto/mbedtls/test/src/testcases/md5_test.c    |   27 +
 crypto/mbedtls/test/src/testcases/pkcs5_test.c  |   27 +
 .../mbedtls/test/src/testcases/ripemd160_test.c |   27 +
 crypto/mbedtls/test/src/testcases/rsa_test.c    |   27 +
 crypto/mbedtls/test/src/testcases/sha1_test.c   |   27 +
 crypto/mbedtls/test/src/testcases/sha256_test.c |   27 +
 crypto/mbedtls/test/src/testcases/sha512_test.c |   27 +
 crypto/mbedtls/test/src/testcases/x509_test.c   |   27 +
 crypto/mbedtls/test/src/testcases/xtea_test.c   |   27 +
 encoding/base64/test/src/encoding_test.c        |   11 +-
 encoding/base64/test/src/encoding_test_priv.h   |    7 +-
 encoding/base64/test/src/hex_test.c             |  125 -
 encoding/base64/test/src/testcases/hex2str.c    |   64 +
 encoding/base64/test/src/testcases/str2hex.c    |   72 +
 encoding/json/test/src/test_json.c              |    6 +-
 encoding/json/test/src/test_json.h              |   32 +-
 encoding/json/test/src/test_json_simple.c       |  360 -
 encoding/json/test/src/test_json_utils.c        |   98 +
 .../test/src/testcases/json_simple_decode.c     |  205 +
 .../test/src/testcases/json_simple_encode.c     |   85 +
 fs/fcb/test/src/fcb_test.c                      |  558 +-
 fs/fcb/test/src/fcb_test.h                      |   53 +
 fs/fcb/test/src/testcases/fcb_test_append.c     |   56 +
 .../test/src/testcases/fcb_test_append_fill.c   |   90 +
 .../src/testcases/fcb_test_append_too_big.c     |   65 +
 fs/fcb/test/src/testcases/fcb_test_empty_walk.c |   38 +
 fs/fcb/test/src/testcases/fcb_test_init.c       |   40 +
 fs/fcb/test/src/testcases/fcb_test_len.c        |   37 +
 .../src/testcases/fcb_test_multiple_scratch.c   |  110 +
 fs/fcb/test/src/testcases/fcb_test_reset.c      |  145 +
 fs/fcb/test/src/testcases/fcb_test_rotate.c     |  108 +
 fs/nffs/src/nffs_priv.h                         |    5 +
 fs/nffs/syscfg.yml                              |    1 +
 fs/nffs/test/src/arch/cortex_m4/nffs_test.c     |   27 -
 fs/nffs/test/src/arch/sim/nffs_test.c           | 3251 ---------
 fs/nffs/test/src/arch/sim/nffs_test_priv.h      |   50 -
 fs/nffs/test/src/arch/sim/nffs_test_system_01.c | 6537 ------------------
 fs/nffs/test/src/nffs_test.c                    |  721 ++
 fs/nffs/test/src/nffs_test.h                    |   27 +
 fs/nffs/test/src/nffs_test_debug.c              |  522 ++
 fs/nffs/test/src/nffs_test_priv.h               |   49 +
 fs/nffs/test/src/nffs_test_system_01.c          | 6537 ++++++++++++++++++
 fs/nffs/test/src/nffs_test_utils.c              |  744 ++
 fs/nffs/test/src/nffs_test_utils.h              |   92 +
 fs/nffs/test/src/testcases/append_test.c        |  169 +
 .../test/src/testcases/cache_large_file_test.c  |   89 +
 fs/nffs/test/src/testcases/corrupt_block_test.c |  121 +
 .../test/src/testcases/corrupt_scratch_test.c   |   83 +
 fs/nffs/test/src/testcases/gc_on_oom_test.c     |   88 +
 fs/nffs/test/src/testcases/gc_test.c            |   67 +
 .../test/src/testcases/incomplete_block_test.c  |  119 +
 fs/nffs/test/src/testcases/large_system_test.c  |   43 +
 fs/nffs/test/src/testcases/large_unlink_test.c  |   80 +
 fs/nffs/test/src/testcases/large_write_test.c   |   71 +
 fs/nffs/test/src/testcases/long_filename_test.c |   59 +
 fs/nffs/test/src/testcases/lost_found_test.c    |  107 +
 fs/nffs/test/src/testcases/many_children_test.c |   74 +
 fs/nffs/test/src/testcases/mkdir_test.c         |   92 +
 fs/nffs/test/src/testcases/open_test.c          |   74 +
 .../test/src/testcases/overwrite_many_test.c    |  105 +
 fs/nffs/test/src/testcases/overwrite_one_test.c |  142 +
 .../test/src/testcases/overwrite_three_test.c   |  167 +
 fs/nffs/test/src/testcases/overwrite_two_test.c |  159 +
 fs/nffs/test/src/testcases/read_test.c          |   53 +
 fs/nffs/test/src/testcases/readdir_test.c       |  124 +
 fs/nffs/test/src/testcases/rename_test.c        |   98 +
 fs/nffs/test/src/testcases/split_file_test.c    |   65 +
 fs/nffs/test/src/testcases/truncate_test.c      |   73 +
 fs/nffs/test/src/testcases/unlink_test.c        |  121 +
 fs/nffs/test/src/testcases/wear_level_test.c    |   58 +
 hw/bsp/native/syscfg.yml                        |    1 +
 .../test/src/arch/cortex_m4/os_test_arch_arm.c  |   27 -
 kernel/os/test/src/arch/sim/os_test_arch_sim.c  |   52 -
 kernel/os/test/src/callout_test.c               |   97 +-
 kernel/os/test/src/callout_test.h               |   96 +
 kernel/os/test/src/eventq_test.c                |  152 +-
 kernel/os/test/src/eventq_test.h                |  104 +
 kernel/os/test/src/mbuf_test.c                  |  331 +-
 kernel/os/test/src/mbuf_test.h                  |   56 +
 kernel/os/test/src/mempool_test.c               |   16 +-
 kernel/os/test/src/mempool_test.h               |   60 +
 kernel/os/test/src/mutex_test.c                 |   85 +-
 kernel/os/test/src/mutex_test.h                 |   78 +
 kernel/os/test/src/os_test.c                    |   35 +-
 kernel/os/test/src/os_test_priv.h               |   13 +
 kernel/os/test/src/sem_test.c                   |  164 +-
 kernel/os/test/src/sem_test.h                   |   79 +
 .../test/src/testcases/event_test_poll_0timo.c  |   52 +
 .../src/testcases/event_test_poll_single_sr.c   |   49 +
 .../os/test/src/testcases/event_test_poll_sr.c  |   46 +
 .../src/testcases/event_test_poll_timeout_sr.c  |   49 +
 kernel/os/test/src/testcases/event_test_src.c   |   45 +
 kernel/os/test/src/testcases/ob_mbuf_test_adj.c |   60 +
 .../os/test/src/testcases/ob_mbuf_test_pullup.c |  106 +
 kernel/os/test/src/testcases/os_callout_test.c  |   46 +
 .../test/src/testcases/os_callout_test_speak.c  |   45 +
 .../test/src/testcases/os_callout_test_stop.c   |   51 +
 .../os/test/src/testcases/os_mbuf_test_alloc.c  |   33 +
 .../os/test/src/testcases/os_mbuf_test_append.c |   43 +
 kernel/os/test/src/testcases/os_mbuf_test_dup.c |   77 +
 .../os/test/src/testcases/os_mbuf_test_extend.c |   91 +
 .../src/testcases/os_mbuf_test_get_pkghdr.c     |   34 +
 .../test/src/testcases/os_mempool_test_case.c   |   31 +
 .../os/test/src/testcases/os_mutex_test_basic.c |   32 +
 .../test/src/testcases/os_mutex_test_case_1.c   |   48 +
 .../test/src/testcases/os_mutex_test_case_2.c   |   46 +
 .../os/test/src/testcases/os_sem_test_basic.c   |   34 +
 .../os/test/src/testcases/os_sem_test_case_1.c  |   42 +
 .../os/test/src/testcases/os_sem_test_case_2.c  |   45 +
 .../os/test/src/testcases/os_sem_test_case_3.c  |   45 +
 .../os/test/src/testcases/os_sem_test_case_4.c  |   45 +
 net/ip/mn_socket/test/src/mn_sock_test.c        |  850 +--
 net/ip/mn_socket/test/src/mn_sock_test.h        |   42 +
 net/ip/mn_socket/test/src/mn_sock_util.c        |  775 +++
 .../test/src/testcases/inet_ntop_test.c         |   49 +
 .../test/src/testcases/inet_pton_test.c         |   55 +
 .../mn_socket/test/src/testcases/socket_tests.c |   31 +
 net/nimble/host/test/src/ble_hs_test.c          |    2 +-
 sys/config/include/config/config_fcb.h          |    4 +-
 sys/config/test-fcb/pkg.yml                     |   31 +
 sys/config/test-fcb/src/conf_test_fcb.c         |  363 +
 sys/config/test-fcb/src/conf_test_fcb.h         |   90 +
 .../src/testcases/config_empty_lookups.c        |   34 +
 .../test-fcb/src/testcases/config_test_commit.c |   41 +
 .../src/testcases/config_test_compress_reset.c  |   88 +
 .../src/testcases/config_test_empty_fcb.c       |   42 +
 .../src/testcases/config_test_getset_bytes.c    |   49 +
 .../src/testcases/config_test_getset_int.c      |   40 +
 .../src/testcases/config_test_getset_unknown.c  |   48 +
 .../test-fcb/src/testcases/config_test_insert.c |   27 +
 .../src/testcases/config_test_insert2.c         |   27 +
 .../src/testcases/config_test_insert3.c         |   27 +
 .../src/testcases/config_test_save_1_fcb.c      |   46 +
 .../src/testcases/config_test_save_2_fcb.c      |   76 +
 .../src/testcases/config_test_save_3_fcb.c      |   51 +
 .../src/testcases/config_test_save_one_fcb.c    |   55 +
 sys/config/test-fcb/syscfg.yml                  |    4 +
 sys/config/test-nffs/pkg.yml                    |   31 +
 sys/config/test-nffs/src/conf_test_nffs.c       |  367 +
 sys/config/test-nffs/src/conf_test_nffs.h       |   87 +
 .../src/testcases/config_empty_lookups.c        |   34 +
 .../test-nffs/src/testcases/config_setup_nffs.c |   29 +
 .../src/testcases/config_test_commit.c          |   41 +
 .../src/testcases/config_test_empty_file.c      |   56 +
 .../src/testcases/config_test_getset_bytes.c    |   49 +
 .../src/testcases/config_test_getset_int.c      |   40 +
 .../src/testcases/config_test_getset_unknown.c  |   48 +
 .../src/testcases/config_test_insert.c          |   27 +
 .../src/testcases/config_test_insert2.c         |   27 +
 .../src/testcases/config_test_insert3.c         |   27 +
 .../testcases/config_test_multiple_in_file.c    |   52 +
 .../src/testcases/config_test_save_in_file.c    |   50 +
 .../src/testcases/config_test_save_one_file.c   |   53 +
 .../src/testcases/config_test_small_file.c      |   56 +
 sys/config/test-nffs/syscfg.yml                 |    5 +
 sys/config/test/pkg.yml                         |   32 -
 sys/config/test/src/conf_test.c                 |  953 ---
 sys/config/test/src/conf_test.h                 |   33 -
 sys/config/test/src/conf_test_suite.c           |   40 -
 sys/config/test/src/config_test.h               |   32 -
 sys/config/test/syscfg.yml                      |    5 -
 sys/flash_map/test/src/flash_map_test.c         |  126 +-
 sys/flash_map/test/src/flash_map_test.h         |   44 +
 .../test/src/testcases/flash_map_test_case_1.c  |   63 +
 .../test/src/testcases/flash_map_test_case_2.c  |   96 +
 sys/log/test/src/log_test.c                     |   67 +-
 sys/log/test/src/log_test.h                     |   54 +
 sys/log/test/src/testcases/log_append_fcb.c     |   33 +
 sys/log/test/src/testcases/log_setup_fcb.c      |   39 +
 sys/log/test/src/testcases/log_walk_fcb.c       |   29 +
 test/testutil/include/testutil/testutil.h       |  253 +-
 .../src/arch/cortex_m4/testutil_arch_arm.c      |   27 -
 test/testutil/src/arch/sim/testutil_arch_sim.c  |   30 -
 test/testutil/src/arch/sim/tu_args.c            |   23 -
 test/testutil/src/case.c                        |  120 +-
 test/testutil/src/suite.c                       |   66 +-
 test/testutil/src/testutil.c                    |   45 +-
 util/cbmem/test/src/cbmem_test.c                |  120 +-
 util/cbmem/test/src/cbmem_test.h                |   48 +
 .../test/src/testcases/cbmem_test_case_1.c      |   33 +
 .../test/src/testcases/cbmem_test_case_2.c      |   49 +
 .../test/src/testcases/cbmem_test_case_3.c      |   63 +
 util/cbmem/test/src/util_test.c                 |   45 -
 util/cbmem/test/src/util_test_priv.h            |   33 -
 222 files changed, 20783 insertions(+), 15182 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/boot_serial/test/src/boot_test.c
----------------------------------------------------------------------
diff --git a/boot/boot_serial/test/src/boot_test.c 
b/boot/boot_serial/test/src/boot_test.c
index 384606b..94efbd6 100644
--- a/boot/boot_serial/test/src/boot_test.c
+++ b/boot/boot_serial/test/src/boot_test.c
@@ -16,7 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
 #include <assert.h>
 #include <stddef.h>
 #include <stdio.h>
@@ -34,147 +33,18 @@
 
 #include "boot_serial_priv.h"
 
+TEST_CASE_DECL(boot_serial_setup)
+TEST_CASE_DECL(boot_serial_empty_msg)
+TEST_CASE_DECL(boot_serial_empty_img_msg)
+TEST_CASE_DECL(boot_serial_img_msg)
+TEST_CASE_DECL(boot_serial_upload_bigger_image)
+
 void
 tx_msg(void *src, int len)
 {
     boot_serial_input(src, len);
 }
 
-TEST_CASE(boot_serial_setup)
-{
-
-}
-
-TEST_CASE(boot_serial_empty_msg)
-{
-    char buf[4];
-    struct nmgr_hdr hdr;
-
-    boot_serial_input(buf, 0);
-
-    tx_msg(buf, 0);
-
-    strcpy(buf, "--");
-    tx_msg(buf, 2);
-
-    memset(&hdr, 0, sizeof(hdr));
-    tx_msg(&hdr, sizeof(hdr));
-
-    hdr.nh_op = NMGR_OP_WRITE;
-
-    tx_msg(&hdr, sizeof(hdr));
-}
-
-TEST_CASE(boot_serial_empty_img_msg)
-{
-    char buf[sizeof(struct nmgr_hdr) + 32];
-    struct nmgr_hdr *hdr;
-
-    hdr = (struct nmgr_hdr *)buf;
-    memset(hdr, 0, sizeof(*hdr));
-    hdr->nh_op = NMGR_OP_WRITE;
-    hdr->nh_group = htons(NMGR_GROUP_ID_IMAGE);
-    hdr->nh_id = IMGMGR_NMGR_OP_UPLOAD;
-    hdr->nh_len = htons(2);
-    strcpy((char *)(hdr + 1), "{}");
-
-    tx_msg(buf, sizeof(*hdr) + 2);
-}
-
-TEST_CASE(boot_serial_img_msg)
-{
-    char img[16];
-    char enc_img[BASE64_ENCODE_SIZE(sizeof(img)) + 1];
-    char buf[sizeof(struct nmgr_hdr) + sizeof(enc_img) + 32];
-    int len;
-    int rc;
-    struct nmgr_hdr *hdr;
-    const struct flash_area *fap;
-
-    memset(img, 0xa5, sizeof(img));
-    len = base64_encode(img, sizeof(img), enc_img, 1);
-    assert(len > 0);
-    enc_img[len] = '\0';
-
-    hdr = (struct nmgr_hdr *)buf;
-    memset(hdr, 0, sizeof(*hdr));
-    hdr->nh_op = NMGR_OP_WRITE;
-    hdr->nh_group = htons(NMGR_GROUP_ID_IMAGE);
-    hdr->nh_id = IMGMGR_NMGR_OP_UPLOAD;
-
-    len = sprintf((char *)(hdr + 1), "{\"off\":0,\"len\":16,\"data\":\"%s\"}",
-      enc_img);
-    hdr->nh_len = htons(len);
-
-    len = sizeof(*hdr) + len;
-
-    tx_msg(buf, len);
-
-    /*
-     * Validate contents inside image 0 slot
-     */
-    rc = flash_area_open(FLASH_AREA_IMAGE_0, &fap);
-    assert(rc == 0);
-
-    rc = flash_area_read(fap, 0, enc_img, sizeof(img));
-    assert(rc == 0);
-    assert(!memcmp(enc_img, img, sizeof(img)));
-}
-
-TEST_CASE(boot_serial_upload_bigger_image)
-{
-    char img[256];
-    char enc_img[64];
-    char buf[sizeof(struct nmgr_hdr) + 128];
-    int len;
-    int off;
-    int rc;
-    struct nmgr_hdr *hdr;
-    const struct flash_area *fap;
-    int i;
-
-    for (i = 0; i < sizeof(img); i++) {
-        img[i] = i;
-    }
-
-    for (off = 0; off < sizeof(img); off += 32) {
-        len = base64_encode(&img[off], 32, enc_img, 1);
-        assert(len > 0);
-        enc_img[len] = '\0';
-
-        hdr = (struct nmgr_hdr *)buf;
-        memset(hdr, 0, sizeof(*hdr));
-        hdr->nh_op = NMGR_OP_WRITE;
-        hdr->nh_group = htons(NMGR_GROUP_ID_IMAGE);
-        hdr->nh_id = IMGMGR_NMGR_OP_UPLOAD;
-
-        if (off) {
-            len = sprintf((char *)(hdr + 1), "{\"off\":%d,\"data\":\"%s\"}",
-              off, enc_img);
-        } else {
-            len = sprintf((char *)(hdr + 1), "{\"off\": 0 ,\"len\":%ld, "
-              "\"data\":\"%s\"}", (long)sizeof(img), enc_img);
-        }
-        hdr->nh_len = htons(len);
-
-        len = sizeof(*hdr) + len;
-
-        tx_msg(buf, len);
-    }
-
-    /*
-     * Validate contents inside image 0 slot
-     */
-    rc = flash_area_open(FLASH_AREA_IMAGE_0, &fap);
-    assert(rc == 0);
-
-    for (off = 0; off < sizeof(img); off += sizeof(enc_img)) {
-        rc = flash_area_read(fap, off, enc_img, sizeof(enc_img));
-        assert(rc == 0);
-        assert(!memcmp(enc_img, &img[off], sizeof(enc_img)));
-    }
-}
-
 TEST_SUITE(boot_serial_suite)
 {
     boot_serial_setup();
@@ -195,12 +65,11 @@ boot_serial_test(void)
 int
 main(void)
 {
-    tu_config.tc_print_results = 1;
+    ts_config.ts_print_results = 1;
     tu_init();
 
     boot_serial_test();
 
     return tu_any_failed;
 }
-
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/boot_serial/test/src/boot_test.h
----------------------------------------------------------------------
diff --git a/boot/boot_serial/test/src/boot_test.h 
b/boot/boot_serial/test/src/boot_test.h
new file mode 100644
index 0000000..b517a04
--- /dev/null
+++ b/boot/boot_serial/test/src/boot_test.h
@@ -0,0 +1,49 @@
+/*
+ * 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 _BOOT_TEST_H
+#define _BOOT_TEST_H
+
+#include <assert.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include "syscfg/syscfg.h"
+#include "sysflash/sysflash.h"
+#include "os/endian.h"
+#include "base64/base64.h"
+#include "crc/crc16.h"
+#include "testutil/testutil.h"
+#include "hal/hal_flash.h"
+#include "flash_map/flash_map.h"
+
+#include "boot_serial_priv.h"
+
+#ifdef __cplusplus
+#extern "C" {
+#endif
+
+void tx_msg(void *src, int len);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _BOOT_TEST_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/boot_serial/test/src/testcases/boot_serial_empty_img_msg.c
----------------------------------------------------------------------
diff --git a/boot/boot_serial/test/src/testcases/boot_serial_empty_img_msg.c 
b/boot/boot_serial/test/src/testcases/boot_serial_empty_img_msg.c
new file mode 100644
index 0000000..88a4ee8
--- /dev/null
+++ b/boot/boot_serial/test/src/testcases/boot_serial_empty_img_msg.c
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include "boot_test.h"
+
+TEST_CASE(boot_serial_empty_img_msg)
+{
+    char buf[sizeof(struct nmgr_hdr) + 32];
+    struct nmgr_hdr *hdr;
+
+    hdr = (struct nmgr_hdr *)buf;
+    memset(hdr, 0, sizeof(*hdr));
+    hdr->nh_op = NMGR_OP_WRITE;
+    hdr->nh_group = htons(NMGR_GROUP_ID_IMAGE);
+    hdr->nh_id = IMGMGR_NMGR_OP_UPLOAD;
+    hdr->nh_len = htons(2);
+    strcpy((char *)(hdr + 1), "{}");
+
+    tx_msg(buf, sizeof(*hdr) + 2);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/boot_serial/test/src/testcases/boot_serial_empty_msg.c
----------------------------------------------------------------------
diff --git a/boot/boot_serial/test/src/testcases/boot_serial_empty_msg.c 
b/boot/boot_serial/test/src/testcases/boot_serial_empty_msg.c
new file mode 100644
index 0000000..a4bd470
--- /dev/null
+++ b/boot/boot_serial/test/src/testcases/boot_serial_empty_msg.c
@@ -0,0 +1,39 @@
+/*
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_serial_empty_msg)
+{
+    char buf[4];
+    struct nmgr_hdr hdr;
+
+    boot_serial_input(buf, 0);
+
+    tx_msg(buf, 0);
+
+    strcpy(buf, "--");
+    tx_msg(buf, 2);
+
+    memset(&hdr, 0, sizeof(hdr));
+    tx_msg(&hdr, sizeof(hdr));
+
+    hdr.nh_op = NMGR_OP_WRITE;
+
+    tx_msg(&hdr, sizeof(hdr));
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/boot_serial/test/src/testcases/boot_serial_img_msg.c
----------------------------------------------------------------------
diff --git a/boot/boot_serial/test/src/testcases/boot_serial_img_msg.c 
b/boot/boot_serial/test/src/testcases/boot_serial_img_msg.c
new file mode 100644
index 0000000..7c5428f
--- /dev/null
+++ b/boot/boot_serial/test/src/testcases/boot_serial_img_msg.c
@@ -0,0 +1,58 @@
+/*
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_serial_img_msg)
+{
+    char img[16];
+    char enc_img[BASE64_ENCODE_SIZE(sizeof(img)) + 1];
+    char buf[sizeof(struct nmgr_hdr) + sizeof(enc_img) + 32];
+    int len;
+    int rc;
+    struct nmgr_hdr *hdr;
+    const struct flash_area *fap;
+
+    memset(img, 0xa5, sizeof(img));
+    len = base64_encode(img, sizeof(img), enc_img, 1);
+    assert(len > 0);
+
+    hdr = (struct nmgr_hdr *)buf;
+    memset(hdr, 0, sizeof(*hdr));
+    hdr->nh_op = NMGR_OP_WRITE;
+    hdr->nh_group = htons(NMGR_GROUP_ID_IMAGE);
+    hdr->nh_id = IMGMGR_NMGR_OP_UPLOAD;
+
+    len = sprintf((char *)(hdr + 1),
+                  "{\"off\":0,\"len\":16,\"data\":\"%s\"}", enc_img);
+    hdr->nh_len = htons(len);
+
+    len = sizeof(*hdr) + len;
+
+    tx_msg(buf, len);
+
+    /*
+     * Validate contents inside image 0 slot
+     */
+    rc = flash_area_open(FLASH_AREA_IMAGE_0, &fap);
+    assert(rc == 0);
+
+    rc = flash_area_read(fap, 0, enc_img, sizeof(img));
+    assert(rc == 0);
+    assert(!memcmp(enc_img, img, sizeof(img)));
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/boot_serial/test/src/testcases/boot_serial_setup.c
----------------------------------------------------------------------
diff --git a/boot/boot_serial/test/src/testcases/boot_serial_setup.c 
b/boot/boot_serial/test/src/testcases/boot_serial_setup.c
new file mode 100644
index 0000000..791e845
--- /dev/null
+++ b/boot/boot_serial/test/src/testcases/boot_serial_setup.c
@@ -0,0 +1,24 @@
+/*
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_serial_setup)
+{
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/boot_serial/test/src/testcases/boot_serial_upload_bigger_image.c
----------------------------------------------------------------------
diff --git 
a/boot/boot_serial/test/src/testcases/boot_serial_upload_bigger_image.c 
b/boot/boot_serial/test/src/testcases/boot_serial_upload_bigger_image.c
new file mode 100644
index 0000000..b551bb2
--- /dev/null
+++ b/boot/boot_serial/test/src/testcases/boot_serial_upload_bigger_image.c
@@ -0,0 +1,72 @@
+/*
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_serial_upload_bigger_image)
+{
+    char img[256];
+    char enc_img[64];
+    char buf[sizeof(struct nmgr_hdr) + 128];
+    int len;
+    int off;
+    int rc;
+    struct nmgr_hdr *hdr;
+    const struct flash_area *fap;
+    int i;
+
+    for (i = 0; i < sizeof(img); i++) {
+        img[i] = i;
+    }
+
+    for (off = 0; off < sizeof(img); off += 32) {
+        len = base64_encode(&img[off], 32, enc_img, 1);
+        assert(len > 0);
+
+        hdr = (struct nmgr_hdr *)buf;
+        memset(hdr, 0, sizeof(*hdr));
+        hdr->nh_op = NMGR_OP_WRITE;
+        hdr->nh_group = htons(NMGR_GROUP_ID_IMAGE);
+        hdr->nh_id = IMGMGR_NMGR_OP_UPLOAD;
+
+        if (off) {
+            len = sprintf((char *)(hdr + 1), "{\"off\":%d,\"data\":\"%s\"}",
+              off, enc_img);
+        } else {
+            len = sprintf((char *)(hdr + 1), "{\"off\": 0 ,\"len\":%ld, "
+              "\"data\":\"%s\"}", (long)sizeof(img), enc_img);
+        }
+        hdr->nh_len = htons(len);
+
+        len = sizeof(*hdr) + len;
+
+        tx_msg(buf, len);
+    }
+
+    /*
+     * Validate contents inside image 0 slot
+     */
+    rc = flash_area_open(FLASH_AREA_IMAGE_0, &fap);
+    assert(rc == 0);
+
+    for (off = 0; off < sizeof(img); off += sizeof(enc_img)) {
+        rc = flash_area_read(fap, off, enc_img, sizeof(enc_img));
+        assert(rc == 0);
+        assert(!memcmp(enc_img, &img[off], sizeof(enc_img)));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/boot_test.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/boot_test.c 
b/boot/bootutil/test/src/boot_test.c
index 65715d6..269db36 100644
--- a/boot/bootutil/test/src/boot_test.c
+++ b/boot/bootutil/test/src/boot_test.c
@@ -38,7 +38,7 @@
 #define BOOT_TEST_HEADER_SIZE       0x200
 
 /** Internal flash layout. */
-static struct flash_area boot_test_area_descs[] = {
+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 },
@@ -50,12 +50,12 @@ static struct flash_area boot_test_area_descs[] = {
 };
 
 /** Areas representing the beginning of image slots. */
-static uint8_t boot_test_slot_areas[] = {
+uint8_t boot_test_slot_areas[] = {
     0, 3,
 };
 
 /** Flash offsets of the two image slots. */
-static struct {
+struct {
     uint8_t flash_id;
     uint32_t address;
 } boot_test_img_addrs[] = {
@@ -68,7 +68,7 @@ static struct {
 
 #define BOOT_TEST_AREA_IDX_SCRATCH 6
 
-static uint8_t
+uint8_t
 boot_test_util_byte_at(int img_msb, uint32_t image_offset)
 {
     uint32_t u32;
@@ -80,7 +80,7 @@ boot_test_util_byte_at(int img_msb, uint32_t image_offset)
     return u8p[image_offset % 4];
 }
 
-static void
+void
 boot_test_util_init_flash(void)
 {
     const struct flash_area *area_desc;
@@ -98,7 +98,7 @@ boot_test_util_init_flash(void)
     }
 }
 
-static void
+void
 boot_test_util_copy_area(int from_area_idx, int to_area_idx)
 {
     const struct flash_area *from_area_desc;
@@ -164,7 +164,7 @@ boot_test_util_area_write_size(int dst_idx, uint32_t off, 
uint32_t size)
     return size;
 }
 
-static void
+void
 boot_test_util_swap_areas(int area_idx1, int area_idx2)
 {
     const struct flash_area *area_desc1;
@@ -209,7 +209,7 @@ boot_test_util_swap_areas(int area_idx1, int area_idx2)
     free(buf2);
 }
 
-static void
+void
 boot_test_util_write_image(const struct image_header *hdr, int slot)
 {
     uint32_t image_off;
@@ -249,7 +249,7 @@ boot_test_util_write_image(const struct image_header *hdr, 
int slot)
     }
 }
 
-static void
+void
 boot_test_util_write_hash(const struct image_header *hdr, int slot)
 {
     uint8_t tmpdata[1024];
@@ -292,7 +292,7 @@ boot_test_util_write_hash(const struct image_header *hdr, 
int slot)
     TEST_ASSERT(rc == 0);
 }
 
-static void
+void
 boot_test_util_verify_area(const struct flash_area *area_desc,
                            const struct image_header *hdr,
                            uint32_t image_addr, int img_msb)
@@ -366,7 +366,7 @@ boot_test_util_verify_area(const struct flash_area 
*area_desc,
     }
 }
 
-static void
+void
 boot_test_util_verify_status_clear(void)
 {
     struct boot_img_trailer bit;
@@ -383,7 +383,7 @@ boot_test_util_verify_status_clear(void)
       bit.bit_copy_done != 0xff);
 }
 
-static void
+void
 boot_test_util_verify_flash(const struct image_header *hdr0, int orig_slot_0,
                             const struct image_header *hdr1, int orig_slot_1)
 {
@@ -416,7 +416,7 @@ boot_test_util_verify_flash(const struct image_header 
*hdr0, int orig_slot_0,
     }
 }
 
-static void
+void
 boot_test_util_verify_all(const struct boot_req *req, int expected_swap_type,
                           const struct image_header *hdr0,
                           const struct image_header *hdr1)
@@ -490,665 +490,23 @@ boot_test_util_verify_all(const struct boot_req *req, 
int expected_swap_type,
     }
 }
 
-TEST_CASE(boot_test_nv_ns_10)
-{
-    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_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr, NULL);
-}
-
-TEST_CASE(boot_test_nv_ns_01)
-{
-    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_test_util_verify_all(&req, BOOT_SWAP_TYPE_PERM, NULL, &hdr);
-}
-
-TEST_CASE(boot_test_nv_ns_11)
-{
-    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);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr0, &hdr1);
-}
-
-TEST_CASE(boot_test_vm_ns_10)
-{
-    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_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr, NULL);
-}
-
-TEST_CASE(boot_test_vm_ns_01)
-{
-    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_set_pending(1);
-    TEST_ASSERT(rc == 0);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_PERM, NULL, &hdr);
-}
-
-TEST_CASE(boot_test_vm_ns_11_a)
-{
-    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);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr0, &hdr1);
-}
-
-TEST_CASE(boot_test_vm_ns_11_b)
-{
-    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_set_pending(1);
-    TEST_ASSERT(rc == 0);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1);
-}
-
-TEST_CASE(boot_test_vm_ns_11_2areas)
-{
-    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_set_pending(1);
-    TEST_ASSERT(rc == 0);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1);
-}
-
-TEST_CASE(boot_test_nv_bs_10)
-{
-    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);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr, NULL);
-}
-
-TEST_CASE(boot_test_nv_bs_11)
-{
-    struct boot_status status;
-    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);
-    rc = boot_set_pending(1);
-    boot_test_util_copy_area(5, BOOT_TEST_AREA_IDX_SCRATCH);
-
-    boot_req_set(&req);
-    status.idx = 0;
-    status.elem_sz = 1;
-    status.state = 1;
-
-    rc = boot_write_status(&status);
-    TEST_ASSERT(rc == 0);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1);
-}
-
-TEST_CASE(boot_test_nv_bs_11_2areas)
-{
-    struct boot_status status;
-    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 = 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(2, 5);
-
-    rc = boot_set_pending(1);
-    TEST_ASSERT_FATAL(rc == 0);
-
-    status.idx = 1;
-    status.elem_sz = 1;
-    status.state = 0;
-
-    rc = boot_write_status(&status);
-    TEST_ASSERT_FATAL(rc == 0);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1);
-}
-
-TEST_CASE(boot_test_vb_ns_11)
-{
-    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_set_pending(1);
-    TEST_ASSERT_FATAL(rc == 0);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1);
-}
-
-TEST_CASE(boot_test_no_hash)
-{
-    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 = 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(&hdr0, 0);
-    boot_test_util_write_hash(&hdr0, 0);
-    boot_test_util_write_image(&hdr1, 1);
-
-    rc = boot_set_pending(1);
-    TEST_ASSERT_FATAL(rc == 0);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr0, NULL);
-}
-
-TEST_CASE(boot_test_no_flag_has_hash)
-{
-    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 = 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(&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_set_pending(1);
-    TEST_ASSERT(rc == 0);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr0, NULL);
-}
-
-TEST_CASE(boot_test_invalid_hash)
-{
-    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 = 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(&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_set_pending(1);
-    TEST_ASSERT(rc == 0);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr0, NULL);
-}
-
-TEST_CASE(boot_test_revert)
-{
-    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);
-
-    /* Indicate that the image in slot 0 is being tested. */
-    boot_set_copy_done();
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_PERM, &hdr0, &hdr1);
-}
-
-TEST_CASE(boot_test_revert_continue)
-{
-    struct boot_status status;
-    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);
-
-    boot_test_util_swap_areas(2, 5);
-
-    /* Indicate that the image in slot 0 is being tested. */
-    boot_set_copy_done();
-
-    status.idx = 1;
-    status.elem_sz = 1;
-    status.state = 0;
-
-    rc = boot_write_status(&status);
-    TEST_ASSERT_FATAL(rc == 0);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_PERM, &hdr0, &hdr1);
-}
+TEST_CASE_DECL(boot_test_nv_ns_10)
+TEST_CASE_DECL(boot_test_nv_ns_01)
+TEST_CASE_DECL(boot_test_nv_ns_11)
+TEST_CASE_DECL(boot_test_vm_ns_10)
+TEST_CASE_DECL(boot_test_vm_ns_01)
+TEST_CASE_DECL(boot_test_vm_ns_11_a)
+TEST_CASE_DECL(boot_test_vm_ns_11_b)
+TEST_CASE_DECL(boot_test_vm_ns_11_2areas)
+TEST_CASE_DECL(boot_test_nv_bs_10)
+TEST_CASE_DECL(boot_test_nv_bs_11)
+TEST_CASE_DECL(boot_test_nv_bs_11_2areas)
+TEST_CASE_DECL(boot_test_vb_ns_11)
+TEST_CASE_DECL(boot_test_no_hash)
+TEST_CASE_DECL(boot_test_no_flag_has_hash)
+TEST_CASE_DECL(boot_test_invalid_hash)
+TEST_CASE_DECL(boot_test_revert)
+TEST_CASE_DECL(boot_test_revert_continue)
 
 TEST_SUITE(boot_test_main)
 {
@@ -1183,7 +541,7 @@ boot_test_all(void)
 int
 main(int argc, char **argv)
 {
-    tu_config.tc_print_results = 1;
+    ts_config.ts_print_results = 1;
     tu_parse_args(argc, argv);
 
     tu_init();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/boot_test.h
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/boot_test.h 
b/boot/bootutil/test/src/boot_test.h
new file mode 100644
index 0000000..25e2da2
--- /dev/null
+++ b/boot/bootutil/test/src/boot_test.h
@@ -0,0 +1,85 @@
+/**
+ * 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 _BOOT_TEST_H
+#define _BOOT_TEST_H
+
+#include <assert.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include "syscfg/syscfg.h"
+#include "sysflash/sysflash.h"
+#include "testutil/testutil.h"
+#include "hal/hal_flash.h"
+#include "flash_map/flash_map.h"
+#include "bootutil/image.h"
+#include "bootutil/loader.h"
+#include "bootutil/bootutil_misc.h"
+#include "../../src/bootutil_priv.h"
+#include "testutil/testutil.h"
+
+#include "mbedtls/sha256.h"
+
+#ifdef __cplusplus
+#extern "C" {
+#endif
+
+#define BOOT_TEST_HEADER_SIZE       0x200
+
+/** Internal flash layout. */
+extern struct flash_area boot_test_area_descs[];
+
+/** Areas representing the beginning of image slots. */
+extern uint8_t boot_test_slot_areas[];
+
+/** Flash offsets of the two image slots. */
+struct boot_test_img_addrs {
+    uint8_t flash_id;
+    uint32_t address;
+};
+extern struct boot_test_img_addrs boot_test_img_addrs[];
+
+#define BOOT_TEST_AREA_IDX_SCRATCH 6
+
+uint8_t boot_test_util_byte_at(int img_msb, uint32_t image_offset);
+void boot_test_util_init_flash(void);
+void boot_test_util_copy_area(int from_area_idx, int to_area_idx);
+void boot_test_util_swap_areas(int area_idx1, int area_idx2);
+void boot_test_util_write_image(const struct image_header *hdr,
+                                       int slot);
+void boot_test_util_write_hash(const struct image_header *hdr, int slot);
+void boot_test_util_verify_area(const struct flash_area *area_desc,
+                                       const struct image_header *hdr,
+                                       uint32_t image_addr, int img_msb);
+void boot_test_util_verify_status_clear(void);
+void boot_test_util_verify_flash(const struct image_header *hdr0,
+                                        int orig_slot_0,
+                                        const struct image_header *hdr1,
+                                        int orig_slot_1);
+void boot_test_util_verify_all(const struct boot_req *req,
+                               int expected_swap_type,
+                               const struct image_header *hdr0,
+                               const struct image_header *hdr1);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*_BOOT_TEST_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/boot_test_utils.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/boot_test_utils.c 
b/boot/bootutil/test/src/boot_test_utils.c
new file mode 100644
index 0000000..160e81d
--- /dev/null
+++ b/boot/bootutil/test/src/boot_test_utils.c
@@ -0,0 +1,361 @@
+/**
+ * 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 "boot_test.h"
+
+/** Internal flash layout. */
+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 },
+    [7] = { 0 },
+};
+
+/** Areas representing the beginning of image slots. */
+uint8_t boot_test_slot_areas[] = {
+    0, 3,
+};
+
+/** Flash offsets of the two image slots. */
+struct boot_test_img_addrs boot_test_img_addrs[] = {
+    { 0, 0x20000 },
+    { 0, 0x80000 },
+};
+
+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];
+}
+
+
+void
+boot_test_util_init_flash(void)
+{
+    const struct flash_area *area_desc;
+    int rc;
+
+    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);
+    }
+}
+
+
+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);
+}
+
+
+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);
+}
+
+
+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;
+    }
+}
+
+
+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);
+}
+
+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_device_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_device_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;
+    }
+}
+
+
+void
+boot_test_util_verify_status_clear(void)
+{
+    struct boot_img_trailer bit;
+    const struct flash_area *fap;
+    int rc;
+
+    rc = flash_area_open(FLASH_AREA_IMAGE_0, &fap);
+    TEST_ASSERT(rc == 0);
+
+    rc = flash_area_read(fap, fap->fa_size - sizeof(bit), &bit, sizeof(bit));
+    TEST_ASSERT(rc == 0);
+
+    TEST_ASSERT(bit.bit_copy_start != BOOT_MAGIC_SWAP_TEMP ||
+      bit.bit_copy_done != 0xff);
+}
+
+
+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_device_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++;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_invalid_hash.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_invalid_hash.c 
b/boot/bootutil/test/src/testcases/boot_test_invalid_hash.c
new file mode 100644
index 0000000..af3e558
--- /dev/null
+++ b/boot/bootutil/test/src/testcases/boot_test_invalid_hash.c
@@ -0,0 +1,67 @@
+/*
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_test_invalid_hash)
+{
+    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 = 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(&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_set_pending(1);
+    TEST_ASSERT(rc == 0);
+
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr0, NULL);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_no_flag_has_hash.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_no_flag_has_hash.c 
b/boot/bootutil/test/src/testcases/boot_test_no_flag_has_hash.c
new file mode 100644
index 0000000..c3d1636
--- /dev/null
+++ b/boot/bootutil/test/src/testcases/boot_test_no_flag_has_hash.c
@@ -0,0 +1,60 @@
+/**
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_test_no_flag_has_hash)
+{
+    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 = 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(&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_set_pending(1);
+    TEST_ASSERT(rc == 0);
+
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr0, NULL);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_no_hash.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_no_hash.c 
b/boot/bootutil/test/src/testcases/boot_test_no_hash.c
new file mode 100644
index 0000000..339753e
--- /dev/null
+++ b/boot/bootutil/test/src/testcases/boot_test_no_hash.c
@@ -0,0 +1,59 @@
+/**
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_test_no_hash)
+{
+    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 = 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(&hdr0, 0);
+    boot_test_util_write_hash(&hdr0, 0);
+    boot_test_util_write_image(&hdr1, 1);
+
+    rc = boot_set_pending(1);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr0, NULL);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_nv_bs_10.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_nv_bs_10.c 
b/boot/bootutil/test/src/testcases/boot_test_nv_bs_10.c
new file mode 100644
index 0000000..cced9fb
--- /dev/null
+++ b/boot/bootutil/test/src/testcases/boot_test_nv_bs_10.c
@@ -0,0 +1,47 @@
+/**
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_test_nv_bs_10)
+{
+    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);
+
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr, NULL);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_nv_bs_11.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_nv_bs_11.c 
b/boot/bootutil/test/src/testcases/boot_test_nv_bs_11.c
new file mode 100644
index 0000000..3312ec4
--- /dev/null
+++ b/boot/bootutil/test/src/testcases/boot_test_nv_bs_11.c
@@ -0,0 +1,69 @@
+/**
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_test_nv_bs_11)
+{
+    struct boot_status status;
+    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);
+    rc = boot_set_pending(1);
+    boot_test_util_copy_area(5, BOOT_TEST_AREA_IDX_SCRATCH);
+
+    boot_req_set(&req);
+    status.idx = 0;
+    status.elem_sz = 1;
+    status.state = 1;
+
+    rc = boot_write_status(&status);
+    TEST_ASSERT(rc == 0);
+
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_nv_bs_11_2areas.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_nv_bs_11_2areas.c 
b/boot/bootutil/test/src/testcases/boot_test_nv_bs_11_2areas.c
new file mode 100644
index 0000000..11a8a6f
--- /dev/null
+++ b/boot/bootutil/test/src/testcases/boot_test_nv_bs_11_2areas.c
@@ -0,0 +1,71 @@
+/**
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_test_nv_bs_11_2areas)
+{
+    struct boot_status status;
+    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 = 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(2, 5);
+
+    rc = boot_set_pending(1);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    status.idx = 1;
+    status.elem_sz = 1;
+    status.state = 0;
+
+    rc = boot_write_status(&status);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_nv_ns_01.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_nv_ns_01.c 
b/boot/bootutil/test/src/testcases/boot_test_nv_ns_01.c
new file mode 100644
index 0000000..c887eca
--- /dev/null
+++ b/boot/bootutil/test/src/testcases/boot_test_nv_ns_01.c
@@ -0,0 +1,45 @@
+/**
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_test_nv_ns_01)
+{
+    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_test_util_verify_all(&req, BOOT_SWAP_TYPE_PERM, NULL, &hdr);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_nv_ns_10.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_nv_ns_10.c 
b/boot/bootutil/test/src/testcases/boot_test_nv_ns_10.c
new file mode 100644
index 0000000..a6bbff2
--- /dev/null
+++ b/boot/bootutil/test/src/testcases/boot_test_nv_ns_10.c
@@ -0,0 +1,45 @@
+/**
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_test_nv_ns_10)
+{
+    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_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr, NULL);
+}


Reply via email to