forked from E4S-Project/testsuite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-all.sh
executable file
·265 lines (238 loc) · 7.17 KB
/
test-all.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/bin/bash
final_ret=0
ran_test=true
print_json=false
print_logs=false
basedir=validation_tests
export e4s_print_color=true
skip_to=""
testtime=$(date +"%Y-%m-%d_%T")
if [[ $# -gt 0 && -d $1 ]] ; then
basedir=$1
fi
while test $# -gt 0
do
if [[ -d $1 ]] ; then
basedir=$1
else
case "$1" in
--json) print_json=true
;;
--print-logs) print_logs=true
;;
--settings) export TESTSUITE_SETTINGS_FILE=`readlink -f "$2"`
shift
;;
--color-off) export e4s_print_color=false
;;
--skip-to) skip_to="$2"
shift
;;
--test-only) test_only="$2"
shift
;;
--help)
echo "Usage:"
echo " ./test-all.sh [Test Directory (Optional.)] <--json> <--settings [settings file]> <--color-off>"
echo " --json: Print json output. Redirect to file manually if needed. e.g. ./test-all.sh --json > testout.json"
echo " --print-logs: Print contents of all clean/compiler/run logs to screen."
echo " --settings </path/to/some.settings.sh>: Use the specified settings.sh file to define compile and run options.
Defaults to <testsuite>/settings.sh"
echo " --color-off: disable printing test results in color"
echo " --skip-to [test]: Start with the specified test, skipping over any listed earlier in lexical order."
echo " --test-only [\"list of tests\"]: Run only the tests named in the list."
echo "Examples:"
echo " ./test-all.sh #Run all tests in the <testsuite>/validation_tests directory"
echo " ./test-all.sh /path/to/test/directory #Run all tests in the specified directory"
echo " ./test-all.sh /path/to/test/directory --json --settings /path/to/some.settings.sh #Run all tests in the specified directory,
#print output as json, use some.settings.sh as settings file"
exit 0
esac
fi
shift
done
if [ $e4s_print_color = true -a -n "$TERM" ];
then
bold=$(tput bold)$(tput setaf 1)
green=$(tput bold)$(tput setaf 2)
yellow=$(tput bold)$(tput setaf 3)
normal=$(tput sgr0);
fi
. ./setup.sh
if [ $print_json = true ]; then
echo "["
fi
# If $1 is a directory, run tests or recurse into it.
iterate_directories() {
testdir=$1
local _ret
if [ -d $testdir ] ; then
cd $testdir
if [ $print_json != true ]; then
echo "==="
echo $testdir
fi
cwd=`pwd`
if [ -e "$cwd/run.sh" ] ; then
#echo "Running in $cwd"
local itout
itout=$(iterate_files)
_ret=$?
echo $itout
if [ $_ret -ne 0 ] ; then
final_ret=$( expr $final_ret + 1 )
fi
#if [ $print_json = true ]; then
# echo "}},"
#fi
else
#set -x
for d in */ ; do
if [ ! -z $skip_to ] && [[ $d < $skip_to ]]; then
continue
fi
if [ ! -z "$test_only" ] && echo "$test_only" | grep -vw -P "(?<![\w-])`basename $d`(?![\w-])" >/dev/null; then
continue
fi
#echo $d
iterate_directories $d
done
fi
cd ..
fi
}
# Check to see if this directory has clean, compile and run scripts.
# If so, set a flag so we don't recurse further.
iterate_files() {
cwd=`pwd`
local _ret
if [ $print_json = true ]; then
printf "{\"test\": \"$testdir\", \"test_stages\": {"
fi
unset E4S_TEST_SETUP
export SPACK_LOAD_RESULT=0
source $cwd/setup.sh >&2
_ret=$SPACK_LOAD_RESULT
export E4S_TEST_SETUP=1
E4S_LOG_SUFFIX="$(basename $cwd)"_"$E4S_TEST_HASH"_"$testtime".log
#echo $E4S_LOG_SUFFIX >&2
#echo "SPACK LOAD RESULT RETURN: $_ret" >&2
if [ $_ret -eq 215 ] ; then
if [ $print_json = true ]; then
echo "\"setup\":\"missing\"}},"
else
echo "Required Spack Packages ${yellow}Not Found${normal}" >&2
fi
return $_ret
fi
if [ $_ret -ne 0 ] ; then
if [ $print_json = true ]; then
echo "\"setup\":\"fail\"}},"
else
echo "Setup ${bold}failed${normal}" >&2
fi
return $_ret
fi
if [ -e "$cwd/clean.sh" ] ; then
if [ $print_json = true ]; then
printf "\"clean\":"
else
echo "Cleaning $cwd" >&2
fi
./clean.sh >& ./clean-"$E4S_LOG_SUFFIX"
_ret=$?
if [ $print_logs = true ]; then
echo "---CLEANUP LOG---" >&2
cat ./clean-$E4S_LOG_SUFFIX >&2
fi
if [ $_ret -eq 215 ] ; then
if [ $print_json = true ]; then
echo "\"missing\"}},"
else
echo "Required Spack Packages ${yellow}Not Found${normal}" >&2
fi
return $_ret
fi
if [ $_ret -ne 0 ] ; then
if [ $print_json = true ]; then
echo "\"fail\"}},"
else
echo "Clean ${bold}failed${normal}" >&2
fi
return $_ret
fi
if [ $print_json = true ]; then
printf "\"pass\","
fi
fi
if [ -e "$cwd/compile.sh" ] ; then
if [ $print_json = true ]; then
printf "\"compile\":"
else
echo "Compiling $cwd" >&2
fi
./compile.sh >& ./compile-$E4S_LOG_SUFFIX
_ret=$?
if [ $print_logs = true ]; then
echo "---COMPILE LOG---" >&2
cat ./compile-$E4S_LOG_SUFFIX >&2
fi
if [ $_ret -eq 215 ] ; then
if [ $print_json = true ]; then
echo "\"missing\"}},"
else
echo "Required Spack Packages ${yellow}Not Found${normal}" >&2
fi
return $_ret
fi
if [ $_ret -ne 0 ] ; then
if [ $print_json = true ]; then
echo "\"fail\"}},"
else
echo "Compile ${bold}failed${normal}" >&2
fi
return $_ret
fi
if [ $print_json = true ]; then
printf "\"pass\","
fi
fi
if [ $print_json = true ]; then
printf "\"run\":"
else
echo "Running $cwd" >&2
fi
./run.sh >& run-$E4S_LOG_SUFFIX
_ret=$?
if [ $print_logs = true ]; then
echo "---RUN LOG---"
cat ./run-$E4S_LOG_SUFFIX >&2
fi
if [ $_ret -eq 215 ] ; then
if [ $print_json = true ]; then
echo "\"missing\"}},"
else
echo "Required Spack Packages ${yellow}Not Found${normal}" >&2
fi
return $_ret
fi
if [ $_ret -ne 0 ] ; then
if [ $print_json = true ]; then
echo "\"fail\"}},"
else
echo "Run ${bold}failed${normal}" >&2
fi
return $_ret
fi
if [ $print_json = true ]; then
echo "\"pass\"}},"
else
echo "${green}Success${normal}" >&2
fi
}
#set -x
iterate_directories $basedir
if [ $print_json = true ]; then
echo "{}]"
fi
exit $final_ret