Initial import to Tizen
[profile/ivi/sphinxbase.git] / test / regression / tutorial-check.sh
1 #!/bin/bash -x
2
3 # Check if we're running under PBS and print information useful for debugging
4 if [ -n "$PBS_ENVIRONMENT" ]; then
5     echo ""
6     echo "This job was submitted by user: $PBS_O_LOGNAME"
7     echo "This job was submitted to host: $PBS_O_HOST"
8     echo "This job was submitted to queue: $PBS_O_QUEUE"
9     echo "PBS working directory: $PBS_O_WORKDIR"
10     echo "PBS job id: $PBS_JOBID"
11     echo "PBS job name: $PBS_JOBNAME"
12     echo "PBS environment: $PBS_ENVIRONMENT"
13     echo ""
14     echo "This script is running on `hostname` "
15     echo ""
16 fi
17
18 # make sure that /usr/ucb is here, towards the beginning, to make sure
19 # that the 'ps' command in Solaris is compatible with the gnu one.
20 export PATH=/usr/ucb:/usr/local/bin:${PATH}
21
22 loopUntilSuccess () {
23     cmd=$@
24     # start loop to download code
25     count=0;
26
27     while ! $cmd; do
28         count=`expr $count + 1`
29         if [ $count -gt 50 ]; then
30             # not successful, and we attempted it too many times. Clean up and leave.
31             return $count
32         fi
33     done
34 }
35
36 # Check that we have all executables
37 if ! WGET=`command -v wget 2>&1`; then exit 1; fi
38 if ! SVN=`command -v svn 2>&1`; then exit 1; fi
39 if ! PERL=`command -v perl 2>&1`; then exit 1; fi
40 if ! MAKE=`command -v gmake 2>&1`; then 
41   if ! MAKE=`command -v make 2>&1`; then exit 1; fi
42 fi
43 if ! TAR=`command -v gtar 2>&1`; then
44   if ! TAR=`command -v tar 2>&1`; then exit 1; fi
45 fi
46 if ! MAIL=`command -v mhmail 2>&1`; then
47   if ! MAIL=`command -v mailx 2>&1`; then
48     if ! MAIL=`command -v sendmail 2>&1`; then
49       if ! MAIL=`command -v mutt 2>&1`; then exit 1; fi
50     fi
51   fi
52 fi
53
54 # Create temp directory
55 temp_dir=/tmp/temp$$
56 mkdir $temp_dir
57 pushd $temp_dir > /dev/null
58
59 LOG=$temp_dir/log.txt
60 echo > $LOG
61 MAILLIST=cmusphinx-results@lists.sourceforge.net
62
63 # Get the data
64 ${WGET} -q http://www.speech.cs.cmu.edu/databases/an4/an4_sphere.tar.gz
65 ${TAR} -xzf an4_sphere.tar.gz
66 /bin/rm an4_sphere.tar.gz
67
68 # Get sphinxbase
69 if (loopUntilSuccess ${SVN} co https://cmusphinx.svn.sourceforge.net/svnroot/cmusphinx/trunk/sphinxbase > /dev/null &&
70 cd sphinxbase &&
71 ./autogen.sh &&
72 ./autogen.sh CFLAGS="-O2 -Wall" --prefix=`(cd ..; pwd)`/build &&
73 ${MAKE} all install) >> $LOG 2>&1 ; then
74
75 # Get the trainer
76 if (loopUntilSuccess ${SVN} co https://cmusphinx.svn.sourceforge.net/svnroot/cmusphinx/trunk/SphinxTrain > /dev/null &&
77 cd SphinxTrain &&
78 ./configure CFLAGS="-O2 -Wall" --with-sphinxbase=$temp_dir/sphinxbase && 
79 ${MAKE} && 
80 ${PERL} scripts_pl/setup_tutorial.pl an4) >> $LOG 2>&1 ; then
81
82 # Get the decoder
83 if (loopUntilSuccess ${SVN} co https://cmusphinx.svn.sourceforge.net/svnroot/cmusphinx/trunk/sphinx3 > /dev/null &&
84 cd sphinx3 &&
85 ./autogen.sh &&
86 ./autogen.sh  CFLAGS="-O2 -Wall" --prefix=`(cd ..; pwd)`/build --with-sphinxbase=$temp_dir/sphinxbase && 
87 ${MAKE} all install && 
88 ${PERL} scripts/setup_tutorial.pl an4) >> $LOG 2>&1 ; then
89
90 # Run it
91 cd an4 &&
92 perl scripts_pl/make_feats.pl -ctl etc/an4_train.fileids >> $LOG 2>&1 &&
93 perl scripts_pl/make_feats.pl -ctl etc/an4_test.fileids >> $LOG 2>&1 &&
94 perl scripts_pl/RunAll.pl >> $LOG 2>&1 &&
95 perl scripts_pl/decode/slave.pl >> $LOG 2>&1
96
97 # end of if (sphinx3)
98 fi
99 # end of if (SphinxTrain)
100 fi
101 # end of sphinxbase
102 fi
103
104 # Check whether the Word Error Rate is reasonable, hardwired for now
105 if SER=`grep 'SENTENCE ERROR' $LOG 2>&1`; then
106 SUCCESS=`echo $SER | awk '{d = $(3) - 57};{if (d < 0) d = -d};{if (d < 2) print "1"}'`;
107 fi;
108
109 # Send mail if we failed
110 if test x${SUCCESS} == x ; then
111 cat `find $temp_dir/an4/logdir/ -type f -print | tail -1` >> ${LOG}
112 $MAIL -s "Tutorial failed" ${MAILLIST} < ${LOG}
113 else
114 echo $SER | $MAIL -s "Tutorial succeded" ${MAILLIST}
115 fi
116
117 # Remove what we created
118 popd > /dev/null
119 /bin/rm -rf $temp_dir