#!/bin/sh
# PCP QA Test No. 926
# Exercise the ganglia2pcp utility
#
# PCP_ARCHIVE_VERSION V2 variant, see 1411 for the V3 variant.
#
# Copyright (c) 2015 Martins Innus.  All Rights Reserved.
#
# The test archives are machine specific. If a set of 
# files for your architecture is not present, please: 
#
# cd  qa/ganglia && mk-gangliatest
#
# and submit the results.

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

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

which ganglia2pcp >/dev/null 2>&1
[ $? -eq 0 ] || _notrun "ganglia2pcp not installed"

perl -e "use Date::Parse" >/dev/null 2>&1
[ $? -eq 0 ] || _notrun "perl Date::Parse module not installed"

perl -e "use Date::Format" >/dev/null 2>&1
[ $? -eq 0 ] || _notrun "perl Date::Format module not installed"

perl -e "use RRDs" >/dev/null 2>&1
[ $? -eq 0 ] || _notrun "perl RRDs module not installed"

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

# We used to use uname -m to pick the right ganglia file, but
# this does not work in CI where the container "architecture" and
# the base platform architecture may not be the same
# The sizeof(void *) seem safer, which is what src/sizeof reports.
#
uname -a >>$seq.full
src/sizeof int long ptr >>$seq.full

rm -f $seq.out
eval `src/sizeof ptr`
case "$ptr"
in
4)
    machine=32
    ;;
8)
    machine=64
    ;;
esac
[ -f $seq.out.$machine ] || \
	_notrun No qualified output for ptr=$ptr architecture. Please run mk-gangliatest and submit the new files.
ln $seq.out.$machine $seq.out || exit 1

# real QA test starts here
# only one dir for now, add more if we get more sample data
# rrdtool can't read data from different architectures

indir=./ganglia/gangliatest.$machine

echo
echo "=== $indir ==="
rm -f $tmp.0 $tmp.index $tmp.meta
outfile=`basename $tmp`
outdir=`dirname $tmp`
ganglia2pcp  -V2 -s "Feb 10 12:00:00 UTC 2015" -e "Feb 12 12:00:00 UTC 2015" -f $outfile -d $outdir -Z UTC $indir

if [ -f $tmp.0 ]
then
    pmdumplog -z -dilmst $tmp
fi

# success, all done
exit

