3 # Common routines for all tests
8 echo "$*" | tee -a $RESULTS
20 echo "############### $@" >> $RESULTS 2>&1
21 "$@" >> $RESULTS 2>&1 || _fail "failed: $@"
26 if ! [ -f $TOP/$1 ]; then
27 _fail "Failed prerequisities: $1";
36 echo "testing image $(basename $image)" >> $RESULTS
37 $TOP/btrfs check $image >> $RESULTS 2>&1
38 [ $? -eq 0 ] && _fail "btrfs check should have detected corruption"
40 run_check $TOP/btrfs check --repair $image
41 run_check $TOP/btrfs check $image
44 # Process all image dumps in a given directory,
45 # - raw btrfs filesystem images, suffix .raw
46 # - dtto compressed by XZ, suffix .raw.xz
47 # - meta-dump images with suffix .img
48 # - dtto compressed by XZ, suffix .img.xz
52 for image in $(find $dir \( -iname '*.img' -o \
53 -iname '*.img.xz' -o \
55 -iname '*.raw.xz' \) )
63 xz --decompress --keep "$image" || \
64 _fail "failed to decompress image $image"
70 cp --sparse=auto $image $image.restored
73 xz --decompress --keep "$image" || \
74 _fail "failed to decompress image $image"
76 mv "$image" "$image".restored
80 if ! [ -f $image.restored ]; then
81 echo "restoring image $(basename $image)" >> $RESULTS
82 $TOP/btrfs-image -r $image $image.restored || \
83 _fail "failed to restore image $image"
86 check_image $image.restored
88 rm -f $image.restored $cleanme
92 # some tests need to mount the recovered image and do verifications call
93 # 'setup_root_helper' and then check for have_root_helper == 1 if the test
94 # needs to fail otherwise; using sudo by default for now
96 NEED_SUDO_VALIDATE=unknown
98 export NEED_SUDO_VALIDATE
101 if [ $UID -eq 0 ]; then
104 if [ "$NEED_SUDO_VALIDATE" = 'yes' ]; then
105 sudo -v -n &>/dev/null || \
106 _not_run "Need to validate sudo credentials"
108 elif [ "$NEED_SUDO_VALIDATE" = 'no' ]; then
109 sudo -n /bin/true &> /dev/null || \
110 _not_run "Need to validate sudo user settings"
114 _not_run "Need to validate root privileges"
121 if [ $UID -eq 0 ]; then
125 # Test for old sudo or special settings, which make sudo -v fail even
126 # if user setting is NOPASSWD
127 sudo -n /bin/true &>/dev/null && NEED_SUDO_VALIDATE=no
129 # Newer sudo or default sudo setting
130 sudo -v -n &>/dev/null && NEED_SUDO_VALIDATE=yes
132 if [ "$NEED_SUDO_VALIDATE" = 'unknown' ]; then
133 _not_run "Need to validate root privileges"
135 SUDO_HELPER=root_helper