OLD | NEW |
(Empty) | |
| 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 |
| 3 * found in the LICENSE file. |
| 4 */ |
| 5 |
| 6 #include "cgpt.h" |
| 7 #include "cgpt_test.h" |
| 8 |
| 9 #define TEST_CASE(func) #func, func |
| 10 typedef int (*test_func)(void); |
| 11 |
| 12 /* Tests if header CRC in two copies are calculated. */ |
| 13 int HeaderCrcTest() { |
| 14 return TEST_FAIL; |
| 15 } |
| 16 |
| 17 /* Tests if myLBA field is checked (1 for primary, last for secondary). */ |
| 18 int MyLbaTest() { |
| 19 return TEST_FAIL; |
| 20 } |
| 21 |
| 22 /* Tests if SizeOfPartitionEntry is checked. SizeOfPartitionEntry must be |
| 23 * between 128 and 512, and a multiple of 8. */ |
| 24 int SizeOfPartitionEntryTest() { |
| 25 return TEST_FAIL; |
| 26 } |
| 27 |
| 28 /* Tests if NumberOfPartitionEntries is checes. NumberOfPartitionEntries must |
| 29 * be between 32 and 512, and SizeOfPartitionEntry * NumberOfPartitionEntries |
| 30 * must be 16384. */ |
| 31 int NumberOfPartitionEntriesTest() { |
| 32 return TEST_FAIL; |
| 33 } |
| 34 |
| 35 /* Tests if PartitionEntryLBA in primary/secondary headers is checked. */ |
| 36 int PartitionEntryLbaTest() { |
| 37 return TEST_FAIL; |
| 38 } |
| 39 |
| 40 /* Tests if FirstUsableLBA and LastUsableLBA are checked. |
| 41 * FirstUsableLBA must be after the end of the primary GPT table array. |
| 42 * LastUsableLBA must be before the start of the secondary GPT table array. |
| 43 * FirstUsableLBA <= LastUsableLBA. */ |
| 44 int FirstUsableLbaAndLastUsableLbaTest() { |
| 45 return TEST_FAIL; |
| 46 } |
| 47 |
| 48 /* Tests if GPTInit() handles non-identical partition entries well. |
| 49 * Two copies of partition table entries must be identical. If not, we trust the |
| 50 * primary table entries, and mark secondary as modified (see Caller's write- |
| 51 * back order below). */ |
| 52 int IdenticalEntriesTest() { |
| 53 return TEST_FAIL; |
| 54 } |
| 55 |
| 56 /* Tests if GPTInit() handles non-identical headers well. |
| 57 * Two partition headers must be identical. If not, we trust the primary |
| 58 * partition header, and mark secondary as modified (see Caller's write-back |
| 59 * order below). */ |
| 60 int IdenticalHeaderTest() { |
| 61 return TEST_FAIL; |
| 62 } |
| 63 |
| 64 /* Tests if PartitionEntryArrayCRC32 is checked. |
| 65 * PartitionEntryArrayCRC32 must be calculated over SizeOfPartitionEntry * |
| 66 * NumberOfPartitionEntries bytes. |
| 67 */ |
| 68 int EntriesCrcTest() { |
| 69 return TEST_FAIL; |
| 70 } |
| 71 |
| 72 /* Tests if partition geometry is checked. |
| 73 * All active (non-zero PartitionTypeGUID) partition entries should have: |
| 74 * entry.StartingLBA >= header.FirstUsableLBA |
| 75 * entry.EndingLBA <= header.LastUsableLBA |
| 76 * entry.StartingLBA <= entry.EndingLBA |
| 77 */ |
| 78 int ValidEntryTest() { |
| 79 return TEST_FAIL; |
| 80 } |
| 81 |
| 82 /* Tests if overlapped partition tables can be detected. */ |
| 83 int NoOverlappedPartitionTest() { |
| 84 return TEST_FAIL; |
| 85 } |
| 86 |
| 87 /* Tests if GPTNextKernelEntry() can survive in different corrupt header/entries |
| 88 * combinations, like: |
| 89 * primary GPT header - valid |
| 90 * primary partition table - invalid |
| 91 * secondary partition table - valid |
| 92 * secondary GPT header - invalid |
| 93 */ |
| 94 int CorruptCombinationTest() { |
| 95 return TEST_FAIL; |
| 96 } |
| 97 |
| 98 int main(int argc, char *argv[]) { |
| 99 int i; |
| 100 struct { |
| 101 char *name; |
| 102 test_func fp; |
| 103 int retval; |
| 104 } test_cases[] = { |
| 105 { TEST_CASE(HeaderCrcTest), }, |
| 106 { TEST_CASE(MyLbaTest), }, |
| 107 { TEST_CASE(SizeOfPartitionEntryTest), }, |
| 108 { TEST_CASE(NumberOfPartitionEntriesTest), }, |
| 109 { TEST_CASE(PartitionEntryLbaTest), }, |
| 110 { TEST_CASE(FirstUsableLbaAndLastUsableLbaTest), }, |
| 111 { TEST_CASE(IdenticalEntriesTest), }, |
| 112 { TEST_CASE(IdenticalHeaderTest), }, |
| 113 { TEST_CASE(EntriesCrcTest), }, |
| 114 { TEST_CASE(ValidEntryTest), }, |
| 115 { TEST_CASE(NoOverlappedPartitionTest), }, |
| 116 { TEST_CASE(CorruptCombinationTest), }, |
| 117 }; |
| 118 |
| 119 for (i = 0; i < sizeof(test_cases)/sizeof(test_cases[0]); ++i) { |
| 120 printf("Running %s() ...\n", test_cases[i].name); |
| 121 test_cases[i].retval = test_cases[i].fp(); |
| 122 if (test_cases[i].retval) |
| 123 printf(COL_RED "[ERROR]" COL_STOP " %s()\n\n", test_cases[i].name); |
| 124 else |
| 125 printf(COL_GREEN "[PASS]" COL_STOP " %s()\n\n", test_cases[i].name); |
| 126 } |
| 127 |
| 128 printf("\n--------------------------------------------------\n"); |
| 129 printf("The following test cases are failed:\n"); |
| 130 for (i = 0; i < sizeof(test_cases)/sizeof(test_cases[0]); ++i) { |
| 131 if (test_cases[i].retval) |
| 132 printf(" %s()\n", test_cases[i].name); |
| 133 } |
| 134 |
| 135 return 0; |
| 136 } |
OLD | NEW |