gzip_tests.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0-or-later
  3. # Copyright (c) International Business Machines Corp., 2001
  4. # Author: Manoj Iyer <manjo@mail.utexas.edu>
  5. #
  6. # Test basic functionality of gzip and gunzip command
  7. # Test #1: Test that gzip -r will travel directories and
  8. # compress all the files available.
  9. #
  10. # Test #2: Test that gunzip -r will travel directories and
  11. # uncompress all the files available.
  12. TST_CNT=2
  13. TST_TESTFUNC=test
  14. TST_NEEDS_TMPDIR=1
  15. TST_NEEDS_CMDS="gzip gunzip"
  16. . tst_test.sh
  17. creat_dirnfiles()
  18. {
  19. local numdirs=$2
  20. local numfiles=$3
  21. local dirname=$4
  22. local dircnt=0
  23. local fcnt=0
  24. tst_res TINFO "Test #$1: Creating $numdirs directories"
  25. tst_res TINFO "Test #$1: filling each dir with $numfiles files"
  26. while [ $dircnt -lt $numdirs ]; do
  27. dirname=$dirname/d.$dircnt
  28. ROD_SILENT mkdir -p $dirname
  29. fcnt=0
  30. while [ $fcnt -lt $numfiles ]; do
  31. ROD_SILENT touch $dirname/f.$fcnt
  32. fcnt=$(($fcnt+1))
  33. done
  34. dircnt=$(($dircnt+1))
  35. done
  36. }
  37. creat_expout()
  38. {
  39. local numdir=$1
  40. local numfile=$2
  41. local dirname=$3
  42. local ext=$4
  43. local dircnt=0
  44. local fcnt=0
  45. echo "$dirname:" 1> tst_gzip.exp
  46. echo "d.$dircnt" 1>> tst_gzip.exp
  47. while [ $dircnt -lt $numdirs ]; do
  48. dirname=$dirname/d.$dircnt
  49. dircnt=$(($dircnt+1))
  50. echo "$dirname:" 1>> tst_gzip.exp
  51. if [ $dircnt -lt $numdirs ]; then
  52. echo "d.$dircnt" 1>> tst_gzip.exp
  53. fi
  54. fcnt=0
  55. while [ $fcnt -lt $numfiles ]; do
  56. echo "f.$fcnt$ext " 1>> tst_gzip.exp
  57. fcnt=$(($fcnt+1))
  58. done
  59. printf "\n\n" 1>> tst_gzip.exp
  60. done
  61. }
  62. test1()
  63. {
  64. numdirs=10
  65. numfiles=10
  66. dircnt=0
  67. fcnt=0
  68. ROD_SILENT mkdir tst_gzip.tmp
  69. tst_res TINFO "Test #1: gzip -r will recursively compress contents" \
  70. "of directory"
  71. creat_dirnfiles 1 $numdirs $numfiles tst_gzip.tmp
  72. gzip -r tst_gzip.tmp > tst_gzip.err 2>&1
  73. if [ $? -ne 0 ]; then
  74. cat tst_gzip.err
  75. tst_brk TFAIL "Test #1: gzip -r failed"
  76. fi
  77. tst_res TINFO "Test #1: creating output file"
  78. ls -R tst_gzip.tmp > tst_gzip.out 2>&1
  79. tst_res TINFO "Test #1: creating expected output file"
  80. creat_expout $numdirs $numfiles tst_gzip.tmp .gz
  81. diff -w -B tst_gzip.out tst_gzip.exp > tst_gzip.err 2>&1
  82. if [ $? -ne 0 ]; then
  83. cat tst_gzip.err
  84. tst_res TFAIL "Test #1: gzip failed"
  85. else
  86. tst_res TPASS "Test #1: gzip -r success"
  87. fi
  88. ROD_SILENT rm -rf tst_gzip.tmp/
  89. }
  90. test2()
  91. {
  92. numdirs=10
  93. numfiles=10
  94. dircnt=0
  95. fcnt=0
  96. ROD_SILENT mkdir tst_gzip.tmp
  97. tst_res TINFO "Test #2: gunzip -r will recursively uncompress" \
  98. "contents of directory"
  99. creat_dirnfiles 2 $numdirs $numfiles tst_gzip.tmp
  100. gzip -r tst_gzip.tmp > tst_gzip.err 2>&1
  101. if [ $? -ne 0 ]; then
  102. cat tst_gzip.err
  103. tst_brk TBROK "Test #2: compressing directory tst_gzip.tmp" \
  104. "failed"
  105. fi
  106. gunzip -r tst_gzip.tmp > tst_gzip.err 2>&1
  107. if [ $? -ne 0 ]; then
  108. cat tst_gzip.err
  109. tst_brk TBROK "Test #2: uncompressing directory" \
  110. " tst_gzip.tmp failed"
  111. fi
  112. tst_res TINFO "Test #2: creating output file"
  113. ls -R tst_gzip.tmp > tst_gzip.out 2>&1
  114. tst_res TINFO "Test #2: creating expected output file"
  115. creat_expout $numdirs $numfiles tst_gzip.tmp
  116. tst_res TINFO "Test #2: comparing expected out and actual output file"
  117. diff -w -B tst_gzip.out tst_gzip.exp > tst_gzip.err 2>&1
  118. if [ $? -ne 0 ]; then
  119. cat tst_gzip.err
  120. tst_res TFAIL "Test #2: gunzip failed"
  121. else
  122. tst_res TPASS "Test #2: gunzip -r success"
  123. fi
  124. ROD_SILENT rm -rf tst_gzip.tmp/
  125. }
  126. tst_run