Fix the creation of the dumpdir directory in stress_floppy Makefile
[ltp-debian.git] / testcases / commands / cpio / cpio_tests.sh
blob0221aa7d01f45dbccb0c8b02caa53016a18ee5bf
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ##
19 ## ##
20 ################################################################################
23 # File : cpio_test.sh
25 # Description: Test basic functionality of cpio command
26 # - Test #1: cpio -o can create an archive.
28 # Author: Manoj Iyer, manjo@mail.utexas.edu
30 # History: Jan 30 2003 - Created - Manoj Iyer.
32 # Function: init
34 # Description: - Check if command cpio is available.
35 # - Create temprary directory, and temporary files.
36 # - Initialize environment variables.
38 # Return - zero on success
39 # - non zero on failure. return value from commands ($RC)
40 init()
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,
48 if [ -z "$LTPTMP" -a -z "$TMPBASE" ]
49 then
50 LTPTMP=/tmp
51 else
52 LTPTMP=$TMPBASE
55 LTPBIN=$LTPTOOLS
57 $LTPBIN/tst_resm TINFO "INIT: Inititalizing tests."
59 which cpio > $LTPTMP/tst_cpio.err 2>&1 || RC=$?
60 if [ $RC -ne 0 ]
61 then
62 $LTPBIN/tst_brk TBROK $LTPTMP/tst_cpio.err NULL \
63 "Test #1: cpio command does not exist. Reason:"
64 return $RC
67 mkdir -p $LTPTMP/tst_cpio.tmp > $LTPTMP/tst_cpio.err 2>&1 || RC=$?
68 if [ $RC -ne 0 ]
69 then
70 $LTPBIN/tst_brk TBROK $LTPTMP/tst_cpio.err NULL \
71 "Test #1: failed creating temp directory. Reason:"
72 return $RC
75 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
77 touch $LTPTMP/tst_cpio.tmp/$i > $LTPTMP/tst_cpio.err 2>&1 || RC=$?
78 if [ $RC -ne 0 ]
79 then
80 $LTPBIN/tst_brk TBROK $LTPTMP/tst_cpio.err NULL \
81 "Test #1: failed creating temp directory. Reason:"
82 return $RC
84 done
85 return $RC
88 # Function: clean
90 # Description - Remove all temorary directories and file.s
92 # Return - NONE
93 clean()
95 export TCID=cpio # this is the init function.
96 export TST_COUNT=0 # init identifier,
98 $LTPBIN/tst_resm TINFO "CLEAN cleaning up before return"
99 rm -fr $LTPTMP/tst_cpio* > /dev/null 2>&1
100 return
104 # Function: test01
106 # Description - Test #1: Test that cpio -o will create a cpio archive.
108 # Return - zero on success
109 # - non zero on failure. return value from commands ($RC)
111 test01()
113 RC=0 # Return value from commands.
114 export TCID=cpio01 # Name of the test case.
115 export TST_COUNT=1 # Test number.
117 $LTPBIN/tst_resm TINFO "Test #1: cpio -o will create an archive."
119 find $LTPTMP/tst_cpio.tmp/ -type f | cpio -o > $LTPTMP/tst_cpio.out \
120 2>$LTPTMP/tst_cpio.err || RC=$?
121 if [ $RC -ne 0 ]
122 then
123 $LTPBIN/tst_res TFAIL $LTPTMP/tst_cpio.err \
124 "Test #1: creating cpio archive failed. Reason:"
125 return $RC
126 else
127 if [ -f $LTPTMP/tst_cpio.out ]
128 then
129 file $LTPTMP/tst_cpio.out > $LTPTMP/tst_cpio.err 2>&1 || RC=$?
130 if [ $? -ne 0 ]
131 then
132 $LTPBIN/tst_res TFAIL $LTPTMP/tst_cpio.err \
133 "Test #1: bad output, not cpio format. Reason:"
134 return $RC
136 else
137 $LTPBIN/tst_resm TFAIL "Test #1: did not create cpio file."
138 return $RC
141 return $RC
145 # Function: main
147 # Description: - Execute all tests, report results.
149 # Exit: - zero on success
150 # - non-zero on failure.
153 TFAILCNT=0 # Set TFAILCNT to 0, increment on failure.
154 RC=0 # Return code from tests.
156 init || exit $RC # Exit if initializing testcases fails.
158 test01 || RC=$? # Test #1
159 if [ $RC -eq 0 ]
160 then
161 $LTPBIN/tst_resm TPASS "Test #1: cpio created an archive"
162 else
163 TFAILCNT=$(( $TFAILCNT+1 ))
166 clean # clean up before returning
168 exit $TFAILCNT