8366659: Fixed semi-broken tests

This commit is contained in:
Anton Artemov 2025-12-02 11:24:14 +01:00
parent 8283d9c0c2
commit d45fc76b0d
4 changed files with 58 additions and 9 deletions

View File

@ -28,7 +28,7 @@
* @requires vm.jvmti
* @library /test/lib
* @compile SuspendWithObjectMonitorWait1.java
* @run main/othervm/native -agentlib:SuspendWithObjectMonitorWait SuspendWithObjectMonitorWait1
* @run main/othervm/native -agentlib:SuspendWithObjectMonitorWait SuspendWithObjectMonitorWait1 1
*/
import java.io.PrintStream;
@ -70,7 +70,7 @@ public class SuspendWithObjectMonitorWait1 extends SuspendWithObjectMonitorWaitB
SuspendWithObjectMonitorWaitWorker waiter; // waiter thread
SuspendWithObjectMonitorWaitWorker resumer; // resumer thread
System.out.println("About to execute for " + timeMax + " seconds.");
System.out.println("Test 1: About to execute for " + timeMax + " seconds.");
long start_time = System.currentTimeMillis();
while (System.currentTimeMillis() < start_time + (timeMax * 1000)) {

View File

@ -28,7 +28,7 @@
* @requires vm.jvmti
* @library /test/lib
* @compile SuspendWithObjectMonitorWait2.java
* @run main/othervm/native -agentlib:SuspendWithObjectMonitorWait SuspendWithObjectMonitorWait2
* @run main/othervm/native -agentlib:SuspendWithObjectMonitorWait SuspendWithObjectMonitorWait2 2
*/
import java.io.PrintStream;
@ -79,7 +79,7 @@ public class SuspendWithObjectMonitorWait2 extends SuspendWithObjectMonitorWaitB
SuspendWithObjectMonitorWaitWorker waiter; // waiter thread
SuspendWithObjectMonitorWaitWorker resumer; // resumer thread
System.out.println("About to execute for " + timeMax + " seconds.");
System.out.println("Test 2: About to execute for " + timeMax + " seconds.");
long start_time = System.currentTimeMillis();
while (System.currentTimeMillis() < start_time + (timeMax * 1000)) {

View File

@ -28,7 +28,7 @@
* @requires vm.jvmti
* @library /test/lib
* @compile SuspendWithObjectMonitorWait3.java
* @run main/othervm/native -agentlib:SuspendWithObjectMonitorWait SuspendWithObjectMonitorWait3
* @run main/othervm/native -agentlib:SuspendWithObjectMonitorWait SuspendWithObjectMonitorWait3 3
*/
import java.io.PrintStream;
@ -85,7 +85,7 @@ public class SuspendWithObjectMonitorWait3 extends SuspendWithObjectMonitorWaitB
SuspendWithObjectMonitorWaitWorker waiter; // waiter thread
SuspendWithObjectMonitorWaitWorker resumer; // resumer thread
System.out.println("About to execute for " + timeMax + " seconds.");
System.out.println("Test 3: About to execute for " + timeMax + " seconds.");
long start_time = System.currentTimeMillis();
while (System.currentTimeMillis() < start_time + (timeMax * 1000)) {

View File

@ -145,7 +145,12 @@ public class SuspendWithObjectMonitorWaitBase {
}
public static void main(String[] args) throws Exception {
if (args.length > 2) {
if (args.length == 0) {
System.err.println("Invalid number of arguments, there should be at least a test_case given.");
usage();
}
if (args.length > 3) {
System.err.println("Invalid number of arguments, there are too many arguments.");
usage();
}
@ -159,14 +164,32 @@ public class SuspendWithObjectMonitorWaitBase {
throw ule;
}
int testCase = 0;
int timeMax = 0;
for (int argIndex = 0; argIndex < args.length; argIndex++) {
if ("-p".equals(args[argIndex])) {
if (args[argIndex].equals("-p")) {
// Handle optional -p arg regardless of position.
printDebug = true;
continue;
}
if (testCase == 0) {
try {
// testCase must be the first non-optional arg.
testCase = Integer.parseUnsignedInt(args[argIndex]);
log("testCase = " + testCase);
} catch (NumberFormatException nfe) {
System.err.println("'" + args[argIndex] +
"': invalid test_case value.");
usage();
}
if (testCase < 1 || testCase > 3) {
System.err.println("Invalid test_case value: '" + testCase + "'");
usage();
}
continue;
}
if (argIndex < args.length) {
// timeMax is an optional arg.
try {
@ -180,7 +203,33 @@ public class SuspendWithObjectMonitorWaitBase {
timeMax = DEF_TIME_MAX;
}
}
SuspendWithObjectMonitorWaitBase test = new SuspendWithObjectMonitorWaitBase();
if (timeMax == 0) {
timeMax = DEF_TIME_MAX;
}
log("timeMax = " + timeMax);
if (testCase == 0) {
// Just -p was given.
System.err.println("Invalid number of arguments, no test_case given.");
usage();
}
SuspendWithObjectMonitorWaitBase test = null;
switch (testCase) {
case 1:
test = new SuspendWithObjectMonitorWait1();
break;
case 2:
test = new SuspendWithObjectMonitorWait2();
break;
case 3:
test = new SuspendWithObjectMonitorWait3();
break;
default:
// Impossible
break;
}
int result = test.run(timeMax, System.out);
System.exit(result + exit_delta);
}