test/sun/tools/common/ApplicationSetup.sh

Print this page




  26 
  27 # Support functions to start, stop, wait for or kill a given SimpleApplication
  28 
  29 # Starts a given app as background process, usage:
  30 #   startApplication <class> port-file [args...]
  31 #
  32 # The following variables are set:
  33 #
  34 # appJavaPid  - application's Java pid
  35 # appOtherPid - pid associated with the app other than appJavaPid
  36 # appPidList  - all pids associated with the app
  37 # appOutput   - file containing stdout and stderr from the app
  38 #
  39 # Waits for at least one line of output from the app to indicate
  40 # that it is up and running.
  41 #
  42 startApplication()
  43 {
  44   appOutput="${TESTCLASSES}/Application.out"
  45 
  46   ${JAVA} -XX:+UsePerfData -classpath "${TESTCLASSPATH:-${TESTCLASSES}}" "$@" > "$appOutput" 2>&1 &
  47   appJavaPid="$!"
  48   appOtherPid=
  49   appPidList="$appJavaPid"
  50 
  51   echo "INFO: waiting for $1 to initialize..."
  52   _cnt=0
  53   while true; do
  54     # if the app doesn't start then the JavaTest/JTREG timeout will
  55     # kick in so this isn't really a endless loop
  56     sleep 1
  57     out=`tail -1 "$appOutput"`
  58     if [ -n "$out" ]; then
  59       # we got some output from the app so it's running
  60       break
  61     fi
  62     _cnt=`expr $_cnt + 1`
  63     echo "INFO: waited $_cnt second(s) ..."
  64   done
  65   unset _cnt
  66 


 114       exit 2
 115     fi
 116     appPidList="$appOtherPid $appJavaPid"
 117   fi
 118 
 119   echo "INFO: $1 is process $appJavaPid"
 120   echo "INFO: $1 output is in $appOutput"
 121 }
 122 
 123 
 124 # Stops a simple application by invoking ShutdownSimpleApplication
 125 # class with a specific port-file, usage:
 126 #   stopApplication port-file
 127 #
 128 # Note: When this function returns, the SimpleApplication (or a subclass)
 129 # may still be running because the application has not yet reached the
 130 # shutdown check.
 131 #
 132 stopApplication()
 133 {
 134   $JAVA -XX:+UsePerfData -classpath "${TESTCLASSPATH:-${TESTCLASSES}}" ShutdownSimpleApplication $1
 135 }
 136 
 137 
 138 # Wait for a simple application to stop running.
 139 #
 140 waitForApplication() {
 141   if [ $isWindows = false ]; then
 142     # non-Windows is easy; just one process
 143     echo "INFO: waiting for $appJavaPid"
 144     set +e
 145     wait "$appJavaPid"
 146     set -e
 147 
 148   elif $isCygwin; then
 149     # Cygwin pid and not the Windows pid
 150     echo "INFO: waiting for $appOtherPid"
 151     set +e
 152     wait "$appOtherPid"
 153     set -e
 154 




  26 
  27 # Support functions to start, stop, wait for or kill a given SimpleApplication
  28 
  29 # Starts a given app as background process, usage:
  30 #   startApplication <class> port-file [args...]
  31 #
  32 # The following variables are set:
  33 #
  34 # appJavaPid  - application's Java pid
  35 # appOtherPid - pid associated with the app other than appJavaPid
  36 # appPidList  - all pids associated with the app
  37 # appOutput   - file containing stdout and stderr from the app
  38 #
  39 # Waits for at least one line of output from the app to indicate
  40 # that it is up and running.
  41 #
  42 startApplication()
  43 {
  44   appOutput="${TESTCLASSES}/Application.out"
  45 
  46   ${JAVA} ${TESTVMOPTS} ${TESTJAVAOPTS} -XX:+UsePerfData -classpath "${TESTCLASSPATH:-${TESTCLASSES}}" "$@" > "$appOutput" 2>&1 &
  47   appJavaPid="$!"
  48   appOtherPid=
  49   appPidList="$appJavaPid"
  50 
  51   echo "INFO: waiting for $1 to initialize..."
  52   _cnt=0
  53   while true; do
  54     # if the app doesn't start then the JavaTest/JTREG timeout will
  55     # kick in so this isn't really a endless loop
  56     sleep 1
  57     out=`tail -1 "$appOutput"`
  58     if [ -n "$out" ]; then
  59       # we got some output from the app so it's running
  60       break
  61     fi
  62     _cnt=`expr $_cnt + 1`
  63     echo "INFO: waited $_cnt second(s) ..."
  64   done
  65   unset _cnt
  66 


 114       exit 2
 115     fi
 116     appPidList="$appOtherPid $appJavaPid"
 117   fi
 118 
 119   echo "INFO: $1 is process $appJavaPid"
 120   echo "INFO: $1 output is in $appOutput"
 121 }
 122 
 123 
 124 # Stops a simple application by invoking ShutdownSimpleApplication
 125 # class with a specific port-file, usage:
 126 #   stopApplication port-file
 127 #
 128 # Note: When this function returns, the SimpleApplication (or a subclass)
 129 # may still be running because the application has not yet reached the
 130 # shutdown check.
 131 #
 132 stopApplication()
 133 {
 134   $JAVA ${TESTVMOPTS} ${TESTJAVAOPTS} -XX:+UsePerfData -classpath "${TESTCLASSPATH:-${TESTCLASSES}}" ShutdownSimpleApplication $1
 135 }
 136 
 137 
 138 # Wait for a simple application to stop running.
 139 #
 140 waitForApplication() {
 141   if [ $isWindows = false ]; then
 142     # non-Windows is easy; just one process
 143     echo "INFO: waiting for $appJavaPid"
 144     set +e
 145     wait "$appJavaPid"
 146     set -e
 147 
 148   elif $isCygwin; then
 149     # Cygwin pid and not the Windows pid
 150     echo "INFO: waiting for $appOtherPid"
 151     set +e
 152     wait "$appOtherPid"
 153     set -e
 154