t_gpt.sh revision 1.6 1 1.6 christos # $NetBSD: t_gpt.sh,v 1.6 2015/12/04 17:15:21 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.6 christos partremmsg() {
70 1.6 christos echo "^$disk: Partition $1 removed\$"
71 1.6 christos }
72 1.6 christos
73 1.6 christos partlblmsg() {
74 1.6 christos echo "^$disk: Partition $1 label changed\$"
75 1.6 christos }
76 1.6 christos
77 1.1 christos recovermsg() {
78 1.1 christos echo "^$disk: Recovered $1 GPT [a-z]* from $2\$"
79 1.1 christos }
80 1.1 christos
81 1.1 christos atf_test_case create_empty
82 1.1 christos create_empty_head() {
83 1.1 christos atf_set "descr" "Create empty disk"
84 1.1 christos }
85 1.1 christos
86 1.1 christos create_empty_body() {
87 1.1 christos prepare
88 1.1 christos atf_check -s exit:0 -o empty -e empty gpt create $disk
89 1.4 christos atf_check -s exit:0 -o file:"$src/gpt.empty.show.normal" \
90 1.1 christos -e empty gpt show $disk
91 1.1 christos }
92 1.1 christos
93 1.1 christos atf_test_case create_2part
94 1.1 christos create_2part_head() {
95 1.1 christos atf_set "descr" "Create 2 partition disk"
96 1.1 christos }
97 1.1 christos
98 1.1 christos create_2part_body() {
99 1.1 christos prepare_2part
100 1.1 christos check_2part
101 1.1 christos }
102 1.1 christos
103 1.1 christos atf_test_case backup_2part
104 1.1 christos backup_2part_head() {
105 1.1 christos atf_set "descr" "Backup 2 partition disk"
106 1.1 christos }
107 1.1 christos
108 1.1 christos backup_2part_body() {
109 1.1 christos prepare_2part
110 1.1 christos atf_check -s exit:0 -o save:test.backup -e empty gpt backup $disk
111 1.4 christos atf_check -s exit:0 -o file:"$src/gpt.backup" -e empty \
112 1.4 christos sed -e "s/$uuid/$zero/g" "test.backup"
113 1.1 christos }
114 1.1 christos
115 1.1 christos atf_test_case restore_2part
116 1.1 christos restore_2part_head() {
117 1.1 christos atf_set "descr" "Restore 2 partition disk"
118 1.1 christos }
119 1.1 christos
120 1.1 christos restore_2part_body() {
121 1.1 christos prepare_2part
122 1.1 christos atf_check -s exit:0 -o save:test.backup -e empty gpt backup $disk
123 1.1 christos prepare
124 1.1 christos atf_check -s exit:0 -o empty -e empty gpt restore -i test.backup $disk
125 1.1 christos check_2part
126 1.1 christos }
127 1.1 christos
128 1.1 christos atf_test_case recover_backup
129 1.1 christos recover_backup_head() {
130 1.1 christos atf_set "descr" "Recover the backup GPT header and table"
131 1.1 christos }
132 1.1 christos
133 1.1 christos recover_backup_body() {
134 1.1 christos prepare_2part
135 1.1 christos dd conv=notrunc if=/dev/zero of=$disk seek=$((size - shdr)) count=$shdr
136 1.1 christos atf_check -s exit:0 -o match:"$(recovermsg secondary primary)" \
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_test_case recover_primary
142 1.1 christos recover_primary_head() {
143 1.1 christos atf_set "descr" "Recover the primary GPT header and table"
144 1.1 christos }
145 1.1 christos
146 1.1 christos recover_primary_body() {
147 1.1 christos prepare_2part
148 1.1 christos dd conv=notrunc if=/dev/zero of=$disk seek=1 count=$shdr
149 1.1 christos atf_check -s exit:0 -o match:"$(recovermsg primary secondary)" \
150 1.1 christos -e empty gpt recover $disk
151 1.1 christos check_2part
152 1.1 christos }
153 1.1 christos
154 1.5 christos atf_test_case resize_2part
155 1.5 christos resize_2part_head() {
156 1.5 christos atf_set "descr" "Resize a 2 partition disk and partition"
157 1.5 christos }
158 1.5 christos
159 1.5 christos resize_2part_body() {
160 1.5 christos prepare_2part
161 1.5 christos dd conv=notrunc if=/dev/zero of=$disk seek=$newsize count=1
162 1.5 christos atf_check -s exit:0 -o empty -e empty gpt resizedisk $disk
163 1.5 christos atf_check -s exit:0 -o file:"$src/gpt.resizedisk.show.normal" \
164 1.5 christos gpt show $disk
165 1.5 christos atf_check -s exit:0 -o match:"$(partresmsg 2 1058 19390)" \
166 1.5 christos -e empty gpt resize -i 2 $disk
167 1.5 christos atf_check -s exit:0 -o file:"$src/gpt.resizepart.show.normal" \
168 1.5 christos gpt show $disk
169 1.5 christos }
170 1.5 christos
171 1.6 christos atf_test_case remove_2part
172 1.6 christos remove_2part_head() {
173 1.6 christos atf_set "descr" "Remove a partition from a 2 partition disk"
174 1.6 christos }
175 1.6 christos
176 1.6 christos remove_2part_body() {
177 1.6 christos prepare_2part
178 1.6 christos atf_check -s exit:0 -o match:"$(partremmsg 1)" -e empty gpt remove \
179 1.6 christos -i 1 $disk
180 1.6 christos atf_check -s exit:0 -o file:"$src/gpt.removepart.show.normal" \
181 1.6 christos gpt show $disk
182 1.6 christos }
183 1.6 christos
184 1.6 christos atf_test_case label_2part
185 1.6 christos label_2part_head() {
186 1.6 christos atf_set "descr" "Label partitions in 2 partition disk"
187 1.6 christos }
188 1.6 christos
189 1.6 christos label_2part_body() {
190 1.6 christos prepare_2part
191 1.6 christos atf_check -s exit:0 -o match:"$(partlblmsg 1)" -e empty \
192 1.6 christos gpt label -i 1 -l potato $disk
193 1.6 christos atf_check -s exit:0 -o match:"$(partlblmsg 2)" -e empty \
194 1.6 christos gpt label -i 2 -l tomato $disk
195 1.6 christos atf_check -s exit:0 -o file:"$src/gpt.2part.show.label" gpt show -l $disk
196 1.6 christos }
197 1.6 christos
198 1.1 christos atf_init_test_cases() {
199 1.1 christos atf_add_test_case create_empty
200 1.1 christos atf_add_test_case create_2part
201 1.1 christos atf_add_test_case backup_2part
202 1.6 christos atf_add_test_case remove_2part
203 1.1 christos atf_add_test_case restore_2part
204 1.1 christos atf_add_test_case recover_backup
205 1.1 christos atf_add_test_case recover_primary
206 1.5 christos atf_add_test_case resize_2part
207 1.6 christos atf_add_test_case label_2part
208 1.1 christos }
209