test/jdk/tools/launcher/TestXcheckJNIWarnings.java
author mr
Wed, 16 Jan 2019 16:27:21 -0800
changeset 53372 4003935e6e5f
parent 47251 4fe50ead4783
permissions -rw-r--r--
8216532: tools/launcher/Test7029048.java fails (Solaris) Reviewed-by: rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47251
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
     1
/*
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
     4
 *
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
     8
 *
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    13
 * accompanied this code).
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    14
 *
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    18
 *
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    21
 * questions.
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    22
 */
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    23
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    24
import java.io.File;
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    25
import java.io.IOException;
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    26
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    27
/**
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    28
 * @test
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    29
 * @bug 8187442
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    30
 * @summary Launching app shouldn't produce any jni warnings.
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    31
 * @modules jdk.compiler
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    32
 *          jdk.zipfs
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    33
 * @compile TestXcheckJNIWarnings.java
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    34
 * @run main TestXcheckJNIWarnings
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    35
 */
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    36
public final class TestXcheckJNIWarnings extends TestHelper {
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    37
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    38
    static void createJarFile(File testJar) throws IOException {
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    39
        StringBuilder tsrc = new StringBuilder();
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    40
        tsrc.append("public static void main(String... args) {\n");
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    41
        tsrc.append("    System.out.println(\"Hello World\");\n");
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    42
        tsrc.append("}\n");
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    43
        createJar(testJar, new File("Foo"), tsrc.toString());
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    44
    }
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    45
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    46
    public static void main(String... args) throws IOException {
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    47
        File testJarFile = new File("test.jar");
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    48
        createJarFile(testJarFile);
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    49
        TestResult tr = doExec(javaCmd, "-jar", "-Xcheck:jni",
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    50
                               testJarFile.getName());
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    51
        if (!tr.isOK()) {
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    52
            System.out.println(tr);
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    53
            throw new RuntimeException("test returned non-positive value");
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    54
        }
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    55
        if (!tr.contains("Hello World")) {
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    56
            System.out.println(tr);
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    57
            throw new RuntimeException("expected output not found");
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    58
        }
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    59
        if (tr.contains("WARNING")) {
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    60
            System.out.println(tr);
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    61
            throw new RuntimeException("WARNING was found in the output");
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    62
        }
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    63
    }
4fe50ead4783 8187442: Xcheck:jni produces various "WARNING in native method" in launcher
serb
parents:
diff changeset
    64
}