提交 a69246cd 编写于 作者: M mgerdin

8009808: TEST-BUG : test case is using bash style tests. Default shell for...

8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
Summary: Rewrite test to use Java only instead of shell script
Reviewed-by: mgerdin, brutisso
Contributed-by: leonid.mesnik@oracle.com
上级 0ec6a45b
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test Test6941923.java
* @bug 6941923
* @summary test flags for gc log rotation
* @library /testlibrary
* @run main/othervm/timeout=600 Test6941923
*
*/
import com.oracle.java.testlibrary.*;
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.Arrays;
class GCLoggingGenerator {
public static void main(String[] args) throws Exception {
long sizeOfLog = Long.parseLong(args[0]);
long lines = sizeOfLog / 80;
// full.GC generates ad least 1-line which is not shorter then 80 chars
// for some GC 2 shorter lines are generated
for (long i = 0; i < lines; i++) {
System.gc();
}
}
}
public class Test6941923 {
static final File currentDirectory = new File(".");
static final String logFileName = "test.log";
static final int logFileSizeK = 16;
static FilenameFilter logFilter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.startsWith(logFileName);
}
};
public static void cleanLogs() {
for (File log : currentDirectory.listFiles(logFilter)) {
if (!log.delete()) {
throw new Error("Unable to delete " + log.getAbsolutePath());
}
}
}
public static void runTest(int numberOfFiles) throws Exception {
ArrayList<String> args = new ArrayList();
String[] logOpts = new String[]{
"-cp", System.getProperty("java.class.path"),
"-Xloggc:" + logFileName,
"-XX:-DisableExplicitGC", // to sure that System.gc() works
"-XX:+PrintGC", "-XX:+PrintGCDetails", "-XX:+UseGCLogFileRotation",
"-XX:NumberOfGCLogFiles=" + numberOfFiles,
"-XX:GCLogFileSize=" + logFileSizeK + "K", "-Xmx128M"};
// System.getProperty("test.java.opts") is '' if no options is set
// need to skip such empty
String[] externalVMopts = System.getProperty("test.java.opts").length() == 0
? new String[0]
: System.getProperty("test.java.opts").split(" ");
args.addAll(Arrays.asList(externalVMopts));
args.addAll(Arrays.asList(logOpts));
args.add(GCLoggingGenerator.class.getName());
args.add(String.valueOf(numberOfFiles * logFileSizeK * 1024));
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args.toArray(new String[0]));
pb.redirectErrorStream(true);
pb.redirectOutput(new File(GCLoggingGenerator.class.getName() + ".log"));
Process process = pb.start();
int result = process.waitFor();
if (result != 0) {
throw new Error("Unexpected exit code = " + result);
}
File[] logs = currentDirectory.listFiles(logFilter);
int smallFilesNumber = 0;
for (File log : logs) {
if (log.length() < logFileSizeK * 1024) {
smallFilesNumber++;
}
}
if (logs.length != numberOfFiles) {
throw new Error("There are only " + logs.length + " logs instead " + numberOfFiles);
}
if (smallFilesNumber > 1) {
throw new Error("There should maximum one log with size < " + logFileSizeK + "K");
}
}
public static void main(String[] args) throws Exception {
cleanLogs();
runTest(1);
cleanLogs();
runTest(3);
cleanLogs();
}
}
##
## @test @(#)test6941923.sh
## @bug 6941923
## @summary test new added flags for gc log rotation
## @author yqi
## @run shell test6941923.sh
##
## some tests require path to find test source dir
if [ "${TESTSRC}" = "" ]
then
TESTSRC=${PWD}
echo "TESTSRC not set. Using "${TESTSRC}" as default"
fi
echo "TESTSRC=${TESTSRC}"
## Adding common setup Variables for running shell tests.
. ${TESTSRC}/../../test_env.sh
## skip on windows
OS=`uname -s`
case "$OS" in
Windows_* | CYGWIN_* )
echo "Test skipped for Windows"
exit 0
;;
esac
# 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))
${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${testname}.java > $NULL 2>&1
if [ $? != 0 ]; then
echo "${COMPILEJAVA}/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 ...."
${TESTJAVA}/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 ...."
${TESTJAVA}/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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册