#!/bin/sh

check(){
  if [ "`head -1 $1 2>/dev/null | cut -d "=" -f 1 2>/dev/null`" != "startup" ]; then
    echo "'$1' does not appear to be an ltp results file in tabular ASCII format"
    exit 1
  fi
}

process(){
  sed -e 's/startup=.*//' -e 's/\(stime\|dur\|cu\|cs\)=[^ ]*//g' -e 's/ \+/ /g' $1 > $2
}

if [ -z "$1" -o -z "$2" ]; then
  echo "usage $0 <first_result> <second_result>"
  exit 1
fi

check $1
check $2

TMP1=`mktemp /tmp/results.XXXXXXXXXX`
TMP2=`mktemp /tmp/results.XXXXXXXXXX`

process $1 $TMP1
process $2 $TMP2

diff $TMP1 $TMP2
RESULT=$?
if [ "$RESULT" == 0 ]; then
  echo "No differences in test results"
fi
rm $TMP1 $TMP2
exit $RESULT
