8306758: com/sun/jdi/ConnectedVMs.java fails with "Non-zero debuggee exitValue: 143"

Reviewed-by: amenkov, sspitsyn
This commit is contained in:
Chris Plummer 2023-05-10 19:09:24 +00:00
parent 1964954da9
commit 268836482d
3 changed files with 45 additions and 10 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2023, 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
@ -28,6 +28,7 @@
* VirtualMachineManager.connectedVirtualMachines()
* @author Robert Field
*
* @library /test/lib
* @run build TestScaffold VMConnection TargetListener TargetAdapter
* @run compile -g InstTarg.java
* @run driver ConnectedVMs Kill
@ -40,6 +41,8 @@ import com.sun.jdi.event.*;
import com.sun.jdi.request.*;
import java.util.List;
import jdk.test.lib.Platform;
public class ConnectedVMs extends TestScaffold {
static int failCount = 0;;
static String passName;
@ -62,6 +65,23 @@ public class ConnectedVMs extends TestScaffold {
System.out.println("create " + passName);
}
@Override
protected boolean allowedExitValue(int exitValue) {
if (passName.equals("Kill")) {
// 143 is SIGTERM, which we expect to get when doing a Process.destroy(),
// unless we are on Windows, which will exit with a 1.
if (!Platform.isWindows()) {
return exitValue == 143;
} else {
return exitValue == 1;
}
} else if (passName.equals("exit()")) {
// This version of the test does an exit(1), so that's what we expect.
return exitValue == 1;
}
return super.allowedExitValue(exitValue);
}
void vms(int expected) {
List vms = Bootstrap.virtualMachineManager().
connectedVirtualMachines();
@ -76,9 +96,9 @@ public class ConnectedVMs extends TestScaffold {
protected void runTests() throws Exception {
System.out.println("Testing " + passName);
vms(0);
startToMain("InstTarg");
ThreadReference thread = waitForVMStart();
StepEvent stepEvent = stepIntoLine(thread);
BreakpointEvent bp = startToMain("InstTarg");
waitForVMStart();
StepEvent stepEvent = stepIntoLine(bp.thread());
vms(1);
// pick a way to die based on the input arg.

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2023 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
@ -29,6 +29,16 @@ public class InstTarg {
public static void main(String args[]) {
start();
// Sleep before exiting to allow disconnect efforts done on the JDI side to complete.
// Note that not sleeping long enough is for the most part harmless, but might render
// the testing insufficient because the debuggee will quickly exit naturally
// once the debuggee does the vm.resume(), rather than waiting for disconnect
// efforts to complete first.
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
static void start() {

View File

@ -722,6 +722,13 @@ abstract public class TestScaffold extends TargetAdapter {
return vmStartThread;
}
/*
* Tests that expect an exitValue other than 0 or 1 will need to override this method.
*/
protected boolean allowedExitValue(int exitValue) {
return exitValue == 0 || exitValue == 1;
}
public synchronized void waitForVMDisconnect() {
traceln("TS: waitForVMDisconnect");
while (!vmDisconnected) {
@ -738,11 +745,9 @@ abstract public class TestScaffold extends TargetAdapter {
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
int res = p.exitValue();
// Some tests purposefully exit with an exception, which produces exitValue
// 1, so we have to allow it also.
if (res != 0 && res != 1) {
throw new RuntimeException("Non-zero debuggee exitValue: " + res);
int exitValue = p.exitValue();
if (!allowedExitValue(exitValue)) {
throw new RuntimeException("Invalid debuggee exitValue: " + exitValue);
}
traceln("TS: waitForVMDisconnect: done");