Home | History | Annotate | Download | only in cpio
      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 #
     23 # File :        cpio_test.sh
     24 #
     25 # Description:  Test basic functionality of cpio command
     26 #				- Test #1:  cpio -o can create an archive.
     27 #
     28 # Author:       Manoj Iyer, manjo (at] mail.utexas.edu
     29 #
     30 # History:      Jan 30 2003 - Created - Manoj Iyer.
     31 #
     32 # Function:		init
     33 #
     34 # Description:	- Check if command cpio is available.
     35 #               - Create temprary directory, and temporary files.
     36 #               - Initialize environment variables.
     37 #
     38 # Return		- zero on success
     39 #               - non zero on failure. return value from commands ($RC)
     40 init()
     41 {
     42 
     43 	RC=0				# Return code from commands.
     44 	export TST_TOTAL=1	# total numner of tests in this file.
     45 	export TCID=cpio	# this is the init function.
     46 	export TST_COUNT=0	# init identifier,
     47 
     48 	if [ -z "$LTPTMP" -a -z "$TMPBASE" ]
     49 	then
     50 		LTPTMP=/tmp
     51 	else
     52 		LTPTMP=$TMPBASE
     53 	fi
     54 	if [ -z "$LTPBIN" -a -z "$LTPROOT" ]
     55 	then
     56 		LTPBIN=./
     57 	else
     58 		LTPBIN=$LTPROOT/testcases/bin
     59 	fi
     60 
     61 
     62 	$LTPBIN/tst_resm TINFO "INIT: Inititalizing tests."
     63 
     64 	which cpio > $LTPTMP/tst_cpio.err 2>&1 || RC=$?
     65 	if [ $RC -ne 0 ]
     66 	then
     67 		$LTPBIN/tst_brk TBROK $LTPTMP/tst_cpio.err NULL \
     68 			"Test #1: cpio command does not exist. Reason:"
     69 		return $RC
     70 	fi
     71 
     72 	mkdir -p $LTPTMP/tst_cpio.tmp > $LTPTMP/tst_cpio.err 2>&1 || RC=$?
     73 	if [ $RC -ne 0 ]
     74 	then
     75 		$LTPBIN/tst_brk TBROK $LTPTMP/tst_cpio.err NULL \
     76 			"Test #1: failed creating temp directory. Reason:"
     77 		return $RC
     78 	fi
     79 
     80 	for i in a b c d e f g h i j k l m n o p q r s t u v w x y z
     81 	do
     82 		touch $LTPTMP/tst_cpio.tmp/$i > $LTPTMP/tst_cpio.err 2>&1 || RC=$?
     83 		if [ $RC -ne 0 ]
     84 		then
     85 			$LTPBIN/tst_brk TBROK $LTPTMP/tst_cpio.err NULL \
     86 				"Test #1: failed creating temp directory. Reason:"
     87 			return $RC
     88 		fi
     89 	done
     90 	return $RC
     91 }
     92 
     93 # Function:		clean
     94 #
     95 # Description	- Remove all temorary directories and file.s
     96 #
     97 # Return		- NONE
     98 clean()
     99 {
    100 	export TCID=cpio	# this is the init function.
    101 	export TST_COUNT=0	# init identifier,
    102 
    103 	$LTPBIN/tst_resm TINFO "CLEAN cleaning up before return"
    104 	rm -fr $LTPTMP/tst_cpio* > /dev/null 2>&1
    105 	return
    106 }
    107 
    108 
    109 # Function:		test01
    110 #
    111 # Description	- Test #1: Test that cpio -o will create a cpio archive.
    112 #
    113 # Return		- zero on success
    114 #               - non zero on failure. return value from commands ($RC)
    115 
    116 test01()
    117 {
    118 	RC=0				# Return value from commands.
    119 	export TCID=cpio01	# Name of the test case.
    120 	export TST_COUNT=1	# Test number.
    121 
    122 	$LTPBIN/tst_resm TINFO "Test #1: cpio -o will create an archive."
    123 
    124 	find  $LTPTMP/tst_cpio.tmp/ -type f | cpio -o > $LTPTMP/tst_cpio.out \
    125 		2>$LTPTMP/tst_cpio.err || RC=$?
    126 	if [ $RC -ne 0 ]
    127 	then
    128 		 $LTPBIN/tst_res TFAIL $LTPTMP/tst_cpio.err \
    129 			"Test #1: creating cpio archive failed. Reason:"
    130 		return $RC
    131 	else
    132 		if [ -f $LTPTMP/tst_cpio.out ]
    133 		then
    134 			file $LTPTMP/tst_cpio.out > $LTPTMP/tst_cpio.err 2>&1 || RC=$?
    135 			if [ $? -ne 0 ]
    136 			then
    137 				$LTPBIN/tst_res TFAIL $LTPTMP/tst_cpio.err	\
    138 				"Test #1: bad output, not cpio format. Reason:"
    139 				return $RC
    140 			fi
    141 		else
    142 			 $LTPBIN/tst_resm TFAIL "Test #1: did not create cpio file."
    143 			 return $RC
    144 		fi
    145 	fi
    146 	return $RC
    147 }
    148 
    149 
    150 # Function:		main
    151 #
    152 # Description:	- Execute all tests, report results.
    153 #
    154 # Exit:			- zero on success
    155 # 				- non-zero on failure.
    156 
    157 
    158 TFAILCNT=0			# Set TFAILCNT to 0, increment on failure.
    159 RC=0				# Return code from tests.
    160 
    161 init || exit $RC	# Exit if initializing testcases fails.
    162 
    163 test01 || RC=$?		# Test #1
    164 if [ $RC -eq 0 ]
    165 then
    166 	$LTPBIN/tst_resm TPASS "Test #1: cpio created an archive"
    167 else
    168 		 TFAILCNT=$(( $TFAILCNT+1 ))
    169 fi
    170 
    171 clean				# clean up before returning
    172 
    173 exit $TFAILCNT
    174