bitwriter.c : Add missing "extern" declaration
[platform/upstream/flac.git] / test / test_seeking.sh
1 #!/bin/sh
2
3 #  FLAC - Free Lossless Audio Codec
4 #  Copyright (C) 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=../src/libFLAC/.libs:$LD_LIBRARY_PATH
33 LD_LIBRARY_PATH=../objs/$BUILD/lib:$LD_LIBRARY_PATH
34 export LD_LIBRARY_PATH
35 export MALLOC_CHECK_=3
36 export MALLOC_PERTURB_=$((RANDOM % 255 + 1))
37 PATH=../src/flac:$PATH
38 PATH=../src/metaflac:$PATH
39 PATH=../src/test_seeking:$PATH
40 PATH=../src/test_streams:$PATH
41 PATH=../objs/$BUILD/bin:$PATH
42
43 if [ x"$FLAC__TEST_LEVEL" = x ] ; then
44         FLAC__TEST_LEVEL=1
45 fi
46
47 flac --help 1>/dev/null 2>/dev/null || die "ERROR can't find flac executable"
48 metaflac --help 1>/dev/null 2>/dev/null || die "ERROR can't find metaflac executable"
49
50 run_flac ()
51 {
52         if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
53                 echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 flac $*" >>test_seeking.valgrind.log
54                 valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 flac $* 4>>test_seeking.valgrind.log
55         else
56                 flac $*
57         fi
58 }
59
60 run_metaflac ()
61 {
62         if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
63                 echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 metaflac $*" >>test_seeking.valgrind.log
64                 valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 metaflac $* 4>>test_seeking.valgrind.log
65         else
66                 metaflac $*
67         fi
68 }
69
70 run_test_seeking ()
71 {
72         if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
73                 echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 test_seeking $*" >>test_seeking.valgrind.log
74                 valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 test_seeking $* 4>>test_seeking.valgrind.log
75         else
76                 test_seeking $*
77         fi
78 }
79
80 echo "Checking for --ogg support in flac..."
81 if flac --ogg --silent --force-raw-format --endian=little --sign=signed --channels=1 --bps=8 --sample-rate=44100 -c $0 1>/dev/null 2>&1 ; then
82         has_ogg=yes;
83         echo "flac --ogg works"
84 else
85         has_ogg=no;
86         echo "flac --ogg doesn't work"
87 fi
88
89
90 echo "Generating streams..."
91 if [ ! -f noise.raw ] ; then
92         test_streams || die "ERROR during test_streams"
93 fi
94
95 echo "generating FLAC files for seeking:"
96 run_flac --verify --force --silent --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=8 --channels=1 --blocksize=576 -S- --output-name=tiny.flac noise8m32.raw || die "ERROR generating FLAC file"
97 run_flac --verify --force --silent --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=16 --channels=2 --blocksize=576 -S- --output-name=small.flac noise.raw || die "ERROR generating FLAC file"
98 run_flac --verify --force --silent --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=8 --channels=1 --blocksize=576 -S10x --output-name=tiny-s.flac noise8m32.raw || die "ERROR generating FLAC file"
99 run_flac --verify --force --silent --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=16 --channels=2 --blocksize=576 -S10x --output-name=small-s.flac noise.raw || die "ERROR generating FLAC file"
100
101 tiny_samples=`metaflac --show-total-samples tiny.flac`
102 small_samples=`metaflac --show-total-samples small.flac`
103
104 tiny_seek_count=100
105 if [ "$FLAC__TEST_LEVEL" -gt 1 ] ; then
106         small_seek_count=10000
107 else
108         small_seek_count=100
109 fi
110
111 for suffix in '' '-s' ; do
112         echo "testing tiny$suffix.flac:"
113         if run_test_seeking tiny$suffix.flac $tiny_seek_count $tiny_samples noise8m32.raw ; then : ; else
114                 die "ERROR: during test_seeking"
115         fi
116
117         echo "testing small$suffix.flac:"
118         if run_test_seeking small$suffix.flac $small_seek_count $small_samples noise.raw ; then : ; else
119                 die "ERROR: during test_seeking"
120         fi
121
122         echo "removing sample count from tiny$suffix.flac and small$suffix.flac:"
123         if run_metaflac --no-filename --set-total-samples=0 tiny$suffix.flac small$suffix.flac ; then : ; else
124                 die "ERROR: during metaflac"
125         fi
126
127         echo "testing tiny$suffix.flac with total_samples=0:"
128         if run_test_seeking tiny$suffix.flac $tiny_seek_count $tiny_samples noise8m32.raw ; then : ; else
129                 die "ERROR: during test_seeking"
130         fi
131
132         echo "testing small$suffix.flac with total_samples=0:"
133         if run_test_seeking small$suffix.flac $small_seek_count $small_samples noise.raw ; then : ; else
134                 die "ERROR: during test_seeking"
135         fi
136 done
137
138 if [ $has_ogg = "yes" ] ; then
139
140         echo "generating Ogg FLAC files for seeking:"
141         run_flac --verify --force --silent --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=8 --channels=1 --blocksize=576 --output-name=tiny.oga --ogg noise8m32.raw || die "ERROR generating Ogg FLAC file"
142         run_flac --verify --force --silent --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=16 --channels=2 --blocksize=576 --output-name=small.oga --ogg noise.raw || die "ERROR generating Ogg FLAC file"
143         # seek tables are not used in Ogg FLAC
144
145         echo "testing tiny.oga:"
146         if run_test_seeking tiny.oga $tiny_seek_count $tiny_samples noise8m32.raw ; then : ; else
147                 die "ERROR: during test_seeking"
148         fi
149
150         echo "testing small.oga:"
151         if run_test_seeking small.oga $small_seek_count $small_samples noise.raw ; then : ; else
152                 die "ERROR: during test_seeking"
153         fi
154
155 fi
156
157 rm -f tiny.flac tiny.oga small.flac small.oga tiny-s.flac small-s.flac