extend tests with --disable-...-subframe loops; precursor to valgrind support
[platform/upstream/flac.git] / test / test_streams.sh
1 #!/bin/sh
2
3 #  FLAC - Free Lossless Audio Codec
4 #  Copyright (C) 2001,2002  Josh Coalson
5 #
6 #  This program is part of FLAC; you can redistribute it and/or
7 #  modify it under the terms of the GNU General Public License
8 #  as published by the Free Software Foundation; either version 2
9 #  of the License, or (at your option) any later version.
10 #
11 #  This program is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #  GNU General Public License for more details.
15 #
16 #  You should have received a copy of the GNU General Public License
17 #  along with this program; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20 LD_LIBRARY_PATH=../src/libFLAC/.libs:../obj/lib:$LD_LIBRARY_PATH
21 export LD_LIBRARY_PATH
22 PATH=../src/flac:../src/test_streams:../obj/bin:$PATH
23
24 flac --help 1>/dev/null 2>/dev/null || (echo "ERROR can't find flac executable" 1>&2 && exit 1)
25 if [ $? != 0 ] ; then exit 1 ; fi
26
27 echo "Generating streams..."
28 if test_streams ; then : ; else
29         echo "ERROR during test_streams" 1>&2
30         exit 1
31 fi
32
33 echo "Checking for --ogg support in flac..."
34 if flac --ogg wacky1.wav 1>/dev/null 2>&1 ; then
35         has_ogg=yes;
36         echo "flac --ogg works"
37 else
38         has_ogg=no;
39         echo "flac --ogg doesn't work"
40 fi
41
42 #FLAC="valgrind --leak-check=yes --show-reachable=yes --logfile-fd=1 flac"
43 FLAC=flac
44
45 #
46 # multi-file tests
47 #
48 echo "Generating multiple input files from noise..."
49 if $FLAC --verify --silent --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=16 --channels=2 noise.raw ; then : ; else
50         echo "ERROR generating FLAC file" 1>&2
51         exit 1
52 fi
53 if $FLAC --decode --silent noise.flac ; then : ; else
54         echo "ERROR generating WAVE file" 1>&2
55         exit 1
56 fi
57 rm -f noise.flac
58 mv noise.wav file0.wav
59 cp file0.wav file1.wav
60 cp file1.wav file2.wav
61
62 test_multifile ()
63 {
64         streamtype=$1
65         sector_align=$2
66         encode_options="$3"
67
68         if [ $streamtype = ogg ] ; then
69                 suffix=ogg
70                 encode_options="$encode_options --ogg"
71         else
72                 suffix=flac
73         fi
74
75         if [ $sector_align = sector_align ] ; then
76                 encode_options="$encode_options --sector-align"
77         fi
78
79         if $FLAC $encode_options file0.wav file1.wav file2.wav ; then : ; else
80                 echo "ERROR" 1>&2
81                 exit 1
82         fi
83         for n in 0 1 2 ; do
84                 mv file$n.$suffix file${n}x.$suffix
85         done
86         if $FLAC --decode file0x.$suffix file1x.$suffix file2x.$suffix ; then : ; else
87                 echo "ERROR" 1>&2
88                 exit 1
89         fi
90         if [ $sector_align != sector_align ] ; then
91                 for n in 0 1 2 ; do
92                         if cmp file$n.wav file${n}x.wav ; then : ; else
93                                 echo "ERROR: file mismatch on file #$n" 1>&2
94                                 exit 1
95                         fi
96                 done
97         fi
98         for n in 0 1 2 ; do
99                 rm -f file${n}x.$suffix file${n}x.wav
100         done
101 }
102
103 echo "Testing multiple files without verify..."
104 test_multifile flac no_sector_align ""
105
106 echo "Testing multiple files with verify..."
107 test_multifile flac no_sector_align "--verify"
108
109 echo "Testing multiple files with --sector-align, without verify..."
110 test_multifile flac sector_align ""
111
112 echo "Testing multiple files with --sector-align, with verify..."
113 test_multifile flac sector_align "--verify"
114
115 if [ $has_ogg = "yes" ] ; then
116         echo "Testing multiple files with --ogg, without verify..."
117         test_multifile ogg no_sector_align ""
118
119         echo "Testing multiple files with --ogg, with verify..."
120         test_multifile ogg no_sector_align "--verify"
121
122         echo "Testing multiple files with --ogg and --sector-align, without verify..."
123         test_multifile ogg sector_align ""
124
125         echo "Testing multiple files with --ogg and --sector-align, with verify..."
126         test_multifile sector_align ogg "--verify"
127
128         echo "Testing multiple files with --ogg and --serial-number, with verify..."
129         test_multifile ogg no_sector_align "--serial-number=321 --verify"
130 fi
131
132 #
133 # single-file tests
134 #
135
136 test_file ()
137 {
138         name=$1
139         channels=$2
140         bps=$3
141         encode_options="$4"
142
143         echo -n "$name (--channels=$channels --bps=$bps $encode_options): encode..."
144         cmd="$FLAC --verify --silent --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=$bps --channels=$channels $encode_options $name.raw"
145         echo "### ENCODE $name #######################################################" >> ./streams.log
146         echo "###    cmd=$cmd" >> ./streams.log
147         if $cmd 2>>./streams.log ; then : ; else
148                 echo "ERROR during encode of $name" 1>&2
149                 exit 1
150         fi
151         echo -n "decode..."
152         cmd="$FLAC --silent --endian=big --sign=signed --decode --force-raw-format --output-name=$name.cmp $name.flac"
153         echo "### DECODE $name #######################################################" >> ./streams.log
154         echo "###    cmd=$cmd" >> ./streams.log
155         if $cmd 2>>./streams.log ; then : ; else
156                 echo "ERROR during decode of $name" 1>&2
157                 exit 1
158         fi
159         ls -1l $name.raw >> ./streams.log
160         ls -1l $name.flac >> ./streams.log
161         ls -1l $name.cmp >> ./streams.log
162         echo -n "compare..."
163         if cmp $name.raw $name.cmp ; then : ; else
164                 echo "ERROR during compare of $name" 1>&2
165                 exit 1
166         fi
167         echo OK
168 }
169
170 test_file_piped ()
171 {
172         name=$1
173         channels=$2
174         bps=$3
175         encode_options="$4"
176
177         if [ `env | grep -ic '^comspec='` != 0 ] ; then
178                 is_win=yes
179         else
180                 is_win=no
181         fi
182
183         echo -n "$name: encode via pipes..."
184         if [ $is_win = yes ] ; then
185                 cmd="$FLAC --verify --silent --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=$bps --channels=$channels $encode_options --stdout $name.raw"
186                 echo "### ENCODE $name #######################################################" >> ./streams.log
187                 echo "###    cmd=$cmd" >> ./streams.log
188                 if $cmd 1>$name.flac 2>>./streams.log ; then : ; else
189                         echo "ERROR during encode of $name" 1>&2
190                         exit 1
191                 fi
192         else
193                 cmd="$FLAC --verify --silent --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=$bps --channels=$channels $encode_options --stdout -"
194                 echo "### ENCODE $name #######################################################" >> ./streams.log
195                 echo "###    cmd=$cmd" >> ./streams.log
196                 if cat $name.raw | $cmd 1>$name.flac 2>>./streams.log ; then : ; else
197                         echo "ERROR during encode of $name" 1>&2
198                         exit 1
199                 fi
200         fi
201         echo -n "decode via pipes..."
202         if [ $is_win = yes ] ; then
203                 cmd="$FLAC --silent --endian=big --sign=signed --decode --force-raw-format --stdout $name.flac"
204                 echo "### DECODE $name #######################################################" >> ./streams.log
205                 echo "###    cmd=$cmd" >> ./streams.log
206                 if $cmd 1>$name.cmp 2>>./streams.log ; then : ; else
207                         echo "ERROR during decode of $name" 1>&2
208                         exit 1
209                 fi
210         else
211                 cmd="$FLAC --silent --endian=big --sign=signed --decode --force-raw-format --stdout -"
212                 echo "### DECODE $name #######################################################" >> ./streams.log
213                 echo "###    cmd=$cmd" >> ./streams.log
214                 if cat $name.flac | $cmd 1>$name.cmp 2>>./streams.log ; then : ; else
215                         echo "ERROR during decode of $name" 1>&2
216                         exit 1
217                 fi
218         fi
219         ls -1l $name.raw >> ./streams.log
220         ls -1l $name.flac >> ./streams.log
221         ls -1l $name.cmp >> ./streams.log
222         echo -n "compare..."
223         if cmp $name.raw $name.cmp ; then : ; else
224                 echo "ERROR during compare of $name" 1>&2
225                 exit 1
226         fi
227         echo OK
228 }
229
230 if [ "$FLAC__EXHAUSTIVE_TESTS" = yes ] ; then
231         max_lpc_order=32
232 else
233         max_lpc_order=16
234 fi
235
236 echo "Testing noise through pipes..."
237 test_file_piped noise 1 8 "-0"
238
239 echo "Testing small files..."
240 test_file test01 1 16 "-0 -l $max_lpc_order -m -e -p"
241 test_file test02 2 16 "-0 -l $max_lpc_order -m -e -p"
242 test_file test03 1 16 "-0 -l $max_lpc_order -m -e -p"
243 test_file test04 2 16 "-0 -l $max_lpc_order -m -e -p"
244
245 echo "Testing 8-bit full-scale deflection streams..."
246 for b in 01 02 03 04 05 06 07 ; do
247         test_file fsd8-$b 1 8 "-0 -l $max_lpc_order -m -e -p"
248 done
249
250 echo "Testing 16-bit full-scale deflection streams..."
251 for b in 01 02 03 04 05 06 07 ; do
252         test_file fsd16-$b 1 16 "-0 -l $max_lpc_order -m -e -p"
253 done
254
255 echo "Testing 24-bit full-scale deflection streams..."
256 for b in 01 02 03 04 05 06 07 ; do
257         test_file fsd24-$b 1 24 "-0 -l $max_lpc_order -m -e -p"
258 done
259
260 echo "Testing 16-bit wasted-bits-per-sample streams..."
261 for b in 01 ; do
262         test_file wbps16-$b 1 16 "-0 -l $max_lpc_order -m -e -p"
263 done
264
265 for bps in 8 16 24 ; do
266         echo "Testing $bps-bit sine wave streams..."
267         for b in 00 ; do
268                 test_file sine${bps}-$b 1 $bps "-0 -l $max_lpc_order -m -e --sample-rate=48000"
269         done
270         for b in 01 ; do
271                 test_file sine${bps}-$b 1 $bps "-0 -l $max_lpc_order -m -e --sample-rate=96000"
272         done
273         for b in 02 03 04 ; do
274                 test_file sine${bps}-$b 1 $bps "-0 -l $max_lpc_order -m -e"
275         done
276         for b in 10 11 ; do
277                 test_file sine${bps}-$b 2 $bps "-0 -l $max_lpc_order -m -e --sample-rate=48000"
278         done
279         for b in 12 ; do
280                 test_file sine${bps}-$b 2 $bps "-0 -l $max_lpc_order -m -e --sample-rate=96000"
281         done
282         for b in 13 14 15 16 17 18 19 ; do
283                 test_file sine${bps}-$b 2 $bps "-0 -l $max_lpc_order -m -e"
284         done
285 done
286
287 echo "Testing blocksize variations..."
288 for disable in '' '--disable-verbatim-subframes --disable-constant-subframes' '--disable-verbatim-subframes --disable-constant-subframes --disable-fixed-subframes' ; do
289         for blocksize in 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ; do
290                 for lpc_order in 0 1 2 3 4 5 7 8 9 15 16 17 31 32 ; do
291                         if [ $lpc_order = 0 ] || [ $lpc_order -le $blocksize ] ; then
292                                         test_file noise8m32 1 8 "-8 -p -e -l $lpc_order --lax --blocksize=$blocksize $disable"
293                         fi
294                 done
295         done
296 done
297
298 echo "Testing some frame header variations..."
299 test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax -b $max_lpc_order"
300 test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax -b 65535"
301 test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=9"
302 test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=90"
303 test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=90000"
304 test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=9"
305 test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=90"
306 test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=90000"
307
308 echo "Testing option variations..."
309 for f in 00 01 02 03 04 ; do
310         for disable in '' '--disable-verbatim-subframes --disable-constant-subframes' '--disable-verbatim-subframes --disable-constant-subframes --disable-fixed-subframes' ; do
311                 for opt in 0 1 2 4 5 6 8 ; do
312                         for extras in '' '-p' '-e' ; do
313                                 test_file sine16-$f 1 16 "-$opt $extras $disable"
314                         done
315                 done
316                 if [ "$FLAC__EXHAUSTIVE_TESTS" = yes ] ; then
317                         test_file sine16-$f 1 16 "-b 16384 -m -r 8 -l $max_lpc_order -e -p $disable"
318                 fi
319         done
320 done
321
322 for f in 10 11 12 13 14 15 16 17 18 19 ; do
323         for disable in '' '--disable-verbatim-subframes --disable-constant-subframes' '--disable-verbatim-subframes --disable-constant-subframes --disable-fixed-subframes' ; do
324                 for opt in 0 1 2 4 5 6 8 ; do
325                         for extras in '' '-p' '-e' ; do
326                                 test_file sine16-$f 2 16 "-$opt $extras $disable"
327                         done
328                 done
329                 if [ "$FLAC__EXHAUSTIVE_TESTS" = yes ] ; then
330                         test_file sine16-$f 2 16 "-b 16384 -m -r 8 -l $max_lpc_order -e -p $disable"
331                 fi
332         done
333 done
334
335 echo "Testing noise..."
336 for disable in '' '--disable-verbatim-subframes --disable-constant-subframes' '--disable-verbatim-subframes --disable-constant-subframes --disable-fixed-subframes' ; do
337         for channels in 1 2 4 8 ; do
338                 for bps in 8 16 24 ; do
339                         for opt in 0 1 2 3 4 5 6 7 8 ; do
340                                 for extras in '' '-p' '-e' ; do
341                                         for blocksize in '' '--lax -b 32' '--lax -b 32768' '--lax -b 65535' ; do
342                                                 test_file noise $channels $bps "-$opt $extras $blocksize $disable"
343                                         done
344                                 done
345                         done
346                         if [ "$FLAC__EXHAUSTIVE_TESTS" = yes ] ; then
347                                 test_file noise $channels $bps "-b 16384 -m -r 8 -l $max_lpc_order -e -p $disable"
348                         fi
349                 done
350         done
351 done