"Fossies" - the Fresh Open Source Software Archive

Member "srm-1.2.15/test.sh" (26 Feb 2015, 4683 Bytes) of package /linux/privat/srm-1.2.15.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "test.sh": 1.2.14_vs_1.2.15.

    1 #!/bin/sh
    2 # test script for srm
    3 
    4 set -e # exit if any commands fail
    5 
    6 make
    7 test/fill_test
    8 
    9 SRM="src/srm -vvvvvvv"
   10 
   11 # test different file types
   12 
   13 testremove()
   14 {
   15     $SRM -rf "$1"
   16     if [ -e "$1" ] ; then
   17     echo could not remove $1
   18     exit 1
   19     fi
   20 }
   21 
   22 # symlink
   23 echo "testing symlinks..."
   24 rm -f test.symlink
   25 echo "TEST" > test.file
   26 if [ ! -f test.file ] ; then
   27     echo could not create test file
   28     exit 1
   29 fi
   30 
   31 ln -s test.file test.symlink
   32 if [ ! -L test.symlink ] ; then
   33     echo could not create symlink
   34     exit 1
   35 fi
   36 testremove test.symlink
   37 
   38 I=`whoami`
   39 if [ "$I" != root ] ; then
   40     echo "testing symlink to root's files..."
   41     ln -s /etc/fstab test.symlink
   42     if [ ! -L test.symlink ] ; then
   43     echo could not create symlink
   44     exit 1
   45     fi
   46     testremove test.symlink
   47 else
   48     echo "can not test symlink to root's files, test.sh is run by root."
   49 fi
   50 
   51 # permissions
   52 echo
   53 echo "testing file permissions..."
   54 echo "TEST" > test.file2
   55 chmod 000 test.file2
   56 testremove test.file2
   57 
   58 # recursing into directories
   59 echo
   60 echo "testing recursing into directories..."
   61 rm -rf test.dir
   62 mkdir test.dir
   63 if [ ! -d test.dir ] ; then
   64     echo could not mkdir test.dir
   65     exit 1
   66 fi
   67 
   68 echo "TEST2" > test.dir/file2
   69 cd test.dir
   70 ln -s file2 link2
   71 if [ ! -L link2 ] ; then
   72     echo link2
   73     exit 1
   74 fi
   75 cd ..
   76 
   77 testremove test.dir
   78 
   79 # device nodes
   80 echo
   81 if [ "$I" = root ] ; then
   82     echo "testing device nodes..."
   83 
   84     mkdir test.dir2
   85     echo "TEST" > test.dir2/test.file
   86     chmod 000 test.dir2/test.file
   87     chmod 000 test.dir2
   88     testremove test.dir2
   89 
   90     mknod test.char c 1 1
   91     if [ ! -c test.char ] ; then
   92     echo could not mknod test.char
   93     exit 1
   94     fi
   95     testremove test.char
   96 
   97     mknod test.block b 1 1
   98     if [ ! -b test.block ] ; then
   99     echo could not mknod test.block
  100     exit 1
  101     fi
  102     testremove test.block
  103 
  104 else
  105     echo "not running test.sh as root, not testing device nodes"
  106 fi
  107 
  108 # FIFO special file
  109 echo
  110 echo "testing FIFO..."
  111 mkfifo test.fifo
  112 if [ ! -p test.fifo ] ; then
  113     echo could not create fifo
  114     exit 1
  115 fi
  116 testremove test.fifo
  117 
  118 # hard links
  119 echo
  120 echo "testing hard links..."
  121 echo "the hard link" > test.file
  122 cp -f test.file test2.file
  123 ln test.file test3.file
  124 if ! cmp test.file test3.file ; then
  125     echo "compare of test.file and test3.file failed on hard link test"
  126     exit 1
  127 fi
  128 testremove test3.file
  129 if ! cmp test.file test2.file ; then
  130     echo "compare of test.file and test2.file failed on hard link test"
  131     exit 1
  132 fi
  133 testremove test2.file
  134 if [ -f test2.file ] ; then
  135     echo "could not remove test2.file on hard link test"
  136     exit 1
  137 fi
  138 if [ -f test3.file ] ; then
  139     echo "could not remove test3.file on hard link test"
  140     exit 1
  141 fi
  142 
  143 testremove test.file
  144 if [ -f test.file ] ; then
  145     echo could not remove test file
  146     exit 1
  147 fi
  148 
  149 # test directory symlink
  150 echo
  151 echo "testing directory symlinks..."
  152 mkdir test.dir
  153 cd test.dir
  154 echo test > test.file
  155 ln -s test.file test.link
  156 mkdir -p /tmp/doj
  157 echo test2 > /tmp/doj/test.file2
  158 ln -s /tmp/doj doj
  159 cd ..
  160 testremove test.dir
  161 if [ ! -f /tmp/doj/test.file2 ] ; then
  162     echo srm deleted /tmp/doj/test.file2 instead of directory symlink
  163     exit 1
  164 fi
  165 
  166 # test return code if remove fails
  167 if [ "$USER" = doj -a "$HOST" = cubicle.cubic.org ] ; then
  168     cp -f /etc/fstab "/tmp/$USER.fstab"
  169     set +e
  170     if $SRM -f /etc/fstab ; then
  171     echo "removing /etc/fstab as user should not work"
  172     exit 1
  173     fi
  174     set -e
  175 fi
  176 
  177 # test extended attributes
  178 if [ 1 = 2 ] ; then
  179 echo
  180 echo "test extended attributes..."
  181 DIR=test.test
  182 mkdir -p $DIR
  183 chmod +t $DIR
  184 FN=$DIR/test.atr
  185 echo "TEST" > $FN
  186 OS=$(uname -s)
  187 if [ "$OS" = Linux ] ; then
  188     setfattr -n user.a1 -v "The value of extended attribute number 1" $FN
  189     setfattr -n user.num2 -v "A second attribute." $FN
  190 elif [ "$OS" = FreeBSD ] ; then
  191     setextattr user a1 "The value of extended attribute number 1" $FN
  192     setextattr user num2 "A second attribute." $FN
  193 elif [ "$OS" = Darwin ] ; then
  194     xattr -w a1 "The value of extended attribute number 1" $FN
  195     xattr -w num2 "A second attribute." $FN
  196 fi
  197 $SRM $FN
  198 rmdir $DIR
  199 fi
  200 
  201 # test file sizes
  202 
  203 BS=123
  204 SRC=/dev/zero # /dev/urandom
  205 
  206 if [ ! -c $SRC ] ; then
  207     echo $SRC not present or no char device
  208     exit 1
  209 fi
  210 
  211 testsrm()
  212 {
  213     if [ ! -f $F ] ; then
  214     echo failed to create $F
  215     exit 1
  216     fi
  217     if ! $SRM $F ; then
  218     echo failed to secure remove $F
  219     exit 1
  220     fi
  221     if [ -f $F ] ; then
  222     echo srm was not able to remove $F
  223     exit 1
  224     fi
  225 }
  226 
  227 F="0.tst"
  228 touch $F
  229 testsrm
  230 
  231 # test until ~5GiB
  232 for i in 1 22 333 4444 55555 666666 7777777 44444444
  233 do
  234     echo
  235     echo
  236     echo "test file of $(($i * $BS / 1024)) KB..."
  237     F="$i.tst"
  238     dd if=$SRC of=$F bs=$BS count=$i 2> /dev/null
  239     testsrm
  240 done
  241 
  242 echo "all tests successful."
  243 exit 0