Home | History | Annotate | Line # | Download | only in gpt
t_gpt.sh revision 1.7
      1  1.7  christos # $NetBSD: t_gpt.sh,v 1.7 2015/12/05 14:23:41 christos Exp $
      2  1.1  christos #
      3  1.2  christos # Copyright (c) 2015 The NetBSD Foundation, Inc.
      4  1.1  christos # All rights reserved.
      5  1.1  christos #
      6  1.1  christos # This code is derived from software contributed to The NetBSD Foundation
      7  1.2  christos # by Christos Zoulas
      8  1.1  christos #
      9  1.1  christos # Redistribution and use in source and binary forms, with or without
     10  1.1  christos # modification, are permitted provided that the following conditions
     11  1.1  christos # are met:
     12  1.1  christos # 1. Redistributions of source code must retain the above copyright
     13  1.1  christos #    notice, this list of conditions and the following disclaimer.
     14  1.1  christos # 2. Redistributions in binary form must reproduce the above copyright
     15  1.1  christos #    notice, this list of conditions and the following disclaimer in the
     16  1.1  christos #    documentation and/or other materials provided with the distribution.
     17  1.1  christos #
     18  1.1  christos # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     19  1.1  christos # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     20  1.1  christos # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     21  1.1  christos # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     22  1.1  christos # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     23  1.1  christos # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     24  1.1  christos # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25  1.1  christos # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     26  1.1  christos # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     27  1.1  christos # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28  1.1  christos # POSSIBILITY OF SUCH DAMAGE.
     29  1.1  christos #
     30  1.1  christos 
     31  1.7  christos bootblk=/usr/mdec/gptmbr.bin
     32  1.1  christos size=10240
     33  1.5  christos newsize=20480
     34  1.1  christos shdr=34
     35  1.1  christos disk=gpt.disk
     36  1.1  christos uuid="........-....-....-....-............"
     37  1.1  christos zero="00000000-0000-0000-0000-000000000000"
     38  1.4  christos src=$(atf_get_srcdir)
     39  1.1  christos 
     40  1.1  christos prepare() {
     41  1.7  christos 	rm -f "$disk"
     42  1.7  christos 	dd if=/dev/zero of="$disk" seek="$size" count=1
     43  1.1  christos }
     44  1.1  christos 
     45  1.1  christos prepare_2part() {
     46  1.1  christos 	prepare
     47  1.7  christos 	atf_check -s exit:0 -o empty -e empty gpt create "$disk"
     48  1.5  christos 	atf_check -s exit:0 -o match:"$(partaddmsg 1 34 1024)" -e empty \
     49  1.7  christos 	    gpt add -t efi -s 1024 "$disk"
     50  1.5  christos 	atf_check -s exit:0 -o match:"$(partaddmsg 2 1058 9150)" -e empty \
     51  1.7  christos 	    gpt add "$disk"
     52  1.1  christos }
     53  1.1  christos 
     54  1.3  christos # Calling this from tests does not work. BUG!
     55  1.1  christos check_2part() {
     56  1.4  christos 	atf_check -s exit:0 -o file:"$src/gpt.2part.show.normal" \
     57  1.7  christos 	    -e empty gpt show "$disk"
     58  1.4  christos 	atf_check -s exit:0 -o file:"$src/gpt.2part.show.uuid" \
     59  1.7  christos 	    -e empty gpt show -u "$disk"
     60  1.1  christos }
     61  1.1  christos 
     62  1.5  christos partaddmsg() {
     63  1.1  christos 	echo "^$disk: Partition $1 added: $uuid $2 $3\$"
     64  1.1  christos }
     65  1.1  christos 
     66  1.5  christos partresmsg() {
     67  1.5  christos 	echo "^$disk: Partition $1 resized: $2 $3\$"
     68  1.5  christos }
     69  1.5  christos 
     70  1.6  christos partremmsg() {
     71  1.6  christos 	echo "^$disk: Partition $1 removed\$"
     72  1.6  christos }
     73  1.6  christos 
     74  1.6  christos partlblmsg() {
     75  1.6  christos 	echo "^$disk: Partition $1 label changed\$"
     76  1.6  christos }
     77  1.6  christos 
     78  1.7  christos partbootmsg() {
     79  1.7  christos 	echo "^$disk: Partition $1 marked as bootable\$"
     80  1.7  christos 
     81  1.7  christos }
     82  1.7  christos 
     83  1.1  christos recovermsg() {
     84  1.1  christos 	echo "^$disk: Recovered $1 GPT [a-z]* from $2\$"
     85  1.1  christos }
     86  1.1  christos 
     87  1.1  christos atf_test_case create_empty
     88  1.1  christos create_empty_head() {
     89  1.1  christos 	atf_set "descr" "Create empty disk"
     90  1.1  christos }
     91  1.1  christos 
     92  1.1  christos create_empty_body() {
     93  1.1  christos 	prepare
     94  1.7  christos 	atf_check -s exit:0 -o empty -e empty gpt create "$disk"
     95  1.4  christos 	atf_check -s exit:0 -o file:"$src/gpt.empty.show.normal" \
     96  1.7  christos 	    -e empty gpt show "$disk"
     97  1.1  christos }
     98  1.1  christos 
     99  1.1  christos atf_test_case create_2part
    100  1.1  christos create_2part_head() {
    101  1.1  christos 	atf_set "descr" "Create 2 partition disk"
    102  1.1  christos }
    103  1.1  christos 
    104  1.1  christos create_2part_body() {
    105  1.1  christos 	prepare_2part
    106  1.1  christos 	check_2part
    107  1.1  christos }
    108  1.1  christos 
    109  1.1  christos atf_test_case backup_2part
    110  1.1  christos backup_2part_head() {
    111  1.1  christos 	atf_set "descr" "Backup 2 partition disk"
    112  1.1  christos }
    113  1.1  christos 
    114  1.1  christos backup_2part_body() {
    115  1.1  christos 	prepare_2part
    116  1.7  christos 	atf_check -s exit:0 -o save:test.backup -e empty gpt backup "$disk"
    117  1.4  christos 	atf_check -s exit:0 -o file:"$src/gpt.backup" -e empty \
    118  1.4  christos 	    sed -e "s/$uuid/$zero/g" "test.backup"
    119  1.1  christos }
    120  1.1  christos 
    121  1.1  christos atf_test_case restore_2part
    122  1.1  christos restore_2part_head() {
    123  1.1  christos 	atf_set "descr" "Restore 2 partition disk"
    124  1.1  christos }
    125  1.1  christos 
    126  1.1  christos restore_2part_body() {
    127  1.1  christos 	prepare_2part
    128  1.7  christos 	atf_check -s exit:0 -o save:test.backup -e empty gpt backup "$disk"
    129  1.1  christos 	prepare
    130  1.7  christos 	atf_check -s exit:0 -o empty -e empty gpt restore -i test.backup "$disk"
    131  1.1  christos 	check_2part
    132  1.1  christos }
    133  1.1  christos 
    134  1.1  christos atf_test_case recover_backup
    135  1.1  christos recover_backup_head() {
    136  1.1  christos 	atf_set "descr" "Recover the backup GPT header and table"
    137  1.1  christos }
    138  1.1  christos 
    139  1.1  christos recover_backup_body() {
    140  1.1  christos 	prepare_2part
    141  1.7  christos 	dd conv=notrunc if=/dev/zero of="$disk" seek="$((size - shdr))" \
    142  1.7  christos 	    count="$shdr"
    143  1.1  christos 	atf_check -s exit:0 -o match:"$(recovermsg secondary primary)" \
    144  1.7  christos 	    -e empty gpt recover "$disk"
    145  1.1  christos 	check_2part
    146  1.1  christos }
    147  1.1  christos 
    148  1.1  christos atf_test_case recover_primary
    149  1.1  christos recover_primary_head() {
    150  1.1  christos 	atf_set "descr" "Recover the primary GPT header and table"
    151  1.1  christos }
    152  1.1  christos 
    153  1.1  christos recover_primary_body() {
    154  1.1  christos 	prepare_2part
    155  1.7  christos 	dd conv=notrunc if=/dev/zero of="$disk" seek=1 count="$shdr"
    156  1.1  christos 	atf_check -s exit:0 -o match:"$(recovermsg primary secondary)" \
    157  1.7  christos 	    -e empty gpt recover "$disk"
    158  1.1  christos 	check_2part
    159  1.1  christos }
    160  1.1  christos 
    161  1.5  christos atf_test_case resize_2part
    162  1.5  christos resize_2part_head() {
    163  1.5  christos 	atf_set "descr" "Resize a 2 partition disk and partition"
    164  1.5  christos }
    165  1.5  christos 
    166  1.5  christos resize_2part_body() {
    167  1.5  christos 	prepare_2part
    168  1.7  christos 	dd conv=notrunc if=/dev/zero of="$disk" seek="$newsize" count=1
    169  1.7  christos 	atf_check -s exit:0 -o empty -e empty gpt resizedisk "$disk"
    170  1.5  christos 	atf_check -s exit:0 -o file:"$src/gpt.resizedisk.show.normal" \
    171  1.7  christos 	    gpt show "$disk"
    172  1.5  christos 	atf_check -s exit:0 -o match:"$(partresmsg 2 1058 19390)" \
    173  1.7  christos 	    -e empty gpt resize -i 2 "$disk"
    174  1.5  christos 	atf_check -s exit:0 -o file:"$src/gpt.resizepart.show.normal" \
    175  1.7  christos 	    gpt show "$disk"
    176  1.5  christos }
    177  1.5  christos 
    178  1.6  christos atf_test_case remove_2part
    179  1.6  christos remove_2part_head() {
    180  1.6  christos 	atf_set "descr" "Remove a partition from a 2 partition disk"
    181  1.6  christos }
    182  1.6  christos 
    183  1.6  christos remove_2part_body() {
    184  1.6  christos 	prepare_2part
    185  1.6  christos 	atf_check -s exit:0 -o match:"$(partremmsg 1)" -e empty gpt remove \
    186  1.7  christos 	    -i 1 "$disk"
    187  1.6  christos 	atf_check -s exit:0 -o file:"$src/gpt.removepart.show.normal" \
    188  1.7  christos 	    gpt show "$disk"
    189  1.6  christos }
    190  1.6  christos 
    191  1.6  christos atf_test_case label_2part
    192  1.6  christos label_2part_head() {
    193  1.7  christos 	atf_set "descr" "Label partitions in a 2 partition disk"
    194  1.6  christos }
    195  1.6  christos 
    196  1.6  christos label_2part_body() {
    197  1.6  christos 	prepare_2part
    198  1.6  christos 	atf_check -s exit:0 -o match:"$(partlblmsg 1)" -e empty \
    199  1.7  christos 	    gpt label -i 1 -l potato "$disk"
    200  1.6  christos 	atf_check -s exit:0 -o match:"$(partlblmsg 2)" -e empty \
    201  1.7  christos 	    gpt label -i 2 -l tomato "$disk"
    202  1.7  christos 	atf_check -s exit:0 -o file:"$src/gpt.2part.show.label" \
    203  1.7  christos 	    gpt show -l "$disk"
    204  1.7  christos }
    205  1.7  christos 
    206  1.7  christos atf_test_case bootable_2part
    207  1.7  christos bootable_2part_head() {
    208  1.7  christos 	atf_set "descr" "Make partition 2 bootable in a 2 partition disk"
    209  1.7  christos }
    210  1.7  christos 
    211  1.7  christos bootable_2part_body() {
    212  1.7  christos 	prepare_2part
    213  1.7  christos 	atf_check -s exit:0 -o match:"$(partbootmsg 2)" -e empty \
    214  1.7  christos 	    gpt biosboot -i 2 "$disk"
    215  1.7  christos 	local bootsz="$(ls -l "$bootblk" | awk '{ print $5 }')"
    216  1.7  christos 	dd if="$disk" of=bootblk bs=1 count="$bootsz"
    217  1.7  christos 	atf_check -s exit:0 -o empty -e empty cmp "$bootblk" bootblk
    218  1.7  christos 	gpt show -i 2 "$disk" | tail -1 > bootattr
    219  1.7  christos 	atf_check -s exit:0 -o match:"^  legacy BIOS boot partition\$" \
    220  1.7  christos 	    -e empty cat bootattr
    221  1.6  christos }
    222  1.6  christos 
    223  1.1  christos atf_init_test_cases() {
    224  1.1  christos 	atf_add_test_case create_empty
    225  1.1  christos 	atf_add_test_case create_2part
    226  1.1  christos 	atf_add_test_case backup_2part
    227  1.6  christos 	atf_add_test_case remove_2part
    228  1.1  christos 	atf_add_test_case restore_2part
    229  1.1  christos 	atf_add_test_case recover_backup
    230  1.1  christos 	atf_add_test_case recover_primary
    231  1.5  christos 	atf_add_test_case resize_2part
    232  1.6  christos 	atf_add_test_case label_2part
    233  1.7  christos 	atf_add_test_case bootable_2part
    234  1.1  christos }
    235