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 | # |
| 7 | # Run tests for RSA Signature verification. |
| 8 | |
| 9 | # Load common constants and variables. |
| 10 | . "$(dirname "$0")/common.sh" |
| 11 | |
Bill Richardson | 793e1b4 | 2010-08-20 07:58:43 -0700 | [diff] [blame^] | 12 | GPT=$(readlink -f "$1") |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 13 | [ -x "$GPT" ] || error "Can't execute $GPT" |
Bill Richardson | 793e1b4 | 2010-08-20 07:58:43 -0700 | [diff] [blame^] | 14 | |
| 15 | # Run tests in a dedicated directory for easy cleanup or debugging. |
| 16 | DIR="${TEST_DIR}/cgpt_test_dir" |
| 17 | [ -d "$DIR" ] || mkdir -p "$DIR" |
| 18 | warning "testing $GPT in $DIR" |
| 19 | cd "$DIR" |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 20 | |
| 21 | echo "Create an empty file to use as the device..." |
| 22 | NUM_SECTORS=1000 |
Bill Richardson | 793e1b4 | 2010-08-20 07:58:43 -0700 | [diff] [blame^] | 23 | DEV=fake_dev.bin |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 24 | 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] | 25 | |
| 26 | |
| 27 | echo "Create a bunch of partitions, using the real GUID types..." |
| 28 | DATA_START=100 |
| 29 | DATA_SIZE=20 |
| 30 | DATA_LABEL="data stuff" |
| 31 | DATA_GUID='ebd0a0a2-b9e5-4433-87c0-68b6b72699c7' |
| 32 | DATA_NUM=1 |
| 33 | |
| 34 | KERN_START=200 |
| 35 | KERN_SIZE=30 |
| 36 | KERN_LABEL="kernel stuff" |
| 37 | KERN_GUID='fe3a2a5d-4f32-41a7-b725-accc3285a309' |
| 38 | KERN_NUM=2 |
| 39 | |
| 40 | ROOTFS_START=300 |
| 41 | ROOTFS_SIZE=40 |
| 42 | ROOTFS_LABEL="rootfs stuff" |
| 43 | ROOTFS_GUID='3cb8e202-3b7e-47dd-8a3c-7ff2a13cfcec' |
| 44 | ROOTFS_NUM=3 |
| 45 | |
| 46 | ESP_START=400 |
| 47 | ESP_SIZE=50 |
| 48 | ESP_LABEL="ESP stuff" |
| 49 | ESP_GUID='c12a7328-f81f-11d2-ba4b-00a0c93ec93b' |
| 50 | ESP_NUM=4 |
| 51 | |
| 52 | FUTURE_START=500 |
| 53 | FUTURE_SIZE=60 |
| 54 | FUTURE_LABEL="future stuff" |
| 55 | FUTURE_GUID='2e0a753d-9e48-43b0-8337-b15192cb1b5e' |
| 56 | FUTURE_NUM=5 |
| 57 | |
| 58 | RANDOM_START=600 |
| 59 | RANDOM_SIZE=70 |
| 60 | RANDOM_LABEL="random stuff" |
| 61 | RANDOM_GUID='2364a860-bf63-42fb-a83d-9ad3e057fcf5' |
| 62 | RANDOM_NUM=6 |
| 63 | |
| 64 | $GPT create ${DEV} |
| 65 | |
| 66 | $GPT add -b ${DATA_START} -s ${DATA_SIZE} -t ${DATA_GUID} \ |
| 67 | -l "${DATA_LABEL}" ${DEV} |
| 68 | $GPT add -b ${KERN_START} -s ${KERN_SIZE} -t ${KERN_GUID} \ |
| 69 | -l "${KERN_LABEL}" ${DEV} |
| 70 | $GPT add -b ${ROOTFS_START} -s ${ROOTFS_SIZE} -t ${ROOTFS_GUID} \ |
| 71 | -l "${ROOTFS_LABEL}" ${DEV} |
| 72 | $GPT add -b ${ESP_START} -s ${ESP_SIZE} -t ${ESP_GUID} \ |
| 73 | -l "${ESP_LABEL}" ${DEV} |
| 74 | $GPT add -b ${FUTURE_START} -s ${FUTURE_SIZE} -t ${FUTURE_GUID} \ |
| 75 | -l "${FUTURE_LABEL}" ${DEV} |
| 76 | $GPT add -b ${RANDOM_START} -s ${RANDOM_SIZE} -t ${RANDOM_GUID} \ |
| 77 | -l "${RANDOM_LABEL}" ${DEV} |
| 78 | |
| 79 | |
| 80 | echo "Extract the start and size of given partitions..." |
| 81 | |
| 82 | X=$($GPT show -b -i $DATA_NUM ${DEV}) |
| 83 | Y=$($GPT show -s -i $DATA_NUM ${DEV}) |
| 84 | [ "$X $Y" = "$DATA_START $DATA_SIZE" ] || error "fail at line $LINENO" |
| 85 | |
| 86 | X=$($GPT show -b -i $KERN_NUM ${DEV}) |
| 87 | Y=$($GPT show -s -i $KERN_NUM ${DEV}) |
| 88 | [ "$X $Y" = "$KERN_START $KERN_SIZE" ] || error "fail at line $LINENO" |
| 89 | |
| 90 | X=$($GPT show -b -i $ROOTFS_NUM ${DEV}) |
| 91 | Y=$($GPT show -s -i $ROOTFS_NUM ${DEV}) |
| 92 | [ "$X $Y" = "$ROOTFS_START $ROOTFS_SIZE" ] || error "fail at line $LINENO" |
| 93 | |
| 94 | X=$($GPT show -b -i $ESP_NUM ${DEV}) |
| 95 | Y=$($GPT show -s -i $ESP_NUM ${DEV}) |
| 96 | [ "$X $Y" = "$ESP_START $ESP_SIZE" ] || error "fail at line $LINENO" |
| 97 | |
| 98 | X=$($GPT show -b -i $FUTURE_NUM ${DEV}) |
| 99 | Y=$($GPT show -s -i $FUTURE_NUM ${DEV}) |
| 100 | [ "$X $Y" = "$FUTURE_START $FUTURE_SIZE" ] || error "fail at line $LINENO" |
| 101 | |
| 102 | X=$($GPT show -b -i $RANDOM_NUM ${DEV}) |
| 103 | Y=$($GPT show -s -i $RANDOM_NUM ${DEV}) |
| 104 | [ "$X $Y" = "$RANDOM_START $RANDOM_SIZE" ] || error "fail at line $LINENO" |
| 105 | |
| 106 | |
| 107 | echo "Set the boot partition.." |
| 108 | $GPT boot -i ${KERN_NUM} ${DEV} >/dev/null |
| 109 | |
| 110 | echo "Check the PMBR's idea of the boot partition..." |
| 111 | X=$($GPT boot ${DEV}) |
| 112 | Y=$($GPT show -u -i $KERN_NUM $DEV) |
| 113 | [ "$X" = "$Y" ] || error "fail at line $LINENO" |
| 114 | |
| 115 | echo "Done." |
| 116 | |
| 117 | happy "All tests passed." |