#!/bin/sh

# Copyright 2015-2016 Canonical
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# This runs the $1 autopilot suite ensuring that the testbed is configured
# properly

SUITE=$1

set -e

if ! pgrep -f unity-system-compositor ; then
   # We're not using Mir, setup enough of an X stack

   # FIXME: We won't need an X stack once Mir provides mirvfb or any other
   # mean to test consistently on all platforms -- vila 2015-04-22
   sudo -A ADT_NORMAL_USER=${USER} sh -e /usr/share/autopkgtest/setup-commands/ubuntu-touch-session
   # Import the environment produced above in the current shell
   set -a
   . /etc/environment
elif pgrep -f unity8 ; then
   # Work around https://launchpad.net/bugs/1574706
   initctl --session restart unity8
   sleep 20
   gdbus call --session --dest com.canonical.UnityGreeter --object-path / --method com.canonical.UnityGreeter.HideGreeter
fi

autopilot3 run --verbose --format xml --output "${ADT_ARTIFACTS}/${SUITE}.xml" ${SUITE}
