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