aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archival/bbunzip_test.sh61
-rw-r--r--archival/bbunzip_test2.sh10
-rw-r--r--archival/bbunzip_test3.sh23
3 files changed, 94 insertions, 0 deletions
diff --git a/archival/bbunzip_test.sh b/archival/bbunzip_test.sh
new file mode 100644
index 000000000..b8e31bf97
--- /dev/null
+++ b/archival/bbunzip_test.sh
@@ -0,0 +1,61 @@
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
7gzip="gzip"
8gunzip="../busybox gunzip"
9# Or the other way around:
10#gzip="../busybox gzip"
11#gunzip="gunzip"
12
13c=0
14i=$PID
15while 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)"
61done
diff --git a/archival/bbunzip_test2.sh b/archival/bbunzip_test2.sh
new file mode 100644
index 000000000..5b7e83e13
--- /dev/null
+++ b/archival/bbunzip_test2.sh
@@ -0,0 +1,10 @@
1#!/bin/sh
2# Leak test for gunzip. Watch top for growing process size.
3
4# Just using urandom will make gzip use method 0 (store) -
5# not good for test coverage!
6
7cat /dev/urandom \
8| while true; do read junk; echo "junk $RANDOM $junk"; done \
9| ../busybox gzip \
10| ../busybox gunzip -c >/dev/null
diff --git a/archival/bbunzip_test3.sh b/archival/bbunzip_test3.sh
new file mode 100644
index 000000000..2dc4afda1
--- /dev/null
+++ b/archival/bbunzip_test3.sh
@@ -0,0 +1,23 @@
1#!/bin/sh
2# Leak test for gunzip. Watch top for growing process size.
3# In this case we look for leaks in "concatenated .gz" code -
4# we feed gunzip with a stream of .gz files.
5
6i=$PID
7c=0
8while true; do
9 c=$((c + 1))
10 echo "Block# $c" >&2
11 # RANDOM is not very random on some shells. Spice it up.
12 i=$((i * 1664525 + 1013904223))
13 # 100003 is prime
14 len=$(( (((RANDOM*RANDOM)^i) & 0x7ffffff) % 100003 ))
15
16 # Just using urandom will make gzip use method 0 (store) -
17 # not good for test coverage!
18 cat /dev/urandom \
19 | while true; do read junk; echo "junk $c $i $junk"; done \
20 | dd bs=$len count=1 2>/dev/null \
21 | gzip >xxx.gz
22 cat xxx.gz xxx.gz xxx.gz xxx.gz xxx.gz xxx.gz xxx.gz xxx.gz
23done | ../busybox gunzip -c >/dev/null