Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 1 | #!/bin/bash -eu |
| 2 | |
| 3 | # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | # |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 7 | # Run tests for cgpt utility. |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 8 | |
| 9 | # Load common constants and variables. |
| 10 | . "$(dirname "$0")/common.sh" |
| 11 | |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 12 | CGPT=$(readlink -f "$1") |
| 13 | [ -x "$CGPT" ] || error "Can't execute $CGPT" |
Bill Richardson | 793e1b4 | 2010-08-20 07:58:43 -0700 | [diff] [blame] | 14 | |
Albert Chaulk | 42c08cb | 2013-04-02 14:38:07 -0700 | [diff] [blame] | 15 | MTD="${2:-}" |
| 16 | CGPT="${CGPT} ${MTD}" |
| 17 | |
Bill Richardson | 793e1b4 | 2010-08-20 07:58:43 -0700 | [diff] [blame] | 18 | # Run tests in a dedicated directory for easy cleanup or debugging. |
| 19 | DIR="${TEST_DIR}/cgpt_test_dir" |
| 20 | [ -d "$DIR" ] || mkdir -p "$DIR" |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 21 | warning "testing $CGPT in $DIR" |
Bill Richardson | 793e1b4 | 2010-08-20 07:58:43 -0700 | [diff] [blame] | 22 | cd "$DIR" |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 23 | |
Nam T. Nguyen | 6ee52d9 | 2014-10-24 13:20:39 -0700 | [diff] [blame^] | 24 | # Test failure on non existing file. |
| 25 | set +e |
| 26 | ${CGPT} show blah_404_haha |
| 27 | [ $? != 0 ] || error "CGPT should fail on non existing file." |
| 28 | set -e |
| 29 | |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 30 | echo "Create an empty file to use as the device..." |
| 31 | NUM_SECTORS=1000 |
Bill Richardson | 793e1b4 | 2010-08-20 07:58:43 -0700 | [diff] [blame] | 32 | DEV=fake_dev.bin |
Bill Richardson | 23429d3 | 2012-04-30 11:33:13 -0700 | [diff] [blame] | 33 | rm -f ${DEV} |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 34 | dd if=/dev/zero of=${DEV} conv=notrunc bs=512 count=${NUM_SECTORS} 2>/dev/null |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 35 | |
| 36 | |
| 37 | echo "Create a bunch of partitions, using the real GUID types..." |
| 38 | DATA_START=100 |
| 39 | DATA_SIZE=20 |
| 40 | DATA_LABEL="data stuff" |
| 41 | DATA_GUID='ebd0a0a2-b9e5-4433-87c0-68b6b72699c7' |
| 42 | DATA_NUM=1 |
| 43 | |
| 44 | KERN_START=200 |
| 45 | KERN_SIZE=30 |
| 46 | KERN_LABEL="kernel stuff" |
| 47 | KERN_GUID='fe3a2a5d-4f32-41a7-b725-accc3285a309' |
| 48 | KERN_NUM=2 |
| 49 | |
| 50 | ROOTFS_START=300 |
| 51 | ROOTFS_SIZE=40 |
| 52 | ROOTFS_LABEL="rootfs stuff" |
| 53 | ROOTFS_GUID='3cb8e202-3b7e-47dd-8a3c-7ff2a13cfcec' |
| 54 | ROOTFS_NUM=3 |
| 55 | |
| 56 | ESP_START=400 |
| 57 | ESP_SIZE=50 |
| 58 | ESP_LABEL="ESP stuff" |
| 59 | ESP_GUID='c12a7328-f81f-11d2-ba4b-00a0c93ec93b' |
| 60 | ESP_NUM=4 |
| 61 | |
| 62 | FUTURE_START=500 |
| 63 | FUTURE_SIZE=60 |
| 64 | FUTURE_LABEL="future stuff" |
| 65 | FUTURE_GUID='2e0a753d-9e48-43b0-8337-b15192cb1b5e' |
| 66 | FUTURE_NUM=5 |
| 67 | |
| 68 | RANDOM_START=600 |
| 69 | RANDOM_SIZE=70 |
| 70 | RANDOM_LABEL="random stuff" |
| 71 | RANDOM_GUID='2364a860-bf63-42fb-a83d-9ad3e057fcf5' |
| 72 | RANDOM_NUM=6 |
| 73 | |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 74 | $CGPT create ${DEV} |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 75 | |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 76 | $CGPT add -b ${DATA_START} -s ${DATA_SIZE} -t ${DATA_GUID} \ |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 77 | -l "${DATA_LABEL}" ${DEV} |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 78 | $CGPT add -b ${KERN_START} -s ${KERN_SIZE} -t ${KERN_GUID} \ |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 79 | -l "${KERN_LABEL}" ${DEV} |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 80 | $CGPT add -b ${ROOTFS_START} -s ${ROOTFS_SIZE} -t ${ROOTFS_GUID} \ |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 81 | -l "${ROOTFS_LABEL}" ${DEV} |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 82 | $CGPT add -b ${ESP_START} -s ${ESP_SIZE} -t ${ESP_GUID} \ |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 83 | -l "${ESP_LABEL}" ${DEV} |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 84 | $CGPT add -b ${FUTURE_START} -s ${FUTURE_SIZE} -t ${FUTURE_GUID} \ |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 85 | -l "${FUTURE_LABEL}" ${DEV} |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 86 | $CGPT add -b ${RANDOM_START} -s ${RANDOM_SIZE} -t ${RANDOM_GUID} \ |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 87 | -l "${RANDOM_LABEL}" ${DEV} |
| 88 | |
| 89 | |
| 90 | echo "Extract the start and size of given partitions..." |
| 91 | |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 92 | X=$($CGPT show -b -i $DATA_NUM ${DEV}) |
| 93 | Y=$($CGPT show -s -i $DATA_NUM ${DEV}) |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 94 | [ "$X $Y" = "$DATA_START $DATA_SIZE" ] || error |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 95 | |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 96 | X=$($CGPT show -b -i $KERN_NUM ${DEV}) |
| 97 | Y=$($CGPT show -s -i $KERN_NUM ${DEV}) |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 98 | [ "$X $Y" = "$KERN_START $KERN_SIZE" ] || error |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 99 | |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 100 | X=$($CGPT show -b -i $ROOTFS_NUM ${DEV}) |
| 101 | Y=$($CGPT show -s -i $ROOTFS_NUM ${DEV}) |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 102 | [ "$X $Y" = "$ROOTFS_START $ROOTFS_SIZE" ] || error |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 103 | |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 104 | X=$($CGPT show -b -i $ESP_NUM ${DEV}) |
| 105 | Y=$($CGPT show -s -i $ESP_NUM ${DEV}) |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 106 | [ "$X $Y" = "$ESP_START $ESP_SIZE" ] || error |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 107 | |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 108 | X=$($CGPT show -b -i $FUTURE_NUM ${DEV}) |
| 109 | Y=$($CGPT show -s -i $FUTURE_NUM ${DEV}) |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 110 | [ "$X $Y" = "$FUTURE_START $FUTURE_SIZE" ] || error |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 111 | |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 112 | X=$($CGPT show -b -i $RANDOM_NUM ${DEV}) |
| 113 | Y=$($CGPT show -s -i $RANDOM_NUM ${DEV}) |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 114 | [ "$X $Y" = "$RANDOM_START $RANDOM_SIZE" ] || error |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 115 | |
| 116 | |
Bill Richardson | da77e69 | 2012-08-24 17:52:01 -0700 | [diff] [blame] | 117 | echo "Change the beginning..." |
| 118 | DATA_START=$((DATA_START + 10)) |
| 119 | $CGPT add -i 1 -b ${DATA_START} ${DEV} || error |
| 120 | X=$($CGPT show -b -i 1 ${DEV}) |
| 121 | [ "$X" = "$DATA_START" ] || error |
| 122 | |
| 123 | echo "Change the size..." |
| 124 | DATA_SIZE=$((DATA_SIZE + 10)) |
| 125 | $CGPT add -i 1 -s ${DATA_SIZE} ${DEV} || error |
| 126 | X=$($CGPT show -s -i 1 ${DEV}) |
| 127 | [ "$X" = "$DATA_SIZE" ] || error |
| 128 | |
| 129 | echo "Change the type..." |
| 130 | $CGPT add -i 1 -t reserved ${DEV} || error |
| 131 | X=$($CGPT show -t -i 1 ${DEV} | tr 'A-Z' 'a-z') |
| 132 | [ "$X" = "$FUTURE_GUID" ] || error |
| 133 | # arbitrary value |
Albert Chaulk | 42c08cb | 2013-04-02 14:38:07 -0700 | [diff] [blame] | 134 | if [ -z "$MTD" ]; then |
| 135 | $CGPT add -i 1 -t 610a563a-a55c-4ae0-ab07-86e5bb9db67f ${DEV} || error |
| 136 | X=$($CGPT show -t -i 1 ${DEV}) |
| 137 | [ "$X" = "610A563A-A55C-4AE0-AB07-86E5BB9DB67F" ] || error |
| 138 | fi |
Bill Richardson | da77e69 | 2012-08-24 17:52:01 -0700 | [diff] [blame] | 139 | $CGPT add -i 1 -t data ${DEV} || error |
| 140 | X=$($CGPT show -t -i 1 ${DEV} | tr 'A-Z' 'a-z') |
| 141 | [ "$X" = "$DATA_GUID" ] || error |
| 142 | |
| 143 | |
Albert Chaulk | 42c08cb | 2013-04-02 14:38:07 -0700 | [diff] [blame] | 144 | if [ -z "$MTD" ]; then |
| 145 | echo "Set the boot partition.." |
| 146 | $CGPT boot -i ${KERN_NUM} ${DEV} >/dev/null |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 147 | |
Albert Chaulk | 42c08cb | 2013-04-02 14:38:07 -0700 | [diff] [blame] | 148 | echo "Check the PMBR's idea of the boot partition..." |
| 149 | X=$($CGPT boot ${DEV}) |
| 150 | Y=$($CGPT show -u -i $KERN_NUM $DEV) |
| 151 | [ "$X" = "$Y" ] || error |
| 152 | fi |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 153 | |
| 154 | echo "Test the cgpt prioritize command..." |
| 155 | |
| 156 | # Input: sequence of priorities |
| 157 | # Output: ${DEV} has kernel partitions with the given priorities |
| 158 | make_pri() { |
| 159 | local idx=0 |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 160 | $CGPT create ${DEV} |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 161 | for pri in "$@"; do |
| 162 | idx=$((idx+1)) |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 163 | $CGPT add -t kernel -l "kern$idx" -b $((100 + 2 * $idx)) -s 1 -P $pri ${DEV} |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 164 | done |
| 165 | } |
| 166 | |
| 167 | # Output: returns string containing priorities of all kernels |
| 168 | get_pri() { |
| 169 | echo $( |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 170 | for idx in $($CGPT find -t kernel ${DEV} | sed -e s@${DEV}@@); do |
| 171 | $CGPT show -i $idx -P ${DEV} |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 172 | done |
| 173 | ) |
| 174 | } |
| 175 | |
| 176 | # Input: list of priorities |
| 177 | # Operation: expects ${DEV} to contain those kernel priorities |
| 178 | assert_pri() { |
| 179 | local expected="$*" |
| 180 | local actual=$(get_pri) |
| 181 | [ "$actual" = "$expected" ] || \ |
| 182 | error 1 "expected priority \"$expected\", actual priority \"$actual\"" |
| 183 | } |
| 184 | |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 185 | # no kernels at all. This should do nothing. |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 186 | $CGPT create ${DEV} |
| 187 | $CGPT add -t rootfs -b 100 -s 1 ${DEV} |
| 188 | $CGPT prioritize ${DEV} |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 189 | assert_pri "" |
| 190 | |
| 191 | # common install/upgrade sequence |
| 192 | make_pri 2 0 0 |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 193 | $CGPT prioritize -i 1 ${DEV} |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 194 | assert_pri 1 0 0 |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 195 | $CGPT prioritize -i 2 ${DEV} |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 196 | assert_pri 1 2 0 |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 197 | $CGPT prioritize -i 1 ${DEV} |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 198 | assert_pri 2 1 0 |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 199 | $CGPT prioritize -i 2 ${DEV} |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 200 | assert_pri 1 2 0 |
| 201 | |
| 202 | # lots of kernels, all same starting priority, should go to priority 1 |
| 203 | make_pri 8 8 8 8 8 8 8 8 8 8 8 0 0 8 |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 204 | $CGPT prioritize ${DEV} |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 205 | assert_pri 1 1 1 1 1 1 1 1 1 1 1 0 0 1 |
| 206 | |
| 207 | # now raise them all up again |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 208 | $CGPT prioritize -P 4 ${DEV} |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 209 | assert_pri 4 4 4 4 4 4 4 4 4 4 4 0 0 4 |
| 210 | |
| 211 | # set one of them higher, should leave the rest alone |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 212 | $CGPT prioritize -P 5 -i 3 ${DEV} |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 213 | assert_pri 4 4 5 4 4 4 4 4 4 4 4 0 0 4 |
| 214 | |
| 215 | # set one of them lower, should bring the rest down |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 216 | $CGPT prioritize -P 3 -i 4 ${DEV} |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 217 | assert_pri 1 1 2 3 1 1 1 1 1 1 1 0 0 1 |
| 218 | |
| 219 | # raise a group by including the friends of one partition |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 220 | $CGPT prioritize -P 6 -i 1 -f ${DEV} |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 221 | assert_pri 6 6 4 5 6 6 6 6 6 6 6 0 0 6 |
| 222 | |
| 223 | # resurrect one, should not affect the others |
| 224 | make_pri 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 225 | $CGPT prioritize -i 2 ${DEV} |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 226 | assert_pri 0 1 0 0 0 0 0 0 0 0 0 0 0 0 |
| 227 | |
| 228 | # resurrect one and all its friends |
| 229 | make_pri 0 0 0 0 0 0 0 0 1 2 0 0 0 0 |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 230 | $CGPT prioritize -P 5 -i 2 -f ${DEV} |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 231 | assert_pri 5 5 5 5 5 5 5 5 3 4 5 5 5 5 |
| 232 | |
| 233 | # no options should maintain the same order |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 234 | $CGPT prioritize ${DEV} |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 235 | assert_pri 3 3 3 3 3 3 3 3 1 2 3 3 3 3 |
| 236 | |
| 237 | # squish all the ranks |
| 238 | make_pri 1 1 2 2 3 3 4 4 5 5 0 6 7 7 |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 239 | $CGPT prioritize -P 6 ${DEV} |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 240 | assert_pri 1 1 1 1 2 2 3 3 4 4 0 5 6 6 |
| 241 | |
| 242 | # squish the ranks by not leaving room |
| 243 | make_pri 1 1 2 2 3 3 4 4 5 5 0 6 7 7 |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 244 | $CGPT prioritize -P 7 -i 3 ${DEV} |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 245 | assert_pri 1 1 7 1 2 2 3 3 4 4 0 5 6 6 |
| 246 | |
| 247 | # squish the ranks while bringing the friends along |
| 248 | make_pri 1 1 2 2 3 3 4 4 5 5 0 6 7 7 |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 249 | $CGPT prioritize -P 6 -i 3 -f ${DEV} |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 250 | assert_pri 1 1 6 6 1 1 2 2 3 3 0 4 5 5 |
| 251 | |
| 252 | # squish them pretty hard |
| 253 | make_pri 1 1 2 2 3 3 4 4 5 5 0 6 7 7 |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 254 | $CGPT prioritize -P 2 ${DEV} |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 255 | assert_pri 1 1 1 1 1 1 1 1 1 1 0 1 2 2 |
| 256 | |
| 257 | # squish them really really hard (nobody gets reduced to zero, though) |
| 258 | make_pri 1 1 2 2 3 3 4 4 5 5 0 6 7 7 |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 259 | $CGPT prioritize -P 1 -i 3 ${DEV} |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 260 | assert_pri 1 1 1 1 1 1 1 1 1 1 0 1 1 1 |
| 261 | |
Albert Chaulk | 42c08cb | 2013-04-02 14:38:07 -0700 | [diff] [blame] | 262 | if [ -z "$MTD" ]; then # MTD doesn't support this many partitions |
| 263 | # squish if we try to go too high |
| 264 | make_pri 15 15 14 14 13 13 12 12 11 11 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0 |
| 265 | $CGPT prioritize -i 3 ${DEV} |
| 266 | assert_pri 14 14 15 13 12 12 11 11 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 1 1 0 |
| 267 | $CGPT prioritize -i 5 ${DEV} |
| 268 | assert_pri 13 13 14 12 15 11 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 1 1 1 1 0 |
| 269 | # but if I bring friends I don't have to squish |
| 270 | $CGPT prioritize -i 1 -f ${DEV} |
| 271 | assert_pri 15 15 13 12 14 11 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 1 1 1 1 0 |
| 272 | fi |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 273 | |
Bill Richardson | 23429d3 | 2012-04-30 11:33:13 -0700 | [diff] [blame] | 274 | |
| 275 | # Now make sure that we don't need write access if we're just looking. |
| 276 | echo "Test read vs read-write access..." |
| 277 | chmod 0444 ${DEV} |
| 278 | |
| 279 | # These should fail |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 280 | $CGPT create -z ${DEV} 2>/dev/null && error |
| 281 | $CGPT add -i 2 -P 3 ${DEV} 2>/dev/null && error |
| 282 | $CGPT repair ${DEV} 2>/dev/null && error |
| 283 | $CGPT prioritize -i 3 ${DEV} 2>/dev/null && error |
Bill Richardson | 23429d3 | 2012-04-30 11:33:13 -0700 | [diff] [blame] | 284 | |
| 285 | # Most 'boot' usage should fail too. |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 286 | $CGPT boot -p ${DEV} 2>/dev/null && error |
Bill Richardson | 23429d3 | 2012-04-30 11:33:13 -0700 | [diff] [blame] | 287 | dd if=/dev/zero of=fake_mbr.bin bs=100 count=1 2>/dev/null |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 288 | $CGPT boot -b fake_mbr.bin ${DEV} 2>/dev/null && error |
| 289 | $CGPT boot -i 2 ${DEV} 2>/dev/null && error |
Bill Richardson | 23429d3 | 2012-04-30 11:33:13 -0700 | [diff] [blame] | 290 | |
| 291 | # These should pass |
Albert Chaulk | 42c08cb | 2013-04-02 14:38:07 -0700 | [diff] [blame] | 292 | if [ -z "$MTD" ]; then |
| 293 | $CGPT boot ${DEV} >/dev/null |
| 294 | fi |
Bill Richardson | 263ffdf | 2012-08-24 14:39:21 -0700 | [diff] [blame] | 295 | $CGPT show ${DEV} >/dev/null |
| 296 | $CGPT find -t kernel ${DEV} >/dev/null |
Bill Richardson | 23429d3 | 2012-04-30 11:33:13 -0700 | [diff] [blame] | 297 | |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 298 | echo "Done." |
| 299 | |
| 300 | happy "All tests passed." |