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