summaryrefslogtreecommitdiff
path: root/qa/301
blob: bc4d9b5cd78c93946ebc0b9b912ae876d72f8e29 (plain)
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
#!/bin/sh
# PCP QA Test No. 301
# Stop pmcd and check no pmdas are still running.
#
# Copyright (c) 1995-2002 Silicon Graphics, Inc.  All Rights Reserved.
#

seq=`basename $0`
echo "QA output created by $seq"

# get standard filters
. ./common.product
. ./common.filter
. ./common.check

signal=$PCP_BINADM_DIR/pmsignal
status=1	# failure is the default!
trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15

# real QA test starts here


#  Useful definitions...
DEADLIMIT=120	# seconds
BREATHER=30	# seconds

#  Debugging controls...
CMND=$seq   	    	#  already done for us
DBUG=${DBUG:-FALSE} 	#  normally, the name of this script, $0
DBUGLVL=${DBUGLVL:-1}	#  normally set to 1

#  Requires common.product:
case $PCP_PLATFORM
in
    linux|darwin|solaris)
	AMTIME1970PROG="date +%s"
	;;
    *)
	if [ -x /usr/etc/amtime1970 ]
	then
	    AMTIME1970PROG=/usr/etc/amtime1970
	else
	    echo "Unknown platfrom $PCP_PLATFORM"
	    exit 1
	fi
	;;
esac

dbugEcho () {
    if [ $# -gt 1 -a "$DBUG" != FALSE -a "$DBUG" = "$CMND" -a "$DBUGLVL" -ge "$1" ]
    then
    	shift
	printf "  ?: " 1>&2
	for P
	do
    	    printf "%s" "$P" 1>&2
	done
	printf "\n" 1>&2
    fi
}


waitTilDead () {
    NUMPROC=1
    DEADSTART=`$AMTIME1970PROG`
    DEADTIME=0
    while [ "$NUMPROC" -gt 0 -a $DEADTIME -lt $DEADLIMIT ]
    do
    	sleep 1
    	NUMPROC=`ps -eo "args pid" | $PCP_AWK_PROG '
/^\/var\/pcp\/pmdas\/.*pmda.*/	{ print $NF," ",$1 }
' | wc -l`
    	DEADTIME=`$AMTIME1970PROG`
    	DEADTIME=`expr $DEADTIME - $DEADSTART`
    done
    
    echo $DEADTIME
    return 0
}


dbugEcho 1 "Shutting down PCP"
$sudo sh $PCP_RC_DIR/pcp stop >/dev/null &

#  Wait for PMDAs with sprocs to exit.
dbugEcho 1 "Waiting until PCP is dead"
SDTIME=`waitTilDead`
if [ $? != 0 ]
then
    echo 1>&2 "$seq: unable to determine current time of day"
    status=2
else
    if [ "$SDTIME" -ge $DEADLIMIT ]
    then
	echo 1>&2 "$seq: PCP could not be shut down after $DEADLIMIT seconds"
    	status=2
    else
	dbugEcho 1 "PMDAs took $SDTIME second(s) to shut down"
    fi
fi

# really make sure the "$PCP_RC_DIR/pcp stop" is complete, so it does
# not terminate the pmcd we're going to start
#
$sudo $signal -a pmcd >/dev/null 2>&1
wait

if [ $status -gt 1 ]
then
    dbugEcho 1 "Recovering after $BREATHER seconds"
    sleep $BREATHER
fi
dbugEcho 1 "Starting up PCP"
$sudo sh $PCP_RC_DIR/pcp restart >/dev/null
_wait_for_pmcd

# success or failure, we've finished
status=`expr $status - 1`
exit