--- /dev/null 2015-01-17 02:57:05.640001672 +0300 +++ new/test/gc/logging/TestPrintGCTimeStampsEnabled.java 2015-01-20 17:14:20.593425896 +0300 @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2015, 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. + */ + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import com.oracle.java.testlibrary.Asserts; + +/* + * @test TestPrintGCTimeStampsEnabled + * @summary test checks -XX:+PrintGCDateStamps enables date stamps printing + * @key gc + * @library /testlibrary + * @run main/othervm -Xmx128M -Xloggc:PrintGCTimeStampsEnabled.txt -XX:+PrintGC -XX:+PrintGCTimeStamps GCTask + * @run main TestPrintGCTimeStampsEnabled + */ +public class TestPrintGCTimeStampsEnabled extends AbstractPrintGCTest { + + public void runTest() { + String content = getContent(); + Pattern pattern = Pattern.compile("^(\\d+\\.\\d+):.*\\[GC", Pattern.MULTILINE); + Matcher matcher = pattern.matcher(content); + float gcLastRunTimestamp = 0.0f; + while (matcher.find()) { + String match = matcher.group(1); + float timestamp = Float.parseFloat(match); + Asserts.assertGreaterThanOrEqual(timestamp, gcLastRunTimestamp, + "GC timestamps are inconsistent"); + gcLastRunTimestamp = timestamp; + } + } + + public static void main(String[] args) { + new TestPrintGCTimeStampsEnabled().runTest(); + } +}