README.osx wasn't easily readable in Finder. Revert back to
[sox.git] / src / tests.sh
blobaf4dad3de2cc17c5ffa7bc30e75c6f9708ba1f3d
1 #!/bin/sh
3 # SoX Regression Test script: Lossless file conversion
5 bindir="."
6 builddir="."
7 srcdir="."
9 if [ -f ./sox.exe ] ; then
10 EXEEXT=".exe"
11 else
12 EXEEXT=""
15 # Set options & allow user to override paths. Useful for testing an
16 # installed sox.
17 while [ $# -ne 0 ]; do
18 case "$1" in
19 -e)
20 echo=$1
23 -V)
24 verbose=$1
25 echo=$1
28 -a) # Perform each test up to 3 times with different #s of
29 all=all # channels; probably enough coverage without this though.
32 --bindir=*)
33 bindir=`echo $1 | sed 's/.*=//'`
36 -i)
37 shift
38 bindir=$1
41 --builddir=*)
42 builddir=`echo $1 | sed 's/.*=//'`
45 -b)
46 shift
47 builddir=$1
50 --srcdir=*)
51 srcdir=`echo $1 | sed 's/.*=//'`
54 -c)
55 shift
56 srcdir=$1
60 echo "Unknown option"
61 exit 1
62 esac
63 shift
64 done
66 getFormat () {
67 formatExt=$1; formatText=$1; formatFlags=""
68 case $1 in
69 al ) formatText="alaw" ;;
70 ul ) formatText="ulaw" ;;
71 wavu8)formatText="u8 in wav"; formatFlags="-u -1"; formatExt="wav" ;;
72 s1X ) formatText="s8 (swap bits)"; formatExt="s8"; formatFlags="-X" ;;
73 s1N ) formatText="s8 (swap nibbles)"; formatExt="s8"; formatFlags="-N" ;;
74 s1XN) formatText="s8 (swap nibbles & bits)"; formatExt="s8"; formatFlags="-X -N" ;;
75 esac
78 execute() {
79 if [ "${echo}x" != "x" ] ; then
80 echo $*
82 cmd=$1
83 shift
84 echo $* | xargs $cmd
87 convertToAndFrom () {
88 while [ $# != 0 ]; do
89 if [ "${skip}x" != "x" ] ; then
90 format1_skip=`echo ${skip} | grep ${format1}`
91 from_skip=`echo ${skip} | grep ${1}`
93 if [ "${format1_skip}x" = "x" -a "${from_skip}x" = "x" ] ; then
94 getFormat ${format1}; format1Ext=$formatExt; format1Text=$formatText; format1Flags=$formatFlags
95 getFormat $1; format2Ext=$formatExt; format2Text=$formatText; format2Flags=$formatFlags
96 execute ${bindir}/sox${EXEEXT} $verbose -RD -r $rate -c $channels -n $format1Flags input.$format1Ext synth $samples's' sin 300-3300 noise trapezium
97 execute ${bindir}/sox${EXEEXT} $verbose -RD -r $rate -c $channels $format1Flags input.$format1Ext $format2Flags intermediate.$format2Ext
98 execute ${bindir}/sox${EXEEXT} $verbose -RD -r $rate -c $channels $format2Flags intermediate.$format2Ext $format1Flags output.$format1Ext
99 intermediateReference=vectors/intermediate`echo "$channels $rate $format1Flags $format1Ext $format2Flags"|tr " " "_"`.$format2Ext
101 # Uncomment to generate new reference files
102 # N.B. new reference files must be manually checked for correctness
103 #cp -i intermediate.$format2Ext $intermediateReference
105 if test -f $intermediateReference
106 then
107 cmp -s $intermediateReference intermediate.$format2Ext
108 if [ "$?" != "0" ]
109 then
110 echo "*FAIL vector* channels=$channels \"$format1Text\" ---> \"$format2Text\"."
111 exit 1 # This allows failure inspection.
113 vectors=`expr $vectors + 1`
116 if cmp -s input.$format1Ext output.$format1Ext
117 then
118 echo "ok channels=$channels \"$format1Text\" <--> \"$format2Text\"."
119 else
120 echo "*FAIL* channels=$channels \"$format1Text\" <--> \"$format2Text\"."
121 exit 1 # This allows failure inspection.
123 rm -f input.$format1Ext intermediate.$format2Ext output.$format1Ext
125 shift
126 done
129 do_multichannel_formats () {
130 format1=u8
131 convertToAndFrom s8 u8 s16 u16 s24 u24 s32 u32 f32 f64 dat au wav aiff aifc flac caf sph wv sox
133 format1=s16
134 convertToAndFrom s16 u16 s24 u24 s32 u32 f32 f64 dat au wav aiff aifc flac caf sph wv sox
136 format1=u24
137 convertToAndFrom s24 u24 s32 u32 f32 f64 wav aiff aifc flac sph wv sox
138 (samples=23500; convertToAndFrom paf) || exit 1
140 format1=s32
141 convertToAndFrom s32 u32 f64 wav aiff aifc caf sph wv mat4 mat5 sox
143 format1=al
144 convertToAndFrom al s16 u16 s32 f32 f64 dat aiff aifc flac caf w64
146 format1=ul
147 convertToAndFrom ul s16 u16 s32 f32 f64 dat aiff aifc flac caf sph
149 format1=wavu8
150 convertToAndFrom wavu8 aiff aifc au dat sf flac caf sph
153 do_twochannel_formats () {
154 format1=wavu8
155 convertToAndFrom avr maud
156 (rate=8000; convertToAndFrom voc) || exit 1 # Fixed rate
157 (samples=23492; convertToAndFrom 8svx) || exit 1 # Even number of samples only
160 do_singlechannel_formats () {
161 format1=vox
162 convertToAndFrom vox s16 u16 s24 u24 s32 u32 f32 f64 dat au wav aiff aifc flac caf sox
164 format1=ima
165 convertToAndFrom ima s16 u16 s24 u24 s32 u32 f32 f64 dat au aiff aifc flac caf # FIXME: wav
167 format1=wavu8
168 convertToAndFrom smp s8 s1X s1N s1XN sndt sndr
169 #(rate=50000; convertToAndFrom txw) || exit 1 # FIXME
170 (rate=11025; convertToAndFrom hcom) || exit 1 # Fixed rates
172 format1=wve
173 (rate=8000; convertToAndFrom al s16 u16 s32 f32 f64 dat) || exit 1 # Fixed rate
175 format1=prc
176 (rate=8000; convertToAndFrom al s16 u16 s32 f32 f64 dat) || exit 1 # Fixed rate
179 stderr_time () {
180 egrep -v "^real |^user |^sys " $1 1>&2
181 grep "^user " $1 | sed "s/^user //"
184 # Reading and writing performance test
185 time="/usr/bin/time -p"
186 timeIO () {
187 $time ${bindir}/sox${EXEEXT} -c $channels -r $rate -n tmp.sox synth $samples's' saw 0:`expr $rate / 2` noise brown vol .9 2> tmp.write
188 echo TIME synth channels=$channels samples=$samples `stderr_time tmp.write`s
189 if [ `uname` != SunOS ]; then
190 while [ $# != 0 ]; do
191 if [ "${skip}x" != "x" ] ; then
192 from_skip=`echo ${skip} | grep ${1}`
194 if [ "${from_skip}x" = "x" ] ; then
195 getFormat $1;
196 ($time ${bindir}/sox${EXEEXT} $verbose -D tmp.sox $formatFlags -t $1 - 2> tmp.read) | \
197 ($time ${bindir}/sox${EXEEXT} $verbose -t $1 -c $channels -r $rate - -t sox /dev/null 2> tmp.write)
198 echo "TIME `printf %4s $formatText` write=`stderr_time tmp.write`s read=`stderr_time tmp.read`s"
200 shift
201 done
203 rm -f tmp.sox tmp.write tmp.read
206 # Don't try to test un-built formats
207 skip_check () {
208 while [ $# -ne 0 ]; do
209 ${bindir}/sox${EXEEXT} --help|grep "^AUDIO FILE.*\<$1\>">/dev/null || skip="$1 $skip"
210 shift
211 done
215 # Run tests
217 ${builddir}/sox_sample_test${EXEEXT} || exit 1
219 skip_check caf flac mat4 mat5 paf w64 wv
221 vectors=0
223 rate=44100
224 samples=23493
226 channels=3
227 do_multichannel_formats
229 channels=2
230 if [ "$all" = "all" ]; then
231 do_multichannel_formats
233 do_twochannel_formats
234 format1=cdda # 2-channel only
235 convertToAndFrom s16 u24 aiff
237 channels=1
238 if [ "$all" = "all" ]; then
239 do_multichannel_formats
240 do_twochannel_formats
242 do_singlechannel_formats
244 if false; then # needs skip & dir work for general use
245 ${srcdir}/test-comments
246 if [ $? -eq 0 ]; then
247 echo "ok comments"
248 else
249 echo "*FAIL* comments"
250 exit 1
254 ${bindir}/sox${EXEEXT} -c 1 -r 44100 -n output.u8 synth .01 vol .5
255 if [ `wc -c <output.u8` = 441 ]; then
256 echo "ok synth size"
257 else
258 echo "*FAIL* synth size"
260 rm output.u8
262 echo "Checked $vectors vectors"
264 channels=2
265 samples=1e7
266 timeIO s8 u8 s16 u16 s24 u24 s32 u32 f32 f64 au wav aiff aifc sph # FIXME?: caf flac dat
268 test -n "$skip" && echo "Skipped: $skip"
270 # Run one last command so return code is not error
271 # when $skip is empty.
272 echo "done."