test/jdk/jdk/jfr/tool/TestPrint.java
author egahlin
Wed, 05 Dec 2018 16:40:12 +0100
changeset 52850 f527b24990d7
child 52888 9607fb16ccfe
permissions -rw-r--r--
8205516: JFR tool Reviewed-by: mgronlun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
52850
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
     1
/*
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
     2
 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
     4
 *
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    10
 *
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    15
 * accompanied this code).
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    16
 *
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    20
 *
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    23
 * questions.
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    24
 */
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    25
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    26
package jdk.jfr.tool;
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    27
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    28
import java.io.FileWriter;
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    29
import java.nio.file.Files;
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    30
import java.nio.file.Path;
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    31
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    32
import jdk.test.lib.Utils;
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    33
import jdk.test.lib.process.OutputAnalyzer;
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    34
import jdk.test.lib.process.ProcessTools;
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    35
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    36
/**
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    37
 * @test
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    38
 * @summary Test jfr print
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    39
 * @key jfr
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    40
 * @requires vm.hasJFR
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    41
 * @library /test/lib /test/jdk
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    42
 * @run main/othervm jdk.jfr.tool.TestPrint
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    43
 */
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    44
public class TestPrint {
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    45
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    46
    public static void main(String[] args) throws Throwable {
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    47
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    48
        OutputAnalyzer output = ProcessTools.executeProcess("jfr", "print");
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    49
        output.shouldContain("missing file");
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    50
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    51
        output = ProcessTools.executeProcess("jfr", "print", "missing.jfr");
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    52
        output.shouldContain("could not find file ");
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    53
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    54
        Path file = Utils.createTempFile("faked-print-file",  ".jfr");
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    55
        FileWriter fw = new FileWriter(file.toFile());
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    56
        fw.write('d');
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    57
        fw.close();
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    58
        output = ProcessTools.executeProcess("jfr", "print", "--wrongOption", file.toAbsolutePath().toString());
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    59
        output.shouldContain("unknown option");
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    60
        Files.delete(file);
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    61
    }
f527b24990d7 8205516: JFR tool
egahlin
parents:
diff changeset
    62
}