#!/bin/sh
# PCP QA Test No. 521
# pmie unit scale factors and predefined macro tests
#
# Copyright (c) 2012 Ken McDonell.  All Rights Reserved.
#

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

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

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

_filter()
{
    sed \
	-e 's/[A-Z][a-z][a-z] [A-Z][a-z][a-z]  *[0-9][0-9]* [0-9][0-9]:[0-9][0-9]:[0-9][0-9]/DATE/' \
	-e 's/DATE [12][0-9][0-9][0-9]/DATE/' \
	-e '/evaluator exiting/s/pmie([0-9][0-9]*)/pmie(PID)/' \
	-e '/Performance Co-Pilot Inference Engine/s/Version .*/Version .../' \
	-e '/^raw_/d'
}

cat <<'End-of-File' >$tmp.pmie
// scale factors
nanosecond_microsecond = sample.long.hundred * 10nanosecond == 1microsecond;
nanosec_microsec = sample.long.hundred * 10 nanosec == 1 microsec;
nsec_usec = sample.long.hundred * 10nsec == 1usec;
millisecond_second = sample.long.ten * 100millisecond == 1second;
millisec_sec = sample.long.ten * 100 millisec == 1 sec;
msec_min = sample.long.ten * 600msec == 6sec;
second_minute = sample.long.one * 1second == 1minute / 60;
sec_min = sample.long.one * 1 sec == 1 min / 60;
hour_min = sample.long.one * 1 hour == 60 min;
byte_Kbyte = sample.long.one * 1024 byte == 1 Kbyte;
Mbyte_Gbyte = sample.long.one * 1024 Mbyte == 1 Gbyte;
Gbyte_Tbyte = sample.long.one * 1024 Gbyte == 1 Tbyte;
count_Kcount = sample.long.one * 1000 count == 1 Kcount;
Kcount_Mcount = sample.long.one * 1Kcount == 1Mcount/1000;

// predefined macros
raw_minute_macro = $minute;
minute_macro = ($minute >= 00) && ($minute <= 59);
raw_hour_macro = $hour;
hour_macro = ($hour >= 00) && ($hour <= 23);
raw_day_macro = $day;
day_macro = ($day >= 1) && ($day <= 31);
raw_day_of_week_macro = $day_of_week;
day_of_week_macro = ($day_of_week >= 0) && ($day_of_week <= 6);
raw_year_macro = $year;
year_macro = $year > 2012;
raw_delta_macro = $delta;
delta_macro = $delta == 0.5;
End-of-File

# real QA test starts here
pmie -c $tmp.pmie -t 500msec -T900msec -v >$tmp.out 2>$tmp.err

echo "=== pmie output ===" >>$seq.full
cat $tmp.out >>$seq.full
echo >>$seq.full
echo "=== pmie errors ===" >>$seq.full
cat $tmp.err >>$seq.full

_filter <$tmp.err
_filter <$tmp.out

# success, all done
status=0
exit
