#!/bin/sh

EXEC_PROG="/usr/games/gnome-mastermind"

if [ ! -e $EXEC_PROG ]; then
  echo "gnome-mastermind binary not found in /usr/games/"
  exit 1
fi

/usr/bin/xvfb-run -a $EXEC_PROG 2>$AUTOPKGTEST_TMP/err.txt &
sleep 5

# Get PID, match exact to not get 2 PIDs
pidret=`pgrep -xf "$EXEC_PROG"`

if [ ! $pidret ]; then
  echo "$EXEC_PROG process not found"
  exit 1
fi

# Kill processes
kill -9 $pidret

ret=$?

# Check for output to stderr
sizeerr=`wc $AUTOPKGTEST_TMP/err.txt -c | awk '{print $1}'`
if [ $sizeerr -gt 0 ]; then
  echo "Error found"
  cat $AUTOPKGTEST_TMP/err.txt
  exit 1
elif [ $ret = 0 ]; then
  echo "gnome-mastermind opened and closed successfully"
  exit $ret
else
  exit $ret
fi

