2592N/A##
2592N/A## @test @(#)test6941923.sh
2592N/A## @bug 6941923
2592N/A## @summary test new added flags for gc log rotation
2592N/A## @author yqi
2592N/A## @run shell test6941923.sh
2592N/A##
4503N/A## some tests require path to find test source dir
4503N/Aif [ "${TESTSRC}" = "" ]
4503N/Athen
4503N/A TESTSRC=${PWD}
4503N/A echo "TESTSRC not set. Using "${TESTSRC}" as default"
4503N/Afi
4503N/Aecho "TESTSRC=${TESTSRC}"
4503N/A## Adding common setup Variables for running shell tests.
4503N/A. ${TESTSRC}/../../test_env.sh
2592N/A
2592N/A## skip on windows
2592N/AOS=`uname -s`
2592N/Acase "$OS" in
3985N/A Windows_* | CYGWIN_* )
2592N/A echo "Test skipped for Windows"
2592N/A exit 0
2592N/A ;;
2592N/Aesac
2592N/A
2592N/A# create a small test case
2592N/Atestname="Test"
2592N/Aif [ -e ${testname}.java ]; then
2592N/A rm -rf ${testname}.*
2592N/Afi
2592N/A
2592N/Acat >> ${testname}.java << __EOF__
2592N/Aimport java.util.Vector;
2592N/A
2592N/Apublic class Test implements Runnable
2592N/A{
2592N/A private boolean _should_stop = false;
2592N/A
2592N/A public static void main(String[] args) throws Exception {
2592N/A
2592N/A long limit = Long.parseLong(args[0]) * 60L * 1000L; // minutes
2592N/A Test t = new Test();
2592N/A t.set_stop(false);
2592N/A Thread thr = new Thread(t);
2592N/A thr.start();
2592N/A
2592N/A long time1 = System.currentTimeMillis();
2592N/A long time2 = System.currentTimeMillis();
2592N/A while (time2 - time1 < limit) {
2592N/A try {
2592N/A Thread.sleep(2000); // 2 seconds
2592N/A }
2592N/A catch(Exception e) {}
2592N/A time2 = System.currentTimeMillis();
2592N/A System.out.print("\r... " + (time2 - time1)/1000 + " seconds");
2592N/A }
2592N/A System.out.println();
2592N/A t.set_stop(true);
2592N/A }
2592N/A public void set_stop(boolean value) { _should_stop = value; }
2592N/A public void run() {
2592N/A int cap = 20000;
2592N/A int fix_size = 2048;
2592N/A int loop = 0;
2592N/A Vector< byte[] > v = new Vector< byte[] >(cap);
2592N/A while(!_should_stop) {
2592N/A byte[] g = new byte[fix_size];
2592N/A v.add(g);
2592N/A loop++;
2592N/A if (loop > cap) {
2592N/A v = null;
2592N/A cap *= 2;
2592N/A if (cap > 80000) cap = 80000;
2592N/A v = new Vector< byte[] >(cap);
2592N/A }
2592N/A }
2592N/A }
2592N/A}
2592N/A__EOF__
2592N/A
2592N/Amsgsuccess="succeeded"
2592N/Amsgfail="failed"
2592N/Agclogsize="16K"
2592N/Afilesize=$((16*1024))
4503N/A${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${testname}.java > $NULL 2>&1
2592N/A
2592N/Aif [ $? != 0 ]; then
4503N/A echo "${COMPILEJAVA}/bin/javac ${testname}.java $fail"
2592N/A exit -1
2592N/Afi
2592N/A
2592N/A# test for 2 minutes, it will complete circulation of gc log rotation
2592N/Atts=2
2592N/Alogfile="test.log"
2592N/Ahotspotlog="hotspot.log"
2592N/A
2592N/Aif [ -e $logfile ]; then
2592N/A rm -rf $logfile
2592N/Afi
2592N/A
2592N/A#also delete $hotspotlog if it exists
2592N/Aif [ -f $hotspotlog ]; then
2592N/A rm -rf $hotspotlog
2592N/Afi
2592N/A
2592N/Aoptions="-Xloggc:$logfile -XX:+UseConcMarkSweepGC -XX:+PrintGC -XX:+PrintGCDetails -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=1 -XX:GCLogFileSize=$gclogsize"
2592N/Aecho "Test gc log rotation in same file, wait for $tts minutes ...."
4503N/A${TESTJAVA}/bin/java $options $testname $tts
2592N/Aif [ $? != 0 ]; then
2592N/A echo "$msgfail"
2592N/A exit -1
2592N/Afi
2592N/A
2592N/A# rotation file will be $logfile.0
2592N/Aif [ -f $logfile.0 ]; then
2592N/A outfilesize=`ls -l $logfile.0 | awk '{print $5 }'`
2592N/A if [ $((outfilesize)) -ge $((filesize)) ]; then
2592N/A echo $msgsuccess
2592N/A else
2592N/A echo $msgfail
2592N/A fi
2592N/Aelse
2592N/A echo $msgfail
2592N/A exit -1
2592N/Afi
2592N/A
2592N/A# delete log file
2592N/Arm -rf $logfile.0
2592N/Aif [ -f $hotspotlog ]; then
2592N/A rm -rf $hotspotlog
2592N/Afi
2592N/A
2592N/A#multiple log files
2592N/Anumoffiles=3
2592N/Aoptions="-Xloggc:$logfile -XX:+UseConcMarkSweepGC -XX:+PrintGC -XX:+PrintGCDetails -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=$numoffiles -XX:GCLogFileSize=$gclogsize"
2592N/Aecho "Test gc log rotation in $numoffiles files, wait for $tts minutes ...."
4503N/A${TESTJAVA}/bin/java $options $testname $tts
2592N/Aif [ $? != 0 ]; then
2592N/A echo "$msgfail"
2592N/A exit -1
2592N/Afi
2592N/A
2592N/Aatleast=0 # at least size of numoffile-1 files >= $gclogsize
2592N/Atk=0
2592N/Awhile [ $(($tk)) -lt $(($numoffiles)) ]
2592N/Ado
2592N/A if [ -f $logfile.$tk ]; then
2592N/A outfilesize=`ls -l $logfile.$tk | awk '{ print $5 }'`
2592N/A if [ $(($outfilesize)) -ge $(($filesize)) ]; then
2592N/A atleast=$((atleast+1))
2592N/A fi
2592N/A fi
2592N/A tk=$((tk+1))
2592N/Adone
2592N/A
2592N/Arm -rf $logfile.*
2592N/Arm -rf $testname.*
2592N/Arm -rf $hotspotlog
2592N/A
2592N/Aif [ $(($atleast)) -ge $(($numoffiles-1)) ]; then
2592N/A echo $msgsuccess
2592N/Aelse
2592N/A echo $msgfail
2592N/A exit -1
2592N/Afi