#!/bin/bash
# Run the vagrant tests

machines=""

# Allow the specific platform to be specified via parameter
if [ ,"$1" = ,"ubuntu" ] ; then
	machines="ubuntu"
elif [ ,"$1" = ,"centos" ] ; then
	machines="centos"
else
	machines="ubuntu centos"
fi

all_test_output=./sdp/alltests.out
if [ -f $all_test_output ] ; then
	rm $all_test_output
fi

echo Running SDP tests
vagrant up > /tmp/sdp-vagrant.out
for machine in $machines
do
	echo $machine>> $all_test_output
	test_output="test-$machine.out"
	vagrant ssh $machine-sdpmaster -c "sudo /p4/reset_sdp.sh" -- -n -T
	vagrant ssh $machine-sdpmaster -c "sudo -u perforce date > /tmp/$test_output" -- -n -T
	vagrant ssh $machine-sdpmaster -c "uname -a >> /tmp/$test_output" -- -n -T
	if [ ,"$machine" = ,"ubuntu" ] ; then
		vagrant ssh $machine-sdpmaster -c "sudo -H -u perforce python3 /p4/test_SDP.py >> /tmp/$test_output 2>&1" -- -n -T
	else
		vagrant ssh $machine-sdpmaster -c "sudo -i -u perforce /usr/local/bin/python3.3 /p4/test_SDP.py >> /tmp/$test_output 2>&1" -- -t -t
	fi
	vagrant ssh $machine-sdpmaster -c "sudo cp /tmp/$test_output /sdp" -- -t -t
	cat ./sdp/$test_output>> $all_test_output
done
cat $all_test_output
