#!/bin/sh
# PCP QA Test No. 1893
# Exercise the Linux proc PMDA exe and cwd metrics.
#
# Copyright (c) 2021 Red Hat.  All Rights Reserved.
#

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

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check

[ $PCP_PLATFORM = linux ] || _notrun "Linux proc PMDA specific test"

_cleanup()
{
    cd $here
    $sudo rm -rf $tmp $tmp.*
}

status=0	# success is the default!
$sudo rm -rf $tmp $tmp.* $seq.full
trap "_cleanup; exit \$status" 0 1 2 3 15

_filter()
{
    sed \
	-e "s/0*$mypid .*sh.] value/MYPID sh] value/g" \
	-e "s/*$mypid or /MYPID or /g" \
	-e "s,$mycwd,CWD,g" \
	-e "s,$myexe,EXE,g" \
    # end
}

# real QA test starts here
mypid=$$
mycwd=`pwd`
myexe=`readlink /proc/$$/exe`

echo mypid: $mypid > $seq.full
echo mycwd: $mycwd >> $seq.full
echo myexe: $myexe >> $seq.full

echo == check for any exe failures
pminfo -v proc.psinfo.exe
echo done

echo == check exe value for self | tee -a $seq.full
pminfo -f proc.psinfo.exe | tee -a $seq.full | fgrep "inst [$mypid " | _filter
echo done

echo == check for any cwd failure
pminfo -v proc.psinfo.cwd
echo done

echo == check cwd value for self | tee -a $seq.full
pminfo -f proc.psinfo.cwd | tee -a $seq.full | fgrep "inst [$mypid " | _filter
echo done

# success, all done
exit
