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

View File

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