diff --git a/docs/Integrator.md b/docs/Integrator.md index 6726f35b039868206d1e4f3395b316ac7703e4b7..93c703a3a37b023193599a89a5cff0a1f1a83c9a 100644 --- a/docs/Integrator.md +++ b/docs/Integrator.md @@ -102,3 +102,8 @@ The preprocessed versions of the source code are put in branches named \<model\> The preprocessing tools are described in the [Tools documentation](./Tools.md). +## Code validation + +The testing.h script can be automatically run to help for validation. This script is described +in the [Tools documentation](./Tools.md). + diff --git a/docs/Tools.md b/docs/Tools.md index 6fb2df1d0478ff442f973a1a2bac3d87926daa9c..aef6814aed5719215c635383ffe3954819230f46 100644 --- a/docs/Tools.md +++ b/docs/Tools.md @@ -61,6 +61,12 @@ script with the 'REF' argument), the reference simulation directory (under $TEST This script is used by the different check\_commit\_\* scripts and can be used directly to pre-process the source code. The installation is described in the [tools/INSTALL\_mnh\_expand.md file](../tools/INSTALL_mnh_expand.md) +### testing.sh + +This script is designed to be run periodically by cron. It searches for the last commit on a github repository, +use the different check\_commit\_\* scripts to run the test cases and add a comments attached to the gihub commit +to report success or unsecess of these tests. In case of an error, the script can also send an email. + ### others Other scripts are: diff --git a/tools/check_commit_ial.sh b/tools/check_commit_ial.sh index 9539527200a47738ca1239cfd77fc041f372ecfc..e3c05adf428d1a9e0f5174a0c80c2b9d7e8cc90d 100755 --- a/tools/check_commit_ial.sh +++ b/tools/check_commit_ial.sh @@ -65,6 +65,7 @@ set -o pipefail #abort if left command on a pipe fails specialPack="ori split split_48t1 split_48t3 recompil split_49t0" availTests="small_3D,small_3D_np2,small_3D_alt1,small_3D_alt2,small_3D_alt3,small_3D_alt4,small_3D_alt5,small_3D_alt6,small_3D_alt7" defaultTest="small_3D" +allowedTests="small_3D,small_3D_np2,small_3D_alt1,small_3D_alt2,small_3D_alt3,small_3D_alt4,small_3D_alt5,small_3D_alt6,small_3D_alt7,small_3D_alt8,small_3D_alt9,small_3D_alt10,small_3D_alt11,small_3D_alt12,small_3D_lima" separator='_' #- be carrefull, gmkpack (at least on belenos) has multiple allergies (':', '.', '@') #- seprator must be in sync with prep_code.sh separator @@ -83,6 +84,7 @@ if [ $(hostname | cut -c 1-7) == 'belenos' -o $(hostname | cut -c 1-7) == 'taran defaultMainPackVersion=01 defaultRef='split_${cycle}' availTests="${availTests},big_3D" + allowedTests="${allowedTests},big_3D" else HPC=0 gmkpack_l[default]=MPIGFORTRAN920DBL @@ -97,7 +99,7 @@ mainPackVersion=${mainPackVersion:-${defaultMainPackVersion}} extraCompilationCheck=1 function usage { - echo "Usage: $0 [-h] [-p] [-c] [-r] [-C] [-s] [-f] [--noexpand] [-t test] [--cycle CYCLE] [--repo-user] [--repo-protocol] commit [reference]" + echo "Usage: $0 [-h] [-p] [-c] [-r] [-C] [-s] [-f] [--noexpand] [-t test] [--cycle CYCLE] [--repo-user] [--repo-protocol] [--remove] commit [reference]" echo "commit commit hash (or a directory, or among $specialPack) to test" echo "reference commit hash (or a directory, or among $specialPack) REF to use as a reference" echo "-s suppress compilation pack" @@ -115,12 +117,17 @@ function usage { echo " defaults to the env variable PHYEXREOuser (=$PHYEXREOuser)" echo "--repo-protocol protocol (https or ssh) to reach the PHYEX repository on github," echo " defaults to the env variable PHYEXREOprotocol (=$PHYEXREOprotocol)" + echo "--remove removes the pack" echo "" - echo "If nothing is asked (pack creation, compilation, running, check) everything is done" + echo "If nothing is asked (pack creation, compilation, running, check, removing) everything" + echo "except the removing is done" + echo echo "If no test is aked for, the default one ($defaultTest) is executed" echo echo "With the special reference REF commit, a suitable reference is guessed" + echo echo "The directory (for commit only, not ref) can take the form server:directory" + echo echo "If using a directory (for commit or reference) it must contain at least one '/'" echo "The commit can be a tag, written with syntagx tags/<TAG>" echo @@ -141,6 +148,7 @@ useexpand=1 fullcompilation=0 cycle="" scripttag='' +remove=0 while [ -n "$1" ]; do case "$1" in @@ -157,6 +165,7 @@ while [ -n "$1" ]; do '--scripttag') scripttag="$2"; shift;; '--repo-user') export PHYEXREPOuser=$2; shift;; '--repo-protocol') export PHYEXREPOprotocol=$2; shift;; + '--remove') remove=1;; #--) shift; break ;; *) if [ -z "${commit-}" ]; then commit=$1 @@ -195,7 +204,8 @@ fi if [ $packcreation -eq 0 -a \ $compilation -eq 0 -a \ $run -eq 0 -a \ - $check -eq 0 ]; then + $check -eq 0 -a \ + $remove -eq 0 ]; then packcreation=1 compilation=1 run=1 @@ -534,17 +544,18 @@ if [ $compilation -eq 1 ]; then grep -v "'CPLNG: Error" | \ grep -v '"Error' | \ grep -v "'*** Error" | \ - grep -v "-- Up-to-date:" | wc -l) -ne 0 ]; then - echo "MASTERODB was produced but errors occured during compilation:" - grep Error Output_compilation | \ - grep -v TestErrorHandler | \ - grep -v "'Error" | \ - grep -v "'CPLNG: Error" | \ - grep -v '"Error' | \ - grep -v "'*** Error" | \ - grep -v "-- Up-to-date:" - echo "MASTERODB suppressed!" - rm -f bin/MASTERODB + grep -v "\-\- Up-to-date:" | wc -l) -ne 0 ]; then + echo "MASTERODB was produced but errors occured during compilation:" + grep Error Output_compilation | \ + grep -v TestErrorHandler | \ + grep -v "'Error" | \ + grep -v "'CPLNG: Error" | \ + grep -v '"Error' | \ + grep -v "'*** Error" | \ + grep -v "\-\- Up-to-date:" + echo "MASTERODB suppressed!" + rm -f bin/MASTERODB + exit 12 fi fi @@ -566,10 +577,14 @@ if [ $run -ge 1 ]; then #Run the tests one after the other for t in $(echo $tests | sed 's/,/ /g'); do - cd $HOMEPACK/$name - mkdir -p conf_tests/$t - cd conf_tests/$t - MYLIB=$name TESTDIR=$dirconf/$t exescript Output_run $dirconf/$t/aro${cycle}${scripttag}.sh + if echo $allowedTests | grep -w $t; then + cd $HOMEPACK/$name + mkdir -p conf_tests/$t + cd conf_tests/$t + MYLIB=$name TESTDIR=$dirconf/$t exescript Output_run $dirconf/$t/aro${cycle}${scripttag}.sh + else + echo "The test $t is not allowed" + fi done fi @@ -580,10 +595,14 @@ if [ $check -eq 1 ]; then message="" filestocheck="" for t in $(echo $tests | sed 's/,/ /g'); do - if echo $t | grep 'small' > /dev/null; then - filestocheck="$filestocheck ${t},conf_tests/$t/ICMSHFPOS+0002:00 ${t},conf_tests/$t/DHFDLFPOS+0002" + if echo $allowedTests | grep -w $t; then + if echo $t | grep 'small' > /dev/null; then + filestocheck="$filestocheck ${t},conf_tests/$t/ICMSHFPOS+0002:00 ${t},conf_tests/$t/DHFDLFPOS+0002" + else + filestocheck="$filestocheck ${t},conf_tests/$t/NODE.001_01" + fi else - filestocheck="$filestocheck ${t},conf_tests/$t/NODE.001_01" + echo "The test $t is not allowed" fi done for tag_file in $filestocheck; do @@ -656,5 +675,13 @@ if [ $check -eq 1 ]; then else echo "*************** Files are different *******************" echo -e "$message" + cmpstatus=50 fi fi + +if [ $remove -eq 1 ]; then + echo "### Remove model directory for commit $commit" + [ -d $HOMEPACK/$name ] && rm -rf $HOMEPACK/$name +fi + +exit $cmpstatus diff --git a/tools/check_commit_lmdz.sh b/tools/check_commit_lmdz.sh index e9b73e6d8655d1afca5edc867273d72db4312a53..b8b1d0af79d3025a17601f9718d27e38231ca821 100755 --- a/tools/check_commit_lmdz.sh +++ b/tools/check_commit_lmdz.sh @@ -17,7 +17,7 @@ separator='_' #- be carrefull, gmkpack (at least on belenos) has multiple allerg #- seprator must be in sync with prep_code.sh separator function usage { - echo "Usage: $0 [-h] [-p] [-c] [-C] [-r] [-s] [--expand] [-t test] [--version VERSION] [--repo-user] [--repo-protocol] commit [reference]" + echo "Usage: $0 [-h] [-p] [-c] [-C] [-r] [-s] [--expand] [-t test] [--version VERSION] [--repo-user] [--repo-protocol] [--remove] commit [reference]" echo "commit commit hash (or a directory, or among $specialPack) to test" echo "reference commit hash (or a directory, or among $specialPack) REF to use as a reference" echo "-s suppress compilation pack" @@ -34,12 +34,17 @@ function usage { echo " defaults to the env variable PHYEXREOuser (=$PHYEXREOuser)" echo "--repo-protocol protocol (https or ssh) to reach the PHYEX repository on github," echo " defaults to the env variable PHYEXREOprotocol (=$PHYEXREOprotocol)" + echo "--remove removes the pack" echo "" - echo "If nothing is asked (pack creation, compilation, running, check) everything is done" + echo "If nothing is asked (pack creation, compilation, running, check, removing) everything" + echo "except the removing is done" + echo echo "If no test is aked for, the default one ($defaultTest) is executed" echo echo "With the special reference REF commit, a suitable reference is guessed" + echo echo "The directory (for commit only, not ref) can take the form server:directory" + echo echo "If using a directory (for commit or reference) it must contain at least one '/'" echo "The commit can be a tag, written with syntagx tags/<TAG>" } @@ -56,6 +61,7 @@ suppress=0 useexpand=0 version="" link=0 #Not yet put in command line argument becaus this option has not been tested here +remove=0 while [ -n "$1" ]; do case "$1" in @@ -71,6 +77,7 @@ while [ -n "$1" ]; do '--version') version="$2"; shift;; '--repo-user') export PHYEXREPOuser=$2; shift;; '--repo-protocol') export PHYEXREPOprotocol=$2; shift;; + '--remove') remove=1;; #--) shift; break ;; *) if [ -z "${commit-}" ]; then commit=$1 @@ -95,7 +102,8 @@ fi if [ $packcreation -eq 0 -a \ $compilation -eq 0 -a \ $run -eq 0 -a \ - $check -eq 0 ]; then + $check -eq 0 -a \ + $remove -eq 0 ]; then packcreation=1 compilation=1 run=1 @@ -325,3 +333,7 @@ if [ $check -eq 1 ]; then exit 6 fi +if [ $remove -eq 1 ]; then + echo "### Remove model directory for commit $commit" + [ -d $LMDZPACK/$name ] && rm -rf $LMDZPACK/$name +fi diff --git a/tools/check_commit_mesonh.sh b/tools/check_commit_mesonh.sh index 3c54c7b48eda522f644e904e155ab0604b810f40..b3d2835f5b4f05baa97d2207ef2110feadf57daa 100755 --- a/tools/check_commit_mesonh.sh +++ b/tools/check_commit_mesonh.sh @@ -22,7 +22,7 @@ separator='_' #- be carrefull, gmkpack (at least on belenos) has multiple allerg PHYEXTOOLSDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" function usage { - echo "Usage: $0 [-h] [-c] [-r] [-C] [-s] [--expand] [-t test] commit reference" + echo "Usage: $0 [-h] [-c] [-r] [-C] [-s] [--expand] [-t test] [--remove] commit [reference]" echo "commit commit hash (or a directory)" echo "reference commit hash or a directory or nothing for ref" echo "-s suppress compilation pack" @@ -36,14 +36,19 @@ function usage { echo " defaults to the env variable PHYEXREOuser (=$PHYEXREOuser)" echo "--repo-protocol protocol (https or ssh) to reach the PHYEX repository on github," echo " defaults to the env variable PHYEXREOprotocol (=$PHYEXREOprotocol)" + echo "--remove removes the pack" echo "" - echo "If nothing is asked (compilation, running, check) everything is done" - echo - echo "If no test is aked for, the default on ($defaultTest) is executed" + echo "If nothing is asked (compilation, running, check, removing) everything" + echo "except the removing is done" + echo + echo "If no test is aked for, the default one ($defaultTest) is executed" + echo + echo "With the special reference REF commit, a suitable reference is guessed" echo echo "The directory (for commit only, not ref) can take the form server:directory" echo echo "If using a directory (for commit or reference) it must contain at least one '/'" + echo "The commit can be a tag, written with syntagx tags/<TAG>" } compilation=0 @@ -54,6 +59,7 @@ reference="" tests="" suppress=0 useexpand=0 +remove=0 while [ -n "$1" ]; do case "$1" in @@ -66,6 +72,7 @@ while [ -n "$1" ]; do '--expand') useexpand=1;; '--repo-user') export PHYEXREPOuser=$2; shift;; '--repo-protocol') export PHYEXREPOprotocol=$2; shift;; + '--remove') remove=1;; #--) shift; break ;; *) if [ -z "${commit-}" ]; then commit=$1 @@ -94,7 +101,8 @@ fi if [ $compilation -eq 0 -a \ $run -eq 0 -a \ - $check -eq 0 ]; then + $check -eq 0 -a \ + $remove -eq 0 ]; then compilation=1 run=1 check=1 @@ -546,6 +554,14 @@ if [ $check -eq 1 ]; then status="OK" else status="Files are different" + cmpstatus=50 fi echo "...comparison done: $status" fi + +if [ $remove -eq 1 ]; then + echo "### Remove model directory for commit $commit" + [ -d $MNHPACK/$name ] && rm -rf $MNHPACK/$name +fi + +exit $cmpstatus diff --git a/tools/check_commit_testprogs.sh b/tools/check_commit_testprogs.sh index 71e5974838aa09c1a94301db7fbc9b7550561cd5..3314f89eccc4b2f75912b8982cd102c364ca19bb 100755 --- a/tools/check_commit_testprogs.sh +++ b/tools/check_commit_testprogs.sh @@ -46,7 +46,7 @@ fi defaultRef=ref function usage { - echo "Usage: $0 [-h] [-c] [-r] [-C] [-s] [-f] [--noexpand] [-t test] [--repo-user user] [--repo-protocol protocol] [-a arch] [-A arch] commit [reference]" + echo "Usage: $0 [-h] [-c] [-r] [-C] [-s] [-f] [--noexpand] [-t test] [--repo-user user] [--repo-protocol protocol] [-a arch] [-A arch] [--remove] commit [reference]" echo "commit commit hash (or a directory, or among $specialName) to test" echo "reference commit hash (or a directory, or among $specialName) REF to use as a reference" echo "-s suppress compilation directory" @@ -60,18 +60,21 @@ function usage { echo " defaults to the env variable PHYEXREOuser (=$PHYEXREOuser)" echo "--repo-protocol protocol (https or ssh) to reach the PHYEX repository on github," echo " defaults to the env variable PHYEXREOprotocol (=$PHYEXREOprotocol)" + echo "--remove removes the pack" echo "-a arch architecture name to use to build and run the commit (=$defaultarchfile)" echo "-A arch architecture name to use for the reference simulation (=$defaultarchfile)" echo "" - echo "If nothing is asked (compilation, running, check) everything is done" - echo - echo "With the special reference REF commit, a suitable reference is guessed" + echo "If nothing is asked (compilation, running, check, removing) everything" + echo "except the removing is done" echo echo "If no test is aked for, the default one ($defaultTest) is executed" echo + echo "With the special reference REF commit, a suitable reference is guessed" + echo echo "The directory (for commit only, not ref) can take the form server:directory" echo echo "If using a directory (for commit or reference) it must contain at least one '/'" + echo "The commit can be a tag, written with syntagx tags/<TAG>" } compilation=0 @@ -84,6 +87,7 @@ suppress=0 useexpand="" archfile=$defaultarchfile refarchfile=$defaultarchfile +remove=0 while [ -n "$1" ]; do case "$1" in @@ -96,6 +100,7 @@ while [ -n "$1" ]; do '--noexpand') useexpand=$1;; '--repo-user') export PHYEXREPOuser=$2; shift;; '--repo-protocol') export PHYEXREPOprotocol=$2; shift;; + '--remove') remove=1;; '-a') archfile="$2"; shift;; '-A') refarchfile="$2"; shift;; #--) shift; break ;; @@ -136,7 +141,8 @@ fi if [ $compilation -eq 0 -a \ $run -eq 0 -a \ - $check -eq 0 ]; then + $check -eq 0 -a \ + $remove -eq 0 ]; then compilation=1 run=1 check=1 @@ -267,5 +273,13 @@ if [ $check -eq 1 ]; then else echo "*************** Files are different *******************" echo -e "$message" + cmpstatus=50 fi fi + +if [ $remove -eq 1 ]; then + echo "### Remove model directory for commit $commit" + [ -d $TESTDIR/$name ] && rm -rf $TESTDIR/$name +fi + +exit $cmpstatus diff --git a/tools/compare.py b/tools/compare.py index 230462e4f16f8e987fb9acf344d5a7076950abc1..16410e00d3faddfd4647bb5f6a8daa7eb0e9a6f1 100755 --- a/tools/compare.py +++ b/tools/compare.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import xarray as xr +import sys avail_groups=['Stations/sta1', 'LES_budgets/Miscellaneous/Cartesian/Not_time_averaged/Not_normalized/cart/', @@ -119,9 +120,12 @@ if __name__ == "__main__": parser.add_argument('--f3', metavar='file3', type=str, help=".000 file1 user ") parser.add_argument('--f4', metavar='file4', type=str, help=".000 file2 reference") args = parser.parse_args() + totalstatus=0 status1=compareBACKUPFiles(args.f1, args.f2) + totalstatus += status1 print('status1 = ' + str(status1)) if args.f3: status2=compareTSERIESFiles(args.f3, args.f4) + totalstatus += status2 print('status2 = ' + str(status2)) - + sys.exit(totalstatus) diff --git a/tools/testing.sh b/tools/testing.sh new file mode 100755 index 0000000000000000000000000000000000000000..391aa9438dbc3d95cfd211af48313433fa37c2d8 --- /dev/null +++ b/tools/testing.sh @@ -0,0 +1,354 @@ +#!/bin/bash + +set -e +set -o pipefail #abort if left command on a pipe fails + +function usage { + echo "Usage: $0 [-h] [--repo-user] [--repo-protocol] [--repo-repo] [--no-update] [--no-compil]" + echo " [--no-exec] [--no-comp] [--no-remove] [--commit SHA] [--ref REF] [--force] [MAIL]" + echo "--repo-user user hosting the PHYEX repository on github," + echo " defaults to the env variable PHYEXREPOuser (=$PHYEXREPOuser)" + echo "--repo-protocol protocol (https or ssh) to reach the PHYEX repository on github," + echo " defaults to the env variable PHYEXREPOprotocol (=$PHYEXREPOprotocol)" + echo "--repo-repo repository name" + echo " defaults to the env variable PHYEXREPOrepo (=$PHYEXREPOrepo)" + echo "--no-update do not update the tools" + echo "--no-compil do not compil (only usefull after a first execution with --no-update)" + echo "--no-exec do not execute (only usefull after a first execution with --no-update)" + echo "--no-comp do not compare (only usefull after a first execution with --no-update)" + echo "--no-remove do not remove compilation directory" + echo "--force perform the test even if github commit comment already exists" + echo "--commit SHA use the commit with sha SHA instead of the last one" + echo "--ref REF ref to use (defaults to refs/heads/master)" + echo "--only-model MODEL" + echo " performs the test only using model MODEL (option can be provided several times)" + echo "MAIL comma-separated list of e-mail addresses (no spaces); if not provided, mail is not sent" + echo "" + echo "This script provides functionality for automated tests." + echo "It can be run with cron to periodically test the last commit on the PHYEX repository" + echo "(eg '00 22 * * * bash -l -c \"SHELL=/bin/bash PHYEXWORKDIR=~/PHYEXTESTING ~/PHYEXTESTING/PHYEX/tools/testing.sh \\" + echo " --repo-user UMR-CNRM --repo-protocol ssh --repo-repo PHYEX user@domain\"')" + echo "The repository must be hosted on github as it relies on github commit comments functionnality." + echo "A github token must be set in the .netrc file." + echo "" + echo "All the work is done within the \${PHYEXWORKDIR} directory (it defaults to ~/PHYEXTESTING)." + echo "It may be necessary to fill the \${PHYEXWORKDIR}/PHYEX/tools/pack with base source code" + echo "(for arome and/or mesonh) or with data (testprogs)." + echo "" + echo "The script compare the results against reference simulations. These reference simulations must" + echo "be available in the different subdirectories in \${WORKDIR}." +} + +MAIL="" +PHYEXREPOuser=${PHYEXREPOuser:=UMR-CNRM} +PHYEXREPOrepo=${PHYEXREPOrepo:=PHYEX} +PHYEXREPOprotocol=${PHYEXREPOprotocol:=ssh} +REF="refs/heads/master" +WORKDIR=${PHYEXWORKDIR:=${HOME}/PHYEXTESTING} +update=1 +compil=1 +execute=1 +comp=1 +remove=1 +commit="" +SHA=0 +force=0 +models="" + +while [ -n "$1" ]; do + case "$1" in + '-h') usage; exit;; + '--repo-user') export PHYEXREPOuser=$2; shift;; + '--repo-protocol') export PHYEXREPOprotocol=$2; shift;; + '--repo-repo') export PHYEXREPOrepo=$2; shift;; + '--no-update') update=0;; + '--no-compil') compil=0;; + '--no-exec') execute=0;; + '--no-comp') comp=0;; + '--no-remove') remove=0;; + '--force') force=1;; + '--commit') SHA=$2; shift;; + '--ref') REF=$2; shift;; + '--only-model') models="${models} $2"; shift;; + #--) shift; break ;; + *) if [ -z "${MAIL-}" ]; then + MAIL="$1" + else + echo "Only one email address allowed" + exit 1 + fi;; + esac + shift +done +[ "${models}" == "" ] && models="ial mesonh testprogs lmdz" + +[ ! -d ${WORKDIR} ] && mkdir -p ${WORKDIR} + +#stdout and stderr redirection +logfile="${WORKDIR}/logfile" +exec > "${logfile}" 2>&1 + +#Title used to identify comments added by this script +title="__ PHYEX TESTING V1.0 ${HOSTNAME} __" + +#Interactions with github +if [ "${PHYEXREPOprotocol}" == 'ssh' ]; then + PHYEXREPOgiturl="git@github.com:${PHYEXREPOuser}/${PHYEXREPOrepo}.git" +else + PHYEXREPOgiturl="https://github.com/${PHYEXREPOuser}/${PHYEXREPOrepo}.git" +fi +function get_last_commit { + git ls-remote "${PHYEXREPOgiturl}" "${REF}" | cut -f1 +} + +function get_comments { + SHA="$1" + curl -L --netrc \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "https://api.github.com/repos/${PHYEXREPOuser}/${PHYEXREPOrepo}/commits/${SHA}/comments" +} + +function add_comment { + SHA="$1" + comment="$2" + + #The --netrc option does not seem to be enough, we manually read token from the .netrc file + TOKEN=$(python3 -c "import netrc, socket; print(netrc.netrc().authenticators('github.com')[2])") + curl -L --netrc \ + -X POST \ + -H "Authorization: Bearer $TOKEN"\ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "https://api.github.com/repos/${PHYEXREPOuser}/${PHYEXREPOrepo}/commits/${SHA}/comments" \ + -d "{\"body\":\"${comment}\"}" +} + +function get_cases { + SHA="$1" + file="$2" + + url="https://raw.githubusercontent.com/${PHYEXREPOuser}/${PHYEXREPOrepo}/${SHA}/${file}" + content=$(wget --no-check-certificate "${url}" -O - 2>/dev/null) + if [ "${content}" != "" ]; then + content="${content}" python3 -c "import json, os; print(' '.join([k+':'+v for k, v in json.loads(os.environ['content']).get('testing', {}).items()]))" + fi +} + +#reporting +function send_mail { + message="$1" + if [ "$MAIL" != "" ]; then + mail -s "$title" "$MAIL" <<EOF +$(echo -e ${message}) +EOF + fi +} + +header="${title}\n\n$(date)" +message="" +function report { + ret=$1 + if [ ${ret} -eq 0 ]; then + error_msg="" + else + error_msg="XXXXXXXXXXXXXXXXXXXX ERROR ${ret} XXXXXXXXXXXXXXXXXXXX" + error_msg="${error_msg}\n\n" + fi + message="${header}\n${message}\n\n${error_msg}$(date)" + if [ ${ret} -ne 0 ]; then + send_mail "${message}" + fi + if [ "${SHA}" != 0 ]; then + add_comment "${SHA}" "${message}" + fi +} + +log_message="" +function exit_error { + ret=$1 + if [ ${ret} -ne 0 ]; then + message="__ ABNORMAL EXIT ${ret} __\n${log_message}\n${message}" + message="${message}\n\nMore information can be found in ${HOSTNAME}:${logfile}" + report ${ret} + fi +} +trap 'exit_error $?' EXIT + +function log { + level=$1; shift + echo "$@" + if [ ${level} -eq 0 ]; then + message="${message}\n$@" + fi + log_message="${log_message}\n$@" +} + +#Test +if [ "${SHA}" -eq 0 ]; then + log 1 "Getting last commit hash" + SHA=$(get_last_commit) + log 1 "Commit hash is ${SHA}" +fi +if [ ${force} -eq 1 -o $(get_comments "${SHA}" | grep "${title}" | wc -l) -eq 0 ]; then + log 1 "This commit has not been tested (or --force id provided)" + ret=0 + + export TESTPROGSDIR="${WORKDIR}/TESTPROGS" + export HOMEPACK="${WORKDIR}/pack" + export MNHPACK="${WORKDIR}/MesoNH" + export LMDZPACK="${WORKDIR}/LMDZ" + for d in "${TESTPROGSDIR}" "${HOMEPACK}" "${MNHPACK}" "${LMDZPACK}"; do + if [ ! -d "${d}" ]; then + log 1 "Creating directory ${d}" + mkdir -p "${d}" + fi + done + + #Checkout tools, set PATH and use the last version of the testing script + currentdir="${PWD}" + if [ ${update} -eq 1 ]; then + currentMD5=$(md5sum "${BASH_SOURCE[0]}" | cut -d\ -f1) + if [ ! -d "${WORKDIR}/PHYEX" ]; then + log 1 "Clonig PHYEX in ${WORKDIR}/PHYEX" + git clone "${PHYEXREPOgiturl}" "${WORKDIR}/PHYEX" + + log 1 "Installing filepp" + cd tools/mnh_expand + wget https://www-users.york.ac.uk/~dm26/filepp/filepp-1.8.0.tar.gz + tar xvf filepp-1.8.0.tar.gz + cd filepp-1.8.0 + ./configure --prefix="${PWD}" + make install + cd .. + ln -s filepp-1.8.0 filepp + + log 1 "Installing MNH_Expand_Array" + git clone https://github.com/JuanEscobarMunoz/MNH_Expand_Array.git + fi + log 1 "Checkout commit ${SHA}" + cd "${WORKDIR}/PHYEX" + git fetch "${PHYEXREPOgiturl}" + git checkout "${SHA}" + cd "${currentdir}" + . "${WORKDIR}/PHYEX/tools/env.sh" + if [ -f "${WORKDIR}/PHYEX/tools/testing.sh" ]; then + if [ "${currentMD5}" != $(md5sum "${WORKDIR}/PHYEX/tools/testing.sh" | cut -d\ -f1) ]; then + log 1 "Script has changed, running the new version" #This log and the preivous ones are lost + exec "${WORKDIR}/PHYEX/tools/testing.sh" $@ + fi + fi + fi + + for model in $models; do + log 1 "Starting tests for model ${model}" + #Model specific configuration + if [ "${model}" == 'ial' ]; then + compilation='-p -c' + execution='-r' + jsonfile="src/arome/ial_version.json" + docmp=1 + elif [ "${model}" == 'lmdz' ]; then + compilation='-p -c --nofcm' + execution='-r --nofcm' + jsonfile="src/${model}/${model}_version.json" + docmp=0 + else + compilation='-c' + execution='-r' + jsonfile="src/${model}/${model}_version.json" + docmp=1 + fi + + #Commande + cmd="check_commit_${model}.sh --repo-user ${PHYEXREPOuser} --repo-protocol ${PHYEXREPOprotocol} ${SHA}" + + #Compilation + result=0 + if [ ${compil} -eq 1 ]; then + compilecmd="$cmd ${compilation}" + log 1 "Compilation with ${compilecmd}" + set +e + ${compilecmd} + result=$? + set -e + if [ ${result} -ne 0 ]; then + ret=1 + log 0 "${model} compilation: error" + else + log 0 "${model} compilation: OK" + fi + fi + + #Execution and comparison + if [ ${result} -eq 0 ]; then + #Get the list of cases with associated references + cases=$(get_cases "${SHA}" "${jsonfile}") + [ "${cases}" == "" ] && cases="DEF:DEF" + for case_ref in ${cases}; do + case=$(echo "${case_ref}" | cut -d: -f1) + ref=$(echo "${case_ref}" | cut -d: -f2) + if [ "${case}" == "DEF" -a "${ref}" == "DEF" ]; then + casearg="" + refarg="REF" + casedescr="default case(s)" + log 1 "No cases found in ${jsonfile}, we only test the default cases" + else + casearg="-t ${case}" + refarg="${ref}" + casedescr="${case} (ref=${ref})" + log 1 "Testing case ${case} against reference ${ref}" + fi + + result=0 + if [ ${execute} -eq 1 ]; then + execcmd="$cmd ${execution} ${casearg}" + log 1 "Excution with ${execcmd}" + set +e + ${execcmd} + result=$? + set -e + if [ ${result} -ne 0 ]; then + ret=1 + log 0 " ${model} ${casedescr}: execution error" + else + log 0 " ${model} ${casedescr}: execution OK (but status not reliable)" + fi + fi + if [ ${result} -eq 0 -a ${docmp} -eq 1 -a ${comp} -eq 1 ]; then + compcmd="$cmd -C ${casearg} ${refarg}" + log 1 "Comparison with ${compcmd}" + set +e + ${compcmd} + result=$? + set -e + if [ ${result} -ne 0 ]; then + ret=1 + log 0 " ${model} ${casedescr}: comparison error" + else + log 0 " ${model} ${casedescr}: comparison OK" + fi + fi + done + + #Cleaning + if [ ${remove} -eq 1 ]; then + cleancmd="${cmd} --remove" + log 1 "Cleaning with ${cleancmd}" + set +e + ${cleancmd} + result=$? + set -e + if [ ${result} -ne 0 ]; then + ret=1 + log 0 " ${model}: cleaning error" + else + log 0 " ${model}: cleaning OK" + fi + fi + fi + done + + #Report result + report ${ret} +fi