xref: /plan9-contrib/sys/src/cmd/lzip/testsuite/check.sh (revision 13d37d7716a3e781f408392d7869dff5927c6669)
1#! /bin/sh
2# check script for Clzip - LZMA lossless data compressor
3# Copyright (C) 2010-2017 Antonio Diaz Diaz.
4#
5# This script is free software: you have unlimited permission
6# to copy, distribute and modify it.
7
8LC_ALL=C
9export LC_ALL
10objdir=`pwd`
11testdir=`cd "$1" ; pwd`
12LZIP="${objdir}"/clzip
13framework_failure() { echo "failure in testing framework" ; exit 1 ; }
14
15if [ ! -f "${LZIP}" ] || [ ! -x "${LZIP}" ] ; then
16	echo "${LZIP}: cannot execute"
17	exit 1
18fi
19
20[ -e "${LZIP}" ] 2> /dev/null ||
21	{
22	echo "$0: a POSIX shell is required to run the tests"
23	echo "Try bash -c \"$0 $1 $2\""
24	exit 1
25	}
26
27if [ -d tmp ] ; then rm -rf tmp ; fi
28mkdir tmp
29cd "${objdir}"/tmp || framework_failure
30
31cat "${testdir}"/test.txt > in || framework_failure
32in_lz="${testdir}"/test.txt.lz
33fail=0
34test_failed() { fail=1 ; printf " $1" ; [ -z "$2" ] || printf "($2)" ; }
35
36printf "testing clzip-%s..." "$2"
37
38"${LZIP}" -fkqm4 in
39{ [ $? = 1 ] && [ ! -e in.lz ] ; } || test_failed $LINENO
40"${LZIP}" -fkqm274 in
41{ [ $? = 1 ] && [ ! -e in.lz ] ; } || test_failed $LINENO
42for i in bad_size -1 0 4095 513MiB 1G 1T 1P 1E 1Z 1Y 10KB ; do
43	"${LZIP}" -fkqs $i in
44	{ [ $? = 1 ] && [ ! -e in.lz ] ; } || test_failed $LINENO $i
45done
46"${LZIP}" -lq in
47[ $? = 2 ] || test_failed $LINENO
48"${LZIP}" -tq in
49[ $? = 2 ] || test_failed $LINENO
50"${LZIP}" -tq < in
51[ $? = 2 ] || test_failed $LINENO
52"${LZIP}" -cdq in
53[ $? = 2 ] || test_failed $LINENO
54"${LZIP}" -cdq < in
55[ $? = 2 ] || test_failed $LINENO
56# these are for code coverage
57"${LZIP}" -lt "${in_lz}" 2> /dev/null
58[ $? = 1 ] || test_failed $LINENO
59"${LZIP}" -cdl "${in_lz}" > out 2> /dev/null
60[ $? = 1 ] || test_failed $LINENO
61"${LZIP}" -cdt "${in_lz}" > out 2> /dev/null
62[ $? = 1 ] || test_failed $LINENO
63"${LZIP}" -t -- nx_file 2> /dev/null
64[ $? = 1 ] || test_failed $LINENO
65"${LZIP}" --help > /dev/null || test_failed $LINENO
66"${LZIP}" -n1 -V > /dev/null || test_failed $LINENO
67"${LZIP}" -m 2> /dev/null
68[ $? = 1 ] || test_failed $LINENO
69"${LZIP}" -z 2> /dev/null
70[ $? = 1 ] || test_failed $LINENO
71"${LZIP}" --bad_option 2> /dev/null
72[ $? = 1 ] || test_failed $LINENO
73"${LZIP}" --t 2> /dev/null
74[ $? = 1 ] || test_failed $LINENO
75"${LZIP}" --test=2 2> /dev/null
76[ $? = 1 ] || test_failed $LINENO
77"${LZIP}" --output= 2> /dev/null
78[ $? = 1 ] || test_failed $LINENO
79"${LZIP}" --output 2> /dev/null
80[ $? = 1 ] || test_failed $LINENO
81printf "LZIP\001-.............................." | "${LZIP}" -t 2> /dev/null
82printf "LZIP\002-.............................." | "${LZIP}" -t 2> /dev/null
83printf "LZIP\001+.............................." | "${LZIP}" -t 2> /dev/null
84
85printf "\ntesting decompression..."
86
87"${LZIP}" -lq "${in_lz}" || test_failed $LINENO
88"${LZIP}" -t "${in_lz}" || test_failed $LINENO
89"${LZIP}" -cd "${in_lz}" > copy || test_failed $LINENO
90cmp in copy || test_failed $LINENO
91
92rm -f copy
93cat "${in_lz}" > copy.lz || framework_failure
94"${LZIP}" -dk copy.lz || test_failed $LINENO
95cmp in copy || test_failed $LINENO
96printf "to be overwritten" > copy || framework_failure
97"${LZIP}" -d copy.lz 2> /dev/null
98[ $? = 1 ] || test_failed $LINENO
99"${LZIP}" -df copy.lz
100{ [ $? = 0 ] && [ ! -e copy.lz ] && cmp in copy ; } || test_failed $LINENO
101
102printf "to be overwritten" > copy || framework_failure
103"${LZIP}" -df -o copy < "${in_lz}" || test_failed $LINENO
104cmp in copy || test_failed $LINENO
105
106rm -f copy
107"${LZIP}" < in > anyothername || test_failed $LINENO
108"${LZIP}" -dv --output copy - anyothername - < "${in_lz}" 2> /dev/null
109{ [ $? = 0 ] && cmp in copy && cmp in anyothername.out ; } ||
110	test_failed $LINENO
111rm -f copy anyothername.out
112
113"${LZIP}" -lq in "${in_lz}"
114[ $? = 2 ] || test_failed $LINENO
115"${LZIP}" -lq nx_file.lz "${in_lz}"
116[ $? = 1 ] || test_failed $LINENO
117"${LZIP}" -tq in "${in_lz}"
118[ $? = 2 ] || test_failed $LINENO
119"${LZIP}" -tq nx_file.lz "${in_lz}"
120[ $? = 1 ] || test_failed $LINENO
121"${LZIP}" -cdq in "${in_lz}" > copy
122{ [ $? = 2 ] && cat copy in | cmp in - ; } || test_failed $LINENO
123"${LZIP}" -cdq nx_file.lz "${in_lz}" > copy
124{ [ $? = 1 ] && cmp in copy ; } || test_failed $LINENO
125rm -f copy
126cat "${in_lz}" > copy.lz || framework_failure
127for i in 1 2 3 4 5 6 7 ; do
128	printf "g" >> copy.lz || framework_failure
129	"${LZIP}" -alvv copy.lz "${in_lz}" > /dev/null 2>&1
130	[ $? = 2 ] || test_failed $LINENO $i
131	"${LZIP}" -atvvvv copy.lz "${in_lz}" 2> /dev/null
132	[ $? = 2 ] || test_failed $LINENO $i
133done
134"${LZIP}" -dq in copy.lz
135{ [ $? = 2 ] && [ -e copy.lz ] && [ ! -e copy ] && [ ! -e in.out ] ; } ||
136	test_failed $LINENO
137"${LZIP}" -dq nx_file.lz copy.lz
138{ [ $? = 1 ] && [ ! -e copy.lz ] && [ ! -e nx_file ] && cmp in copy ; } ||
139	test_failed $LINENO
140
141cat in in > in2 || framework_failure
142cat "${in_lz}" "${in_lz}" > in2.lz || framework_failure
143"${LZIP}" -lq in2.lz || test_failed $LINENO
144"${LZIP}" -t in2.lz || test_failed $LINENO
145"${LZIP}" -cd in2.lz > copy2 || test_failed $LINENO
146cmp in2 copy2 || test_failed $LINENO
147
148"${LZIP}" --output=copy2 < in2 || test_failed $LINENO
149"${LZIP}" -lq copy2.lz || test_failed $LINENO
150"${LZIP}" -t copy2.lz || test_failed $LINENO
151"${LZIP}" -cd copy2.lz > copy2 || test_failed $LINENO
152cmp in2 copy2 || test_failed $LINENO
153
154printf "\ngarbage" >> copy2.lz || framework_failure
155"${LZIP}" -tvvvv copy2.lz 2> /dev/null || test_failed $LINENO
156rm -f copy2
157"${LZIP}" -alq copy2.lz
158[ $? = 2 ] || test_failed $LINENO
159"${LZIP}" -atq copy2.lz
160[ $? = 2 ] || test_failed $LINENO
161"${LZIP}" -atq < copy2.lz
162[ $? = 2 ] || test_failed $LINENO
163"${LZIP}" -adkq copy2.lz
164{ [ $? = 2 ] && [ ! -e copy2 ] ; } || test_failed $LINENO
165"${LZIP}" -adkq -o copy2 < copy2.lz
166{ [ $? = 2 ] && [ ! -e copy2 ] ; } || test_failed $LINENO
167printf "to be overwritten" > copy2 || framework_failure
168"${LZIP}" -df copy2.lz || test_failed $LINENO
169cmp in2 copy2 || test_failed $LINENO
170
171printf "\ntesting   compression..."
172
173"${LZIP}" -cf "${in_lz}" > out 2> /dev/null	# /dev/null is a tty on OS/2
174[ $? = 1 ] || test_failed $LINENO
175"${LZIP}" -cFvvm36 "${in_lz}" > out 2> /dev/null || test_failed $LINENO
176"${LZIP}" -cd out | "${LZIP}" -d > copy || test_failed $LINENO
177cmp in copy || test_failed $LINENO
178
179for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do
180	"${LZIP}" -k -$i in || test_failed $LINENO $i
181	mv -f in.lz copy.lz || test_failed $LINENO $i
182	printf "garbage" >> copy.lz || framework_failure
183	"${LZIP}" -df copy.lz || test_failed $LINENO $i
184	cmp in copy || test_failed $LINENO $i
185done
186
187for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do
188	"${LZIP}" -c -$i in > out || test_failed $LINENO $i
189	printf "g" >> out || framework_failure
190	"${LZIP}" -cd out > copy || test_failed $LINENO $i
191	cmp in copy || test_failed $LINENO $i
192done
193
194for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do
195	"${LZIP}" -$i < in > out || test_failed $LINENO $i
196	"${LZIP}" -d < out > copy || test_failed $LINENO $i
197	cmp in copy || test_failed $LINENO $i
198done
199
200for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do
201	"${LZIP}" -f -$i -o out < in || test_failed $LINENO $i
202	"${LZIP}" -df -o copy < out.lz || test_failed $LINENO $i
203	cmp in copy || test_failed $LINENO $i
204done
205
206cat in in in in in in in in > in8 || framework_failure
207"${LZIP}" -1s12 -S100k -o out < in8 || test_failed $LINENO
208"${LZIP}" -t out00001.lz out00002.lz || test_failed $LINENO
209"${LZIP}" -cd out00001.lz out00002.lz | cmp in8 - || test_failed $LINENO
210rm -f out00001.lz
211"${LZIP}" -1ks4Ki -b100000 in8 || test_failed $LINENO
212"${LZIP}" -t in8.lz || test_failed $LINENO
213"${LZIP}" -cd in8.lz | cmp in8 - || test_failed $LINENO
214rm -f in8
215"${LZIP}" -0 -S100k -o out < in8.lz || test_failed $LINENO
216"${LZIP}" -t out00001.lz out00002.lz || test_failed $LINENO
217"${LZIP}" -cd out00001.lz out00002.lz | cmp in8.lz - || test_failed $LINENO
218rm -f out00001.lz out00002.lz
219"${LZIP}" -0kF -b100k in8.lz || test_failed $LINENO
220"${LZIP}" -t in8.lz.lz || test_failed $LINENO
221"${LZIP}" -cd in8.lz.lz | cmp in8.lz - || test_failed $LINENO
222rm -f in8.lz in8.lz.lz
223
224printf "\ntesting bad input..."
225
226cat "${in_lz}" "${in_lz}" "${in_lz}" > in3.lz || framework_failure
227if dd if=in3.lz of=trunc.lz bs=14752 count=1 2> /dev/null &&
228   [ -e trunc.lz ] && cmp in2.lz trunc.lz > /dev/null 2>&1 ; then
229	for i in 6 20 14734 14753 14754 14755 14756 14757 14758 ; do
230		dd if=in3.lz of=trunc.lz bs=$i count=1 2> /dev/null
231		"${LZIP}" -lq trunc.lz
232		[ $? = 2 ] || test_failed $LINENO $i
233		"${LZIP}" -t trunc.lz 2> /dev/null
234		[ $? = 2 ] || test_failed $LINENO $i
235		"${LZIP}" -tq < trunc.lz
236		[ $? = 2 ] || test_failed $LINENO $i
237		"${LZIP}" -cdq trunc.lz > out
238		[ $? = 2 ] || test_failed $LINENO $i
239		"${LZIP}" -dq < trunc.lz > out
240		[ $? = 2 ] || test_failed $LINENO $i
241	done
242else
243	printf "\nwarning: skipping truncation test: 'dd' does not work on your system."
244fi
245
246cat "${in_lz}" > ingin.lz || framework_failure
247printf "g" >> ingin.lz || framework_failure
248cat "${in_lz}" >> ingin.lz || framework_failure
249"${LZIP}" -lq ingin.lz
250[ $? = 2 ] || test_failed $LINENO
251"${LZIP}" -t ingin.lz || test_failed $LINENO
252"${LZIP}" -cd ingin.lz > copy || test_failed $LINENO
253cmp in copy || test_failed $LINENO
254"${LZIP}" -t < ingin.lz || test_failed $LINENO
255"${LZIP}" -d < ingin.lz > copy || test_failed $LINENO
256cmp in copy || test_failed $LINENO
257
258echo
259if [ ${fail} = 0 ] ; then
260	echo "tests completed successfully."
261	cd "${objdir}" && rm -r tmp
262else
263	echo "tests failed."
264fi
265exit ${fail}
266