subrata_modak | c864960 | 2008-08-27 11:29:55 +0000 | [diff] [blame] | 1 | #!/bin/sh |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 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 | ################################################################################ |
| 21 | # |
| 22 | # File: file_test.sh |
| 23 | # |
| 24 | # Description: This program tests the file command. The tests are aimed at |
| 25 | # testing if the file command can recognize some of the commonly |
| 26 | # used file formats like, tar, tar.gz, rpm, C, ASCII, ELF etc. |
| 27 | # |
| 28 | # Author: Manoj Iyer, manjo@mail.utexas.edu |
| 29 | # |
| 30 | # History: Dec 16 2002 - Created. - Manoj Iyer manjo@austin.ibm.com. |
| 31 | # Dec 17 2002 - Added. - GPL header and minor doc changes. |
iyermanoj | 4706bad | 2002-12-17 16:11:20 +0000 | [diff] [blame] | 32 | # If LTPTMP and LTPBIN are not exported set their |
| 33 | # values to /tmp and 'pwd' respectively. |
iyermanoj | 2a8f209 | 2002-12-17 16:42:06 +0000 | [diff] [blame] | 34 | # - Added. - exit status, if any test fails the test |
| 35 | # exits with non-zero value if all tests pass test |
| 36 | # exits with zero. |
iyermanoj | a06f878 | 2002-12-18 20:21:05 +0000 | [diff] [blame] | 37 | # Dec 18 2002 - Added. - Code to read environment variable |
| 38 | # LTPROOT and TMPBASE and set LTPTMP and LTPBIN |
| 39 | # accordingly. |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 40 | |
| 41 | |
subrata_modak | 1ae0595 | 2009-07-10 10:31:18 +0000 | [diff] [blame] | 42 | # |
| 43 | # Description of individual test cases |
| 44 | # ------------------------------------ |
| 45 | # |
| 46 | # Test01: Test if file command recognizes ASCII text files |
| 47 | # ------- |
| 48 | # 1) Write text to a known file |
| 49 | # 2) Use 'file' command to get the type of the known file |
| 50 | # Ex: file xyz.txt |
| 51 | # 3) Grep for the keyword "ASCII text" in the output of the |
| 52 | # 'file' command |
| 53 | # 4) Declare test as PASS if above step is successful else |
| 54 | # declare test as FAIL |
| 55 | # |
| 56 | # Test02: Test if file command can recognize bash shell script |
| 57 | # ------- |
| 58 | # 1) Write a small bash shell script to a known file |
| 59 | # 2) Use 'file' command to get the type of the known file |
| 60 | # Ex: file xyz.sh |
| 61 | # 3) Grep for the keyword "Bourne-Again shell script" in |
| 62 | # the output of the 'file' command |
| 63 | # 4) Declare test as PASS if above step is successful else |
| 64 | # declare test as FAIL |
| 65 | # |
| 66 | # Test03: Test if file command can recognize bash shell script |
| 67 | # ------- |
| 68 | # Similar test(as Test02) is performed with Korn shell script |
| 69 | # |
| 70 | # Test04: Test if file command can recognize C shell script |
| 71 | # ------- |
| 72 | # Similar test(as Test02) is performed with C shell script |
| 73 | # |
| 74 | # Test05: Test if file command can recognize C program text |
| 75 | # ------- |
| 76 | # Similar test(as Test02) is performed with C program text |
| 77 | # |
| 78 | # Test06: Test if file command can recognize ELF binay executables |
| 79 | # ------- |
| 80 | # 1) Grep for 'm68k' or 'sparc' or 'mips' or 'mipseb' or 'sh.eb' |
| 81 | # or 'powerpc' or 'ppc' or 's390' from the output of the command |
| 82 | # 'uname -m' |
| 83 | # 2) If the above step is successful, assign string 'MSB' to variable |
| 84 | # TARGET_ARCH else assign string 'LSB' |
| 85 | # 3) Write small C program to a known '.c' file |
| 86 | # 4) Compile it using "cc" |
| 87 | # Ex: cc xyz xyz.c |
| 88 | # 5) Use file command to get the type of the object file |
| 89 | # 6) Grep for the string "ELF .*-bit $TEST_ARCH executable, .*" |
| 90 | # in the output of the 'file' command |
| 91 | # 7) If the above command is successful, declare test as PASS |
| 92 | # else declare test as FAIL |
| 93 | # |
| 94 | # Test07: Test if file command can recognize tar files |
| 95 | # ------- |
| 96 | # 1) Write text to three different files |
| 97 | # 2) Archive the files using "tar" command |
| 98 | # Ex: tar -cf ... |
| 99 | # 3) Use 'file' command to get the type of the archive file |
| 100 | # Ex: file xyz.tar |
| 101 | # 4) Grep for the string "tar archive" from the output of |
| 102 | # the above 'file' command |
| 103 | # 5) Declare test as PASS, if the above step is successfull else |
| 104 | # declare test as FAIL |
| 105 | # |
| 106 | # Test08: Test if file command can tar zip files |
| 107 | # ------- |
| 108 | # 1) Write text to three different files |
| 109 | # 2) Archive the files using "tar" command |
| 110 | # Ex: tar -cf ... |
| 111 | # 3) Use 'gzip' command to zip tar files |
| 112 | # Ex: gzip -f xyz.tar |
| 113 | # 4) Use 'file' command to get the type of the archive file |
| 114 | # Ex: file xyz.tar.gz |
| 115 | # 5) Grep for the string "gzip compressed data, .*" from the above |
| 116 | # file commnand |
| 117 | # 6) Declare test as PASS, if the above step is successfull else |
| 118 | # declare test as FAIL |
| 119 | # |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 120 | |
subrata_modak | 1ae0595 | 2009-07-10 10:31:18 +0000 | [diff] [blame] | 121 | |
| 122 | export TST_TOTAL=10 # Number of tests in this testcase |
| 123 | |
robbiew | 87ea61f | 2003-12-08 16:07:38 +0000 | [diff] [blame] | 124 | if [ -z "$LTPTMP" -a -z "$TMPBASE" ] |
iyermanoj | 4706bad | 2002-12-17 16:11:20 +0000 | [diff] [blame] | 125 | then |
iyermanoj | a06f878 | 2002-12-18 20:21:05 +0000 | [diff] [blame] | 126 | LTPTMP=/tmp/ |
| 127 | else |
subrata_modak | 1ae0595 | 2009-07-10 10:31:18 +0000 | [diff] [blame] | 128 | LTPTMP=$TMPBASE |
iyermanoj | 4706bad | 2002-12-17 16:11:20 +0000 | [diff] [blame] | 129 | fi |
| 130 | |
subrata_modak | 1ae0595 | 2009-07-10 10:31:18 +0000 | [diff] [blame] | 131 | # 'LTPBIN' where actual test cases (test binaries) reside |
| 132 | # 'LTPROOT' where the actual LTP test suite resides |
robbiew | 87ea61f | 2003-12-08 16:07:38 +0000 | [diff] [blame] | 133 | if [ -z "$LTPBIN" -a -z "$LTPROOT" ] |
iyermanoj | 4706bad | 2002-12-17 16:11:20 +0000 | [diff] [blame] | 134 | then |
| 135 | LTPBIN=./ |
iyermanoj | a06f878 | 2002-12-18 20:21:05 +0000 | [diff] [blame] | 136 | else |
| 137 | LTPBIN=$LTPROOT/testcases/bin/ |
iyermanoj | 4706bad | 2002-12-17 16:11:20 +0000 | [diff] [blame] | 138 | fi |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 139 | |
| 140 | # set return code RC variable to 0, it will be set with a non-zero return code |
iyermanoj | 2a8f209 | 2002-12-17 16:42:06 +0000 | [diff] [blame] | 141 | # in case of error. Set TFAILCNT to 0, increment if there occures a failure. |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 142 | |
iyermanoj | 2a8f209 | 2002-12-17 16:42:06 +0000 | [diff] [blame] | 143 | TFAILCNT=0 |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 144 | RC=0 |
| 145 | |
| 146 | # TEST #1 |
| 147 | # Test if file command recognizes ASCII text files. |
| 148 | |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 149 | export TCID=file01 |
subrata_modak | 1ae0595 | 2009-07-10 10:31:18 +0000 | [diff] [blame] | 150 | export TST_COUNT=1 |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 151 | |
subrata_modak | 29e1375 | 2009-08-23 06:30:42 +0000 | [diff] [blame] | 152 | $LTPBIN/tst_resm TINFO "TEST #1: file command recogizes ASCII text files" |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 153 | |
| 154 | cat > $LTPTMP/test_file.txt <<EOF |
| 155 | This is a text file |
| 156 | to test file command. |
| 157 | EOF |
| 158 | |
| 159 | # Execute file command & check for output. |
| 160 | # Expected out put is the string "ASCII English text" |
| 161 | |
subrata_modak | 39552a0 | 2008-10-21 06:54:15 +0000 | [diff] [blame] | 162 | file $LTPTMP/test_file.txt > $LTPTMP/file.out 2>&1 |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 163 | |
robbiew | c6f5e76 | 2003-12-09 19:03:08 +0000 | [diff] [blame] | 164 | if [ $? -eq 0 ] |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 165 | then |
subrata_modak | 39552a0 | 2008-10-21 06:54:15 +0000 | [diff] [blame] | 166 | grep "ASCII text" $LTPTMP/file.out > /dev/null 2>&1 |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 167 | if [ $? -eq 0 ] |
| 168 | then |
| 169 | $LTPBIN/tst_resm TPASS "file: Recognised ASCII file correctly" |
robbiew | c6f5e76 | 2003-12-09 19:03:08 +0000 | [diff] [blame] | 170 | rm -f $LTPTMP/test_file.txt |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 171 | else |
| 172 | $LTPBIN/tst_res TFAIL $LTPTMP/file.out \ |
| 173 | "file: Failed to recognise ASCII file correctlyi. Reason:" |
robbiew | 46d7556 | 2003-04-07 21:30:25 +0000 | [diff] [blame] | 174 | TFAILCNT=$(( $TFAILCNT+1 )) |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 175 | fi |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 176 | else |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 177 | $LTPBIN/tst_res TFAIL $LTPTMP/file.out \ |
| 178 | "file: failed to recognize ASCII file correctly\t\t" |
robbiew | 46d7556 | 2003-04-07 21:30:25 +0000 | [diff] [blame] | 179 | TFAILCNT=$(( $TFAILCNT+1 )) |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 180 | fi |
| 181 | |
| 182 | # TEST #2 |
| 183 | # Test if file command can recognize bash shell script |
| 184 | |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 185 | export TCID=file02 |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 186 | export TST_COUNT=2 |
| 187 | |
| 188 | $LTPBIN/tst_resm TINFO "TEST #2: file command recognizes bash shell scripts" |
| 189 | |
| 190 | cat > $LTPTMP/bash_script.sh <<EOF |
| 191 | #! /bin/bash |
| 192 | |
| 193 | echo "this is a shell script" |
subrata_modak | 29e1375 | 2009-08-23 06:30:42 +0000 | [diff] [blame] | 194 | echo "used to test file command" |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 195 | |
| 196 | EOF |
| 197 | |
subrata_modak | 39552a0 | 2008-10-21 06:54:15 +0000 | [diff] [blame] | 198 | file $LTPTMP/bash_script.sh > $LTPTMP/file.out 2>&1 |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 199 | |
robbiew | c6f5e76 | 2003-12-09 19:03:08 +0000 | [diff] [blame] | 200 | if [ $? -eq 0 ] |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 201 | then |
subrata_modak | 39552a0 | 2008-10-21 06:54:15 +0000 | [diff] [blame] | 202 | grep "Bourne-Again shell script" $LTPTMP/file.out > /dev/null 2>&1 |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 203 | if [ $? -eq 0 ] |
| 204 | then |
| 205 | $LTPBIN/tst_resm TPASS "file: Recognised bash shell script correctly" |
robbiew | c6f5e76 | 2003-12-09 19:03:08 +0000 | [diff] [blame] | 206 | rm -f $LTPTMP/bash_script.sh |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 207 | else |
| 208 | $LTPBIN/tst_res TFAIL $LTPTMP/file.out \ |
| 209 | "file: Failed to recognise bash shell script. Reason" |
robbiew | 46d7556 | 2003-04-07 21:30:25 +0000 | [diff] [blame] | 210 | TFAILCNT=$(( $TFAILCNT+1 )) |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 211 | fi |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 212 | else |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 213 | $LTPBIN/tst_resm TFAIL "file: Failed to recognize bash shell script" |
robbiew | 46d7556 | 2003-04-07 21:30:25 +0000 | [diff] [blame] | 214 | TFAILCNT=$(( $TFAILCNT+1 )) |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 215 | fi |
| 216 | |
| 217 | # TEST #3 |
| 218 | # Test if file command can recognize korn shell script |
| 219 | |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 220 | export TCID=file03 |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 221 | export TST_COUNT=3 |
| 222 | |
| 223 | $LTPBIN/tst_resm TINFO "TEST #3: file command recognizes korn shell scripts" |
| 224 | |
| 225 | cat > $LTPTMP/ksh_script.sh <<EOF |
| 226 | #! /bin/ksh |
| 227 | |
| 228 | echo "this is a shell script" |
subrata_modak | 29e1375 | 2009-08-23 06:30:42 +0000 | [diff] [blame] | 229 | echo "used to test file command" |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 230 | |
| 231 | EOF |
| 232 | |
subrata_modak | 39552a0 | 2008-10-21 06:54:15 +0000 | [diff] [blame] | 233 | file $LTPTMP/ksh_script.sh > $LTPTMP/file.out 2>&1 |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 234 | |
robbiew | c6f5e76 | 2003-12-09 19:03:08 +0000 | [diff] [blame] | 235 | if [ $? -eq 0 ] |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 236 | then |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 237 | grep "Korn shell script" $LTPTMP/file.out 2>&1 1>/dev/null |
| 238 | if [ $? -eq 0 ] |
| 239 | then |
| 240 | $LTPBIN/tst_resm TPASS "file: recognised korn shell script" |
robbiew | c6f5e76 | 2003-12-09 19:03:08 +0000 | [diff] [blame] | 241 | rm -f $LTPTMP/ksh_script.sh |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 242 | else |
| 243 | $LTPBIN/tst_res TFAIL $LTPTMP/file.out \ |
| 244 | "file: Failed to recognise korn shell script. Reason:" |
robbiew | 46d7556 | 2003-04-07 21:30:25 +0000 | [diff] [blame] | 245 | TFAILCNT=$(( $TFAILCNT+1 )) |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 246 | fi |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 247 | else |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 248 | $LTPBIN/tst_resm TFAIL "File: Failed to recognize korn shell script" |
robbiew | 46d7556 | 2003-04-07 21:30:25 +0000 | [diff] [blame] | 249 | TFAILCNT=$(( $TFAILCNT+1 )) |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 250 | fi |
| 251 | |
| 252 | |
| 253 | # TEST #4 |
| 254 | # Test if file command can recognize C shell script |
| 255 | |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 256 | export TCID=file04 |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 257 | export TST_COUNT=4 |
| 258 | |
| 259 | $LTPBIN/tst_resm TINFO "TEST #4: file command recognizes C shell scripts" |
| 260 | |
| 261 | cat > $LTPTMP/C_script.sh <<EOF |
| 262 | #! /bin/csh |
| 263 | |
| 264 | echo "this is a shell script" |
subrata_modak | 29e1375 | 2009-08-23 06:30:42 +0000 | [diff] [blame] | 265 | echo "used to test file command" |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 266 | |
| 267 | EOF |
| 268 | |
subrata_modak | 39552a0 | 2008-10-21 06:54:15 +0000 | [diff] [blame] | 269 | file $LTPTMP/C_script.sh > $LTPTMP/file.out 2>&1 |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 270 | |
robbiew | c6f5e76 | 2003-12-09 19:03:08 +0000 | [diff] [blame] | 271 | if [ $? -eq 0 ] |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 272 | then |
subrata_modak | 39552a0 | 2008-10-21 06:54:15 +0000 | [diff] [blame] | 273 | grep "C shell script" $LTPTMP/file.out > /dev/null 2>&1 |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 274 | if [ $? -eq 0 ] |
| 275 | then |
| 276 | $LTPBIN/tst_resm TPASS "file: Recognised C shell script correctly" |
robbiew | c6f5e76 | 2003-12-09 19:03:08 +0000 | [diff] [blame] | 277 | rm -f $LTPTMP/C_script.sh |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 278 | else |
| 279 | $LTPBIN/tst_resm TFAIL $LTPTMP/file.out \ |
| 280 | "file: Failed to recognise C shell script correctly. Reason:" |
robbiew | 46d7556 | 2003-04-07 21:30:25 +0000 | [diff] [blame] | 281 | TFAILCNT=$(( $TFAILCNT+1 )) |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 282 | fi |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 283 | else |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 284 | $LTPBIN/tst_resm TFAIL "file: Failed to recognize C shell script" |
robbiew | 46d7556 | 2003-04-07 21:30:25 +0000 | [diff] [blame] | 285 | TFAILCNT=$(( $TFAILCNT+1 )) |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 286 | fi |
| 287 | |
| 288 | |
| 289 | # TEST #5 |
| 290 | # Test if file command can recognize C program text |
| 291 | |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 292 | export TCID=file05 |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 293 | export TST_COUNT=5 |
| 294 | |
| 295 | $LTPBIN/tst_resm TINFO "TEST #5: file command recognizes C programs text" |
| 296 | |
| 297 | cat > $LTPTMP/cprog.c <<EOF |
| 298 | #include <stdio.h> |
| 299 | |
| 300 | main() |
| 301 | { |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 302 | printf("Hello Hell\n"); |
| 303 | exit(0); |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 304 | } |
| 305 | EOF |
| 306 | |
subrata_modak | 39552a0 | 2008-10-21 06:54:15 +0000 | [diff] [blame] | 307 | file $LTPTMP/cprog.c > $LTPTMP/file.out 2>&1 |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 308 | |
robbiew | c6f5e76 | 2003-12-09 19:03:08 +0000 | [diff] [blame] | 309 | if [ $? -eq 0 ] |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 310 | then |
subrata_modak | 39552a0 | 2008-10-21 06:54:15 +0000 | [diff] [blame] | 311 | grep "ASCII C program text" $LTPTMP/file.out > /dev/null 2>&1 |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 312 | if [ $? -eq 0 ] |
| 313 | then |
| 314 | $LTPBIN/tst_resm TPASS "file: Recognised C program text correctly" |
robbiew | c6f5e76 | 2003-12-09 19:03:08 +0000 | [diff] [blame] | 315 | rm -f $LTPTMP/cprog.c |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 316 | else |
| 317 | $LTPBIN/tst_res TFAIL $LTPTMP/file.out \ |
| 318 | "file: Failed to Recognize C program text correctly. Reason:" |
robbiew | 46d7556 | 2003-04-07 21:30:25 +0000 | [diff] [blame] | 319 | TFAILCNT=$(( $TFAILCNT+1 )) |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 320 | |
| 321 | fi |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 322 | else |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 323 | $LTPBIN/tst_resm TFAIL "file: Failed to recognize C programi text" |
robbiew | 46d7556 | 2003-04-07 21:30:25 +0000 | [diff] [blame] | 324 | TFAILCNT=$(( $TFAILCNT+1 )) |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 325 | fi |
| 326 | |
| 327 | |
| 328 | # TEST #6 |
| 329 | # Test if file command can recognize ELF binay executables |
| 330 | |
mreed10 | 8308866 | 2007-02-28 18:01:32 +0000 | [diff] [blame] | 331 | # Check ppc architecture |
| 332 | TEST_ARCH=LSB # Assume the architecture is Intel |
mreed10 | 8308866 | 2007-02-28 18:01:32 +0000 | [diff] [blame] | 333 | |
subrata_modak | f8ee2c5 | 2008-10-21 09:01:48 +0000 | [diff] [blame] | 334 | if uname -m | |
| 335 | grep -qe '\(m68k\)\|\(sparc\)\|\(mips\b\)\|\(mipseb\)\|\(sh.eb\)' \ |
| 336 | -e '\(powerpc\)\|\(ppc\)\|\(s390\)'; then |
mreed10 | 8308866 | 2007-02-28 18:01:32 +0000 | [diff] [blame] | 337 | TEST_ARCH=MSB |
| 338 | fi |
| 339 | |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 340 | export TCID=file06 |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 341 | export TST_COUNT=6 |
| 342 | |
| 343 | $LTPBIN/tst_resm TINFO \ |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 344 | "TEST #6: file command recognizes ELF executables" |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 345 | |
| 346 | |
| 347 | cat > $LTPTMP/cprog.c <<EOF |
| 348 | #include <stdio.h> |
| 349 | |
| 350 | main() |
| 351 | { |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 352 | printf("Hello Hell\n"); |
| 353 | exit(0); |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 354 | } |
| 355 | EOF |
| 356 | |
subrata_modak | 39552a0 | 2008-10-21 06:54:15 +0000 | [diff] [blame] | 357 | cc -o $LTPTMP/cprog $LTPTMP/cprog.c > /dev/null 2>&1 |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 358 | |
subrata_modak | 39552a0 | 2008-10-21 06:54:15 +0000 | [diff] [blame] | 359 | file $LTPTMP/cprog > $LTPTMP/file.out 2>&1 |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 360 | |
robbiew | c6f5e76 | 2003-12-09 19:03:08 +0000 | [diff] [blame] | 361 | if [ $? -eq 0 ] |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 362 | then |
subrata_modak | 39552a0 | 2008-10-21 06:54:15 +0000 | [diff] [blame] | 363 | grep "ELF .*-bit $TEST_ARCH executable, .*" $LTPTMP/file.out > /dev/null 2>&1 |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 364 | if [ $? -eq 0 ] |
| 365 | then |
| 366 | $LTPBIN/tst_resm TPASS "file: Recognized ELF binary executable" |
robbiew | c6f5e76 | 2003-12-09 19:03:08 +0000 | [diff] [blame] | 367 | rm -f $LTPTMP/cprog.c $LTPTMP/cprog |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 368 | else |
| 369 | $LTPBIN/tst_res TFAIL $LTPTMP/file.out \ |
| 370 | "file: Failed to Recognize ELF binary executable. Reason:" |
robbiew | 46d7556 | 2003-04-07 21:30:25 +0000 | [diff] [blame] | 371 | TFAILCNT=$(( $TFAILCNT+1 )) |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 372 | fi |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 373 | else |
subrata_modak | c60b482 | 2008-10-21 06:51:42 +0000 | [diff] [blame] | 374 | $LTPBIN/tst_resm TFAIL "file: Failed to recognize ELF binary executable" |
robbiew | 46d7556 | 2003-04-07 21:30:25 +0000 | [diff] [blame] | 375 | TFAILCNT=$(( $TFAILCNT+1 )) |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 376 | fi |
| 377 | |
| 378 | |
| 379 | # TEST #7 |
| 380 | # Test if file command can recognize tar files |
| 381 | |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 382 | export TCID=file07 |
robbiew | 87ea61f | 2003-12-08 16:07:38 +0000 | [diff] [blame] | 383 | export TST_COUNT=7 |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 384 | |
| 385 | $LTPBIN/tst_resm TINFO "TEST #7: file command recognizes tar files." |
| 386 | |
| 387 | cat > $LTPTMP/file1 <<EOF |
| 388 | This is a simple test file |
| 389 | EOF |
| 390 | |
| 391 | cat > $LTPTMP/file2 <<EOF |
| 392 | This is a simple test file |
| 393 | EOF |
| 394 | |
| 395 | cat > $LTPTMP/file3 <<EOF |
| 396 | This is a simple test file |
| 397 | EOF |
| 398 | |
subrata_modak | 39552a0 | 2008-10-21 06:54:15 +0000 | [diff] [blame] | 399 | tar -cf $LTPTMP/files.tar $LTPTMP/file1 $LTPTMP/file2 $LTPTMP/file3 > /dev/null 2>&1 |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 400 | |
subrata_modak | 39552a0 | 2008-10-21 06:54:15 +0000 | [diff] [blame] | 401 | file $LTPTMP/files.tar > $LTPTMP/file.out 2>&1 |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 402 | |
robbiew | c6f5e76 | 2003-12-09 19:03:08 +0000 | [diff] [blame] | 403 | if [ $? -eq 0 ] |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 404 | then |
subrata_modak | 39552a0 | 2008-10-21 06:54:15 +0000 | [diff] [blame] | 405 | grep "tar archive" $LTPTMP/file.out > /dev/null 2>&1 |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 406 | if [ $? -eq 0 ] |
| 407 | then |
| 408 | $LTPBIN/tst_resm TPASS "file: Recognised tar files" |
robbiew | c6f5e76 | 2003-12-09 19:03:08 +0000 | [diff] [blame] | 409 | rm -f $LTPTMP/files.tar # save $LTPTMP/file[123] for next test case |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 410 | else |
| 411 | $LTPBIN/tst_res TFAIL $LTPTMP/file.out \ |
| 412 | "file: Failed to Recognize tar files. Reason:" |
robbiew | 46d7556 | 2003-04-07 21:30:25 +0000 | [diff] [blame] | 413 | TFAILCNT=$(( $TFAILCNT+1 )) |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 414 | fi |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 415 | else |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 416 | $LTPBIN/tst_resm TFAIL "file: Failed to recognize tar files." |
robbiew | 46d7556 | 2003-04-07 21:30:25 +0000 | [diff] [blame] | 417 | TFAILCNT=$(( $TFAILCNT+1 )) |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 418 | fi |
| 419 | |
| 420 | |
| 421 | # TEST #8 |
| 422 | # Test if file command can tar zip files |
| 423 | |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 424 | export TCID=file08 |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 425 | export TST_COUNT=8 |
| 426 | |
| 427 | $LTPBIN/tst_resm TINFO "TEST #8: file command recognizes tar zip files" |
| 428 | |
robbiew | 6583934 | 2003-11-26 19:30:28 +0000 | [diff] [blame] | 429 | tar cf $LTPTMP/files.tar $LTPTMP/file1 $LTPTMP/file2 $LTPTMP/file3 \ |
subrata_modak | 39552a0 | 2008-10-21 06:54:15 +0000 | [diff] [blame] | 430 | > $LTPTMP/file.out 2>&1 |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 431 | if [ $? -ne 0 ] |
| 432 | then |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 433 | $LTPBIN/tst_brk TBROK $LTPTMP/file.out NULL \ |
| 434 | "file: tar failed unexpectedly. Reason:" |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 435 | fi |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 436 | |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 437 | gzip -f $LTPTMP/files.tar |
| 438 | if [ $? -ne 0 ] |
| 439 | then |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 440 | $LTPBIN/tst_brk TBROK $LTPTMP/file.out NULL \ |
| 441 | "file: gzip failed unexpectedly. Reason:" |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 442 | fi |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 443 | |
subrata_modak | 39552a0 | 2008-10-21 06:54:15 +0000 | [diff] [blame] | 444 | file $LTPTMP/files.tar.gz > $LTPTMP/file.out 2>&1 |
robbiew | c6f5e76 | 2003-12-09 19:03:08 +0000 | [diff] [blame] | 445 | if [ $? -eq 0 ] |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 446 | then |
subrata_modak | 39552a0 | 2008-10-21 06:54:15 +0000 | [diff] [blame] | 447 | grep "gzip compressed data, .*" $LTPTMP/file.out > $LTPTMP/file1.out 2>&1 |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 448 | if [ $? -eq 0 ] |
| 449 | then |
| 450 | $LTPBIN/tst_resm TPASS "file: Recognised tar zip file" |
robbiew | c6f5e76 | 2003-12-09 19:03:08 +0000 | [diff] [blame] | 451 | rm -f $LTPTMP/files.tar.gz $LTPTMP/file1 $LTPTMP/file2 $LTPTMP/file3 |
| 452 | rm -f $LTPTMP/file1.out |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 453 | else |
| 454 | $LTPBIN/tst_brkm TBROK NULL \ |
| 455 | "expected string: gzip compressed data, deflated, |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 456 | original filename, \`files.tar'" |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 457 | $LTPBIN/tst_res TFAIL $LTPTMP/file.out \ |
| 458 | "file: Failed to Recognize tar zip. Reason:" |
robbiew | 46d7556 | 2003-04-07 21:30:25 +0000 | [diff] [blame] | 459 | TFAILCNT=$(( $TFAILCNT+1 )) |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 460 | fi |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 461 | else |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 462 | $LTPBIN/tst_brk TBROK $LTPTMP/file.out NULL \ |
| 463 | "file: Failed to recognize tar zip file. Reason:" |
robbiew | 46d7556 | 2003-04-07 21:30:25 +0000 | [diff] [blame] | 464 | TFAILCNT=$(( $TFAILCNT+1 )) |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 465 | fi |
| 466 | |
| 467 | |
| 468 | # TEST #9 |
| 469 | # Test if file command can recognize RPM files. |
| 470 | |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 471 | export TCID=file09 |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 472 | export TST_COUNT=9 |
| 473 | |
| 474 | $LTPBIN/tst_resm TINFO "TEST #9: file command recognizes RPM files" |
subrata_modak | 97544a1 | 2009-10-26 15:07:57 +0000 | [diff] [blame^] | 475 | type rpm > /dev/null 2>&1 |
subrata_modak | 2d01bce | 2009-08-23 05:57:38 +0000 | [diff] [blame] | 476 | if [ $? = 0 ]; then |
subrata_modak | 33463f8 | 2009-08-28 06:00:20 +0000 | [diff] [blame] | 477 | bDIR=$(rpm --eval "%{_topdir}") |
| 478 | bCMD=rpmbuild |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 479 | |
mreed10 | 16c180b | 2006-05-01 23:01:24 +0000 | [diff] [blame] | 480 | rpmversion=`rpm --version | awk -F ' ' '{print $3}' | cut -d '.' -f1 ` |
| 481 | |
| 482 | if [ "$rpmversion" -ge "4" ]; then |
| 483 | gpl="License: GPL" |
| 484 | else |
| 485 | gpl="Copyright: GPL" |
| 486 | fi |
| 487 | |
| 488 | |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 489 | cat > $LTPTMP/files.spec <<EOF |
| 490 | |
| 491 | Summary: Dummy package used to test file command |
| 492 | Name: cprog |
| 493 | Version: 0.0.7 |
| 494 | Release: 3 |
mreed10 | 16c180b | 2006-05-01 23:01:24 +0000 | [diff] [blame] | 495 | $gpl |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 496 | Group: LillB test case |
| 497 | Source: ./cprog.c |
| 498 | BuildRoot: /var/tmp/%{name}-buildroot |
| 499 | |
| 500 | %description |
| 501 | Dummy RPM package used for testing file command. |
| 502 | |
| 503 | %prep |
| 504 | %setup -q |
| 505 | |
| 506 | %build |
| 507 | make RPM_OPT_FLAGS="$RPM_OPT_FLAGS" |
| 508 | |
| 509 | %install |
| 510 | rm -rf $RPM_BUILD_ROOT |
| 511 | install -s -m 755 cprog $RPM_BUILD_ROOT/tmp |
| 512 | |
| 513 | %clean |
| 514 | rm -rf $RPM_BUILD_ROOT |
| 515 | |
| 516 | %files -f ./cprog.c |
| 517 | %defattr(-,root,root) |
| 518 | %doc README TODO COPYING ChangeLog |
| 519 | |
| 520 | EOF |
| 521 | |
robbiew | c6f5e76 | 2003-12-09 19:03:08 +0000 | [diff] [blame] | 522 | RC=0 |
robbiew | 6583934 | 2003-11-26 19:30:28 +0000 | [diff] [blame] | 523 | if [ -d $bDIR/SOURCES ] |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 524 | then |
subrata_modak | 39552a0 | 2008-10-21 06:54:15 +0000 | [diff] [blame] | 525 | echo "directory exists" > $LTPTMP/file.out 2>&1 |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 526 | else |
subrata_modak | 39552a0 | 2008-10-21 06:54:15 +0000 | [diff] [blame] | 527 | mkdir -p $bDIR/SOURCES/ > $LTPTMP/file.out 2>&1 || RC=$? |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 528 | fi |
| 529 | |
| 530 | if [ $RC -ne 0 ] |
| 531 | then |
subrata_modak | 8905033 | 2009-08-23 06:32:43 +0000 | [diff] [blame] | 532 | $LTPBIN/tst_brk TBROK $LTPTMP/file.out NULL "mkdir: broke. Reason:" |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 533 | fi |
| 534 | |
robbiew | c6f5e76 | 2003-12-09 19:03:08 +0000 | [diff] [blame] | 535 | cat > $bDIR/SOURCES/cprog.c <<EOF |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 536 | #include <stdio.h> |
| 537 | |
| 538 | main() |
| 539 | { |
| 540 | printf("Hello Hell\n"); |
| 541 | exit(0); |
| 542 | } |
| 543 | EOF |
robbiew | c6f5e76 | 2003-12-09 19:03:08 +0000 | [diff] [blame] | 544 | if [ $? -ne 0 ] |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 545 | then |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 546 | $LTPBIN/tst_brkm TBROK NULL "cat: failed to create test file cprog.c" |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 547 | fi |
| 548 | |
subrata_modak | 5412730 | 2009-05-22 06:30:17 +0000 | [diff] [blame] | 549 | $bCMD --define "_topdir $bDIR" -bs $LTPTMP/files.spec > $LTPTMP/file.out 2>&1 |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 550 | if [ $? -ne 0 ] |
| 551 | then |
subrata_modak | 8905033 | 2009-08-23 06:32:43 +0000 | [diff] [blame] | 552 | $LTPBIN/tst_brk TBROK $LTPTMP/file.out NULL "rpm command broke. Reason:" |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 553 | fi |
| 554 | |
subrata_modak | 39552a0 | 2008-10-21 06:54:15 +0000 | [diff] [blame] | 555 | file $bDIR/SRPMS/cprog-0.0.7-3.src.rpm > $LTPTMP/file.out 2>&1 |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 556 | |
robbiew | c6f5e76 | 2003-12-09 19:03:08 +0000 | [diff] [blame] | 557 | if [ $? -eq 0 ] |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 558 | then |
subrata_modak | 39552a0 | 2008-10-21 06:54:15 +0000 | [diff] [blame] | 559 | grep "RPM v3 src" $LTPTMP/file.out > /dev/null 2>&1 |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 560 | if [ $? -eq 0 ] |
| 561 | then |
| 562 | $LTPBIN/tst_resm TPASS "file: Recognised RPM file correctly" |
robbiew | c6f5e76 | 2003-12-09 19:03:08 +0000 | [diff] [blame] | 563 | rm -f $LTPTMP/files.spec |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 564 | else |
| 565 | $LTPBIN/tst_res TFAIL $LTPTMP/file.out \ |
| 566 | "file: Failed to Recognize RPM file. Reason:" |
robbiew | 46d7556 | 2003-04-07 21:30:25 +0000 | [diff] [blame] | 567 | TFAILCNT=$(( $TFAILCNT+1 )) |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 568 | |
| 569 | fi |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 570 | else |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 571 | $LTPBIN/tst_resm TFAIL "file: Failed to recognize RPM file" |
robbiew | 46d7556 | 2003-04-07 21:30:25 +0000 | [diff] [blame] | 572 | TFAILCNT=$(( $TFAILCNT+1 )) |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 573 | fi |
subrata_modak | 2d01bce | 2009-08-23 05:57:38 +0000 | [diff] [blame] | 574 | else |
| 575 | $LTPBIN/tst_resm TCONF "rpm not installed" |
| 576 | fi |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 577 | |
| 578 | |
| 579 | # TEST #10 |
subrata_modak | 7c4ec40 | 2008-02-27 14:38:32 +0000 | [diff] [blame] | 580 | # Test if file command can recognize kernel file |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 581 | |
| 582 | export TCID=file10 |
robbiew | 87ea61f | 2003-12-08 16:07:38 +0000 | [diff] [blame] | 583 | export TST_COUNT=10 |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 584 | |
subrata_modak | 2d01bce | 2009-08-23 05:57:38 +0000 | [diff] [blame] | 585 | KERNEL=vmlinu |
subrata_modak | 7c4ec40 | 2008-02-27 14:38:32 +0000 | [diff] [blame] | 586 | |
| 587 | $LTPBIN/tst_resm TINFO "TEST #10: file command recognizes $KERNEL file" |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 588 | |
subrata_modak | f8ee2c5 | 2008-10-21 09:01:48 +0000 | [diff] [blame] | 589 | # S390 Work around for vmlinuz file type |
| 590 | # Applesoft BASIC: |
| 591 | # |
| 592 | # This is incredibly sloppy, but will be true if the program was |
| 593 | # written at its usual memory location of 2048 and its first line |
| 594 | # number is less than 256. Yuck. |
| 595 | #0 belong&0xff00ff 0x80000 Applesoft BASIC program data |
| 596 | #>2 leshort x \b, first line number %d |
| 597 | |
robbiew | c6f5e76 | 2003-12-09 19:03:08 +0000 | [diff] [blame] | 598 | # Red Hat creates a user-mode-linux vmlinuz file (ends in .uml) - ignore it |
subrata_modak | 7c4ec40 | 2008-02-27 14:38:32 +0000 | [diff] [blame] | 599 | KERNFILE=$(find /boot ! -type l -name "$KERNEL*" | grep -v '.uml' | tail -1) |
subrata_modak | 39552a0 | 2008-10-21 06:54:15 +0000 | [diff] [blame] | 600 | file $KERNFILE > $LTPTMP/file.out 2>&1 |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 601 | |
robbiew | 87ea61f | 2003-12-08 16:07:38 +0000 | [diff] [blame] | 602 | if [ $? -eq 0 ] |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 603 | then |
robbiew | 87ea61f | 2003-12-08 16:07:38 +0000 | [diff] [blame] | 604 | ##### |
| 605 | # There are lots of possible strings to look for, given the number |
| 606 | # of different architectures... |
| 607 | ##### |
| 608 | MATCHED="" |
subrata_modak | 7c4ec40 | 2008-02-27 14:38:32 +0000 | [diff] [blame] | 609 | grep -iq "$TEST_ARCH" $LTPTMP/file.out && MATCHED="y" |
| 610 | grep -iq "kernel" $LTPTMP/file.out && MATCHED="y" |
| 611 | grep -iq "compressed data" $LTPTMP/file.out && MATCHED="y" |
| 612 | grep -iq "x86 boot sector" $LTPTMP/file.out && MATCHED="y" |
subrata_modak | f8ee2c5 | 2008-10-21 09:01:48 +0000 | [diff] [blame] | 613 | grep -iq "Applesoft BASIC" $LTPTMP/file.out && MATCHED="y" |
robbiew | 87ea61f | 2003-12-08 16:07:38 +0000 | [diff] [blame] | 614 | if [ -n "$MATCHED" ] |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 615 | then |
subrata_modak | 7c4ec40 | 2008-02-27 14:38:32 +0000 | [diff] [blame] | 616 | $LTPBIN/tst_resm TPASS "file: Recognised $KERNEL file correctly" |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 617 | else |
| 618 | $LTPBIN/tst_res TFAIL $LTPTMP/file.out \ |
subrata_modak | 7c4ec40 | 2008-02-27 14:38:32 +0000 | [diff] [blame] | 619 | "file: Failed to Recognize $KERNEL correctly. Reason:" |
robbiew | 46d7556 | 2003-04-07 21:30:25 +0000 | [diff] [blame] | 620 | TFAILCNT=$(( $TFAILCNT+1 )) |
iyermanoj | de6f398 | 2002-12-17 16:02:52 +0000 | [diff] [blame] | 621 | fi |
| 622 | else |
subrata_modak | 7c4ec40 | 2008-02-27 14:38:32 +0000 | [diff] [blame] | 623 | $LTPBIN/tst_resm TFAIL "file: Failed to recognize $KERNEL file" |
robbiew | 46d7556 | 2003-04-07 21:30:25 +0000 | [diff] [blame] | 624 | TFAILCNT=$(( $TFAILCNT+1 )) |
iyermanoj | fce3141 | 2002-12-17 15:37:29 +0000 | [diff] [blame] | 625 | fi |
iyermanoj | 2a8f209 | 2002-12-17 16:42:06 +0000 | [diff] [blame] | 626 | |
robbiew | c6f5e76 | 2003-12-09 19:03:08 +0000 | [diff] [blame] | 627 | rm -f $LTPTMP/file.out |
iyermanoj | 2a8f209 | 2002-12-17 16:42:06 +0000 | [diff] [blame] | 628 | exit $TFAILCNT |