[5077] | 1 | #!/bin/bash
|
---|
| 2 | #This bash script calls the dailyrun.m matlab file to run our daily test decks.
|
---|
| 3 | #It then processes the results and sends an email to the Ice developpers.
|
---|
| 4 |
|
---|
[5082] | 5 | #Hard coded options
|
---|
| 6 | NUMCPUS_RUN=7
|
---|
| 7 | NROPTIONS=""
|
---|
| 8 |
|
---|
[5077] | 9 | #some functions
|
---|
| 10 | function timer() #{{{1
|
---|
| 11 | {
|
---|
| 12 | if [[ $# -eq 0 ]]; then
|
---|
| 13 | echo $(date '+%s')
|
---|
| 14 | else
|
---|
| 15 | local stime=$1
|
---|
| 16 | etime=$(date '+%s')
|
---|
| 17 |
|
---|
| 18 | if [[ -z "$stime" ]]; then stime=$etime; fi
|
---|
| 19 |
|
---|
| 20 | dt=$((etime - stime))
|
---|
| 21 | ds=$((dt % 60))
|
---|
| 22 | dm=$(((dt / 60) % 60))
|
---|
| 23 | dh=$((dt / 3600))
|
---|
| 24 | printf '%d:%02d:%02d' $dh $dm $ds
|
---|
| 25 | fi
|
---|
| 26 | } #}}}
|
---|
| 27 | function todaydate() #{{{1
|
---|
| 28 | {
|
---|
| 29 | suffix=`date | awk '{printf("%s-%s-%s %s",$2,$3,$6,$4);}'`
|
---|
| 30 | echo $suffix;
|
---|
| 31 | } #}}}
|
---|
| 32 | function host_name() #{{{1
|
---|
| 33 | {
|
---|
| 34 | #return host name depending on the OS
|
---|
| 35 | if [ "$1" = "winxp32" ]
|
---|
| 36 | then
|
---|
| 37 | HOST_NAME=`hostname`;
|
---|
| 38 | else
|
---|
| 39 | HOST_NAME=`hostname -s`;
|
---|
| 40 | fi
|
---|
| 41 | echo $HOST_NAME;
|
---|
| 42 | } #}}}
|
---|
| 43 |
|
---|
| 44 | #Get configuration
|
---|
| 45 | #Initialize variables {{{1
|
---|
| 46 | TODAY=$(todaydate);
|
---|
| 47 | HOST_NAME=$(host_name $OS);
|
---|
| 48 | START_TIME=$(timer);
|
---|
| 49 | ISSM_RELEASE="N/A"
|
---|
| 50 | USER=$(whoami);
|
---|
| 51 | INIT_PATH=$(pwd);
|
---|
| 52 | #}}}
|
---|
| 53 |
|
---|
| 54 | #Prepare run
|
---|
| 55 | #Windows hack for startup.m {{{1
|
---|
[12159] | 56 | #windows environments: ISSM_DIR_WIN variable not correctly picked up when using
|
---|
| 57 | #the cron job. just get startup to take the ISSM_DIR variable as the pwd:
|
---|
[5077] | 58 | if [ "$OS" = "winxp32" ]
|
---|
| 59 | then
|
---|
[12159] | 60 | cat startup.m | sed 's/clear status/clear status; ISSM_DIR=pwd;/g' > startup.m.bak
|
---|
[5077] | 61 | mv startup.m.bak startup.m
|
---|
| 62 | fi
|
---|
| 63 | #}}}
|
---|
[5082] | 64 | #create softlink to startup {{{1
|
---|
[12159] | 65 | cd $ISSM_DIR/test/NightlyRun/
|
---|
| 66 | ln -s $ISSM_DIR/startup.m .
|
---|
[5082] | 67 | #}}}
|
---|
| 68 | #Create dailylog directory and info.log {{{1
|
---|
| 69 | #put installation elapsed time in info.log
|
---|
[5077] | 70 | INSTALL_TIME=$(timer)
|
---|
| 71 | ELAPSED_INSTALL=$(timer $START_TIME)
|
---|
[12159] | 72 | rm -rf $ISSM_DIR/dailylog
|
---|
| 73 | mkdir $ISSM_DIR/dailylog
|
---|
| 74 | cat << END > $ISSM_DIR/dailylog/info.log
|
---|
[5077] | 75 | today: $(echo $TODAY)
|
---|
| 76 | user: $(echo $USER)
|
---|
| 77 | host: $(echo $HOST_NAME)
|
---|
| 78 | OS: N/A
|
---|
| 79 | release: N/A
|
---|
| 80 | init_path: $(echo $INIT_PATH)
|
---|
| 81 | elapsed_install: $(echo $ELAPSED_INSTALL)
|
---|
| 82 | END
|
---|
| 83 | #}}}
|
---|
[5082] | 84 | #check NUMCPUS_RUN options {{{1
|
---|
| 85 | if [ "$NUMCPUS_RUN" = "" ]
|
---|
| 86 | then
|
---|
| 87 | echo "NUMCPUS_RUN option not found, defaulting to NUMCPUS_RUN = 1"
|
---|
| 88 | NUMCPUS_RUN=1
|
---|
| 89 | fi
|
---|
| 90 | #}}}
|
---|
[5077] | 91 |
|
---|
| 92 | #Run tests
|
---|
[5082] | 93 | #Launch all tests on different cpus {{{1
|
---|
| 94 | for (( i=1;i<=$NUMCPUS_RUN;i++ ))
|
---|
| 95 | do
|
---|
| 96 | #Launch matlab and the daily run script
|
---|
[12159] | 97 | cat > $ISSM_DIR/dailylog/matlab_run$i.m << EOF
|
---|
[5082] | 98 | warning off %necessary to avoid a info.log of several Go for parallel runs
|
---|
| 99 | try,
|
---|
[12159] | 100 | cd $ISSM_DIR/test/NightlyRun
|
---|
[5082] | 101 | startup;
|
---|
| 102 | $(if [ "$NROPTIONS" = "" ]
|
---|
| 103 | then
|
---|
| 104 | echo "runme('output','daily','rank',$i,'numprocs',$NUMCPUS_RUN);"
|
---|
| 105 | else
|
---|
| 106 | echo "runme($NROPTIONS,'output','daily','rank',$i,'numprocs',$NUMCPUS_RUN);"
|
---|
| 107 | fi
|
---|
| 108 | )
|
---|
| 109 | catch me,
|
---|
| 110 | %An error occured, get report and exit
|
---|
| 111 | directory=strsplit(pwd,'/');
|
---|
| 112 | message=getReport(me)
|
---|
[12159] | 113 | fid=fopen([ISSM_DIR '/dailylog/matlaberror.log'], 'at');
|
---|
[5082] | 114 | fprintf(fid,'\nMatlab error occured in: %s\n\n',directory{end});
|
---|
| 115 | fprintf(fid,'%s',message);
|
---|
| 116 | fclose(fid);
|
---|
| 117 | end
|
---|
[5591] | 118 | disp('MATLABEXITEDCORRECTLY');
|
---|
[5082] | 119 | exit
|
---|
| 120 | EOF
|
---|
| 121 |
|
---|
| 122 | #Start run from dailylog directory
|
---|
[12159] | 123 | cd $ISSM_DIR/dailylog/
|
---|
[5082] | 124 |
|
---|
| 125 | #Start test
|
---|
| 126 | MATLAB_VERSION="7.6" #7.2,7.4,7.6 and 7.8
|
---|
| 127 | /usr/local/pkgs/matlab-$MATLAB_VERSION/bin/matlab -nojvm -nosplash -r matlab_run$i -logfile matlab_log$i.log &
|
---|
| 128 | done
|
---|
| 129 |
|
---|
| 130 | #wait until matlab closes
|
---|
| 131 | wait
|
---|
[5077] | 132 | #}}}
|
---|
[5082] | 133 | #concatenate all reports {{{1
|
---|
[12159] | 134 | cd $ISSM_DIR/dailylog/
|
---|
[5082] | 135 | mv matlab_log1.log matlab_log.log
|
---|
| 136 | for (( i=2;i<=$NUMCPUS_RUN;i++ ))
|
---|
| 137 | do
|
---|
| 138 | cat matlab_log.log matlab_log$i.log > matlab_log.log.bak
|
---|
| 139 | mv matlab_log.log.bak matlab_log.log
|
---|
| 140 | done
|
---|
| 141 | #}}}
|
---|
| 142 | #Complete info.log {{{1
|
---|
[5591] | 143 | if [ $(cat matlab_log.log | grep "MATLABEXITEDCORRECTLY" | wc -l) -eq $NUMCPUS_RUN ]
|
---|
| 144 | then
|
---|
| 145 | MATLABCRASH=0
|
---|
| 146 | else
|
---|
| 147 | MATLABCRASH=1
|
---|
| 148 | fi
|
---|
[5077] | 149 | ELAPSED_RUN=$(timer $INSTALL_TIME)
|
---|
| 150 | ELAPSED_TOTAL=$(timer $START_TIME)
|
---|
[12159] | 151 | cat << END >> $ISSM_DIR/dailylog/info.log
|
---|
[5077] | 152 | elapsed_run: $(echo $ELAPSED_RUN)
|
---|
| 153 | elapsed_total: $(echo $ELAPSED_TOTAL)
|
---|
[5591] | 154 | matlab_crash: $(echo $MATLABCRASH)
|
---|
[5077] | 155 | END
|
---|
| 156 | #}}}
|
---|
| 157 |
|
---|
| 158 | #Send Report
|
---|
| 159 | #Build html report {{{1
|
---|
[12159] | 160 | cd $ISSM_DIR/dailylog/
|
---|
[5082] | 161 | sh ../scripts/report.sh
|
---|
[12159] | 162 | ln -s $ISSM_DIR/dailylog/report.html $INIT_PATH
|
---|
| 163 | echo "html report located in $ISSM_DIR/dailylog/report.html and $INIT_PATH/report.html"
|
---|
[5077] | 164 | #}}}
|
---|