summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/vboot_api_kernel_tests.c75
-rw-r--r--tests/vboot_kernel_tests.c16
2 files changed, 72 insertions, 19 deletions
diff --git a/tests/vboot_api_kernel_tests.c b/tests/vboot_api_kernel_tests.c
index 69128730..1734c386 100644
--- a/tests/vboot_api_kernel_tests.c
+++ b/tests/vboot_api_kernel_tests.c
@@ -75,8 +75,8 @@ test_case_t test[] = {
},
.disk_count_to_return = DEFAULT_COUNT,
.diskgetinfo_return_val = VB2_SUCCESS,
- .loadkernel_return_val = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1,},
- .external_expected = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
+ .loadkernel_return_val = {0},
+ .external_expected = {0},
.expected_recovery_request_val = VB2_RECOVERY_NOT_REQUESTED,
.expected_to_find_disk = pickme,
@@ -84,7 +84,7 @@ test_case_t test[] = {
.expected_return_val = VB2_SUCCESS
},
{
- .name = "first removable drive",
+ .name = "first removable drive (skip external GPT)",
.want_flags = VB_DISK_FLAG_REMOVABLE,
.disks_to_provide = {
/* too small */
@@ -107,8 +107,8 @@ test_case_t test[] = {
},
.disk_count_to_return = DEFAULT_COUNT,
.diskgetinfo_return_val = VB2_SUCCESS,
- .loadkernel_return_val = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1,},
- .external_expected = {1, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
+ .loadkernel_return_val = {0, 0},
+ .external_expected = {1, 0},
.expected_recovery_request_val = VB2_RECOVERY_NOT_REQUESTED,
.expected_to_find_disk = pickme,
@@ -126,7 +126,7 @@ test_case_t test[] = {
},
.disk_count_to_return = DEFAULT_COUNT,
.diskgetinfo_return_val = VB2_SUCCESS,
- .loadkernel_return_val = {1, 0, 1, 1, 1, 1, 1, 1, 1, 1,},
+ .loadkernel_return_val = {VBERROR_INVALID_KERNEL_FOUND, 0},
.expected_recovery_request_val = VB2_RECOVERY_NOT_REQUESTED,
.expected_to_find_disk = pickme,
@@ -158,7 +158,7 @@ test_case_t test[] = {
},
.disk_count_to_return = DEFAULT_COUNT,
.diskgetinfo_return_val = VB2_SUCCESS,
- .loadkernel_return_val = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1,},
+ .loadkernel_return_val = {0},
.expected_recovery_request_val = VB2_RECOVERY_NOT_REQUESTED,
.expected_to_find_disk = pickme,
@@ -171,7 +171,6 @@ test_case_t test[] = {
.disks_to_provide = {},
.disk_count_to_return = DEFAULT_COUNT,
.diskgetinfo_return_val = VB2_SUCCESS,
- .loadkernel_return_val = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1,},
.expected_recovery_request_val = VB2_RECOVERY_RW_NO_DISK,
.expected_to_find_disk = 0,
@@ -179,7 +178,22 @@ test_case_t test[] = {
.expected_return_val = VBERROR_NO_DISK_FOUND
},
{
- .name = "no valid drives",
+ .name = "VbExDiskGetInfo() error",
+ .want_flags = VB_DISK_FLAG_FIXED,
+ .disks_to_provide = {
+ {512, 10, VB_DISK_FLAG_REMOVABLE, 0},
+ {512, 100, VB_DISK_FLAG_FIXED, 0},
+ },
+ .disk_count_to_return = DEFAULT_COUNT,
+ .diskgetinfo_return_val = VB2_ERROR_UNKNOWN,
+
+ .expected_recovery_request_val = VB2_RECOVERY_RW_NO_DISK,
+ .expected_to_find_disk = 0,
+ .expected_to_load_disk = 0,
+ .expected_return_val = VBERROR_NO_DISK_FOUND,
+ },
+ {
+ .name = "invalid kernel",
.want_flags = VB_DISK_FLAG_FIXED,
.disks_to_provide = {
/* too small */
@@ -195,18 +209,53 @@ test_case_t test[] = {
/* still wrong flags */
{512, 100, -1, 0},
/* doesn't load */
- {512, 100, VB_DISK_FLAG_FIXED, "bad1"},
+ {512, 100, VB_DISK_FLAG_FIXED, "corrupted kernel"},
/* doesn't load */
- {512, 100, VB_DISK_FLAG_FIXED, "bad2"},
+ {512, 100, VB_DISK_FLAG_FIXED, "stateful partition"},
+ },
+ .disk_count_to_return = DEFAULT_COUNT,
+ .diskgetinfo_return_val = VB2_SUCCESS,
+ .loadkernel_return_val = {VBERROR_INVALID_KERNEL_FOUND,
+ VBERROR_NO_KERNEL_FOUND},
+
+ .expected_recovery_request_val = VB2_RECOVERY_RW_INVALID_OS,
+ .expected_to_find_disk = DONT_CARE,
+ .expected_to_load_disk = 0,
+ .expected_return_val = VBERROR_INVALID_KERNEL_FOUND,
+ },
+ {
+ .name = "invalid kernel, order flipped",
+ .want_flags = VB_DISK_FLAG_FIXED,
+ .disks_to_provide = {
+ {512, 1000, VB_DISK_FLAG_FIXED, "stateful partition"},
+ {512, 1000, VB_DISK_FLAG_FIXED, "corrupted kernel"},
+ },
+ .disk_count_to_return = DEFAULT_COUNT,
+ .diskgetinfo_return_val = VB2_SUCCESS,
+ .loadkernel_return_val = {VBERROR_NO_KERNEL_FOUND,
+ VBERROR_INVALID_KERNEL_FOUND},
+
+ .expected_recovery_request_val = VB2_RECOVERY_RW_INVALID_OS,
+ .expected_to_find_disk = DONT_CARE,
+ .expected_to_load_disk = 0,
+ .expected_return_val = VBERROR_INVALID_KERNEL_FOUND,
+ },
+ {
+ .name = "no Chrome OS partitions",
+ .want_flags = VB_DISK_FLAG_FIXED,
+ .disks_to_provide = {
+ {512, 100, VB_DISK_FLAG_FIXED, "stateful partition"},
+ {512, 1000, VB_DISK_FLAG_FIXED, "Chrubuntu"},
},
.disk_count_to_return = DEFAULT_COUNT,
.diskgetinfo_return_val = VB2_SUCCESS,
- .loadkernel_return_val = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1,},
+ .loadkernel_return_val = {VBERROR_NO_KERNEL_FOUND,
+ VBERROR_NO_KERNEL_FOUND},
.expected_recovery_request_val = VB2_RECOVERY_RW_NO_KERNEL,
.expected_to_find_disk = DONT_CARE,
.expected_to_load_disk = 0,
- .expected_return_val = 1
+ .expected_return_val = VBERROR_NO_KERNEL_FOUND,
},
};
diff --git a/tests/vboot_kernel_tests.c b/tests/vboot_kernel_tests.c
index b43d68b4..9c80eed7 100644
--- a/tests/vboot_kernel_tests.c
+++ b/tests/vboot_kernel_tests.c
@@ -335,6 +335,12 @@ vb2_error_t vb2_digest_buffer(const uint8_t *buf, uint32_t size,
return VB2_SUCCESS;
}
+/* Make sure nothing tested here ever calls this directly. */
+void vb2api_fail(struct vb2_context *c, uint8_t reason, uint8_t subcode)
+{
+ TEST_TRUE(0, " called vb2api_fail()");
+}
+
/**
* Test reading/writing GPT
*/
@@ -589,6 +595,10 @@ static void ReadWriteGptTest(void)
static void TestLoadKernel(int expect_retval, const char *test_name)
{
TEST_EQ(LoadKernel(&ctx, &lkp), expect_retval, test_name);
+
+ /* LoadKernel() should never request recovery directly. */
+ TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST),
+ 0, " recovery request");
}
/**
@@ -616,8 +626,6 @@ static void LoadKernelTest(void)
TEST_EQ(lkp.bootloader_size, 0x1234, " bootloader size");
TEST_STR_EQ((char *)lkp.partition_guid, "FakeGuid", " guid");
TEST_EQ(gpt_flag_external, 0, "GPT was internal");
- TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST),
- 0, " recovery request");
ResetMocks();
mock_parts[1].start = 300;
@@ -630,15 +638,11 @@ static void LoadKernelTest(void)
ResetMocks();
mock_parts[0].size = 0;
TestLoadKernel(VBERROR_NO_KERNEL_FOUND, "No kernels");
- TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST),
- VB2_RECOVERY_RW_NO_KERNEL, " recovery request");
/* Skip kernels which are too small */
ResetMocks();
mock_parts[0].size = 10;
TestLoadKernel(VBERROR_INVALID_KERNEL_FOUND, "Too small");
- TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST),
- VB2_RECOVERY_RW_INVALID_OS, " recovery request");
ResetMocks();
disk_read_to_fail = 100;