1 # 2 # Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. 3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 # 5 # This code is free software; you can redistribute it and/or modify it 6 # under the terms of the GNU General Public License version 2 only, as 7 # published by the Free Software Foundation. 8 # 9 # This code is distributed in the hope that it will be useful, but WITHOUT 10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 # version 2 for more details (a copy is included in the LICENSE file that 13 # accompanied this code). 14 # 15 # You should have received a copy of the GNU General Public License version 16 # 2 along with this work; if not, write to the Free Software Foundation, 17 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 # 19 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 # or visit www.oracle.com if you need additional information or have any 21 # questions. 22 # 23 24 # 25 # @test 26 # @summary Tests OperatingSystemMXBean.getSystemLoadAverage() api. 27 # @author Mandy Chung 28 # @bug 6336608 6367473 6511738 29 # 30 # @modules java.management 31 # @run build GetSystemLoadAverage 32 # @run shell/timeout=300 TestSystemLoadAvg.sh 33 # 34 35 # 36 # This test tests the system load average on linux and solaris. 37 # On windows tests if it returns -1.0 The verification is done 38 # by the GetSystemLoadAverage class. By default it takes no 39 # input argument which verifies the system load average with 40 # /usr/bin/uptime command. Or specify "-1.0" as the input argument 41 # indicatiing that the platform doesn't support the system load average. 42 43 #Set appropriate jdk 44 # 45 46 if [ ! -z "${TESTJAVA}" ] ; then 47 jdk="$TESTJAVA" 48 else 49 echo "--Error: TESTJAVA must be defined as the pathname of a jdk to test." 50 exit 1 51 fi 52 53 runOne() 54 { 55 echo "$TESTJAVA/bin/java -classpath $TESTCLASSES $@" 56 $TESTJAVA/bin/java ${TESTVMOPTS} -classpath $TESTCLASSES $@ 57 } 58 59 # Retry 5 times to be more resilent to system load fluctation. 60 MAX=5 61 i=1 62 while true; do 63 echo "Run $i: TestSystemLoadAvg" 64 case `uname -s` in 65 SunOS | Linux | Darwin | AIX ) 66 runOne GetSystemLoadAverage 67 ;; 68 * ) 69 # On Windows -1.0 should be returned 70 runOne GetSystemLoadAverage "-1.0" 71 ;; 72 esac 73 if [ $? -eq 0 ]; then 74 # exit if the test passes 75 echo "Run $i: TestSystemLoadAvg test passed" 76 exit 0 77 elif [ $i -eq $MAX ] ; then 78 echo "TEST FAILED: TestSystemLoadAvg test failed $i runs" 79 exit 1 80 fi 81 i=`expr $i + 1` 82 # sleep for 5 seconds 83 sleep 5 84 done