#!/bin/sh
# PCP QA Test No. 1623
# test LOGIMPORT logvol switching
#
# Copyright (c) 2020 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

# test for-some-thing || _notrun No support for some-thing
which collectl2pcp >/dev/null 2>&1 || _notrun collectl2pcp not installed
which pmrep >/dev/null 2>&1 || _notrun pmrep not installed

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

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

# real QA test starts here
[ ! -d "$tmp" ] && mkdir -p $tmp
echo checking one volume created without PCP_LOGIMPORT_MAXLOGSZ
collectl2pcp collectl/rhel6.raw.gz $tmp/onevol
vols=`echo $tmp/onevol.[0-9]* | wc -w`
[ "$vols" -ne 1 ] && echo onevol FAILED, expected 1 volume but got $vols && status=1 && exit

echo checking 4 volumes created with PCP_LOGIMPORT_MAXLOGSZ=250000
PCP_LOGIMPORT_MAXLOGSZ=250000 collectl2pcp collectl/rhel6.raw.gz $tmp/manyvols
vols=`echo $tmp/manyvols.[0-9]* | wc -w`
[ "$vols" -ne 4 ] && echo manyvols FAILED, expected 14 volumes but got $vols && status=1 && exit

echo check they replay the same, expect no diff
pmrep -a $tmp/onevol -z -p -f%c -t 10s kernel.all.load >$tmp.onevol
pmrep -a $tmp/manyvols -z -p -f%c -t 10s kernel.all.load  | diff - $tmp.onevol || status=1

# success, all done
status=0
exit
