#!/bin/sh
# PCP QA Test No. 1165 (was 1125)
# Exercise the BCC PMDA klockstat module - install, remove and values.
#
# Copyright (c) 2019 Red Hat.
#

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

. ./common.bcc

_pmdabcc_check
_pmdabcc_require_kernel_version 4 7

status=1       # failure is the default!
signal=$PCP_BINADM_DIR/pmsignal
$sudo rm -rf $tmp.* $seq.full

_value_filter()
{
    awk '/value [1-9][0-9]*/ {print "OK"; exit}'
}

cat <<EOF >$tmp.conf
# Installed by PCP QA test $seq on `date`
[pmda]
modules = klockstat
prefix = bcc.
[klockstat]
module = klockstat
cluster = 31
process = pmcd
EOF

_pmdabcc_try_compile $tmp.conf

_prepare_pmda bcc
trap "_pmdabcc_cleanup; exit \$status" 0 1 2 3 15
_stop_auto_restart pmcd

# real QA test starts here
_pmdabcc_install <$tmp.conf
_pmdabcc_wait_for_metric

# Generate system activity for the BCC klockstat module
for i in 1 2 3 ; do pminfo bcc > /dev/null ; done

echo "=== report metric values ==="
pminfo -dfmtT bcc.kernel.lock.mutex.spin.avg 2>&1 | tee -a $here/$seq.full \
| _value_filter

_pmdabcc_remove

status=0
exit
