Changeset 25916


Ignore:
Timestamp:
12/29/20 13:27:50 (4 years ago)
Author:
jdquinn
Message:

CHG: Initial commit of changes for examples build

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified issm/trunk-jpl/jenkins/jenkins.sh

    r25878 r25916  
    11#!/bin/bash
    22################################################################################
    3 # This bash script manages installation of ISSM on a given Jenkins node using a
     3# This script manages installation of ISSM on a given Jenkins node using a
    44# configuration file passed as the only argument. This file also contains
    55# details about which nightly run tests should be executed after the build has
     
    2323#Get configuration
    2424#Source config file{{{
    25 if [ $# -ne 1 ];
    26 then
     25if [ $# -ne 1 ]; then
    2726        #no config file specified: exit
    2827        echo "no config file specified. Exiting..." >&2 # Error message to stderr.
    2928        exit 1
    3029fi
    31 if [ ! -f "$1" ]
    32 then
     30if [ ! -f "$1" ]; then
    3331        echo "File $1 not found!" >&2 # Error message to stderr.
    3432        exit 1
     
    4644NUMCPUS_RUN=1
    4745
    48 
    4946#source configuration script
    5047source $1;
    5148#}}}
     49
     50if [[ $EXAMPLES_TEST -eq 1 && $MATLAB_TEST+$PYTHON_TEST+$JAVASCRIPT_TEST -ne 0 ]]; then
     51        echo "When running examples tests, set *only* EXAMPLES_TEST=1"
     52        exit 1
     53fi
     54
    5255#Get Operating system (OS) name{{{
    5356OS=$(uname -s)
     
    6265echo "             Determining Installation type            "
    6366echo "======================================================";
    64 if [ -a $ISSM_DIR/svn_revision_old ]
    65 then
     67if [ -a $ISSM_DIR/svn_revision_old ]; then
    6668        SVN_PREVIOUS=$(cat $ISSM_DIR/svn_revision_old)
    6769        SVN_CURRENT=$SVN_REVISION_1
     
    9799        # If the contents of the externalpackages directory were modified in any
    98100        # way, check for changed external packages
    99         if [ ! -z "$(cat $ISSM_DIR/TEMP | grep externalpackages)" ] ; then
    100                 echo "  -- checking for changed externalpackages... yes";
     101        if [ ! -z "$(cat $ISSM_DIR/TEMP | grep externalpackages)" ]; then
     102                echo "  -- checking for changed externalpackages... yes"
    101103                ISSM_EXTERNALPACKAGES="yes"
    102104        else
    103                 echo "  -- checking for changed externalpackages... no";
     105                echo "  -- checking for changed externalpackages... no"
    104106                ISSM_EXTERNALPACKAGES="no"
    105107        fi
     
    109111        if [ ! -z "$(cat $ISSM_DIR/TEMP | grep -e "Makefile.am" -e "m4" )" ] ||
    110112                [ ! -f "$ISSM_DIR/bin/issm.exe" ] && [ ! -f "$ISSM_DIR/bin/issm-bin.js" ] ||
    111                 [ "$ISSM_EXTERNALPACKAGES" == "yes" ] ;
    112         then
    113                 echo "  -- checking for reconfiguration... yes";
     113                [ "$ISSM_EXTERNALPACKAGES" == "yes" ]; then
     114                echo "  -- checking for reconfiguration... yes"
    114115                ISSM_RECONFIGURE="yes"
    115116        else
    116                 echo "  -- checking for reconfiguration... no";
     117                echo "  -- checking for reconfiguration... no"
    117118                ISSM_RECONFIGURE="no"
    118119        fi
     
    120121        # If source files were changed in any way, recompile
    121122        if [ ! -z "$(cat $ISSM_DIR/TEMP | grep -e "\.cpp" -e "\.h" )" ] ||
    122                 [ "$ISSM_RECONFIGURE" == "yes" ] ;
    123         then
    124                 echo "  -- checking for recompilation... yes";
     123                [ "$ISSM_RECONFIGURE" == "yes" ]; then
     124                echo "  -- checking for recompilation... yes"
    125125                ISSM_COMPILATION="yes"
    126126        else
    127                 echo "  -- checking for recompilation... no";
     127                echo "  -- checking for recompilation... no"
    128128                ISSM_COMPILATION="no"
    129129        fi
     
    134134else
    135135        echo "Previous revision not found, this must be a fresh install"
    136         echo "  -- checking for changed externalpackages... yes";
    137         echo "  -- checking for reconfiguration... yes";
    138         echo "  -- checking for recompilation... yes";
     136        echo "  -- checking for changed externalpackages... yes"
     137        echo "  -- checking for reconfiguration... yes"
     138        echo "  -- checking for recompilation... yes"
    139139        ISSM_EXTERNALPACKAGES="yes"
    140140        ISSM_RECONFIGURE="yes"
     
    168168EXTERNALPACKAGES_FAILED=0;
    169169
    170 for ((i=1;i<=$NUMPACKAGES;i++))
    171 do
     170for ((i=1;i<=$NUMPACKAGES;i++)); do
    172171        NUM1=$((2*$i-1))
    173172        NUM2=$((2*$i))
     
    176175
    177176        #install if requested or if previous install has not been successful
    178         if [ "$ISSM_EXTERNALPACKAGES" == "yes" ] || [[ ! -d ./install && ! -d ./install-javascript ]]; then
     177        if [ "$ISSM_EXTERNALPACKAGES" == "yes" ]; then # NOTE: Removed check on if 'install' directory exist
    179178                cd $ISSM_DIR/externalpackages/$PACKAGENAME
    180179
     
    198197                        echo "<testcase classname=\"externalpackages\" name=\"$PACKAGENAME\"/>" >> $EXTERNAL_TEST_FILE
    199198                fi
    200                 source $ISSM_DIR/etc/environment.sh
     199                source $ISSM_DIR/etc/environment-shared.sh
    201200
    202201                #If external package is rebuilt, we also need to recompile
     
    210209        fi
    211210done
     211
    212212echo '</testsuite>' >> $EXTERNAL_TEST_FILE
    213213
     
    220220
    221221# Source here to include any newly installed externalpackages on the path.
    222 source $ISSM_DIR/etc/environment.sh
     222source $ISSM_DIR/etc/environment-shared.sh
    223223
    224224if [ "$OS" == "win" ]; then
     
    249249#}}}
    250250#ISSM compilation yes/no                (ISSM_COMPILATION) {{{
    251 if [ "$ISSM_COMPILATION" == "yes" ]
    252 then
     251if [ "$ISSM_COMPILATION" == "yes" ]; then
    253252        cd $ISSM_DIR
    254         if [ "$ISSM_RECONFIGURE" == "yes" ]
    255         then
     253        if [ "$ISSM_RECONFIGURE" == "yes" ]; then
    256254                echo "======================================================";
    257255                echo "             Cleaning up and reconfiguring            "
     
    274272
    275273        #4: compile and install ISSM
    276         echo "======================================================";
     274        echo "======================================================"
    277275        echo "                    Compiling ISSM                    "
    278         echo "======================================================";
     276        echo "======================================================"
    279277        if [ $NUMCPUS_INSTALL -gt 1 ]; then
    280278                echo "Making with " $NUMCPUS_INSTALL " cpus"
     
    310308# {{{
    311309if [ $MATLAB_TEST -eq 1 ]; then
    312 #Launch all tests on different cpus
    313 for (( i=1;i<=$NUMCPUS_RUN;i++ ))
    314 do
    315         #Launch matlab and the nightly run script
    316         cat > $ISSM_DIR/nightlylog/matlab_run$i.m << EOF
    317         warning off %necessary to avoid a log of several Go for parallel runs
    318         try,
    319         $(if [ "$MATLAB_NROPTIONS" = "" ]; then
    320                 echo "runme('output','nightly','rank',$i,'numprocs',$NUMCPUS_RUN);"
     310        #Launch all tests on different cpus
     311        for (( i=1;i<=$NUMCPUS_RUN;i++ )); do
     312                #Launch matlab and the nightly run script
     313                cat > $ISSM_DIR/nightlylog/matlab_run$i.m << EOF
     314                warning off %necessary to avoid a log of several Go for parallel runs
     315                try,
     316                        $(if [ "$MATLAB_NROPTIONS" = "" ]; then
     317                                echo "runme('output','nightly','rank',$i,'numprocs',$NUMCPUS_RUN);"
     318                        else
     319                                echo "runme($MATLAB_NROPTIONS,'output','nightly','rank',$i,'numprocs',$NUMCPUS_RUN);"
     320                        fi)
     321                catch me,
     322                        %An error occured, get report and exit
     323                        message=getReport(me)
     324                        directory=strsplit(pwd,'/');
     325                        fid=fopen([issmdir '/nightlylog/matlaberror.log'], 'at');
     326                        fprintf(fid,'\nMatlab error occured in: %s\n\n',directory{end});
     327                        fprintf(fid,'%s',message);
     328                        fclose(fid);
     329                end
     330                disp('MATLABEXITEDCORRECTLY');
     331                exit
     332EOF
     333                cd $ISSM_DIR/test/NightlyRun
     334                if [ "$OS" = "win" ]; then
     335                        $MATLAB_PATH/bin/matlab -nodisplay -nosplash -r "addpath $ISSM_DIR_WIN/src/m/dev; devpath; addpath $ISSM_DIR_WIN/nightlylog/; matlab_run$i" -logfile $ISSM_DIR_WIN/nightlylog/matlab_log$i.log &
     336                else
     337                        $MATLAB_PATH/bin/matlab -nodisplay -nosplash -r "addpath $ISSM_DIR/src/m/dev; devpath; addpath $ISSM_DIR/nightlylog/; matlab_run$i" -logfile $ISSM_DIR/nightlylog/matlab_log$i.log &
     338                fi
     339        done
     340
     341        #wait until matlab closes
     342        if [ "$OS" = "win" ]; then
     343                sleep 5;
     344                echo "Waiting for matlab on windows"
     345                pid=$(ps aux -W | grep MATLAB | awk '{printf("%s\n","MATLAB");}')
     346                echo '-----------------------------'
     347                echo "pid: $pid"
     348                echo '-----------------------------'
     349                while [ -n "$pid" ]; do
     350                        pid=$(ps aux -W | grep MATLAB | awk '{printf("%s\n","MATLAB");}')
     351                        sleep 1;
     352                done
     353                echo "DONE!"
    321354        else
    322                 echo "runme($MATLAB_NROPTIONS,'output','nightly','rank',$i,'numprocs',$NUMCPUS_RUN);"
    323         fi
    324         )
    325         catch me,
    326                 %An error occured, get report and exit
    327                 message=getReport(me)
    328                 directory=strsplit(pwd,'/');
    329                 fid=fopen([issmdir '/nightlylog/matlaberror.log'], 'at');
    330                 fprintf(fid,'\nMatlab error occured in: %s\n\n',directory{end});
    331                 fprintf(fid,'%s',message);
    332                 fclose(fid);
    333         end
    334         disp('MATLABEXITEDCORRECTLY');
    335 
    336         exit
    337 EOF
    338         cd $ISSM_DIR/test/NightlyRun
    339         if [ "$OS" = "win" ]; then
    340                 $MATLAB_PATH/bin/matlab -nodisplay -nosplash -r "addpath $ISSM_DIR_WIN/src/m/dev; devpath; addpath $ISSM_DIR_WIN/nightlylog/; matlab_run$i" -logfile $ISSM_DIR_WIN/nightlylog/matlab_log$i.log &
    341         else
    342                 $MATLAB_PATH/bin/matlab -nodisplay -nosplash -r "addpath $ISSM_DIR/src/m/dev; devpath; addpath $ISSM_DIR/nightlylog/; matlab_run$i" -logfile $ISSM_DIR/nightlylog/matlab_log$i.log &
    343         fi
    344 done
    345 
    346 #wait until matlab closes
    347 if [ "$OS" = "win" ]; then
    348         sleep 5;
    349         echo "Waiting for matlab on windows"
    350         pid=$(ps aux -W | grep MATLAB | awk '{printf("%s\n","MATLAB");}')
    351         echo '-----------------------------'
    352         echo "pid: $pid"
    353         echo '-----------------------------'
    354         while [ -n "$pid" ]
    355         do
    356                 pid=$(ps aux -W | grep MATLAB | awk '{printf("%s\n","MATLAB");}')
    357                 sleep 1;
    358         done
    359         echo "DONE!"
    360 else
    361         wait
    362 fi
    363 
    364 #concatenate reports
    365 cd $ISSM_DIR/nightlylog/
    366 #echo 'CHECKING NIGHTLYLOG DIRECTORY'
    367 #echo '-----------------------------'
    368 #ls -la
    369 #echo '-----------------------------'
    370 
    371 if [ -f matlab_log.log ]; then
    372         rm matlab_log.log
    373 fi
    374 
    375 for job in `jobs -p`
    376 do
    377         echo "Waiting on: $job"
    378         wait $job
    379 done
    380 
    381 for (( i=1;i<=$NUMCPUS_RUN;i++ ))
    382 do
    383         cat matlab_log$i.log >> matlab_log.log
    384 done
    385 
    386 #filter out windows characters:
    387 cat matlab_log.log | tr -cd '\11\12\40-\176' > matlab_log.log2 && mv matlab_log.log2 matlab_log.log
     355                wait
     356        fi
     357
     358        #concatenate reports
     359        cd $ISSM_DIR/nightlylog/
     360        #echo 'CHECKING NIGHTLYLOG DIRECTORY'
     361        #echo '-----------------------------'
     362        #ls -la
     363        #echo '-----------------------------'
     364
     365        if [ -f matlab_log.log ]; then
     366                rm matlab_log.log
     367        fi
     368
     369        for job in `jobs -p`; do
     370                echo "Waiting on: $job"
     371                wait $job
     372        done
     373
     374        for (( i=1;i<=$NUMCPUS_RUN;i++ )); do
     375                cat matlab_log$i.log >> matlab_log.log
     376        done
     377
     378        #filter out windows characters:
     379        cat matlab_log.log | tr -cd '\11\12\40-\176' > matlab_log.log2 && mv matlab_log.log2 matlab_log.log
    388380fi
    389381# }}}
     
    429421rm -f $ISSM_DIR/execution/*/ADOLC-*
    430422
    431 # Examples Test
     423# Examples Tests
    432424# {{{
    433 # This test will allow us to check on the status of the examples.
    434 if [ $EXAMPLES_TEST -eq 1 ];
    435 then
    436         FILE='runme.m'
    437         cd $ISSM_DIR/examples
    438 
    439         for dir in ./* ;
    440         do
    441                 if [ -d "${dir}" ];
    442                 then
    443                 # Some of the examples are incomplete (on purpose). As such, we will
    444                 # have to populate the missing steps in order to make sure that
    445                 # everything is working.
    446                         echo "Testing directory example: $(basename $dir)"
    447 
    448                         if [ -z "$SED" ];
    449                         then
    450                                 SED='sed'
    451                         fi
    452 
    453                         cd ${dir}
    454 
    455                         if [ "${dir}" == "./Greenland" ];
    456                         then
    457                                 # Greenland is missing step 8
    458                                 STEP_EIGHT="\n  disp('   Step 8: Plotting exercise');\n md = loadmodel('.\/Models\/Greenland.HistoricTransient');\n     figure\n        surfmb=[]; for i=2:201; surfmb=[surfmb ...\n            md.results.TransientSolution(i).SmbMassBalance]; end\n  subplot(3,1,1); plot([1:200],mean(surfmb));\n   title('Mean Surface mass balance');\n   vel=[]; for i=2:201; vel=[vel md.results.TransientSolution(i).Vel]; end\n       subplot(3,1,2); plot([1:200],mean(vel));\n      title('Mean Velocity');\n       volume=[]; for i=2:201; volume=[volume md.results.TransientSolution(i).IceVolume]; end\n        subplot(3,1,3); plot([1:200],volume);\n title('Ice Volume'); xlabel('years');"
    459 
    460                                 $SED -i .bak 's/steps=\[1\];/steps=\[1:8\];\n\ntry\n/' $FILE
    461                                 $SED -i .bak "s/if any(steps==8)/&${STEP_EIGHT}/" $FILE
    462                         elif [ "${dir}" == "./IceBridge" ];
    463                         then
    464                                 $SED -i .bak 's/steps=\[1\];/steps=\[1:5\];\n\ntry\n/' $FILE
    465                         elif [ "${dir}" == "./IceflowModels" ];
    466                         then
    467                                 # Almost nothing to this example
    468                                 $SED -i .bak '1 s/^.*$/try\n\n&/' $FILE
    469                         elif [ "${dir}" == "./ISMIP" ];
    470                         then
    471                                 # Eight steps... none of which are implmented in the script...
    472                                 $SED -i .bak '1 s/^.*$/try\n\n&/' $FILE
    473                         elif [ "${dir}" == "./Inversion" ];
    474                         then
    475                                 $SED -i .bak 's/steps=\[1\];/steps=\[1:4\];\n\ntry\n/' $FILE
    476                         elif [ "${dir}" == "./Jakobshavn" ];
    477                         then
    478                                 $SED -i .bak 's/steps=\[1\];/steps=\[1:4\];\n\ntry\n/' $FILE
    479                         elif [ "${dir}" == "./Jakobshavn" ];
    480                         then
    481                                 $SED -i .bak 's/steps=\[1\];/steps=\[1:4\];\n\ntry\n/' $FILE
    482                         elif [ "${dir}" == "./Pig" ];
    483                         then
    484                                 # Step 6 is needed
    485                                 STEP_SIX="\n disp('Needs work!')"
    486                                 $SED -i .bak 's/steps=\[1\];/steps=\[1:7\];\n!mv DomainOutline.bkp DomainOutline.exp;\n\ntry\n/' $FILE
    487                                 $SED -i .bak "s/if any(steps==6)/&${STEP_SIX}/" $FILE
    488                         elif [ "${dir}" == "./PigSensitivity" ];
    489                         then
    490                                 # Step 4 is needed
    491                                 STEP_FOUR="\n disp('Needs work!')"
    492                                 $SED -i .bak 's/steps=\[1\];/steps=\[1:4\];\n\ntry\n/' $FILE
    493                                 $SED -i .bak "s/if any(steps==6)/&${STEP_FOUR}/" $FILE
    494                         elif [ "${dir}" == "./SquareIceShelf" ];
    495                         then
    496                                 # Almost nothing to this example
    497                                 $SED -i .bak '1 s/^.*$/try\n\n&/' $FILE
    498                         elif [ "${dir}" == "./UncertaintyQuantification" ];
    499                         then
    500                                 $SED -i .bak 's/steps=\[1\];/steps=\[1:7\];\n\ntry\n/' $FILE
    501                         elif [ "${dir}" == "./Data" ];
    502                         then
    503                                 echo "Data directory is used by examples. No modifications required."
    504                         else
    505                                 echo "Not implemented yet!"
    506                                 $SED -i .bak '1 s/^.*$/try\n\n&/' $FILE
    507                         fi
    508 
    509                         if [ "${dir}" == "./Data" ];
    510                         then
    511                                 ./Download.sh
    512                         else
    513                                 LOG_FILE="matlab_log_$(basename $dir)_examples.log"
    514                                 echo "disp('SUCCESS');" >> $FILE
    515                                 echo 'catch me' >> $FILE
    516                                 echo 'message=getReport(me);' >> $FILE
    517                                 echo "fprintf('%s',message);" >> $FILE
    518                                 echo "disp('FAILURE');" >> $FILE
    519                                 echo 'end' >> $FILE
    520 
    521                                 $MATLAB_PATH/bin/matlab -nodisplay -nosplash -r "addpath $ISSM_DIR/src/m/dev; devpath; addpath $ISSM_DIR/nightlylog/; runme" -logfile $ISSM_DIR/nightlylog/$LOG_FILE
    522                                 echo "starting: $(basename $dir)" >> $ISSM_DIR/nightlylog/matlab_log_examples.log
    523                                 cat $ISSM_DIR/nightlylog/$LOG_FILE >> $ISSM_DIR/nightlylog/matlab_log_examples.log
    524                                 echo "finished: $(basename $dir)" >> $ISSM_DIR/nightlylog/matlab_log_examples.log
    525                         fi
    526                         cd ..
    527                 fi
    528         done
     425# The following tests check that the examples (i.e. contents of examples
     426# directory, which are implementations of the tutorials found at
     427# https://issm.jpl.nasa.gov/documentation/tutorials/) can be run.
     428#
     429# runme files are modifed as needed to fill in statements that would otherwise
     430# be added by user.
     431#
     432# NOTE:
     433# - Indentation of replacement string literals (e.g. 'STEP_EIGHT') is set to
     434#       nest cleanly in this file, but will result in unclean nesting runme file
     435#       (which should not be an issue)
     436# - Single-line string replacements in runme.m can effectively be performed
     437#       using sed. When performing multi-line replacements, perl is a better
     438#       option.
     439#
     440if [ $EXAMPLES_TEST -eq 1 ]; then
     441        $ISSM_DIR/jenkins/examples_tests.sh
    529442fi
    530443# }}}
     
    542455
    543456        #look through numtests:
    544         for i in `echo $testlist`
    545         do
     457        for i in `echo $testlist`; do
    546458                juLog -test=MATLAB-$i -name=Error -error=ERROR awk "/starting:$i/{flag=1;next}/finished/{flag=0} flag{print}" matlab_log.log
    547459                juLog -test=MATLAB-$i -name=Failure -error=FAILURE awk "/starting:$i/{flag=1;next}/finished/{flag=0} flag{print}" matlab_log.log
     
    551463        matlabExitedInError=`grep -E "Activation cannot proceed|Error in matlab_run" matlab_log.log | wc -l`
    552464
    553         if [ $matlabExitedInError -ne 0 ]
    554         then
     465        if [ $matlabExitedInError -ne 0 ]; then
    555466                echo "----------MATLAB exited in error!----------"
    556467                cat matlab_log.log
     
    570481
    571482        #look through numtests:
    572         for i in `echo $testlist`
    573         do
     483        for i in `echo $testlist`; do
    574484                juLog -test=PYTHON-$i -name=Error -error=ERROR awk "/starting:$i/{flag=1;next}/finished/{flag=0} flag{print}" python_log.log
    575485                juLog -test=PYTHON-$i -name=Failure -error=FAILURE awk "/starting:$i/{flag=1;next}/finished/{flag=0} flag{print}" python_log.log
     
    579489        pythonExitedInError=`grep -E "Error|Standard exception|Traceback|bad interpreter" python_log.log | wc -l`
    580490
    581         if [ $pythonExitedInError -ne 0 ]
    582         then
     491        if [ $pythonExitedInError -ne 0 ]; then
    583492                echo "----------Python exited in error!----------"
    584493                cat python_log.log
     
    595504fi
    596505
    597 if [ $EXAMPLES_TEST -eq 1 ];
    598 then
     506if [ $EXAMPLES_TEST -eq 1 ]; then
    599507        # Inexplicably, there are backspace chars in the error output that are causing issues
    600         $SED -i .bak 's///g' matlab_log_examples.log
     508        sed -i '.bak' 's///g' matlab_log_examples.log
    601509
    602510        numtests=`cat matlab_log_examples.log | grep "starting: " | wc -l`
     
    604512
    605513        echo "Processing: $numtests"
    606         for i in `echo $testlist`
    607         do
     514        for i in `echo $testlist`; do
    608515                juLog -test=Example-$i -name=Error -error=FAILURE awk "/starting: $i/{flag=1;next}/finished: $i/{flag=0} flag{print}" matlab_log_examples.log
    609516        done
Note: See TracChangeset for help on using the changeset viewer.