d33ef2a68c6f81b855fbe791736f920bff61b92b
[platform/upstream/flac.git] / test / test_seeking.sh
1 #!/bin/sh
2
3 #  FLAC - Free Lossless Audio Codec
4 #  Copyright (C) 2004-2009  Josh Coalson
5 #  Copyright (C) 2011-2013  Xiph.Org Foundation
6 #
7 #  This file is part the FLAC project.  FLAC is comprised of several
8 #  components distributed under difference licenses.  The codec libraries
9 #  are distributed under Xiph.Org's BSD-like license (see the file
10 #  COPYING.Xiph in this distribution).  All other programs, libraries, and
11 #  plugins are distributed under the GPL (see COPYING.GPL).  The documentation
12 #  is distributed under the Gnu FDL (see COPYING.FDL).  Each file in the
13 #  FLAC distribution contains at the top the terms under which it may be
14 #  distributed.
15 #
16 #  Since this particular file is relevant to all components of FLAC,
17 #  it may be distributed under the Xiph.Org license, which is the least
18 #  restrictive of those mentioned above.  See the file COPYING.Xiph in this
19 #  distribution.
20
21 die ()
22 {
23         echo $* 1>&2
24         exit 1
25 }
26
27 if [ x = x"$1" ] ; then 
28         BUILD=debug
29 else
30         BUILD="$1"
31 fi
32
33 LD_LIBRARY_PATH=../src/libFLAC/.libs:$LD_LIBRARY_PATH
34 LD_LIBRARY_PATH=../objs/$BUILD/lib:$LD_LIBRARY_PATH
35 export LD_LIBRARY_PATH
36 export MALLOC_CHECK_=3
37 export MALLOC_PERTURB_=$((RANDOM % 255 + 1))
38 PATH=../src/flac:$PATH
39 PATH=../src/metaflac:$PATH
40 PATH=../src/test_seeking:$PATH
41 PATH=../src/test_streams:$PATH
42 PATH=../objs/$BUILD/bin:$PATH
43
44 if [ x"$FLAC__TEST_LEVEL" = x ] ; then
45         FLAC__TEST_LEVEL=1
46 fi
47
48 flac --help 1>/dev/null 2>/dev/null || die "ERROR can't find flac executable"
49 metaflac --help 1>/dev/null 2>/dev/null || die "ERROR can't find metaflac executable"
50
51 run_flac ()
52 {
53         if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
54                 echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 flac $*" >>test_seeking.valgrind.log
55                 valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 flac $* 4>>test_seeking.valgrind.log
56         else
57                 flac $*
58         fi
59 }
60
61 run_metaflac ()
62 {
63         if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
64                 echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 metaflac $*" >>test_seeking.valgrind.log
65                 valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 metaflac $* 4>>test_seeking.valgrind.log
66         else
67                 metaflac $*
68         fi
69 }
70
71 run_test_seeking ()
72 {
73         if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
74                 echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 test_seeking $*" >>test_seeking.valgrind.log
75                 valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 test_seeking $* 4>>test_seeking.valgrind.log
76         else
77                 test_seeking $*
78         fi
79 }
80
81 echo "Checking for --ogg support in flac..."
82 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
83         has_ogg=yes;
84         echo "flac --ogg works"
85 else
86         has_ogg=no;
87         echo "flac --ogg doesn't work"
88 fi
89
90
91 echo "Generating streams..."
92 if [ ! -f noise.raw ] ; then
93         test_streams || die "ERROR during test_streams"
94 fi
95
96 echo "generating FLAC files for seeking:"
97 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"
98 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"
99 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"
100 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"
101
102 tiny_samples=`metaflac --show-total-samples tiny.flac`
103 small_samples=`metaflac --show-total-samples small.flac`
104
105 tiny_seek_count=100
106 if [ "$FLAC__TEST_LEVEL" -gt 1 ] ; then
107         small_seek_count=10000
108 else
109         small_seek_count=100
110 fi
111
112 for suffix in '' '-s' ; do
113         echo "testing tiny$suffix.flac:"
114         if run_test_seeking tiny$suffix.flac $tiny_seek_count $tiny_samples noise8m32.raw ; then : ; else
115                 die "ERROR: during test_seeking"
116         fi
117
118         echo "testing small$suffix.flac:"
119         if run_test_seeking small$suffix.flac $small_seek_count $small_samples noise.raw ; then : ; else
120                 die "ERROR: during test_seeking"
121         fi
122
123         echo "removing sample count from tiny$suffix.flac and small$suffix.flac:"
124         if run_metaflac --no-filename --set-total-samples=0 tiny$suffix.flac small$suffix.flac ; then : ; else
125                 die "ERROR: during metaflac"
126         fi
127
128         echo "testing tiny$suffix.flac with total_samples=0:"
129         if run_test_seeking tiny$suffix.flac $tiny_seek_count $tiny_samples noise8m32.raw ; then : ; else
130                 die "ERROR: during test_seeking"
131         fi
132
133         echo "testing small$suffix.flac with total_samples=0:"
134         if run_test_seeking small$suffix.flac $small_seek_count $small_samples noise.raw ; then : ; else
135                 die "ERROR: during test_seeking"
136         fi
137 done
138
139 if [ $has_ogg = "yes" ] ; then
140
141         echo "generating Ogg FLAC files for seeking:"
142         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"
143         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"
144         # seek tables are not used in Ogg FLAC
145
146         echo "testing tiny.oga:"
147         if run_test_seeking tiny.oga $tiny_seek_count $tiny_samples noise8m32.raw ; then : ; else
148                 die "ERROR: during test_seeking"
149         fi
150
151         echo "testing small.oga:"
152         if run_test_seeking small.oga $small_seek_count $small_samples noise.raw ; then : ; else
153                 die "ERROR: during test_seeking"
154         fi
155
156 fi
157
158 rm -f tiny.flac tiny.oga small.flac small.oga tiny-s.flac small-s.flac