Skip to content

Commit

Permalink
8292066: Convert TestInputArgument.sh and TestSystemLoadAvg.sh to jav…
Browse files Browse the repository at this point in the history
…a version

Backport-of: 032be168b5a6af6f9e82deb8c8cafcd2c44b5447
  • Loading branch information
GoeLin committed Feb 2, 2023
1 parent 78c6be2 commit c74eb2b
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 168 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2022, 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
Expand All @@ -22,11 +22,14 @@
*/

/*
*
*
* @bug 6336608 6511738
* @test
* @bug 6336608 6511738 6367473
* @summary Basic unit test of OperatingSystemMXBean.getSystemLoadAverage()
* @author Mandy Chung
*
* @library /test/lib
*
* @run testng GetSystemLoadAverage
*/

/*
Expand All @@ -42,8 +45,13 @@
* running on Windows.
*/

import java.lang.management.*;
import java.io.*;
import jdk.test.lib.Platform;
import org.testng.annotations.Test;

import java.io.InputStreamReader;
import java.io.Reader;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;

public class GetSystemLoadAverage {

Expand All @@ -52,31 +60,41 @@ public class GetSystemLoadAverage {

// The system load average may be changing due to other jobs running.
// Allow some delta.
private static double DELTA = 0.05;

public static void main(String args[]) throws Exception {
if (args.length > 1) {
throw new IllegalArgumentException("Unexpected number of args " + args.length);
}

if (args.length == 0) {
// On Linux or Solaris
checkLoadAvg();
} else {
// On Windows, the system load average is expected to be -1.0
if (!args[0].equals("-1.0")) {
throw new IllegalArgumentException("Invalid argument: " + args[0]);
} else {
double loadavg = mbean.getSystemLoadAverage();
if (loadavg != -1.0) {
throw new RuntimeException("Expected load average : -1.0" +
" but getSystemLoadAverage returned: " +
loadavg);
private static final double DELTA = 0.05;

private static final int MAX_RETRIES = 5;
private static final int WAIT_TIME_MS = 5000;

@Test(timeOut = (300 + WAIT_TIME_MS) * MAX_RETRIES)
void testSystemLoadAvg() throws Exception {
for (int i = 1; i <= MAX_RETRIES; i++) {
try {
System.out.println(String.format("Run %d: TestSystemLoadAvg", i));
if (!Platform.isWindows()) {
// On Linux or Mac
checkLoadAvg();
} else {
// On Windows, the system load average is expected to be -1.0
double loadavg = mbean.getSystemLoadAverage();
if (loadavg != -1.0) {
throw new RuntimeException("Expected load average : -1.0" +
" but getSystemLoadAverage returned: " + loadavg);
}
}
System.out.println(String.format("Run %d: TestSystemLoadAvg test passed", i));
return;
} catch (Exception e) {
System.out.println(
String.format("TEST FAILED: TestSystemLoadAvg test " + "failed %d runs",
i));
if (i == MAX_RETRIES) {
throw e;
}

System.out.println("Wait for 5 seconds");
Thread.sleep(WAIT_TIME_MS);
}
}

System.out.println("Test passed.");
}

private static String LOAD_AVERAGE_TEXT
Expand Down Expand Up @@ -132,5 +150,4 @@ private static String commandOutput(Process p) throws Exception {
p.exitValue();
return output;
}

}

This file was deleted.

35 changes: 34 additions & 1 deletion test/jdk/java/lang/management/RuntimeMXBean/InputArgument.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2022, 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
Expand All @@ -22,11 +22,44 @@
*/

/*
* @test
* @bug 4530538
* @summary Basic unit test of RuntimeMXBean.getInputArguments().
*
* @author Mandy Chung
*
* @run main InputArgument
*/

/*
* @test
* @bug 4530538
* @summary Basic unit test of RuntimeMXBean.getInputArguments().
*
* @author Mandy Chung
*
* @run main/othervm -XX:+UseFastJNIAccessors -Xlog:gc*=debug InputArgument
*/

/*
* @test
* @bug 4530538
* @summary Basic unit test of RuntimeMXBean.getInputArguments().
*
* @author Mandy Chung
*
* @run main/othervm -XX:+UseFastJNIAccessors -Xlog:gc*=debug InputArgument
* -XX:+UseFastJNIAccessors
*/

/*
* @test
* @bug 4530538
* @summary Basic unit test of RuntimeMXBean.getInputArguments().
*
* @author Mandy Chung
*
* @run main/othervm -Dprops=something InputArgument -Dprops=something
*/

import java.lang.management.*;
Expand Down
55 changes: 0 additions & 55 deletions test/jdk/java/lang/management/RuntimeMXBean/TestInputArgument.sh

This file was deleted.

1 comment on commit c74eb2b

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.