]> git.wh0rd.org - dump.git/blob - testing/scripts/quick-regression.sh
Regenerate configure.
[dump.git] / testing / scripts / quick-regression.sh
1 #!/bin/bash
2
3 #
4 # 5-second regression test for dump/verify/restore. It's not intended to be
5 # an exhaustive regression test, just a quick way to verify that you haven't
6 # introduced any errors when changing code.
7 #
8 # N.B., this only verifies that THIS build of dump(8) and THIS build of
9 # restore(8) will play well together. It does not guarantee that these systems
10 # are compatible with released versions of the software! For that we need
11 # to keep images of known-good partitions and dump files.
12 #
13 # Author: Bear Giles (bgiles@coyotesong.com)
14 # License granted to dump project under non-advertising BSD license.
15 #
16
17 #
18 # Create 10 MB virtual partition.
19 #
20 # mkvirtpart(filename, loop device)
21 #
22 mkvirtpart()
23 {
24 FILENAME=$1
25 LOOPDEV=$2
26
27 if [ "$#" -ne "2" ]; then
28 /bin/echo "usage: mkvrtpart FILENAME LOOPDEV"
29 return 1
30 fi
31
32 # create 10M sparse file
33 /usr/bin/truncate -s 10M $FILENAME
34 if [ "$?" -ne "0" ]; then
35 /bin/echo "unable to create partition image."
36 return 1
37 fi
38
39 # mount and format it
40 /sbin/losetup $LOOPDEV $FILENAME
41 if [ "$?" -ne "0" ]; then
42 /bin/echo "setting up loop device failed."
43 return 1
44 fi
45
46 /sbin/mkfs -text4 $LOOPDEV
47 if [ "$?" -ne "0" ]; then
48 /bin/echo "formating test partition failed."
49 /sbin/losetup -d $LOOPDEV
50 return 1
51 fi
52
53 /sbin/losetup -d $LOOPDEV
54 if [ "$?" -ne "0" ]; then
55 /bin/echo "tearing down loop device failed."
56 return 1
57 fi
58 }
59
60 #
61 # Populate test filesystem
62 #
63 # mktestfs(root)
64 mktestfs()
65 {
66 ROOT=$1
67
68 if [ "$#" -ne "1" ]; then
69 /bin/echo "usage: mktestfs ROOT"
70 return 1
71 fi
72
73 if [ "$ROOT" == "" -o "$ROOT" == "/" ]; then
74 /bin/echo "cowardly refusing to stomp on root."
75 return 1
76 fi
77
78 /usr/bin/install -d $ROOT
79
80 # create typical file
81 /usr/bin/touch $ROOT/perm644
82 /bin/chmod 0644 $ROOT/perm644
83
84 # create typical executable
85 /usr/bin/touch $ROOT/perm755
86 /bin/chmod 0755 $ROOT/perm755
87
88 # create multiple symlinks
89 /usr/bin/touch $ROOT/symlink
90 /bin/ln $ROOT/symlink $ROOT/symlink1
91 /bin/ln $ROOT/symlink $ROOT/symlink2
92
93 # create hard links
94 /usr/bin/touch $ROOT/hardlink
95 /bin/ln $ROOT/hardlink $ROOT/hardlink1
96 /bin/ln $ROOT/hardlink $ROOT/hardlink2
97
98 # create block device
99 /bin/mknod $ROOT/block b 10 20
100
101 # create character device
102 /bin/mknod $ROOT/char c 11 21
103
104 # create FIFO
105 /bin/mknod $ROOT/pipe p
106
107 # make sparse device
108 #/usr/bin/truncate -s 500k $ROOT/sparse
109
110 # populate some files
111 /bin/mkdir $ROOT/man1
112 /bin/cp -rp /usr/share/man/man1/* $ROOT/man1
113 }
114
115 #
116 # Single test cycle
117 #
118 dump_verify_restore() {
119
120 if [ "$#" -lt "5" ]; then
121 /bin/echo "usage: dump_verify_restore SRC_LOOPDEV SRC_MOUNTPOINT DEST_LOOPDEV DEST_MOUNTPOINT DUMPFILE ..."
122 return 1
123 fi
124
125 SRC_LOOPDEV=$1
126 SRC_MOUNTPOINT=$2
127 DEST_LOOPDEV=$3
128 DEST_MOUNTPOINT=$4
129 DUMPFILE=$5
130
131 shift; shift; shift; shift; shift
132
133 /sbin/losetup $SRC_LOOPDEV $SRC_FILENAME
134 if [ "$?" -ne "0" ]; then
135 /bin/echo "setting up loop device failed."
136 return 1
137 fi
138
139 # we have to mount partition for verify to work even if we dump the
140 # underlying partition.
141 /bin/mount $SRC_LOOPDEV $SRC_MOUNTPOINT
142 if [ "$?" -ne "0" ]; then
143 /bin/echo "mounting source partition failed."
144 /sbin/losetup -d $SRC_LOOPDEV
145 return 1;
146 fi
147
148 # dump the test partition
149 ../dump/dump -0 $@ -f $DUMPFILE $SRC_LOOPDEV
150 if [ "$?" -ne "0" ]; then
151 echo "dump failed, error code $?"
152 /bin/rm $DUMPFILE
153 /bin/umount $SRC_MOUNTPOINT
154 /sbin/losetup -d $SRC_LOOPDEV
155 return 1
156 fi
157
158 # verify
159 ../restore/restore -C -f $DUMPFILE
160 if [ "$?" -ne "0" ]; then
161 echo "verification failed, error code $?"
162 /bin/rm $DUMPFILE
163 /bin/umount $SRC_MOUNTPOINT
164 /sbin/losetup -d $SRC_LOOPDEV
165 return 1
166 fi
167
168 # restore fs, compare to orginal one
169 # I can't do that yet since restore will only restore to the current directory.
170 # this makes sense for a number of reasons it difficult to test our newly
171 # compiled code.
172 # ../../restore/restore -r ...
173
174 # tear everything down
175 /bin/umount $SRC_MOUNTPOINT
176 if [ "$?" -ne "0" ]; then
177 /bin/echo "unmounting test partition failed."
178 return 1
179 fi
180
181 /sbin/losetup -d $SRC_LOOPDEV
182 if [ "$?" -ne "0" ]; then
183 /bin/echo "tearing down loop device failed."
184 return 1
185 fi
186 }
187
188 #
189 # set up source partition.
190 #
191 setup_src_partition() {
192 SRC_FILENAME=$1
193 SRC_LOOPDEV=$2
194 SRC_MOUNTPOINT=$3
195
196 if [ "$#" -ne "3" ]; then
197 /bin/echo "usage: setup_src_partition SRC_FILENAME SRC_LOOPDEV SRC_MOUNTPOINT"
198 return 1
199 fi
200
201 mkvirtpart $SRC_FILENAME $SRC_LOOPDEV
202 if [ $? -ne 0 ]; then
203 /bin/echo "creating source test partition failed."
204 return 1
205 fi
206
207 # mount it
208 /sbin/losetup $SRC_LOOPDEV $SRC_FILENAME
209 if [ "$?" -ne "0" ]; then
210 /bin/echo "setting up loop device failed."
211 return 1
212 fi
213
214 /bin/mount $SRC_LOOPDEV $SRC_MOUNTPOINT
215 if [ "$?" -ne "0" ]; then
216 /bin/echo "mounting test partition failed."
217 return 1
218 fi
219
220 mktestfs $SRC_MOUNTPOINT
221 if [ "$?" -ne "0" ]; then
222 return 1
223 fi
224
225 /bin/umount $SRC_LOOPDEV
226 if [ "$?" -ne "0" ]; then
227 /bin/echo "unmounting test partition failed."
228 return 1
229 fi
230
231 /sbin/losetup -d $SRC_LOOPDEV
232 if [ "$?" -ne "0" ]; then
233 /bin/echo "tearing down loop device failed."
234 return 1
235 fi
236
237 return 0
238 }
239
240
241 #
242 # clean up temporary files. We want to be extremely careful here that
243 # we don't accidently do a 'rm -rf' on /
244 #
245 cleanup() {
246
247 if [ "$#" -ne "6" ]; then
248 /bin/echo "usage: cleanup SRC_FILENAME SRC_MOUNTPOINT DEST_FILENAME DEST_MOUNTPOINT BASEDIR DUMPFILE"
249 return 1
250 fi
251
252 SRC_FILENAME=$1
253 SRC_MOUNTPOINT=$2
254 DEST_FILENAME=$3
255 DEST_MOUNTPOINT=$4
256 BASEDIR=$5
257 DUMPFILE=$6
258
259 if [ "$BASEDIR" == "" -o "$BASEDIR" == "/" ]; then
260 /bin/echo "cowardly refusing to delete root."
261 return 1
262 fi
263
264 # we don't do rm -r since we don't want to delete
265 # anything we didn't create.
266 /bin/rm -f $SRC_FILENAME
267 /bin/rmdir $SRC_MOUNTPOINT
268 /bin/rm -f $DEST_FILENAME
269 /bin/rmdir $DEST_MOUNTPOINT
270 /bin/rm -f $DUMPFILE
271 /bin/rmdir $BASEDIR
272
273 return 0
274 }
275
276 ###############################################
277 #
278 # the actual script
279 #
280 BASEDIR=`/bin/mktemp -d`
281
282 SRC_FILENAME=$BASEDIR/dump-test-src.img
283 SRC_LOOPDEV=/dev/loop6
284 SRC_MOUNTPOINT=$BASEDIR/src
285 DEST_FILENAME=$BASEDIR/dump-test-dst.img
286 DEST_LOOPDEV=/dev/loop7
287 DEST_MOUNTPOINT=$BASEDIR/dest
288 DUMPFILE=$BASEDIR/dump-test.dump
289
290 /bin/echo BASEDIR = $BASEDIR
291
292 /usr/bin/install -d $BASEDIR
293 /usr/bin/install -d $SRC_MOUNTPOINT
294 /usr/bin/install -d $DEST_MOUNTPOINT
295
296 # Setup source partition
297 setup_src_partition $SRC_FILENAME $SRC_LOOPDEV $SRC_MOUNTPOINT
298 if [ $? -ne 0 ]; then
299 /bin/echo "creating source test partition failed."
300 cleanup $SRC_FILENAME $SRC_MOUNTPOINT $DEST_FILENAME $DEST_MOUNTPOINT $BASEDIR $DUMPFILE
301 exit 1
302 fi
303
304 # create dest partition (for restores)
305 mkvirtpart $DEST_FILENAME $DEST_LOOPDEV
306 if [ $? -ne 0 ]; then
307 /bin/echo "creating destination test partition failed."
308 cleanup $SRC_FILENAME $SRC_MOUNTPOINT $DEST_FILENAME $DEST_MOUNTPOINT $BASEDIR $DUMPFILE
309 exit 1
310 fi
311
312 echo
313 echo "testing basic dump/restore"
314 dump_verify_restore $SRC_LOOPDEV $SRC_MOUNTPOINT $DEST_LOOPDEV $DEST_MOUNTPOINT $DUMPFILE
315 if [ $? -ne 0 ]; then
316 /bin/echo "dump cycle failed."
317 cleanup $SRC_FILENAME $SRC_MOUNTPOINT $DEST_FILENAME $DEST_MOUNTPOINT $BASEDIR $DUMPFILE
318 exit 1
319 fi
320
321 echo
322 echo "testing compressed dump/restore (lzo)..."
323 dump_verify_restore $SRC_LOOPDEV $SRC_MOUNTPOINT $DEST_LOOPDEV $DEST_MOUNTPOINT $DUMPFILE -y
324 if [ $? -ne 0 ]; then
325 /bin/echo "dump cycle failed."
326 cleanup $SRC_FILENAME $SRC_MOUNTPOINT $DEST_FILENAME $DEST_MOUNTPOINT $BASEDIR $DUMPFILE
327 exit 1
328 fi
329
330 echo
331 echo "testing compressed dump/restore (zlib)..."
332 dump_verify_restore $SRC_LOOPDEV $SRC_MOUNTPOINT $DEST_LOOPDEV $DEST_MOUNTPOINT $DUMPFILE -z2
333 if [ $? -ne 0 ]; then
334 /bin/echo "dump cycle failed."
335 cleanup $SRC_FILENAME $SRC_MOUNTPOINT $DEST_FILENAME $DEST_MOUNTPOINT $BASEDIR $DUMPFILE
336 exit 1
337 fi
338
339 echo
340 echo "testing compressed dump/restore (bzlib)..."
341 dump_verify_restore $SRC_LOOPDEV $SRC_MOUNTPOINT $DEST_LOOPDEV $DEST_MOUNTPOINT $DUMPFILE -j2
342 if [ $? -ne 0 ]; then
343 /bin/echo "dump cycle failed."
344 cleanup $SRC_FILENAME $SRC_MOUNTPOINT $DEST_FILENAME $DEST_MOUNTPOINT $BASEDIR $DUMPFILE
345 exit 1
346 fi
347
348 cleanup $SRC_FILENAME $SRC_MOUNTPOINT $DEST_FILENAME $DEST_MOUNTPOINT $BASEDIR $DUMPFILE
349
350 /bin/echo "#"
351 /bin/echo "# success!"
352 /bin/echo "#"
353
354 exit 0