source: issm/oecreview/Archive/16554-17801/ISSM-16605-16606.diff@ 17802

Last change on this file since 17802 was 17802, checked in by Mathieu Morlighem, 11 years ago

Added archives

File size: 8.0 KB
  • ../trunk-jpl/scripts/jenkins.sh

     
    1 #!/bin/bash
    2 #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 functions
    6 function timer() #{{{
    7 {
    8         if [[ $# -eq 0 ]]; then
    9                 echo $(date '+%s')
    10         else
    11                 local  stime=$1
    12                 etime=$(date '+%s')
    13 
    14                 if [[ -z "$stime" ]]; then stime=$etime; fi
    15 
    16                 dt=$((etime - stime))
    17                 ds=$((dt % 60))
    18                 dm=$(((dt / 60) % 60))
    19                 dh=$((dt / 3600))
    20                 printf '%d:%02d:%02d' $dh $dm $ds
    21         fi
    22 } #}}}
    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 OS
    31         if [ "$1" = "win7" ]
    32         then
    33                 HOST_NAME=`hostname | sed 's/-//g'`;
    34         else
    35                 HOST_NAME=`hostname -s | sed 's/-//g'`;
    36         fi
    37         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 do
    45         pid=`ps aux -W | grep $1 | awk '{printf("%s\n",$1);}'`
    46 done
    47 }
    48 #}}}
    49 
    50 #Get configuration
    51 #Source config file{{{
    52 if [ $# -ne 1 ];
    53 then
    54         #no config file specified: exit
    55         echo "no config file specified. Exiting..." >&2 # Error message to stderr.
    56         exit 1
    57 fi
    58 if [ ! -f "$1" ]
    59 then
    60         echo "File $1 not found!" >&2   # Error message to stderr.
    61         exit 1
    62 fi
    63 source $1;
    64 #}}}
    65 #Export ISSM_* variables{{{
    66 export ISSM_DIR
    67 export ISSM_ARCH
    68 #}}}
    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 ISSM
    80 #create matlab's installation sript {{{
    81 cat << END > $ISSM_DIR/externalpackages/matlab/install.sh
    82 #!/bin/bash
    83 rm -rf install
    84 ln -s $MATLAB_PATH install
    85 END
    86 #}}}
    87 #install/copy/none external packages    (ISSM_EXTERNALPACKAGES){{{
    88 if [ "$ISSM_EXTERNALPACKAGES" == "install" ]
    89 then
    90        
    91         cd $ISSM_DIR/externalpackages
    92 
    93         #number of packages:
    94         NUMPACKAGES=$(($(echo $EXTERNALPACKAGES | wc -w )/2))
    95 
    96         for ((i=1;i<=$NUMPACKAGES;i++))
    97         do
    98                 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 $PACKAGENAME
    104                 echo "======================================================";
    105                 echo "       Installing $PACKAGENAME                        ";
    106                 echo "======================================================";
    107                 ./$PACKAGEINST |  tee compil.log
    108                 if [ $? -ne 0 ]; then
    109                         echo "======================================================";
    110                         echo "    ERROR: installation of $PACKAGENAME failed        ";
    111                         echo "======================================================";
    112                 fi
    113                 source $ISSM_DIR/etc/environment.sh
    114                 cd ..
    115         done
    116 
    117 elif [ "$ISSM_EXTERNALPACKAGES" == "copy" ]
    118 then
    119         cd $ISSM_DIR
    120         rm -rf externalpackages
    121         cp -Rf $EXTERNALPACKAGESDIR ./
    122 elif [ "$ISSM_EXTERNALPACKAGES" == "link" ]
    123 then
    124         cd $ISSM_DIR
    125         rm -rf externalpackages
    126         ln -s  $EXTERNALPACKAGESDIR  .
    127 elif [ "$ISSM_EXTERNALPACKAGES" == "none" ]
    128 then
    129         echo "Skipping external packages installation"
    130 else
    131         echo "ISSM_EXTERNALPACKAGES supported values are: install, copy and none. Exiting..." >&2 # Error message to stderr.
    132         exit 1
    133 fi
    134 source $ISSM_DIR/etc/environment.sh
    135 #}}}
    136 #ISSM compilation yes/no                (ISSM_COMPILATION) {{{
    137 if [ "$ISSM_COMPILATION" == "yes" ]
    138 then
    139         cd $ISSM_DIR
    140         make uninstall
    141         make clean
    142         make distclean
    143         ./scripts/automakererun.sh
    144         cat > configure.sh << EOF
    145 ./configure $ISSM_CONFIG
    146 EOF
    147         chmod 700 configure.sh
    148         ./configure.sh
    149 
    150         #4: compile and install ISSM
    151         if [ $NUMCPUS_INSTALL -gt 1 ]
    152         then
    153                 echo "Making with " $NUMCPUS_INSTALL " cpus"
    154                 make -j $NUMCPUS_INSTALL install
    155         else
    156                 make install
    157         fi
    158 elif [ "$ISSM_COMPILATION" == "no" ]
    159 then
    160         echo "Skipping ISSM compilation"
    161 else
    162         echo "ISSM_COMPILATION supported values are: yes and no. Exiting..." >&2 # Error message to stderr.
    163         exit 1
    164 fi
    165 #}}}
    166 
    167 #Prepare info.log
    168 #{{{
    169 rm -rf $ISSM_DIR/nightlylog
    170 mkdir  $ISSM_DIR/nightlylog
    171 INSTALL_TIME=$(timer)
    172 ELAPSED=$(timer $START_TIME)
    173 VERSION=$(svnversion $ISSM_DIR)
    174 cat << END > $ISSM_DIR/nightlylog/info.log
    175 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 END
    187 #}}}
    188 
    189 #matlab tests
    190 if [ $MATLAB_TEST -eq 1 ]; then
    191 #Launch all tests on different cpus {{{
    192 MATLAB_START_TIME=$(timer);
    193 for (( i=1;i<=$NUMCPUS_RUN;i++ ))
    194 do
    195         #Launch matlab and the nightly run script
    196         cat > $ISSM_DIR/nightlylog/matlab_run$i.m << EOF
    197         warning off %necessary to avoid a info.log of several Go for parallel runs
    198         try,
    199         $(if [ "$MATLAB_NROPTIONS" = ""  ]
    200         then
    201                 echo "runme('output','nightly','rank',$i,'numprocs',$NUMCPUS_RUN);"
    202         else
    203                 echo "runme($MATLAB_NROPTIONS,'output','nightly','rank',$i,'numprocs',$NUMCPUS_RUN);"
    204         fi
    205         )
    206         catch me,
    207                 %An error occured, get report and exit
    208                 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         end
    215         disp('MATLABEXITEDCORRECTLY');
    216         exit
    217 EOF
    218         cd $ISSM_DIR/test/NightlyRun
    219         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 done
    221 
    222 #wait until matlab closes
    223 if [ "$OS" = "win7" ]; then
    224         pause MATLAB
    225 else
    226         wait
    227 fi
    228 
    229 #concatenate reports
    230 cd $ISSM_DIR/nightlylog/
    231 rm matlab_log.log
    232 for (( i=1;i<=$NUMCPUS_RUN;i++ ))
    233 do
    234         cat matlab_log$i.log >> matlab_log.log
    235 done
    236 #}}}
    237 #Complete info.log {{{
    238 if [ $(cat matlab_log.log | grep "MATLABEXITEDCORRECTLY" | wc -l) -eq $NUMCPUS_RUN ]
    239 then
    240         MATLABCRASH=0
    241 else
    242         MATLABCRASH=1
    243 fi
    244 ELAPSED=$(timer $MATLAB_START_TIME)
    245 cat << END >>  $ISSM_DIR/nightlylog/info.log
    246 elapsed_matlab: $(echo $ELAPSED)
    247 matlab_crash:   $(echo $MATLABCRASH)
    248 END
    249 #}}}
    250 fi
    251 
    252 #python tests
    253 if [ $PYTHON_TEST -eq 1 ]; then
    254 #Launch all tests on different cpus {{{
    255 PYTHON_START_TIME=$(timer);
    256 export PYTHONSTARTUP=$ISSM_DIR/src/m/dev/devpath.py
    257 for (( i=1;i<=$NUMCPUS_RUN;i++ ))
    258 do
    259         cd $ISSM_DIR/test/NightlyRun
    260         ./runme.py --output=nightly --rank=$i --numprocs=$NUMCPUS_RUN $PYTHON_NROPTIONS 2>&1 > $ISSM_DIR/nightlylog/python_log$i.log &
    261 done
    262 
    263 #wait until python closes
    264 if [ "$OS" = "win7" ]; then
    265         pause MATLAB
    266 else
    267         wait
    268 fi
    269 
    270 #concatenate reports
    271 cd $ISSM_DIR/nightlylog/
    272 rm python_log.log
    273 for (( i=1;i<=$NUMCPUS_RUN;i++ ))
    274 do
    275         cat python_log$i.log >> python_log.log
    276 done
    277 #}}}
    278 #Complete info.log {{{
    279 if [ $(cat python_log.log | grep "PYTHONEXITEDCORRECTLY" | wc -l) -eq $NUMCPUS_RUN ]
    280 then
    281         PYTHONCRASH=0
    282 else
    283         PYTHONCRASH=1
    284 fi
    285 ELAPSED=$(timer $PYTHON_START_TIME)
    286 cat << END >>  $ISSM_DIR/nightlylog/info.log
    287 elapsed_python: $(echo $ELAPSED)
    288 python_crash:   $(echo $PYTHONCRASH)
    289 END
    290 #}}}
    291 fi
    292 
    293 #complete info.log
    294 #{{{
    295 ELAPSED=$(timer $START_TIME)
    296 cat << END >>  $ISSM_DIR/nightlylog/info.log
    297 elapsed_total:  $(echo $ELAPSED)
    298 END
    299 #}}}
    300 
    301 #Send Report
    302 #Build html report {{{
    303 cd $ISSM_DIR/nightlylog/
    304 sh ../scripts/report.sh
    305 echo "html report located in $ISSM_DIR/nightlylog/report.html"
    306 #}}}
    307 #send mail if requested                  (SKIPMAIL) {{{
    308 if [ "$SKIPMAIL" != "yes" ]
    309 then
    310         echo "sending report..."
    311         for i in `echo $MAILINGLIST`; do
    312 
    313 cat - $ISSM_DIR/nightlylog/report.html <<HERE | /usr/lib/sendmail  -oi -t
    314 From: "ISSM Nightly run" <$EMAIL_ADRESS>
    315 To: $i
    316 Subject: ISSM nightly runs report: $NAME
    317 Mime-Version: 1.0
    318 Content-Type: text/html
    319 HERE
    320         done
    321 fi
    322 #}}}
    323 
    324 #remove lock file
    325 #{{{
    326 cd $ISSM_DIR/../
    327 rm NIGHTLYLOCK
    328 #}}}
Note: See TracBrowser for help on using the repository browser.