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