#!/bin/sh

cd "$(dirname $0)" || exit $?
for f in *.vgtest
do
  b="${f%.vgtest}"
  if [ ${b%_xml} != $b ]; then
    continue
  fi
  echo === $b
  prereq="$(sed -n 's/^prereq: //p' $f)"
  if [ "$prereq" = "" ]; then
    prereq="true"
  fi
  prog="$(sed -n 's/^prog: //p' $f)"
  args="$(sed -n 's/^args: //p' $f)"
  vgopts="$(sed -n 's/^vgopts: //p' $f)"
  if eval $prereq; then
    ../../vg-in-place --tool=drd --xml=yes --xml-file="$b-%q{USER}.xml" --xml-user-comment="<runBy>$(basename $0)</runBy>" --child-silent-after-fork=yes --gen-suppressions=all $vgopts ./$prog $args
    xmllint --noout --schema ../docs/drd-xml-output.xsd $b-${USER}.xml 2>&1 | tee $b.xmllint
  else
    echo "Skipping because $prereq failed"
  fi
done
