#!/bin/sh
# PCP QA Test No. 1722
# Exercise the bpftrace PMDA - autostart script with custom name
#

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

. ./common.bpftrace

_pmdabpftrace_check

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

_prepare_pmda bpftrace
trap "_pmdabpftrace_cleanup; exit \$status" 0 1 2 3 15
_stop_auto_restart pmcd


# real QA test starts here
_pmdabpftrace_clean_autostart_scripts
cat <<EOF | sudo tee $PCP_PMDAS_DIR/bpftrace/autostart/script.bt > /dev/null
// name: testscript
BEGIN { @scalar = 2; }
tracepoint:syscalls:sys_enter_openat { @ = count(); }
EOF
cat <<EOF | _pmdabpftrace_install
# Installed by PCP QA test $seq on `date`
EOF

echo "=== check script is running ==="
_pmdabpftrace_wait_for_value bpftrace.scripts.testscript.probes 3
pminfo bpftrace

echo "=== check metrics ==="
pminfo -dfmtT bpftrace.scripts.testscript.data.scalar


_pmdabpftrace_remove
status=0
exit
