#!/bin/sh
# PCP QA Test No. 1707
# Exercise the bpftrace PMDA - custom output blocks
#

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 | _pmdabpftrace_install
# Installed by PCP QA test $seq on `date`
[dynamic_scripts]
enabled = true
auth_enabled = false
EOF

echo "=== start bpftrace script ==="
pmstore bpftrace.control.register "// name: testscript
// custom-output-block
tracepoint:syscalls:sys_enter_openat { @ = count(); @scalar = 2; }
interval:s:1 { print(@scalar); }"
_pmdabpftrace_wait_for_value bpftrace.scripts.testscript.probes 2

echo "=== generating openat() syscall activity ==="
_pmdabpftrace_generate_openat_syscall_activity &
echo "wait 2 seconds to capture syscall activity..."
pmsleep 2

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

echo "=== we disabled default output block, therefore we should get output only for @scalar ==="
pminfo -dfmtT bpftrace.scripts.testscript.data.root


_pmdabpftrace_remove
status=0
exit
