]> icculus.org git repositories - icculus/xz.git/blob - tests/test_compress.sh
Initial changes to change the suffix of the new format to .xz.
[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         if $LZMA -c "$@" "$FILE" > tmp_compressed; then
29                 :
30         else
31                 echo "Compressing failed: $* $FILE"
32                 (exit 1)
33                 exit 1
34         fi
35
36         if $LZMA -cd tmp_compressed > tmp_uncompressed ; then
37                 :
38         else
39                 echo "Decoding failed: $* $FILE"
40                 (exit 1)
41                 exit 1
42         fi
43
44         if cmp tmp_uncompressed "$FILE" ; then
45                 :
46         else
47                 echo "Decoded file does not match the original: $* $FILE"
48                 (exit 1)
49                 exit 1
50         fi
51
52         if $LZMADEC tmp_compressed > tmp_uncompressed ; then
53                 :
54         else
55                 echo "Decoding failed: $* $FILE"
56                 (exit 1)
57                 exit 1
58         fi
59
60         if cmp tmp_uncompressed "$FILE" ; then
61                 :
62         else
63                 echo "Decoded file does not match the original: $* $FILE"
64                 (exit 1)
65                 exit 1
66         fi
67
68         # Show progress:
69         echo . | tr -d '\n\r'
70 }
71
72 # TODO: Remove --format=xz once the command name has been changed.
73 LZMA="../src/lzma/lzma --memory=15Mi --threads=1 --format=xz"
74 LZMADEC="../src/lzmadec/lzmadec --memory=4Mi"
75 unset LZMA_OPT
76
77 # Create the required input files.
78 if ./create_compress_files ; then
79         :
80 else
81         rm -f compress_*
82         echo "Failed to create files to test compression."
83         (exit 1)
84         exit 1
85 fi
86
87 # Remove temporary now (in case they are something weird), and on exit.
88 rm -f tmp_compressed tmp_uncompressed
89 trap 'rm -f tmp_compressed tmp_uncompressed' 0
90
91 # Encode and decode each file with various filter configurations.
92 # This takes quite a bit of time.
93 echo "test_compress.sh:"
94 for FILE in compress_generated_* "$srcdir"/compress_prepared_*
95 do
96         MSG=`echo "x$FILE" | sed 's,^x,,; s,^.*/,,; s,^compress_,,'`
97         echo "  $MSG" | tr -d '\n\r'
98
99         # Don't test with empty arguments; it breaks some ancient
100         # proprietary /bin/sh versions due to $@ used in test_lzma().
101         test_lzma -1
102         test_lzma -2
103         test_lzma -3
104         test_lzma -4
105
106         for ARGS in \
107                 --subblock \
108                 --subblock=size=1 \
109                 --subblock=size=1,rle=1 \
110                 --subblock=size=1,rle=4 \
111                 --subblock=size=4,rle=4 \
112                 --subblock=size=8,rle=4 \
113                 --subblock=size=8,rle=8 \
114                 --subblock=size=4096,rle=12 \
115                 --delta=dist=1 \
116                 --delta=dist=4 \
117                 --delta=dist=256 \
118                 --x86 \
119                 --powerpc \
120                 --ia64 \
121                 --arm \
122                 --armthumb \
123                 --sparc
124         do
125                 test_lzma $ARGS --lzma2=dict=64KiB,nice=32,mode=fast
126                 test_lzma --subblock $ARGS --lzma2=dict=64KiB,nice=32,mode=fast
127         done
128
129         echo
130 done
131
132 (exit 0)
133 exit 0