Wed, 27 Mar 2013 09:49:51 -0700
8009152: A number of jtreg tests need review/improvement
Summary: Added a new test_env.txt file to capture common shell variable. Added concept of COMPILEJAVA for use when TESTJAVA is a JRE. If COMPILEJAVA not set then TESTJAVA will be the default with assumption it is a JDK.
Reviewed-by: kvn, brutisso, coleenp
1 ##
2 ## @test @(#)test6941923.sh
3 ## @bug 6941923
4 ## @summary test new added flags for gc log rotation
5 ## @author yqi
6 ## @run shell test6941923.sh
7 ##
8 ## some tests require path to find test source dir
9 if [ "${TESTSRC}" = "" ]
10 then
11 TESTSRC=${PWD}
12 echo "TESTSRC not set. Using "${TESTSRC}" as default"
13 fi
14 echo "TESTSRC=${TESTSRC}"
15 ## Adding common setup Variables for running shell tests.
16 . ${TESTSRC}/../../test_env.sh
18 ## skip on windows
19 OS=`uname -s`
20 case "$OS" in
21 Windows_* | CYGWIN_* )
22 echo "Test skipped for Windows"
23 exit 0
24 ;;
25 esac
27 # create a small test case
28 testname="Test"
29 if [ -e ${testname}.java ]; then
30 rm -rf ${testname}.*
31 fi
33 cat >> ${testname}.java << __EOF__
34 import java.util.Vector;
36 public class Test implements Runnable
37 {
38 private boolean _should_stop = false;
40 public static void main(String[] args) throws Exception {
42 long limit = Long.parseLong(args[0]) * 60L * 1000L; // minutes
43 Test t = new Test();
44 t.set_stop(false);
45 Thread thr = new Thread(t);
46 thr.start();
48 long time1 = System.currentTimeMillis();
49 long time2 = System.currentTimeMillis();
50 while (time2 - time1 < limit) {
51 try {
52 Thread.sleep(2000); // 2 seconds
53 }
54 catch(Exception e) {}
55 time2 = System.currentTimeMillis();
56 System.out.print("\r... " + (time2 - time1)/1000 + " seconds");
57 }
58 System.out.println();
59 t.set_stop(true);
60 }
61 public void set_stop(boolean value) { _should_stop = value; }
62 public void run() {
63 int cap = 20000;
64 int fix_size = 2048;
65 int loop = 0;
66 Vector< byte[] > v = new Vector< byte[] >(cap);
67 while(!_should_stop) {
68 byte[] g = new byte[fix_size];
69 v.add(g);
70 loop++;
71 if (loop > cap) {
72 v = null;
73 cap *= 2;
74 if (cap > 80000) cap = 80000;
75 v = new Vector< byte[] >(cap);
76 }
77 }
78 }
79 }
80 __EOF__
82 msgsuccess="succeeded"
83 msgfail="failed"
84 gclogsize="16K"
85 filesize=$((16*1024))
86 ${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${testname}.java > $NULL 2>&1
88 if [ $? != 0 ]; then
89 echo "${COMPILEJAVA}/bin/javac ${testname}.java $fail"
90 exit -1
91 fi
93 # test for 2 minutes, it will complete circulation of gc log rotation
94 tts=2
95 logfile="test.log"
96 hotspotlog="hotspot.log"
98 if [ -e $logfile ]; then
99 rm -rf $logfile
100 fi
102 #also delete $hotspotlog if it exists
103 if [ -f $hotspotlog ]; then
104 rm -rf $hotspotlog
105 fi
107 options="-Xloggc:$logfile -XX:+UseConcMarkSweepGC -XX:+PrintGC -XX:+PrintGCDetails -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=1 -XX:GCLogFileSize=$gclogsize"
108 echo "Test gc log rotation in same file, wait for $tts minutes ...."
109 ${TESTJAVA}/bin/java $options $testname $tts
110 if [ $? != 0 ]; then
111 echo "$msgfail"
112 exit -1
113 fi
115 # rotation file will be $logfile.0
116 if [ -f $logfile.0 ]; then
117 outfilesize=`ls -l $logfile.0 | awk '{print $5 }'`
118 if [ $((outfilesize)) -ge $((filesize)) ]; then
119 echo $msgsuccess
120 else
121 echo $msgfail
122 fi
123 else
124 echo $msgfail
125 exit -1
126 fi
128 # delete log file
129 rm -rf $logfile.0
130 if [ -f $hotspotlog ]; then
131 rm -rf $hotspotlog
132 fi
134 #multiple log files
135 numoffiles=3
136 options="-Xloggc:$logfile -XX:+UseConcMarkSweepGC -XX:+PrintGC -XX:+PrintGCDetails -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=$numoffiles -XX:GCLogFileSize=$gclogsize"
137 echo "Test gc log rotation in $numoffiles files, wait for $tts minutes ...."
138 ${TESTJAVA}/bin/java $options $testname $tts
139 if [ $? != 0 ]; then
140 echo "$msgfail"
141 exit -1
142 fi
144 atleast=0 # at least size of numoffile-1 files >= $gclogsize
145 tk=0
146 while [ $(($tk)) -lt $(($numoffiles)) ]
147 do
148 if [ -f $logfile.$tk ]; then
149 outfilesize=`ls -l $logfile.$tk | awk '{ print $5 }'`
150 if [ $(($outfilesize)) -ge $(($filesize)) ]; then
151 atleast=$((atleast+1))
152 fi
153 fi
154 tk=$((tk+1))
155 done
157 rm -rf $logfile.*
158 rm -rf $testname.*
159 rm -rf $hotspotlog
161 if [ $(($atleast)) -ge $(($numoffiles-1)) ]; then
162 echo $msgsuccess
163 else
164 echo $msgfail
165 exit -1
166 fi