Home | History | Annotate | Line # | Download | only in gpt
t_gpt.sh revision 1.4
      1  1.4  christos # $NetBSD: t_gpt.sh,v 1.4 2015/12/04 01:42:47 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.1  christos size=10240
     32  1.1  christos shdr=34
     33  1.1  christos disk=gpt.disk
     34  1.1  christos uuid="........-....-....-....-............"
     35  1.1  christos zero="00000000-0000-0000-0000-000000000000"
     36  1.4  christos src=$(atf_get_srcdir)
     37  1.1  christos 
     38  1.1  christos prepare() {
     39  1.1  christos 	rm -f $disk
     40  1.1  christos 	dd if=/dev/zero of=$disk seek=$size count=1
     41  1.1  christos }
     42  1.1  christos 
     43  1.1  christos prepare_2part() {
     44  1.1  christos 	prepare
     45  1.1  christos 	atf_check -s exit:0 -o empty -e empty gpt create $disk
     46  1.1  christos 	atf_check -s exit:0 -o match:"$(partmsg 1 34 1024)" -e empty \
     47  1.1  christos 	    gpt add -t efi -s 1024 $disk
     48  1.1  christos 	atf_check -s exit:0 -o match:"$(partmsg 2 1058 9150)" -e empty \
     49  1.1  christos 	    gpt add $disk
     50  1.1  christos }
     51  1.1  christos 
     52  1.3  christos # Calling this from tests does not work. BUG!
     53  1.1  christos check_2part() {
     54  1.4  christos 	atf_check -s exit:0 -o file:"$src/gpt.2part.show.normal" \
     55  1.4  christos 	    -e empty gpt show $disk
     56  1.4  christos 	atf_check -s exit:0 -o file:"$src/gpt.2part.show.uuid" \
     57  1.4  christos 	    -e empty gpt show -u $disk
     58  1.1  christos }
     59  1.1  christos 
     60  1.1  christos partmsg() {
     61  1.1  christos 	echo "^$disk: Partition $1 added: $uuid $2 $3\$"
     62  1.1  christos }
     63  1.1  christos 
     64  1.1  christos recovermsg() {
     65  1.1  christos 	echo "^$disk: Recovered $1 GPT [a-z]* from $2\$"
     66  1.1  christos }
     67  1.1  christos 
     68  1.1  christos atf_test_case create_empty
     69  1.1  christos create_empty_head() {
     70  1.1  christos 	atf_set "descr" "Create empty disk"
     71  1.1  christos }
     72  1.1  christos 
     73  1.1  christos create_empty_body() {
     74  1.1  christos 	prepare
     75  1.1  christos 	atf_check -s exit:0 -o empty -e empty gpt create $disk
     76  1.4  christos 	atf_check -s exit:0 -o file:"$src/gpt.empty.show.normal" \
     77  1.1  christos 	    -e empty gpt show $disk
     78  1.1  christos }
     79  1.1  christos 
     80  1.1  christos atf_test_case create_2part
     81  1.1  christos create_2part_head() {
     82  1.1  christos 	atf_set "descr" "Create 2 partition disk"
     83  1.1  christos }
     84  1.1  christos 
     85  1.1  christos create_2part_body() {
     86  1.1  christos 	prepare_2part
     87  1.1  christos 	check_2part
     88  1.1  christos }
     89  1.1  christos 
     90  1.1  christos atf_test_case backup_2part
     91  1.1  christos backup_2part_head() {
     92  1.1  christos 	atf_set "descr" "Backup 2 partition disk"
     93  1.1  christos }
     94  1.1  christos 
     95  1.1  christos backup_2part_body() {
     96  1.1  christos 	prepare_2part
     97  1.1  christos 	atf_check -s exit:0 -o save:test.backup -e empty gpt backup $disk
     98  1.4  christos 	atf_check -s exit:0 -o file:"$src/gpt.backup" -e empty \
     99  1.4  christos 	    sed -e "s/$uuid/$zero/g" "test.backup"
    100  1.1  christos }
    101  1.1  christos 
    102  1.1  christos atf_test_case restore_2part
    103  1.1  christos restore_2part_head() {
    104  1.1  christos 	atf_set "descr" "Restore 2 partition disk"
    105  1.1  christos }
    106  1.1  christos 
    107  1.1  christos restore_2part_body() {
    108  1.1  christos 	prepare_2part
    109  1.1  christos 	atf_check -s exit:0 -o save:test.backup -e empty gpt backup $disk
    110  1.1  christos 	prepare
    111  1.1  christos 	atf_check -s exit:0 -o empty -e empty gpt restore -i test.backup $disk
    112  1.1  christos 	check_2part
    113  1.1  christos }
    114  1.1  christos 
    115  1.1  christos atf_test_case recover_backup
    116  1.1  christos recover_backup_head() {
    117  1.1  christos 	atf_set "descr" "Recover the backup GPT header and table"
    118  1.1  christos }
    119  1.1  christos 
    120  1.1  christos recover_backup_body() {
    121  1.1  christos 	prepare_2part
    122  1.1  christos 	dd conv=notrunc if=/dev/zero of=$disk seek=$((size - shdr)) count=$shdr
    123  1.1  christos 	atf_check -s exit:0 -o match:"$(recovermsg secondary primary)" \
    124  1.1  christos 	    -e empty gpt recover $disk
    125  1.1  christos 	check_2part
    126  1.1  christos }
    127  1.1  christos 
    128  1.1  christos atf_test_case recover_primary
    129  1.1  christos recover_primary_head() {
    130  1.1  christos 	atf_set "descr" "Recover the primary GPT header and table"
    131  1.1  christos }
    132  1.1  christos 
    133  1.1  christos recover_primary_body() {
    134  1.1  christos 	prepare_2part
    135  1.1  christos 	dd conv=notrunc if=/dev/zero of=$disk seek=1 count=$shdr
    136  1.1  christos 	atf_check -s exit:0 -o match:"$(recovermsg primary secondary)" \
    137  1.1  christos 	    -e empty gpt recover $disk
    138  1.1  christos 	check_2part
    139  1.1  christos }
    140  1.1  christos 
    141  1.1  christos atf_init_test_cases() {
    142  1.1  christos 	atf_add_test_case create_empty
    143  1.1  christos 	atf_add_test_case create_2part
    144  1.1  christos 	atf_add_test_case backup_2part
    145  1.1  christos 	atf_add_test_case restore_2part
    146  1.1  christos 	atf_add_test_case recover_backup
    147  1.1  christos 	atf_add_test_case recover_primary
    148  1.1  christos }
    149