test/sun/tools/common/ApplicationSetup.sh

Print this page




  28 
  29 # Starts a given application as background process, usage:
  30 #   startApplication <class> [args...]
  31 #
  32 # Waits for application to print something to indicate it is running
  33 # (and initialized). Output is directed to ${TESTCLASSES}/Application.out.
  34 # Sets $pid to be the process-id of the application.
  35 
  36 startApplication()
  37 {
  38   OUTPUTFILE=${TESTCLASSES}/Application.out
  39   ${JAVA} $1 $2 $3 $4 $5 $6 > ${OUTPUTFILE} &
  40   pid="$!"
  41                                                                                                      
  42   # MKS creates an intermediate shell to launch ${JAVA} so
  43   # ${pid} is not the actual pid. We have put in a small sleep
  44   # to give the intermediate shell process time to launch the
  45   # "java" process.
  46   if [ "$OS" = "Windows" ]; then
  47     sleep 2



  48     realpid=`ps -o pid,ppid,comm|grep ${pid}|grep "java"|cut -c1-6`

  49     pid=${realpid}
  50   fi
  51                                                                                                      
  52   echo "Waiting for Application to initialize..."
  53   attempts=0
  54   while true; do
  55     sleep 1
  56     out=`tail -1 ${OUTPUTFILE}`
  57     if [ ! -z "$out" ]; then
  58       break
  59     fi
  60     attempts=`expr $attempts + 1`
  61     echo "Waiting $attempts second(s) ..."
  62   done
  63 
  64   echo "Application is process $pid"
  65 }
  66 
  67 # Stops an application by invoking the given class and argument, usage:
  68 #   stopApplication <class> <argument>


  28 
  29 # Starts a given application as background process, usage:
  30 #   startApplication <class> [args...]
  31 #
  32 # Waits for application to print something to indicate it is running
  33 # (and initialized). Output is directed to ${TESTCLASSES}/Application.out.
  34 # Sets $pid to be the process-id of the application.
  35 
  36 startApplication()
  37 {
  38   OUTPUTFILE=${TESTCLASSES}/Application.out
  39   ${JAVA} $1 $2 $3 $4 $5 $6 > ${OUTPUTFILE} &
  40   pid="$!"
  41                                                                                                      
  42   # MKS creates an intermediate shell to launch ${JAVA} so
  43   # ${pid} is not the actual pid. We have put in a small sleep
  44   # to give the intermediate shell process time to launch the
  45   # "java" process.
  46   if [ "$OS" = "Windows" ]; then
  47     sleep 2
  48     if [ "${isCygwin}" = "true" ] ; then
  49       realpid=`ps -p ${pid} | tail -1 | awk '{print $4;}'`
  50     else
  51       realpid=`ps -o pid,ppid,comm|grep ${pid}|grep "java"|cut -c1-6`
  52     fi
  53     pid=${realpid}
  54   fi
  55                                                                                                      
  56   echo "Waiting for Application to initialize..."
  57   attempts=0
  58   while true; do
  59     sleep 1
  60     out=`tail -1 ${OUTPUTFILE}`
  61     if [ ! -z "$out" ]; then
  62       break
  63     fi
  64     attempts=`expr $attempts + 1`
  65     echo "Waiting $attempts second(s) ..."
  66   done
  67 
  68   echo "Application is process $pid"
  69 }
  70 
  71 # Stops an application by invoking the given class and argument, usage:
  72 #   stopApplication <class> <argument>