add test_picture to grabbag tests
[platform/upstream/flac.git] / test / test_streams.sh
1 #!/bin/sh
2
3 #  FLAC - Free Lossless Audio Codec
4 #  Copyright (C) 2001,2002,2003,2004,2005,2006  Josh Coalson
5 #
6 #  This file is part the FLAC project.  FLAC is comprised of several
7 #  components distributed under difference licenses.  The codec libraries
8 #  are distributed under Xiph.Org's BSD-like license (see the file
9 #  COPYING.Xiph in this distribution).  All other programs, libraries, and
10 #  plugins are distributed under the GPL (see COPYING.GPL).  The documentation
11 #  is distributed under the Gnu FDL (see COPYING.FDL).  Each file in the
12 #  FLAC distribution contains at the top the terms under which it may be
13 #  distributed.
14 #
15 #  Since this particular file is relevant to all components of FLAC,
16 #  it may be distributed under the Xiph.Org license, which is the least
17 #  restrictive of those mentioned above.  See the file COPYING.Xiph in this
18 #  distribution.
19
20 die ()
21 {
22         echo $* 1>&2
23         exit 1
24 }
25
26 if [ x = x"$1" ] ; then 
27         BUILD=debug
28 else
29         BUILD="$1"
30 fi
31
32 LD_LIBRARY_PATH=../obj/$BUILD/lib:$LD_LIBRARY_PATH
33 export LD_LIBRARY_PATH
34 PATH=../src/flac:$PATH
35 PATH=../src/test_streams:$PATH
36 PATH=../obj/$BUILD/bin:$PATH
37
38 if [ x"$FLAC__TEST_LEVEL" = x ] ; then
39         FLAC__TEST_LEVEL=1
40 fi
41
42 flac --help 1>/dev/null 2>/dev/null || die "ERROR can't find flac executable"
43
44 run_flac ()
45 {
46         if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
47                 valgrind --leak-check=yes --show-reachable=yes --num-callers=100 --logfile-fd=4 flac $* 4>>test_streams.valgrind.log
48         else
49                 flac $*
50         fi
51 }
52
53 echo "Generating streams..."
54 if [ ! -f wacky1.wav ] ; then
55         test_streams || die "ERROR during test_streams"
56 fi
57
58 #
59 # single-file test routines
60 #
61
62 test_file ()
63 {
64         name=$1
65         channels=$2
66         bps=$3
67         encode_options="$4"
68
69         echo -n "$name (--channels=$channels --bps=$bps $encode_options): encode..."
70         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"
71         echo "### ENCODE $name #######################################################" >> ./streams.log
72         echo "###    cmd=$cmd" >> ./streams.log
73         $cmd 2>>./streams.log || die "ERROR during encode of $name"
74
75         echo -n "decode..."
76         cmd="run_flac --silent --force --endian=little --sign=signed --decode --force-raw-format --output-name=$name.cmp $name.flac"
77         echo "### DECODE $name #######################################################" >> ./streams.log
78         echo "###    cmd=$cmd" >> ./streams.log
79         $cmd 2>>./streams.log || die "ERROR during decode of $name"
80
81         ls -1l $name.raw >> ./streams.log
82         ls -1l $name.flac >> ./streams.log
83         ls -1l $name.cmp >> ./streams.log
84
85         echo -n "compare..."
86         cmp $name.raw $name.cmp || die "ERROR during compare of $name"
87
88         echo OK
89 }
90
91 test_file_piped ()
92 {
93         name=$1
94         channels=$2
95         bps=$3
96         encode_options="$4"
97
98         if [ `env | grep -ic '^comspec='` != 0 ] ; then
99                 is_win=yes
100         else
101                 is_win=no
102         fi
103
104         echo -n "$name: encode via pipes..."
105         if [ $is_win = yes ] ; then
106                 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"
107                 echo "### ENCODE $name #######################################################" >> ./streams.log
108                 echo "###    cmd=$cmd" >> ./streams.log
109                 $cmd 1>$name.flac 2>>./streams.log || die "ERROR during encode of $name"
110         else
111                 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 -"
112                 echo "### ENCODE $name #######################################################" >> ./streams.log
113                 echo "###    cmd=$cmd" >> ./streams.log
114                 cat $name.raw | $cmd 1>$name.flac 2>>./streams.log || die "ERROR during encode of $name"
115         fi
116         echo -n "decode via pipes..."
117         if [ $is_win = yes ] ; then
118                 cmd="run_flac --silent --force --endian=little --sign=signed --decode --force-raw-format --stdout $name.flac"
119                 echo "### DECODE $name #######################################################" >> ./streams.log
120                 echo "###    cmd=$cmd" >> ./streams.log
121                 $cmd 1>$name.cmp 2>>./streams.log || die "ERROR during decode of $name"
122         else
123                 cmd="run_flac --silent --force --endian=little --sign=signed --decode --force-raw-format --stdout -"
124                 echo "### DECODE $name #######################################################" >> ./streams.log
125                 echo "###    cmd=$cmd" >> ./streams.log
126                 cat $name.flac | $cmd 1>$name.cmp 2>>./streams.log || die "ERROR during decode of $name"
127         fi
128         ls -1l $name.raw >> ./streams.log
129         ls -1l $name.flac >> ./streams.log
130         ls -1l $name.cmp >> ./streams.log
131
132         echo -n "compare..."
133         cmp $name.raw $name.cmp || die "ERROR during compare of $name"
134
135         echo OK
136 }
137
138 if [ "$FLAC__TEST_LEVEL" -gt 1 ] ; then
139         max_lpc_order=32
140 else
141         max_lpc_order=16
142 fi
143
144 echo "Testing noise through pipes..."
145 test_file_piped noise 1 8 "-0"
146
147 echo "Testing small files..."
148 test_file test01 1 16 "-0 -l $max_lpc_order --lax -m -e -p"
149 test_file test02 2 16 "-0 -l $max_lpc_order --lax -m -e -p"
150 test_file test03 1 16 "-0 -l $max_lpc_order --lax -m -e -p"
151 test_file test04 2 16 "-0 -l $max_lpc_order --lax -m -e -p"
152
153 echo "Testing 8-bit full-scale deflection streams..."
154 for b in 01 02 03 04 05 06 07 ; do
155         test_file fsd8-$b 1 8 "-0 -l $max_lpc_order --lax -m -e -p"
156 done
157
158 echo "Testing 16-bit full-scale deflection streams..."
159 for b in 01 02 03 04 05 06 07 ; do
160         test_file fsd16-$b 1 16 "-0 -l $max_lpc_order --lax -m -e -p"
161 done
162
163 echo "Testing 24-bit full-scale deflection streams..."
164 for b in 01 02 03 04 05 06 07 ; do
165         test_file fsd24-$b 1 24 "-0 -l $max_lpc_order --lax -m -e -p"
166 done
167
168 echo "Testing 16-bit wasted-bits-per-sample streams..."
169 for b in 01 ; do
170         test_file wbps16-$b 1 16 "-0 -l $max_lpc_order --lax -m -e -p"
171 done
172
173 for bps in 8 16 24 ; do
174         echo "Testing $bps-bit sine wave streams..."
175         for b in 00 ; do
176                 test_file sine${bps}-$b 1 $bps "-0 -l $max_lpc_order --lax -m -e --sample-rate=48000"
177         done
178         for b in 01 ; do
179                 test_file sine${bps}-$b 1 $bps "-0 -l $max_lpc_order --lax -m -e --sample-rate=96000"
180         done
181         for b in 02 03 04 ; do
182                 test_file sine${bps}-$b 1 $bps "-0 -l $max_lpc_order --lax -m -e"
183         done
184         for b in 10 11 ; do
185                 test_file sine${bps}-$b 2 $bps "-0 -l $max_lpc_order --lax -m -e --sample-rate=48000"
186         done
187         for b in 12 ; do
188                 test_file sine${bps}-$b 2 $bps "-0 -l $max_lpc_order --lax -m -e --sample-rate=96000"
189         done
190         for b in 13 14 15 16 17 18 19 ; do
191                 test_file sine${bps}-$b 2 $bps "-0 -l $max_lpc_order --lax -m -e"
192         done
193 done
194
195 echo "Testing blocksize variations..."
196 for disable in '' '--disable-verbatim-subframes --disable-constant-subframes' '--disable-verbatim-subframes --disable-constant-subframes --disable-fixed-subframes' ; do
197         for blocksize in 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ; do
198                 for lpc_order in 0 1 2 3 4 5 7 8 9 15 16 17 31 32 ; do
199                         if [ $lpc_order = 0 ] || [ $lpc_order -le $blocksize ] ; then
200                                         test_file noise8m32 1 8 "-8 -p -e -l $lpc_order --lax --blocksize=$blocksize $disable"
201                         fi
202                 done
203         done
204 done
205
206 echo "Testing some frame header variations..."
207 test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax -b $max_lpc_order"
208 test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax -b 65535"
209 test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=9"
210 test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=90"
211 test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=90000"
212 test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=9"
213 test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=90"
214 test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=90000"
215
216 echo "Testing option variations..."
217 for f in 00 01 02 03 04 ; do
218         for disable in '' '--disable-verbatim-subframes --disable-constant-subframes' '--disable-verbatim-subframes --disable-constant-subframes --disable-fixed-subframes' ; do
219                 if [ -z "$disable" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
220                         for opt in 0 1 2 4 5 6 8 ; do
221                                 for extras in '' '-p' '-e' ; do
222                                         if [ -z "$extras" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
223                                                 test_file sine16-$f 1 16 "-$opt $extras $disable"
224                                         fi
225                                 done
226                         done
227                         if [ "$FLAC__TEST_LEVEL" -gt 1 ] ; then
228                                 test_file sine16-$f 1 16 "-b 16384 -m -r 8 -l $max_lpc_order --lax -e -p $disable"
229                         fi
230                 fi
231         done
232 done
233
234 for f in 10 11 12 13 14 15 16 17 18 19 ; do
235         for disable in '' '--disable-verbatim-subframes --disable-constant-subframes' '--disable-verbatim-subframes --disable-constant-subframes --disable-fixed-subframes' ; do
236                 if [ -z "$disable" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
237                         for opt in 0 1 2 4 5 6 8 ; do
238                                 for extras in '' '-p' '-e' ; do
239                                         if [ -z "$extras" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
240                                                 test_file sine16-$f 2 16 "-$opt $extras $disable"
241                                         fi
242                                 done
243                         done
244                         if [ "$FLAC__TEST_LEVEL" -gt 1 ] ; then
245                                 test_file sine16-$f 2 16 "-b 16384 -m -r 8 -l $max_lpc_order --lax -e -p $disable"
246                         fi
247                 fi
248         done
249 done
250
251 echo "Testing noise..."
252 for disable in '' '--disable-verbatim-subframes --disable-constant-subframes' '--disable-verbatim-subframes --disable-constant-subframes --disable-fixed-subframes' ; do
253         if [ -z "$disable" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
254                 for channels in 1 2 4 8 ; do
255                         if [ $channels -le 2 ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
256                                 for bps in 8 16 24 ; do
257                                         for opt in 0 1 2 3 4 5 6 7 8 ; do
258                                                 for extras in '' '-p' '-e' ; do
259                                                         if [ -z "$extras" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
260                                                                 for blocksize in '' '--lax -b 32' '--lax -b 32768' '--lax -b 65535' ; do
261                                                                         if [ -z "$blocksize" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
262                                                                                 test_file noise $channels $bps "-$opt $extras $blocksize $disable"
263                                                                         fi
264                                                                 done
265                                                         fi
266                                                 done
267                                         done
268                                         if [ "$FLAC__TEST_LEVEL" -gt 1 ] ; then
269                                                 test_file noise $channels $bps "-b 16384 -m -r 8 -l $max_lpc_order --lax -e -p $disable"
270                                         fi
271                                 done
272                         fi
273                 done
274         fi
275 done