1 #!/bin/ksh -p
   2 
   3 #
   4 # Copyright (c) 2015, 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       EventQueuePushAutoshutdown.sh
  28 #   @bug        8081485
  29 #   @summary    tests that a program terminates automatically
  30 #               after EventQueue.push()
  31 #   @author     Anton Nashatyrev : area=toolkit
  32 #
  33 #   @compile EventQueuePushAutoshutdown.java
  34 #   @run shell EventQueuePushAutoshutdown.sh
  35 
  36 
  37 # Beginning of subroutines:
  38 status=1
  39 
  40 #Call this from anywhere to fail the test with an error message
  41 # usage: fail "reason why the test failed"
  42 fail()
  43  { echo "The test failed :-("
  44    echo "$*" 1>&2
  45    echo "exit status was $status"
  46    exit $status
  47  } #end of fail()
  48 
  49 #Call this from anywhere to pass the test with a message
  50 # usage: pass "reason why the test passed if applicable"
  51 pass()
  52  { echo "The test passed!!!"
  53    echo "$*" 1>&2
  54    exit 0
  55  } #end of pass()
  56 
  57 # end of subroutines
  58 
  59 
  60 # The beginning of the script proper
  61 OS=`uname -s`
  62 case "$OS" in
  63    SunOS | Linux | Darwin | CYGWIN* )
  64       FILESEP="/"
  65       ;;
  66 
  67    Windows_95 | Windows_98 |  Windows_NT | Windows_ME )
  68       FILESEP="\\"
  69       ;;
  70 
  71    # catch all other OSs
  72    * )
  73       echo "Unrecognized system!  $OS"
  74       fail "Unrecognized system!  $OS"
  75       ;;
  76 esac
  77 
  78 
  79 # Want this test to run standalone as well as in the harness, so do the
  80 #  following to copy the test's directory into the harness's scratch directory
  81 #  and set all appropriate variables:
  82 
  83 if [ -z "${TESTJAVA}" ] ; then
  84    # TESTJAVA is not set, so the test is running stand-alone.
  85    # TESTJAVA holds the path to the root directory of the build of the JDK
  86    # to be tested.  That is, any java files run explicitly in this shell
  87    # should use TESTJAVA in the path to the java interpreter.
  88    # So, we'll set this to the JDK spec'd on the command line.  If none
  89    # is given on the command line, tell the user that and use a cheesy
  90    # default.
  91    # THIS IS THE JDK BEING TESTED.
  92    if [ -n "$1" ] ;
  93       then TESTJAVA=$1
  94       else fail "no JDK specified on command line!"
  95    fi
  96    TESTSRC=.
  97    TESTCLASSES=.
  98    STANDALONE=1;
  99 fi
 100 echo "JDK under test is: $TESTJAVA"
 101 
 102 #Deal with .class files:
 103 if [ -n "${STANDALONE}" ] ;
 104    then
 105    #if standalone, remind user to cd to dir. containing test before running it
 106    echo "Just a reminder: cd to the dir containing this test when running it"
 107    # then compile all .java files (if there are any) into .class files
 108    if [ -a *.java ] ;
 109       then echo "Reminder, this test should be in its own directory with all"
 110       echo "supporting files it needs in the directory with it."
 111       ${TESTJAVA}/bin/javac ./*.java ;
 112    fi
 113    # else in harness so copy all the class files from where jtreg put them
 114    # over to the scratch directory this test is running in.
 115    else cp ${TESTCLASSES}/*.class . ;
 116 fi
 117 
 118 #if in test harness, then copy the entire directory that the test is in over
 119 # to the scratch directory.  This catches any support files needed by the test.
 120 if [ -z "${STANDALONE}" ] ;
 121    then cp ${TESTSRC}/* .
 122 fi
 123 
 124 #Just before executing anything, make sure it has executable permission!
 125 chmod 777 ./*
 126 
 127 ###############  YOUR TEST CODE HERE!!!!!!!  #############
 128 
 129 #All files required for the test should be in the same directory with
 130 # this file.  If converting a standalone test to run with the harness,
 131 # as long as all files are in the same directory and it returns 0 for
 132 # pass, you should be able to cut and paste it into here and it will
 133 # run with the test harness.
 134 
 135 ${TESTJAVA}/bin/java EventQueuePushAutoshutdown
 136 
 137 ###############  END YOUR TEST CODE !!!!! ############
 138 #Be sure the last command executed above this line returns 0 for success,
 139 # something non-zero for failure.
 140 status=$?
 141 
 142 # pass or fail the test based on status of the command
 143 case "$status" in
 144    0 )
 145       pass ""
 146       ;;
 147 
 148    1 )
 149       fail "The program didn't automatically shut down"
 150       ;;
 151 
 152    * )
 153       fail "The program terminated unexpectedly!"
 154       ;;
 155 esac
 156 
 157 #For additional examples of how to write platform independent KSH scripts,
 158 # see the jtreg file itself.  It is a KSH script for both Solaris and Win32