jdk/test/sun/tools/common/CommonTests.sh
changeset 28418 7593914c0304
parent 28405 53e900131e21
parent 28417 0cef041bf4fc
child 28419 361e3aa27cb5
equal deleted inserted replaced
28405:53e900131e21 28418:7593914c0304
     1 #!/bin/sh
       
     2 
       
     3 #
       
     4 # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
       
     5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     6 #
       
     7 # This code is free software; you can redistribute it and/or modify it
       
     8 # under the terms of the GNU General Public License version 2 only, as
       
     9 # published by the Free Software Foundation.
       
    10 #
       
    11 # This code is distributed in the hope that it will be useful, but WITHOUT
       
    12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14 # version 2 for more details (a copy is included in the LICENSE file that
       
    15 # accompanied this code).
       
    16 #
       
    17 # You should have received a copy of the GNU General Public License version
       
    18 # 2 along with this work; if not, write to the Free Software Foundation,
       
    19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20 #
       
    21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22 # or visit www.oracle.com if you need additional information or have any
       
    23 # questions.
       
    24 #
       
    25 
       
    26 
       
    27 # @test
       
    28 # @bug 6964018
       
    29 # @summary Unit test for common tools infrastructure.
       
    30 #
       
    31 # @build SimpleApplication SleeperApplication ShutdownSimpleApplication
       
    32 # @run shell CommonTests.sh
       
    33 
       
    34 . ${TESTSRC}/CommonSetup.sh
       
    35 . ${TESTSRC}/ApplicationSetup.sh
       
    36 
       
    37 # hope for the best:
       
    38 status=0
       
    39 
       
    40 
       
    41 # Test program path constants from CommonSetup.sh:
       
    42 #
       
    43 for name in JAVA JHAT JINFO JMAP JPS JSTACK; do
       
    44     eval value=$`echo $name`
       
    45 
       
    46     echo "INFO: $name=$value"
       
    47     if [ -x "$value" ]; then
       
    48         echo "INFO: '$value' is executable."
       
    49     else
       
    50         echo "ERROR: '$value' is not executable." >&2
       
    51         status=1
       
    52     fi
       
    53 done
       
    54 
       
    55 
       
    56 # Display flag values from CommonSetup.sh:
       
    57 #
       
    58 for name in isCygwin isMKS isLinux isSolaris isUnknownOS isWindows; do
       
    59     eval value=$`echo $name`
       
    60     echo "INFO: flag $name=$value"
       
    61 done
       
    62 
       
    63 
       
    64 # Test OS constant from CommonSetup.sh:
       
    65 #
       
    66 if [ -z "$OS" ]; then
       
    67     echo "ERROR: OS constant cannot be empty." >&2
       
    68     status=1
       
    69 fi
       
    70 
       
    71 
       
    72 # Display the PATTERN_EOL value:
       
    73 #
       
    74 echo "INFO: PATTERN_EOL="`echo "$PATTERN_EOL" | od -c`
       
    75 
       
    76 
       
    77 # Test PATTERN_EOL with 'grep' for a regular line.
       
    78 #
       
    79 TESTOUT="${TESTCLASSES}/testout.grep_reg_line_eol"
       
    80 set +e
       
    81 echo 'regular line' | grep "line${PATTERN_EOL}" > "$TESTOUT"
       
    82 set -e
       
    83 if [ -s "$TESTOUT" ]; then
       
    84     echo "INFO: PATTERN_EOL works for regular line with grep."
       
    85 else
       
    86     echo "ERROR: PATTERN_EOL does not work for regular line with grep." >&2
       
    87     status=1
       
    88 fi
       
    89 
       
    90 
       
    91 if $isWindows; then
       
    92     # Test PATTERN_EOL with 'grep' for a CR line.
       
    93     #
       
    94     TESTOUT="${TESTCLASSES}/testout.grep_cr_line_eol"
       
    95     set +e
       
    96     echo 'CR line
       
    97 ' | grep "line${PATTERN_EOL}" > "$TESTOUT"
       
    98     set -e
       
    99     if [ -s "$TESTOUT" ]; then
       
   100         echo "INFO: PATTERN_EOL works for CR line with grep."
       
   101     else
       
   102         echo "ERROR: PATTERN_EOL does not work for CR line with grep." >&2
       
   103         status=1
       
   104     fi
       
   105 fi
       
   106 
       
   107 
       
   108 # Test PATTERN_EOL with 'sed' for a regular line.
       
   109 #
       
   110 TESTOUT="${TESTCLASSES}/testout.sed_reg_line_eol"
       
   111 echo 'regular line' | sed -n "/line${PATTERN_EOL}/p" > "$TESTOUT"
       
   112 if [ -s "$TESTOUT" ]; then
       
   113     echo "INFO: PATTERN_EOL works for regular line with sed."
       
   114 else
       
   115     echo "ERROR: PATTERN_EOL does not work for regular line with sed." >&2
       
   116     status=1
       
   117 fi
       
   118 
       
   119 
       
   120 if $isWindows; then
       
   121     # Test PATTERN_EOL with 'sed' for a CR line.
       
   122     #
       
   123     TESTOUT="${TESTCLASSES}/testout.sed_cr_line_eol"
       
   124     echo 'CR line
       
   125 ' | sed -n "/line${PATTERN_EOL}/p" > "$TESTOUT"
       
   126     if [ -s "$TESTOUT" ]; then
       
   127         echo "INFO: PATTERN_EOL works for CR line with sed."
       
   128     else
       
   129         echo "ERROR: PATTERN_EOL does not work for CR line with sed." >&2
       
   130         status=1
       
   131     fi
       
   132 fi
       
   133 
       
   134 
       
   135 # Display the PATTERN_WS value:
       
   136 #
       
   137 echo "INFO: PATTERN_WS="`echo "$PATTERN_WS" | od -c`
       
   138 
       
   139 
       
   140 # Test PATTERN_WS with 'grep' for a blank.
       
   141 #
       
   142 TESTOUT="${TESTCLASSES}/testout.grep_blank"
       
   143 set +e
       
   144 echo 'blank: ' | grep "$PATTERN_WS" > "$TESTOUT"
       
   145 set -e
       
   146 if [ -s "$TESTOUT" ]; then
       
   147     echo "INFO: PATTERN_WS works for blanks with grep."
       
   148 else
       
   149     echo "ERROR: PATTERN_WS does not work for blanks with grep." >&2
       
   150     status=1
       
   151 fi
       
   152 
       
   153 
       
   154 # Test PATTERN_WS with 'grep' for a tab.
       
   155 #
       
   156 TESTOUT="${TESTCLASSES}/testout.grep_tab"
       
   157 set +e
       
   158 echo 'tab:	' | grep "$PATTERN_WS" > "$TESTOUT"
       
   159 set -e
       
   160 if [ -s "$TESTOUT" ]; then
       
   161     echo "INFO: PATTERN_WS works for tabs with grep."
       
   162 else
       
   163     echo "ERROR: PATTERN_WS does not work for tabs with grep." >&2
       
   164     status=1
       
   165 fi
       
   166 
       
   167 
       
   168 # Test PATTERN_WS with 'sed' for a blank.
       
   169 #
       
   170 TESTOUT="${TESTCLASSES}/testout.sed_blank"
       
   171 echo 'blank: ' | sed -n "/$PATTERN_WS/p" > "$TESTOUT"
       
   172 if [ -s "$TESTOUT" ]; then
       
   173     echo "INFO: PATTERN_WS works for blanks with sed."
       
   174 else
       
   175     echo "ERROR: PATTERN_WS does not work for blanks with sed." >&2
       
   176     status=1
       
   177 fi
       
   178 
       
   179 
       
   180 # Test PATTERN_WS with 'sed' for a tab.
       
   181 #
       
   182 TESTOUT="${TESTCLASSES}/testout.sed_tab"
       
   183 echo 'tab:	' | sed -n "/$PATTERN_WS/p" > "$TESTOUT"
       
   184 if [ -s "$TESTOUT" ]; then
       
   185     echo "INFO: PATTERN_WS works for tabs with sed."
       
   186 else
       
   187     echo "ERROR: PATTERN_WS does not work for tabs with sed." >&2
       
   188     status=1
       
   189 fi
       
   190 
       
   191 
       
   192 # Test startApplication and use PORTFILE for coordination
       
   193 # The app sleeps for 30 seconds.
       
   194 #
       
   195 PORTFILE="${TESTCLASSES}"/shutdown.port
       
   196 startApplication SleeperApplication "${PORTFILE}" 30
       
   197 
       
   198 
       
   199 # Test appJavaPid in "ps" cmd output.
       
   200 #
       
   201 TESTOUT="${TESTCLASSES}/testout.ps_app"
       
   202 set +e
       
   203 if $isCygwin; then
       
   204     # On Cygwin, appJavaPid is the Windows pid for the Java process
       
   205     # and appOtherPid is the Cygwin pid for the Java process.
       
   206     ps -p "$appOtherPid" \
       
   207         | grep "${PATTERN_WS}${appJavaPid}${PATTERN_WS}" > "$TESTOUT"
       
   208 else
       
   209     # output only pid and comm columns to avoid mismatches
       
   210     ps -eo pid,comm \
       
   211         | grep "^${PATTERN_WS}*${appJavaPid}${PATTERN_WS}" > "$TESTOUT"
       
   212 fi
       
   213 set -e
       
   214 if [ -s "$TESTOUT" ]; then
       
   215     echo "INFO: begin appJavaPid=$appJavaPid in 'ps' cmd output:"
       
   216     cat "$TESTOUT"
       
   217     echo "INFO: end appJavaPid=$appJavaPid in 'ps' cmd output."
       
   218 else
       
   219     echo "ERROR: 'ps' cmd should show appJavaPid=$appJavaPid." >&2
       
   220     status=1
       
   221 fi
       
   222 
       
   223 if [ -n "$appOtherPid" ]; then
       
   224     # Test appOtherPid in "ps" cmd output, if we have one.
       
   225     #
       
   226     TESTOUT="${TESTCLASSES}/testout.ps_other"
       
   227     set +e
       
   228     if $isCygwin; then
       
   229         ps -p "$appOtherPid" \
       
   230             | grep "${PATTERN_WS}${appOtherPid}${PATTERN_WS}" > "$TESTOUT"
       
   231     else
       
   232         # output only pid and comm columns to avoid mismatches
       
   233         ps -eo pid,comm \
       
   234             | grep "^${PATTERN_WS}*${appOtherPid}${PATTERN_WS}" > "$TESTOUT"
       
   235     fi
       
   236     set -e
       
   237     if [ -s "$TESTOUT" ]; then
       
   238         echo "INFO: begin appOtherPid=$appOtherPid in 'ps' cmd output:"
       
   239         cat "$TESTOUT"
       
   240         echo "INFO: end appOtherPid=$appOtherPid in 'ps' cmd output."
       
   241     else
       
   242         echo "ERROR: 'ps' cmd should show appOtherPid=$appOtherPid." >&2
       
   243         status=1
       
   244     fi
       
   245 fi
       
   246 
       
   247 
       
   248 # Test stopApplication and PORTFILE for coordination
       
   249 #
       
   250 stopApplication "${PORTFILE}"
       
   251 
       
   252 
       
   253 # Test application still running after stopApplication.
       
   254 #
       
   255 # stopApplication just lets the app know that it can stop, but the
       
   256 # app might still be doing work. This test just demonstrates that
       
   257 # fact and doesn't fail if the app is already done.
       
   258 #
       
   259 TESTOUT="${TESTCLASSES}/testout.after_stop"
       
   260 set +e
       
   261 if $isCygwin; then
       
   262     # On Cygwin, appJavaPid is the Windows pid for the Java process
       
   263     # and appOtherPid is the Cygwin pid for the Java process.
       
   264     ps -p "$appOtherPid" \
       
   265         | grep "${PATTERN_WS}${appJavaPid}${PATTERN_WS}" > "$TESTOUT"
       
   266 else
       
   267     # output only pid and comm columns to avoid mismatches
       
   268     ps -eo pid,comm \
       
   269         | grep "^${PATTERN_WS}*${appJavaPid}${PATTERN_WS}" > "$TESTOUT"
       
   270 fi
       
   271 set -e
       
   272 if [ -s "$TESTOUT" ]; then
       
   273     echo "INFO: it is okay for appJavaPid=$appJavaPid to still be running" \
       
   274         "after stopApplication() is called."
       
   275     echo "INFO: begin 'after_stop' output:"
       
   276     cat "$TESTOUT"
       
   277     echo "INFO: end 'after_stop' output."
       
   278 fi
       
   279 
       
   280 
       
   281 # Test waitForApplication
       
   282 #
       
   283 # The app might already be gone so this function shouldn't generate
       
   284 # a fatal error in either call.
       
   285 #
       
   286 waitForApplication
       
   287 
       
   288 if [ $isWindows = false ]; then
       
   289     # Windows can recycle pids quickly so we can't use this test there
       
   290     TESTOUT="${TESTCLASSES}/testout.after_kill"
       
   291     set +e
       
   292     # output only pid and comm columns to avoid mismatches
       
   293     ps -eo pid,comm \
       
   294         | grep "^${PATTERN_WS}*${appJavaPid}${PATTERN_WS}" > "$TESTOUT"
       
   295     set -e
       
   296     if [ -s "$TESTOUT" ]; then
       
   297         echo "ERROR: 'ps' cmd should not show appJavaPid." >&2
       
   298         echo "ERROR: begin 'after_kill' output:" >&2
       
   299         cat "$TESTOUT" >&2
       
   300         echo "ERROR: end 'after_kill' output." >&2
       
   301         status=1
       
   302     else
       
   303         echo "INFO: 'ps' cmd does not show appJavaPid after" \
       
   304             "waitForApplication() is called."
       
   305     fi
       
   306 fi
       
   307 
       
   308 
       
   309 # Test killApplication
       
   310 #
       
   311 # The app is already be gone so this function shouldn't generate
       
   312 # a fatal error.
       
   313 #
       
   314 killApplication
       
   315 
       
   316 exit $status