-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathremote_tests.sh
executable file
·687 lines (578 loc) · 18.8 KB
/
remote_tests.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
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
#!/bin/bash
set -m
# This allows for the debug, quiet and info flags
# -q (QUIET) prevents showing the progress indicator - this is automatically selected
# if the output is in JSON (done by passing .json to the test runner)
# -d (DEBUG_MODE) drops the user into the remote shell after the tests complete - this
# is not allowed if the output is in JSON (done by passing .json to the test runner)
# -i (SHOW_INFO) displays info about the remote server including PHP/PHPUnit
# version and info about missing PHP extensions or database command line tools - this
# mode will not run any tests
# -a (ADD_KEY) this adds the current user's SSH public key to all of the remote accounts
# listed - no tests will be run or info shown with this flag
# -n 0-9 (CONCURRENT) this number of tests will be run conccurently instead of sequentially
# -p (PARALLEL_DB) if this flag is present, all tests for each type of database will be
# run sequentially on all specified hosts, but all database types will be run at the
# same time and all non-database tests will be run in parallel with all of the database tests
QUIET=0
DEBUG_MODE=0
SHOW_INFO=0
ADD_KEY=0
SUB_CALL=0
JSON=0
TEXT=0
CONCURRENT=1
NO_MYSQL=0
NO_POSTGRESQL=0
NO_MSSQL=0
NO_ORACLE=0
NO_DB2=0
PARALLEL_DB=0
while [[ ${1:0:1} = - ]]; do
if [[ $1 = -q ]]; then
QUIET=1
shift
elif [[ $1 = -d ]]; then
DEBUG_MODE=1
shift
elif [[ $1 = -i ]]; then
SHOW_INFO=1
shift
elif [[ $1 = -a ]]; then
ADD_KEY=1
shift
elif [[ $1 = -s ]]; then
SUB_CALL=1
shift
elif [[ $1 = -n ]]; then
CONCURRENT="$2"
shift 2
elif [[ $1 = -p ]]; then
PARALLEL_DB=1
JSON=1
QUIET=1
shift
fi
done
# JSON output always triggers quiet mode since JSON is intended for programatic use
for ARG in "$@"; do
if [[ $ARG = .json ]]; then
JSON=1
QUIET=1
elif [[ $ARG = .text ]]; then
TEXT=1
QUIET=1
elif [[ $ART = '!mysql*' ]]; then
NO_MYSQL=1
PARALLEL_DB=0
elif [[ $ART = '!postgresql*' ]]; then
NO_POSTGRESQL=1
PARALLEL_DB=0
elif [[ $ART = '!mssql*' ]]; then
NO_MSSQL=1
PARALLEL_DB=0
elif [[ $ART = '!oracle*' ]]; then
NO_ORACLE=1
PARALLEL_DB=0
elif [[ $ART = '!db2*' ]]; then
NO_DB2=1
PARALLEL_DB=0
fi
done
# The C shell requires multi-line text to have a \ before each newline, so we have
# to detect it and change out parameters accordingly - this is true even though we
# use bash to run the tests, because bash is invoked by the default user's shell
IS_CSH=""
# Makes a queue of commands to run remotely
#
# All parameters passed to this function are added to a list of commands to be
# run remotely over SSH. Obviously any redirection commands will need to be escaped
# to prevent them being applied to this command.
queue_command()
{
SEPARATOR=' ; '
if [[ $1 = ";" || $1 = "&&" || $1 = "||" ]]; then
SEPARATOR=" $1 "
shift
fi
if [[ $COMMAND_QUEUE ]]; then
COMMAND_QUEUE="${COMMAND_QUEUE}${SEPARATOR}"
fi
# This detects all parameters with one or more character plus blank parameters
while [[ -n $1 || ${1-XXX} != XXX ]]; do
ARG="$1"
shift
# quotes the value in a foo=bar or --foo=bar parameter
if [[ $ARG =~ ^[a-zA-Z0-9_-]+= ]]; then
VALUE=$(printf "%s" "$ARG" | sed 's/^[a-zA-Z0-9_]*=//')
VALUE=\"$(printf "%s" "$VALUE" | sed 's/"/"\\""/g')\"
ARG=$(printf "%s" "$ARG" | sed "s/^\([a-zA-Z0-9_]*\)=.*$/\1=$VALUE/")
# lets params that are all non-alpha through, such as |, &&, >, etc
elif [[ $ARG =~ ^[^' 'a-zA-Z]+$ ]]; then
ARG="$ARG"
# quotes any param that would be interpreted as multiple words or blank parameters
elif [[ $ARG =~ [^a-zA-Z0-9_.\/=:@~-] || ! $ARG ]]; then
ARG=\"$(printf "%s" "$ARG" | sed 's/"/"\\""/g' | sed 's/*/"*"/g')\"
if [[ $IS_CSH != "" ]]; then
ARG=${ARG/!/\\!}
ARG=$(printf "%s\n" "$ARG" | awk 'BEGIN { RS="" } {gsub("\n", "\\\\&");print}')
fi
fi
COMMAND_QUEUE="$COMMAND_QUEUE $ARG"
done
}
# Executes the remote command queue on the user@host specified as the first param
#
# Any string passed as the second param will be used as the variable name to store the output
# of the command in, instead of it being done interactively
exec_commands()
{
PORT=""
if [[ $1 =~ : ]]; then
PORT="-p ${1##*:}"
SSH_HOST=${1%%:*}
else
SSH_HOST="$1"
fi
COMMAND_QUEUE=$(printf "%s" "$COMMAND_QUEUE" | sed "s/'/'\\\\''/g")
if [[ $2 ]]; then
OUTPUT=$(ssh -A -q $PORT $SSH_HOST "bash -l -c '$COMMAND_QUEUE'")
eval "$2='$OUTPUT'"
else
ssh -A -tq $PORT $SSH_HOST "bash -l -c '$COMMAND_QUEUE'"
fi
COMMAND_QUEUE=""
}
# This function shows a color coded status of required and optional remote software
# @param $1 The name of the software to display
# @param $2 The status of the remote software - 1 = installed, -1 = required but missing, 0 = optional but missing
# @param $3 Optional: the text to display in the colored output - overrides the default yes or no
show_status()
{
WIDTH=${4-14}
echo -n " "
echo "$1" | awk "{ printf "\""%-${WIDTH}s"\"", \$0 }"
if [[ $2 = 1 ]]; then
TEXT=yes
if [[ $3 != "" ]]; then
TEXT="$3"
fi
echo -e "\033[1;37;43m$TEXT\033[0m"
elif [[ $2 = -1 ]]; then
echo -e "\033[1;37;41mno\033[0m"
else
TEXT=no
if [[ $3 != "" ]]; then
TEXT="$TEXT $3"
fi
echo -e "\033[1;37;40m$TEXT\033[0m"
fi
}
# A shortcut to show_status() that defaults to the program being required
# @param $1 The name of the software to display
# @param $2 If the software was found - 0 means no, anything else means yes
# @param $3 Optional: text to display in the colored output
show_required()
{
STATUS=-1
if (( $2 )); then
STATUS=1
fi
show_status "$1" $STATUS $3
}
# A shortcut to show info if either the command line interface or PHP extension for
# a database is missing. If both are present, or missing, nothing will be shown.
# @param $1 The database type
# @param $2 If a PHP extension for the database is installed - 0 for no, anything else for yes
# @param $3 If the cli for the database is installed - 0 for no, anything else for yes
show_db()
{
STATUS=0
TEXT=""
if (( $2 && $3 )); then
return
elif (( ! $2 && $3 )); then
TEXT=ext
elif (( $2 && ! $3 )); then
TEXT=cli
else
return
fi
show_status "$1" $STATUS $TEXT
}
# Shows a comma-separated list of PHP extensions that are required or optional for Flourish
# and that are not installed. Optional ones are shown in grey text, required are shown with
# a red background and white text
# @param $1 The extension name
# @param $2 If the extension was found - 0 implies no, anything else implies yes
# @param $3 If the extension is required
show_ext()
{
STATUS=0
if (( $2 )); then
return
elif (( $3 )); then
STATUS=-1
fi
if (( $EXT_NUM )); then
echo -n ' '
else
echo -n ' missing exts' | awk '{ printf "%-18s", $0 }'
fi
if [[ $STATUS = -1 ]]; then
echo -e -n "\033[0;37;41m$1\033[0m"
else
echo -e -n "\033[1;37;40m$1\033[0m"
fi
((EXT_NUM++))
}
# Checks for a grep regex pattern inside of a larger block of text - prints the number of
# lines that contain the search terms
# @param $1 The haystack
# @param $2 The grep regex to search for
present()
{
printf "%s" "$1" | grep "$2" | wc -l
}
# Takes a large block of text, splits it on separator and assigns the results to multiple
# variables
# @param $1 The text to split
# @param $2 The separator to split on
# @param $3 The name of the variable to store the first part in
# @param $4,... The name of the variable to store the second part in
assign()
{
VAR="$1"
NUM=3
while [[ $VAR ]]; do
eval "${!NUM}=\${VAR%%?$2*}"
OLD_VAR="$VAR"
eval "VAR=\${VAR#*$2?}"
if [[ $VAR = $OLD_VAR ]]; then
VAR=""
fi
((NUM++))
done
}
ACTIVITY_PID=""
# Starts an activity indicator as a background process that prints a . every 1/3 seconds
# @param $1 Text to display before the .s start
# @param $2,... More text to display
start_activity()
{
if (( $QUIET )); then
return
fi
while [[ $2 ]]; do
echo "$1"
shift
done
echo -n "$1"
(
while [[ 1 ]]; do
echo -n .
sleep 0.3
done
) &
ACTIVITY_PID=$!
}
# Stops the activity indicator
stop_activity()
{
if (( $QUIET )); then
return
fi
disown $ACTIVITY_PID
kill $ACTIVITY_PID
echo " ]"
}
TOTAL_HOSTS=0
RHOSTS=""
while [[ $1 =~ .@ ]]; do
RHOSTS="$RHOSTS $1"
shift
((TOTAL_HOSTS++))
done
if (( ! $TOTAL_HOSTS )); then
RHOSTS="will@vm-arch.wbond.net will@vm-centos.wbond.net will@vm-debian.wbond.net will@vm-fedora.wbond.net will@vm-freebsd.wbond.net will@vm-netbsd.wbond.net will@vm-openbsd.wbond.net will@vm-opensolaris.wbond.net will@vm-opensuse.wbond.net will@osx.wbond.net will@vm-server2008.wbond.net will@vm-ubuntu.wbond.net will@vm-xp.wbond.net"
TOTAL_HOSTS=12
fi
# If we are adding keys, grab the current user's SSH public key
PUBLIC_KEY=""
if (( $ADD_KEY )); then
if [[ -e ~/.ssh/id_rsa.pub ]]; then
PUBLIC_KEY=$(cat ~/.ssh/id_rsa.pub)
elif [[ -e ~/.ssh/id_dsa.pub ]]; then
PUBLIC_KEY=$(cat ~/.ssh/id_dsa.pub)
else
echo "ERROR - No public key found in ~/.ssh/id_rsa.pub or ~/.ssh/id_dsa.pub"
exit
fi
fi
if (( ! $ADD_KEY && ! $SHOW_INFO && ! $SUB_CALL )); then
MASTER_START=$(date +%s)
start_activity "[ Creating tarball"
tar --exclude='*/output/*' --exclude='*/.svn/*' --exclude='*/cachegrind.out.*' -czpf /tmp/flourish_local.tar.gz -C ../ classes tests
stop_activity
fi
if (( $PARALLEL_DB )); then
$0 -s $RHOSTS "$@" .text ':mysql*' '!postgresql*' '!mssql*' '!oracle*' '!db2*' > output/parallel.mysql.text &
$0 -s $RHOSTS "$@" .text ':oracle*' '!mysql*' '!postgresql*' '!mssql*' '!db2*' > output/parallel.oracle.text &
$0 -s $RHOSTS "$@" .text ':postgresql*' '!mysql*' '!mssql*' '!oracle*' '!db2*' > output/parallel.postgresql.text &
$0 -s $RHOSTS "$@" .text ':mssql*' '!mysql*' '!postgresql*' '!oracle*' '!db2*' > output/parallel.mssql.text &
$0 -s $RHOSTS "$@" .text '!mssql*' '!mysql*' '!postgresql*' '!oracle*' ':db2*' > output/parallel.db2.text &
wait
$0 -s -n $CONCURRENT $RHOSTS "$@" .text '!mysql*' '!postgresql*' '!mssql*' '!oracle*' '!db2*' > output/parallel.non-db.text &
wait
echo "{"
I=0
for RHOST in $RHOSTS; do
PASSED=0
FAILED=0
SKIPPED=0
PHP_ERRORS=0
for FILE in output/parallel.mysql.text output/parallel.postgresql.text output/parallel.mssql.text output/parallel.oracle.text output/parallel.db2.text output/parallel.non-db.text; do
#for FILE in output/parallel.mysql.text; do
PASSED=$(( $PASSED + $(grep "$RHOST>passed=" "$FILE" | sed "s/$RHOST>passed=//") ))
FAILED=$(( $FAILED + $(grep "$RHOST>failed=" "$FILE" | sed "s/$RHOST>failed=//") ))
SKIPPED=$(( $SKIPPED + $(grep "$RHOST>skipped=" "$FILE" | sed "s/$RHOST>skipped=//") ))
PHP_ERRORS=$(( $PHP_ERRORS + $(grep "$RHOST>php_errors=" "$FILE" | sed "s/$RHOST>php_errors=//") ))
done
if (( $I != 0 )); then
echo ','
fi
echo -n ' "'"$RHOST"'": {"passed": '"$PASSED"', "failed": '"$FAILED"', "skipped": '"$SKIPPED"', "php_errors": '"$PHP_ERRORS"'}'
((I++))
done
echo
echo "}"
rm output/parallel.mysql.text
rm output/parallel.postgresql.text
rm output/parallel.mssql.text
rm output/parallel.oracle.text
rm output/parallel.db2.text
rm output/parallel.non-db.text
rm /tmp/flourish_local.tar.gz
exit
fi
if (( $JSON && $TOTAL_HOSTS > 1 )); then
printf "{"
fi
RHOST_NUM=0
for RHOST in $RHOSTS; do
if (( $SHOW_INFO )); then
queue_command uname -a
queue_command echo '----'
queue_command uname -v
queue_command echo '----'
queue_command which php phpunit sqsh mysql psql sqlplus db2batch convert \2\> /dev/null
queue_command echo '----'
queue_command php -m
queue_command echo '----'
queue_command php --version \| head -n 1 \| sed 's/^PHP \([0-9.]*\).*$/\1/'
queue_command echo '----'
queue_command phpunit --version \| sed 's/^[^0-9]*\([0-9.]*\) [^0-9]*/\1/g' \| head -n 1
exec_commands $RHOST OUTPUT
assign "$OUTPUT" ---- UNAME UNAME_V PROGRAMS PHP_MODULES PHP_VERSION PHPUNIT_VERSION
UNAME=${UNAME/ $UNAME_V/}
if (( $RHOST_NUM )); then
echo
fi
echo -e "\033[1;37;44m$RHOST\033[0m:"
show_required php $(present "$PROGRAMS" '/php\>') $PHP_VERSION
show_required phpunit $(present "$PROGRAMS" /phpunit) $PHPUNIT_VERSION
EXT_NUM=0
show_ext bcmath $(present "$PHP_MODULES" bcmath) 0
show_ext ctype $(present "$PHP_MODULES" ctype) 1
show_ext dom $(present "$PHP_MODULES" dom) 1
show_ext gd $(present "$PHP_MODULES" gd) 0
show_ext iconv $(present "$PHP_MODULES" iconv) 1
show_ext ibm_db2 $(present "$PHP_MODULES" ibm_db2) 0
show_ext json $(present "$PHP_MODULES" json) 0
show_ext mbstring $(present "$PHP_MODULES" mbstring) 0
show_ext mcrypt $(present "$PHP_MODULES" mcrypt) 0
show_ext openssl $(present "$PHP_MODULES" openssl) 0
show_ext mssql $(present "$PHP_MODULES" mssql) 0
show_ext mysql $(present "$PHP_MODULES" 'mysql\>') 0
show_ext mysqli $(present "$PHP_MODULES" mysqli) 0
show_ext oci8 $(present "$PHP_MODULES" oci8) 0
show_ext pdo_dblib $(present "$PHP_MODULES" 'pdo_dblib\|pdo_mssql') 0
show_ext pdo_ibm $(present "$PHP_MODULES" pdo_ibm) 0
show_ext pdo_mysql $(present "$PHP_MODULES" pdo_mysql) 0
show_ext pdo_oci $(present "$PHP_MODULES" PDO_OCI) 0
show_ext pdo_pgsql $(present "$PHP_MODULES" pdo_pgsql) 0
show_ext pdo_sqlite $(present "$PHP_MODULES" pdo_sqlite) 0
show_ext pgsql $(present "$PHP_MODULES" pgsql) 0
show_ext sqlite $(present "$PHP_MODULES" sqlite) 0
show_ext sqlsrv $(present "$PHP_MODULES" sqlsrv) 0
if (( $EXT_NUM )); then
echo
fi
show_db db2 $(present "$PHP_MODULES" ibm) $(present "$PROGRAMS" /db2batch)
show_db mysql $(present "$PHP_MODULES" mysql) $(present "$PROGRAMS" /mysql)
show_db postgresql $(present "$PHP_MODULES" pgsql) $(present "$PROGRAMS" /psql)
show_db oracle $(present "$PHP_MODULES" oci) $(present "$PROGRAMS" /sqlplus)
show_db mssql $(present "$PHP_MODULES" 'mssql\|dblib\|sqlsrv') $(present "$PROGRAMS" /sqsh)
show_status ImageMagick $(present "$PROGRAMS" /convert)
continue
fi
if (( $ADD_KEY )); then
queue_command \( \[ ! -e \~/.ssh \] \&\& ssh-keygen -q -f \~/.ssh/id_rsa -N '' \)
queue_command echo "$PUBLIC_KEY" \>\> \~/.ssh/authorized_keys
exec_commands $RHOST
continue
fi
if (( $CONCURRENT == 1 )); then
TOKEN=1
start_activity "[ Pushing to $RHOST"
SSH_PORT=""
SCP_PORT=""
PORT=""
if [[ $RHOST =~ : ]]; then
PORT=${RHOST##*:}
SSH_PORT="-p $PORT"
SCP_PORT="-P $PORT"
SSH_HOST=${RHOST%%:*}
else
SSH_HOST="$RHOST"
fi
REMOTE_INFO=$(ssh -A -q $SSH_PORT $SSH_HOST 'echo $SHELL && which mysql psql sqlplus sqsh db2batch' 2> /dev/null)
REMOTE_SHELL=$(echo "$REMOTE_INFO" | awk 'BEGIN { RS=""; FS="\n" } {print $1}')
if [[ $REMOTE_SHELL =~ csh ]]; then
IS_CSH=1
fi
HAS_MYSQL=$(present "$REMOTE_INFO" /mysql)
HAS_PSQL=$(present "$REMOTE_INFO" /psql)
HAS_SQLPLUS=$(present "$REMOTE_INFO" /sqlplus)
HAS_SQSH=$(present "$REMOTE_INFO" /sqsh)
HAS_DB2BATCH=$(present "$REMOTE_INFO" /db2batch)
scp $SCP_PORT -q /tmp/flourish_local.tar.gz $SSH_HOST:/tmp/flourish_$TOKEN.tar.gz
queue_command cd /tmp/
queue_command rm -Rf flourish_$TOKEN
queue_command mkdir flourish_$TOKEN
queue_command mv flourish_$TOKEN.tar.gz flourish_$TOKEN/
queue_command cd flourish_$TOKEN
queue_command gunzip flourish_$TOKEN.tar.gz
queue_command tar xf flourish_$TOKEN.tar \2\> /dev/null
if (( $SUB_CALL || $JSON || $TEXT )); then
exec_commands $RHOST OUTPUT
else
exec_commands $RHOST
fi
stop_activity
CONFIG_EXCLUSIONS=""
queue_command cd /tmp/flourish_$TOKEN/tests/
if (( ! $NO_MYSQL && $HAS_MYSQL )); then
queue_command ./reset_databases.sh -t mysql flourish_$TOKEN
fi
if (( ! $NO_POSTGRESQL && $HAS_PSQL )); then
queue_command ./reset_databases.sh -t pgsql flourish_$TOKEN
fi
if (( ! $NO_ORACLE && $HAS_SQLPLUS )); then
queue_command ./reset_databases.sh -t oracle flourish_$TOKEN
fi
if (( ! $NO_MSSQL && $HAS_SQSH )); then
queue_command ./reset_databases.sh -t mssql flourish_$TOKEN
fi
if (( ! $NO_DB2 && $HAS_DB2BATCH )); then
queue_command ./reset_databases.sh -t db2 flourish_$TOKEN
fi
DEBUG_FLAG="";
if (( $DEBUG_MODE )); then
DEBUG_FLAG="@d"
fi
queue_command export NLS_LANG="AMERICAN_AMERICA.AL32UTF8"
queue_command export DB2CODEPAGE="1208"
queue_command php tests.php \#flourish_$TOKEN $CONFIG_EXCLUSIONS "$@" $DEBUG_FLAG $FORMAT
if (( $DEBUG_MODE )); then
queue_command gzip -S .${SSH_HOST##*@}.gz /tmp/flourish_$TOKEN/tests/cachegrind.out.*
queue_command echo "[ Debug shell - database is flourish_$TOKEN - type 'exit' to finish ]"
queue_command bash
fi
if (( $SUB_CALL || $JSON || $TEXT )); then
exec_commands $RHOST OUTPUT
if (( $JSON && $TOTAL_HOSTS > 1 )); then
SEP=""
if (( $RHOST_NUM < $TOTAL_HOSTS - 1 )); then
SEP=","
fi
printf "\n "\""%s"\"": %s$SEP" ${RHOST%%:*} "$OUTPUT"
else
echo "$OUTPUT"
fi
else
exec_commands $RHOST
fi
start_activity "[ Cleaning up"
if (( $DEBUG_MODE )); then
scp $SCP_PORT -q $SSH_HOST:/tmp/flourish_$TOKEN/tests/cachegrind.out.* ./
fi
queue_command rm -Rf /tmp/flourish_$TOKEN
if (( $SUB_CALL || $JSON || $TEXT )); then
exec_commands $RHOST OUTPUT
else
exec_commands $RHOST
fi
stop_activity
else
while (( $(jobs -pr | wc -l) >= $CONCURRENT )); do
sleep 1
done
# When we run tests on multiple machines, we run them in the background recursively
if (( $JSON )); then
SEP=""
if (( $RHOST_NUM < $TOTAL_HOSTS - 1 )); then
SEP=","
fi
printf "\n "\""%s"\"": %s$SEP" ${RHOST%%:*} "$($0 -s $RHOST "$@")" &
elif (( $TEXT )); then
(
OUT=$($0 -s $RHOST "$@")
printf "%s" "$OUT" | awk -F "\n" '{print '\""$RHOST>"\"' $1}'
) &
else
$0 -s $RHOST "$@" &
fi
fi
((RHOST_NUM++))
done
if (( ! $ADD_KEY && ! $SHOW_INFO && ! $SUB_CALL && $TOTAL_HOSTS == 1 )); then
rm /tmp/flourish_local.tar.gz
fi
# Here we take the output of tests from multiple servers and make one big JSON object
if (( ! $SHOW_INFO && ! $ADD_KEY && $TOTAL_HOSTS > 1 )); then
wait
if (( ! $SUB_CALL )); then
rm /tmp/flourish_local.tar.gz
fi
if (( $JSON )); then
printf "\n}\n"
fi
fi
if (( ! $ADD_KEY && ! $SHOW_INFO && ! $SUB_CALL && $TOTAL_HOSTS > 1 && ! $QUIET )); then
MASTER_END=$(date +%s)
RUNTIME=$((MASTER_END - MASTER_START))
RUNTIME_HOURS=$((RUNTIME/3600%60))
RUNTIME_MINUTES=$((RUNTIME/60%60))
RUNTIME_SECONDS=$((RUNTIME%60))
echo -n "["
if (( $RUNTIME_HOURS )); then
echo -n " $RUNTIME_HOURS hour"
if (( $RUNTIME_HOURS != 1 )); then
echo -n "s"
fi
fi
if (( $RUNTIME_MINUTES )); then
echo -n " $RUNTIME_MINUTES minute"
if (( $RUNTIME_MINUTES != 1 )); then
echo -n "s"
fi
fi
if (( $RUNTIME_SECONDS )); then
echo -n " $RUNTIME_SECONDS second"
if (( $RUNTIME_SECONDS != 1 )); then
echo -n "s"
fi
fi
echo " total ]"
fi