#!/bin/bash
######################################################################
# Transcoder Selft Test Script 
#
# Author: Shaunt Libarian
# Arguements:
#   -d = device to test. Can be all or specific device
######################################################################

# TEMP patch for NTG ldconfig lib
/sbin/ldconfig /usr/local/nsc/lib

#usage clause
usage="Usage: $0 [ -d {all|eth0|eth1} -c {Capacity}]"

if [ $1 ] && [ $2 ]  
then
  
  while getopts "d" options
  do
    case $options in
      d)
        if [ $2 == "all" ] || [ $2 == "ALL" ];
        then
          #Run self test for all transcoding adapters
          echo "ALL Adapters"
        else  
          #run test on specific transcoder
          export ip=`/sbin/ifconfig $2 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
         
          #Start the test 
          rm -fr /tmp/sng-self-test-transcoding.txt 
		
	  ulimit -n 65000
          nice -n 20 /usr/local/ntg/bin/sngtc_client -bert -timeout 30 -ethdev $2 -bindip $ip -sessions $4 2>&1 | tee /tmp/sng-self-test-transcoding.txt 
          
          rc=${PIPESTATUS[0]}
          if [[ $rc != 0 ]] ; then
                exit $rc
          fi
         
        fi
        ;;
      \?)
        echo $usage >&2
        exit 1
        ;;
      esac
    done
    
else
  echo $usage >&2
  exit 2
fi
