This closes #114.

Merge remote-tracking branch 'peterfs/ci-testing' into develop

* peterfs/ci-testing:
  Unit test infrastructure


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

Branch: refs/heads/develop
Commit: 914236c1c72d3d2df8743cb80e0aa6cc44628d05
Parents: c76c680 75101ba
Author: Christopher Collins <ccoll...@apache.org>
Authored: Mon Oct 17 16:53:59 2016 -0700
Committer: Christopher Collins <ccoll...@apache.org>
Committed: Mon Oct 17 16:53:59 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              | 1148 +--
 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, 20770 insertions(+), 15639 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/914236c1/boot/bootutil/test/src/boot_test.c
----------------------------------------------------------------------
diff --cc boot/bootutil/test/src/boot_test.c
index 205993c,269db36..68cabc0
--- a/boot/bootutil/test/src/boot_test.c
+++ b/boot/bootutil/test/src/boot_test.c
@@@ -34,1135 -35,478 +34,23 @@@
  
  #include "mbedtls/sha256.h"
  
--#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 },
--    [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. */
- 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[] = {
--    { 0, 0x20000 },
--    { 0, 0x80000 },
--};
 -
 -/** Three areas per image slot */
 -#define BOOT_TEST_IMAGE_NUM_AREAS  3
--
--#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;
--    uint8_t *u8p;
--
--    TEST_ASSERT(image_offset < 0x01000000);
--    u32 = image_offset + (img_msb << 24);
--    u8p = (void *)&u32;
--    return u8p[image_offset % 4];
--}
--
- static void
 -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);
--    }
--}
--
- static void
 -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 uint32_t
--boot_test_util_area_write_size(int dst_idx, uint32_t off, uint32_t size)
--{
--    const struct flash_area *desc;
--    int64_t diff;
--    uint32_t trailer_start;
 -    int i;
--
-     if (dst_idx != BOOT_TEST_AREA_IDX_SCRATCH - 1) {
-         return size;
-     }
 -    for (i = 0;
 -         i < sizeof boot_test_slot_areas / sizeof boot_test_slot_areas[0];
 -         i++) {
--
-     /* Don't include trailer in copy to second slot. */
-     desc = boot_test_area_descs + dst_idx;
-     trailer_start = desc->fa_size - boot_status_sz(1);
-     diff = off + size - trailer_start;
-     if (diff > 0) {
-         if (diff > size) {
-             size = 0;
-         } else {
-             size -= diff;
 -        /* Don't include trailer in copy. */
 -        if (dst_idx ==
 -            boot_test_slot_areas[i] + BOOT_TEST_IMAGE_NUM_AREAS - 1) {
 -
 -            desc = boot_test_area_descs + dst_idx;
 -            trailer_start = desc->fa_size - boot_status_sz();
 -            diff = off + size - trailer_start;
 -            if (diff > 0) {
 -                if (diff > size) {
 -                    size = 0;
 -                } else {
 -                    size -= diff;
 -                }
 -            }
 -
 -            break;
--        }
--    }
--
--    return size;
--}
--
- static void
 -void
--boot_test_util_swap_areas(int area_idx1, int area_idx2)
--{
--    const struct flash_area *area_desc1;
--    const struct flash_area *area_desc2;
--    uint32_t size;
--    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);
--
--    size = boot_test_util_area_write_size(area_idx1, 0, area_desc1->fa_size);
--    rc = flash_area_write(area_desc1, 0, buf2, size);
--    TEST_ASSERT(rc == 0);
--
--    size = boot_test_util_area_write_size(area_idx2, 0, area_desc2->fa_size);
--    rc = flash_area_write(area_desc2, 0, buf1, size);
--    TEST_ASSERT(rc == 0);
--
--    free(buf1);
--    free(buf2);
--}
--
- static void
 -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
 -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_write_bit(int flash_area_id, struct boot_img_trailer *bit)
- {
-     const struct flash_area *fap;
-     int rc;
- 
-     /* XXX: This function only works by chance.  It requires that the boot
-      * loader have have been run once already so that its global state has 
been
-      * populated.
-      */
- 
-     rc = flash_area_open(flash_area_id, &fap);
-     TEST_ASSERT_FATAL(rc == 0);
- 
-     rc = flash_area_write(fap, fap->fa_size - sizeof *bit, bit, sizeof *bit);
-     TEST_ASSERT_FATAL(rc == 0);
- }
- 
- static void
- boot_test_util_mark_revert(void)
- {
-     struct boot_img_trailer bit_slot0 = {
-         .bit_copy_start = BOOT_IMG_MAGIC,
-         .bit_copy_done = 0x01,
-         .bit_img_ok = 0xff,
-         ._pad = 0xffff,
-     };
- 
-     boot_test_util_write_bit(FLASH_AREA_IMAGE_0, &bit_slot0);
--}
--
- 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)
--{
--    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;
--    }
--}
--
- static void
 -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_IMG_MAGIC ||
 -    TEST_ASSERT(bit.bit_copy_start != BOOT_MAGIC_SWAP_TEMP ||
--      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)
--{
--    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++;
--    }
--}
--
- 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)
--{
--    const struct image_header *slot0hdr;
--    const struct image_header *slot1hdr;
--    struct boot_rsp rsp;
--    int orig_slot_0;
--    int orig_slot_1;
--    int num_swaps;
--    int rc;
--    int i;
--
--    TEST_ASSERT_FATAL(req != NULL);
--    TEST_ASSERT_FATAL(hdr0 != NULL || hdr1 != NULL);
--
--    num_swaps = 0;
--    for (i = 0; i < 3; i++) {
--        rc = boot_go(req, &rsp);
--        TEST_ASSERT_FATAL(rc == 0);
--
--        if (expected_swap_type != BOOT_SWAP_TYPE_NONE) {
--            num_swaps++;
--        }
--
--        if (num_swaps % 2 == 0) {
--            if (hdr0 != NULL) {
--                slot0hdr = hdr0;
--                slot1hdr = hdr1;
--            } else {
--                slot0hdr = hdr1;
--                slot1hdr = hdr0;
--            }
--            orig_slot_0 = 0;
--            orig_slot_1 = 1;
--        } else {
--            if (hdr1 != NULL) {
--                slot0hdr = hdr1;
--                slot1hdr = hdr0;
--            } else {
--                slot0hdr = hdr0;
--                slot1hdr = hdr1;
--            }
--            orig_slot_0 = 1;
--            orig_slot_1 = 0;
--        }
--
--        TEST_ASSERT(memcmp(rsp.br_hdr, slot0hdr, sizeof *slot0hdr) == 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(slot0hdr, orig_slot_0,
--                                    slot1hdr, orig_slot_1);
--        boot_test_util_verify_status_clear();
--
--        if (expected_swap_type != BOOT_SWAP_TYPE_NONE) {
--            switch (expected_swap_type) {
-             case BOOT_SWAP_TYPE_TEST:
-                 expected_swap_type = BOOT_SWAP_TYPE_REVERT;
 -            case BOOT_SWAP_TYPE_TEMP:
 -                expected_swap_type = BOOT_SWAP_TYPE_PERM;
--                break;
--
-             case BOOT_SWAP_TYPE_REVERT:
 -            case BOOT_SWAP_TYPE_PERM:
--                expected_swap_type = BOOT_SWAP_TYPE_NONE;
--                break;
--
--            default:
--                TEST_ASSERT_FATAL(0);
--                break;
--            }
--        }
--    }
- }
- 
- 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_set_pending(1);
- 
-     boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_REVERT, 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_REVERT, 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_TEST, &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_TEST, &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_TEST, &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);
-     rc = boot_set_pending(1);
-     TEST_ASSERT_FATAL(rc == 0);
- 
-     boot_test_util_swap_areas(2, 5);
- 
-     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_TEST, &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(rc == 0);
- 
-     boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEST, &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(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_test_util_mark_revert();
- 
-     boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_REVERT, &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);
- 
-     /* Indicate that the image in slot 0 is being tested. */
-     boot_test_util_mark_revert();
- 
-     boot_test_util_swap_areas(2, 5);
- 
-     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_REVERT, &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)
  {

Reply via email to