summaryrefslogtreecommitdiff
path: root/tests/vboot_kernel_tests.c
diff options
context:
space:
mode:
authorDan Ehrenberg <dehrenberg@chromium.org>2015-04-22 11:00:51 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-04-29 00:21:30 +0000
commitd7da706484823654f4f7f50b8d30f4d7a9d61089 (patch)
treeac15a3dbb490cb0976bae3fa51bb811ae7eb74ba /tests/vboot_kernel_tests.c
parente2e14ae8274ef85041bf3b25a87a465380fe2ced (diff)
downloadvboot-d7da706484823654f4f7f50b8d30f4d7a9d61089.tar.gz
cgpt: Handle read errors gracefullystabilize-7019.Bstabilize-7018.B
When a read fails in getting the GPT, just zero the contents of the buffer and carry on. Some testing changes are required for this. When a read of the GPT fails, it is no longer fatal, so tests of that have been adjusted. Tests have been improved to show that the GPT is automatically repaired when a read error occurs. There was one test which checked that a zero-sized disk would fail to load a kernel, but it was surrounded by a number of mocked functions which normally do that error checking, and it amounted to the same test as read failure; that test was deleted. BUG=chrome-os-partner:35440 TEST=vboot tests pass BRANCH=none Change-Id: I0c05813e7492920433733947d3fb74a7e4aa66f2 Signed-off-by: Dan Ehrenberg <dehrenberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/266882 Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'tests/vboot_kernel_tests.c')
-rw-r--r--tests/vboot_kernel_tests.c56
1 files changed, 34 insertions, 22 deletions
diff --git a/tests/vboot_kernel_tests.c b/tests/vboot_kernel_tests.c
index 03e77f98..e690bc31 100644
--- a/tests/vboot_kernel_tests.c
+++ b/tests/vboot_kernel_tests.c
@@ -12,6 +12,7 @@
#include "cgptlib.h"
#include "cgptlib_internal.h"
+#include "crc32.h"
#include "gbb_header.h"
#include "gpt.h"
#include "host_common.h"
@@ -467,27 +468,43 @@ static void ReadWriteGptTest(void)
/* Error reading */
ResetMocks();
disk_read_to_fail = 1;
- TEST_NEQ(AllocAndReadGptData(handle, &g), 0, "AllocAndRead disk fail");
- Memset(g.primary_header, '\0', g.sector_bytes);
- WriteAndFreeGptData(handle, &g);
+ TEST_EQ(AllocAndReadGptData(handle, &g), 0, "AllocAndRead disk fail");
+ g.valid_headers = g.valid_entries = MASK_SECONDARY;
+ GptRepair(&g);
+ ResetCallLog();
+ TEST_EQ(WriteAndFreeGptData(handle, &g), 0, "WriteAndFree mod 1");
+ TEST_CALLS("VbExDiskWrite(h, 1, 1)\n"
+ "VbExDiskWrite(h, 2, 32)\n");
ResetMocks();
disk_read_to_fail = 2;
- TEST_NEQ(AllocAndReadGptData(handle, &g), 0, "AllocAndRead disk fail");
- Memset(g.primary_header, '\0', g.sector_bytes);
- WriteAndFreeGptData(handle, &g);
+ TEST_EQ(AllocAndReadGptData(handle, &g), 0, "AllocAndRead disk fail");
+ g.valid_headers = MASK_BOTH;
+ g.valid_entries = MASK_SECONDARY;
+ GptRepair(&g);
+ ResetCallLog();
+ TEST_EQ(WriteAndFreeGptData(handle, &g), 0, "WriteAndFree mod 1");
+ TEST_CALLS("VbExDiskWrite(h, 2, 32)\n");
ResetMocks();
disk_read_to_fail = 991;
- TEST_NEQ(AllocAndReadGptData(handle, &g), 0, "AllocAndRead disk fail");
- Memset(g.primary_header, '\0', g.sector_bytes);
- WriteAndFreeGptData(handle, &g);
+ TEST_EQ(AllocAndReadGptData(handle, &g), 0, "AllocAndRead disk fail");
+ g.valid_headers = MASK_BOTH;
+ g.valid_entries = MASK_PRIMARY;
+ GptRepair(&g);
+ ResetCallLog();
+ TEST_EQ(WriteAndFreeGptData(handle, &g), 0, "WriteAndFree mod 2");
+ TEST_CALLS("VbExDiskWrite(h, 991, 32)\n");
ResetMocks();
disk_read_to_fail = 1023;
- TEST_NEQ(AllocAndReadGptData(handle, &g), 0, "AllocAndRead disk fail");
- Memset(g.primary_header, '\0', g.sector_bytes);
- WriteAndFreeGptData(handle, &g);
+ TEST_EQ(AllocAndReadGptData(handle, &g), 0, "AllocAndRead disk fail");
+ g.valid_headers = g.valid_entries = MASK_PRIMARY;
+ GptRepair(&g);
+ ResetCallLog();
+ TEST_EQ(WriteAndFreeGptData(handle, &g), 0, "WriteAndFree mod 2");
+ TEST_CALLS("VbExDiskWrite(h, 1023, 1)\n"
+ "VbExDiskWrite(h, 991, 32)\n");
/* Error writing */
ResetMocks();
@@ -543,20 +560,10 @@ static void InvalidParamsTest(void)
"Huge lba size");
ResetMocks();
- disk_read_to_fail = 1;
- TEST_EQ(LoadKernel(&lkp, &cparams), VBERROR_NO_KERNEL_FOUND,
- "Can't read disk");
-
- ResetMocks();
gpt_init_fail = 1;
TEST_EQ(LoadKernel(&lkp, &cparams), VBERROR_NO_KERNEL_FOUND,
"Bad GPT");
- ResetMocks();
- lkp.gpt_lba_count = 0;
- TEST_EQ(LoadKernel(&lkp, &cparams), VBERROR_NO_KERNEL_FOUND,
- "GPT size = 0");
-
/* This causes the stream open call to fail */
ResetMocks();
lkp.disk_handle = NULL;
@@ -765,6 +772,11 @@ static void LoadKernelTest(void)
lkp.boot_flags |= BOOT_FLAG_EXTERNAL_GPT;
TEST_EQ(LoadKernel(&lkp, &cparams), 0, "Succeed external GPT");
TEST_EQ(gpt_flag_external, 1, "GPT was external");
+
+ /* Check recovery from unreadble primary GPT */
+ ResetMocks();
+ disk_read_to_fail = 1;
+ TEST_EQ(LoadKernel(&lkp, &cparams), 0, "Can't read disk");
}
int main(void)