You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/10/17 23:59:42 UTC
[16/16] incubator-mynewt-core git commit: Fix some minor unit test
merge issues.
Fix some minor unit test merge issues.
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/7aa94c51
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/7aa94c51
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/7aa94c51
Branch: refs/heads/develop
Commit: 7aa94c51a3749dda2a66e6e3f7a39546a1f4ee9c
Parents: 914236c
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Oct 17 17:00:19 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Oct 17 17:00:19 2016 -0700
----------------------------------------------------------------------
boot/bootutil/test/src/boot_test.h | 8 +-
boot/bootutil/test/src/boot_test_utils.c | 143 ++++++++++++++++++-
.../test/src/testcases/boot_test_no_hash.c | 2 +-
.../test/src/testcases/boot_test_nv_bs_10.c | 2 +-
.../test/src/testcases/boot_test_nv_bs_11.c | 2 +-
.../src/testcases/boot_test_nv_bs_11_2areas.c | 7 +-
.../test/src/testcases/boot_test_nv_ns_01.c | 4 +-
.../test/src/testcases/boot_test_revert.c | 7 +-
.../src/testcases/boot_test_revert_continue.c | 8 +-
.../test/src/testcases/boot_test_vb_ns_11.c | 4 +-
.../test/src/testcases/boot_test_vm_ns_01.c | 2 +-
.../src/testcases/boot_test_vm_ns_11_2areas.c | 2 +-
.../test/src/testcases/boot_test_vm_ns_11_b.c | 2 +-
net/ip/mn_socket/test/src/mn_sock_test.c | 2 +
14 files changed, 165 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7aa94c51/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
index 25e2da2..e883c8f 100644
--- a/boot/bootutil/test/src/boot_test.h
+++ b/boot/bootutil/test/src/boot_test.h
@@ -31,15 +31,14 @@
#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 "bootutil/bootutil.h"
+#include "bootutil_priv.h"
#include "testutil/testutil.h"
#include "mbedtls/sha256.h"
#ifdef __cplusplus
-#extern "C" {
+extern "C" {
#endif
#define BOOT_TEST_HEADER_SIZE 0x200
@@ -66,6 +65,7 @@ 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_mark_revert(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);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7aa94c51/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
index 160e81d..3040604 100644
--- a/boot/bootutil/test/src/boot_test_utils.c
+++ b/boot/bootutil/test/src/boot_test_utils.c
@@ -42,6 +42,8 @@ struct boot_test_img_addrs boot_test_img_addrs[] = {
{ 0, 0x80000 },
};
+#define BOOT_TEST_AREA_IDX_SCRATCH 6
+
uint8_t
boot_test_util_byte_at(int img_msb, uint32_t image_offset)
{
@@ -73,7 +75,6 @@ boot_test_util_init_flash(void)
}
}
-
void
boot_test_util_copy_area(int from_area_idx, int to_area_idx)
{
@@ -106,12 +107,38 @@ boot_test_util_copy_area(int from_area_idx, int to_area_idx)
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;
+
+ if (dst_idx != BOOT_TEST_AREA_IDX_SCRATCH - 1) {
+ return size;
+ }
+
+ /* 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;
+ }
+ }
+
+ return size;
+}
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;
@@ -139,17 +166,18 @@ boot_test_util_swap_areas(int area_idx1, int area_idx2)
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);
+ 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);
- rc = flash_area_write(area_desc2, 0, buf1, area_desc2->fa_size);
+ 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);
}
-
void
boot_test_util_write_image(const struct image_header *hdr, int slot)
{
@@ -235,6 +263,37 @@ boot_test_util_write_hash(const struct image_header *hdr, int slot)
}
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);
+}
+
+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);
+}
+
+void
boot_test_util_verify_area(const struct flash_area *area_desc,
const struct image_header *hdr,
uint32_t image_addr, int img_msb)
@@ -322,7 +381,7 @@ boot_test_util_verify_status_clear(void)
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 ||
+ TEST_ASSERT(bit.bit_copy_start != BOOT_IMG_MAGIC ||
bit.bit_copy_done != 0xff);
}
@@ -359,3 +418,77 @@ boot_test_util_verify_flash(const struct image_header *hdr0, int orig_slot_0,
area_idx++;
}
}
+
+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;
+ break;
+
+ case BOOT_SWAP_TYPE_REVERT:
+ expected_swap_type = BOOT_SWAP_TYPE_NONE;
+ break;
+
+ default:
+ TEST_ASSERT_FATAL(0);
+ break;
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7aa94c51/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
index 339753e..0ce1a54 100644
--- a/boot/bootutil/test/src/testcases/boot_test_no_hash.c
+++ b/boot/bootutil/test/src/testcases/boot_test_no_hash.c
@@ -53,7 +53,7 @@ TEST_CASE(boot_test_no_hash)
boot_test_util_write_image(&hdr1, 1);
rc = boot_set_pending(1);
- TEST_ASSERT_FATAL(rc == 0);
+ 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/7aa94c51/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
index cced9fb..bb7bc9c 100644
--- a/boot/bootutil/test/src/testcases/boot_test_nv_bs_10.c
+++ b/boot/bootutil/test/src/testcases/boot_test_nv_bs_10.c
@@ -41,7 +41,7 @@ TEST_CASE(boot_test_nv_bs_10)
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_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/7aa94c51/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
index 3312ec4..86146b1 100644
--- a/boot/bootutil/test/src/testcases/boot_test_nv_bs_11.c
+++ b/boot/bootutil/test/src/testcases/boot_test_nv_bs_11.c
@@ -65,5 +65,5 @@ TEST_CASE(boot_test_nv_bs_11)
rc = boot_write_status(&status);
TEST_ASSERT(rc == 0);
- boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1);
+ boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEST, &hdr0, &hdr1);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7aa94c51/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
index 11a8a6f..e427f36 100644
--- 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
@@ -54,12 +54,11 @@ TEST_CASE(boot_test_nv_bs_11_2areas)
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);
+ boot_test_util_swap_areas(2, 5);
+
status.idx = 1;
status.elem_sz = 1;
status.state = 0;
@@ -67,5 +66,5 @@ TEST_CASE(boot_test_nv_bs_11_2areas)
rc = boot_write_status(&status);
TEST_ASSERT_FATAL(rc == 0);
- boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1);
+ boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEST, &hdr0, &hdr1);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7aa94c51/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
index c887eca..00a1967 100644
--- a/boot/bootutil/test/src/testcases/boot_test_nv_ns_01.c
+++ b/boot/bootutil/test/src/testcases/boot_test_nv_ns_01.c
@@ -41,5 +41,7 @@ TEST_CASE(boot_test_nv_ns_01)
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);
+ boot_set_pending(1);
+
+ boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_REVERT, NULL, &hdr);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7aa94c51/boot/bootutil/test/src/testcases/boot_test_revert.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_revert.c b/boot/bootutil/test/src/testcases/boot_test_revert.c
index d49d42d..f564f7c 100644
--- a/boot/bootutil/test/src/testcases/boot_test_revert.c
+++ b/boot/bootutil/test/src/testcases/boot_test_revert.c
@@ -20,8 +20,7 @@
TEST_CASE(boot_test_revert)
{
- struct image_header hdr0 = {
- .ih_magic = IMAGE_MAGIC,
+ 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,
@@ -53,7 +52,7 @@ TEST_CASE(boot_test_revert)
boot_test_util_write_hash(&hdr1, 1);
/* Indicate that the image in slot 0 is being tested. */
- boot_set_copy_done();
+ boot_test_util_mark_revert();
- boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_PERM, &hdr0, &hdr1);
+ boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_REVERT, &hdr0, &hdr1);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7aa94c51/boot/bootutil/test/src/testcases/boot_test_revert_continue.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_revert_continue.c b/boot/bootutil/test/src/testcases/boot_test_revert_continue.c
index ec4f56c..4abd87f 100644
--- a/boot/bootutil/test/src/testcases/boot_test_revert_continue.c
+++ b/boot/bootutil/test/src/testcases/boot_test_revert_continue.c
@@ -55,10 +55,10 @@ TEST_CASE(boot_test_revert_continue)
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();
+ boot_test_util_mark_revert();
+
+ boot_test_util_swap_areas(2, 5);
status.idx = 1;
status.elem_sz = 1;
@@ -67,5 +67,5 @@ TEST_CASE(boot_test_revert_continue)
rc = boot_write_status(&status);
TEST_ASSERT_FATAL(rc == 0);
- boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_PERM, &hdr0, &hdr1);
+ boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_REVERT, &hdr0, &hdr1);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7aa94c51/boot/bootutil/test/src/testcases/boot_test_vb_ns_11.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_vb_ns_11.c b/boot/bootutil/test/src/testcases/boot_test_vb_ns_11.c
index 38fa8f9..0ac7480 100644
--- a/boot/bootutil/test/src/testcases/boot_test_vb_ns_11.c
+++ b/boot/bootutil/test/src/testcases/boot_test_vb_ns_11.c
@@ -55,7 +55,7 @@ TEST_CASE(boot_test_vb_ns_11)
boot_test_util_write_hash(&hdr1, 1);
rc = boot_set_pending(1);
- TEST_ASSERT_FATAL(rc == 0);
+ TEST_ASSERT(rc == 0);
- boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1);
+ boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEST, &hdr0, &hdr1);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7aa94c51/boot/bootutil/test/src/testcases/boot_test_vm_ns_01.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_vm_ns_01.c b/boot/bootutil/test/src/testcases/boot_test_vm_ns_01.c
index ac31824..b749f87 100644
--- a/boot/bootutil/test/src/testcases/boot_test_vm_ns_01.c
+++ b/boot/bootutil/test/src/testcases/boot_test_vm_ns_01.c
@@ -46,5 +46,5 @@ TEST_CASE(boot_test_vm_ns_01)
rc = boot_set_pending(1);
TEST_ASSERT(rc == 0);
- boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_PERM, NULL, &hdr);
+ boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_REVERT, NULL, &hdr);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7aa94c51/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_2areas.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_2areas.c b/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_2areas.c
index 84e6a91..6f75c31 100644
--- a/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_2areas.c
+++ b/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_2areas.c
@@ -57,5 +57,5 @@ TEST_CASE(boot_test_vm_ns_11_2areas)
rc = boot_set_pending(1);
TEST_ASSERT(rc == 0);
- boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1);
+ boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEST, &hdr0, &hdr1);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7aa94c51/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_b.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_b.c b/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_b.c
index f4df74a..88d9e74 100644
--- a/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_b.c
+++ b/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_b.c
@@ -57,5 +57,5 @@ TEST_CASE(boot_test_vm_ns_11_b)
rc = boot_set_pending(1);
TEST_ASSERT(rc == 0);
- boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1);
+ boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEST, &hdr0, &hdr1);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7aa94c51/net/ip/mn_socket/test/src/mn_sock_test.c
----------------------------------------------------------------------
diff --git a/net/ip/mn_socket/test/src/mn_sock_test.c b/net/ip/mn_socket/test/src/mn_sock_test.c
index 0f56db5..e52d012 100644
--- a/net/ip/mn_socket/test/src/mn_sock_test.c
+++ b/net/ip/mn_socket/test/src/mn_sock_test.c
@@ -86,5 +86,7 @@ main(int argc, char **argv)
tu_suite_set_init_cb((void*)mn_socket_test_init, NULL);
mn_socket_test_all();
+
+ return 0;
}
#endif