summaryrefslogtreecommitdiff
path: root/Build/source/extra/xz-4.999.9beta-124-gb637/tests/test_compress.sh
blob: ff0cb304df427b431e42ace4644726cf0ca4b2c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/sh

###############################################################################
#
# Author: Lasse Collin
#
# This file has been put into the public domain.
# You can do whatever you want with this file.
#
###############################################################################

# Find out if our shell supports functions.
eval 'unset foo ; foo() { return 42; } ; foo'
if test $? != 42 ; then
	echo "/bin/sh doesn't support functions, skipping this test."
	(exit 77)
	exit 77
fi

test_xz() {
	if $XZ -c "$@" "$FILE" > tmp_compressed; then
		:
	else
		echo "Compressing failed: $* $FILE"
		(exit 1)
		exit 1
	fi

	if $XZ -cd tmp_compressed > tmp_uncompressed ; then
		:
	else
		echo "Decoding failed: $* $FILE"
		(exit 1)
		exit 1
	fi

	if cmp tmp_uncompressed "$FILE" ; then
		:
	else
		echo "Decoded file does not match the original: $* $FILE"
		(exit 1)
		exit 1
	fi

	if $XZDEC tmp_compressed > tmp_uncompressed ; then
		:
	else
		echo "Decoding failed: $* $FILE"
		(exit 1)
		exit 1
	fi

	if cmp tmp_uncompressed "$FILE" ; then
		:
	else
		echo "Decoded file does not match the original: $* $FILE"
		(exit 1)
		exit 1
	fi

	# Show progress:
	echo . | tr -d '\n\r'
}

XZ="../src/xz/xz --memory=28MiB --threads=1"
XZDEC="../src/xzdec/xzdec --memory=4MiB"
unset XZ_OPT

# Create the required input files.
if ./create_compress_files ; then
	:
else
	rm -f compress_*
	echo "Failed to create files to test compression."
	(exit 1)
	exit 1
fi

# Remove temporary now (in case they are something weird), and on exit.
rm -f tmp_compressed tmp_uncompressed
trap 'rm -f tmp_compressed tmp_uncompressed' 0

# Encode and decode each file with various filter configurations.
# This takes quite a bit of time.
echo "test_compress.sh:"
for FILE in compress_generated_* "$srcdir"/compress_prepared_*
do
	MSG=`echo "x$FILE" | sed 's,^x,,; s,^.*/,,; s,^compress_,,'`
	echo "  $MSG" | tr -d '\n\r'

	# Don't test with empty arguments; it breaks some ancient
	# proprietary /bin/sh versions due to $@ used in test_xz().
	test_xz -1
	test_xz -2
	test_xz -3
	test_xz -4

	# Disabled until Subblock format is stable.
#		--subblock \
#		--subblock=size=1 \
#		--subblock=size=1,rle=1 \
#		--subblock=size=1,rle=4 \
#		--subblock=size=4,rle=4 \
#		--subblock=size=8,rle=4 \
#		--subblock=size=8,rle=8 \
#		--subblock=size=4096,rle=12 \
#
	for ARGS in \
		--delta=dist=1 \
		--delta=dist=4 \
		--delta=dist=256 \
		--x86 \
		--powerpc \
		--ia64 \
		--arm \
		--armthumb \
		--sparc
	do
		test_xz $ARGS --lzma2=dict=64KiB,nice=32,mode=fast

		# Disabled until Subblock format is stable.
		# test_xz --subblock $ARGS --lzma2=dict=64KiB,nice=32,mode=fast
	done

	echo
done

(exit 0)
exit 0