docs: tweak formatting in pmrep(1) archive folio example
[pcp.git] / qa / 518
blob5b91cc71c4bd7aed0397f40b312a23a6eba0ed2b
1 #!/bin/sh
2 # PCP QA Test No. 518
3 # pcp -P workout
5 # Copyright (c) 2012 Ken McDonell. All Rights Reserved.
8 seq=`basename $0`
9 echo "QA output created by $seq"
11 # get standard environment, filters and checks
12 . ./common.product
13 . ./common.filter
14 . ./common.check
16 status=1 # failure is the default!
17 $sudo rm -rf $tmp.* $seq.full
18 trap "$sudo rm -f $tmp.*; exit \$status" 0 1 2 3 15
20 cat <<End-of-File >$tmp.pmie
21 hinv.ncpu > 0 -> print "we have cpus, no surprise here!";
22 hinv.ncpu < 0 -> print "whoa ... no cpus!";
23 End-of-File
25 # real QA test starts here
27 # prefer to run as "pcp", must ensure we can write stats files
28 # to PCP_TMP_DIR which is no longer a world-writable directory
30 user=pcp
31 id pcp >/dev/null 2>/dev/null || user=root
32 $sudo -u $user pmie -t 0.25sec -T 3sec -c $tmp.pmie 2>$tmp.err >$tmp.out &
33 pid=$!
35 # let stats accumulate via rule firings
36 sleep 2
38 # NB: For a naive exact match, there is a race condition here, as
39 # 518.out expects exactly three evaluation rounds to be complete by the
40 # time the following operation is invoked. If sudo/pmie is too slow,
41 # it'll lose the race (actions<5). If this thread is too slow, pmie
42 # will go ahead (actions>5). So we tolerate values in the range 4,5,6-9
43 # for the true, false and action counts, but the counts for each must
44 # be equal.
46 # pcp -P output ...
47 # pmie: bozo-vm: /tmp/518-28812.pmie (2 rules)
48 # evaluations true=5 false=5 unknown=0 (actions=2)
49 # expected evaluation rate=8.00 rules/sec
50 # bozo-vm: /var/log/pcp/pmmgr/bozo-vm/config.pmie (12 rules)
51 # evaluations true=0 false=3 unknown=9 (actions=0)
52 # expected evaluation rate=0.10 rules/sec
54 # want our pmie, not any other pmie processes
55 # map = -> '= ' and )$ -> ' )' for evaluations line
56 # map rules) -> rule) to dodge pluralization
58 # wrinkle is line breaks in the output formatting of pcp(1) ...
59 # pmie: bozo-laptop: /var/log/pcp/pmmgr/bozo-laptop/config.pmie
60 # (12 rules)
62 debug=false
63 pcp -P \
64 | tee -a $seq.full \
65 | sed \
66 -e '/:/{
67 :loop
69 s/\n[ ]*\(.*([0-9][0-9]* rules\)/ \1/
70 }' \
71 | sed \
72 -e '/^ *evaluations / {
73 s/=/= /g
74 s/)$/ )/
75 }' \
76 -e 's/rules)$/rule)/' \
77 | tee $tmp.dbg.1 \
78 | $PCP_AWK_PROG '
79 /pmie: .* rule\)/ { state=1 }
80 '$debug' == "true" { print "state=" state " want=" want ": " $0 }
81 state==1 && /'`echo $tmp.pmie | sed -e s@/@\\\\\\\\/@g`' \(2 rule\)/ { print; want = 1; next }
82 state==1 && / \(actions=/ { if ($3 == $5 && $5 == $9) {
83 if ($3 >= 4 && $3 <= 9) $3 = "OK"
84 if ($5 >= 4 && $5 <= 9) $5 = "OK"
85 if ($9 >= 4 && $9 <= 9) $9 = "OK"
88 state==1 && / rule\)/ { want = 0 }
89 want==1 { print }' \
90 | tee $tmp.dbg.2 \
91 | sed \
92 -e '/^evaluations / {
93 s/= /=/g
94 s/ )$/)/
95 }' \
96 -e "s;$tmp;TMP;" \
97 -e "s;/privateTMP;TMP;g" \
98 -e '/TMP/{
99 s/ (.*//
100 s/.*:/HOST:/
103 wait
105 echo >>$seq.full
106 echo "=== pmie stdout ===" >>$seq.full
107 cat $tmp.out >>$seq.full
108 echo >>$seq.full
109 echo "=== pmie stderr ===" >>$seq.full
110 cat $tmp.err >>$seq.full
111 echo >>$seq.full
112 echo "=== filter after sed ===" >>$seq.full
113 cat $tmp.dbg.1 >>$seq.full
114 echo >>$seq.full
115 echo "=== filter after awk ===" >>$seq.full
116 cat $tmp.dbg.2 >>$seq.full
118 status=0
119 exit