test_streams.sh 9.74 KB
Newer Older
Josh Coalson's avatar
Josh Coalson committed
1
2
#!/bin/sh

3
#  FLAC - Free Lossless Audio Codec
4
5
#  Copyright (C) 2001-2009  Josh Coalson
#  Copyright (C) 2011-2013  Xiph.Org Foundation
6
#
Josh Coalson's avatar
Josh Coalson committed
7
#  This file is part the FLAC project.  FLAC is comprised of several
8
#  components distributed under different licenses.  The codec libraries
Josh Coalson's avatar
Josh Coalson committed
9
10
11
12
13
14
#  are distributed under Xiph.Org's BSD-like license (see the file
#  COPYING.Xiph in this distribution).  All other programs, libraries, and
#  plugins are distributed under the GPL (see COPYING.GPL).  The documentation
#  is distributed under the Gnu FDL (see COPYING.FDL).  Each file in the
#  FLAC distribution contains at the top the terms under which it may be
#  distributed.
15
#
Josh Coalson's avatar
Josh Coalson committed
16
17
18
19
#  Since this particular file is relevant to all components of FLAC,
#  it may be distributed under the Xiph.Org license, which is the least
#  restrictive of those mentioned above.  See the file COPYING.Xiph in this
#  distribution.
20

21
22
23
24
25
26
die ()
{
	echo $* 1>&2
	exit 1
}

27
if [ x = x"$1" ] ; then
28
29
30
31
32
	BUILD=debug
else
	BUILD="$1"
fi

33
LD_LIBRARY_PATH=../objs/$BUILD/lib:$LD_LIBRARY_PATH
Josh Coalson's avatar
Josh Coalson committed
34
export LD_LIBRARY_PATH
35
export MALLOC_CHECK_=3
36
export MALLOC_PERTURB_=$((RANDOM % 255 + 1))
37
38
PATH=../src/flac:$PATH
PATH=../src/test_streams:$PATH
39
PATH=../objs/$BUILD/bin:$PATH
Josh Coalson's avatar
Josh Coalson committed
40

Josh Coalson's avatar
Josh Coalson committed
41
42
43
44
if [ x"$FLAC__TEST_LEVEL" = x ] ; then
	FLAC__TEST_LEVEL=1
fi

45
flac --help 1>/dev/null 2>/dev/null || die "ERROR can't find flac executable"
46

Josh Coalson's avatar
Josh Coalson committed
47
48
run_flac ()
{
49
	if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
50
		echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 flac $*" >>test_streams.valgrind.log
51
		valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 flac --no-error-on-compression-fail $* 4>>test_streams.valgrind.log
Josh Coalson's avatar
Josh Coalson committed
52
	else
53
		flac --no-error-on-compression-fail $*
Josh Coalson's avatar
Josh Coalson committed
54
55
56
	fi
}

57
echo "Generating streams..."
58
if [ ! -f wacky1.wav ] ; then
59
	test_streams || die "ERROR during test_streams"
60
61
62
fi

#
63
# single-file test routines
64
65
#

Josh Coalson's avatar
Josh Coalson committed
66
67
68
69
70
71
72
test_file ()
{
	name=$1
	channels=$2
	bps=$3
	encode_options="$4"

Josh Coalson's avatar
Josh Coalson committed
73
	echo -n "$name (--channels=$channels --bps=$bps $encode_options): encode..."
74
	cmd="run_flac --verify --silent --force --force-raw-format --endian=little --sign=signed --sample-rate=44100 --bps=$bps --channels=$channels $encode_options --no-padding $name.raw"
75
76
	echo "### ENCODE $name #######################################################" >> ./streams.log
	echo "###    cmd=$cmd" >> ./streams.log
77
78
	$cmd 2>>./streams.log || die "ERROR during encode of $name"

Josh Coalson's avatar
Josh Coalson committed
79
	echo -n "decode..."
80
	cmd="run_flac --silent --force --endian=little --sign=signed --decode --force-raw-format --output-name=$name.cmp $name.flac"
81
82
	echo "### DECODE $name #######################################################" >> ./streams.log
	echo "###    cmd=$cmd" >> ./streams.log
83
84
	$cmd 2>>./streams.log || die "ERROR during decode of $name"

85
86
87
	ls -1l $name.raw >> ./streams.log
	ls -1l $name.flac >> ./streams.log
	ls -1l $name.cmp >> ./streams.log
88

Josh Coalson's avatar
Josh Coalson committed
89
	echo -n "compare..."
90
91
	cmp $name.raw $name.cmp || die "ERROR during compare of $name"

Josh Coalson's avatar
Josh Coalson committed
92
93
94
	echo OK
}

Josh Coalson's avatar
Josh Coalson committed
95
96
97
98
99
100
101
test_file_piped ()
{
	name=$1
	channels=$2
	bps=$3
	encode_options="$4"

102
103
104
105
106
107
	if [ `env | grep -ic '^comspec='` != 0 ] ; then
		is_win=yes
	else
		is_win=no
	fi

Josh Coalson's avatar
Josh Coalson committed
108
	echo -n "$name: encode via pipes..."
109
	if [ $is_win = yes ] ; then
110
		cmd="run_flac --verify --silent --force --force-raw-format --endian=little --sign=signed --sample-rate=44100 --bps=$bps --channels=$channels $encode_options --no-padding --stdout $name.raw"
111
112
		echo "### ENCODE $name #######################################################" >> ./streams.log
		echo "###    cmd=$cmd" >> ./streams.log
113
		$cmd 1>$name.flac 2>>./streams.log || die "ERROR during encode of $name"
114
	else
115
		cmd="run_flac --verify --silent --force --force-raw-format --endian=little --sign=signed --sample-rate=44100 --bps=$bps --channels=$channels $encode_options --no-padding --stdout -"
116
117
		echo "### ENCODE $name #######################################################" >> ./streams.log
		echo "###    cmd=$cmd" >> ./streams.log
118
		cat $name.raw | $cmd 1>$name.flac 2>>./streams.log || die "ERROR during encode of $name"
Josh Coalson's avatar
Josh Coalson committed
119
120
	fi
	echo -n "decode via pipes..."
121
	if [ $is_win = yes ] ; then
122
		cmd="run_flac --silent --force --endian=little --sign=signed --decode --force-raw-format --stdout $name.flac"
123
124
		echo "### DECODE $name #######################################################" >> ./streams.log
		echo "###    cmd=$cmd" >> ./streams.log
125
		$cmd 1>$name.cmp 2>>./streams.log || die "ERROR during decode of $name"
126
	else
127
		cmd="run_flac --silent --force --endian=little --sign=signed --decode --force-raw-format --stdout -"
128
129
		echo "### DECODE $name #######################################################" >> ./streams.log
		echo "###    cmd=$cmd" >> ./streams.log
130
		cat $name.flac | $cmd 1>$name.cmp 2>>./streams.log || die "ERROR during decode of $name"
Josh Coalson's avatar
Josh Coalson committed
131
132
133
134
	fi
	ls -1l $name.raw >> ./streams.log
	ls -1l $name.flac >> ./streams.log
	ls -1l $name.cmp >> ./streams.log
135

Josh Coalson's avatar
Josh Coalson committed
136
	echo -n "compare..."
137
138
	cmp $name.raw $name.cmp || die "ERROR during compare of $name"

Josh Coalson's avatar
Josh Coalson committed
139
140
141
	echo OK
}

142
if [ "$FLAC__TEST_LEVEL" -gt 1 ] ; then
Josh Coalson's avatar
Josh Coalson committed
143
144
145
146
147
	max_lpc_order=32
else
	max_lpc_order=16
fi

Josh Coalson's avatar
Josh Coalson committed
148
149
150
echo "Testing noise through pipes..."
test_file_piped noise 1 8 "-0"

Josh Coalson's avatar
Josh Coalson committed
151
echo "Testing small files..."
152
153
154
155
test_file test01 1 16 "-0 -l $max_lpc_order --lax -m -e -p"
test_file test02 2 16 "-0 -l $max_lpc_order --lax -m -e -p"
test_file test03 1 16 "-0 -l $max_lpc_order --lax -m -e -p"
test_file test04 2 16 "-0 -l $max_lpc_order --lax -m -e -p"
Josh Coalson's avatar
Josh Coalson committed
156

157
158
159
160
161
for bps in 8 16 24 ; do
	echo "Testing $bps-bit full-scale deflection streams..."
	for b in 01 02 03 04 05 06 07 ; do
		test_file fsd$bps-$b 1 $bps "-0 -l $max_lpc_order --lax -m -e -p"
	done
162
done
163

164
165
echo "Testing 16-bit wasted-bits-per-sample streams..."
for b in 01 ; do
166
	test_file wbps16-$b 1 16 "-0 -l $max_lpc_order --lax -m -e -p"
167
168
done

169
for bps in 8 16 24 ; do
170
	echo "Testing $bps-bit sine wave streams..."
171
	for b in 00 ; do
172
		test_file sine${bps}-$b 1 $bps "-0 -l $max_lpc_order --lax -m -e --sample-rate=48000"
173
174
	done
	for b in 01 ; do
175
		test_file sine${bps}-$b 1 $bps "-0 -l $max_lpc_order --lax -m -e --sample-rate=96000"
176
177
	done
	for b in 02 03 04 ; do
178
		test_file sine${bps}-$b 1 $bps "-0 -l $max_lpc_order --lax -m -e"
179
	done
180
	for b in 10 11 ; do
181
		test_file sine${bps}-$b 2 $bps "-0 -l $max_lpc_order --lax -m -e --sample-rate=48000"
182
183
	done
	for b in 12 ; do
184
		test_file sine${bps}-$b 2 $bps "-0 -l $max_lpc_order --lax -m -e --sample-rate=96000"
185
186
	done
	for b in 13 14 15 16 17 18 19 ; do
187
		test_file sine${bps}-$b 2 $bps "-0 -l $max_lpc_order --lax -m -e"
188
	done
Josh Coalson's avatar
Josh Coalson committed
189
190
done

191
192
193
194
195
echo "Testing blocksize variations..."
for disable in '' '--disable-verbatim-subframes --disable-constant-subframes' '--disable-verbatim-subframes --disable-constant-subframes --disable-fixed-subframes' ; do
	for blocksize in 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ; do
		for lpc_order in 0 1 2 3 4 5 7 8 9 15 16 17 31 32 ; do
			if [ $lpc_order = 0 ] || [ $lpc_order -le $blocksize ] ; then
196
				test_file noise8m32 1 8 "-8 -p -e -l $lpc_order --lax --blocksize=$blocksize $disable"
197
198
199
200
201
			fi
		done
	done
done

Josh Coalson's avatar
Josh Coalson committed
202
echo "Testing some frame header variations..."
Josh Coalson's avatar
Josh Coalson committed
203
204
205
206
207
test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax -b $max_lpc_order"
test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax -b 65535"
test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=9"
test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=90"
test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=90000"
208
209
210
test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=9"
test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=90"
test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=90000"
211
212
213

echo "Testing option variations..."
for f in 00 01 02 03 04 ; do
214
	for disable in '' '--disable-verbatim-subframes --disable-constant-subframes' '--disable-verbatim-subframes --disable-constant-subframes --disable-fixed-subframes' ; do
215
216
217
218
219
220
221
		if [ -z "$disable" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
			for opt in 0 1 2 4 5 6 8 ; do
				for extras in '' '-p' '-e' ; do
					if [ -z "$extras" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
						test_file sine16-$f 1 16 "-$opt $extras $disable"
					fi
				done
222
			done
223
			if [ "$FLAC__TEST_LEVEL" -gt 1 ] ; then
224
				test_file sine16-$f 1 16 "-b 16384 -m -r 8 -l $max_lpc_order --lax -e -p $disable"
225
			fi
226
		fi
227
228
	done
done
Josh Coalson's avatar
Josh Coalson committed
229

230
for f in 10 11 12 13 14 15 16 17 18 19 ; do
231
	for disable in '' '--disable-verbatim-subframes --disable-constant-subframes' '--disable-verbatim-subframes --disable-constant-subframes --disable-fixed-subframes' ; do
232
233
234
235
236
237
238
		if [ -z "$disable" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
			for opt in 0 1 2 4 5 6 8 ; do
				for extras in '' '-p' '-e' ; do
					if [ -z "$extras" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
						test_file sine16-$f 2 16 "-$opt $extras $disable"
					fi
				done
239
			done
240
			if [ "$FLAC__TEST_LEVEL" -gt 1 ] ; then
241
				test_file sine16-$f 2 16 "-b 16384 -m -r 8 -l $max_lpc_order --lax -e -p $disable"
242
			fi
243
		fi
244
245
246
247
	done
done

echo "Testing noise..."
248
for disable in '' '--disable-verbatim-subframes --disable-constant-subframes' '--disable-verbatim-subframes --disable-constant-subframes --disable-fixed-subframes' ; do
249
250
251
252
253
254
255
256
257
258
259
260
261
262
	if [ -z "$disable" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
		for channels in 1 2 4 8 ; do
			if [ $channels -le 2 ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
				for bps in 8 16 24 ; do
					for opt in 0 1 2 3 4 5 6 7 8 ; do
						for extras in '' '-p' '-e' ; do
							if [ -z "$extras" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
								for blocksize in '' '--lax -b 32' '--lax -b 32768' '--lax -b 65535' ; do
									if [ -z "$blocksize" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
										test_file noise $channels $bps "-$opt $extras $blocksize $disable"
									fi
								done
							fi
						done
263
					done
264
					if [ "$FLAC__TEST_LEVEL" -gt 1 ] ; then
265
						test_file noise $channels $bps "-b 16384 -m -r 8 -l $max_lpc_order --lax -e -p $disable"
266
					fi
267
				done
268
			fi
269
		done
270
	fi
271
done