test/jdk/sun/tools/jcmd/JcmdOutputEncodingTest.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 57564 0a8436eda2fa
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
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;
57564
0a8436eda2fa 8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents: 55758
diff changeset
    25
import java.nio.charset.Charset;
0a8436eda2fa 8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents: 55758
diff changeset
    26
import java.nio.charset.StandardCharsets;
55758
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    27
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    28
import jdk.test.lib.process.OutputAnalyzer;
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    29
import jdk.test.lib.process.ProcessTools;
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    30
import jdk.test.lib.JDKToolLauncher;
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    31
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    32
/*
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    33
 * @test
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    34
 * @bug 8222491
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    35
 * @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
    36
 * @library /test/lib
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    37
 * @run main 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 class JcmdOutputEncodingTest {
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    40
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    41
    public static void main(String[] args) throws Exception {
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    42
        testThreadDump();
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    43
    }
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    44
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    45
    private static void testThreadDump() throws Exception {
57564
0a8436eda2fa 8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents: 55758
diff changeset
    46
        String marker = "markerName" + "\u00e4\u0bb5".repeat(60);
0a8436eda2fa 8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents: 55758
diff changeset
    47
        Charset cs = StandardCharsets.UTF_8;
0a8436eda2fa 8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents: 55758
diff changeset
    48
        Thread.currentThread().setName(marker);
55758
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    49
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    50
        JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jcmd");
57564
0a8436eda2fa 8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents: 55758
diff changeset
    51
        launcher.addVMArg("-Dfile.encoding=" + cs);
55758
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    52
        launcher.addToolArg(Long.toString(ProcessTools.getProcessId()));
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    53
        launcher.addToolArg("Thread.print");
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    54
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    55
        ProcessBuilder processBuilder = new ProcessBuilder();
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    56
        processBuilder.command(launcher.getCommand());
57564
0a8436eda2fa 8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents: 55758
diff changeset
    57
        OutputAnalyzer output = ProcessTools.executeProcess(processBuilder, null, cs);
55758
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    58
        output.shouldHaveExitValue(0);
57564
0a8436eda2fa 8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents: 55758
diff changeset
    59
        output.shouldContain(marker);
55758
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    60
    }
bbe9c361a477 8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
diff changeset
    61
}