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