3 # Common routines for all tests
8 echo "$*" | tee -a $RESULTS
12 # log a message to the results file
15 echo "$*" | tee -a $RESULTS
26 echo "############### $@" >> $RESULTS 2>&1
27 "$@" >> $RESULTS 2>&1 || _fail "failed: $@"
30 # same as run_check but the stderr+stdout output is duplicated on stdout and
31 # can be processed further
34 echo "############### $@" >> $RESULTS 2>&1
35 "$@" 2>&1 | tee -a $RESULTS || _fail "failed: $@"
38 # same as run_check but does not fail the test, output is logged
41 echo "############### $@" >> $RESULTS 2>&1
42 "$@" >> $RESULTS 2>&1 || _log "failed (ignored): $@"
47 if ! [ -f $TOP/$1 ]; then
48 _fail "Failed prerequisities: $1";
57 echo "testing image $(basename $image)" >> $RESULTS
58 $TOP/btrfs check $image >> $RESULTS 2>&1
59 [ $? -eq 0 ] && _fail "btrfs check should have detected corruption"
61 run_check $TOP/btrfs check --repair $image
62 run_check $TOP/btrfs check $image
65 # Process all image dumps in a given directory,
66 # - raw btrfs filesystem images, suffix .raw
67 # - dtto compressed by XZ, suffix .raw.xz
68 # - meta-dump images with suffix .img
69 # - dtto compressed by XZ, suffix .img.xz
73 for image in $(find $dir \( -iname '*.img' -o \
74 -iname '*.img.xz' -o \
76 -iname '*.raw.xz' \) | sort)
84 xz --decompress --keep "$image" || \
85 _fail "failed to decompress image $image"
91 cp --sparse=auto $image $image.restored
94 xz --decompress --keep "$image" || \
95 _fail "failed to decompress image $image"
97 mv "$image" "$image".restored
101 if ! [ -f $image.restored ]; then
102 echo "restoring image $(basename $image)" >> $RESULTS
103 $TOP/btrfs-image -r $image $image.restored || \
104 _fail "failed to restore image $image"
107 check_image $image.restored
109 rm -f $image.restored $cleanme
113 # some tests need to mount the recovered image and do verifications call
114 # 'setup_root_helper' and then check for have_root_helper == 1 if the test
115 # needs to fail otherwise; using sudo by default for now
117 NEED_SUDO_VALIDATE=unknown
119 export NEED_SUDO_VALIDATE
122 if [ $UID -eq 0 ]; then
125 if [ "$NEED_SUDO_VALIDATE" = 'yes' ]; then
126 sudo -v -n &>/dev/null || \
127 _not_run "Need to validate sudo credentials"
129 elif [ "$NEED_SUDO_VALIDATE" = 'no' ]; then
130 sudo -n /bin/true &> /dev/null || \
131 _not_run "Need to validate sudo user settings"
135 _not_run "Need to validate root privileges"
142 if [ $UID -eq 0 ]; then
146 # Test for old sudo or special settings, which make sudo -v fail even
147 # if user setting is NOPASSWD
148 sudo -n /bin/true &>/dev/null && NEED_SUDO_VALIDATE=no
150 # Newer sudo or default sudo setting
151 sudo -v -n &>/dev/null && NEED_SUDO_VALIDATE=yes
153 if [ "$NEED_SUDO_VALIDATE" = 'unknown' ]; then
154 _not_run "Need to validate root privileges"
156 SUDO_HELPER=root_helper
164 [[ "$TEST_DEV" ]] && return
165 [[ "$size" ]] || size='1G'
167 echo "\$TEST_DEV not given, use $TOP/test/test.img as fallback" >> \
169 TEST_DEV="$TOP/tests/test.img"
171 truncate -s "$size" "$TEST_DEV" || _not_run "create file for loop device failed"