3
0

bbunzip_test.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/sh
  2. # Test that concatenated gz files are unpacking correctly.
  3. # It also tests that unpacking in general is working right.
  4. # Since zip code has many corner cases, run it for a few hours
  5. # to get a decent coverage (200000 tests or more).
  6. gzip="gzip"
  7. gunzip="../busybox gunzip"
  8. # Or the other way around:
  9. #gzip="../busybox gzip"
  10. #gunzip="gunzip"
  11. c=0
  12. i=$PID
  13. while true; do
  14. c=$((c+1))
  15. # RANDOM is not very random on some shells. Spice it up.
  16. # 100003 is prime
  17. len1=$(( (((RANDOM*RANDOM)^i) & 0x7ffffff) % 100003 ))
  18. i=$((i * 1664525 + 1013904223))
  19. len2=$(( (((RANDOM*RANDOM)^i) & 0x7ffffff) % 100003 ))
  20. # Just using urandom will make gzip use method 0 (store) -
  21. # not good for test coverage!
  22. cat /dev/urandom | while true; do read junk; echo "junk $c $i $junk"; done \
  23. | dd bs=$len1 count=1 >z1 2>/dev/null
  24. cat /dev/urandom | while true; do read junk; echo "junk $c $i $junk"; done \
  25. | dd bs=$len2 count=1 >z2 2>/dev/null
  26. $gzip <z1 >zz.gz
  27. $gzip <z2 >>zz.gz
  28. $gunzip -c zz.gz >z9 || {
  29. echo "Exitcode $?"
  30. exit
  31. }
  32. sum=`cat z1 z2 | md5sum`
  33. sum9=`md5sum <z9`
  34. test "$sum" == "$sum9" || {
  35. echo "md5sums don't match"
  36. exit
  37. }
  38. echo "Test $c ok: len1=$len1 len2=$len2 sum=$sum"
  39. sum=`cat z1 z2 z1 z2 | md5sum`
  40. rm z1.gz z2.gz 2>/dev/null
  41. $gzip z1
  42. $gzip z2
  43. cat z1.gz z2.gz z1.gz z2.gz >zz.gz
  44. $gunzip -c zz.gz >z9 || {
  45. echo "Exitcode $? (2)"
  46. exit
  47. }
  48. sum9=`md5sum <z9`
  49. test "$sum" == "$sum9" || {
  50. echo "md5sums don't match (1)"
  51. exit
  52. }
  53. echo "Test $c ok: len1=$len1 len2=$len2 sum=$sum (2)"
  54. done