Lines Matching full:file
22 # File: file_test.sh
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.
46 # Test01: Test if file command recognizes ASCII text files
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
52 # 'file' command
56 # Test02: Test if file command can recognize bash shell script
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
62 # the output of the 'file' command
66 # Test03: Test if file command can recognize bash shell script
70 # Test04: Test if file command can recognize C shell script
74 # Test05: Test if file command can recognize C program text
78 # Test06: Test if file command can recognize ELF binary executables
82 # 2) Write small C program to a known '.c' file
85 # 4) Use file command to get the type of the object file
87 # in the output of the 'file' command
91 # Test07: Test if file command can recognize tar files
96 # 3) Use 'file' command to get the type of the archive file
97 # Ex: file xyz.tar
99 # the above 'file' command
103 # Test08: Test if file command can tar zip files
110 # 4) Use 'file' command to get the type of the archive file
111 # Ex: file xyz.tar.gz
113 # file commnand
144 # Test if file command recognizes ASCII text files.
149 $LTPBIN/tst_resm TINFO "TEST #1: file command recogizes ASCII text files"
152 This is a text file
153 to test file command.
156 # Execute file command & check for output.
159 file $LTPTMP/test_file.txt > $LTPTMP/file.out 2>&1
163 grep -q "ASCII text" $LTPTMP/file.out
166 $LTPBIN/tst_resm TPASS "file: Recognised ASCII file correctly"
169 $LTPBIN/tst_res TFAIL $LTPTMP/file.out \
170 "file: Failed to recognise ASCII file correctlyi. Reason:"
174 $LTPBIN/tst_res TFAIL $LTPTMP/file.out \
175 "file: failed to recognize ASCII file correctly\t\t"
180 # Test if file command can recognize bash shell script
185 $LTPBIN/tst_resm TINFO "TEST #2: file command recognizes bash shell scripts"
191 echo "used to test file command"
195 file $LTPTMP/bash_script.sh > $LTPTMP/file.out 2>&1
199 grep -q "Bourne-Again shell script" $LTPTMP/file.out
202 $LTPBIN/tst_resm TPASS "file: Recognised bash shell script correctly"
205 $LTPBIN/tst_res TFAIL $LTPTMP/file.out \
206 "file: Failed to recognise bash shell script. Reason"
210 $LTPBIN/tst_resm TFAIL "file: Failed to recognize bash shell script"
215 # Test if file command can recognize korn shell script
220 $LTPBIN/tst_resm TINFO "TEST #3: file command recognizes korn shell scripts"
226 echo "used to test file command"
230 file $LTPTMP/ksh_script.sh > $LTPTMP/file.out 2>&1
234 grep -q "Korn shell script" $LTPTMP/file.out
237 $LTPBIN/tst_resm TPASS "file: recognised korn shell script"
240 $LTPBIN/tst_res TFAIL $LTPTMP/file.out \
241 "file: Failed to recognise korn shell script. Reason:"
245 $LTPBIN/tst_resm TFAIL "File: Failed to recognize korn shell script"
251 # Test if file command can recognize C shell script
256 $LTPBIN/tst_resm TINFO "TEST #4: file command recognizes C shell scripts"
262 echo "used to test file command"
266 file $LTPTMP/C_script.sh > $LTPTMP/file.out 2>&1
270 grep -q "C shell script" $LTPTMP/file.out
273 $LTPBIN/tst_resm TPASS "file: Recognised C shell script correctly"
276 $LTPBIN/tst_resm TFAIL $LTPTMP/file.out \
277 "file: Failed to recognise C shell script correctly. Reason:"
281 $LTPBIN/tst_resm TFAIL "file: Failed to recognize C shell script"
287 # Test if file command can recognize C program text
292 $LTPBIN/tst_resm TINFO "TEST #5: file command recognizes C programs text"
304 file $LTPTMP/cprog.c > $LTPTMP/file.out 2>&1
308 grep -q "ASCII C program text" $LTPTMP/file.out
311 $LTPBIN/tst_resm TPASS "file: Recognised C program text correctly"
314 grep -q "C source, ASCII text" $LTPTMP/file.out
317 $LTPBIN/tst_resm TPASS "file: Recognised C program text correctly"
320 $LTPBIN/tst_res TFAIL $LTPTMP/file.out \
321 "file: Failed to Recognize C program text correctly. Reason:"
326 $LTPBIN/tst_resm TFAIL "file: Failed to recognize C programi text"
332 # Test if file command can recognize ELF binary executables
338 "TEST #6: file command recognizes ELF executables"
350 $LTPBIN/tst_resm TFAIL "file: Could not determine CPU endianness"
366 file $LTPTMP/cprog > $LTPTMP/file.out 2>&1
370 grep -q "ELF .*-bit $TEST_ARCH executable, .*" $LTPTMP/file.out
373 $LTPBIN/tst_resm TPASS "file: Recognized ELF binary executable"
376 $LTPBIN/tst_res TFAIL $LTPTMP/file.out \
377 "file: Failed to Recognize ELF binary executable. Reason:"
381 $LTPBIN/tst_resm TFAIL "file: Failed to recognize ELF binary executable"
387 # Test if file command can recognize tar files
392 $LTPBIN/tst_resm TINFO "TEST #7: file command recognizes tar files."
395 This is a simple test file
399 This is a simple test file
403 This is a simple test file
408 file $LTPTMP/files.tar > $LTPTMP/file.out 2>&1
412 grep -q "tar archive" $LTPTMP/file.out
415 $LTPBIN/tst_resm TPASS "file: Recognised tar files"
416 rm -f $LTPTMP/files.tar # save $LTPTMP/file[123] for next test case
418 $LTPBIN/tst_res TFAIL $LTPTMP/file.out \
419 "file: Failed to Recognize tar files. Reason:"
423 $LTPBIN/tst_resm TFAIL "file: Failed to recognize tar files."
429 # Test if file command can tar zip files
434 $LTPBIN/tst_resm TINFO "TEST #8: file command recognizes tar zip files"
437 > $LTPTMP/file.out 2>&1
440 $LTPBIN/tst_brk TBROK $LTPTMP/file.out NULL \
441 "file: tar failed unexpectedly. Reason:"
447 $LTPBIN/tst_brk TBROK $LTPTMP/file.out NULL \
448 "file: gzip failed unexpectedly. Reason:"
451 file $LTPTMP/files.tar.gz > $LTPTMP/file.out 2>&1
454 grep "gzip compressed data, .*" $LTPTMP/file.out > $LTPTMP/file1.out 2>&1
457 $LTPBIN/tst_resm TPASS "file: Recognised tar zip file"
464 $LTPBIN/tst_res TFAIL $LTPTMP/file.out \
465 "file: Failed to Recognize tar zip. Reason:"
469 $LTPBIN/tst_brk TBROK $LTPTMP/file.out NULL \
470 "file: Failed to recognize tar zip file. Reason:"
476 # Test if file command can recognize RPM files.
481 $LTPBIN/tst_resm TINFO "TEST #9: file command recognizes RPM files"
498 Summary: Dummy package used to test file command
508 Dummy RPM package used for testing file command.
532 echo "directory exists" > $LTPTMP/file.out 2>&1
534 mkdir -p $bDIR/SOURCES/ > $LTPTMP/file.out 2>&1 || RC=$?
539 $LTPBIN/tst_brk TBROK $LTPTMP/file.out NULL "mkdir: broke. Reason:"
553 $LTPBIN/tst_brkm TBROK NULL "cat: failed to create test file cprog.c"
556 $bCMD --define "_topdir $bDIR" -bs $LTPTMP/files.spec > $LTPTMP/file.out 2>&1
559 $LTPBIN/tst_brk TBROK $LTPTMP/file.out NULL "rpm command broke. Reason:"
562 file $bDIR/SRPMS/cprog-0.0.7-3.src.rpm > $LTPTMP/file.out 2>&1
566 grep -qE "RPM v3(\.0)? src" $LTPTMP/file.out
569 $LTPBIN/tst_resm TPASS "file: Recognised RPM file correctly"
572 $LTPBIN/tst_res TFAIL $LTPTMP/file.out \
573 "file: Failed to Recognize RPM file. Reason:"
578 $LTPBIN/tst_resm TFAIL "file: Failed to recognize RPM file"
587 # Test if file command can recognize kernel file
594 $LTPBIN/tst_resm TINFO "TEST #10: file command recognizes $KERNEL file"
596 # S390 Work around for vmlinuz file type
605 # Red Hat creates a user-mode-linux vmlinuz file (ends in .uml) - ignore it
607 file $KERNFILE > $LTPTMP/file.out 2>&1
616 grep -iq "$TEST_ARCH" $LTPTMP/file.out && MATCHED="y"
617 grep -iq "linux" $LTPTMP/file.out && MATCHED="y"
618 grep -iq "kernel" $LTPTMP/file.out && MATCHED="y"
619 grep -iq "compressed data" $LTPTMP/file.out && MATCHED="y"
620 grep -iq "x86 boot sector" $LTPTMP/file.out && MATCHED="y"
621 grep -iq "Applesoft BASIC" $LTPTMP/file.out && MATCHED="y"
624 $LTPBIN/tst_resm TPASS "file: Recognised $KERNEL file correctly"
626 $LTPBIN/tst_res TFAIL $LTPTMP/file.out \
627 "file: Failed to Recognize $KERNEL correctly. Reason:"
631 $LTPBIN/tst_resm TFAIL "file: Failed to recognize $KERNEL file"
635 rm -f $LTPTMP/file.out