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