]> icculus.org git repositories - icculus/xz.git/blob - tests/test_compress.sh
Added test_compress.sh and bunch of files needed by it.
[icculus/xz.git] / tests / test_compress.sh
1 #!/bin/sh
2
3 ###############################################################################
4 #
5 #   Copyright (C) 2008 Lasse Collin
6 #
7 #   This library is free software; you can redistribute it and/or
8 #   modify it under the terms of the GNU Lesser General Public
9 #   License as published by the Free Software Foundation; either
10 #   version 2.1 of the License, or (at your option) any later version.
11 #
12 #   This library is distributed in the hope that it will be useful,
13 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 #   Lesser General Public License for more details.
16 #
17 ###############################################################################
18
19 # Find out if our shell supports functions.
20 eval 'unset foo ; foo() { return 42; } ; foo'
21 if test $? != 42 ; then
22         echo "/bin/sh doesn't support functions, skipping this test."
23         (exit 77)
24         exit 77
25 fi
26
27 test_lzma() {
28         ################
29         # Non-streamed #
30         ################
31
32         if $LZMA -c "$@" "$FILE" > tmp_compressed; then
33                 :
34         else
35                 echo "Non-streamed compressing failed: $* $FILE"
36                 (exit 1)
37                 exit 1
38         fi
39
40         if $LZMA -cd tmp_compressed > tmp_uncompressed ; then
41                 :
42         else
43                 echo "Decoding of non-streamed file failed: $* $FILE"
44                 (exit 1)
45                 exit 1
46         fi
47
48         if cmp tmp_uncompressed "$FILE" ; then
49                 :
50         else
51                 echo "Decoded non-streamed file does not match the original: $* $FILE"
52                 (exit 1)
53                 exit 1
54         fi
55
56         if $LZMADEC tmp_compressed > tmp_uncompressed ; then
57                 :
58         else
59                 echo "Decoding of non-streamed file failed: $* $FILE"
60                 (exit 1)
61                 exit 1
62         fi
63
64         if cmp tmp_uncompressed "$FILE" ; then
65                 :
66         else
67                 echo "Decoded non-streamed file does not match the original: $* $FILE"
68                 (exit 1)
69                 exit 1
70         fi
71
72         ############
73         # Streamed #
74         ############
75
76         if $LZMA -c "$@" < "$FILE" > tmp_compressed; then
77                 :
78         else
79                 echo "Streamed compressing failed: $* $FILE"
80                 (exit 1)
81                 exit 1
82         fi
83
84         if $LZMA -cd < tmp_compressed > tmp_uncompressed ; then
85                 :
86         else
87                 echo "Decoding of streamed file failed: $* $FILE"
88                 (exit 1)
89                 exit 1
90         fi
91
92         if cmp tmp_uncompressed "$FILE" ; then
93                 :
94         else
95                 echo "Decoded streamed file does not match the original: $* $FILE"
96                 (exit 1)
97                 exit 1
98         fi
99
100         if $LZMADEC < tmp_compressed > tmp_uncompressed ; then
101                 :
102         else
103                 echo "Decoding of streamed file failed: $* $FILE"
104                 (exit 1)
105                 exit 1
106         fi
107
108         if cmp tmp_uncompressed "$FILE" ; then
109                 :
110         else
111                 echo "Decoded streamed file does not match the original: $* $FILE"
112                 (exit 1)
113                 exit 1
114         fi
115
116         # Show progress:
117         echo . | tr -d '\n\r'
118 }
119
120 LZMA="../src/lzma/lzma --memory=15Mi --threads=1"
121 LZMADEC="../src/lzmadec/lzmadec --memory=4Mi"
122 unset LZMA_OPT
123
124 # Create the required input files.
125 if ./create_compress_files ; then
126         :
127 else
128         rm -f compress_*
129         echo "Failed to create files to test compression."
130         (exit 1)
131         exit 1
132 fi
133
134 # Remove temporary now (in case they are something weird), and on exit.
135 rm -f tmp_compressed tmp_uncompressed
136 trap 'rm -f tmp_compressed tmp_uncompressed' 0
137
138 # Encode and decode each file with various filter configurations.
139 # This takes quite a bit of time.
140 echo "test_compress.sh:"
141 for FILE in compress_generated_* "$srcdir"/compress_prepared_*
142 do
143         MSG=`echo "x$FILE" | sed 's,^x,,; s,^.*/,,; s,^compress_,,'`
144         echo "  $MSG" | tr -d '\n\r'
145
146         # Don't test with empty arguments; it breaks some ancient
147         # proprietary /bin/sh versions due to $@ used in test_lzma().
148         test_lzma -1
149         test_lzma -2
150         test_lzma -3
151         test_lzma -4
152
153         for ARGS in \
154                 --copy \
155                 --subblock \
156                 --subblock=size=1 \
157                 --subblock=size=1,rle=1 \
158                 --subblock=size=1,rle=4 \
159                 --subblock=size=4,rle=4 \
160                 --subblock=size=8,rle=4 \
161                 --subblock=size=8,rle=8 \
162                 --subblock=size=4096,rle=12 \
163                 --delta=distance=1 \
164                 --delta=distance=4 \
165                 --delta=distance=256 \
166                 --x86 \
167                 --powerpc \
168                 --ia64 \
169                 --arm \
170                 --armthumb \
171                 --sparc
172         do
173                 test_lzma $ARGS
174                 test_lzma --subblock $ARGS
175                 test_lzma $ARGS --subblock
176                 test_lzma --subblock $ARGS --subblock
177         done
178
179         echo
180 done
181
182 (exit 0)
183 exit 0