common.sh 7.0 KB
Newer Older
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
#!/bin/sh
# 
# Copyright (c) 2013, 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.
# 
# 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.
# 
# 

# $1 - error code
# $2 - test name
# $3,.. - decription
test_fail() {
    error=$1
    shift
    name=$1
    shift
    echo "TEST [$name] FAILED:"
    echo "$@"
    exit $error
}

# $@ - additional vm opts
start_test() {
    # disable core dump on *nix
    ulimit -S -c 0
    # disable core dump on windows
    VMOPTS="$@ -XX:-CreateMinidumpOnCrash"
    cmd="${JAVA} ${VMOPTS} -XX:+ReplayCompiles -XX:ReplayDataFile=${replay_data}"
    echo $cmd
    $cmd
    return $?
}

# $1 - error_code
# $2 - test name
# $3,.. - additional vm opts
positive_test() {
    error=$1
    shift
    name=$1
    shift
    VMOPTS="${TESTVMOPTS} $@"
    echo "POSITIVE TEST [$name]"
    start_test ${VMOPTS}
    exit_code=$?
    if [ ${exit_code} -ne 0 ]
    then
        test_fail $error "$name" "exit_code[${exit_code}] != 0 during replay "\
                "w/ vmopts: ${VMOPTS}"
    fi
}

# $1 - error_code
# $2 - test name
# $2,.. - additional vm opts
negative_test() {
    error=$1
    shift
    name=$1
    shift
    VMOPTS="${TESTVMOPTS} $@"
    echo "NEGATIVE TEST [$name]"
    start_test ${VMOPTS}
    exit_code=$?
    if [ ${exit_code} -eq 0 ]
    then
        test_fail $error "$name" "exit_code[${exit_code}] == 0 during replay "\
                "w/ vmopts: ${VMOPTS}"
    fi
}

# $1 - initial error_code
common_tests() {
    positive_test $1 "COMMON :: THE SAME FLAGS"
92 93 94 95
    if [ $tiered_available -eq 1 ]
    then
        positive_test `expr $1 + 1` "COMMON :: TIERED" -XX:+TieredCompilation
    fi
96 97 98 99 100 101
}

# $1 - initial error_code
# $2 - non-tiered comp_level 
nontiered_tests() {
    level=`grep "^compile " $replay_data | awk '{print $6}'`
102
    # is level available in non-tiered
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
    if [ "$level" -eq $2 ]
    then
        positive_test $1 "NON-TIERED :: AVAILABLE COMP_LEVEL" \
                -XX:-TieredCompilation
    else
        negative_test `expr $1 + 1` "NON-TIERED :: UNAVAILABLE COMP_LEVEL" \
                -XX:-TieredCompilation
    fi
}

# $1 - initial error_code
client_tests() {
    # testing in opposite VM
    if [ $server_available -eq 1 ]
    then
        negative_test $1 "SERVER :: NON-TIERED" -XX:-TieredCompilation \
                -server
120 121 122 123 124
        if [ $tiered_available -eq 1 ]
        then
            positive_test `expr $1 + 1` "SERVER :: TIERED" -XX:+TieredCompilation \
                    -server
        fi
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 166 167 168 169 170 171 172 173 174
    fi
    nontiered_tests `expr $1 + 2` $client_level 
}

# $1 - initial error_code
server_tests() {
    # testing in opposite VM
    if [ $client_available -eq 1 ]
    then
        # tiered is unavailable in client vm, so results w/ flags will be the same as w/o flags
        negative_test $1 "CLIENT" -client
    fi
    nontiered_tests `expr $1 + 2` $server_level
}

cleanup() {
    ${RM} -f core*
    ${RM} -f replay*.txt
    ${RM} -f hs_err_pid*.log
    ${RM} -f test_core
    ${RM} -f test_replay.txt
}

JAVA=${TESTJAVA}${FS}bin${FS}java

replay_data=test_replay.txt

${JAVA} ${TESTVMOPTS} -Xinternalversion 2>&1 | grep debug

# Only test fastdebug 
if [ $? -ne 0 ]
then
    echo TEST SKIPPED: product build
    exit 0
fi

is_int=`${JAVA} ${TESTVMOPTS} -version 2>&1 | grep -c "interpreted mode"`
# Not applicable for Xint
if [ $is_int -ne 0 ]
then
    echo TEST SKIPPED: interpreted mode
    exit 0
fi

cleanup

client_available=`${JAVA} ${TESTVMOPTS} -client -Xinternalversion 2>&1 | \
        grep -c Client`
server_available=`${JAVA} ${TESTVMOPTS} -server -Xinternalversion 2>&1 | \
        grep -c Server`
175 176 177
tiered_available=`${JAVA} ${TESTVMOPTS} -XX:+TieredCompilation -XX:+PrintFlagsFinal -version | \
        grep TieredCompilation | \
        grep -c true`
178 179 180 181 182 183 184 185 186 187
is_tiered=`${JAVA} ${TESTVMOPTS} -XX:+PrintFlagsFinal -version | \
        grep TieredCompilation | \
        grep -c true`
# CompLevel_simple -- C1
client_level=1
# CompLevel_full_optimization -- C2 or Shark 
server_level=4

echo "client_available=$client_available"
echo "server_available=$server_available"
188
echo "tiered_available=$tiered_available"
189 190 191 192 193
echo "is_tiered=$is_tiered"

# crash vm in compiler thread with generation replay data and 'small' dump-file
# $@ - additional vm opts
generate_replay() {
194 195 196 197
    if [ $VM_OS != "windows" ]
    then
        # enable core dump
        ulimit -c unlimited
198 199 200 201 202

        if [ $VM_OS = "solaris" ]
        then
            coreadm -p core $$
        fi
203
    fi
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225

    cmd="${JAVA} ${TESTVMOPTS} $@ \
            -Xms8m \
            -Xmx32m \
            -XX:MetaspaceSize=4m \
            -XX:MaxMetaspaceSize=16m \
            -XX:InitialCodeCacheSize=512k \
            -XX:ReservedCodeCacheSize=4m \
            -XX:ThreadStackSize=512 \
            -XX:VMThreadStackSize=512 \
            -XX:CompilerThreadStackSize=512 \
            -XX:ParallelGCThreads=1 \
            -XX:CICompilerCount=1 \
            -Xcomp \
            -XX:CICrashAt=1 \
            -XX:+CreateMinidumpOnCrash \
            -XX:+DumpReplayDataOnError \
            -XX:ReplayDataFile=${replay_data} \
            -version"
    echo GENERATION OF REPLAY.TXT:
    echo $cmd

226
    ${cmd} > crash.out 2>&1
227 228 229 230 231
    
    core_locations=`grep -i core crash.out | grep "location:" | \
            sed -e 's/.*location: //'`
    rm crash.out 
    # processing core locations for *nix
232
    if [ $VM_OS != "windows" ]
233 234 235 236 237
    then
        # remove 'or' between '/core.<pid>' and 'core'
        core_locations=`echo $core_locations | \
                sed -e 's/\([^ ]*\) or \([^ ]*\)/\1 \2/'`
        # add <core_path>/core.<pid> core.<pid>
238 239 240 241
        core_with_dir=`echo $core_locations | awk '{print $1}'`
        dir=`dirname $core_with_dir`
        core_with_pid=`echo $core_locations | awk '{print $2}'`
        if [ -n ${core_with_pid} ]
242
        then
243
            core_locations="$core_locations $dir${FS}$core_with_pid $core_with_pid"
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
        fi
    fi

    echo "LOOKING FOR CORE IN ${core_locations}"
    for core in $core_locations
    do
        if [ -r "$core" ]
        then
            core_file=$core
        fi
    done

    # core-file was found
    if [ -n "$core_file" ]
    then
        ${MV} "${core_file}" test_core
        core_file=test_core
    fi

    ${RM} -f hs_err_pid*.log
}