test6941923.sh 3.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
##
## @test @(#)test6941923.sh
## @bug 6941923 
## @summary test new added flags for gc log rotation 
## @author yqi 
## @run shell test6941923.sh
##

## skip on windows
OS=`uname -s`
case "$OS" in
  SunOS | Linux )
    NULL=/dev/null
    PS=":"
    FS="/"
    ;;
  Windows_* )
    echo "Test skipped for Windows"
    exit 0 
    ;;
  * )
    echo "Unrecognized system!"
    exit 1;
    ;;
esac

if [ "${JAVA_HOME}" = "" ]
then
  echo "JAVA_HOME not set"
  exit 0
fi

$JAVA_HOME/bin/java -version > $NULL 2>&1

if [ $? != 0 ]; then
  echo "Wrong JAVA_HOME? JAVA_HOME: $JAVA_HOME"
  exit $?
fi

# create a small test case
testname="Test"
if [ -e ${testname}.java ]; then
  rm -rf ${testname}.*
fi

cat >> ${testname}.java << __EOF__
import java.util.Vector;

public class Test implements Runnable
{
  private boolean _should_stop = false;

  public static void main(String[] args) throws Exception {

    long limit = Long.parseLong(args[0]) * 60L * 1000L;   // minutes
    Test t = new Test();
    t.set_stop(false);
    Thread thr = new Thread(t);
    thr.start();

    long time1 = System.currentTimeMillis();
    long time2 = System.currentTimeMillis();
    while (time2 - time1 < limit) {
      try {
        Thread.sleep(2000); // 2 seconds
      }
      catch(Exception e) {}
      time2 = System.currentTimeMillis();
      System.out.print("\r... " + (time2 - time1)/1000 + " seconds");
    }
    System.out.println();
    t.set_stop(true);
  }
  public void set_stop(boolean value) { _should_stop = value; }
  public void run() {
    int cap = 20000;
    int fix_size = 2048;
    int loop = 0;
    Vector< byte[] > v = new Vector< byte[] >(cap);
    while(!_should_stop) {
      byte[] g = new byte[fix_size];
      v.add(g);
      loop++;
      if (loop > cap) {
         v = null;
         cap *= 2;
         if (cap > 80000) cap = 80000;
         v = new Vector< byte[] >(cap);
      }
    }
  }
}
__EOF__

msgsuccess="succeeded"
msgfail="failed"
gclogsize="16K"
filesize=$((16*1024))
$JAVA_HOME/bin/javac ${testname}.java > $NULL 2>&1

if [ $? != 0 ]; then
  echo "$JAVA_HOME/bin/javac ${testname}.java $fail"
  exit -1
fi

# test for 2 minutes, it will complete circulation of gc log rotation
tts=2
logfile="test.log"
hotspotlog="hotspot.log"

if [ -e $logfile  ]; then
  rm -rf $logfile
fi

#also delete $hotspotlog if it exists
if [ -f $hotspotlog ]; then 
  rm -rf $hotspotlog
fi

options="-Xloggc:$logfile -XX:+UseConcMarkSweepGC -XX:+PrintGC -XX:+PrintGCDetails -XX:+UseGCLogFileRotation  -XX:NumberOfGCLogFiles=1 -XX:GCLogFileSize=$gclogsize"
echo "Test gc log rotation in same file, wait for $tts minutes ...."
$JAVA_HOME/bin/java $options $testname $tts
if [ $? != 0 ]; then
  echo "$msgfail"
  exit -1
fi

# rotation file will be $logfile.0 
if [ -f $logfile.0 ]; then
  outfilesize=`ls -l $logfile.0 | awk '{print $5 }'`
  if [ $((outfilesize)) -ge $((filesize)) ]; then
    echo $msgsuccess
  else
    echo $msgfail
  fi
else 
  echo $msgfail
  exit -1
fi

# delete log file 
rm -rf $logfile.0
if [ -f $hotspotlog ]; then
  rm -rf $hotspotlog
fi

#multiple log files
numoffiles=3
options="-Xloggc:$logfile -XX:+UseConcMarkSweepGC -XX:+PrintGC -XX:+PrintGCDetails -XX:+UseGCLogFileRotation  -XX:NumberOfGCLogFiles=$numoffiles -XX:GCLogFileSize=$gclogsize"
echo "Test gc log rotation in $numoffiles files, wait for $tts minutes ...."
$JAVA_HOME/bin/java $options $testname $tts
if [ $? != 0 ]; then
  echo "$msgfail"
  exit -1
fi

atleast=0    # at least size of numoffile-1 files >= $gclogsize
tk=0
while [ $(($tk)) -lt $(($numoffiles)) ]
do
  if [ -f $logfile.$tk ]; then
    outfilesize=`ls -l $logfile.$tk | awk '{ print $5 }'`
    if [ $(($outfilesize)) -ge $(($filesize)) ]; then
      atleast=$((atleast+1))
    fi
  fi
  tk=$((tk+1))
done

rm -rf $logfile.*
rm -rf $testname.*
rm -rf $hotspotlog

if [ $(($atleast)) -ge $(($numoffiles-1)) ]; then
  echo $msgsuccess
else
  echo $msgfail
  exit -1
fi