]> icculus.org git repositories - icculus/xz.git/blob - tests/test_compress.sh
Tweak the compression presets -0 .. -5.
[icculus/xz.git] / tests / test_compress.sh
1 #!/bin/sh
2
3 ###############################################################################
4 #
5 # Author: Lasse Collin
6 #
7 # This file has been put into the public domain.
8 # You can do whatever you want with this file.
9 #
10 ###############################################################################
11
12 # Find out if our shell supports functions.
13 eval 'unset foo ; foo() { return 42; } ; foo'
14 if test $? != 42 ; then
15         echo "/bin/sh doesn't support functions, skipping this test."
16         (exit 77)
17         exit 77
18 fi
19
20 test_xz() {
21         if $XZ -c "$@" "$FILE" > tmp_compressed; then
22                 :
23         else
24                 echo "Compressing failed: $* $FILE"
25                 (exit 1)
26                 exit 1
27         fi
28
29         if $XZ -cd tmp_compressed > tmp_uncompressed ; then
30                 :
31         else
32                 echo "Decoding failed: $* $FILE"
33                 (exit 1)
34                 exit 1
35         fi
36
37         if cmp tmp_uncompressed "$FILE" ; then
38                 :
39         else
40                 echo "Decoded file does not match the original: $* $FILE"
41                 (exit 1)
42                 exit 1
43         fi
44
45         if $XZDEC tmp_compressed > tmp_uncompressed ; then
46                 :
47         else
48                 echo "Decoding failed: $* $FILE"
49                 (exit 1)
50                 exit 1
51         fi
52
53         if cmp tmp_uncompressed "$FILE" ; then
54                 :
55         else
56                 echo "Decoded file does not match the original: $* $FILE"
57                 (exit 1)
58                 exit 1
59         fi
60
61         # Show progress:
62         echo . | tr -d '\n\r'
63 }
64
65 XZ="../src/xz/xz --memlimit-compress=28MiB --memlimit-decompress=4MiB \
66                 --no-adjust --threads=1 --check=crc64"
67 XZDEC="../src/xzdec/xzdec" # No memory usage limiter available
68
69 # Create the required input files.
70 if ./create_compress_files ; then
71         :
72 else
73         rm -f compress_*
74         echo "Failed to create files to test compression."
75         (exit 1)
76         exit 1
77 fi
78
79 # Remove temporary now (in case they are something weird), and on exit.
80 rm -f tmp_compressed tmp_uncompressed
81 trap 'rm -f tmp_compressed tmp_uncompressed' 0
82
83 # Encode and decode each file with various filter configurations.
84 # This takes quite a bit of time.
85 echo "test_compress.sh:"
86 for FILE in compress_generated_* "$srcdir"/compress_prepared_*
87 do
88         MSG=`echo "x$FILE" | sed 's,^x,,; s,^.*/,,; s,^compress_,,'`
89         echo "  $MSG" | tr -d '\n\r'
90
91         # Don't test with empty arguments; it breaks some ancient
92         # proprietary /bin/sh versions due to $@ used in test_xz().
93         test_xz -1
94         test_xz -2
95         test_xz -3
96         test_xz -4
97
98         # Disabled until Subblock format is stable.
99 #               --subblock \
100 #               --subblock=size=1 \
101 #               --subblock=size=1,rle=1 \
102 #               --subblock=size=1,rle=4 \
103 #               --subblock=size=4,rle=4 \
104 #               --subblock=size=8,rle=4 \
105 #               --subblock=size=8,rle=8 \
106 #               --subblock=size=4096,rle=12 \
107 #
108         for ARGS in \
109                 --delta=dist=1 \
110                 --delta=dist=4 \
111                 --delta=dist=256 \
112                 --x86 \
113                 --powerpc \
114                 --ia64 \
115                 --arm \
116                 --armthumb \
117                 --sparc
118         do
119                 test_xz $ARGS --lzma2=dict=64KiB,nice=32,mode=fast
120
121                 # Disabled until Subblock format is stable.
122                 # test_xz --subblock $ARGS --lzma2=dict=64KiB,nice=32,mode=fast
123         done
124
125         echo
126 done
127
128 (exit 0)
129 exit 0