forked from jmccreight/wrf_hydro_tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
take_test.sh
executable file
·191 lines (163 loc) · 6.95 KB
/
take_test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/bin/bash
TAKE_TEST_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
currentTestTags=\
`for i in $TAKE_TEST_DIR/tests/*.sh; do
echo " "$(basename $i) | rev | cut -c4- | rev;
done`
theHelp="
take_test: help
A machine specification file is required for
every machine and should be placed in
~/.wrf_hydro_tests_machine_spec.sh
Arguments:
1: candidateSpecFile:
Relative or absolute path to a copy of
wrf_hydr_tests/candidate_template.sh
with details for the specific candidate.
2: testSpec:
Either
1) A file specifying the test (set of
questions) to run on the candidate,
or
2) A known tag for a canned test. The
current list of tags (relative to
where take_test lives, not necessarily
the same as $WRF_HYDRO_TESTS_DIR):
$currentTestTags
"
if [[ -z $1 ]] || [[ -z $2 ]]; then
message="\e[7;49;32mtake_test.sh: Incorrect usage. Please read the following help: \e[0m"
echo -e "$message"
echo -e "$theHelp"
exit 1
fi
#Convert the specification paths to absolute paths if needed.
candidateSpecFile=`readlink -f ${1}`
testSpecFile=`readlink -e ${2}`
#######################################################
# Read the 4 specification files: candidate, machine, user, test.
# User specification, first time.
if [[ -z $WRF_HYDRO_TESTS_USER_SPEC ]]; then
export WRF_HYDRO_TESTS_USER_SPEC=~/.wrf_hydro_tests_user_spec.sh
fi
## TODO: test for existence
source $WRF_HYDRO_TESTS_USER_SPEC
## Candidate specification
## TODO: test for existence
source $candidateSpecFile
# Establish the machine specifications.
if [[ -z $WRF_HYDRO_TESTS_MACHINE_SPEC ]]; then
export WRF_HYDRO_TESTS_MACHINE_SPEC=$WRF_HYDRO_TESTS_DIR/machine_spec.sh
fi
## TODO: test for existence
source $WRF_HYDRO_TESTS_MACHINE_SPEC
# User specification, again.
if [[ -z $WRF_HYDRO_TESTS_USER_SPEC ]]; then
export WRF_HYDRO_TESTS_USER_SPEC=~/.wrf_hydro_tests_user_spec.sh
fi
## TODO: test for existence
source $WRF_HYDRO_TESTS_USER_SPEC
# Does test specification testSpecFile exist? If not, does its tag yield a file in the repo?
# If $2 was not a file, then $testSpecFile will be null
if [[ ! -e $testSpecFile ]]; then
testSpecFile=`readlink -e $WRF_HYDRO_TESTS_DIR/tests/${2}.sh`
if [[ ! -e $testSpecFile ]]; then
echo
echo The second argument, the test specification, does not
echo indicate any file.
echo Neither:
echo `readlink -e ${2}`
echo nor
echo `readlink -e $WRF_HYDRO_TESTS_DIR/tests/${2}.sh`
echo is a file.
# echo "$theHelp"
# Echoing help is potentially confusing because the $WRF_HYDRO_RESTS_DIR
# may not match the users expectation (pulled remote vs local).
echo Exiting.
exit 1
fi
fi
#######################################################
## Now establish logging.
export logFile=`$WRF_HYDRO_TESTS_DIR/toolbox/make_log_file_name.sh $candidateSpecFile $testSpecFile`
rm -f $logFile
function echoTee { echo "$@" 2>&1 | tee -a $logFile; }
# Get the commit of the testing repo being used.
cd $WRF_HYDRO_TESTS_DIR
whTestsCommit=`git rev-parse HEAD`
git diff-index --quiet HEAD --
whTestsUncommitted=$?
cd - > /dev/null 2>&1
# Assume failure for this script if the first
# addition is zero, exitValue is set to zero. Aggregated after that.
exitValue=1
# Reuse this
horizBar='\e[7;49;32m=================================================================\e[0m'
## Boiler plate
echoTee
echoTee -e "$horizBar"
message="\e[7;49;32mtake_test.sh: A wrf_hydro candidate takes a test. \e[0m"
echoTee -e "$message"
echoTee
echoTee -e "\e[0;49;32mBoilerplate:\e[0m"
echoTee "Date : `date +'%Y %h %d %H:%M:%S %Z'`"
echoTee "User : `whoami`"
echoTee "Machine : $HOSTNAME"
echoTee "wrf_hydro_tests commit: $whTestsCommit"
if [[ $whTestsUncommitted -eq 1 ]]; then
echoTee "There are uncommitted changes to wrf_hydro_tests."
fi
echoTee "machine spec file : $WRF_HYDRO_TESTS_MACHINE_SPEC"
echoTee "candidateSpecFile : $candidateSpecFile"
echoTee "testSpecFile : $testSpecFile"
echoTee "Log file : $logFile"
echoTee "Will echo candidateSpecFile to log at end."
echoTee
echoTee -e "$horizBar"
message="\e[7;49;32mSetting up the candidate \e[0m"
echoTee -e "$message"
source $WRF_HYDRO_TESTS_DIR/setup.sh
echoTee
echoTee -e "$horizBar"
message="\e[7;49;32mTesting the candidate \e[0m"
echoTee -e "$message"
$testSpecFile 2>&1 | tee -a $logFile
## The following is how you get a return status in spite of tee.
testExitValue=${PIPESTATUS[0]}
echoTee
echoTee -e "$horizBar"
message="\e[7;49;32mResults of all tests. \e[0m"
echoTee -e "$message"
if [[ $testExitValue -ne 0 ]]; then
message="\e[5;49;31mA total of $testExitValue tests failed.\e[0m"
else
message="\e[5;49;32mAll test appear successful.\e[0m"
fi
echoTee -e "$message"
if [[ $? == 0 ]]; then exitValue=0; else exitValue=$testExitValue; fi
echoTee
echoTee -e "$horizBar"
message="\e[7;49;32mTaking down the candidate. \e[0m"
echoTee -e "$message"
#$WRF_HYDRO_TESTS_DIR/take_down.sh
echoTee
echoTee -e "$horizBar"
message="\e[7;49;32mLogging the candidateSpecFile. \e[0m"
echoTee -e "$message"
source $WRF_HYDRO_TESTS_DIR/toolbox/echo_candidate.sh >> $logFile
echoTee
echoTee -e "$horizBar"
message="\e[7;49;32mCandidate testing complete. \e[0m"
echoTee -e "$message"
exitValue=$(($?+$exitValue))
## How to handle the exit
if [[ $inDocker == TRUE ]]; then
if [[ $testExitValue -ne 0 ]]; then
echoTee -e "\e[5;49;31mEntering docker interactively because some tests failed.\e[0m"
exec /bin/bash
else
exit 0
fi
else
exit $exitValue
fi