src/libFLAC/stream_decoder.c : Fix buffer read overflow.
[platform/upstream/flac.git] / test / test_grabbag.sh
1 #!/bin/sh
2
3 #  FLAC - Free Lossless Audio Codec
4 #  Copyright (C) 2001-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 different 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=../src/share/grabbag/.libs:$LD_LIBRARY_PATH
35 LD_LIBRARY_PATH=../src/share/replaygain_analysis/.libs:$LD_LIBRARY_PATH
36 LD_LIBRARY_PATH=../objs/$BUILD/lib:$LD_LIBRARY_PATH
37 export LD_LIBRARY_PATH
38 export MALLOC_CHECK_=3
39 export MALLOC_PERTURB_=$(($(date +%s) % 255 + 1))
40 PATH=../src/test_grabbag/cuesheet:$PATH
41 PATH=../src/test_grabbag/picture:$PATH
42 PATH=../objs/$BUILD/bin:$PATH
43
44 test_cuesheet -h 1>/dev/null 2>/dev/null || die "ERROR can't find test_cuesheet executable"
45 test_picture -h 1>/dev/null 2>/dev/null || die "ERROR can't find test_picture executable"
46
47 run_test_cuesheet ()
48 {
49         if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
50                 echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 test_cuesheet $*" >>test_grabbag.valgrind.log
51                 valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 test_cuesheet $* 4>>test_grabbag.valgrind.log
52         else
53                 test_cuesheet $*
54         fi
55 }
56
57 run_test_picture ()
58 {
59         if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
60                 echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 test_picture $*" >>test_grabbag.valgrind.log
61                 valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 test_picture $* 4>>test_grabbag.valgrind.log
62         else
63                 test_picture $*
64         fi
65 }
66
67 if [ `env | grep -ic '^comspec='` != 0 ] ; then
68         is_win=yes
69 else
70         is_win=no
71 fi
72
73 ########################################################################
74 #
75 # test_picture
76 #
77 ########################################################################
78
79 log=picture.log
80 picture_dir=pictures
81
82 echo "Running test_picture..."
83
84 rm -f $log
85
86 run_test_picture $picture_dir >> $log 2>&1
87
88 if [ $is_win = yes ] ; then
89         diff -w picture.ok $log > picture.diff || die "Error: .log file does not match .ok file, see picture.diff"
90 else
91         diff picture.ok $log > picture.diff || die "Error: .log file does not match .ok file, see picture.diff"
92 fi
93
94 echo "PASSED (results are in $log)"
95
96 ########################################################################
97 #
98 # test_cuesheet
99 #
100 ########################################################################
101
102 log=cuesheet.log
103 bad_cuesheets=cuesheets/bad.*.cue
104 good_cuesheets=cuesheets/good.*.cue
105 good_leadout=`expr 80 \* 60 \* 44100`
106 bad_leadout=`expr $good_leadout + 1`
107
108 echo "Running test_cuesheet..."
109
110 rm -f $log
111
112 #
113 # negative tests
114 #
115 for cuesheet in $bad_cuesheets ; do
116         echo "NEGATIVE $cuesheet" >> $log 2>&1
117         run_test_cuesheet $cuesheet $good_leadout 44100 cdda >> $log 2>&1
118         exit_code=$?
119         if [ "$exit_code" = 255 ] ; then
120                 die "Error: test script is broken"
121         fi
122         cuesheet_pass1=${cuesheet}.1
123         cuesheet_pass2=${cuesheet}.2
124         rm -f $cuesheet_pass1 $cuesheet_pass2
125 done
126
127 #
128 # positve tests
129 #
130 for cuesheet in $good_cuesheets ; do
131         echo "POSITIVE $cuesheet" >> $log 2>&1
132         run_test_cuesheet $cuesheet $good_leadout 44100 cdda >> $log 2>&1
133         exit_code=$?
134         if [ "$exit_code" = 255 ] ; then
135                 die "Error: test script is broken"
136         elif [ "$exit_code" != 0 ] ; then
137                 die "Error: good cuesheet is broken"
138         fi
139         cuesheet_pass1=${cuesheet}.1
140         cuesheet_pass2=${cuesheet}.2
141         diff $cuesheet_pass1 $cuesheet_pass2 >> $log 2>&1 || die "Error: pass1 and pass2 output differ"
142         rm -f $cuesheet_pass1 $cuesheet_pass2
143 done
144
145 if [ $is_win = yes ] ; then
146         diff -w cuesheet.ok $log > cuesheet.diff || die "Error: .log file does not match .ok file, see cuesheet.diff"
147 else
148         diff cuesheet.ok $log > cuesheet.diff || die "Error: .log file does not match .ok file, see cuesheet.diff"
149 fi
150
151 echo "PASSED (results are in $log)"