Home | History | Annotate | Download | only in tar
      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:        tar_test.sh
     23 #
     24 # Description: Tests tar command. These tests test the basic functioanlity of
     25 #              tape archive command.
     26 #
     27 # Author:      Manoj Iyer, manjo (at] mail.utexas.edu
     28 #
     29 # History:     Dec 17 2002 - Created - Manoj Iyer.
     30 #              Dec 18 2002 - Added code to read the LTPROOT and TMPBASE
     31 #              variables to set LTPBIN and LTPTMP variables
     32 #
     33 
     34 export TST_TOTAL=1
     35 
     36 if [ -z "$LTPTMP" -a -z "$TMPBASE" ]; then
     37     LTPTMP=/tmp
     38 else
     39     LTPTMP=$TMPBASE
     40 fi
     41 
     42 if [ -z "$LTPBIN" -a -z "$LTPROOT" ]; then
     43     LTPBIN=./bin
     44 else
     45     LTPBIN=$LTPROOT/testcases/bin
     46 fi
     47 
     48 # set return code RC variable to 0, it will be set with a non-zero return code
     49 # in case of error. Set TFAILCNT to 0, increment if there occures a failure.
     50 #
     51 
     52 TFAILCNT=0
     53 RC=0
     54 RC1=0
     55 RC2=0
     56 RC3=0
     57 
     58 # Test #1
     59 # Test if tar command can create a tar file 'tar cvf <tar filename> <list of
     60 # files>'
     61 
     62 export TCID=tar01
     63 export TST_COUNT=1
     64 
     65 $LTPBIN/tst_resm TINFO \
     66     "TEST #1: tar command with cvf options creates an archive file"
     67 
     68 touch $LTPTMP/tar_tstf1 $LTPTMP/tar_tstf2 $LTPTMP/tar_tstf3
     69 
     70 tar cvf $LTPTMP/tar_tstf.tar $LTPTMP/tar_tstf1 \
     71     $LTPTMP/tar_tstf2 $LTPTMP/tar_tstf3 > $LTPTMP/tar_tst.out 2>&1 || RC=$?
     72 
     73 if [ $RC -eq 0 ]; then
     74     if [ -f $LTPTMP/tar_tstf.tar ]; then
     75 	$LTPBIN/tst_resm TPASS "tar: cvf option created a tar file."
     76     else
     77 	$LTPBIN/tst_res TFAIL $LTPTMP/tar_tst.out \
     78 	    "tar: cvf option failed to create archive.  Reason"
     79 	TFAILCNT=$(( $TFAILCNT+1 ))
     80     fi
     81 else
     82     $LTPBIN/tst_brk TBROK $LTPTMP/file.out NULL \
     83 	"tar: command failed. Reason:"
     84     TFAILCNT=$(( $TFAILCNT+1 ))
     85 fi
     86 
     87 
     88 # Test #2
     89 # Test if tar command with tvf option will list all the files in the archive.
     90 
     91 export TCID=tar02
     92 export TST_COUNT=2
     93 
     94 $LTPBIN/tst_resm TINFO \
     95     "TEST #2: tar command with tvf options lists all files in an archive file"
     96 
     97 if [ -f $LTPTMP/tar_tstf.tar ]; then
     98     echo "$LTPTMP/tar_tstf.tar exists" > /dev/null 2>&1
     99 else
    100     touch $LTPTMP/tar_tstf1 $LTPTMP/tar_tstf2 $LTPTMP/tar_tstf3
    101     tar cvf $LTPTMP/tar_tstf.tar $LTPTMP/tar_tstf1 \
    102 	$LTPTMP/tar_tstf2 $LTPTMP/tar_tstf3 > $LTPTMP/tar_tst.out 2>&1 || RC=$?
    103 
    104     if [ $RC -eq 0 ]; then
    105 	if [ -f $LTPTMP/tar_tstf.tar ]; then
    106 	    echo "tar file created" > /dev/null 2>&1
    107 	else
    108 	    $LTPBIN/tst_brk TBROK $LTPTMP/tar_tst.out NULL \
    109 		"tar: cvf option failed to create archive.  Reason"
    110 	    TFAILCNT=$(( $TFAILCNT+1 ))
    111 	fi
    112     else
    113 	$LTPBIN/tst_brk TBROK $LTPTMP/file.out NULL \
    114 	    "tar: command failed. Reason:"
    115 	TFAILCNT=$(( $TFAILCNT+1 ))
    116     fi
    117 fi
    118 
    119 tar -tvf $LTPTMP/tar_tstf.tar > /$LTPTMP/tar_tst.out 2>&1 || RC=$?
    120 
    121 if [ $RC -eq 0 ]; then
    122     grep  "tar_tstf1" $LTPTMP/tar_tst.out > $LTPTMP/tar_tst2.out 2>&1 || RC1=$?
    123     grep  "tar_tstf2" $LTPTMP/tar_tst.out 2>&1 1>>$LTPTMP/tar_tst2.out || RC2=$?
    124     grep  "tar_tstf3" $LTPTMP/tar_tst.out 2>&1 1>>$LTPTMP/tar_tst2.out || RC3=$?
    125 
    126     if [ $RC1 -eq 0 -a $RC2 -eq 0 -a $RC3 -eq 0 ]; then
    127 	$LTPBIN/tst_resm TPASS 	"tar: tvf option listed all its contents"
    128     else
    129 	$LTPBIN/tst_res TFAIL $LTPTMP/tar_tst.out \
    130 	    "tar: failed to list all the files in the archive. Reason:"
    131 	TFAILCNT=$(( $TFAILCNT+1 ))
    132     fi
    133 fi
    134 
    135 
    136 # Test #3
    137 # Test if tar command can create a compressed tar file 'tar cvf <tar filename>
    138 # <list of files>'
    139 
    140 export TCID=tar03
    141 export TST_COUNT=3
    142 
    143 $LTPBIN/tst_resm TINFO \
    144     "TEST #3: tar command with zcvf options creates an compressed archive file"
    145 
    146 touch $LTPTMP/tar_tstf1 $LTPTMP/tar_tstf2 $LTPTMP/tar_tstf3
    147 
    148 tar zcvf $LTPTMP/tar_tstf.tgz $LTPTMP/tar_tstf1 \
    149     $LTPTMP/tar_tstf2 $LTPTMP/tar_tstf3 > $LTPTMP/tar_tst.out 2>&1 || RC=$?
    150 
    151 if [ $RC -eq 0 ]; then
    152     if [ -f $LTPTMP/tar_tstf.tgz ]; then
    153 	file $LTPTMP/tar_tstf.tgz | grep "gzip compressed data" \
    154             > $LTPTMP/tar_tst.out 2>&1 || RC=$?
    155 	if [ $RC -eq 0 ]; then
    156 	    $LTPBIN/tst_resm TPASS \
    157 		"tar: zcvf option created a compressed tar file."
    158 	else
    159 	    $LTPBIN/tst_res TFAIL $LTPTMP/tar_tst.out \
    160 		"tar: zcvf option failed to create a compressed tar file. Reason:"
    161 	    TFAILCNT=$(( $TFAILCNT+1 ))
    162 	fi
    163     else
    164 	$LTPBIN/tst_brk TBROK $LTPTMP/tar_tst.out NULL \
    165 	    "tar: cvf option failed to create compressed archive.  Reason"
    166 	TFAILCNT=$(( $TFAILCNT+1 ))
    167     fi
    168 else
    169     $LTPBIN/tst_brk TBROK $LTPTMP/file.out NULL \
    170 	"tar: command failed while creating compressed archive. Reason:"
    171     TFAILCNT=$(( $TFAILCNT+1 ))
    172 fi
    173 
    174 
    175 # Test #4
    176 # Test if tar command with xvf can untar an archive file created by tar.
    177 
    178 export TCID=tar04
    179 export TST_COUNT=4
    180 
    181 $LTPBIN/tst_resm TINFO \
    182     "TEST #4: tar command with xvf options extracts files from an archive file"
    183 
    184 if [ -f $LTPTMP/tar_tstf.tar ]; then
    185     echo "tar file exists" > /dev/null 2>&1
    186 else
    187     touch $LTPTMP/tar_tstf1 $LTPTMP/tar_tstf2 $LTPTMP/tar_tstf3
    188 
    189     tar cvf $LTPTMP/tar_tstf.tar $LTPTMP/tar_tstf1 \
    190 	$LTPTMP/tar_tstf2 $LTPTMP/tar_tstf3 > $LTPTMP/tar_tst.out 2>&1 || RC=$?
    191 
    192     if [ $RC -eq 0 ]; then
    193 	if [ -f $LTPTMP/tar_tstf.tar ];	then
    194 	    $LTPBIN/tst_resm TINFO "tar: cvf option created a tar file."
    195 	else
    196 	    $LTPBIN/tst_brk TBROK $LTPTMP/tar_tst.out NULL \
    197 		"tar: cvf option failed to create archive.  Reason"
    198 	    TFAILCNT=$(( $TFAILCNT+1 ))
    199 	fi
    200     else
    201 	$LTPBIN/tst_brk TBROK $LTPTMP/file.out NULL \
    202 	    "tar: command failed. Reason:"
    203 	TFAILCNT=$(( $TFAILCNT+1 ))
    204     fi
    205 fi
    206 
    207 tar xvf $LTPTMP/tar_tstf.tar > $LTPTMP/tar_tst.out 2>&1 || RC=$?
    208 
    209 if [ $? -eq 0 ]; then
    210    if [ -d $LTPTMP -a -f $LTPTMP/tar_tstf1 -a -f $LTPTMP/tar_tstf2 -a -f $LTPTMP/tar_tstf3 ]; then
    211        $LTPBIN/tst_resm TPASS "tar: xvf option extracted the archive file."
    212    else
    213        $LTPBIN/tst_res TFAIL $LTPTMP/tar_tst.out \
    214 	   "tar: xvf option failed to extract. Reason:"
    215        TFAILCNT=$(( $TFAILCNT+1 ))
    216    fi
    217 else
    218     $LTPBIN/tst_brk TBROK $LTPTMP/tar_tst.out NULL \
    219 	"tar: command failed while extracting files. Reason"
    220     TFAILCNT=$(( $TFAILCNT+1 ))
    221 fi
    222 
    223 rm -f $LTPTMP/tar_tst*
    224 
    225 # Test #5
    226 # Test if tar command can extract a compressed tar file 'tar zxvf
    227 # <tar filename> <list of files>'
    228 
    229 export TCID=tar05
    230 export TST_COUNT=5
    231 
    232 $LTPBIN/tst_resm TINFO \
    233 	"TEST #5: tar command with zxvf options extracts a compressed archive file"
    234 
    235 if [ -f tar_tstf.tgz ]; then
    236     echo "compressed archive file already exists" > /dev/null 2>&1
    237 else
    238 
    239     touch $LTPTMP/tar_tstf1 $LTPTMP/tar_tstf2 $LTPTMP/tar_tstf3
    240     tar zcvf $LTPTMP/tar_tstf.tgz $LTPTMP/tar_tstf1 \
    241 	$LTPTMP/tar_tstf2 $LTPTMP/tar_tstf3 > $LTPTMP/tar_tst.out 2>&1 || RC=$?
    242 
    243 	if [ $RC -eq 0 ]; then
    244 	    if [ -f $LTPTMP/tar_tstf.tgz ]; then
    245 		file $LTPTMP/tar_tstf.tgz | grep "gzip compressed data" \
    246 		    > $LTPTMP/tar_tst.out 2>&1 || RC=$?
    247 		if [ $RC -eq 0 ]; then
    248 		    $LTPBIN/tst_resm TINFO  \
    249 			"tar: zcvf option created a compressed tar file."
    250 		else
    251 		    $LTPBIN/tst_brk TBROK $LTPTMP/tar_tst.out NULL \
    252 			"tar: zcvf option failed to create a compressed tar file. Reason:"
    253 		    TFAILCNT=$(( $TFAILCNT+1 ))
    254 		fi
    255 	    else
    256 		$LTPBIN/tst_brk TBROK $LTPTMP/tar_tst.out NULL \
    257 		    "tar: cvf option failed to create compressed archive.  Reason"
    258 		TFAILCNT=$(( $TFAILCNT+1 ))
    259 	    fi
    260 	else
    261 	    $LTPBIN/tst_brk TBROK $LTPTMP/tar_tst.out NULL \
    262 		"tar: command failed while creating compressed archive. Reason:"
    263 	    TFAILCNT=$(( $TFAILCNT+1 ))
    264 	fi
    265 fi
    266 
    267 tar zxvf $LTPTMP/tar_tstf.tgz > $LTPTMP/tar_tst.out 2>&1 || RC=$?
    268 
    269 if [ $? -eq 0 ]; then
    270     if [ -d $LTPTMP -a -f $LTPTMP/tar_tstf1 -a -f $LTPTMP/tar_tstf2 -a -f $LTPTMP/tar_tstf3 ]; then
    271 	$LTPBIN/tst_resm TPASS \
    272 	    "tar: zxvf option extracted the compressed archive file."
    273     else
    274 	$LTPBIN/tst_res TFAIL $LTPTMP/tar_tst.out \
    275 	    "tar: zxvf option failed to extract compressed archive. Reason:"
    276 	TFAILCNT=$(( $TFAILCNT+1 ))
    277     fi
    278 else
    279     $LTPBIN/tst_brk TBROK $LTPTMP/tar_tst.out NULL \
    280 	"tar: command failed while extracting compressed archive files. Reason"
    281     TFAILCNT=$(( $TFAILCNT+1 ))
    282 fi
    283 
    284 rm -f $LTPTMP/tar_tst*
    285 
    286 exit $TFAILCNT
    287