Merge branch 'master' of git://git.pcp.io/pcp into qt
[pcp.git] / qa / 067
blobda1be3c8bdd3fb0ee61b9fa003b9ac40921398ee
1 #! /bin/sh
2 # PCP QA Test No. 067
3 # Test PMCD's ability to detect and cleanup agents it didn't create when they
4 # terminate
6 # Copyright (c) 1995-2002 Silicon Graphics, Inc. All Rights Reserved.
9 seq=`basename $0`
10 echo "QA output created by $seq"
12 # get standard filters
13 . ./common.product
14 . ./common.filter
15 . ./common.check
17 which netstat >/dev/null 2>&1 || _notrun "netstat not installed"
19 rm -f $seq.out
20 _get_libpcp_config
21 if $ipv6 ; then
22 ln $seq.out.ipv6 $seq.out || exit 1
23 else
24 ln $seq.out.nonipv6 $seq.out || exit 1
27 trap "rm -f $tmp.*; exit" 0 1 2 3 15
29 # real QA test starts here
31 signal=$PCP_BINADM_DIR/pmsignal
32 log=$PCP_PMCDLOG_PATH
33 LOCALHOST=`hostname`
35 _filter_log()
37 sleep 1
38 _filter_pmcd_log <$log \
39 | sed \
40 -e '/^$/d' \
41 -e 's/ *$//' \
42 -e 's/^$//' \
43 -e '/^->/d' \
44 -e '/^00[08]:/d' \
45 -e '/^sample/s/.*/sample agent.../' \
46 -e 's/fd=[0-9][0-9]*/fd=<n>/g' \
47 -e 's/^ ok [0-9]*/ ok <n>/g' \
48 -e '/^test/s/ *[0-9][0-9]* *[0-9][0-9]* ... bin/ <n> <n> <n> bin/' \
49 -e '/Resource busy/d' \
50 -e 's/0x[^ ]*\([^ ][^ ][^ ]\)/ADDR...\1/' \
51 -e '/client connection from/,/^$/d' \
52 -e '/Cleanup/d' \
53 -e '/Info: spindle_stats_init/d' \
54 -e '/UNIX_DOMAIN_SOCKET/d' \
55 #end
58 _filter_pmda_log()
60 sed \
61 -e 's/^\(Log for pmda[^ ]* on\) .*/\1 HOST .../' \
62 -e 's/^\(Log finished\) .*/\1 .../'
65 interrupt()
67 echo "Interrupted"
68 exit
71 if [ -d $PCP_LOG_DIR/pmlogger ]
72 then
73 LOGGING_DIR=$PCP_LOG_DIR/pmlogger
74 else
75 LOGGING_DIR=$PCP_LOG_DIR
78 cleanup()
80 _restore_config $PCP_PMCDCONF_PATH
81 pmafm $LOGGING_DIR/$LOCALHOST/Latest remove >$tmp.cmd 2>&1 \
82 && $sudo sh $tmp.cmd
83 echo "Restarting pmcd"
84 $sudo $PCP_RC_DIR/pcp restart | _filter_pcp_start
85 _wait_for_pmcd
86 _wait_for_pmlogger
87 rm -f $tmp.*
90 trap interrupt 1 2 3 15
91 trap cleanup 0
93 domain=246
94 if [ $PCP_PLATFORM = linux ]
95 then
96 cat >$tmp.config <<End-of-file
97 # pmcd.conf generated by QA $seq
98 linux 60 dso linux_init $PCP_PMDAS_DIR/linux/pmda_linux.so
99 pmcd 2 dso pmcd_init $PCP_PMDAS_DIR/pmcd/pmda_pmcd.so
100 test $domain socket inet 2222
101 End-of-file
102 elif [ $PCP_PLATFORM = darwin ]
103 then
104 cat >$tmp.config <<End-of-file
105 # pmcd.conf generated by QA $seq
106 darwin 78 dso darwin_init $PCP_PMDAS_DIR/darwin/pmda_darwin.dylib
107 pmcd 2 dso pmcd_init $PCP_PMDAS_DIR/pmcd/pmda_pmcd.dylib
108 test $domain socket inet 2222
109 End-of-file
110 elif [ $PCP_PLATFORM = solaris ]
111 then
112 cat >>$tmp.config <<End-of-File
113 # pmcd.conf generated by QA $seq
114 solaris 75 dso solaris_init $PCP_PMDAS_DIR/solaris/pmda_solaris.so
115 pmcd 2 dso pmcd_init $PCP_PMDAS_DIR/pmcd/pmda_pmcd.so
116 test $domain socket inet 2222
117 End-of-File
118 elif [ $PCP_PLATFORM = freebsd ]
119 then
120 cat >>$tmp.config <<End-of-File
121 # pmcd.conf generated by QA $seq
122 freebsd 85 dso freebsd_init $PCP_PMDAS_DIR/freebsd/pmda_freebsd.so
123 pmcd 2 dso pmcd_init $PCP_PMDAS_DIR/pmcd/pmda_pmcd.so
124 test $domain socket inet 2222
125 End-of-File
126 else
127 echo "Error - need pmcd.conf setup for $PCP_PLATFORM"
128 exit 1
131 # netstat -an formats
133 # Redhat 7.3 and 9
134 # tcp 0 0 0.0.0.0:2222 0.0.0.0:* LISTEN
136 # Mac OS X 10.6
137 # tcp4 0 0 *.2222 *.* LISTEN
139 # openindiana
140 # *.2222 *.* 0 0 128000 0 LISTEN
143 $sudo $signal -a pmgadgets pmchart pmview pmie >/dev/null 2>&1
144 src/pmdashutdown -i 2222 -d $domain -l $tmp.pmdalog &
145 pid=$!
146 echo "pmdashutdown pid: $pid" >$seq.full
147 sleep 1
148 echo
149 echo "port 2222 should be listening"
150 netstat -an \
151 | tee -a $seq.full \
152 | grep '[.:]2222 ' \
153 | sed \
154 -e 's/127\.0\.0\.1/*/g' \
155 -e 's/0\.0\.0\.0/*/g' \
156 -e 's/:/./g' \
157 -e 's/.*\(\*.2222\).*\(LISTEN\).*/... \1 ... \2/'
158 echo
160 _save_config $PCP_PMCDCONF_PATH
161 $sudo cp $tmp.config $PCP_PMCDCONF_PATH
162 pmafm $LOGGING_DIR/$LOCALHOST/Latest remove >$tmp.cmd 2>&1 \
163 && $sudo sh $tmp.cmd
164 $sudo $PCP_RC_DIR/pcp restart | _filter_pcp_start
165 _wait_for_pmcd
166 # echo "config:"
167 # cat $config | sed -e "s;$PCP_PMDAS_DIR;\$PCP_PMDAS_DIR;"
168 echo
170 # wait for pmdashutdown to finish
172 for t in 1 2 3 4 5 6
174 echo >>$seq.full
175 echo "wait for pmdashutdown to finish ... cycle $t" >>$seq.full
176 if ps $PCP_PS_ALL_FLAGS | tee -a $seq.full | cut -f1 | grep $pid >/dev/null 2>&1
177 then
178 sleep 2
179 else
180 break
182 done
184 echo >>$seq.full
185 cat $tmp.pmdalog >>$seq.full
186 echo
187 echo "pmda log (should have terminated):"
188 _filter_pmda_log <$tmp.pmdalog
189 echo
191 $sudo $signal -a -s HUP pmcd
193 # wait for PMCD to finish writing log (or 5 seconds)
194 for t in 1 2 3 4 5
196 if egrep '^Cleanup "test" agent' $log >/dev/null 2>&1
197 then
198 break
200 sleep 1
201 done
203 _filter_log