File: common

package info (click to toggle)
pcp 7.1.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 252,748 kB
  • sloc: ansic: 1,483,656; sh: 182,366; xml: 160,462; cpp: 83,813; python: 24,980; perl: 18,327; yacc: 6,877; lex: 2,864; makefile: 2,738; awk: 165; fortran: 60; java: 52
file content (979 lines) | stat: -rwxr-xr-x 21,867 bytes parent folder | download
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
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
#!/bin/sh
#
# common procedures for PCP QA scripts
#
# Copyright (c) 1997-2002 Silicon Graphics, Inc.  All Rights Reserved.
#

# may be needed in common.* scripts
#
here=`pwd`

# for _wait_for_pmlogger() and _change_config() and _service()
. ./common.check 

# per product QA script customization
#
. ./common.setup
[ -z "$DEFAULT_HOST" ] && DEFAULT_HOST=`hostname`

_setenvironment()
{
    MSGVERB="text:action"
    export MSGVERB
    export PCP_BINADM_DIR
    PCP_DERIVED_CONFIG=""; export PCP_DERIVED_CONFIG
}

_log_fyi()
{
    echo "FYI ... here are the PMCD logs"
    for __log
    do
	if [ ! -f $__log ]
	then
	    # try in the other place
	    #
	    case $__log
	    in
		$PCP_LOG_DIR/pmcd/*)
		    __try=`echo $__log | sed -e "s;/pmcd/;/;"`
		    ;;
		*)
		    __try=`echo $__log | sed -e "s;$PCP_LOG_DIR/;$PCP_LOG_DIR/pmcd/;"`
		    ;;
	    esac
	    [ -f $__try ] && __log=$__try
	fi
	if [ -f $__log ]
	then
	    echo ":::::::::  start $__log  ::::::::"
	    cat $__log
	    echo "::::::::::  end $__log  :::::::::"
	    
	    [ $__log != $PCP_LOG_DIR/pmcd/pmcd.log ] && $sudo rm -f $__log
	else
	    echo "$__log: not found"
	fi
    done
}

_havesudo()
{
    if [ -z "$PCP_DIR" ]
    then
	__setuid=`$sudo id | sed -e 's/(.*//' -e 's/.*=//'`
	if [ "$__setuid" != 0 ]
	then
	    echo "\"sudo\" is not an executable setuid root. This is fatal."
	    echo "As root, you need to setup your sudoers file for pcpqa."
	    exit 1
	fi
    fi
}

_haveagents()
{
    __restart=false
    __here=`pwd`

    # PMDAs than need to be here for QA
    #
    __common_pmdas="sample sampledso simple"
    if [ -d $PCP_PMDAS_DIR/cisco ]
    then
	# cisco PMDA requires that you can reach a router
	#
	if which ping >/dev/null 2>&1
	then
	    #  Note: PCP_QA_CISCOROUTER needs to be defined in common.rc
	    if ping -c 1 $PCP_QA_CISCOROUTER >/dev/null 2>&1
	    then
		__common_pmdas="$__common_pmdas cisco"
	    fi
	fi
    fi

    for __agent in $__common_pmdas
    do
	__probe=$__agent
	__agentlog=$PCP_LOG_DIR/pmcd/$__agent.log

	# make this empty to stop any attempt to reinstall
	#
	__agentdir=$PCP_PMDAS_DIR/$__agent

	case $__agent
	in
	    cisco)
		__probe=cisco.bytes_in
		;;
	    sample)
		__probe=sample.milliseconds
		;;
	    sampledso)
		__probe=sampledso.milliseconds
		__agentdir=$PCP_PMDAS_DIR/sample
		;;
	    simple)
		__probe=simple.numfetch
		;;
	esac
	__reinstall=false
	while true
	do
	    if pminfo -h $DEFAULT_HOST -f $__probe 2>&1 \
	       | tail -1 \
	       | grep -E "^[ 	]*((value)|(inst))[ 	]" >/dev/null
	    then
		break
	    else
		echo "PMDA probe: pminfo -h $DEFAULT_HOST -f $__probe"
		echo "PMDA $__agent is not responding"
		if $__restart
		then
		    :
		else
		    _log_fyi $PCP_LOG_DIR/pmcd/pmcd.log $__agentlog
		    echo "Restarting PMCD ..."
		    _service pmcd restart
		    _wait_for_pmcd
		    __restart=true
		fi
		if $__reinstall
		then
		    echo "Cannot make PMDA $__agent work, ... giving up!"
		    exit 1
		else
		    if [ -z "$__agentdir" ]
		    then
			echo "Skip PMDA re-install"
			break
		    elif [ -d "$__agentdir" ]
		    then
			echo "Trying to re-install PMDA $__agent from $__agentdir ..."
			cd $__agentdir
			unset ROOT TOOLROOT MAKEFLAGS
			$sudo ./Remove </dev/null
			case $__agent
			in
			    cisco)
				cd $__here
				./common.install.cisco $__scriptname $__agentdir
				;;
			    *)
				$sudo ./Install </dev/null
				;;
			esac
			cd $__here
			_log_fyi $PCP_LOG_DIR/pmcd/pmcd.log $__agentlog
			__reinstall=true
			rm -f $tmp.restart
		    else
			echo "Cannot find PMDA directory ($__agentdir)"
			echo "to re-install, ... giving up!"
			exit 1
		    fi
		fi
	    fi
	done
    done
}

_havelogger()
{
    if [ -z "`_get_pids_by_name -a 'pmlogger.*-P'`" ]
    then
	echo "Primary pmlogger not running ..."
	echo "chkconfig pmlogger on, and restart PMCD"
	_change_config pmlogger on
	if sed -e '/^#/d' "${PCP_PMLOGGERCONTROL_PATH}" \
	   | $PCP_AWK_PROG '$2 == "y" && $3 == "n" { sts = 1 } END { exit 1-sts }'
	then
	    : echo "have primary pmlogger line in main control file"
	elif sed -e '/^#/d' "${PCP_PMLOGGERCONTROL_PATH}.d/local" \
	   | $PCP_AWK_PROG '$2 == "y" && $3 == "n" { sts = 1 } END { exit 1-sts }'
	then
	    : echo "have primary pmlogger line in local control file"
	else
	    : echo "no primary pmlogger line in control file"
	    if $PCP_AWK_PROG '$2 == "y" && $3 == "n" { sts = 1} END { exit 1-sts }' <$PCP_PMLOGGERCONTROL_PATH
	    then
		: echo uncomment
		sed <$PCP_PMLOGGERCONTROL_PATH >$tmp.tmp \
		    -e '/^#[^ 	][^ 	]*[ 	][ 	]*y/s/#//'
		$sudo cp $tmp.tmp $PCP_PMLOGGERCONTROL_PATH
	    elif $PCP_AWK_PROG '$2 == "y" && $3 == "n" { sts = 1} END { exit 1-sts }' <$PCP_PMLOGGERCONTROL_PATH.d/local
	    then
		: echo uncomment
		sed <$PCP_PMLOGGERCONTROL_PATH.d/local >$tmp.tmp \
		    -e '/^#[^ 	][^ 	]*[ 	][ 	]*y/s/#//'
		$sudo cp $tmp.tmp $PCP_PMLOGGERCONTROL_PATH.d/local
	    else
		: echo add
		cp $PCP_PMLOGGERCONTROL_PATH.d/local $tmp.tmp
		cat >>$tmp.tmp <<'End-of-File'

# Installed by PCP QA common on `date`
LOCALHOSTNAME	y   n	PCP_ARCHIVE_DIR/LOCALHOSTNAME	-c config.default
End-of-File
		$sudo cp $tmp.tmp $PCP_PMLOGGERCONTROL_PATH.d/local
	    fi
	fi
	
	# we're seeing races here and timeouts for the first pmcd
	# restart after a package install ... just going one step
	# at a time, carefully ...
	#
	__pid=`_get_pids_by_name -a 'pmlogger.*-P'`
	_service pmlogger stop
	if [ -n "$__pid" ]
	then
	    # odd ... a primary pmlogger has appeared ... wait for it to
	    # go away
	    _wait_pmlogger_end $__pid
	fi
	_service pmlogger start
	_wait_for_pmlogger
    fi
}

_haveremote()
{
    # ensure critical daemons allow for remote access

    if test -f "${PCP_SYSCONFIG_DIR}/pmcd"
    then
	sed <$PCP_SYSCONFIG_DIR/pmcd >$tmp.tmp \
		-e '/^PMCD_LOCAL=1/s/^/#PCP QA# /g'
	diff $PCP_SYSCONFIG_DIR/pmcd $tmp.tmp >/dev/null || \
	$sudo cp $tmp.tmp $PCP_SYSCONFIG_DIR/pmcd
    fi

    if test -f "${PCP_SYSCONFIG_DIR}/pmproxy"
    then
	sed <$PCP_SYSCONFIG_DIR/pmproxy >$tmp.tmp \
		-e '/^PMPROXY_LOCAL=1/s/^/#/g'
	diff $PCP_SYSCONFIG_DIR/pmproxy $tmp.tmp >/dev/null || \
	$sudo cp $tmp.tmp $PCP_SYSCONFIG_DIR/pmproxy
    fi

    if test -f "${PCP_SYSCONFIG_DIR}/pmlogger"
    then
	sed <$PCP_SYSCONFIG_DIR/pmlogger >$tmp.tmp \
		-e '/^PMLOGGER_LOCAL=1/s/^/#/g'
	diff $PCP_SYSCONFIG_DIR/pmlogger $tmp.tmp >/dev/null || \
	$sudo cp $tmp.tmp $PCP_SYSCONFIG_DIR/pmlogger
    fi
}

_havepmcdtrace()
{
    __fix=false
    for __trace in traceconn tracepdu
    do
	__bit=`pminfo -h $DEFAULT_HOST -f pmcd.control.$__trace | sed -n -e '/value/s/ *value *//p'`
	if [ "X$__bit" != X1 ]
	then
	    pminfo -h $DEFAULT_HOST -f pmcd.control.$__trace
	    echo "PMCD event tracing not enabled!"
	    __fix=true
	fi
    done
    if $__fix
    then
	echo "fix options"
	[ -z "PCP_PMCDOPTIONS_PATH" ] && \
	      PCP_PMCDOPTIONS_PATH="$PCP_SYSCONF_DIR/pmcd/pmcd.options"
	PCPQA_PMCDOPTIONS="$PCP_PMCDOPTIONS_PATH"
	sed <$PCPQA_PMCDOPTIONS >$tmp.tmp -e '/^-T/s/^/#/'
	cat >>$tmp.tmp <<End-of-File

# Installed by PCP QA common on `date`
-T 3
End-of-File
	$sudo cp $tmp.tmp $PCPQA_PMCDOPTIONS
	touch $tmp.restart
    fi
}

_setpmcdlimits()
{
    __check=`pmprobe -h $DEFAULT_HOST -v pmcd.limits.contexts | $PCP_AWK_PROG 'NF == 3 && $2 == 1 { print $3 }'`
    if [ -n "$__check" -a $__check != 512 ]
    then
	pminfo -h $DEFAULT_HOST -f pmcd.limits.contexts
	echo "PMCD connection limits not 512 as required"
	echo "fix options"
	[ -z "PCP_PMCDOPTIONS_PATH" ] && \
	      PCP_PMCDOPTIONS_PATH="$PCP_SYSCONF_DIR/pmcd/pmcd.options"
	PCPQA_PMCDOPTIONS="$PCP_PMCDOPTIONS_PATH"
	sed <$PCPQA_PMCDOPTIONS >$tmp.tmp -e '/^-C/s/^/#/'
	cat >>$tmp.tmp <<End-of-File

# Installed by PCP QA common on `date`
-C 512
End-of-File
	$sudo cp $tmp.tmp $PCPQA_PMCDOPTIONS
	touch $tmp.restart
    fi
}

_setenvironment

__check=${__check-true}
__quick=${__quick-false}

# Try and guess what "make" is called ... configure leaves a comment
# like this
#NB: don't override $(MAKE); gnumake sets it well, propagating -j etc.
#MAKE	= /usr/local/bin/gmake
# in builddefs, so try there ...
#
if [ -f $PCP_INC_DIR/builddefs ]
then
    __make=`sed <$PCP_INC_DIR/builddefs -n -e '/^#NB: don.t override \$(MAKE);/{
N
s/.*MAKE[ 	]*=[ 	]*//p
}'`
    if [ -n "$__make" ]
    then
	MAKE=$__make; export MAKE
    fi
fi

if $__check
then
    if $__quick
    then
	:
    else
	if [ -f GNUmakefile.install ]
	then
	    # running QA in the tree
	    ${MAKE:-make} -f GNUmakefile.install >>/tmp/$$.make 2>&1
	    __sts=$?
	    ( cd qt; ./setup-executables )
	else
	    ${MAKE:-make} >/tmp/$$.make 2>&1
	    __sts=$?
	fi
	if [ $__sts != 0 ]
	then
	    cat /tmp/$$.make
	    echo "Warning: ${MAKE:-make} failed -- some tests may be missing"
	fi
	rm -f /tmp/$$.make
    fi
fi

__diff=diff
if [ ! -z "$DISPLAY" ]
then
    which tkdiff >/dev/null 2>&1 && __diff=tkdiff
    which xdiff >/dev/null 2>&1 && __diff=xdiff
    which xxdiff >/dev/null 2>&1 && __diff=xxdiff
    which gdiff >/dev/null 2>&1 && __diff=gdiff
fi

__color=false
__group=false
__xgroup=false
__exclude=false
__rflag=false
__selbygroup=false
__showme=false
__have_test_arg=false
__check_config=false
__timestamp=false
__timings_file=false
rm -f $tmp.list $tmp.tmp $tmp.sed $tmp.exclude

for __r
do

    if $__group
    then
    	__selbygroup=true

	# arg after -g
	__group_list=`
	if $__rflag
	then
	    sed <group \
		-e 's/\([0-9]\):retired /\1 /' \
		-e 's/\([0-9]\):reserved /\1 /' \
	    # end
	else
	    sed <group \
		-e '/[0-9]:retired /d' \
		-e '/[0-9]:reserved /d' \
	    # end
	fi \
	| sed -n -e 's/$/ /' -e "/^[0-9][0-9]*.* $__r /"'{
s/ .*//p
}'`
	if [ -z "$__group_list" ]
	then
	    echo "Group \"$__r\" is empty or not defined; ignored" >&2
	else
	    [ ! -s $tmp.list ] && touch $tmp.list
	    for __t in $__group_list
	    do
		if grep -s "^$__t\$" $tmp.list >/dev/null
		then
		    :
		else
		    echo "$__t" >>$tmp.list
		fi
	    done
    	fi
	__group=false
	continue

    elif $__xgroup
    then
    	__selbygroup=true

	# if no test numbers, do everything from group file
	[ -s $tmp.list ] || \
	if $__rflag
	then
	    sed -e 's/\([0-9]\):\(retired\|reserved\) /\1 /' <group
	else
	    sed -e '/[0-9]:\(retired\|reserved\) /d' <group
	fi \
	| sed -n -e '/^[0-9]/s/[ 	].*//p' >$tmp.list

	# arg after -x
	__group_list=`
	if $__rflag
	then
	    sed -e 's/\([0-9]\):\(retired\|reserved\) /\1 /' <group
	else
	    sed -e '/[0-9]:\(retired\|reserved\) /d' <group
	fi \
	| sed -n \
	    -e "/^[0-9].* $__r /s/[ 	].*//p" \
	    -e "/^[0-9].* $__r\$/s/[ 	].*//p"`
	if [ -z "$__group_list" ]
	then
	    echo "Group \"$__r\" is empty or not defined; ignored" >&2
	else
	    __numsed=0
	    rm -f $tmp.sed
	    for __t in $__group_list
	    do
		if [ $__numsed -gt 100 ]
		then
		    sed -f $tmp.sed <$tmp.list >$tmp.tmp
		    mv $tmp.tmp $tmp.list
		    __numsed=0
		    rm -f $tmp.sed
		fi
		echo "/^$__t\$/d" >>$tmp.sed
		__numsed=`expr $__numsed + 1`
	    done
	    sed -f $tmp.sed <$tmp.list >$tmp.tmp
	    mv $tmp.tmp $tmp.list
    	fi
	__xgroup=false
	continue

    elif $__exclude
    then
	# if no test numbers, do everything from group file
	[ -s $tmp.list ] || \
	if $__rflag
	then
	    sed -e 's/\([0-9]\):\(retired\|reserved\) /\1 /' <group
	else
	    sed -e '/[0-9]:\(retired\|reserved\) /d' <group
	fi \
	| sed -n -e '/^[0-9]/s/[ 	].*//p' >$tmp.list

	if echo "$__r" | grep '[0-9]-[0-9]' >/dev/null
	then
	    eval `echo $__r | sed -e 's/^/__start=/' -e 's/-/ __end=/'`
	    $PCP_AWK_PROG </dev/null '
BEGIN	{ for (t = '$__start'; t <= '$__end'; t++) printf "%03d\n",t }' \
	    | while read __id
	    do
		# if test not present, silently forget about it
		if [ ! -f $__id ]
		then
		    continue
		fi
		if grep -E -s "^$__id([: 	]|\$)" group >/dev/null
		then
		    # in group file ... OK
		    echo "/^$__id\$/d" >>$tmp.exclude
		fi
	    done
	else
	    for __t in `echo "$__r" | sed -e 's/,/ /g'`
	    do
		echo "/^0*$__t\$/d" >>$tmp.exclude
	    done
	fi
	__exclude=false
	continue
    fi

    __xpand=true
    __range=false
    case "$__r"
    in

	-\?)	# usage
	    echo "Usage: $0 [options] [seq[ seq...]]"'

check options
    -c		check configuration files [off]
    -C		color mode output [off]
    -CI		run in CI environment => set $PCPQA_IN_CI in environment
    		and -x x11 -x remote -x not_in_ci
    -g group	include tests from this group (additive for multiple -g options)
    -G          report groups and number of tests per group
    -l		line mode diff [xdiff]
    -s		sssh mode diff [no diff, regular output]
    -n		show me, do not run tests
    -q		quick, no PMDA checks (you are on your own)
    -r		include reserved and retired tests
    -T		output timestamps
    -TT		write timestamps to check.timings
    -x group	exclude tests from this group (additive for multiple -x options)
    -X seq[,seq...]
		exclude these tests (additive for multiple -X options)

And seq is a test number or a test number range, e.g. 000-009 or 1000
'
	    __aborted=false
	    exit 0
	    ;;

	-c)	# check config files
	    __check_config=true
	    __xpand=false
	    ;;

	-C)	# color mode for results and summaries
	    __color=true
	    __xpand=false
	    ;;

	-CI)	# run in CI environment
		# TODO still need -x x11 -x remote -x not_in_ci
	    PCPQA_IN_CI=yes; export PCPQA_IN_CI
	    __xpand=false
	    ;;

	-G)	# -G report groups and number of tests per group
	    sed -n -e '/^[a-z]/{
s/[ 	].*//
p
}' <group >$tmp.group
	    cat $tmp.group
	    echo ===
	    LC_COLLATE=POSIX sort $tmp.group \
	    | while read __name
	    do
		__num=`
		    if $__rflag
		    then
			sed -e 's/\([0-9]\):\(retired\|reserved\) /\1 /' <group
		    else
			sed -e '/[0-9]:\(retired\|reserved\) /d' <group
		    fi \
		    | grep -E "^[0-9].*[ 	]$__name([ 	]|\$)" \
		    | wc -l \
		    | sed -e 's/ //g'`
		printf "%-20.20s %3d\n" $__name $__num
	    done \
	    | LC_COLLATE=POSIX sort -nr -k2,2
	    __aborted=false
	    exit 0
	    ;;

	-g)	# -g group ... pick from group file
	    __group=true
	    __xpand=false
	    ;;

	-l)	# line mode for diff, not gdiff over modems
	    __diff=diff
	    __xpand=false
	    ;;

	-n)	# show me, don't do it
	    __showme=true
	    __quick=true
	    __xpand=false
	    ;;

	-q)	# "quick", no PMDA checks (you are on your own)
	    __quick=true
	    __xpand=false
	    ;;

	-r)	# include reserved and retired tests
	    __rflag=true
	    __xpand=false
	    ;;

	-s)	# sssh mode for diff, no diff at all 
	    __diff=true
	    __xpand=false
	    ;;

	-T)	# turn on timestamp output
	    __timestamp=true
	    __xpand=false
	    ;;

	-TT)	# turn on check.timings
	    __timings_file=true
	    __xpand=false
	    ;;

	-x)	# -x group ... exclude from group file
	    __xgroup=true
	    __xpand=false
	    ;;

	-X)	# -X seq[,seq...] or -X seq-seq ... exclude explicit tests
	    __exclude=true
	    __xpand=false
	    ;;

	'[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
	    echo "No tests?" >&2
	    status=1
	    exit $status
	    ;;

	[0-9]*-[0-9]*)
	    eval `echo $__r | sed -e 's/^/__start=/' -e 's/-/ __end=/'`
	    __range=true
	    ;;

	[0-9]*-)
	    eval `echo $__r | sed -e 's/^/__start=/' -e 's/-//'`
	    __end=`echo [0-9][0-9][0-9] [0-9][0-9][0-9][0-9] | sed -e 's/\[0-9]//g' -e 's/  *$//' -e 's/.* //'`
	    if [ -z "$__end" ]
	    then
		echo "No tests in __range \"$__r\"?" >&2
		status=1
		exit $status
	    fi
	    __range=true
	    ;;

	[0-9]|[0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9][0-9][0-9])
	    __start=$__r
	    __end=$__r
	    ;;

	*)
	    echo "Error: \"$__r\" is not a valid QA test number" >&2
	    status=1
	    exit $status
	    ;;

    esac

    if $__xpand
    then
	__start=`echo $__start | sed -e 's/^0*\(.\)/\1/'`
	__end=`echo $__end | sed -e 's/^0*\(.\)/\1/'`
	__have_test_arg=true
	if $__rflag
	then
	    sed -e 's/\([0-9]\):\(retired\|reserved\) /\1 /' <group
	else
	    sed -e '/[0-9]:\(retired\|reserved\) /d' <group
	fi >$tmp.group
	$PCP_AWK_PROG </dev/null '
BEGIN	{ for (t = '$__start'; t <= '$__end'; t++) printf "%03d\n",t }' \
	| while read __id
	do
	    # if test not present, forget about it
	    if [ ! -f $__id ]
	    then
		if [ $__id = $__start ]
		then
		    echo "$__id - no such test, skipped"
		elif [ $__id = $__end ]
		then
		    echo "$__id - no such test, skipped"
		fi
		continue
	    fi
	    if grep -E -s "^$__id([ 	]|$)" $tmp.group >/dev/null
	    then
		# in group file ... OK
		echo $__id >>$tmp.list
	    elif grep -E -s "^$__id:retired([ 	]|$)" group >/dev/null
	    then
		# in group file, but retired
		if $__rflag
		then
		    echo $__id >>$tmp.list
		else
		   $__range || echo "$__id - retired test, ignored"
		fi
	    elif grep -E -s "^$__id:reserved([ 	]|$)" group >/dev/null
	    then
		# in group file, but reserved
		if $__rflag
		then
		    echo $__id >>$tmp.list
		else
		    $__range || echo "$__id - reserved test, ignored"
		fi
	    else
		# oops
		$__range || echo "$__id - unknown test, ignored"
	    fi
	done
    fi

done

if [ -s $tmp.list ]
then
    # found some valid test numbers ... this is good
    :
else
    if $__have_test_arg
    then
	# had test numbers, but none in group file ... do nothing
	touch $tmp.list
    else
	if $__selbygroup
    	then
    	    echo "No tests selected?" >&2
    	    exit 1
    	else
	    # no test numbers, do everything from group file
	    touch $tmp.list
	    if $__rflag
	    then
		sed -e 's/\([0-9]\):\(retired\|reserved\) /\1 /' <group
	    else
		sed -e '/[0-9]:\(retired\|reserved\) /d' <group
	    fi \
	    | sed -n -e '/^[0-9]/{
s/[ 	].*//
p
}' \
	    | while read __id
	    do
		[ -f $__id ] || continue
		echo $__id >>$tmp.list
	    done
    	fi
    fi
fi

# handle -X exclusions
#
if [ -s $tmp.exclude ]
then
    sed -f $tmp.exclude <$tmp.list >$tmp.tmp
    mv $tmp.tmp $tmp.list
fi

__list=`sort -n $tmp.list`
rm -f $tmp.list $tmp.tmp $tmp.sed $tmp.exclude

# re-process the product-specific setup in case command line args have
# changed things, e.g. -h hostname
#
. ./common.setup

export QA_USER

if $__check
then
    # try loopback default (-h localhost) first ...
    #
    __x=`pminfo -v pmcd.control.timeout 2>&1`
    if [ -n "$__x" ]
    then
	echo "Is pmcd running on localhost?  Simple test produces ..."
	echo "$__x"
	_triage_pmcd
	exit 1
    fi
    # now try -h localhostname
    #
    $sudo rm -f $tmp.ok
    __x=`pminfo -h $DEFAULT_HOST -v pmcd.control.timeout 2>&1`
    if [ -n "$__x" ]
    then
	case "$__x"
	in
	    *'Connection refused')
		# OK, now this might be a Fedora 27 style config set up
		# where PMCD_LOCAL is set in the environment before the
		# pmcd start up script is run
		#
		if [ -n "$PCP_SYSCONFIG_DIR" -a -f $PCP_SYSCONFIG_DIR/pmcd ]
		then
		    if grep '^[^#]*PMCD_LOCAL=1' $PCP_SYSCONFIG_DIR/pmcd >/dev/null
		    then
			_haveremote
			_service pmcd restart
			_wait_for_pmcd
			__x=`pminfo -h $DEFAULT_HOST -v pmcd.control.timeout 2>&1`
			[ -z "$__x" ] && touch $tmp.ok
		    fi
		fi
		;;
	esac
	if [ ! -f $tmp.ok ]
	then
	    echo "Is pmcd running on host $DEFAULT_HOST?  Simple test produces ..."
	    echo "$__x"
	    exit 1
	fi
    fi
fi

_havesudo

case $__scriptname
in
    check|remake)
	# $PCP_RC_DIR scripts need this to produce deterministic output now
	#
	_change_config verbose on
	;;
esac

if $__quick
then
    :
else
    ./mk.localconfig

    rm -f $tmp.restart
    $OPTION_PMCD_TRACE && _havepmcdtrace
    $OPTION_PMCD_LIMITS && _setpmcdlimits
    $OPTION_AGENTS && _haveagents

    if [ -f $tmp.restart ]
    then
	__grp=root
	case $PCP_PLATFORM
	in
	    freebsd|netbsd|openbsd)
		    __grp=wheel
		    ;;
	esac
	$sudo chown root:$__grp $PCPQA_PMCDOPTIONS
	_service pmcd restart
	_wait_for_pmcd
    fi

    $OPTION_REMOTE && _haveremote
    $OPTION_LOGGER && _havelogger

    if [ -f GNUmakefile.install ]
    then
	# running QA in the tree
	${MAKE:-make} -f GNUmakefile.install setup
	cd pmdas
	if ${MAKE:-make} -f GNUmakefile.install setup >$tmp.tmp 2>&1
	then
	    :
	else
	    cat $tmp.tmp
	    echo "Warning: pmdas: $MAKE -f GNUmakefile.install setup failed"
	fi
	cd broken
	if ${MAKE:-make} -f GNUmakefile.install broken_v2.dir >$tmp.tmp 2>&1
	then
	    :
	else
	    cat $tmp.tmp
	    echo "Warning: pmdas/broken: $MAKE -f GNUmakefile.install broken_v2.dir failed"
	fi
	cd ../..
    else
	${MAKE:-make} setup
    fi
    if [ $? != 0 ]
    then
	echo "Error: ${MAKE:-make} setup failed"
	exit 1
    fi

    # since pmcd no longer runs as root, normal users must be able
    # to read all dirs on the path to the qa home ...
    #
    __x=`pwd`
    while [ -n "$__x" -a "$__x" != / ]
    do
	__prot=`ls -ldL "$__x" | sed -e 's/[ 	].*//'`
	case $__prot
	in
	    dr?x*)
		;;
	    *)
		echo "Warning: parent directory $__x (mode:$__prot) not owner readable and searchable"
		;;
	esac
	__x=`dirname $__x`
    done

    # if we have selinux and it is enforcing, and PCP was build with
    # selinux enabled, then make sure the PCP QA policy module
    # (pcp-testsuite) is installed
    #
    ENABLE_SELINUX=false
    if [ -f $PCP_INC_DIR/builddefs ]
    then
	eval `sed -n -e '/ENABLE_SELINUX =/s/ //gp' <$PCP_INC_DIR/builddefs`
    fi
    #debug# echo "ENABLE_SELINUX=$ENABLE_SELINUX"
    if $ENABLE_SELINUX
    then
	if which getenforce >/dev/null 2>&1
	then
	    case `getenforce`
	    in
		Enforcing)
		    if $sudo semodule -l | grep pcp-testsuite >/dev/null
		    then
			# nothing to do, module already installed
			# ... to force a re-install, e.g. after the module
			# has been updated, do
			# $ sudo semodule -r pcp-testsuite
			# first
			#
			:
		    else
			$sudo semodule -i pcp-testsuite.pp
		    fi
		    # and now any selinux booleans that help
		    #
		    for __bool in pcp_read_generic_logs pcp_bind_all_unreserved_ports
		    do
			if $sudo getsebool $__bool 2>/dev/null | grep ' --> off' >/dev/null
			then
			    $sudo setsebool $__bool true
			fi
		    done
		    ;;
		*)
		    ;;
	    esac
	fi
    fi
fi

# Hook for check.callback to allow once-per-check-run tests
#
touch check.onetrip