8292066: Convert TestInputArgument.sh and TestSystemLoadAvg.sh to java version
Reviewed-by: lmesnik, amenkov
This commit is contained in:
parent
e393973761
commit
032be168b5
@ -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
|
||||
@ -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
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -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 {
|
||||
|
||||
@ -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;
|
||||
private static final 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);
|
||||
}
|
||||
private static final int MAX_RETRIES = 5;
|
||||
private static final int WAIT_TIME_MS = 5000;
|
||||
|
||||
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);
|
||||
@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
|
||||
@ -132,5 +150,4 @@ public class GetSystemLoadAverage {
|
||||
p.exitValue();
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,83 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2005, 2020, 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
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
#
|
||||
# @test
|
||||
# @bug 6336608 6367473 6511738
|
||||
# @summary Tests OperatingSystemMXBean.getSystemLoadAverage() api.
|
||||
# @author Mandy Chung
|
||||
#
|
||||
# @run build GetSystemLoadAverage
|
||||
# @run shell/timeout=300 TestSystemLoadAvg.sh
|
||||
#
|
||||
|
||||
#
|
||||
# This test tests the system load average on linux and solaris.
|
||||
# On windows tests if it returns -1.0 The verification is done
|
||||
# by the GetSystemLoadAverage class. By default it takes no
|
||||
# input argument which verifies the system load average with
|
||||
# /usr/bin/uptime command. Or specify "-1.0" as the input argument
|
||||
# indicatiing that the platform doesn't support the system load average.
|
||||
|
||||
#Set appropriate jdk
|
||||
#
|
||||
|
||||
if [ ! -z "${TESTJAVA}" ] ; then
|
||||
jdk="$TESTJAVA"
|
||||
else
|
||||
echo "--Error: TESTJAVA must be defined as the pathname of a jdk to test."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
runOne()
|
||||
{
|
||||
echo "$TESTJAVA/bin/java -classpath $TESTCLASSES $@"
|
||||
$TESTJAVA/bin/java ${TESTVMOPTS} -classpath $TESTCLASSES $@
|
||||
}
|
||||
|
||||
# Retry 5 times to be more resilent to system load fluctation.
|
||||
MAX=5
|
||||
i=1
|
||||
while true; do
|
||||
echo "Run $i: TestSystemLoadAvg"
|
||||
case `uname -s` in
|
||||
Linux | Darwin | AIX )
|
||||
runOne GetSystemLoadAverage
|
||||
;;
|
||||
* )
|
||||
# On Windows -1.0 should be returned
|
||||
runOne GetSystemLoadAverage "-1.0"
|
||||
;;
|
||||
esac
|
||||
if [ $? -eq 0 ]; then
|
||||
# exit if the test passes
|
||||
echo "Run $i: TestSystemLoadAvg test passed"
|
||||
exit 0
|
||||
elif [ $i -eq $MAX ] ; then
|
||||
echo "TEST FAILED: TestSystemLoadAvg test failed $i runs"
|
||||
exit 1
|
||||
fi
|
||||
i=`expr $i + 1`
|
||||
# sleep for 5 seconds
|
||||
sleep 5
|
||||
done
|
@ -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
|
||||
@ -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.*;
|
||||
|
@ -1,55 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2003, 2015, 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
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
#
|
||||
# @test
|
||||
# @bug 4530538
|
||||
# @summary
|
||||
# @author Mandy Chung
|
||||
#
|
||||
# @run compile InputArgument.java
|
||||
# @run shell TestInputArgument.sh
|
||||
#
|
||||
|
||||
#Set appropriate jdk
|
||||
|
||||
if [ ! -z "${TESTJAVA}" ] ; then
|
||||
jdk="$TESTJAVA"
|
||||
else
|
||||
echo "--Error: TESTJAVA must be defined as the pathname of a jdk to test."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
runOne()
|
||||
{
|
||||
echo "runOne $@"
|
||||
$TESTJAVA/bin/java $TESTVMOPTS -classpath $TESTCLASSES "$@" || exit 2
|
||||
}
|
||||
|
||||
runOne InputArgument
|
||||
|
||||
runOne -XX:+UseFastJNIAccessors -Xlog:gc*=debug InputArgument
|
||||
runOne -XX:+UseFastJNIAccessors -Xlog:gc*=debug InputArgument -XX:+UseFastJNIAccessors
|
||||
runOne "-Dprops=one two three" InputArgument "-Dprops=one two three"
|
||||
|
||||
exit 0
|
Loading…
Reference in New Issue
Block a user