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