New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
trusting.sh in branches/2015/dev_r5092_CNRS18_TRUST/NEMOGCM/TRUST – NEMO

source: branches/2015/dev_r5092_CNRS18_TRUST/NEMOGCM/TRUST/trusting.sh @ 8883

Last change on this file since 8883 was 8883, checked in by nicolasmartin, 6 years ago

Continuation of global refactoring of Trusting tool: modification of options list to maintain consistency with makenemo
After getting a code snippet on https://stackoverflow.com/questions/402377/using-getopts-in-bash-shell-script-to-get-long-and-short-command-line-options in order to handle short '-[a-z]' and long '[a-z]*=' options, I have modified the main trusting script to split betwwen:

  • Short options reserved shared options with makenemo ( -[hjmnr])
  • Long pattern for trusting specified options
  • Property svn:executable set to *
File size: 6.2 KB
Line 
1#!/bin/bash
2
3
4## Possibility to call from outside
5cd $( dirname $0 )
6TRUST_MAIN_DIR=$PWD
7
8## Tool revision in use
9rev=$( svn info | awk '/Last Changed Rev/ {print $NF}' )
10
11
12##--------------------------------------------------------------------------------
13## Flags default
14##--------------------------------------------------------------------------------
15
16TRUST_FLAG_DEBUG='false'; TRUST_FLAG_DEV='false'
17TRUST_FLAG_HELP='false' ; TRUST_FLAG_PROD='false'
18
19
20##--------------------------------------------------------------------------------
21## Options from command line
22##--------------------------------------------------------------------------------
23
24while getopts ab:c:de:hj:lm:n:p:r:s:t:u:v:-: shortopt; do
25
26##  Attempt to maintain consistency with 'makenemo' available options
27##o makenemo: a d e h j k m n r s t u v
28##o trusting: | | | = = | = = = | | | |
29
30    case $shortopt in
31   ## Mandatory (HPCC environment)
32   'm') TRUST_MAIN_HPCC=$OPTARG    ;;
33
34   ## NEMO configuration
35   'n') TRUST_CFG_NEW=$OPTARG      ;; 'r') TRUST_CFG_REF=$OPTARG     ;;
36
37   ## Compilation
38   'j') TRUST_COMPILE_NPROC=$OPTARG;;
39
40   ## Flags
41   'h') TRUST_FLAG_HELP='true'     ;;
42
43   ## Implement long options for specific not to reducing further short possibilites
44   ## https://stackoverflow.com/questions/402377/using-getopts-in-bash-shell-script-to-get-long-and-short-command-line-options
45   '-')
46       [ $OPTIND -ge 1 ] && optind=$( expr $OPTIND - 1 ) || optind=$OPTIND
47            longopt=${!optind}
48       
49       OPTION=${longopt/=[0-9A-Za-z_-]*/}; OPTARG=${longopt/[a-z-]*=/}
50
51            case $OPTION in
52      ## Mandatory (installation environment)
53      '--setup'   ) TRUST_MAIN_SETUP=$OPTARG   ;;
54
55      ##  Alt 'CONFIG' directory for standalone 'TRUST' to check several local branches
56      ##+ (default to ./../CONFIG parent)
57      '--cfgdir'  ) TRUST_DIR_WORK=$OPTARG     ;;
58
59      ## Local working copy
60      '--branch'  ) TRUST_SVN_BRANCH=$OPTARG   ;;
61      '--update'  ) TRUST_SVN_REV=$OPTARG      ;;
62
63      ## Compilation & Computing
64      '--timeout' ) TRUST_JOB_TIMEOUT=$OPTARG  ;;
65
66      ## Inputs
67      '--forctar' ) 
68          TRUST_IO_FORC_TAR=''
69
70          ## Set but not empty
71          if [ $OPTARG ]; then
72         TRUST_IO_FORC_TAR=$OPTARG
73          else
74         OPTARG='null'
75          fi
76                                                         ;;
77      '--forcpath') TRUST_IO_FORC_PATH=$OPTARG ;;
78
79      ## Mailing
80      '--email'   ) TRUST_TEST_MAILING=$OPTARG ;;
81
82      ## Flags (no argument needed)
83      '--dev'     ) TRUST_FLAG_DEV='true'  ; OPTARG='null';;
84      '--prod'    ) TRUST_FLAG_PROD='true' ; OPTARG='null';;
85      '--debug'   ) TRUST_FLAG_DEBUG='true'; OPTARG='null';;
86
87      *           ) printf "\033[0;31m%s illegal long option %s\033[0m\n" \
88          $0 $OPTION;;
89            esac
90
91       OPTIND=1; shift             ;;
92
93   ## Illegal option
94   '?')  TRUST_FLAG_HELP='true'    ;;
95    esac
96
97done
98
99
100##--------------------------------------------------------------------------------
101## Initialization (user & HPC environment)
102##--------------------------------------------------------------------------------
103
104if [[ ! -e ./cfg/${TRUST_MAIN_SETUP}.cfg || ! -e ./cfg/${TRUST_MAIN_HPCC}.cfg ]]; then
105
106    printf "\nUsage: %s -m arch --setup cfg [OPTIONS]\n"        $0
107    printf "\nSee help for options description, %s -h|--help\n" $0
108
109    ## Color this section to part with help
110    printf "\033[0;33m"
111
112    if [ ${TRUST_FLAG_HELP} == 'false' ]; then
113   printf "                                                           \
114       \nAt least 1 cfg file (arch or user) is missing or misspelled: \
115       '%s.cfg' or '%s.cfg'\n"                                        \
116       ${TRUST_MAIN_SETUP} ${TRUST_MAIN_HPCC}
117    else
118   printf "\033[0m"
119   cat ./inc/help.txt
120    fi
121
122    echo -e "\nContent of './cfg' folder:"
123    find ./cfg -name *.cfg | cut -d/ -f3 \
124   | xargs -n 3 printf "%-20s\t%-20s\t%-20s\n"
125    printf "\033[0m\n"
126
127    exit 1
128else
129    ## Verbose output on debug mode
130    [ ${TRUST_FLAG_DEBUG} == 'true' ] && set -vx
131
132    . ./inc/env.sh
133    . ./inc/functions.sh
134
135fi
136
137
138##--------------------------------------------------------------------------------
139## Trusting workflow
140##--------------------------------------------------------------------------------
141
142## Test summary
143##-------------
144
145echo
146## Formatting for email (test not in interactive mode)
147[ ! -t 0 ] && echo '<pre style="font: 2px/1px monospace;">'
148cat ./inc/banner.txt
149[ ! -t 0 ] && echo '</pre>'
150echo
151echo '****************************************************************************************************'
152echo '*                                                                                                  *'
153echo '*                           NEMO Trusting (Continuous Integration Tool)                            *'
154echo "*                                             ver.$rev                                             *"
155echo '*                                                                                                  *'
156echo '****************************************************************************************************'
157echo
158printf "\t§ Testing configuration\t\t%s on branch %s\n" \ ${TRUST_CFG_REF} ${TRUST_SVN_BRANCH}
159printf "\t§ (Super)Computer\t\t%s\n"                ${TRUST_MAIN_HPCC}
160printf "\t§ User installation\t\t%s\n\n"            ${TRUST_MAIN_SETUP}
161echo
162if [ ${TRUST_TEST_BENCHMARK} ]; then
163printf "\t§ Benchmark folder\n\t\t\t%s\n"                 ${TRUST_TEST_BENCHMARK}
164fi
165
166
167## Testing directory
168##------------------
169
170step 'Testing directory'
171init
172
173
174## Local working copy
175##-------------------
176
177step 'Local working copy'
178
179echo "${TRUST_SVN_ACTION} on ${TRUST_SVN_NEMOGCM}:"
180get_nemo_rev
181
182
183## Environment
184##------------
185
186step 'Environment'
187get_soft_rel
188
189
190## Compilation(s)
191##---------------
192
193step 'Compilation(s)'
194
195printf "XIOS? "
196compile_xios
197
198printf "\nNEMO ${TRUST_CFG_NEW} cfg. from ${TRUST_CFG_REF}? "
199compile_nemo
200
201
202## Inputs
203##-------
204
205step 'Inputs'
206
207get_inputs
208
209printf "\nCompare with benchmark? "
210diff_inputs
211
212
213## Job
214##----
215
216step 'Job'
217
218printf "Submit? "
219job_submit
220
221echo 'Pending...'
222job_pending
223
224echo 'Finished!'
225
226printf "State? "
227job_state
228
229printf "Perfs?\n"
230job_perfs
231
232
233## Output(s)
234##----------
235
236step 'Ouput(s)'
237
238echo 'Compare with benchmark:'
239
240printf "Plain text files? "
241diff_results
242
243printf "Restart files? "
244diff_restarts
245
246
247## End, at least nothing major has changed ;-)
248##--------------------------------------------
249
250get_out 0
Note: See TracBrowser for help on using the repository browser.