8009681: TEST_BUG: MethodExitReturnValuesTest.java may fail when there are unexpected background threads

Reviewed-by: sla, allwin
This commit is contained in:
Mikael Auno 2013-10-15 12:53:54 +02:00 committed by Staffan Larsen
parent bdb08c592d
commit f99959f054
2 changed files with 33 additions and 30 deletions

View File

@ -108,14 +108,11 @@ public class MethodEntryExitEvents extends TestScaffold {
final int expectedExitCount = 1 + (15 * 3); final int expectedExitCount = 1 + (15 * 3);
int methodExitCount = 0; int methodExitCount = 0;
/* // Classes which we are interested in
* Class patterns for which we don't want events (copied private List includes = Arrays.asList(new String[] {
* from the "Trace.java" example): "MethodEntryExitEventsDebugee",
* http://java.sun.com/javase/technologies/core/toolsapis/jpda/ "t2"
*/ });
private String[] excludes = {"java.*", "javax.*", "sun.*",
"com.sun.*", "com.oracle.*",
"oracle.*", "jdk.internal.*"};
MethodEntryExitEvents (String args[]) { MethodEntryExitEvents (String args[]) {
super(args); super(args);
@ -161,6 +158,10 @@ public class MethodEntryExitEvents extends TestScaffold {
str.disable(); str.disable();
} }
public void methodEntered(MethodEntryEvent event) { public void methodEntered(MethodEntryEvent event) {
if (!includes.contains(event.method().declaringType().name())) {
return;
}
if (! finishedCounting) { if (! finishedCounting) {
// We have to count the entry to loopComplete, but // We have to count the entry to loopComplete, but
// not the exit // not the exit
@ -176,6 +177,10 @@ public class MethodEntryExitEvents extends TestScaffold {
} }
public void methodExited(MethodExitEvent event) { public void methodExited(MethodExitEvent event) {
if (!includes.contains(event.method().declaringType().name())) {
return;
}
if (! finishedCounting){ if (! finishedCounting){
methodExitCount++; methodExitCount++;
System.out.print (" Method exit number: "); System.out.print (" Method exit number: ");
@ -214,6 +219,10 @@ public class MethodEntryExitEvents extends TestScaffold {
connect((String[]) argList.toArray(args2)); connect((String[]) argList.toArray(args2));
waitForVMStart(); waitForVMStart();
// Determine main thread
ClassPrepareEvent e = resumeToPrepareOf("MethodEntryExitEventsDebugee");
mainThread = e.thread();
try { try {
/* /*
@ -223,6 +232,7 @@ public class MethodEntryExitEvents extends TestScaffold {
eventRequestManager().createExceptionRequest(null, // refType (null == all instances) eventRequestManager().createExceptionRequest(null, // refType (null == all instances)
true, // notifyCaught true, // notifyCaught
true);// notifyUncaught true);// notifyUncaught
exceptionRequest.addThreadFilter(mainThread);
exceptionRequest.setSuspendPolicy(EventRequest.SUSPEND_ALL); exceptionRequest.setSuspendPolicy(EventRequest.SUSPEND_ALL);
exceptionRequest.enable(); exceptionRequest.enable();
@ -231,9 +241,7 @@ public class MethodEntryExitEvents extends TestScaffold {
*/ */
MethodEntryRequest entryRequest = MethodEntryRequest entryRequest =
eventRequestManager().createMethodEntryRequest(); eventRequestManager().createMethodEntryRequest();
for (int i=0; i<excludes.length; ++i) { entryRequest.addThreadFilter(mainThread);
entryRequest.addClassExclusionFilter(excludes[i]);
}
entryRequest.setSuspendPolicy(sessionSuspendPolicy); entryRequest.setSuspendPolicy(sessionSuspendPolicy);
entryRequest.enable(); entryRequest.enable();
@ -242,10 +250,7 @@ public class MethodEntryExitEvents extends TestScaffold {
*/ */
MethodExitRequest exitRequest = MethodExitRequest exitRequest =
eventRequestManager().createMethodExitRequest(); eventRequestManager().createMethodExitRequest();
exitRequest.addThreadFilter(mainThread);
for (int i=0; i<excludes.length; ++i) {
exitRequest.addClassExclusionFilter(excludes[i]);
}
exitRequest.setSuspendPolicy(sessionSuspendPolicy); exitRequest.setSuspendPolicy(sessionSuspendPolicy);
exitRequest.enable(); exitRequest.enable();

View File

@ -209,18 +209,13 @@ class MethodExitReturnValuesTarg {
public class MethodExitReturnValuesTest extends TestScaffold { public class MethodExitReturnValuesTest extends TestScaffold {
// Classes which we are interested in
/* private List includes = Arrays.asList(new String[] {
* Class patterns for which we don't want events (copied "MethodExitReturnValuesTarg",
* from the "Trace.java" example): "java.lang.reflect.Array",
* http://java.sun.com/javase/technologies/core/toolsapis/jpda/ "java.lang.StrictMath",
*/ "java.lang.String"
private String[] excludes = { });
"javax.*",
"sun.*",
"com.sun.*",
"com.oracle.*",
"oracle.*"};
static VirtualMachineManager vmm ; static VirtualMachineManager vmm ;
ClassType targetClass; ClassType targetClass;
@ -487,6 +482,11 @@ public class MethodExitReturnValuesTest extends TestScaffold {
// This is the MethodExitEvent handler. // This is the MethodExitEvent handler.
public void methodExited(MethodExitEvent event) { public void methodExited(MethodExitEvent event) {
String origMethodName = event.method().name(); String origMethodName = event.method().name();
if (!includes.contains(event.method().declaringType().name())) {
return;
}
if (vmm.majorInterfaceVersion() >= 1 && if (vmm.majorInterfaceVersion() >= 1 &&
vmm.minorInterfaceVersion() >= 6 && vmm.minorInterfaceVersion() >= 6 &&
vm().canGetMethodReturnValues()) { vm().canGetMethodReturnValues()) {
@ -560,10 +560,8 @@ public class MethodExitReturnValuesTest extends TestScaffold {
*/ */
MethodExitRequest exitRequest = MethodExitRequest exitRequest =
eventRequestManager().createMethodExitRequest(); eventRequestManager().createMethodExitRequest();
exitRequest.addThreadFilter(mainThread);
for (int i=0; i<excludes.length; ++i) {
exitRequest.addClassExclusionFilter(excludes[i]);
}
int sessionSuspendPolicy = EventRequest.SUSPEND_ALL; int sessionSuspendPolicy = EventRequest.SUSPEND_ALL;
//sessionSuspendPolicy = EventRequest.SUSPEND_EVENT_THREAD; //sessionSuspendPolicy = EventRequest.SUSPEND_EVENT_THREAD;
//sessionSuspendPolicy = EventRequest.SUSPEND_NONE; //sessionSuspendPolicy = EventRequest.SUSPEND_NONE;