8290180: Convert com/sun/management/UnixOperatingSystemMXBean/GetOpenFileDescriptorCount.sh to jtreg java version

8290181: convert com/sun/management/UnixOperatingSystemMXBean/GetMaxFileDescriptorCount.sh to java version

Reviewed-by: lmesnik, amenkov
This commit is contained in:
Bill Huang 2022-08-08 15:06:49 +00:00 committed by Leonid Mesnik
parent 459193710f
commit 124fc4a83d
4 changed files with 26 additions and 172 deletions

View File

@ -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,18 +22,13 @@
*/
/*
*
* @test
* @bug 4858522
* @summary Basic unit test of UnixOperatingSystemMXBean.getMaxFileDescriptorCount()
* @author Steve Bohne
*/
/*
* This test is just a sanity check and does not check for the correct
* value. The correct value should be checked manually:
* Solaris/Linux:
* 1. In a shell, as user who started java process, enter the command
* "limit -h descriptors"
* @requires os.family != "windows"
*
* @run main GetMaxFileDescriptorCount
*/
import com.sun.management.UnixOperatingSystemMXBean;
@ -42,35 +37,26 @@ import java.lang.management.*;
public class GetMaxFileDescriptorCount {
private static UnixOperatingSystemMXBean mbean =
(UnixOperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean();
(UnixOperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
// Careful with these values.
// Min count for pass dynamically determined below.
private static long min_count_for_pass = 1;
private static long minCountForPass = 1;
private static final long MAX_COUNT_FOR_PASS = Long.MAX_VALUE;
private static boolean trace = false;
public static void main(String args[]) throws Exception {
if (args.length > 0 && args[0].equals("trace")) {
trace = true;
}
long min_count = mbean.getOpenFileDescriptorCount();
if (min_count > 0) {
min_count_for_pass = min_count;
long minCount = mbean.getOpenFileDescriptorCount();
if (minCount > 0) {
minCountForPass = minCount;
}
long count = mbean.getMaxFileDescriptorCount();
if (trace) {
System.out.println("Max file descriptor count: " + count);
}
System.out.println("Max file descriptor count: " + count);
if (count < min_count_for_pass || count > MAX_COUNT_FOR_PASS) {
if (count < minCountForPass || count > MAX_COUNT_FOR_PASS) {
throw new RuntimeException("Max file descriptor count " +
"illegal value: " + count + " bytes " +
"(MIN = " + min_count_for_pass + "; " +
"(MIN = " + minCountForPass + "; " +
"MAX = " + MAX_COUNT_FOR_PASS + ")");
}

View File

@ -1,60 +0,0 @@
#
# Copyright (c) 2003, 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 4858522
# @summary
# @author Steve Bohne
#
# @run shell GetMaxFileDescriptorCount.sh
#
if [ "${TESTJAVA}" = "" ] ; then
echo "--Error: TESTJAVA must be defined as the pathname of a jdk to test."
exit 1
fi
if [ "${COMPILEJAVA}" = "" ]; then
COMPILEJAVA="${TESTJAVA}"
fi
runOne()
{
echo "runOne $@"
$COMPILEJAVA/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d $TESTCLASSES \
$TESTSRC/$@.java || exit 2
$TESTJAVA/bin/java ${TESTVMOPTS} -classpath $TESTCLASSES $@ || exit 3
}
# Test GetMaxFileDescriptorCount if we are running on Unix
case `uname -s` in
Linux )
runOne GetMaxFileDescriptorCount
;;
* )
echo "Ignore test when not run on Linux"
exit 0
;;
esac
exit 0

View File

@ -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,17 +22,13 @@
*/
/*
* @test
* @bug 4858522
* @summary Basic unit test of UnixOperatingSystemMXBean.getOpenFileDescriptorCount()
* @author Steve Bohne
*/
/*
* This test is just a sanity check and does not check for the correct
* value. The correct value should be checked manually:
* Solaris/Linux:
* 1. Find the pid of the java process.
* 2. In a shell, enter the command: "ls -1 /proc/<pid>/fd | wc -l"
* @requires os.family != "windows"
*
* @run main GetOpenFileDescriptorCount
*/
import com.sun.management.UnixOperatingSystemMXBean;
@ -41,36 +37,27 @@ import java.lang.management.*;
public class GetOpenFileDescriptorCount {
private static UnixOperatingSystemMXBean mbean =
(UnixOperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean();
(UnixOperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
// Careful with these values.
private static final long MIN_COUNT_FOR_PASS = 1;
// Max count for pass dynamically determined below
private static long max_count_for_pass = Long.MAX_VALUE;
private static boolean trace = false;
private static long maxCountForPass = Long.MAX_VALUE;
public static void main(String args[]) throws Exception {
if (args.length > 0 && args[0].equals("trace")) {
trace = true;
}
long max_count = mbean.getMaxFileDescriptorCount();
if (max_count > 0) {
max_count_for_pass = max_count;
long maxCount = mbean.getMaxFileDescriptorCount();
if (maxCount > 0) {
maxCountForPass = maxCount;
}
long count = mbean.getOpenFileDescriptorCount();
if (trace) {
System.out.println("Open file descriptor count: " + count);
}
System.out.println("Open file descriptor count: " + count);
if (count < MIN_COUNT_FOR_PASS || count > max_count_for_pass) {
if (count < MIN_COUNT_FOR_PASS || count > maxCountForPass) {
throw new RuntimeException("Open file descriptor count " +
"illegal value: " + count + " bytes " +
"(MIN = " + MIN_COUNT_FOR_PASS + "; " +
"MAX = " + max_count_for_pass + ")");
"MAX = " + maxCountForPass + ")");
}
System.out.println("Test passed.");

View File

@ -1,59 +0,0 @@
#
# Copyright (c) 2003, 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 4858522
# @summary
# @author Steve Bohne
#
# @run shell GetOpenFileDescriptorCount.sh
#
if [ "${TESTJAVA}" = "" ] ; then
echo "--Error: TESTJAVA must be defined as the pathname of a jdk to test."
exit 1
fi
if [ "${COMPILEJAVA}" = "" ]; then
COMPILEJAVA="${TESTJAVA}"
fi
runOne()
{
echo "runOne $@"
$COMPILEJAVA/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d $TESTCLASSES \
$TESTSRC/$@.java || exit 2
$TESTJAVA/bin/java ${TESTVMOPTS} -classpath $TESTCLASSES $@ || exit 3
}
# Test GetOpenFileDescriptorCount if we are running on Unix
case `uname -s` in
Linux )
runOne GetOpenFileDescriptorCount
;;
* )
echo "Ignore test when not run on Linux"
exit 0
;;
esac
exit 0