3 # Common routines for all tests
8 echo "$*" | tee -a $RESULTS
20 echo "############### $@" >> $RESULTS 2>&1
21 "$@" >> $RESULTS 2>&1 || _fail "failed: $@"
24 # same as run_check but the stderr+stdout output is duplicated on stdout and
25 # can be processed further
28 echo "############### $@" >> $RESULTS 2>&1
29 "$@" 2>&1 | tee -a $RESULTS || _fail "failed: $@"
34 if ! [ -f $TOP/$1 ]; then
35 _fail "Failed prerequisities: $1";
44 echo "testing image $(basename $image)" >> $RESULTS
45 $TOP/btrfs check $image >> $RESULTS 2>&1
46 [ $? -eq 0 ] && _fail "btrfs check should have detected corruption"
48 run_check $TOP/btrfs check --repair $image
49 run_check $TOP/btrfs check $image
52 # Process all image dumps in a given directory,
53 # - raw btrfs filesystem images, suffix .raw
54 # - dtto compressed by XZ, suffix .raw.xz
55 # - meta-dump images with suffix .img
56 # - dtto compressed by XZ, suffix .img.xz
60 for image in $(find $dir \( -iname '*.img' -o \
61 -iname '*.img.xz' -o \
63 -iname '*.raw.xz' \) | sort)
71 xz --decompress --keep "$image" || \
72 _fail "failed to decompress image $image"
78 cp --sparse=auto $image $image.restored
81 xz --decompress --keep "$image" || \
82 _fail "failed to decompress image $image"
84 mv "$image" "$image".restored
88 if ! [ -f $image.restored ]; then
89 echo "restoring image $(basename $image)" >> $RESULTS
90 $TOP/btrfs-image -r $image $image.restored || \
91 _fail "failed to restore image $image"
94 check_image $image.restored
96 rm -f $image.restored $cleanme
100 # some tests need to mount the recovered image and do verifications call
101 # 'setup_root_helper' and then check for have_root_helper == 1 if the test
102 # needs to fail otherwise; using sudo by default for now
104 NEED_SUDO_VALIDATE=unknown
106 export NEED_SUDO_VALIDATE
109 if [ $UID -eq 0 ]; then
112 if [ "$NEED_SUDO_VALIDATE" = 'yes' ]; then
113 sudo -v -n &>/dev/null || \
114 _not_run "Need to validate sudo credentials"
116 elif [ "$NEED_SUDO_VALIDATE" = 'no' ]; then
117 sudo -n /bin/true &> /dev/null || \
118 _not_run "Need to validate sudo user settings"
122 _not_run "Need to validate root privileges"
129 if [ $UID -eq 0 ]; then
133 # Test for old sudo or special settings, which make sudo -v fail even
134 # if user setting is NOPASSWD
135 sudo -n /bin/true &>/dev/null && NEED_SUDO_VALIDATE=no
137 # Newer sudo or default sudo setting
138 sudo -v -n &>/dev/null && NEED_SUDO_VALIDATE=yes
140 if [ "$NEED_SUDO_VALIDATE" = 'unknown' ]; then
141 _not_run "Need to validate root privileges"
143 SUDO_HELPER=root_helper