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

Side by Side Diff: tests/cgptlib_test.c

Issue 2809037: Make vboot_reference build in MSVC command line environment. (Closed) Base URL: ssh://git@chromiumos-git/vboot_reference.git
Patch Set: Integrated trunk changes. Created 10 years, 6 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
« no previous file with comments | « tests/cgptlib_test.h ('k') | tests/crc32_test.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <string.h> 6 #include <string.h>
7 7
8 #include "cgptlib.h" 8 #include "cgptlib.h"
9 #include "cgptlib_internal.h" 9 #include "cgptlib_internal.h"
10 #include "cgptlib_test.h" 10 #include "cgptlib_test.h"
11 #include "crc32.h" 11 #include "crc32.h"
12 #include "crc32_test.h" 12 #include "crc32_test.h"
13 #include "gpt.h" 13 #include "gpt.h"
14 #include "test_common.h"
14 #include "utility.h" 15 #include "utility.h"
15 16
16 /* Testing partition layout (sector_bytes=512) 17 /* Testing partition layout (sector_bytes=512)
17 * 18 *
18 * LBA Size Usage 19 * LBA Size Usage
19 * --------------------------------------------------------- 20 * ---------------------------------------------------------
20 * 0 1 PMBR 21 * 0 1 PMBR
21 * 1 1 primary partition header 22 * 1 1 primary partition header
22 * 2 32 primary partition entries (128B * 128) 23 * 2 32 primary partition entries (128B * 128)
23 * 34 100 kernel A (index: 0) 24 * 34 100 kernel A (index: 0)
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 * NumberOfPartitionEntries bytes. 554 * NumberOfPartitionEntries bytes.
554 */ 555 */
555 static int EntriesCrcTest() { 556 static int EntriesCrcTest() {
556 GptData* gpt = GetEmptyGptData(); 557 GptData* gpt = GetEmptyGptData();
557 GptHeader* h1 = (GptHeader*)gpt->primary_header; 558 GptHeader* h1 = (GptHeader*)gpt->primary_header;
558 GptEntry* e1 = (GptEntry*)(gpt->primary_entries); 559 GptEntry* e1 = (GptEntry*)(gpt->primary_entries);
559 GptEntry* e2 = (GptEntry*)(gpt->secondary_entries); 560 GptEntry* e2 = (GptEntry*)(gpt->secondary_entries);
560 561
561 /* Modify the first byte of primary entries, and expect the CRC is wrong. */ 562 /* Modify the first byte of primary entries, and expect the CRC is wrong. */
562 BuildTestGptData(gpt); 563 BuildTestGptData(gpt);
563 EXPECT(0 == CheckEntries(e1, h1, gpt->drive_sectors)); 564 EXPECT(0 == CheckEntries(e1, h1));
564 EXPECT(0 == CheckEntries(e2, h1, gpt->drive_sectors)); 565 EXPECT(0 == CheckEntries(e2, h1));
565 gpt->primary_entries[0] ^= 0xa5; /* just XOR a non-zero value */ 566 gpt->primary_entries[0] ^= 0xa5; /* just XOR a non-zero value */
566 gpt->secondary_entries[TOTAL_ENTRIES_SIZE-1] ^= 0x5a; 567 gpt->secondary_entries[TOTAL_ENTRIES_SIZE-1] ^= 0x5a;
567 EXPECT(1 == CheckEntries(e1, h1, gpt->drive_sectors)); 568 EXPECT(1 == CheckEntries(e1, h1));
568 EXPECT(1 == CheckEntries(e2, h1, gpt->drive_sectors)); 569 EXPECT(1 == CheckEntries(e2, h1));
569 570
570 return TEST_OK; 571 return TEST_OK;
571 } 572 }
572 573
573 574
574 /* Tests if partition geometry is checked. 575 /* Tests if partition geometry is checked.
575 * All active (non-zero PartitionTypeGUID) partition entries should have: 576 * All active (non-zero PartitionTypeGUID) partition entries should have:
576 * entry.StartingLBA >= header.FirstUsableLBA 577 * entry.StartingLBA >= header.FirstUsableLBA
577 * entry.EndingLBA <= header.LastUsableLBA 578 * entry.EndingLBA <= header.LastUsableLBA
578 * entry.StartingLBA <= entry.EndingLBA 579 * entry.StartingLBA <= entry.EndingLBA
579 */ 580 */
580 static int ValidEntryTest() { 581 static int ValidEntryTest() {
581 GptData* gpt = GetEmptyGptData(); 582 GptData* gpt = GetEmptyGptData();
582 GptHeader* h1 = (GptHeader*)gpt->primary_header; 583 GptHeader* h1 = (GptHeader*)gpt->primary_header;
583 GptEntry* e1 = (GptEntry*)(gpt->primary_entries); 584 GptEntry* e1 = (GptEntry*)(gpt->primary_entries);
584 585
585 /* error case: entry.StartingLBA < header.FirstUsableLBA */ 586 /* error case: entry.StartingLBA < header.FirstUsableLBA */
586 BuildTestGptData(gpt); 587 BuildTestGptData(gpt);
587 e1[0].starting_lba = h1->first_usable_lba - 1; 588 e1[0].starting_lba = h1->first_usable_lba - 1;
588 RefreshCrc32(gpt); 589 RefreshCrc32(gpt);
589 EXPECT(1 == CheckEntries(e1, h1, gpt->drive_sectors)); 590 EXPECT(1 == CheckEntries(e1, h1));
590 591
591 /* error case: entry.EndingLBA > header.LastUsableLBA */ 592 /* error case: entry.EndingLBA > header.LastUsableLBA */
592 BuildTestGptData(gpt); 593 BuildTestGptData(gpt);
593 e1[2].ending_lba = h1->last_usable_lba + 1; 594 e1[2].ending_lba = h1->last_usable_lba + 1;
594 RefreshCrc32(gpt); 595 RefreshCrc32(gpt);
595 EXPECT(1 == CheckEntries(e1, h1, gpt->drive_sectors)); 596 EXPECT(1 == CheckEntries(e1, h1));
596 597
597 /* error case: entry.StartingLBA > entry.EndingLBA */ 598 /* error case: entry.StartingLBA > entry.EndingLBA */
598 BuildTestGptData(gpt); 599 BuildTestGptData(gpt);
599 e1[3].starting_lba = e1[3].ending_lba + 1; 600 e1[3].starting_lba = e1[3].ending_lba + 1;
600 RefreshCrc32(gpt); 601 RefreshCrc32(gpt);
601 EXPECT(1 == CheckEntries(e1, h1, gpt->drive_sectors)); 602 EXPECT(1 == CheckEntries(e1, h1));
602 603
603 /* case: non active entry should be ignored. */ 604 /* case: non active entry should be ignored. */
604 BuildTestGptData(gpt); 605 BuildTestGptData(gpt);
605 Memset(&e1[1].type, 0, sizeof(e1[1].type)); 606 Memset(&e1[1].type, 0, sizeof(e1[1].type));
606 e1[1].starting_lba = e1[1].ending_lba + 1; 607 e1[1].starting_lba = e1[1].ending_lba + 1;
607 RefreshCrc32(gpt); 608 RefreshCrc32(gpt);
608 EXPECT(0 == CheckEntries(e1, h1, gpt->drive_sectors)); 609 EXPECT(0 == CheckEntries(e1, h1));
609 610
610 return TEST_OK; 611 return TEST_OK;
611 } 612 }
612 613
613 614
614 /* Tests if overlapped partition tables can be detected. */ 615 /* Tests if overlapped partition tables can be detected. */
615 static int OverlappedPartitionTest() { 616 static int OverlappedPartitionTest() {
616 GptData* gpt = GetEmptyGptData(); 617 GptData* gpt = GetEmptyGptData();
617 GptHeader* h = (GptHeader*)gpt->primary_header; 618 GptHeader* h = (GptHeader*)gpt->primary_header;
618 GptEntry* e = (GptEntry*)gpt->primary_entries; 619 GptEntry* e = (GptEntry*)gpt->primary_entries;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 if (!cases[i].entries[j].starting_lba) 661 if (!cases[i].entries[j].starting_lba)
661 break; 662 break;
662 663
663 if (cases[i].entries[j].active) 664 if (cases[i].entries[j].active)
664 Memcpy(&e[j].type, &guid_kernel, sizeof(Guid)); 665 Memcpy(&e[j].type, &guid_kernel, sizeof(Guid));
665 e[j].starting_lba = cases[i].entries[j].starting_lba; 666 e[j].starting_lba = cases[i].entries[j].starting_lba;
666 e[j].ending_lba = cases[i].entries[j].ending_lba; 667 e[j].ending_lba = cases[i].entries[j].ending_lba;
667 } 668 }
668 RefreshCrc32(gpt); 669 RefreshCrc32(gpt);
669 670
670 EXPECT(cases[i].overlapped == CheckEntries(e, h, gpt->drive_sectors)); 671 EXPECT(cases[i].overlapped == CheckEntries(e, h));
671 } 672 }
672 return TEST_OK; 673 return TEST_OK;
673 } 674 }
674 675
675 676
676 /* Test both sanity checking and repair. */ 677 /* Test both sanity checking and repair. */
677 static int SanityCheckTest() { 678 static int SanityCheckTest() {
678 GptData* gpt = GetEmptyGptData(); 679 GptData* gpt = GetEmptyGptData();
679 GptHeader* h1 = (GptHeader*)gpt->primary_header; 680 GptHeader* h1 = (GptHeader*)gpt->primary_header;
680 681
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 EXPECT((GPT_MODIFIED_HEADER2 | GPT_MODIFIED_ENTRIES2) == gpt->modified); 817 EXPECT((GPT_MODIFIED_HEADER2 | GPT_MODIFIED_ENTRIES2) == gpt->modified);
817 818
818 return TEST_OK; 819 return TEST_OK;
819 } 820 }
820 821
821 822
822 static int EntryAttributeGetSetTest() { 823 static int EntryAttributeGetSetTest() {
823 GptData* gpt = GetEmptyGptData(); 824 GptData* gpt = GetEmptyGptData();
824 GptEntry* e = (GptEntry*)(gpt->primary_entries); 825 GptEntry* e = (GptEntry*)(gpt->primary_entries);
825 826
826 e->attrs.whole = 0x0000000000000000LLU; 827 e->attrs.whole = 0x0000000000000000ULL;
827 SetEntrySuccessful(e, 1); 828 SetEntrySuccessful(e, 1);
828 EXPECT(0x0100000000000000LLU == e->attrs.whole); 829 EXPECT(0x0100000000000000ULL == e->attrs.whole);
829 EXPECT(1 == GetEntrySuccessful(e)); 830 EXPECT(1 == GetEntrySuccessful(e));
830 e->attrs.whole = 0xFFFFFFFFFFFFFFFFLLU; 831 e->attrs.whole = 0xFFFFFFFFFFFFFFFFULL;
831 SetEntrySuccessful(e, 0); 832 SetEntrySuccessful(e, 0);
832 EXPECT(0xFEFFFFFFFFFFFFFFLLU == e->attrs.whole); 833 EXPECT(0xFEFFFFFFFFFFFFFFULL == e->attrs.whole);
833 EXPECT(0 == GetEntrySuccessful(e)); 834 EXPECT(0 == GetEntrySuccessful(e));
834 835
835 e->attrs.whole = 0x0000000000000000LLU; 836 e->attrs.whole = 0x0000000000000000ULL;
836 SetEntryTries(e, 15); 837 SetEntryTries(e, 15);
837 EXPECT(15 == GetEntryTries(e)); 838 EXPECT(15 == GetEntryTries(e));
838 EXPECT(0x00F0000000000000LLU == e->attrs.whole); 839 EXPECT(0x00F0000000000000ULL == e->attrs.whole);
839 e->attrs.whole = 0xFFFFFFFFFFFFFFFFLLU; 840 e->attrs.whole = 0xFFFFFFFFFFFFFFFFULL;
840 SetEntryTries(e, 0); 841 SetEntryTries(e, 0);
841 EXPECT(0xFF0FFFFFFFFFFFFFLLU == e->attrs.whole); 842 EXPECT(0xFF0FFFFFFFFFFFFFULL == e->attrs.whole);
842 EXPECT(0 == GetEntryTries(e)); 843 EXPECT(0 == GetEntryTries(e));
843 844
844 e->attrs.whole = 0x0000000000000000LLU; 845 e->attrs.whole = 0x0000000000000000ULL;
845 SetEntryPriority(e, 15); 846 SetEntryPriority(e, 15);
846 EXPECT(0x000F000000000000LLU == e->attrs.whole); 847 EXPECT(0x000F000000000000ULL == e->attrs.whole);
847 EXPECT(15 == GetEntryPriority(e)); 848 EXPECT(15 == GetEntryPriority(e));
848 e->attrs.whole = 0xFFFFFFFFFFFFFFFFLLU; 849 e->attrs.whole = 0xFFFFFFFFFFFFFFFFULL;
849 SetEntryPriority(e, 0); 850 SetEntryPriority(e, 0);
850 EXPECT(0xFFF0FFFFFFFFFFFFLLU == e->attrs.whole); 851 EXPECT(0xFFF0FFFFFFFFFFFFULL == e->attrs.whole);
851 EXPECT(0 == GetEntryPriority(e)); 852 EXPECT(0 == GetEntryPriority(e));
852 853
853 e->attrs.whole = 0xFFFFFFFFFFFFFFFFLLU; 854 e->attrs.whole = 0xFFFFFFFFFFFFFFFFULL;
854 EXPECT(1 == GetEntrySuccessful(e)); 855 EXPECT(1 == GetEntrySuccessful(e));
855 EXPECT(15 == GetEntryPriority(e)); 856 EXPECT(15 == GetEntryPriority(e));
856 EXPECT(15 == GetEntryTries(e)); 857 EXPECT(15 == GetEntryTries(e));
857 858
858 e->attrs.whole = 0x0123000000000000LLU; 859 e->attrs.whole = 0x0123000000000000ULL;
859 EXPECT(1 == GetEntrySuccessful(e)); 860 EXPECT(1 == GetEntrySuccessful(e));
860 EXPECT(2 == GetEntryTries(e)); 861 EXPECT(2 == GetEntryTries(e));
861 EXPECT(3 == GetEntryPriority(e)); 862 EXPECT(3 == GetEntryPriority(e));
862 863
863 return TEST_OK; 864 return TEST_OK;
864 } 865 }
865 866
866 867
867 static int EntryTypeTest() { 868 static int EntryTypeTest() {
868 GptData* gpt = GetEmptyGptData(); 869 GptData* gpt = GetEmptyGptData();
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1084 GptData* gpt = GetEmptyGptData(); 1085 GptData* gpt = GetEmptyGptData();
1085 1086
1086 BuildTestGptData(gpt); 1087 BuildTestGptData(gpt);
1087 gpt->current_kernel = 0; /* anything, but not CGPT_KERNEL_ENTRY_NOT_FOUND */ 1088 gpt->current_kernel = 0; /* anything, but not CGPT_KERNEL_ENTRY_NOT_FOUND */
1088 EXPECT(GPT_ERROR_INVALID_UPDATE_TYPE == 1089 EXPECT(GPT_ERROR_INVALID_UPDATE_TYPE ==
1089 GptUpdateKernelEntry(gpt, 99)); /* any invalid update_type value */ 1090 GptUpdateKernelEntry(gpt, 99)); /* any invalid update_type value */
1090 1091
1091 return TEST_OK; 1092 return TEST_OK;
1092 } 1093 }
1093 1094
1095 /* disable MSVC warnings on unused arguments */
1096 __pragma(warning (disable: 4100))
1094 1097
1095 int main(int argc, char *argv[]) { 1098 int main(int argc, char *argv[]) {
1096 int i; 1099 int i;
1097 int error_count = 0; 1100 int error_count = 0;
1098 struct { 1101 struct {
1099 char *name; 1102 char *name;
1100 test_func fp; 1103 test_func fp;
1101 int retval; 1104 int retval;
1102 } test_cases[] = { 1105 } test_cases[] = {
1103 { TEST_CASE(StructSizeTest), }, 1106 { TEST_CASE(StructSizeTest), },
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1144 printf(COL_RED "The following %d test cases are failed:\n" COL_STOP, 1147 printf(COL_RED "The following %d test cases are failed:\n" COL_STOP,
1145 error_count); 1148 error_count);
1146 for (i = 0; i < sizeof(test_cases)/sizeof(test_cases[0]); ++i) { 1149 for (i = 0; i < sizeof(test_cases)/sizeof(test_cases[0]); ++i) {
1147 if (test_cases[i].retval) 1150 if (test_cases[i].retval)
1148 printf(" %s()\n", test_cases[i].name); 1151 printf(" %s()\n", test_cases[i].name);
1149 } 1152 }
1150 } 1153 }
1151 1154
1152 return (error_count) ? 1 : 0; 1155 return (error_count) ? 1 : 0;
1153 } 1156 }
OLDNEW
« no previous file with comments | « tests/cgptlib_test.h ('k') | tests/crc32_test.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698