1#!/bin/sh 2################################################################################ 3## ## 4## Copyright (c) International Business Machines Corp., 2001 ## 5## ## 6## This program is free software; you can redistribute it and#or modify ## 7## it under the terms of the GNU General Public License as published by ## 8## the Free Software Foundation; either version 2 of the License, or ## 9## (at your option) any later version. ## 10## ## 11## This program is distributed in the hope that it will be useful, but ## 12## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## 13## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## 14## for more details. ## 15## ## 16## You should have received a copy of the GNU General Public License ## 17## along with this program; if not, write to the Free Software ## 18## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ## 19## ## 20################################################################################ 21# 22# File : ln_test.sh 23# 24# Description: Test basic functionality of ln command 25# - Test #1: ln -s make symbolic links instead of hard links 26# 27# Author: Manoj Iyer, manjo@mail.utexas.edu 28# 29# History: Feb 03 2003 - Created, Manoj Iyer 30# 31# Function: init 32# 33# Description: - Check if command ln is available. 34# - Create temprary directory, and temporary files. 35# - Initialize environment variables. 36# 37# Return - zero on success 38# - non zero on failure. return value from commands ($RC) 39init() 40{ 41 42 RC=0 # Return code from commands. 43 export TST_TOTAL=1 # total numner of tests in this file. 44 export TCID=ln # this is the init function. 45 export TST_COUNT=0 # init identifier, 46 47 if [ -z "$LTPTMP" ] && [ -z "$TMPBASE" ] 48 then 49 LTPTMP=/tmp 50 else 51 LTPTMP=$TMPBASE 52 fi 53 if [ -z "$LTPBIN" ] && [ -z "$LTPROOT" ] 54 then 55 LTPBIN=./ 56 else 57 LTPBIN=$LTPROOT/testcases/bin 58 fi 59 60 61 $LTPBIN/tst_resm TINFO "INIT: Inititalizing tests." 62 63 which ln > $LTPTMP/tst_ln.err 2>&1 || RC=$? 64 if [ $RC -ne 0 ] 65 then 66 $LTPBIN/tst_brk TBROK $LTPTMP/tst_ln.err NULL \ 67 "Test #1: ln command does not exist. Reason:" 68 return $RC 69 fi 70 71 mkdir -p $LTPTMP/tst_ln.tmp > $LTPTMP/tst_ln.err 2>&1 || RC=$? 72 if [ $RC -ne 0 ] 73 then 74 $LTPBIN/tst_brk TBROK $LTPTMP/tst_ln.err NULL \ 75 "Test #1: failed creating temp directory. Reason:" 76 return $RC 77 fi 78 return $RC 79} 80 81# Function: creat_dirnfiles 82# 83# Description: - create N directories and fill each with M files 84# 85# Input: $1 - test number 86# $2 - number of directories to create 87# $3 - number of file to create in each directory 88# $4 - name of the base directory 89# 90# Return - zero on success 91# - non zero on failure. return value ($RC) from commands 92creat_dirnfiles() 93{ 94 numdirs=$2 # number of directories to create 95 numfiles=$3 # number of file to create in each directory 96 dirname=$4 # name of the base directory 97 dircnt=0 # index into number of dirs created in loop 98 fcnt=0 # index into number of files created in loop 99 RC=0 # return value from commands 100 101 $LTPBIN/tst_resm TINFO "Test #$1: Creating $numdirs directories." 102 $LTPBIN/tst_resm TINFO "Test #$1: filling each dir with $numfiles files". 103 while [ $dircnt -lt $numdirs ] 104 do 105 dirname=$dirname/d.$dircnt 106 mkdir -p $dirname > $LTPTMP/tst_ln.err 2>&1 || RC=$? 107 if [ $RC -ne 0 ] 108 then 109 $LTPBIN/tst_brk TBROK $LTPTMP/tst_ln.err NULL \ 110 "Test #$1: while creating $numdirs dirs. Reason" 111 return $RC 112 fi 113 fcnt=0 114 while [ $fcnt -lt $numfiles ] 115 do 116 touch $dirname/f.$fcnt 117 if [ $RC -ne 0 ] 118 then 119 $LTPBIN/tst_brk TBROK $LTPTMP/tst_ln.err NULL \ 120 "Test #$1: while creating $numdirs dirs. Reason" 121 return $RC 122 fi 123 fcnt=$(($fcnt+1)) 124 done 125 dircnt=$(($dircnt+1)) 126 done 127 return $RC 128} 129 130 131# Function: creat_expout 132# 133# Description: - create expected output 134# 135# Input: $1 - number of directories to create 136# $2 - number of file to create in each directory 137# $3 - name of the base directory 138# 139# Return - zero on success 140# - non zero on failure. return value ($RC) from commands 141creat_expout() 142{ 143 numdir=$1 # number of directories to create 144 numfile=$2 # number of file to create in each directory 145 dirname=$3 # name of the base directory 146 dircnt=0 # index into dir created in loop 147 fcnt=0 # index into files created in loop 148 RC=0 # return code from commands 149 150 echo "$dirname:" 1>>$LTPTMP/tst_ln.exp 151 echo "d.$dircnt" 1>>$LTPTMP/tst_ln.exp 152 while [ $dircnt -lt $numdirs ] 153 do 154 dirname=$dirname/d.$dircnt 155 dircnt=$(($dircnt+1)) 156 echo "$dirname:" 1>>$LTPTMP/tst_ln.exp 157 if [ $dircnt -lt $numdirs ] 158 then 159 echo "d.$dircnt" 1>>$LTPTMP/tst_ln.exp 160 fi 161 fcnt=0 162 while [ $fcnt -lt $numfiles ] 163 do 164 echo "f.$fcnt " 1>>$LTPTMP/tst_ln.exp 165 fcnt=$(($fcnt+1)) 166 done 167 printf "\n\n" 1>>$LTPTMP/tst_ln.exp 168 done 169} 170 171# Function: test01 172# 173# Description - Test #1: Test that ln -s will copy will copy directories 174# recursively. 175# - create N directories and fill each with M files. 176# - ln -s dir1 to dir2 177# - list contents of dir2 and save it to file - actual output 178# - create expected output from dir1 179# - compare expected output with actual output. 180# 181# Return - zero on success 182# - non zero on failure. return value from commands ($RC) 183 184test01() 185{ 186 RC=0 # Return value from commands. 187 export TCID=ln01 # Name of the test case. 188 export TST_COUNT=1 # Test number. 189 numdirs=10 190 numfiles=10 191 dircnt=0 192 fcnt=0 193 194 $LTPBIN/tst_resm TINFO \ 195 "Test #1: ln -s will make symbolic links instead of hard links" 196 197 creat_dirnfiles 1 $numdirs $numfiles $LTPTMP/tst_ln.tmp || RC=$? 198 if [ $RC -ne 0 ] 199 then 200 return $RC 201 fi 202 203 ln -s $LTPTMP/tst_ln.tmp $LTPTMP/tst_ln.tmp1 > $LTPTMP/tst_ln.err 2>&1 || RC=$? 204 if [ $RC -ne 0 ] 205 then 206 $LTPBIN/tst_res TFAIL $LTPTMP/tst_ln.err \ 207 "Test #1: ln -s failed, ln command returned $RC. Reason:" 208 return $RC 209 fi 210 211 $LTPBIN/tst_resm TINFO "Test #1: creating output file" 212 ls -R $LTPTMP/tst_ln.tmp1 > $LTPTMP/tst_ln.out 2>&1 213 214 $LTPBIN/tst_resm TINFO "Test #1: creating expected output file" 215 creat_expout $numdirs $numfiles $LTPTMP/tst_ln.tmp1 216 217 $LTPBIN/tst_resm TINFO \ 218 "Test #1: comparing expected out and actual output file" 219 diff -w -B $LTPTMP/tst_ln.out $LTPTMP/tst_ln.exp > $LTPTMP/tst_ln.err 2>&1 \ 220 || RC=$? 221 if [ $RC -ne 0 ] 222 then 223 $LTPBIN/tst_res TFAIL $LTPTMP/tst_ln.err \ 224 "Test #1: ln -s failed. Reason:" 225 else 226 $LTPBIN/tst_resm TINFO "Test #1: expected same as actual" 227 if [ -L $LTPTMP/tst_ln.tmp1 ] 228 then 229 $LTPBIN/tst_resm TPASS "Test #1: ln -s success" 230 else 231 $LTPBIN/tst_resm TFAIL "Test #1: $LTPTMP/tst_ln.tmp1 not a link" 232 return $(($RC+1)) 233 fi 234 fi 235 return $RC 236} 237 238 239# Function: main 240# 241# Description: - Execute all tests, report results. 242# 243# Exit: - zero on success 244# - non-zero on failure. 245 246 247TFAILCNT=0 # Set TFAILCNT to 0, increment on failure. 248RC=0 # Return code from tests. 249 250init || return $RC # Exit if initializing testcases fails. 251 252test01 || RC=$? 253if [ $RC -ne 0 ] 254then 255 TFAILCNT=$(($TFAILCNT+1)) 256fi 257 258 259rm -fr $LTPTMP/tst_ln.* 260 261exit $TFAILCNT 262