1 #!/bin/sh
   2 
   3 #
   4 # Copyright (c) 2003, 2013, 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 4673940
  29 # @bug 4930794
  30 # @summary Unit tests for inetd feature
  31 #
  32 # @build StateTest StateTestService EchoTest EchoService CloseTest Launcher Util
  33 # @run shell run_tests.sh
  34 
  35 os=`uname -s`
  36 
  37 if [ "$os" != "Linux" -a "$os" != "SunOS" ]; then
  38     echo "Test not designed to run on this operating system, skipping..."
  39     exit 0
  40 fi
  41 
  42 arch=`uname -p`
  43 if [ "$os" = "SunOS" ]; then
  44     if [ "$arch" = "i386"  -o "$arch" = "sparc" ]; then
  45         echo "Test not designed to run on this operating system, skipping..."
  46         exit 0
  47     fi
  48 fi
  49 
  50 # if TESTJAVA isn't set then we assume an interactive run. So that it's
  51 # clear which version of 'java' is running we do a 'which java' and
  52 # a 'java -version'.
  53 
  54 if [ -z "$TESTJAVA" ]; then
  55     TESTSRC=`pwd`
  56     TESTCLASSES=`pwd`
  57     JAVA=java
  58     which $JAVA
  59     ${JAVA} -d64 -version > /dev/null 2<&1
  60     if [ $? = 1 ]; then
  61         ${JAVA} -version
  62     else
  63         ${JAVA} -d64 -version
  64     fi
  65 else
  66     JAVA="${TESTJAVA}/bin/java"
  67 fi
  68 
  69 CLASSPATH=${TESTCLASSES}
  70 export CLASSPATH
  71 
  72 
  73 # Check that we have libLauncher.so for the right platform.
  74 # On Solaris we assume 64-bit
  75 
  76 DFLAG=
  77 if [ "$os" = "SunOS" ]; then
  78     PLATFORM=solaris
  79     case "`uname -p`" in
  80         i[3-9]86) 
  81             ARCH=amd64
  82             ;;
  83         sparc)
  84             ARCH=sparcv9
  85             ;;
  86     esac 
  87 fi
  88 
  89 if [ "$os" = "Linux" ]; then
  90     PLATFORM=linux
  91     ARCH=unknown
  92     case "`uname -m`" in
  93         i[3-6]86)
  94             ARCH=i586
  95             ;;
  96         ia64)
  97             ARCH=ia64
  98             ;;
  99         x86_64)
 100             ARCH=amd64
 101             ;;
 102     esac
 103 fi
 104 
 105 LIBDIR=lib/${PLATFORM}-${ARCH}
 106 LAUNCHERLIB=${LIBDIR}/libLauncher.so
 107 echo $LIBDIR
 108 
 109 if [ ! -f "${TESTSRC}/${LAUNCHERLIB}" ]; then
 110     echo "Cannot find ${LAUNCHERLIB} - library not available for this system"
 111     exit 0
 112 fi
 113 
 114 LD_LIBRARY_PATH=${TESTSRC}/${LIBDIR}
 115 export LD_LIBRARY_PATH
 116 
 117 failures=0
 118 
 119 go() {
 120     echo ''
 121     sh -xc "$JAVA $DFLAG $1 $2 $3 $4 $5 $6 $7 $8" 2>&1
 122     if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
 123 }
 124 
 125 # Run the tests
 126 
 127 go StateTest
 128 go EchoTest
 129 go CloseTest
 130 
 131 # Re-run StateTest with a SecurityManager set
 132 # Note that the system properties are arguments to StateTest and not options.
 133 # These system properties are passed to the launched service as options:
 134 #   java [-options] class [args...]
 135 
 136 go StateTest -Djava.security.manager -Djava.security.policy=${TESTSRC}/java.policy.pass
 137 go StateTest -expectFail -Djava.security.manager -Djava.security.policy=${TESTSRC}/java.policy.fail
 138 
 139 
 140 #
 141 # Results
 142 #
 143 echo ''
 144 if [ $failures -gt 0 ];
 145   then echo "$failures test(s) failed";
 146   else echo "All test(s) passed"; fi
 147 exit $failures