Path: blob/master/test/jdk/java/lang/management/OperatingSystemMXBean/TestSystemLoadAvg.sh
41153 views
#1# Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.2# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3#4# This code is free software; you can redistribute it and/or modify it5# under the terms of the GNU General Public License version 2 only, as6# published by the Free Software Foundation.7#8# This code is distributed in the hope that it will be useful, but WITHOUT9# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11# version 2 for more details (a copy is included in the LICENSE file that12# accompanied this code).13#14# You should have received a copy of the GNU General Public License version15# 2 along with this work; if not, write to the Free Software Foundation,16# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17#18# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19# or visit www.oracle.com if you need additional information or have any20# questions.21#2223#24# @test25# @bug 6336608 6367473 651173826# @summary Tests OperatingSystemMXBean.getSystemLoadAverage() api.27# @author Mandy Chung28#29# @run build GetSystemLoadAverage30# @run shell/timeout=300 TestSystemLoadAvg.sh31#3233#34# This test tests the system load average on linux and solaris.35# On windows tests if it returns -1.0 The verification is done36# by the GetSystemLoadAverage class. By default it takes no37# input argument which verifies the system load average with38# /usr/bin/uptime command. Or specify "-1.0" as the input argument39# indicatiing that the platform doesn't support the system load average.4041#Set appropriate jdk42#4344if [ ! -z "${TESTJAVA}" ] ; then45jdk="$TESTJAVA"46else47echo "--Error: TESTJAVA must be defined as the pathname of a jdk to test."48exit 149fi5051runOne()52{53echo "$TESTJAVA/bin/java -classpath $TESTCLASSES $@"54$TESTJAVA/bin/java ${TESTVMOPTS} -classpath $TESTCLASSES $@55}5657# Retry 5 times to be more resilent to system load fluctation.58MAX=559i=160while true; do61echo "Run $i: TestSystemLoadAvg"62case `uname -s` in63Linux | Darwin | AIX )64runOne GetSystemLoadAverage65;;66* )67# On Windows -1.0 should be returned68runOne GetSystemLoadAverage "-1.0"69;;70esac71if [ $? -eq 0 ]; then72# exit if the test passes73echo "Run $i: TestSystemLoadAvg test passed"74exit 075elif [ $i -eq $MAX ] ; then76echo "TEST FAILED: TestSystemLoadAvg test failed $i runs"77exit 178fi79i=`expr $i + 1`80# sleep for 5 seconds81sleep 582done838485