hotspot/test/gc/6941923/Test6941923.java
author ccheung
Fri, 04 Oct 2013 21:00:43 -0700
changeset 20384 49bfb2ec8f8f
parent 16683 275523a3b451
child 22234 da823d78ad65
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16683
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
     1
/*
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
     4
 *
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
     7
 * published by the Free Software Foundation.
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
     8
 *
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    13
 * accompanied this code).
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    14
 *
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    18
 *
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    21
 * questions.
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    22
 */
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    23
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    24
/*
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    25
 * @test Test6941923.java
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    26
 * @bug 6941923
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    27
 * @summary test flags for gc log rotation
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    28
 * @library /testlibrary
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    29
 * @run main/othervm/timeout=600 Test6941923
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    30
 *
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    31
 */
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    32
import com.oracle.java.testlibrary.*;
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    33
import java.io.File;
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    34
import java.io.FilenameFilter;
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    35
import java.util.ArrayList;
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    36
import java.util.Arrays;
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    37
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    38
class GCLoggingGenerator {
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    39
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    40
    public static void main(String[] args) throws Exception {
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    41
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    42
        long sizeOfLog = Long.parseLong(args[0]);
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    43
        long lines = sizeOfLog / 80;
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    44
        // full.GC generates ad least 1-line which is not shorter then 80 chars
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    45
        // for some GC 2 shorter lines are generated
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    46
        for (long i = 0; i < lines; i++) {
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    47
            System.gc();
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    48
        }
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    49
    }
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    50
}
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    51
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    52
public class Test6941923 {
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    53
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    54
    static final File currentDirectory = new File(".");
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    55
    static final String logFileName = "test.log";
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    56
    static final int logFileSizeK = 16;
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    57
    static FilenameFilter logFilter = new FilenameFilter() {
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    58
        @Override
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    59
        public boolean accept(File dir, String name) {
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    60
            return name.startsWith(logFileName);
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    61
        }
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    62
    };
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    63
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    64
    public static void cleanLogs() {
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    65
        for (File log : currentDirectory.listFiles(logFilter)) {
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    66
            if (!log.delete()) {
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    67
                throw new Error("Unable to delete " + log.getAbsolutePath());
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    68
            }
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    69
        }
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    70
    }
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    71
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    72
    public static void runTest(int numberOfFiles) throws Exception {
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    73
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    74
        ArrayList<String> args = new ArrayList();
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    75
        String[] logOpts = new String[]{
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    76
            "-cp", System.getProperty("java.class.path"),
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    77
            "-Xloggc:" + logFileName,
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    78
            "-XX:-DisableExplicitGC", // to sure that System.gc() works
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    79
            "-XX:+PrintGC", "-XX:+PrintGCDetails", "-XX:+UseGCLogFileRotation",
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    80
            "-XX:NumberOfGCLogFiles=" + numberOfFiles,
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    81
            "-XX:GCLogFileSize=" + logFileSizeK + "K", "-Xmx128M"};
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    82
        // System.getProperty("test.java.opts") is '' if no options is set
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    83
        // need to skip such empty
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    84
        String[] externalVMopts = System.getProperty("test.java.opts").length() == 0
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    85
                ? new String[0]
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    86
                : System.getProperty("test.java.opts").split(" ");
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    87
        args.addAll(Arrays.asList(externalVMopts));
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    88
        args.addAll(Arrays.asList(logOpts));
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    89
        args.add(GCLoggingGenerator.class.getName());
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    90
        args.add(String.valueOf(numberOfFiles * logFileSizeK * 1024));
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    91
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args.toArray(new String[0]));
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    92
        pb.redirectErrorStream(true);
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    93
        pb.redirectOutput(new File(GCLoggingGenerator.class.getName() + ".log"));
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    94
        Process process = pb.start();
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    95
        int result = process.waitFor();
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    96
        if (result != 0) {
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    97
            throw new Error("Unexpected exit code = " + result);
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    98
        }
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
    99
        File[] logs = currentDirectory.listFiles(logFilter);
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
   100
        int smallFilesNumber = 0;
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
   101
        for (File log : logs) {
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
   102
            if (log.length() < logFileSizeK * 1024) {
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
   103
                smallFilesNumber++;
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
   104
            }
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
   105
        }
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
   106
        if (logs.length != numberOfFiles) {
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
   107
            throw new Error("There are only " + logs.length + " logs instead " + numberOfFiles);
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
   108
        }
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
   109
        if (smallFilesNumber > 1) {
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
   110
            throw new Error("There should maximum one log with size < " + logFileSizeK + "K");
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
   111
        }
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
   112
    }
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
   113
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
   114
    public static void main(String[] args) throws Exception {
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
   115
        cleanLogs();
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
   116
        runTest(1);
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
   117
        cleanLogs();
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
   118
        runTest(3);
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
   119
        cleanLogs();
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
   120
    }
275523a3b451 8009808: TEST-BUG : test case is using bash style tests. Default shell for jtreg is bourne. thus failure
mgerdin
parents:
diff changeset
   121
}