diff options
Diffstat (limited to 'tests/cgptlib_test.c')
-rw-r--r-- | tests/cgptlib_test.c | 564 |
1 files changed, 0 insertions, 564 deletions
diff --git a/tests/cgptlib_test.c b/tests/cgptlib_test.c index fc166fda..fd5cda16 100644 --- a/tests/cgptlib_test.c +++ b/tests/cgptlib_test.c @@ -7,14 +7,11 @@ #include <string.h> #include "../cgpt/cgpt.h" -#include "../cgpt/flash_ts.h" #include "cgptlib_internal.h" #include "cgptlib_test.h" #include "crc32.h" #include "crc32_test.h" #include "gpt.h" -#include "mtdlib.h" -#include "mtdlib_unused.h" #include "test_common.h" #define _STUB_IMPLEMENTATION_ #include "utility.h" @@ -55,11 +52,6 @@ static const Guid guid_rootfs = GPT_ENT_TYPE_CHROMEOS_ROOTFS; const char *progname = "CGPT-TEST"; const char *command = "TEST"; -// Ramdisk for flash ts testing. -static uint8_t *nand_drive = NULL; -static uint32_t nand_drive_sz; -static uint8_t *nand_bad_block_map = NULL; - /* * Copy a random-for-this-program-only Guid into the dest. The num parameter * completely determines the Guid. @@ -142,13 +134,6 @@ static GptData *GetEmptyGptData(void) return &gpt; } -static MtdData *GetEmptyMtdData() { - static MtdData mtd; - Memset(&mtd, 0, sizeof(mtd)); - mtd.current_kernel = CGPT_KERNEL_ENTRY_NOT_FOUND; - return &mtd; -} - /* * Fill in most of fields and creates the layout described in the top of this * file. Before calling this function, primary/secondary header/entries must @@ -215,50 +200,6 @@ static void BuildTestGptData(GptData *gpt) RefreshCrc32(gpt); } -static void BuildTestMtdData(MtdData *mtd) { - MtdDiskPartition *partitions; - - mtd->sector_bytes = DEFAULT_SECTOR_SIZE; - mtd->drive_sectors = DEFAULT_DRIVE_SECTORS; - mtd->current_kernel = CGPT_KERNEL_ENTRY_NOT_FOUND; - mtd->modified = 0; - Memset(&mtd->primary, 0, sizeof(mtd->primary)); - - Memcpy(mtd->primary.signature, MTD_DRIVE_SIGNATURE, - sizeof(mtd->primary.signature)); - mtd->primary.first_offset = 32 * DEFAULT_SECTOR_SIZE; - mtd->primary.last_offset = DEFAULT_DRIVE_SECTORS * DEFAULT_SECTOR_SIZE - 1; - mtd->primary.size = MTD_DRIVE_V1_SIZE; - - /* These values are not used directly by the library, but they are checked */ - mtd->flash_page_bytes = mtd->sector_bytes * 8; - mtd->flash_block_bytes = mtd->flash_page_bytes * 8; - mtd->fts_block_offset = 1; - mtd->fts_block_size = 1; - - partitions = &mtd->primary.partitions[0]; - partitions[0].starting_offset = 34 * DEFAULT_SECTOR_SIZE; - partitions[0].ending_offset = 134 * DEFAULT_SECTOR_SIZE - 1; - partitions[0].flags = - MTD_PARTITION_TYPE_CHROMEOS_KERNEL << MTD_ATTRIBUTE_TYPE_OFFSET; - partitions[1].starting_offset = 134 * DEFAULT_SECTOR_SIZE; - partitions[1].ending_offset = 233 * DEFAULT_SECTOR_SIZE - 1; - partitions[1].flags = - MTD_PARTITION_TYPE_CHROMEOS_ROOTFS << MTD_ATTRIBUTE_TYPE_OFFSET; - partitions[2].starting_offset = 234 * DEFAULT_SECTOR_SIZE; - partitions[2].ending_offset = 332 * DEFAULT_SECTOR_SIZE - 1; - partitions[2].flags = - MTD_PARTITION_TYPE_CHROMEOS_KERNEL << MTD_ATTRIBUTE_TYPE_OFFSET; - partitions[3].starting_offset = 334 * DEFAULT_SECTOR_SIZE; - partitions[3].ending_offset = 431 * DEFAULT_SECTOR_SIZE - 1; - partitions[3].flags = - MTD_PARTITION_TYPE_CHROMEOS_ROOTFS << MTD_ATTRIBUTE_TYPE_OFFSET; - - mtd->primary.crc32 = 0; - mtd->primary.crc32 = Crc32(&mtd->primary, MTD_DRIVE_V1_SIZE); -} - - /* * Test if the structures are the expected size; if this fails, struct packing * is not working properly. @@ -269,8 +210,6 @@ static int StructSizeTest(void) EXPECT(GUID_EXPECTED_SIZE == sizeof(Guid)); EXPECT(GPTHEADER_EXPECTED_SIZE == sizeof(GptHeader)); EXPECT(GPTENTRY_EXPECTED_SIZE == sizeof(GptEntry)); - EXPECT(MTDENTRY_EXPECTED_SIZE == sizeof(MtdDiskPartition)); - EXPECT(MTDLAYOUT_EXPECTED_SIZE == sizeof(MtdDiskLayout)); return TEST_OK; } @@ -288,26 +227,15 @@ static int TestBuildTestGptData(void) return TEST_OK; } -static int TestBuildTestMtdData() { - MtdData *mtd = GetEmptyMtdData(); - - BuildTestMtdData(mtd); - EXPECT(GPT_SUCCESS == MtdInit(mtd)); - return TEST_OK; -} - /* * Test if wrong sector_bytes or drive_sectors is detected by GptInit(). * Currently we only support 512 bytes per sector. In the future, we may * support other sizes. A too small drive_sectors should be rejected by * GptInit(). - * For MtdInit(), additionally test various flash geometries to verify - * that only valid ones are accepted. */ static int ParameterTests(void) { GptData *gpt; - MtdData *mtd; struct { uint32_t sector_bytes; uint64_t drive_sectors; @@ -321,32 +249,6 @@ static int ParameterTests(void) GPT_ENTRIES_SECTORS * 2, GPT_SUCCESS}, {4096, DEFAULT_DRIVE_SECTORS, GPT_ERROR_INVALID_SECTOR_SIZE}, }; - struct { - uint32_t sector_bytes; - uint32_t drive_sectors; - uint32_t flash_page_bytes; - uint32_t flash_block_bytes; - int expected_retval; - } mtdcases[] = { - {512, DEFAULT_DRIVE_SECTORS, 8*512, - 8*512, GPT_SUCCESS}, - {510, DEFAULT_DRIVE_SECTORS, 8*512, - 8*512, GPT_ERROR_INVALID_SECTOR_SIZE}, - {512, DEFAULT_DRIVE_SECTORS, 8*512, - 8*512, GPT_SUCCESS}, - {512, DEFAULT_DRIVE_SECTORS, 512, - 8*512, GPT_SUCCESS}, - {512, DEFAULT_DRIVE_SECTORS, 8*512, - 10*512, GPT_ERROR_INVALID_FLASH_GEOMETRY}, - {512, DEFAULT_DRIVE_SECTORS, 3*512, - 9*512, GPT_SUCCESS}, - {512, DEFAULT_DRIVE_SECTORS, 8*512, - 6*512, GPT_ERROR_INVALID_FLASH_GEOMETRY}, - {512, DEFAULT_DRIVE_SECTORS, 256, - 6*512, GPT_ERROR_INVALID_FLASH_GEOMETRY}, - {512, DEFAULT_DRIVE_SECTORS, 512, - 6*512 + 256, GPT_ERROR_INVALID_FLASH_GEOMETRY}, - }; int i; gpt = GetEmptyGptData(); @@ -357,19 +259,6 @@ static int ParameterTests(void) EXPECT(cases[i].expected_retval == CheckParameters(gpt)); } - mtd = GetEmptyMtdData(); - for (i = 0; i < ARRAY_SIZE(cases); ++i) { - BuildTestMtdData(mtd); - mtd->sector_bytes = mtdcases[i].sector_bytes; - mtd->drive_sectors = mtdcases[i].drive_sectors; - mtd->flash_block_bytes = mtdcases[i].flash_block_bytes; - mtd->flash_page_bytes = mtdcases[i].flash_page_bytes; - if(mtdcases[i].expected_retval != MtdCheckParameters(mtd)) { - printf("i=%d\n",i); - } - EXPECT(mtdcases[i].expected_retval == MtdCheckParameters(mtd)); - } - return TEST_OK; } @@ -811,9 +700,6 @@ static int ValidEntryTest(void) GptData *gpt = GetEmptyGptData(); GptHeader *h1 = (GptHeader *)gpt->primary_header; GptEntry *e1 = (GptEntry *)(gpt->primary_entries); - MtdData *mtd = GetEmptyMtdData(); - MtdDiskLayout *mh = &mtd->primary; - MtdDiskPartition *me = mh->partitions; /* error case: entry.StartingLBA < header.FirstUsableLBA */ BuildTestGptData(gpt); @@ -821,35 +707,18 @@ static int ValidEntryTest(void) RefreshCrc32(gpt); EXPECT(GPT_ERROR_OUT_OF_REGION == CheckEntries(e1, h1)); - BuildTestMtdData(mtd); - if (mh->first_offset > 0) { - me[0].starting_offset = mh->first_offset - 1; - mh->crc32 = MtdHeaderCrc(mh); - EXPECT(GPT_ERROR_OUT_OF_REGION == MtdCheckEntries(me, mh)); - } - /* error case: entry.EndingLBA > header.LastUsableLBA */ BuildTestGptData(gpt); e1[2].ending_lba = h1->last_usable_lba + 1; RefreshCrc32(gpt); EXPECT(GPT_ERROR_OUT_OF_REGION == CheckEntries(e1, h1)); - BuildTestMtdData(mtd); - me[0].ending_offset = mh->last_offset + 1; - mh->crc32 = MtdHeaderCrc(mh); - EXPECT(GPT_ERROR_OUT_OF_REGION == MtdCheckEntries(me, mh)); - /* error case: entry.StartingLBA > entry.EndingLBA */ BuildTestGptData(gpt); e1[3].starting_lba = e1[3].ending_lba + 1; RefreshCrc32(gpt); EXPECT(GPT_ERROR_OUT_OF_REGION == CheckEntries(e1, h1)); - BuildTestMtdData(mtd); - me[0].starting_offset = me[0].ending_offset + 1; - mh->crc32 = MtdHeaderCrc(mh); - EXPECT(GPT_ERROR_OUT_OF_REGION == MtdCheckEntries(me, mh)); - /* case: non active entry should be ignored. */ BuildTestGptData(gpt); Memset(&e1[1].type, 0, sizeof(e1[1].type)); @@ -857,12 +726,6 @@ static int ValidEntryTest(void) RefreshCrc32(gpt); EXPECT(0 == CheckEntries(e1, h1)); - BuildTestMtdData(mtd); - me[0].flags = 0; - me[0].starting_offset = me[0].ending_offset + 1; - mh->crc32 = MtdHeaderCrc(mh); - EXPECT(GPT_SUCCESS == MtdCheckEntries(me, mh)); - return TEST_OK; } @@ -871,9 +734,6 @@ static int OverlappedPartitionTest(void) { GptData *gpt = GetEmptyGptData(); GptHeader *h = (GptHeader *)gpt->primary_header; GptEntry *e = (GptEntry *)gpt->primary_entries; - MtdData *mtd = GetEmptyMtdData(); - MtdDiskLayout *mh = &mtd->primary; - MtdDiskPartition *me = mh->partitions; int i, j; struct { @@ -926,8 +786,6 @@ static int OverlappedPartitionTest(void) { for (i = 0; i < ARRAY_SIZE(cases); ++i) { BuildTestGptData(gpt); - BuildTestMtdData(mtd); - Memset(mh->partitions, 0, sizeof(mh->partitions)); ZeroEntries(gpt); for(j = 0; j < ARRAY_SIZE(cases[0].entries); ++j) { if (!cases[i].entries[j].starting_lba) @@ -935,22 +793,14 @@ static int OverlappedPartitionTest(void) { if (cases[i].entries[j].active) { Memcpy(&e[j].type, &guid_kernel, sizeof(Guid)); - me[j].flags = - MTD_PARTITION_TYPE_CHROMEOS_KERNEL << MTD_ATTRIBUTE_TYPE_OFFSET; } SetGuid(&e[j].unique, j); e[j].starting_lba = cases[i].entries[j].starting_lba; e[j].ending_lba = cases[i].entries[j].ending_lba; - me[j].starting_offset = cases[i].entries[j].starting_lba * - DEFAULT_SECTOR_SIZE; - me[j].ending_offset = cases[i].entries[j].ending_lba * - DEFAULT_SECTOR_SIZE; - } RefreshCrc32(gpt); EXPECT(cases[i].overlapped == CheckEntries(e, h)); - EXPECT(cases[i].overlapped == MtdCheckEntries(me, mh)); } return TEST_OK; } @@ -1181,8 +1031,6 @@ static int EntryAttributeGetSetTest(void) { GptData *gpt = GetEmptyGptData(); GptEntry *e = (GptEntry *)(gpt->primary_entries); - MtdData *mtd = GetEmptyMtdData(); - MtdDiskPartition *m = &mtd->primary.partitions[0]; e->attrs.whole = 0x0000000000000000ULL; SetEntrySuccessful(e, 1); @@ -1193,15 +1041,6 @@ static int EntryAttributeGetSetTest(void) EXPECT(0xFEFFFFFFFFFFFFFFULL == e->attrs.whole); EXPECT(0 == GetEntrySuccessful(e)); - m->flags = 0; - MtdSetEntrySuccessful(m, 1); - EXPECT(0x00000100 == m->flags); - EXPECT(1 == MtdGetEntrySuccessful(m)); - m->flags = ~0; - MtdSetEntrySuccessful(m, 0); - EXPECT(0xFFFFFEFF == m->flags); - EXPECT(0 == MtdGetEntrySuccessful(m)); - e->attrs.whole = 0x0000000000000000ULL; SetEntryTries(e, 15); EXPECT(15 == GetEntryTries(e)); @@ -1211,15 +1050,6 @@ static int EntryAttributeGetSetTest(void) EXPECT(0xFF0FFFFFFFFFFFFFULL == e->attrs.whole); EXPECT(0 == GetEntryTries(e)); - m->flags = 0; - MtdSetEntryTries(m, 15); - EXPECT(0x000000F0 == m->flags); - EXPECT(15 == MtdGetEntryTries(m)); - m->flags = ~0; - MtdSetEntryTries(m, 0); - EXPECT(0xFFFFFF0F == m->flags); - EXPECT(0 == MtdGetEntryTries(m)); - e->attrs.whole = 0x0000000000000000ULL; SetEntryPriority(e, 15); EXPECT(0x000F000000000000ULL == e->attrs.whole); @@ -1229,15 +1059,6 @@ static int EntryAttributeGetSetTest(void) EXPECT(0xFFF0FFFFFFFFFFFFULL == e->attrs.whole); EXPECT(0 == GetEntryPriority(e)); - m->flags = 0; - MtdSetEntryPriority(m, 15); - EXPECT(0x0000000F == m->flags); - EXPECT(15 == MtdGetEntryPriority(m)); - m->flags = ~0; - MtdSetEntryPriority(m, 0); - EXPECT(0xFFFFFFF0 == m->flags); - EXPECT(0 == MtdGetEntryPriority(m)); - e->attrs.whole = 0xFFFFFFFFFFFFFFFFULL; EXPECT(1 == GetEntrySuccessful(e)); EXPECT(15 == GetEntryPriority(e)); @@ -1277,11 +1098,6 @@ static void FreeEntry(GptEntry *e) Memset(&e->type, 0, sizeof(Guid)); } -static void MtdFreeEntry(MtdDiskPartition *e) -{ - MtdSetEntryType(e, MTD_PARTITION_TYPE_UNUSED); -} - /* Set up an entry. */ static void FillEntry(GptEntry *e, int is_kernel, int priority, int successful, int tries) @@ -1292,16 +1108,6 @@ static void FillEntry(GptEntry *e, int is_kernel, SetEntryTries(e, tries); } -static void MtdFillEntry(MtdDiskPartition *e, int is_kernel, - int priority, int successful, int tries) -{ - MtdSetEntryType(e, is_kernel ? MTD_PARTITION_TYPE_CHROMEOS_KERNEL : - MTD_PARTITION_TYPE_CHROMEOS_FIRMWARE); - MtdSetEntryPriority(e, priority); - MtdSetEntrySuccessful(e, successful); - MtdSetEntryTries(e, tries); -} - /* * Invalidate all kernel entries and expect GptNextKernelEntry() cannot find * any usable kernel entry. @@ -1321,20 +1127,6 @@ static int NoValidKernelEntryTest(void) return TEST_OK; } -static int MtdNoValidKernelEntryTest(void) -{ - MtdData *mtd = GetEmptyMtdData(); - MtdDiskPartition *e1 = mtd->primary.partitions; - - BuildTestMtdData(mtd); - MtdSetEntryPriority(e1 + KERNEL_A, 0); - MtdFreeEntry(e1 + KERNEL_B); - EXPECT(GPT_ERROR_NO_VALID_KERNEL == - MtdNextKernelEntry(mtd, NULL, NULL)); - - return TEST_OK; -} - static int GetNextNormalTest(void) { GptData *gpt = GetEmptyGptData(); @@ -1422,169 +1214,6 @@ static int GetNextTriesTest(void) return TEST_OK; } -static int MtdGetNextNormalTest(void) -{ - MtdData *mtd = GetEmptyMtdData(); - MtdDiskPartition *e1 = mtd->primary.partitions; - uint64_t start, size; - - /* Normal case - both kernels successful */ - BuildTestMtdData(mtd); - MtdFillEntry(e1 + KERNEL_A, 1, 2, 1, 0); - MtdFillEntry(e1 + KERNEL_B, 1, 2, 1, 0); - mtd->primary.crc32 = MtdHeaderCrc(&mtd->primary); - MtdInit(mtd); - - EXPECT(GPT_SUCCESS == MtdNextKernelEntry(mtd, &start, &size)); - EXPECT(KERNEL_A == mtd->current_kernel); - EXPECT(34 == start); - EXPECT(100 == size); - - EXPECT(GPT_SUCCESS == MtdNextKernelEntry(mtd, &start, &size)); - EXPECT(KERNEL_B == mtd->current_kernel); - EXPECT(134 == start); - EXPECT(99 == size); - - EXPECT(GPT_ERROR_NO_VALID_KERNEL == - MtdNextKernelEntry(mtd, &start, &size)); - EXPECT(-1 == mtd->current_kernel); - - /* Call as many times as you want; you won't get another kernel... */ - EXPECT(GPT_ERROR_NO_VALID_KERNEL == - MtdNextKernelEntry(mtd, &start, &size)); - EXPECT(-1 == mtd->current_kernel); - - return TEST_OK; -} - -static int MtdGetNextPrioTest(void) -{ - MtdData *mtd = GetEmptyMtdData(); - MtdDiskPartition *e1 = mtd->primary.partitions; - uint64_t start, size; - - /* Priority 3, 4, 0, 4 - should boot order B, Y, A */ - BuildTestMtdData(mtd); - MtdFillEntry(e1 + KERNEL_A, 1, 3, 1, 0); - MtdFillEntry(e1 + KERNEL_B, 1, 4, 1, 0); - MtdFillEntry(e1 + KERNEL_X, 1, 0, 1, 0); - MtdFillEntry(e1 + KERNEL_Y, 1, 4, 1, 0); - mtd->primary.crc32 = MtdHeaderCrc(&mtd->primary); - MtdInit(mtd); - - EXPECT(GPT_SUCCESS == MtdNextKernelEntry(mtd, &start, &size)); - EXPECT(KERNEL_B == mtd->current_kernel); - EXPECT(GPT_SUCCESS == MtdNextKernelEntry(mtd, &start, &size)); - EXPECT(KERNEL_Y == mtd->current_kernel); - EXPECT(GPT_SUCCESS == MtdNextKernelEntry(mtd, &start, &size)); - EXPECT(KERNEL_A == mtd->current_kernel); - EXPECT(GPT_ERROR_NO_VALID_KERNEL == - MtdNextKernelEntry(mtd, &start, &size)); - - return TEST_OK; -} - -static int MtdGetNextTriesTest(void) -{ - MtdData *mtd = GetEmptyMtdData(); - MtdDiskPartition *e1 = mtd->primary.partitions; - uint64_t start, size; - - /* Tries=nonzero is attempted just like success, but tries=0 isn't */ - BuildTestMtdData(mtd); - MtdFillEntry(e1 + KERNEL_A, 1, 2, 1, 0); - MtdFillEntry(e1 + KERNEL_B, 1, 3, 0, 0); - MtdFillEntry(e1 + KERNEL_X, 1, 4, 0, 1); - MtdFillEntry(e1 + KERNEL_Y, 1, 0, 0, 5); - mtd->primary.crc32 = MtdHeaderCrc(&mtd->primary); - MtdInit(mtd); - - EXPECT(GPT_SUCCESS == MtdNextKernelEntry(mtd, &start, &size)); - EXPECT(KERNEL_X == mtd->current_kernel); - EXPECT(GPT_SUCCESS == MtdNextKernelEntry(mtd, &start, &size)); - EXPECT(KERNEL_A == mtd->current_kernel); - EXPECT(GPT_ERROR_NO_VALID_KERNEL == - MtdNextKernelEntry(mtd, &start, &size)); - - return TEST_OK; -} - -static int MtdUpdateTest() { - MtdData *mtd = GetEmptyMtdData(); - MtdDiskPartition *e = &mtd->primary.partitions[0]; - uint64_t start, size; - - BuildTestMtdData(mtd); - - /* Tries=nonzero is attempted just like success, but tries=0 isn't */ - MtdFillEntry(e + KERNEL_A, 1, 4, 1, 0); - MtdFillEntry(e + KERNEL_B, 1, 3, 0, 2); - MtdFillEntry(e + KERNEL_X, 1, 2, 0, 2); - mtd->primary.crc32 = MtdHeaderCrc(&mtd->primary); - mtd->modified = 0; - EXPECT(GPT_SUCCESS == MtdInit(mtd)); - - /* Successful kernel */ - EXPECT(GPT_SUCCESS == MtdNextKernelEntry(mtd, &start, &size)); - EXPECT(KERNEL_A == mtd->current_kernel); - EXPECT(1 == MtdGetEntrySuccessful(e + KERNEL_A)); - EXPECT(4 == MtdGetEntryPriority(e + KERNEL_A)); - EXPECT(0 == MtdGetEntryTries(e + KERNEL_A)); - /* Trying successful kernel changes nothing */ - EXPECT(GPT_SUCCESS == MtdUpdateKernelEntry(mtd, GPT_UPDATE_ENTRY_TRY)); - EXPECT(1 == MtdGetEntrySuccessful(e + KERNEL_A)); - EXPECT(4 == MtdGetEntryPriority(e + KERNEL_A)); - EXPECT(0 == MtdGetEntryTries(e + KERNEL_A)); - EXPECT(0 == mtd->modified); - /* Marking it bad also does not update it. */ - EXPECT(GPT_SUCCESS == MtdUpdateKernelEntry(mtd, GPT_UPDATE_ENTRY_BAD)); - EXPECT(1 == MtdGetEntrySuccessful(e + KERNEL_A)); - EXPECT(4 == MtdGetEntryPriority(e + KERNEL_A)); - EXPECT(0 == MtdGetEntryTries(e + KERNEL_A)); - EXPECT(0 == mtd->modified); - - /* Kernel with tries */ - EXPECT(GPT_SUCCESS == MtdNextKernelEntry(mtd, &start, &size)); - EXPECT(KERNEL_B == mtd->current_kernel); - EXPECT(0 == MtdGetEntrySuccessful(e + KERNEL_B)); - EXPECT(3 == MtdGetEntryPriority(e + KERNEL_B)); - EXPECT(2 == MtdGetEntryTries(e + KERNEL_B)); - /* Marking it bad clears it */ - EXPECT(GPT_SUCCESS == MtdUpdateKernelEntry(mtd, GPT_UPDATE_ENTRY_BAD)); - EXPECT(0 == MtdGetEntrySuccessful(e + KERNEL_B)); - EXPECT(0 == MtdGetEntryPriority(e + KERNEL_B)); - EXPECT(0 == MtdGetEntryTries(e + KERNEL_B)); - /* And that's caused the mtd to need updating */ - EXPECT(1 == mtd->modified); - - /* Another kernel with tries */ - EXPECT(GPT_SUCCESS == MtdNextKernelEntry(mtd, &start, &size)); - EXPECT(KERNEL_X == mtd->current_kernel); - EXPECT(0 == MtdGetEntrySuccessful(e + KERNEL_X)); - EXPECT(2 == MtdGetEntryPriority(e + KERNEL_X)); - EXPECT(2 == MtdGetEntryTries(e + KERNEL_X)); - /* Trying it uses up a try */ - EXPECT(GPT_SUCCESS == MtdUpdateKernelEntry(mtd, GPT_UPDATE_ENTRY_TRY)); - EXPECT(0 == MtdGetEntrySuccessful(e + KERNEL_X)); - EXPECT(2 == MtdGetEntryPriority(e + KERNEL_X)); - EXPECT(1 == MtdGetEntryTries(e + KERNEL_X)); - /* Trying it again marks it inactive */ - EXPECT(GPT_SUCCESS == MtdUpdateKernelEntry(mtd, GPT_UPDATE_ENTRY_TRY)); - EXPECT(0 == MtdGetEntrySuccessful(e + KERNEL_X)); - EXPECT(0 == MtdGetEntryPriority(e + KERNEL_X)); - EXPECT(0 == MtdGetEntryTries(e + KERNEL_X)); - - /* Can't update if entry isn't a kernel, or there isn't an entry */ - MtdSetEntryType(e + KERNEL_X, MTD_PARTITION_TYPE_UNUSED); - EXPECT(GPT_ERROR_INVALID_UPDATE_TYPE == - MtdUpdateKernelEntry(mtd, GPT_UPDATE_ENTRY_BAD)); - mtd->current_kernel = CGPT_KERNEL_ENTRY_NOT_FOUND; - EXPECT(GPT_ERROR_INVALID_UPDATE_TYPE == - MtdUpdateKernelEntry(mtd, GPT_UPDATE_ENTRY_BAD)); - - return TEST_OK; -} - static int GptUpdateTest(void) { GptData *gpt = GetEmptyGptData(); @@ -1691,20 +1320,6 @@ static int UpdateInvalidKernelTypeTest(void) return TEST_OK; } -static int MtdUpdateInvalidKernelTypeTest(void) -{ - MtdData *mtd = GetEmptyMtdData(); - - BuildTestMtdData(mtd); - /* anything, but not CGPT_KERNEL_ENTRY_NOT_FOUND */ - mtd->current_kernel = 0; - /* any invalid update_type value */ - EXPECT(GPT_ERROR_INVALID_UPDATE_TYPE == - MtdUpdateKernelEntry(mtd, 99)); - - return TEST_OK; -} - /* Test duplicate UniqueGuids can be detected. */ static int DuplicateUniqueGuidTest(void) { @@ -1799,177 +1414,6 @@ static int ErrorTextTest(void) return TEST_OK; } -int nand_read_page(const nand_geom *nand, int page, void *buf, int size) { - uint32_t ofs = page * nand->szofpg; - uint32_t sz = size; - if (ofs + sz > nand_drive_sz) { - return -1; - } - Memcpy(buf, nand_drive + ofs, sz); - return 0; -} - -int nand_write_page(const nand_geom *nand, int page, - const void *buf, int size) { - uint32_t ofs = page * nand->szofpg; - uint32_t sz = size; - uint32_t i; - if (ofs + sz > nand_drive_sz) { - return -1; - } - for (i = 0; i < sz; i++) { - if (nand_drive[ofs + i] != 0xff) { - return -1; - } - } - Memcpy(nand_drive + ofs, buf, sz); - return 0; -} - -int nand_erase_block(const nand_geom *nand, int block) { - uint32_t ofs = block * nand->szofblk; - uint32_t sz = nand->szofblk; - if (ofs + sz > nand_drive_sz) { - return -1; - } - if (!--nand_bad_block_map[block]) { - return -1; - } - Memset(nand_drive + ofs, 0xFF, sz); - return 0; -} - -int nand_is_bad_block(const nand_geom *nand, int block) { - return nand_bad_block_map[block] == 0; -} - - -static void nand_make_ramdisk() { - if (nand_drive) { - free(nand_drive); - } - if (nand_bad_block_map) { - free(nand_bad_block_map); - } - nand_drive_sz = 1024 * 1024 * 16; - nand_drive = (uint8_t *)malloc(nand_drive_sz); - nand_bad_block_map = (uint8_t *)malloc(nand_drive_sz / 512); - Memset(nand_drive, 0xff, nand_drive_sz); - Memset(nand_bad_block_map, 0xff, nand_drive_sz / 512); -} - -static int MtdFtsTest() { - int MtdLoad(struct drive *drive, int sector_bytes); - int MtdSave(struct drive *drive); - int FlashGet(const char *key, uint8_t *data, uint32_t *bufsz); - int FlashSet(const char *key, const uint8_t *data, uint32_t bufsz); - - int i, j, err; - - struct { - int result; - unsigned int offset, size, block_size_bytes, page_size_bytes; - } cases[] = { - { 0, 1, 2, 1024 * 1024, 1024 * 4 }, - { 0, 1, 2, 1024 * 1024, 1024 * 16 }, - - /* Failure cases, non-power-of-2 */ - { -ENODEV, 1, 2, 5000000, 1024 * 16 }, - { -ENODEV, 1, 2, 1024 * 1024, 65535 }, - - /* Page > block */ - { -ENODEV, 1, 2, 1024 * 16, 1024 * 1024 }, - }; - - - /* Check if the FTS store works */ - for (i = 0; i < ARRAY_SIZE(cases); i++) { - nand_make_ramdisk(); - EXPECT(cases[i].result == flash_ts_init(cases[i].offset, cases[i].size, - cases[i].page_size_bytes, - cases[i].block_size_bytes, 512, 0)); - - if (cases[i].result == 0) { - /* We should have a working FTS store now */ - char buffer[64]; - uint8_t blob[256], blob_read[256]; - uint32_t sz = sizeof(blob_read); - struct drive drive; - - /* Test the low level API */ - EXPECT(0 == flash_ts_set("some_key", "some value")); - flash_ts_get("some_key", buffer, sizeof(buffer)); - EXPECT(0 == strcmp(buffer, "some value")); - - /* Check overwrite */ - EXPECT(0 == flash_ts_set("some_key", "some other value")); - flash_ts_get("some_key", buffer, sizeof(buffer)); - EXPECT(0 == strcmp(buffer, "some other value")); - - /* Check delete */ - EXPECT(0 == flash_ts_set("some_key", "")); - - /* Verify that re-initialization pulls the right record. */ - flash_ts_init(cases[i].offset, cases[i].size, cases[i].page_size_bytes, - cases[i].block_size_bytes, 512, 0); - flash_ts_get("some_key", buffer, sizeof(buffer)); - EXPECT(0 == strcmp(buffer, "")); - - /* Fill up the disk, eating all erase cycles */ - for (j = 0; j < nand_drive_sz / 512; j++) { - nand_bad_block_map[j] = 2; - } - for (j = 0; j < 999999; j++) { - char str[32]; - sprintf(str, "%d", j); - err = flash_ts_set("some_new_key", str); - if (err) { - EXPECT(err == -ENOMEM); - break; - } - - /* Make sure we can figure out where the latest is. */ - flash_ts_init(cases[i].offset, cases[i].size, cases[i].page_size_bytes, - cases[i].block_size_bytes, 512, 0); - flash_ts_get("some_new_key", buffer, sizeof(buffer)); - EXPECT(0 == strcmp(buffer, str)); - } - EXPECT(j < 999999); - - /* We need our drive back. */ - nand_make_ramdisk(); - flash_ts_init(cases[i].offset, cases[i].size, cases[i].page_size_bytes, - cases[i].block_size_bytes, 512, 0); - - - for (j = 0; j < 256; j++) { - blob[j] = j; - } - - /* Hex conversion / blob storage */ - EXPECT(0 == FlashSet("some_blob", blob, sizeof(blob))); - EXPECT(0 == FlashGet("some_blob", blob_read, &sz)); - EXPECT(sz == sizeof(blob_read)); - EXPECT(0 == Memcmp(blob, blob_read, sizeof(blob))); - - BuildTestMtdData(&drive.mtd); - drive.mtd.flash_block_bytes = cases[i].block_size_bytes; - drive.mtd.flash_page_bytes = cases[i].page_size_bytes; - drive.mtd.fts_block_offset = cases[i].offset; - drive.mtd.fts_block_size = cases[i].size; - drive.mtd.sector_bytes = 512; - drive.mtd.drive_sectors = nand_drive_sz / 512; - - /* MTD-level API */ - EXPECT(0 == MtdSave(&drive)); - Memset(&drive.mtd.primary, 0, sizeof(drive.mtd.primary)); - EXPECT(0 == MtdLoad(&drive, 512)); - } - } - - return TEST_OK; -} - static int CheckHeaderOffDevice() { GptData* gpt = GetEmptyGptData(); @@ -2039,7 +1483,6 @@ int main(int argc, char *argv[]) } test_cases[] = { { TEST_CASE(StructSizeTest), }, { TEST_CASE(TestBuildTestGptData), }, - { TEST_CASE(TestBuildTestMtdData), }, { TEST_CASE(ParameterTests), }, { TEST_CASE(HeaderCrcTest), }, { TEST_CASE(HeaderSameTest), }, @@ -2057,24 +1500,17 @@ int main(int argc, char *argv[]) { TEST_CASE(OverlappedPartitionTest), }, { TEST_CASE(SanityCheckTest), }, { TEST_CASE(NoValidKernelEntryTest), }, - { TEST_CASE(MtdNoValidKernelEntryTest), }, { TEST_CASE(EntryAttributeGetSetTest), }, { TEST_CASE(EntryTypeTest), }, { TEST_CASE(GetNextNormalTest), }, { TEST_CASE(GetNextPrioTest), }, { TEST_CASE(GetNextTriesTest), }, - { TEST_CASE(MtdGetNextNormalTest), }, - { TEST_CASE(MtdGetNextPrioTest), }, - { TEST_CASE(MtdGetNextTriesTest), }, { TEST_CASE(GptUpdateTest), }, - { TEST_CASE(MtdUpdateTest), }, { TEST_CASE(UpdateInvalidKernelTypeTest), }, - { TEST_CASE(MtdUpdateInvalidKernelTypeTest), }, { TEST_CASE(DuplicateUniqueGuidTest), }, { TEST_CASE(TestCrc32TestVectors), }, { TEST_CASE(GetKernelGuidTest), }, { TEST_CASE(ErrorTextTest), }, - { TEST_CASE(MtdFtsTest), }, { TEST_CASE(CheckHeaderOffDevice), }, }; |