summaryrefslogtreecommitdiff
path: root/jtreg/linux/bin/jtreg-lava
blob: 05ed12f1d09a5035be78f4da3dd5768b2c94fb22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/sh

#
# Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.  Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#

# !!!!! This script provides an alternate entry point into JavaTest.  It directs
# !!!!! JavaTest to use a highly customized script and test finder.  It is an
# !!!!! example of how to extend JavaTest to run using specific environments
# !!!!! and properties for test suites using procedural test descriptions.
# !!!!!
# !!!!! "jtreg" does not run JCK-style tests.  Please refer to the "javatest"
# !!!!! script to run the JCK or testsuites following the JCK style.

# Usage:
#    jtreg ...args....
#	Run the application via the regression test-suite front end
#	with the given arguments.
#	The Java runtime used to run JavaTest is found as follows:
#	-   $JT_JAVA is used, if it is set
#       -   Otherwise, $JAVA_HOME/bin/java is used if $JAVA_HOME is set
#           (cf JDK.)
#	-   Otherwise, "java" is used
#
# jtreg requires a version of Java equivalent to JDK 1.5.0 or higher.

# $JT_HOME can be used to specify the jtreg installation directory
#   (e.g. /usr/local/java/jct-tools/3.2.2)
#
# $JT_JAVA is used to specify the version of java to use when running JavaTest
#   (e.g. /usr/local/java/jdk1.5.0/solaris-sparc/bin/java)
#
# You can also run the jar file directly, as in
#   java -jar <path>/lib/jtreg.jar ...args...
# 
# jtreg also provides Ant tasks; see the online help for details.
# E.g.  jtreg -onlineHelp ant

# Determine jtreg/JavaTest installation directory
if [ -z "$JT_HOME" ]; then
    # Deduce where script is installed
    # - should work on most derivatives of Bourne shell, like ash, bash, ksh,
    #   sh, zsh, etc, including on Windows, MKS (ksh) and Cygwin (ash or bash)
    if type -p type 1>/dev/null 2>&1 && test -z "`type -p type`" ; then
        myname=`type -p "$0"`
    elif type type 1>/dev/null 2>&1 ; then
        myname=`type "$0" | sed -e 's/^.* is a tracked alias for //' -e 's/^.* is //'`
    elif whence whence 1>/dev/null 2>&1 ; then
        myname=`whence "$0"`
    fi 
    mydir=`dirname "$myname"`
    p=`cd "$mydir" ; pwd`
    while [ -n "$p" -a "$p" != "/" ]; do
        if [ -r "$p"/lib/jtreg.jar ]; then JT_HOME="$p" ; break; fi
        p=`dirname "$p"`
    done
    if [ -z "$JT_HOME" ]; then
        echo "Cannot determine JT_HOME; please set it explicitly"; exit 1
    fi
    case "`uname -s`" in
        CYGWIN* ) JT_HOME=`cygpath -m "$JT_HOME"` ;;
    esac
fi


# Separate out -J* options for the JVM
# Note jdk as possible default to run jtreg
# Unset IFS and use newline as arg separator to preserve spaces in args
DUALCASE=1  # for MKS: make case statement case-sensitive (6709498)
saveIFS="$IFS"
nl='
'
work_dir=
for i in "$@" ; do
    IFS=
    case $i in 
    -jdk:* )    jdk="`echo $i | sed -e 's/^-jdk://'`"
                jtregOpts=$jtregOpts$nl$i ;;
    -J* )       javaOpts=$javaOpts$nl`echo $i | sed -e 's/^-J//'` ;;
    -agentvm)   jtregOpts=$jtregOpts$nl'-samevm' ;;
    -w:* )      work_dir=`echo $i | sed -e 's/^-w:\(.*\)/\1/'`; jtregOpts=$jtregOpts$nl$i ;;
    -timeoutFactor:4 ) jtregOpts=$jtregOpts$nl'-timeoutFactor:15' ;;
    *   )       jtregOpts=$jtregOpts$nl$i ;;
    esac
    IFS="$saveIFS"
done
unset DUALCASE

# Determine java for jtreg, from JT_JAVA, JAVA_HOME, jdk, java
if [ -n "$JT_JAVA" ]; then
    if [ -d "$JT_JAVA" ]; then 
        JT_JAVA="$JT_JAVA/bin/java" 
    fi
elif [ -n "$JAVA_HOME" ]; then 
    JT_JAVA="$JAVA_HOME/bin/java"
elif [ -n "$jdk" ]; then
    JT_JAVA="$jdk/bin/java"
else
    JT_JAVA=java
fi

# Verify java version (1.)5 or newer used to run jtreg
version=`"$JT_JAVA" -classpath "${JT_HOME}/lib/jtreg.jar" com.sun.javatest.regtest.GetSystemProperty java.version 2>&1 | 
        grep 'java.version=' | sed -e 's/^.*=//' -e 's/^1\.//' -e 's/\([1-9][0-9]*\).*/\1/'`

if [ -z "$version" ]; then
    echo "Cannot determine version of java to run jtreg"
    exit 1;
elif [ "$version" -lt 5 ]; then
    echo "java version 5 or later is required to run jtreg"
    exit 1;
fi

# And finally ...

IFS=$nl

# Use pre-built classes to speed up tests on the foundation model (aarch64).

set -x

if [ -n "$JTREG_LAVA_PREBUILT_CLASSES_DIR" ]; then
    if [ -n "$work_dir" ]; then
        mkdir -p $work_dir/classes
        if [ -d "$JTREG_LAVA_PREBUILT_CLASSES_DIR" ]; then
            cp -a $JTREG_LAVA_PREBUILT_CLASSES_DIR/* $work_dir/classes
            if `grep -- - /sys/devices/system/cpu/online >/dev/null`; then
                for i in /sys/devices/system/cpu/cpu[0-9]*; do
                    a=`basename $i`
                    a=`echo $a | sed s/cpu//`
                    mkdir -p $work_dir/classes/$a
                    cp -a $JTREG_LAVA_PREBUILT_CLASSES_DIR/* $work_dir/classes/$a
                done
            fi
        fi
    fi
fi

"${JT_JAVA}" \
    "${JT_JAVA_OPTS}" \
    $javaOpts \
    -Dprogram=`basename "$0"` \
    -jar "${JT_HOME}/lib/jtreg.jar" \
    $jtregOpts