#!/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

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!
trap "_cleanup; exit \$status" 0 1 2 3 15

rm -f $seq.out
if [ -f $seq.out_v$PCP_ARCHIVE_VERSION ]
then
    ln $seq.out_v$PCP_ARCHIVE_VERSION $seq.out
else
    _notrun "no .out for archive version $PCP_ARCHIVE_VERSION"
fi

# 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 temporal index
pmlogcheck $tmp/onevol
pmdumplog -t $tmp/onevol | sed -e 's/^[0-2][0-9]:[^ ]*/TIMESTAMP/'
src/scandata -o -v $tmp/onevol.0 | grep '^\['

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 checking temporal index
pmdumplog -t $tmp/manyvols | sed -e 's/^[0-2][0-9]:[^ ]*/TIMESTAMP/'
pmlogcheck $tmp/manyvols
for i in 0 1 2 3
do
    src/scandata -o -v $tmp/manyvols.$i | grep '^\['
done

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
