source:
issm/oecreview/Archive/16554-17801/ISSM-16605-16606.diff@
17802
Last change on this file since 17802 was 17802, checked in by , 11 years ago | |
---|---|
File size: 8.0 KB |
-
../trunk-jpl/scripts/jenkins.sh
1 #!/bin/bash2 #This bash script calls the nightlyrun.m matlab file to run our nightly test decks.3 #It then processes the results and sends an email to the Ice developpers.4 5 #some functions6 function timer() #{{{7 {8 if [[ $# -eq 0 ]]; then9 echo $(date '+%s')10 else11 local stime=$112 etime=$(date '+%s')13 14 if [[ -z "$stime" ]]; then stime=$etime; fi15 16 dt=$((etime - stime))17 ds=$((dt % 60))18 dm=$(((dt / 60) % 60))19 dh=$((dt / 3600))20 printf '%d:%02d:%02d' $dh $dm $ds21 fi22 } #}}}23 function todaydate() #{{{24 {25 suffix=`date | awk '{printf("%s-%s-%s %s",$2,$3,$6,$4);}'`26 echo $suffix;27 } #}}}28 function host_name() #{{{29 {30 #return host name depending on the OS31 if [ "$1" = "win7" ]32 then33 HOST_NAME=`hostname | sed 's/-//g'`;34 else35 HOST_NAME=`hostname -s | sed 's/-//g'`;36 fi37 echo $HOST_NAME;38 } #}}}39 function pause() #{{{40 {41 pid=`ps aux -W | grep $1 | awk '{printf("%s\n",$1);}'`42 43 while [ -n "$pid" ]44 do45 pid=`ps aux -W | grep $1 | awk '{printf("%s\n",$1);}'`46 done47 }48 #}}}49 50 #Get configuration51 #Source config file{{{52 if [ $# -ne 1 ];53 then54 #no config file specified: exit55 echo "no config file specified. Exiting..." >&2 # Error message to stderr.56 exit 157 fi58 if [ ! -f "$1" ]59 then60 echo "File $1 not found!" >&2 # Error message to stderr.61 exit 162 fi63 source $1;64 #}}}65 #Export ISSM_* variables{{{66 export ISSM_DIR67 export ISSM_ARCH68 #}}}69 #Initialize variables {{{70 TODAY=$(todaydate);71 HOST_NAME=$(host_name $OS);72 OS=$(uname -s)73 START_TIME=$(timer);74 ISSM_RELEASE=$(basename $(echo $REPOSITORY));75 USER=$(whoami);76 INIT_PATH=$(pwd);77 #}}}78 79 #Installation ISSM80 #create matlab's installation sript {{{81 cat << END > $ISSM_DIR/externalpackages/matlab/install.sh82 #!/bin/bash83 rm -rf install84 ln -s $MATLAB_PATH install85 END86 #}}}87 #install/copy/none external packages (ISSM_EXTERNALPACKAGES){{{88 if [ "$ISSM_EXTERNALPACKAGES" == "install" ]89 then90 91 cd $ISSM_DIR/externalpackages92 93 #number of packages:94 NUMPACKAGES=$(($(echo $EXTERNALPACKAGES | wc -w )/2))95 96 for ((i=1;i<=$NUMPACKAGES;i++))97 do98 NUM1=$((2*$i-1))99 NUM2=$((2*$i))100 PACKAGENAME=$(echo $EXTERNALPACKAGES | cut -d " " -f $NUM1-$NUM1)101 PACKAGEINST=$(echo $EXTERNALPACKAGES | cut -d " " -f $NUM2-$NUM2)102 103 cd $PACKAGENAME104 echo "======================================================";105 echo " Installing $PACKAGENAME ";106 echo "======================================================";107 ./$PACKAGEINST | tee compil.log108 if [ $? -ne 0 ]; then109 echo "======================================================";110 echo " ERROR: installation of $PACKAGENAME failed ";111 echo "======================================================";112 fi113 source $ISSM_DIR/etc/environment.sh114 cd ..115 done116 117 elif [ "$ISSM_EXTERNALPACKAGES" == "copy" ]118 then119 cd $ISSM_DIR120 rm -rf externalpackages121 cp -Rf $EXTERNALPACKAGESDIR ./122 elif [ "$ISSM_EXTERNALPACKAGES" == "link" ]123 then124 cd $ISSM_DIR125 rm -rf externalpackages126 ln -s $EXTERNALPACKAGESDIR .127 elif [ "$ISSM_EXTERNALPACKAGES" == "none" ]128 then129 echo "Skipping external packages installation"130 else131 echo "ISSM_EXTERNALPACKAGES supported values are: install, copy and none. Exiting..." >&2 # Error message to stderr.132 exit 1133 fi134 source $ISSM_DIR/etc/environment.sh135 #}}}136 #ISSM compilation yes/no (ISSM_COMPILATION) {{{137 if [ "$ISSM_COMPILATION" == "yes" ]138 then139 cd $ISSM_DIR140 make uninstall141 make clean142 make distclean143 ./scripts/automakererun.sh144 cat > configure.sh << EOF145 ./configure $ISSM_CONFIG146 EOF147 chmod 700 configure.sh148 ./configure.sh149 150 #4: compile and install ISSM151 if [ $NUMCPUS_INSTALL -gt 1 ]152 then153 echo "Making with " $NUMCPUS_INSTALL " cpus"154 make -j $NUMCPUS_INSTALL install155 else156 make install157 fi158 elif [ "$ISSM_COMPILATION" == "no" ]159 then160 echo "Skipping ISSM compilation"161 else162 echo "ISSM_COMPILATION supported values are: yes and no. Exiting..." >&2 # Error message to stderr.163 exit 1164 fi165 #}}}166 167 #Prepare info.log168 #{{{169 rm -rf $ISSM_DIR/nightlylog170 mkdir $ISSM_DIR/nightlylog171 INSTALL_TIME=$(timer)172 ELAPSED=$(timer $START_TIME)173 VERSION=$(svnversion $ISSM_DIR)174 cat << END > $ISSM_DIR/nightlylog/info.log175 name: $(echo $NAME)176 today: $(echo $TODAY)177 user: $(echo $USER)178 host: $(echo $HOST_NAME)179 OS: $(echo $OS)180 release: $(echo $ISSM_RELEASE)181 init_path: $(echo $INIT_PATH)182 is_matlab: $(echo $MATLAB_TEST)183 is_python: $(echo $PYTHON_TEST)184 elapsed_install: $(echo $ELAPSED)185 version: $(echo $VERSION)186 END187 #}}}188 189 #matlab tests190 if [ $MATLAB_TEST -eq 1 ]; then191 #Launch all tests on different cpus {{{192 MATLAB_START_TIME=$(timer);193 for (( i=1;i<=$NUMCPUS_RUN;i++ ))194 do195 #Launch matlab and the nightly run script196 cat > $ISSM_DIR/nightlylog/matlab_run$i.m << EOF197 warning off %necessary to avoid a info.log of several Go for parallel runs198 try,199 $(if [ "$MATLAB_NROPTIONS" = "" ]200 then201 echo "runme('output','nightly','rank',$i,'numprocs',$NUMCPUS_RUN);"202 else203 echo "runme($MATLAB_NROPTIONS,'output','nightly','rank',$i,'numprocs',$NUMCPUS_RUN);"204 fi205 )206 catch me,207 %An error occured, get report and exit208 message=getReport(me)209 directory=strsplit(pwd,'/');210 fid=fopen([issmdir '/nightlylog/matlaberror.log'], 'at');211 fprintf(fid,'\nMatlab error occured in: %s\n\n',directory{end});212 fprintf(fid,'%s',message);213 fclose(fid);214 end215 disp('MATLABEXITEDCORRECTLY');216 exit217 EOF218 cd $ISSM_DIR/test/NightlyRun219 matlab -nojvm -nosplash -r "addpath $ISSM_DIR/src/m/dev; devpath; addpath $ISSM_DIR/nightlylog/; matlab_run$i" -logfile $ISSM_DIR/nightlylog/matlab_log$i.log &220 done221 222 #wait until matlab closes223 if [ "$OS" = "win7" ]; then224 pause MATLAB225 else226 wait227 fi228 229 #concatenate reports230 cd $ISSM_DIR/nightlylog/231 rm matlab_log.log232 for (( i=1;i<=$NUMCPUS_RUN;i++ ))233 do234 cat matlab_log$i.log >> matlab_log.log235 done236 #}}}237 #Complete info.log {{{238 if [ $(cat matlab_log.log | grep "MATLABEXITEDCORRECTLY" | wc -l) -eq $NUMCPUS_RUN ]239 then240 MATLABCRASH=0241 else242 MATLABCRASH=1243 fi244 ELAPSED=$(timer $MATLAB_START_TIME)245 cat << END >> $ISSM_DIR/nightlylog/info.log246 elapsed_matlab: $(echo $ELAPSED)247 matlab_crash: $(echo $MATLABCRASH)248 END249 #}}}250 fi251 252 #python tests253 if [ $PYTHON_TEST -eq 1 ]; then254 #Launch all tests on different cpus {{{255 PYTHON_START_TIME=$(timer);256 export PYTHONSTARTUP=$ISSM_DIR/src/m/dev/devpath.py257 for (( i=1;i<=$NUMCPUS_RUN;i++ ))258 do259 cd $ISSM_DIR/test/NightlyRun260 ./runme.py --output=nightly --rank=$i --numprocs=$NUMCPUS_RUN $PYTHON_NROPTIONS 2>&1 > $ISSM_DIR/nightlylog/python_log$i.log &261 done262 263 #wait until python closes264 if [ "$OS" = "win7" ]; then265 pause MATLAB266 else267 wait268 fi269 270 #concatenate reports271 cd $ISSM_DIR/nightlylog/272 rm python_log.log273 for (( i=1;i<=$NUMCPUS_RUN;i++ ))274 do275 cat python_log$i.log >> python_log.log276 done277 #}}}278 #Complete info.log {{{279 if [ $(cat python_log.log | grep "PYTHONEXITEDCORRECTLY" | wc -l) -eq $NUMCPUS_RUN ]280 then281 PYTHONCRASH=0282 else283 PYTHONCRASH=1284 fi285 ELAPSED=$(timer $PYTHON_START_TIME)286 cat << END >> $ISSM_DIR/nightlylog/info.log287 elapsed_python: $(echo $ELAPSED)288 python_crash: $(echo $PYTHONCRASH)289 END290 #}}}291 fi292 293 #complete info.log294 #{{{295 ELAPSED=$(timer $START_TIME)296 cat << END >> $ISSM_DIR/nightlylog/info.log297 elapsed_total: $(echo $ELAPSED)298 END299 #}}}300 301 #Send Report302 #Build html report {{{303 cd $ISSM_DIR/nightlylog/304 sh ../scripts/report.sh305 echo "html report located in $ISSM_DIR/nightlylog/report.html"306 #}}}307 #send mail if requested (SKIPMAIL) {{{308 if [ "$SKIPMAIL" != "yes" ]309 then310 echo "sending report..."311 for i in `echo $MAILINGLIST`; do312 313 cat - $ISSM_DIR/nightlylog/report.html <<HERE | /usr/lib/sendmail -oi -t314 From: "ISSM Nightly run" <$EMAIL_ADRESS>315 To: $i316 Subject: ISSM nightly runs report: $NAME317 Mime-Version: 1.0318 Content-Type: text/html319 HERE320 done321 fi322 #}}}323 324 #remove lock file325 #{{{326 cd $ISSM_DIR/../327 rm NIGHTLYLOCK328 #}}}
Note:
See TracBrowser
for help on using the repository browser.