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