test/jdk/sun/tools/jcmd/JcmdOutputEncodingTest.java
author rschmelter
Mon, 22 Jul 2019 14:40:00 +0200
changeset 55758 bbe9c361a477
child 57564 0a8436eda2fa
permissions -rw-r--r--
8227868: jinfo and jstack can fail converting UTF8 output to strings Reviewed-by: sgehwolf, dholmes, cjplummer
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55758
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
     1
/*
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
     4
 *
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
     7
 * published by the Free Software Foundation.
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
     8
 *
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    13
 * accompanied this code).
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    14
 *
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    18
 *
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    21
 * questions.
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    22
 */
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    23
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    24
import java.util.Arrays;
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    25
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    26
import jdk.test.lib.process.OutputAnalyzer;
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    27
import jdk.test.lib.process.ProcessTools;
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    28
import jdk.test.lib.JDKToolLauncher;
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    29
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    30
/*
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    31
 * @test
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    32
 * @bug 8222491
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    33
 * @summary Tests if we handle the encoding of jcmd output correctly.
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    34
 * @library /test/lib
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    35
 * @run main JcmdOutputEncodingTest
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    36
 */
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    37
public class JcmdOutputEncodingTest {
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    38
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    39
    public static void main(String[] args) throws Exception {
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    40
        testThreadDump();
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    41
    }
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    42
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    43
    private static void testThreadDump() throws Exception {
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    44
        String markerName = "markerName" + "\u00e4\u0bb5".repeat(10_000);
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    45
        Thread.currentThread().setName(markerName);
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    46
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    47
        JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jcmd");
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    48
        launcher.addToolArg(Long.toString(ProcessTools.getProcessId()));
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    49
        launcher.addToolArg("Thread.print");
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    50
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    51
        ProcessBuilder processBuilder = new ProcessBuilder();
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    52
        processBuilder.command(launcher.getCommand());
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    53
        OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    54
        output.shouldHaveExitValue(0);
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    55
        output.shouldContain(markerName);
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    56
    }
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    57
}