summaryrefslogtreecommitdiff
path: root/tests/cgptlib_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/cgptlib_test.c')
-rw-r--r--tests/cgptlib_test.c85
1 files changed, 83 insertions, 2 deletions
diff --git a/tests/cgptlib_test.c b/tests/cgptlib_test.c
index 61747522..1e8df252 100644
--- a/tests/cgptlib_test.c
+++ b/tests/cgptlib_test.c
@@ -827,6 +827,7 @@ static int SanityCheckTest(void)
{
GptData *gpt = GetEmptyGptData();
GptHeader *h1 = (GptHeader *)gpt->primary_header;
+ GptHeader *h2 = (GptHeader *)gpt->secondary_header;
GptEntry *e1 = (GptEntry *)gpt->primary_entries;
uint8_t *tempptr;
@@ -835,11 +836,13 @@ static int SanityCheckTest(void)
EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
EXPECT(MASK_BOTH == gpt->valid_headers);
EXPECT(MASK_BOTH == gpt->valid_entries);
+ EXPECT(MASK_NONE == gpt->ignored);
/* Repair doesn't damage it */
GptRepair(gpt);
EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
EXPECT(MASK_BOTH == gpt->valid_headers);
EXPECT(MASK_BOTH == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
EXPECT(0 == gpt->modified);
/* Invalid sector size should fail */
@@ -854,11 +857,13 @@ static int SanityCheckTest(void)
EXPECT(GPT_ERROR_INVALID_HEADERS == GptSanityCheck(gpt));
EXPECT(0 == gpt->valid_headers);
EXPECT(0 == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
/* Repair can't fix completely busted headers */
GptRepair(gpt);
EXPECT(GPT_ERROR_INVALID_HEADERS == GptSanityCheck(gpt));
EXPECT(0 == gpt->valid_headers);
EXPECT(0 == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
EXPECT(0 == gpt->modified);
BuildTestGptData(gpt);
@@ -866,10 +871,12 @@ static int SanityCheckTest(void)
EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
EXPECT(MASK_SECONDARY == gpt->valid_headers);
EXPECT(MASK_BOTH == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
GptRepair(gpt);
EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
EXPECT(MASK_BOTH == gpt->valid_headers);
EXPECT(MASK_BOTH == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
EXPECT(GPT_MODIFIED_HEADER1 == gpt->modified);
BuildTestGptData(gpt);
@@ -877,10 +884,12 @@ static int SanityCheckTest(void)
EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
EXPECT(MASK_PRIMARY == gpt->valid_headers);
EXPECT(MASK_BOTH == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
GptRepair(gpt);
EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
EXPECT(MASK_BOTH == gpt->valid_headers);
EXPECT(MASK_BOTH == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
EXPECT(GPT_MODIFIED_HEADER2 == gpt->modified);
/*
@@ -893,10 +902,12 @@ static int SanityCheckTest(void)
EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
EXPECT(MASK_PRIMARY == gpt->valid_headers);
EXPECT(MASK_BOTH == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
GptRepair(gpt);
EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
EXPECT(MASK_BOTH == gpt->valid_headers);
EXPECT(MASK_BOTH == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
EXPECT(GPT_MODIFIED_HEADER2 == gpt->modified);
/* Modify entries */
@@ -906,11 +917,13 @@ static int SanityCheckTest(void)
EXPECT(GPT_ERROR_INVALID_ENTRIES == GptSanityCheck(gpt));
EXPECT(MASK_BOTH == gpt->valid_headers);
EXPECT(MASK_NONE == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
/* Repair can't fix both copies of entries being bad, either. */
GptRepair(gpt);
EXPECT(GPT_ERROR_INVALID_ENTRIES == GptSanityCheck(gpt));
EXPECT(MASK_BOTH == gpt->valid_headers);
EXPECT(MASK_NONE == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
EXPECT(0 == gpt->modified);
BuildTestGptData(gpt);
@@ -918,10 +931,12 @@ static int SanityCheckTest(void)
EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
EXPECT(MASK_BOTH == gpt->valid_headers);
EXPECT(MASK_SECONDARY == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
GptRepair(gpt);
EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
EXPECT(MASK_BOTH == gpt->valid_headers);
EXPECT(MASK_BOTH == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
EXPECT(GPT_MODIFIED_ENTRIES1 == gpt->modified);
BuildTestGptData(gpt);
@@ -929,10 +944,12 @@ static int SanityCheckTest(void)
EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
EXPECT(MASK_BOTH == gpt->valid_headers);
EXPECT(MASK_PRIMARY == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
GptRepair(gpt);
EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
EXPECT(MASK_BOTH == gpt->valid_headers);
EXPECT(MASK_BOTH == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
EXPECT(GPT_MODIFIED_ENTRIES2 == gpt->modified);
/*
@@ -949,6 +966,7 @@ static int SanityCheckTest(void)
EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
EXPECT(MASK_SECONDARY == gpt->valid_headers);
EXPECT(MASK_BOTH == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
gpt->primary_entries = tempptr;
/* Modify both header and entries */
@@ -958,10 +976,12 @@ static int SanityCheckTest(void)
EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
EXPECT(MASK_SECONDARY == gpt->valid_headers);
EXPECT(MASK_SECONDARY == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
GptRepair(gpt);
EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
EXPECT(MASK_BOTH == gpt->valid_headers);
EXPECT(MASK_BOTH == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
EXPECT((GPT_MODIFIED_HEADER1 | GPT_MODIFIED_ENTRIES1) == gpt->modified);
BuildTestGptData(gpt);
@@ -970,10 +990,12 @@ static int SanityCheckTest(void)
EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
EXPECT(MASK_PRIMARY == gpt->valid_headers);
EXPECT(MASK_PRIMARY == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
GptRepair(gpt);
EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
EXPECT(MASK_BOTH == gpt->valid_headers);
EXPECT(MASK_BOTH == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
EXPECT((GPT_MODIFIED_HEADER2 | GPT_MODIFIED_ENTRIES2) == gpt->modified);
/* Test cross-correction (h1+e2, h2+e1) */
@@ -983,10 +1005,12 @@ static int SanityCheckTest(void)
EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
EXPECT(MASK_SECONDARY == gpt->valid_headers);
EXPECT(MASK_PRIMARY == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
GptRepair(gpt);
EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
EXPECT(MASK_BOTH == gpt->valid_headers);
EXPECT(MASK_BOTH == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
EXPECT((GPT_MODIFIED_HEADER1 | GPT_MODIFIED_ENTRIES2) == gpt->modified);
BuildTestGptData(gpt);
@@ -995,10 +1019,12 @@ static int SanityCheckTest(void)
EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
EXPECT(MASK_PRIMARY == gpt->valid_headers);
EXPECT(MASK_SECONDARY == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
GptRepair(gpt);
EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
EXPECT(MASK_BOTH == gpt->valid_headers);
EXPECT(MASK_BOTH == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
EXPECT((GPT_MODIFIED_HEADER2 | GPT_MODIFIED_ENTRIES1) == gpt->modified);
/*
@@ -1011,35 +1037,90 @@ static int SanityCheckTest(void)
EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
EXPECT(MASK_PRIMARY == gpt->valid_headers);
EXPECT(MASK_PRIMARY == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
GptRepair(gpt);
EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
EXPECT(MASK_BOTH == gpt->valid_headers);
EXPECT(MASK_BOTH == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
EXPECT((GPT_MODIFIED_HEADER2 | GPT_MODIFIED_ENTRIES2) == gpt->modified);
/* Test unloaded entry array. */
- gpt = GetEmptyGptData();
BuildTestGptData(gpt);
gpt->primary_entries = NULL;
EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
EXPECT(MASK_SECONDARY == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
gpt = GetEmptyGptData();
BuildTestGptData(gpt);
gpt->secondary_entries = NULL;
EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
EXPECT(MASK_PRIMARY == gpt->valid_entries);
+ EXPECT(0 == gpt->ignored);
+ gpt = GetEmptyGptData();
/* Test unloaded header. */
- gpt = GetEmptyGptData();
BuildTestGptData(gpt);
gpt->primary_header = NULL;
EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
EXPECT(MASK_SECONDARY == gpt->valid_headers);
+ EXPECT(0 == gpt->ignored);
gpt = GetEmptyGptData();
BuildTestGptData(gpt);
gpt->secondary_header = NULL;
EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
EXPECT(MASK_PRIMARY == gpt->valid_headers);
+ EXPECT(0 == gpt->ignored);
+ gpt = GetEmptyGptData();
+
+ /* Test correct recognition of IGNOREME in primary GPT. */
+ BuildTestGptData(gpt);
+ Memset(gpt->primary_entries, 0, PARTITION_ENTRIES_SIZE);
+ Memset(gpt->primary_header, 0, sizeof(GptHeader));
+ Memcpy(h1->signature, GPT_HEADER_SIGNATURE_IGNORED,
+ GPT_HEADER_SIGNATURE_SIZE);
+ EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
+ EXPECT(MASK_BOTH == gpt->valid_headers);
+ EXPECT(MASK_BOTH == gpt->valid_entries);
+ EXPECT(MASK_PRIMARY == gpt->ignored);
+ EXPECT(0 == gpt->modified);
+
+ /* Test correct recognition of IGNOREME in secondary GPT. */
+ BuildTestGptData(gpt);
+ Memset(gpt->secondary_entries, 0, PARTITION_ENTRIES_SIZE);
+ Memset(gpt->secondary_header, 0, sizeof(GptHeader));
+ Memcpy(h2->signature, GPT_HEADER_SIGNATURE_IGNORED,
+ GPT_HEADER_SIGNATURE_SIZE);
+ EXPECT(GPT_SUCCESS == GptSanityCheck(gpt));
+ EXPECT(MASK_BOTH == gpt->valid_headers);
+ EXPECT(MASK_BOTH == gpt->valid_entries);
+ EXPECT(MASK_SECONDARY == gpt->ignored);
+ EXPECT(0 == gpt->modified);
+
+ /* Test that two IGNOREME GPTs are invalid. */
+ ZeroHeadersEntries(gpt);
+ Memcpy(h1->signature, GPT_HEADER_SIGNATURE_IGNORED,
+ GPT_HEADER_SIGNATURE_SIZE);
+ Memcpy(h2->signature, GPT_HEADER_SIGNATURE_IGNORED,
+ GPT_HEADER_SIGNATURE_SIZE);
+ EXPECT(GPT_ERROR_INVALID_HEADERS == GptSanityCheck(gpt));
+ EXPECT(0 == gpt->valid_headers);
+ EXPECT(0 == gpt->valid_entries);
+ EXPECT(MASK_BOTH == gpt->ignored);
+ EXPECT(0 == gpt->modified);
+
+ /* Test that one IGNOREME GPT and one corrupted one are invalid. */
+ BuildTestGptData(gpt);
+ Memset(gpt->primary_entries, 0, PARTITION_ENTRIES_SIZE);
+ Memset(gpt->primary_header, 0, sizeof(GptHeader));
+ Memcpy(h1->signature, GPT_HEADER_SIGNATURE_IGNORED,
+ GPT_HEADER_SIGNATURE_SIZE);
+ gpt->secondary_entries[0]++;
+ EXPECT(GPT_ERROR_INVALID_ENTRIES == GptSanityCheck(gpt));
+ EXPECT(MASK_SECONDARY == gpt->valid_headers);
+ EXPECT(0 == gpt->valid_entries);
+ EXPECT(MASK_PRIMARY == gpt->ignored);
+ EXPECT(0 == gpt->modified);
return TEST_OK;
}