summaryrefslogtreecommitdiff
path: root/tests/common
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.cz>2015-05-21 16:33:16 +0200
committerDavid Sterba <dsterba@suse.cz>2015-05-21 16:37:52 +0200
commitd6cedbcdd334174468f6f8815fb030b90704df74 (patch)
tree9d086c64336d270396903300b5ba59cabde2c2fb /tests/common
parent7c6801606e11a4664c0a2a195a1422cb86fe7dad (diff)
btrfs-progs: tests: support more formats of test images
We're using he meta-dump images, now we support compressed meta-dump, raw and compressed raw images. Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'tests/common')
-rw-r--r--tests/common47
1 files changed, 41 insertions, 6 deletions
diff --git a/tests/common b/tests/common
index 94cf913c..e02359c7 100644
--- a/tests/common
+++ b/tests/common
@@ -30,6 +30,8 @@ check_prereq()
check_image()
{
+ local image
+
image=$1
echo "testing image $(basename $image)" >> $RESULTS
$TOP/btrfs check $image >> $RESULTS 2>&1
@@ -39,18 +41,51 @@ check_image()
run_check $TOP/btrfs check $image
}
+# Process all image dumps in a given directory,
+# - raw btrfs filesystem images, suffix .raw
+# - dtto compressed by XZ, suffix .raw.xz
+# - meta-dump images with suffix .img
+# - dtto compressed by XZ, suffix .img.xz
check_all_images()
{
dir=$1
- for i in $(find $dir -iname '*.img')
+ for image in $(find $dir \( -iname '*.img' -o \
+ -iname '*.img.xz' -o \
+ -iname '*.raw' -o \
+ -iname '*.raw.xz' \) )
do
- echo "extracting image $(basename $i)" >> $RESULTS
- $TOP/btrfs-image -r $i $i.restored || \
- _fail "failed to extract image $i"
+ cleanme=
+ case "$image" in
+ *.img)
+ rm -f $image.restored
+ : ;;
+ *.img.xz)
+ xz --decompress --keep "$image" || \
+ _fail "failed to decompress image $image"
+ image=${image%%.xz}
+ rm -f $image.restored
+ cleanme=$image
+ ;;
+ *.raw)
+ cp --sparse=auto $image $image.restored
+ ;;
+ *.raw.xz)
+ xz --decompress --keep "$image" || \
+ _fail "failed to decompress image $image"
+ image=${image%%.xz}
+ mv "$image" "$image".restored
+ ;;
+ esac
+
+ if ! [ -f $image.restored ]; then
+ echo "restoring image $(basename $image)" >> $RESULTS
+ $TOP/btrfs-image -r $image $image.restored || \
+ _fail "failed to restore image $image"
+ fi
- check_image $i.restored
+ check_image $image.restored
- rm $i.restored
+ rm -f $image.restored $cleanme
done
}