Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: src/platform/vboot_reference/cgptlib/tests/cgptlib_test.c

Issue 2231002: complete 'cgpt show' and refactor for incoming commands. (Closed) Base URL: ssh://git@chromiumos-git/chromeos
Patch Set: Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be 2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. 3 * found in the LICENSE file.
4 */ 4 */
5 5
6 #include "cgptlib_test.h" 6 #include "cgptlib_test.h"
7 #include <string.h> 7 #include <string.h>
8 #include "cgptlib.h" 8 #include "cgptlib.h"
9 #include "cgptlib_internal.h" 9 #include "cgptlib_internal.h"
10 #include "crc32.h" 10 #include "crc32.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 * this file. */ 107 * this file. */
108 void BuildTestGptData(GptData *gpt) { 108 void BuildTestGptData(GptData *gpt) {
109 GptHeader *header, *header2; 109 GptHeader *header, *header2;
110 GptEntry *entries, *entries2; 110 GptEntry *entries, *entries2;
111 Guid chromeos_kernel = GPT_ENT_TYPE_CHROMEOS_KERNEL; 111 Guid chromeos_kernel = GPT_ENT_TYPE_CHROMEOS_KERNEL;
112 Guid chromeos_rootfs = GPT_ENT_TYPE_CHROMEOS_ROOTFS; 112 Guid chromeos_rootfs = GPT_ENT_TYPE_CHROMEOS_ROOTFS;
113 113
114 gpt->sector_bytes = DEFAULT_SECTOR_SIZE; 114 gpt->sector_bytes = DEFAULT_SECTOR_SIZE;
115 gpt->drive_sectors = DEFAULT_DRIVE_SECTORS; 115 gpt->drive_sectors = DEFAULT_DRIVE_SECTORS;
116 gpt->current_kernel = CGPT_KERNEL_ENTRY_NOT_FOUND; 116 gpt->current_kernel = CGPT_KERNEL_ENTRY_NOT_FOUND;
117 gpt->valid_headers = MASK_BOTH;
118 gpt->valid_entries = MASK_BOTH;
117 119
118 /* build primary */ 120 /* build primary */
119 header = (GptHeader*)gpt->primary_header; 121 header = (GptHeader*)gpt->primary_header;
120 entries = (GptEntry*)gpt->primary_entries; 122 entries = (GptEntry*)gpt->primary_entries;
121 Memcpy(header->signature, GPT_HEADER_SIGNATURE, sizeof(GPT_HEADER_SIGNATURE)); 123 Memcpy(header->signature, GPT_HEADER_SIGNATURE, sizeof(GPT_HEADER_SIGNATURE));
122 header->revision = GPT_HEADER_REVISION; 124 header->revision = GPT_HEADER_REVISION;
123 header->size = sizeof(GptHeader) - sizeof(header->padding); 125 header->size = sizeof(GptHeader) - sizeof(header->padding);
124 header->reserved = 0; 126 header->reserved = 0;
125 header->my_lba = 1; 127 header->my_lba = 1;
126 header->first_usable_lba = 34; 128 header->first_usable_lba = 34;
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 /* Modify the last byte of secondary header, and expect the CRC is wrong. */ 595 /* Modify the last byte of secondary header, and expect the CRC is wrong. */
594 BuildTestGptData(gpt); 596 BuildTestGptData(gpt);
595 gpt->secondary_header[secondary_header->size-1] ^= 0x5a; 597 gpt->secondary_header[secondary_header->size-1] ^= 0x5a;
596 EXPECT(MASK_PRIMARY == CheckHeaderCrc(gpt)); 598 EXPECT(MASK_PRIMARY == CheckHeaderCrc(gpt));
597 599
598 /* Modify out of CRC range, expect CRC is still right. */ 600 /* Modify out of CRC range, expect CRC is still right. */
599 BuildTestGptData(gpt); 601 BuildTestGptData(gpt);
600 gpt->primary_header[primary_header->size] ^= 0x87; 602 gpt->primary_header[primary_header->size] ^= 0x87;
601 EXPECT(MASK_BOTH == CheckHeaderCrc(gpt)); 603 EXPECT(MASK_BOTH == CheckHeaderCrc(gpt));
602 604
605 /* Very long header (actually invalid header). Expect will be ignored. */
606 primary_header->size = 0x12345678;
607 secondary_header->size = 0x87654321;
608 gpt->valid_headers = MASK_NONE;
609 EXPECT(MASK_NONE == CheckHeaderCrc(gpt));
610
603 return TEST_OK; 611 return TEST_OK;
604 } 612 }
605 613
606 /* Tests if PartitionEntryArrayCRC32 is checked. 614 /* Tests if PartitionEntryArrayCRC32 is checked.
607 * PartitionEntryArrayCRC32 must be calculated over SizeOfPartitionEntry * 615 * PartitionEntryArrayCRC32 must be calculated over SizeOfPartitionEntry *
608 * NumberOfPartitionEntries bytes. 616 * NumberOfPartitionEntries bytes.
609 */ 617 */
610 int EntriesCrcTest() { 618 int EntriesCrcTest() {
611 GptData *gpt; 619 GptData *gpt;
612 620
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 secondary_header->disk_uuid.u.raw[0] ^= 0x56; 720 secondary_header->disk_uuid.u.raw[0] ^= 0x56;
713 EXPECT(GPT_MODIFIED_HEADER2 == RepairHeader(gpt, MASK_BOTH)); 721 EXPECT(GPT_MODIFIED_HEADER2 == RepairHeader(gpt, MASK_BOTH));
714 EXPECT(0 == Memcmp(&primary_header->disk_uuid, 722 EXPECT(0 == Memcmp(&primary_header->disk_uuid,
715 &secondary_header->disk_uuid, sizeof(Guid))); 723 &secondary_header->disk_uuid, sizeof(Guid)));
716 724
717 /* Consider header repairing in GptInit(). */ 725 /* Consider header repairing in GptInit(). */
718 BuildTestGptData(gpt); 726 BuildTestGptData(gpt);
719 ++secondary_header->first_usable_lba; 727 ++secondary_header->first_usable_lba;
720 RefreshCrc32(gpt); 728 RefreshCrc32(gpt);
721 EXPECT(GPT_SUCCESS == GptInit(gpt)); 729 EXPECT(GPT_SUCCESS == GptInit(gpt));
722 EXPECT(GPT_MODIFIED_HEADER2 == gpt->modified); 730 EXPECT((gpt->modified & (GPT_MODIFIED_HEADER1 | GPT_MODIFIED_HEADER2)) ==
731 GPT_MODIFIED_HEADER2);
723 EXPECT(primary_header->first_usable_lba == 732 EXPECT(primary_header->first_usable_lba ==
724 secondary_header->first_usable_lba); 733 secondary_header->first_usable_lba);
725 734
726 return TEST_OK; 735 return TEST_OK;
727 } 736 }
728 737
729 /* Tests if partition geometry is checked. 738 /* Tests if partition geometry is checked.
730 * All active (non-zero PartitionTypeGUID) partition entries should have: 739 * All active (non-zero PartitionTypeGUID) partition entries should have:
731 * entry.StartingLBA >= header.FirstUsableLBA 740 * entry.StartingLBA >= header.FirstUsableLBA
732 * entry.EndingLBA <= header.LastUsableLBA 741 * entry.EndingLBA <= header.LastUsableLBA
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 EXPECT(0 == Memcmp(primary_entries, secondary_entries, TOTAL_ENTRIES_SIZE)); 894 EXPECT(0 == Memcmp(primary_entries, secondary_entries, TOTAL_ENTRIES_SIZE));
886 /* We expect the modified header/entries can pass GptInit(). */ 895 /* We expect the modified header/entries can pass GptInit(). */
887 EXPECT(GPT_SUCCESS == GptInit(gpt)); 896 EXPECT(GPT_SUCCESS == GptInit(gpt));
888 EXPECT(0 == gpt->modified); 897 EXPECT(0 == gpt->modified);
889 898
890 /* Make primary header invalid (the entries is not damaged actually). */ 899 /* Make primary header invalid (the entries is not damaged actually). */
891 BuildTestGptData(gpt); 900 BuildTestGptData(gpt);
892 primary_header->entries_crc32 ^= 0x73; 901 primary_header->entries_crc32 ^= 0x73;
893 EXPECT(GPT_SUCCESS == GptInit(gpt)); 902 EXPECT(GPT_SUCCESS == GptInit(gpt));
894 /* After header is repaired, the entries are valid actually. */ 903 /* After header is repaired, the entries are valid actually. */
895 EXPECT((GPT_MODIFIED_HEADER1) == gpt->modified); 904 EXPECT((gpt->modified & (GPT_MODIFIED_HEADER1 | GPT_MODIFIED_HEADER2)) ==
905 GPT_MODIFIED_HEADER1);
896 /* We expect the modified header/entries can pass GptInit(). */ 906 /* We expect the modified header/entries can pass GptInit(). */
897 EXPECT(GPT_SUCCESS == GptInit(gpt)); 907 EXPECT(GPT_SUCCESS == GptInit(gpt));
898 EXPECT(0 == gpt->modified); 908 EXPECT(0 == gpt->modified);
899 909
900 return TEST_OK; 910 return TEST_OK;
901 } 911 }
902 912
903 /* Invalidate all kernel entries and expect GptNextKernelEntry() cannot find 913 /* Invalidate all kernel entries and expect GptNextKernelEntry() cannot find
904 * any usable kernel entry. 914 * any usable kernel entry.
905 */ 915 */
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 printf(COL_RED "The following %d test cases are failed:\n" COL_STOP, 1181 printf(COL_RED "The following %d test cases are failed:\n" COL_STOP,
1172 error_count); 1182 error_count);
1173 for (i = 0; i < sizeof(test_cases)/sizeof(test_cases[0]); ++i) { 1183 for (i = 0; i < sizeof(test_cases)/sizeof(test_cases[0]); ++i) {
1174 if (test_cases[i].retval) 1184 if (test_cases[i].retval)
1175 printf(" %s()\n", test_cases[i].name); 1185 printf(" %s()\n", test_cases[i].name);
1176 } 1186 }
1177 } 1187 }
1178 1188
1179 return (error_count) ? 1 : 0; 1189 return (error_count) ? 1 : 0;
1180 } 1190 }
OLDNEW
« no previous file with comments | « src/platform/vboot_reference/cgptlib/cgptlib_internal.h ('k') | src/platform/vboot_reference/utility/cgpt/Makefile » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698