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
66 if [ $UID -eq 0 ]; then
69 if [ $need_validate -eq 1 ]; then
70 sudo -v -n &> /dev/null || \
71 _not_run "Need validate sudo credential"
73 elif [ $need_validate -eq 0 ]; then
74 sudo -n true &> /dev/null || \
75 _not_run "Need validate sudo user setting"
79 _not_run "Need validate root privilege"
86 if [ $UID -eq 0 ]; then
89 # Test for old sudo or special setting, which makes sudo -v fails even
90 # user is set NOPASSWD
91 sudo -n true &> /dev/null && need_validate=0
93 # Newer sudo or default sudo setting
94 sudo -v -n &> /dev/null && need_validate=1
96 if [ $need_validate -eq -1 ]; then
97 _not_run "Need validate root privilege"