1 #!/bin/ksh -p
   2 #
   3 # Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
   4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5 #
   6 # This code is free software; you can redistribute it and/or modify it
   7 # under the terms of the GNU General Public License version 2 only, as
   8 # published by the Free Software Foundation.
   9 #
  10 # This code is distributed in the hope that it will be useful, but WITHOUT
  11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13 # version 2 for more details (a copy is included in the LICENSE file that
  14 # accompanied this code).
  15 #
  16 # You should have received a copy of the GNU General Public License version
  17 # 2 along with this work; if not, write to the Free Software Foundation,
  18 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19 #
  20 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21 # or visit www.oracle.com if you need additional information or have any
  22 # questions.
  23 #
  24 
  25 #
  26 #   @test
  27 #   @bug        4929170 7078379
  28 #   @summary    Tests that user-supplied IIOMetadata implementations 
  29 #                loaded by separate classloader in separate thread  
  30 #                is able to load correspnding IIOMetadataFormat 
  31 #                implementations.
  32 #   @author     Andrew Brygin
  33 #
  34 #   @compile    UserPluginMetadataFormatTest.java MetadataFormatThreadTest.java MetadataTest.java
  35 #   @run shell/timeout=60 runMetadataFormatThreadTest.sh
  36 
  37 # Note!!!! JavaCodeForYourTest_CHANGE_THIS.java must be changed or deleted.  
  38 # If there is any java code which will be executed during the test, it must 
  39 # be compiled by the line above.  If multiple .java files, separate the 
  40 # files by spaces on that line.  See testing page of AWT home page for
  41 # pointers to the testharness spec. and FAQ.
  42 # Note!!!! Change AppletDeadlock.sh to the name of your test!!!!
  43 
  44 # There are several resources which need to be present before many 
  45 #  shell scripts can run.  Following are examples of how to check for
  46 #  many common ones.
  47 # 
  48 # Note that the shell used is the Korn Shell, KSH
  49 #
  50 # Also note, it is recommended that make files NOT be used.  Rather,
  51 #  put the individual commands directly into this file.  That way,
  52 #  it is possible to use command line arguments and other shell tech-
  53 #  niques to find the compiler, etc on different systems.  For example,
  54 #  a different path could be used depending on whether this were a
  55 #  Solaris or Win32 machine, which is more difficult (if even possible)
  56 #  in a make file.  
  57 
  58 
  59 # Beginning of subroutines:
  60 status=1
  61 
  62 #Call this from anywhere to fail the test with an error message
  63 # usage: fail "reason why the test failed"
  64 fail() 
  65  { echo "The test failed :-("
  66    echo "$*" 1>&2
  67    exit 1
  68  } #end of fail()
  69 
  70 #Call this from anywhere to pass the test with a message
  71 # usage: pass "reason why the test passed if applicable"
  72 pass() 
  73  { echo "The test passed!!!"
  74    echo "$*" 1>&2
  75    exit 0
  76  } #end of pass()
  77 
  78 # end of subroutines
  79 
  80 
  81 # The beginning of the script proper
  82 
  83 # Checking for proper OS
  84 OS=`uname -s`
  85 case "$OS" in
  86    Linux | Darwin | AIX )
  87       VAR="A different value for Linux"
  88       DEFAULT_JDK=/none
  89       #DEFAULT_JDK=/usr/local/java/jdk1.4/linux-i386
  90       FILESEP="/"
  91       ;;
  92 
  93    Windows_95 | Windows_98 | Windows_NT | Windows_ME )
  94       VAR="A different value for Win32"
  95       DEFAULT_JDK=/none
  96       #DEFAULT_JDK=/usr/local/java/jdk1.2/win32
  97       FILESEP="\\"
  98       ;;
  99     
 100     CYGWIN* )
 101       VAR="A different value for CYGWIN"
 102       DEFAULT_JDK=/none
 103       FILESEP="/"
 104       ;;
 105 
 106    # catch all other OSs
 107    * )
 108       echo "Unrecognized system!  $OS"
 109       fail "Unrecognized system!  $OS"
 110       ;;
 111 esac
 112 
 113 # check that some executable or other file you need is available, abort if not
 114 #  note that the name of the executable is in the fail string as well.
 115 # this is how to check for presence of the compiler, etc.
 116 #RESOURCE=`whence SomeProgramOrFileNeeded`
 117 #if [ "${RESOURCE}" = "" ] ; 
 118 #   then fail "Need SomeProgramOrFileNeeded to perform the test" ; 
 119 #fi
 120 
 121 # IT'S FINE TO DELETE THIS IF NOT NEEDED!
 122 # check if an environment variable you need is set, give it a default if not
 123 #if [ -z "${NEEDED_VAR}" ] ; then
 124 #   # The var is NOT set, so give it a default
 125 #   NEEDED_VAR=/some/default/value/such/as/a/path
 126 #fi
 127 
 128 # IT'S FINE TO DELETE THIS IF NOT NEEDED!
 129 #if [ -z "${NEEDED_LATER_VAR}" ] ; then
 130 #   # The var is NOT set, so give it a default
 131 #   # will need it in other scripts called from this one, so export it
 132 #   NEEDED_LATER_VAR="/a/different/path/note/the/quotes"
 133 #   export NEEDED_LATER_VAR
 134 #fi
 135 
 136 # Want this test to run standalone as well as in the harness, so do the 
 137 #  following to copy the test's directory into the harness's scratch directory 
 138 #  and set all appropriate variables:
 139 
 140 if [ -z "${TESTJAVA}" ] ; then
 141    # TESTJAVA is not set, so the test is running stand-alone.
 142    # TESTJAVA holds the path to the root directory of the build of the JDK
 143    # to be tested.  That is, any java files run explicitly in this shell
 144    # should use TESTJAVA in the path to the java interpreter.
 145    # So, we'll set this to the JDK spec'd on the command line.  If none
 146    # is given on the command line, tell the user that and use a cheesy
 147    # default.
 148    # THIS IS THE JDK BEING TESTED.
 149    if [ -n "$1" ] ;
 150       then TESTJAVA=$1
 151       else echo "no JDK specified on command line so using default!"
 152          TESTJAVA=$DEFAULT_JDK
 153    fi
 154    TESTSRC=.
 155    TESTCLASSES=.
 156    STANDALONE=1;
 157 fi
 158 echo "JDK under test is: $TESTJAVA"
 159 
 160 #Deal with .class files:
 161 if [ -n "${STANDALONE}" ] ; 
 162    then 
 163    #if standalone, remind user to cd to dir. containing test before running it
 164    echo "Just a reminder: cd to the dir containing this test when running it"
 165    # then compile all .java files (if there are any) into .class files
 166    if [ -a *.java ] ; 
 167       then echo "Reminder, this test should be in its own directory with all"
 168       echo "supporting files it needs in the directory with it."
 169       ${TESTJAVA}/bin/javac ./*.java ; 
 170    fi
 171    # else in harness so copy all the class files from where jtreg put them
 172    # over to the scratch directory this test is running in. 
 173    else cp ${TESTCLASSES}/*.class . ;
 174 fi
 175 
 176 #if in test harness, then copy the entire directory that the test is in over 
 177 # to the scratch directory.  This catches any support files needed by the test.
 178 
 179 #if [ -z "${STANDALONE}" ] ; 
 180 #   then cp ${TESTSRC}/* . 
 181 #fi
 182 
 183 #Just before executing anything, make sure it has executable permission!
 184 chmod 777 ./*
 185 
 186 ###############  YOUR TEST CODE HERE!!!!!!!  #############
 187 
 188 #All files required for the test should be in the same directory with
 189 # this file.  If converting a standalone test to run with the harness,
 190 # as long as all files are in the same directory and it returns 0 for
 191 # pass, you should be able to cut and paste it into here and it will
 192 # run with the test harness.
 193 
 194 # This is an example of running something -- test
 195 # The stuff below catches the exit status of test then passes or fails
 196 # this shell test as appropriate ( 0 status is considered a pass here )
 197 #./test # DELETE THIS LINE AND REPLACE WITH YOUR OWN COMMAND!!!
 198 
 199 if [ -d ./test_classes ] ; then 
 200     rm -rf ./test_calsses
 201 fi
 202 
 203 mkdir ./test_classes
 204  
 205 # split application classes and test plugin classes
 206 mv ./UserPluginMetadataFormatTest*.class ./test_classes
 207 
 208 $TESTJAVA/bin/java ${TESTVMOPTS} \
 209     MetadataFormatThreadTest test_classes UserPluginMetadataFormatTest
 210 
 211 ###############  END YOUR TEST CODE !!!!! ############
 212 status=$?
 213 
 214 # pass or fail the test based on status of the command
 215 if [ $status -eq "0" ];
 216    then pass "Test passed - no stack trace printing"
 217 
 218    else fail "Test failure - stack trace was printed"
 219 fi
 220 
 221 #For additional examples of how to write platform independent KSH scripts,
 222 # see the jtreg file itself.  It is a KSH script for both Solaris and Win32
 223