-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.sh
executable file
·633 lines (564 loc) · 15.3 KB
/
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
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
#!/bin/sh
# $PIP_license: <Simplified BSD License>
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
# $
# $RIKEN_copyright: Riken Center for Computational Sceience (R-CCS),
# System Software Development Team, 2016-2020
# $
# $PIP_TESTSUITE: Version 1.0.0$
#
# $Author: Atsushi Hori (R-CCS) mailto: ahori@riken.jp or ahori@me.com
# $
# XXX TO-DO: LC_ALL=en_US.UTF-8 doesn't work if custom-built libc is used
unset LANG LC_ALL
TEST_TRAP_SIGS='1 2 14 15';
longestmsg=" T -- UNRESOLVED :-O";
width=60;
print_usage()
{
echo >&2 "Usage: `basename $cmd` [-APLGCT] [-thread] [-process[:preload|:got|:pipclone]] [<test_list_file>]";
exit 2;
}
set_term_width() {
if [ "x$COLUMNS" != "x" ]; then
termwidth=${COLUMNS};
elif [ "x$TERM" != "xdumb" ]; then
termwidth=`tput cols`;
else
termwidth=80;
fi
lmsglen=${#longestmsg};
width=$((termwidth-lmsglen));
if [ $width -lt 40 ]; then
width=60;
fi
}
# not to print any debug messages
export PIP_NODEBUG=1;
check_command() {
prog=$@;
if ! $@ > /dev/null 2>&1; then
echo "[$prog] does not work properly";
exit 2;
fi
}
rprocs=`ps rux | wc -l`;
if [ $rprocs -gt 3 ]; then
echo >&2 "WARNING: some other processes seem to be running ... ($rprocs)"
fi
check_command "dirname ."
check_command "basename ."
dir=`dirname $0`;
dir_real=`cd $dir && pwd`
base=`basename $0`;
myself=$dir_real/$base;
if ! [ -f ${dir_real}/config.sh ]; then
${dir_real}/configure --help
exit 1
fi
. $dir_real/config.sh
BUILD_VERSION_FILE="${dir_real}/.build_version"
if ! [ -f ${BUILD_VERSION_FILE} ]; then
echo "Not yet built"
exit 1
fi
BUILD_VERSION=`cat ${BUILD_VERSION_FILE} | cut -d '.' -f 1`
if [ ${PIP_VERSION_MAJOR} -gt 1 ]; then
if ! [ -x ${LIBPIPSO} ]; then
echo "Unable to find ${LIBPIPSO}"
exit 1
fi
CONFIG_VERSION=`${LIBPIPSO} --version | cut -d '.' -f 1`
else
PIP_CONFIG_HEADER=${PIP_DIR}/include/pip_config.h
if ! [ -f ${PIP_CONFIG_HEADER} ]; then
echo "Unable to find ${PIP_CONFIG_HEADER}"
exit 1
fi
CONFIG_VERSION=`grep PACKAGE_VERSION ${PIP_CONFIG_HEADER} 2> /dev/null | \
cut -d ' ' -f 3 | cut -d '"' -f 2 | cut -d '.' -f 1`
fi
if [ "${BUILD_VERSION}" != "${CONFIG_VERSION}" ]; then
echo "Version miss-match: build=${BUILD_VERSION} configure=${CONFIG_VERSION}"
exit 1
fi
path=.:${dir_real}/utils:${dir_real}/basics:${PIP_DIR}/bin
if [ x"$SUMMARY_FILE" = x ]; then
export PATH=${path}:$PATH
sum_file=$dir_real/.test-sum-$$.sh
else
sum_file=$SUMMARY_FILE
fi
unset PIP_MODE
check_command "pip_mode_check"
check_command "dlmopen_count"
check_command "ompnumthread"
cleanup()
{
echo;
echo "cleaning up ..."
${PIPS} -s KILL -v
rm -f $sum_file;
exit 1;
}
trap cleanup 2;
if [ x"$INCLUDE_FILE" != x ]; then
inc_fn=$INCLUDE_FILE': ';
case $inc_fn in
./*) inc_fn=`expr "$inc_fn" : '..\(.*\)'`;;
esac
fi
. $dir/exit_code.sh.inc
##export NTASKS=`$MCEXEC dlmopen_count -p`
##if [ $NTASKS -lt 8 ]; then
## echo "dlmopen_count:$NTASKS is not enough"
## exit 1;
##fi
##export OMP_NUM_THREADS=`$MCEXEC ompnumthread`;
##if [ $OMP_NUM_THREADS -lt 4 ]; then
## echo "ompnumthread:$OMP_NUM_THREADS is not enough"
## exit 1;
##fi
debug=`${LIBPIPSO} --debug`
if ! [ -f ${PIP_PRELOAD} ]; then
echo "Unable to find pip_preload.so";
exit 1;
fi
file_summary() {
rm -f $sum_file;
echo TEST_LOG_FILE=$TEST_LOG_FILE >> $sum_file;
echo TEST_LOG_XML=$TEST_LOG_XML >> $sum_file;
echo TEST_OUT_STDOUT=$TEST_OUT_STDOUT >> $sum_file;
echo TEST_OUT_STDERR=$TEST_OUT_STDERR >> $sum_file;
echo TEST_OUT_TIME=$TEST_OUT_TIME >> $sum_file;
echo n_PASS=$n_PASS >> $sum_file;
echo n_FAIL=$n_FAIL >> $sum_file;
echo n_XPASS=$n_XPASS >> $sum_file;
echo n_XFAIL=$n_XFAIL >> $sum_file;
echo n_UNRESOLVED=$n_UNRESOLVED >> $sum_file;
echo n_UNTESTED=$n_UNTESTED >> $sum_file;
echo n_UNSUPPORTED=$n_UNSUPPORTED >> $sum_file;
echo n_KILLED=$n_KILLED >> $sum_file;
echo TOTAL_TIME=$TOTAL_TIME >> $sum_file;
chmod +x $sum_file;
}
print_summary()
{
if [ x"$SUMMARY_FILE" = x ]; then
echo ""
echo "Total test: $(expr $n_PASS + $n_FAIL + $n_XPASS + $n_XFAIL \
+ $n_UNRESOLVED + $n_UNTESTED + $n_UNSUPPORTED + $n_KILLED)"
echo " success : $n_PASS"
echo " failure : $n_FAIL"
if [ $n_XPASS -gt 0 ]; then
echo " unexpected success : $n_XPASS";
fi
if [ $n_XFAIL -gt 0 ]; then
echo " expected failure : $n_XFAIL";
fi
if [ $n_UNRESOLVED -gt 0 ]; then
echo " unresolved : $n_UNRESOLVED";
fi
if [ $n_UNTESTED -gt 0 ]; then
echo " untested : $n_UNTESTED";
fi
if [ $n_UNSUPPORTED -gt 0 ]; then
echo " unsupported : $n_UNSUPPORTED";
fi
if [ $n_KILLED -gt 0 ]; then
echo " killed : $n_KILLED";
fi
else
file_summary;
fi
}
reset_summary()
{
TEST_TOP_DIR=$dir_real;
TEST_LOG_FILE=test.log;
: ${TEST_LOG_XML:=$TEST_TOP_DIR/test.log.xml};
## TEST_OUT_STDOUT=$TEST_TOP_DIR/test.out.stdout;
## TEST_OUT_STDERR=$TEST_TOP_DIR/test.out.err;
## TEST_OUT_TIME=$TEST_TOP_DIR/test.out.time;
TEST_OUT_STDOUT=test.out.stdout;
TEST_OUT_STDERR=test.out.err;
TEST_OUT_TIME=test.out.time;
n_PASS=0;
n_FAIL=0;
n_XPASS=0;
n_XFAIL=0;
n_UNRESOLVED=0;
n_UNTESTED=0;
n_UNSUPPORTED=0;
n_KILLED=0;
TOTAL_TIME=0;
file_summary;
}
pip_mode_name_P=process
pip_mode_name_L=$pip_mode_name_P:preload
pip_mode_name_G=$pip_mode_name_P:got
pip_mode_name_C=$pip_mode_name_P:pipclone
pip_mode_name_T=pthread
print_mode_list()
{
echo "List of PiP execution modes:"
echo " " $pip_mode_name_T "(T)";
echo " " $pip_mode_name_G "(G)";
echo " " $pip_mode_name_P "(P)";
echo " " $pip_mode_name_L "(L)";
echo " " $pip_mode_name_C "(C)";
exit 1;
}
# parse command line option
cmd=$0
case $# in
0) print_usage;;
*) run_test_L=''
run_test_G=''
run_test_C=''
run_test_T=''
while case $1 in
-*) true;;
*) false;;
esac
do
case $1 in *A*) run_test_L=L; run_test_G=G; run_test_C=C; run_test_T=T;; esac
case $1 in *P*) run_test_L=L; run_test_G=G; run_test_C=C;; esac
case $1 in *C*) run_test_C=C;; esac
case $1 in *L*) run_test_L=L;; esac
case $1 in *G*) run_test_G=G;; esac
case $1 in *T*) run_test_T=T;; esac
case $1 in *list*) print_mode_list;; esac
case $1 in *thread) run_test_T=T;; esac
case $1 in *process) run_test_L=L; run_test_G=G; run_test_C=C;; esac
case $1 in *$pip_mode_name_L) run_test_L=L;; esac
case $1 in *$pip_mode_name_G) run_test_G=G;; esac
case $1 in *$pip_mode_name_C) run_test_C=C;; esac
shift
done
if [ X"${run_test_L}${run_test_G}${run_test_C}${run_test_T}" = X ]; then
pip_mode_list="L G C T";
else
pip_mode_list="$run_test_L $run_test_G $run_test_C $run_test_T"
fi
;;
esac
case $# in
0) ;;
1) TEST_LIST=$1;;
*) echo >&2 "`basename $cmd`: unknown argument '$*'"
print_usage
exit 2;;
esac
if [ x"$TEST_LIST" == x ]; then
print_usage;
fi
if [ ! -e "$TEST_LIST" ]; then
print_usage;
fi
if [ -z "$pip_mode_list" ]; then
print_usage;
fi
if [ x"$SUMMARY_FILE" = x ]; then
reset_summary;
else
. $SUMMARY_FILE;
fi
[ -f ${TEST_LOG_FILE} ] && mv -f ${TEST_LOG_FILE} ${TEST_LOG_FILE}.bak
if [ -n "$MCEXEC" ]; then
pip_mode_list_all='T';
else
pip_mode_list_all='L G C T';
fi
if [ x"$SUMMARY_FILE" = x ]; then
paths=`echo ${PATH} | sed -e 's/:/ /g'`
npaths=4
echo -n "PATH: "
n=0
for path in $paths; do
if [ ${n} -lt $npaths ] ; then
echo -n "[${n}] ${path} "
n=$((n+1))
continue;
fi
echo "...";
break;
done
echo "--with-pip=$PIP_DIR"
echo "libpip.so -- DEBUG:" $debug
echo "LD_PRELOAD=$PIP_PRELOAD"
echo 'NTASKS: ' ${NTASKS}
echo 'NTHREADS:' ${OMP_NUM_THREADS}
if [ x"$MCEXEC" != x ]; then
echo 'MCEXEC: ' $MCEXEC
fi
fi
# check whether each $PIP_MODE is testable or not
run_test_L=''
run_test_G=''
run_test_C=''
run_test_T=''
if [ x"${SUMMARY_FILE}" == x ]; then
for pip_mode in $pip_mode_list; do
eval 'pip_mode_name=$pip_mode_name_'${pip_mode}
mode_actual=`${PIP_MODE_CMD} -${pip_mode} pip_mode_check 2>/dev/null`
case $pip_mode in
L)
case $mode_actual in
process:preload)
run_test_L='L';
echo "testing ${pip_mode} - ${pip_mode_name}";;
*) echo >&2 "WARNING: $pip_mode_name is not testable";;
esac;;
G)
case $mode_actual in
process:got)
run_test_G='G';
echo "testing ${pip_mode} - ${pip_mode_name}";;
*) echo >&2 "WARNING: $pip_mode_name is not testable";;
esac;;
C)
case $mode_actual in
process:pipclone)
run_test_C='C';
echo "testing ${pip_mode} - ${pip_mode_name}";;
*) echo >&2 "WARNING: $pip_mode_name is not testable";;
esac;;
T)
case $mode_actual in
pthread)
run_test_T='T';
echo "testing ${pip_mode} - ${pip_mode_name}";;
*) echo >&2 "WARNING: $pip_mode_name ($pip_mode) is not testable";;
esac;;
esac
done
else
for pip_mode in $pip_mode_list; do
eval 'pip_mode_name=$pip_mode_name_'${pip_mode}
mode_actual=`${PIP_MODE_CMD} -${pip_mode} pip_mode_check 2>/dev/null`
case $pip_mode in
L)
case $mode_actual in
process:preload) run_test_L='L';;
*) :;;
esac;;
G)
case $mode_actual in
process:got) run_test_G='G';;
*) :;;
esac;;
C)
case $mode_actual in
process:pipclone) run_test_C='C';;
*) :;;
esac;;
T)
case $mode_actual in
pthread) run_test_T='T';;
*) :;;
esac;;
esac
done
fi
pip_mode_list="$run_test_L $run_test_G $run_test_C $run_test_T"
pml=`echo ${pip_mode_list} | tr -d ' '`
if [ -z "$pml" ]; then
echo "No PIP_MODE to test"
exit 1
fi
if [ x"$SUMMARY_FILE" = x ]; then
echo;
fi
if [ x"$run_test_L" = x"L" ]; then
options="-L $options";
fi
if [ x"$run_test_G" = x"G" ]; then
options="-G $options";
fi
if [ x"$run_test_C" = x"C" ]; then
options="-C $options";
fi
if [ x"$run_test_T" = x"T" ]; then
options="-T $options";
fi
LOG_BEG="=== ============================================================ ===="
LOG_SEP="--- ------------------------------------------------------------ ----"
if [ x"$SUMMARY_FILE" = x ]; then
echo "<testsuite>" >$TEST_LOG_XML
fi
cd `dirname $TEST_LIST`
while read line; do
set_term_width;
set x $line
shift
case $# in 0) continue;; esac
case $1 in '%include')
shift;
ifile=$1
if [ -f $ifile ]; then
file_summary;
echo ">>> $ifile"
SUMMARY_FILE=$sum_file \
INCLUDE_FILE=$ifile \
$myself $options $ifile;
echo "<<< $ifile"
. $sum_file;
else
echo >&2 "### inlcude file ($ifile) not found ###";
fi
continue;;
esac
case $1 in '#'*) continue;; esac
cmd="$@";
CMD=$inc_fn$cmd;
if [ ${#CMD} -ge $width ]; then
dash="... "
w=$((${width}-${#dash}))
short="`printf "%-${w}.${w}s" "${inc_fn}${cmd}" "${dash}"`"
else
short=$CMD;
fi
for pip_mode in $pip_mode_list
do
eval 'pip_mode_name=$pip_mode_name_'${pip_mode}
printf "%-${width}.${width}s ${pip_mode} --" "$short"
(
echo "$LOG_BEG"
echo "--- $CMD PIP_MODE=${pip_mode_name}"
echo "$LOG_SEP"
date +'@@_ start at %s - %Y-%m-%d %H:%M:%S'
) >>$TEST_LOG_FILE
rm -f $TEST_OUT_STDOUT $TEST_OUT_STDERR $TEST_OUT_TIME
SECONDS=0
${PIP_MODE_CMD} -${pip_mode} ${MCEXEC} ${cmd} \
> ${TEST_OUT_STDOUT} 2> ${TEST_OUT_STDERR} < /dev/null;
test_exit_status=$?
t=$SECONDS
msg=
case $test_exit_status in
$EXIT_PASS) status=PASS;;
$EXIT_FAIL) status=FAIL;;
$EXIT_XPASS) status=XPASS;;
$EXIT_XFAIL) status=XFAIL;;
$EXIT_UNRESOLVED) status=UNRESOLVED;;
$EXIT_UNTESTED) status=UNTESTED;;
$EXIT_UNSUPPORTED) status=UNSUPPORTED;;
$EXIT_KILLED) status=KILLED;;
*) status=UNRESOLVED;
msg="exit status $test_exit_status";;
esac
eval "((n_$status=n_$status + 1))"
# floating point expression
TOTAL_TIME=$(awk 'BEGIN {print '"$TOTAL_TIMME"'+'"$t"'; exit}')
(
echo ' <testcase classname="'PIP'"' \
'name="'"${CMD} - ${pip_mode_name}"'"' \
'time="'"${t}"'">'
case $status in
PASS|XPASS)
;;
FAIL)
echo ' <failure type="'$status'"/>';;
XFAIL|UNTESTED|UNSUPPORTED)
echo ' <skipped/>';;
UNRESOLVED|KILLED)
printf ' <error type="'$status'"';
if [ -n "$msg" ]; then
printf ' message="'"$msg"'"'
fi
echo '/>'
;;
esac
if [ -s $TEST_OUT_STDOUT ]; then
printf ' <system-out><![CDATA['
iconv -fISO-8859-1 -tUTF-8 <$TEST_OUT_STDOUT
echo ']]></system-out>'
fi
if [ -s $TEST_OUT_STDERR ]; then
printf ' <system-err><![CDATA['
iconv -fISO-8859-1 -tUTF-8 <$TEST_OUT_STDERR
echo ']]></system-err>'
fi
echo ' </testcase>'
) >>$TEST_LOG_XML
: ${msg:=$status}
(
if [ -s $TEST_OUT_STDOUT ]; then
echo "@@:stdout"
cat $TEST_OUT_STDOUT
fi
if [ -s $TEST_OUT_STDERR ]; then
echo "@@:stderr"
cat $TEST_OUT_STDERR
fi
if [ -s $TEST_OUT_TIME ]; then
echo "@@:time"
cat $TEST_OUT_TIME
fi
date +'@@~ end at %s - %Y-%m-%d %H:%M:%S'
echo "$LOG_SEP"
printf "@:= %s %s\n" $CMD "$msg"
) >>$TEST_LOG_FILE
case $status in
FAIL) msg="$msg :-O";;
XPASS) msg="$msg :-D";;
XFAIL) msg="$msg :-?";;
UNRESOLVED) msg="$msg :-O";;
UNTESTED) msg="$msg :-|";;
UNSUPPORTED) msg="$msg";;
KILLED) msg="$msg ^C?";;
esac
echo " $msg"
# stopped by Control-C or something like that
[ $test_exit_status -eq $EXIT_KILLED ] && break 2
done
done < `basename $TEST_LIST`
if [ x"$SUMMARY_FILE" = x ]; then
echo "</testsuite>" >>$TEST_LOG_XML
else
file_summary;
fi
(
echo $LOG_BEG
print_summary
) >>$TEST_LOG_FILE
print_summary
if [ x"$SUMMARY_FILE" = x ]; then
rm -f $sum_file
fi
case $n_KILLED in 0) :;; *) exit $EXIT_KILLED;; esac
case $n_PASS in 0) exit $EXIT_FAIL;; esac
if [ $n_FAIL -eq 0 -a $n_UNRESOLVED -eq 0 -a $n_PASS -gt 0 ]; then
exit $EXIT_PASS
fi
if [ x"${SUMMARY_FILE}" == x ]; then
if [ x"${PIP_TEST_THRESHOLD}" != x ]; then
nerr=`expr $n_FAIL + $n_UNRESOLVED`
if [ $nerr -lt ${PIP_TEST_THRESHOLD} ]; then
echo "Some test fails ($nerr) but less than PIP_TEST_THRESHOLD ($PIP_TEST_THRESHOLD)"
exit $EXIT_PASS
fi
fi
fi
exit $EXIT_FAIL