3 # Common routines for all tests
8 echo "$*" | tee -a $RESULT
20 echo "############### $@" >> $RESULT 2>&1
21 "$@" >> $RESULT 2>&1 || _fail "failed: $@"
26 if ! [ -f $top/$1 ]; then
27 _fail "Failed prerequisities: $1";
34 echo "testing image $(basename $image)" >> $RESULT
35 $top/btrfs check $image >> $RESULT 2>&1
36 [ $? -eq 0 ] && _fail "btrfs check should have detected corruption"
38 run_check $top/btrfs check --repair $image
39 run_check $top/btrfs check $image
45 for i in $(find $dir -iname '*.img')
47 echo "extracting image $(basename $i)" >> $RESULT
48 $top/btrfs-image -r $i $i.restored || \
49 _fail "failed to extract image $i"
51 check_image $i.restored
57 # some tests need to mount the recovered image and do verifications call
58 # 'setup_root_helper' and then check for have_root_helper == 1 if the test
59 # needs to fail otherwise; using sudo by default for now
61 NEED_SUDO_VALIDATE=unknown
63 export NEED_SUDO_VALIDATE
66 if [ $UID -eq 0 ]; then
69 if [ "$NEED_SUDO_VALIDATE" = 'yes' ]; then
70 sudo -v -n &>/dev/null || \
71 _not_run "Need to validate sudo credentials"
73 elif [ "$NEED_SUDO_VALIDATE" = 'no' ]; then
74 sudo -n /bin/true &> /dev/null || \
75 _not_run "Need to validate sudo user settings"
79 _not_run "Need to validate root privileges"
86 if [ $UID -eq 0 ]; then
90 # Test for old sudo or special settings, which make sudo -v fail even
91 # if user setting is NOPASSWD
92 sudo -n /bin/true &>/dev/null && NEED_SUDO_VALIDATE=no
94 # Newer sudo or default sudo setting
95 sudo -v -n &>/dev/null && NEED_SUDO_VALIDATE=yes
97 if [ "$NEED_SUDO_VALIDATE" = 'unknown' ]; then
98 _not_run "Need to validate root privileges"
100 SUDO_HELPER=root_helper