#!/bin/sh
# PCP QA Test No. 1634
# Test pmdasockets
#
# Copyright (c) 2021 Red Hat.  All Rights Reserved.
#

if [ $# -eq 0 ]
then
    seq=`basename $0`
    echo "QA output created by $seq"
else
    # use $seq from caller, unless not set
    [ -n "$seq" ] || seq=`basename $0`
    echo "QA output created by `basename $0` $*"
fi

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

do_valgrind=false
if [ "$1" = "--valgrind" ]
then
    _check_valgrind
    do_valgrind=true
fi

[ $PCP_PLATFORM = linux ] || _notrun "pmdasockets is Linux-specific"
[ -f $PCP_PMDAS_DIR/sockets/pmdasockets ] || _notrun "sockets pmda not installed"

pmns=$PCP_PMDAS_DIR/sockets/root
pmda=$PCP_PMDAS_DIR/sockets/pmda_sockets.$DSO_SUFFIX,sockets_init
_make_helptext sockets

# override the default contents of PMDA cache files
# (do not want localhost versions to be used here).
#
domain=154
[ -f $PCP_VAR_DIR/config/pmda/$domain.0 ] && \
_save_config $PCP_VAR_DIR/config/pmda/$domain.0
$sudo rm -f $PCP_VAR_DIR/config/pmda/$domain.0

_cleanup()
{
    cd $here
    [ -f $PCP_VAR_DIR/config/pmda/$domain.0.$seq ] && \
    _restore_config $PCP_VAR_DIR/config/pmda/$domain.0

    $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/<something>/<else>/' \
    # end
}

# real QA test starts here
for f in sockets/ss_noemitauOH.txt sockets/ss_noemitauOH_ubuntu.txt; do
    echo === testing $f ===
    export PCPQA_PMDA_SOCKETS="$f"
    $sudo rm -f $PCP_VAR_DIR/config/pmda/$domain.0
    _run_valgrind pminfo -L -K clear -K add,154,$pmda -dfmt -n $pmns network.persocket
done

# success, all done
exit
