aoqi@0: /* aoqi@0: * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: /* aoqi@0: * @test Test6941923.java aoqi@0: * @bug 6941923 aoqi@0: * @summary test flags for gc log rotation aoqi@0: * @library /testlibrary aoqi@0: * @run main/othervm/timeout=600 Test6941923 aoqi@0: * aoqi@0: */ aoqi@0: import com.oracle.java.testlibrary.*; aoqi@0: import java.io.File; aoqi@0: import java.io.FilenameFilter; aoqi@0: import java.util.ArrayList; aoqi@0: import java.util.Arrays; aoqi@0: aoqi@0: class GCLoggingGenerator { aoqi@0: aoqi@0: public static void main(String[] args) throws Exception { aoqi@0: aoqi@0: long sizeOfLog = Long.parseLong(args[0]); aoqi@0: long lines = sizeOfLog / 80; aoqi@0: // full.GC generates ad least 1-line which is not shorter then 80 chars aoqi@0: // for some GC 2 shorter lines are generated aoqi@0: for (long i = 0; i < lines; i++) { aoqi@0: System.gc(); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public class Test6941923 { aoqi@0: aoqi@0: static final File currentDirectory = new File("."); aoqi@0: static final String logFileName = "test.log"; aoqi@0: static final int logFileSizeK = 16; aoqi@0: static FilenameFilter logFilter = new FilenameFilter() { aoqi@0: @Override aoqi@0: public boolean accept(File dir, String name) { aoqi@0: return name.startsWith(logFileName); aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: public static void cleanLogs() { aoqi@0: for (File log : currentDirectory.listFiles(logFilter)) { aoqi@0: if (!log.delete()) { aoqi@0: throw new Error("Unable to delete " + log.getAbsolutePath()); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public static void runTest(int numberOfFiles) throws Exception { aoqi@0: aoqi@0: ArrayList args = new ArrayList(); aoqi@0: String[] logOpts = new String[]{ aoqi@0: "-cp", System.getProperty("java.class.path"), aoqi@0: "-Xloggc:" + logFileName, aoqi@0: "-XX:-DisableExplicitGC", // to sure that System.gc() works aoqi@0: "-XX:+PrintGC", "-XX:+PrintGCDetails", "-XX:+UseGCLogFileRotation", aoqi@0: "-XX:NumberOfGCLogFiles=" + numberOfFiles, aoqi@0: "-XX:GCLogFileSize=" + logFileSizeK + "K", "-Xmx128M"}; aoqi@0: // System.getProperty("test.java.opts") is '' if no options is set aoqi@0: // need to skip such empty aoqi@0: String[] externalVMopts = System.getProperty("test.java.opts").length() == 0 aoqi@0: ? new String[0] aoqi@0: : System.getProperty("test.java.opts").split(" "); aoqi@0: args.addAll(Arrays.asList(externalVMopts)); aoqi@0: args.addAll(Arrays.asList(logOpts)); aoqi@0: args.add(GCLoggingGenerator.class.getName()); aoqi@0: args.add(String.valueOf(numberOfFiles * logFileSizeK * 1024)); aoqi@0: ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args.toArray(new String[0])); aoqi@0: pb.redirectErrorStream(true); aoqi@0: pb.redirectOutput(new File(GCLoggingGenerator.class.getName() + ".log")); aoqi@0: Process process = pb.start(); aoqi@0: int result = process.waitFor(); aoqi@0: if (result != 0) { aoqi@0: throw new Error("Unexpected exit code = " + result); aoqi@0: } aoqi@0: File[] logs = currentDirectory.listFiles(logFilter); aoqi@0: int smallFilesNumber = 0; aoqi@0: for (File log : logs) { aoqi@0: if (log.length() < logFileSizeK * 1024) { aoqi@0: smallFilesNumber++; aoqi@0: } aoqi@0: } aoqi@0: if (logs.length != numberOfFiles) { aoqi@0: throw new Error("There are only " + logs.length + " logs instead " + numberOfFiles); aoqi@0: } aoqi@0: if (smallFilesNumber > 1) { aoqi@0: throw new Error("There should maximum one log with size < " + logFileSizeK + "K"); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public static void main(String[] args) throws Exception { aoqi@0: cleanLogs(); aoqi@0: runTest(1); aoqi@0: cleanLogs(); aoqi@0: runTest(3); aoqi@0: cleanLogs(); aoqi@0: } aoqi@0: }