#!/bin/bash
#/////////////////////////////////////////////////////////////////////////
#//
#// (c) University of Southampton IT Innovation Centre, 2017
#//
#// Copyright in this software belongs to University of Southampton
#// IT Innovation Centre of Gamma House, Enterprise Road,
#// Chilworth Science Park, Southampton, SO16 7NS, UK.
#//
#// This software may not be used, sold, licensed, transferred, copied
#// or reproduced in whole or in part in any manner or form or in or
#// on any media by any person other than in accordance with the terms
#// of the Licence Agreement supplied with the software, or otherwise
#// without the prior written consent of the copyright owners.
#//
#// This software is distributed WITHOUT ANY WARRANTY, without even the
#// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
#// PURPOSE, except where stated in the Licence Agreement supplied with
#// the software.
#//
#//      Created By :            Michael Boniface
#//      Created Date :          15/02/2017
#//      Created for Project :   FLAME
#//
#/////////////////////////////////////////////////////////////////////////

if [ "$#" -ne 3 ]; then
    echo "Error: illegal number of arguments: "$#
      echo "Usage: run.sh TEST_RUN_DIR STREAM_URI MAX_CLIENTS"
      exit 
fi

# create test directories
TEST_FOLDER=$(date +%Y%m%d%H%M%S)
TEST_RUN_DIR=$1
TEST_DIR=$TEST_RUN_DIR"/streaming/"$TEST_FOLDER
echo "Test directory: "$TEST_DIR
mkdir -p  "$TEST_DIR"

# run testplan
cd $TEST_DIR

#jmeter -n -LDEBUG -t /vagrant/test/streaming/testplan.jmx -l results.jtx -j jmeter.log

# quick bash equivalent in case Jmeter fails
STREAM_URI=$2
COUNTER=0
MAX_CLIENTS=$3
while [  $COUNTER -lt $MAX_CLIENTS ]; do
  cvlc -Vdummy --no-audio $STREAM_URI &>$TEST_DIR/stdout$COUNTER &
 # cvlc -Vdummy --no-audio --verbose=0 --file-logging --logfile=$TEST_DIR/vlc-log$COUNTER.txt $STREAM_URI &
  sleep 1
  let COUNTER=COUNTER+1 
done



