1#
2# Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4#
5# This code is free software; you can redistribute it and/or modify it
6# under the terms of the GNU General Public License version 2 only, as
7# published by the Free Software Foundation.
8#
9# This code is distributed in the hope that it will be useful, but WITHOUT
10# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12# version 2 for more details (a copy is included in the LICENSE file that
13# accompanied this code).
14#
15# You should have received a copy of the GNU General Public License version
16# 2 along with this work; if not, write to the Free Software Foundation,
17# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18#
19# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20# or visit www.oracle.com if you need additional information or have any
21# questions.
22#
23
24# @test
25# @bug 7182152
26# @bug 8007935
27# @summary Redefine a subclass that implements two interfaces and
28#   verify that the right methods are called.
29# @author Daniel D. Daugherty
30#
31# @run shell MakeJAR3.sh RedefineSubclassWithTwoInterfacesAgent 'Can-Redefine-Classes: true'
32# @run build RedefineSubclassWithTwoInterfacesApp
33# @run shell RedefineSubclassWithTwoInterfaces.sh
34#
35
36if [ "${TESTJAVA}" = "" ]
37then
38  echo "TESTJAVA not set.  Test cannot execute.  Failed."
39  exit 1
40fi
41
42if [ "${COMPILEJAVA}" = "" ]
43then
44  COMPILEJAVA="${TESTJAVA}"
45fi
46echo "COMPILEJAVA=${COMPILEJAVA}"
47
48if [ "${TESTSRC}" = "" ]
49then
50  echo "TESTSRC not set.  Test cannot execute.  Failed."
51  exit 1
52fi
53
54if [ "${TESTCLASSES}" = "" ]
55then
56  echo "TESTCLASSES not set.  Test cannot execute.  Failed."
57  exit 1
58fi
59
60JAVAC="${COMPILEJAVA}"/bin/javac
61JAVA="${TESTJAVA}"/bin/java
62
63echo "INFO: building the replacement classes."
64
65cp "${TESTSRC}"/RedefineSubclassWithTwoInterfacesTarget_1.java \
66    RedefineSubclassWithTwoInterfacesTarget.java
67cp "${TESTSRC}"/RedefineSubclassWithTwoInterfacesImpl_1.java \
68    RedefineSubclassWithTwoInterfacesImpl.java
69"${JAVAC}" ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} \
70    -cp "${TESTCLASSES}" -d . \
71    RedefineSubclassWithTwoInterfacesTarget.java \
72    RedefineSubclassWithTwoInterfacesImpl.java 
73status="$?"
74if [ "$status" != 0 ]; then
75    echo "FAIL: compile of *_1.java files failed."
76    exit "$status"
77fi
78
79mv RedefineSubclassWithTwoInterfacesTarget.java \
80    RedefineSubclassWithTwoInterfacesTarget_1.java
81mv RedefineSubclassWithTwoInterfacesTarget.class \
82    RedefineSubclassWithTwoInterfacesTarget_1.class
83mv RedefineSubclassWithTwoInterfacesImpl.java \
84    RedefineSubclassWithTwoInterfacesImpl_1.java
85mv RedefineSubclassWithTwoInterfacesImpl.class \
86    RedefineSubclassWithTwoInterfacesImpl_1.class
87
88echo "INFO: launching RedefineSubclassWithTwoInterfacesApp"
89
90"${JAVA}" ${TESTVMOPTS} \
91    -Xlog:redefine+class+load=trace,redefine+class+load+exceptions=trace,redefine+class+timer=trace,redefine+class+obsolete=trace,redefine+class+obsolete+metadata=trace,redefine+class+constantpool=trace \
92    -javaagent:RedefineSubclassWithTwoInterfacesAgent.jar \
93    -classpath "${TESTCLASSES}" \
94    RedefineSubclassWithTwoInterfacesApp > output.log 2>&1
95status="$?"
96
97echo "INFO: <begin output.log>"
98cat output.log
99echo "INFO: <end output.log>"
100
101if [ "$status" != 0 ]; then
102    echo "FAIL: RedefineSubclassWithTwoInterfacesApp failed."
103    exit "$status"
104fi
105
106# When this bug manifests, RedefineClasses() will fail to update
107# one of the itable entries to refer to the new method. The log
108# will include the following line when the bug occurs:
109#
110#     guarantee(false) failed: OLD and/or OBSOLETE method(s) found
111#
112# If this guarantee happens, the test should fail in the status
113# check above, but just in case it doesn't, we check for "guarantee".
114#
115
116FAIL_MESG="guarantee"
117grep "$FAIL_MESG" output.log
118status=$?
119if [ "$status" = 0 ]; then
120    echo "FAIL: found '$FAIL_MESG' in the test output."
121    result=1
122else
123    echo "INFO: did NOT find '$FAIL_MESG' in the test output."
124    # be optimistic here
125    result=0
126fi
127
128PASS1_MESG="before any redefines"
129cnt=`grep "$PASS1_MESG" output.log | grep 'version-0' | wc -l`
130# no quotes around $cnt so any whitespace from 'wc -l' is ignored
131if [ $cnt = 2 ]; then
132    echo "INFO: found 2 version-0 '$PASS1_MESG' mesgs."
133else
134    echo "FAIL: did NOT find 2 version-0 '$PASS1_MESG' mesgs."
135    echo "INFO: cnt='$cnt'"
136    echo "INFO: grep '$PASS1_MESG' output:"
137    grep "$PASS1_MESG" output.log
138    result=1
139fi
140
141PASS2_MESG="after redefine"
142cnt=`grep "$PASS2_MESG" output.log | grep 'version-1' | wc -l`
143# no quotes around $cnt so any whitespace from 'wc -l' is ignored
144if [ $cnt = 2 ]; then
145    echo "INFO: found 2 version-1 '$PASS2_MESG' mesgs."
146else
147    echo "FAIL: did NOT find 2 version-1 '$PASS2_MESG' mesgs."
148    echo "INFO: cnt='$cnt'"
149    echo "INFO: grep '$PASS2_MESG' output:"
150    grep "$PASS2_MESG" output.log
151    result=1
152fi
153
154if [ "$result" = 0 ]; then
155    echo "PASS: test passed both positive and negative output checks."
156fi
157
158exit $result
159