Denis Vlasenko | d21f596 | 2007-10-05 15:27:03 +0000 | [diff] [blame^] | 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 | |
| 7 | gzip="gzip" |
| 8 | gunzip="../busybox gunzip" |
| 9 | # Or the other way around: |
| 10 | #gzip="../busybox gzip" |
| 11 | #gunzip="gunzip" |
| 12 | |
| 13 | c=0 |
| 14 | i=$PID |
| 15 | while true; do |
| 16 | c=$((c+1)) |
| 17 | |
| 18 | # RANDOM is not very random on some shells. Spice it up. |
| 19 | # 100003 is prime |
| 20 | len1=$(( (((RANDOM*RANDOM)^i) & 0x7ffffff) % 100003 )) |
| 21 | i=$((i * 1664525 + 1013904223)) |
| 22 | len2=$(( (((RANDOM*RANDOM)^i) & 0x7ffffff) % 100003 )) |
| 23 | |
| 24 | # Just using urandom will make gzip use method 0 (store) - |
| 25 | # not good for test coverage! |
| 26 | cat /dev/urandom | while true; do read junk; echo "junk $c $i $junk"; done \ |
| 27 | | dd bs=$len1 count=1 >z1 2>/dev/null |
| 28 | cat /dev/urandom | while true; do read junk; echo "junk $c $i $junk"; done \ |
| 29 | | dd bs=$len2 count=1 >z2 2>/dev/null |
| 30 | |
| 31 | $gzip <z1 >zz.gz |
| 32 | $gzip <z2 >>zz.gz |
| 33 | $gunzip -c zz.gz >z9 || { |
| 34 | echo "Exitcode $?" |
| 35 | exit |
| 36 | } |
| 37 | sum=`cat z1 z2 | md5sum` |
| 38 | sum9=`md5sum <z9` |
| 39 | test "$sum" == "$sum9" || { |
| 40 | echo "md5sums don't match" |
| 41 | exit |
| 42 | } |
| 43 | echo "Test $c ok: len1=$len1 len2=$len2 sum=$sum" |
| 44 | |
| 45 | sum=`cat z1 z2 z1 z2 | md5sum` |
| 46 | rm z1.gz z2.gz 2>/dev/null |
| 47 | $gzip z1 |
| 48 | $gzip z2 |
| 49 | cat z1.gz z2.gz z1.gz z2.gz >zz.gz |
| 50 | $gunzip -c zz.gz >z9 || { |
| 51 | echo "Exitcode $? (2)" |
| 52 | exit |
| 53 | } |
| 54 | sum9=`md5sum <z9` |
| 55 | test "$sum" == "$sum9" || { |
| 56 | echo "md5sums don't match (1)" |
| 57 | exit |
| 58 | } |
| 59 | |
| 60 | echo "Test $c ok: len1=$len1 len2=$len2 sum=$sum (2)" |
| 61 | done |