test/jdk/tools/launcher/LauncherMessageTest.java
author mr
Wed, 16 Jan 2019 16:27:21 -0800
changeset 53372 4003935e6e5f
parent 47216 71c04702a3d5
permissions -rw-r--r--
8216532: tools/launcher/Test7029048.java fails (Solaris) Reviewed-by: rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43496
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
     1
/*
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
     4
 *
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
     7
 * published by the Free Software Foundation.
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
     8
 *
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    13
 * accompanied this code).
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    14
 *
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    18
 *
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    21
 * questions.
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    22
 */
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    23
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    24
/**
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    25
 * @test
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    26
 * @bug 8167063
45286
cd809e28c082 8180887: move FileUtils to top level testlibrary
iignatyev
parents: 43496
diff changeset
    27
 * @library /test/lib
45944
882cea808912 8179292: a number of launcher tests fail when run with --limit-modules due to CNFE: javax.tools.ToolProvider
anazarov
parents: 45467
diff changeset
    28
 * @modules jdk.compiler
882cea808912 8179292: a number of launcher tests fail when run with --limit-modules due to CNFE: javax.tools.ToolProvider
anazarov
parents: 45467
diff changeset
    29
 *          jdk.zipfs
45467
99c87a16a8e4 8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents: 45286
diff changeset
    30
 * @build jdk.test.lib.Platform
99c87a16a8e4 8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents: 45286
diff changeset
    31
 *        jdk.test.lib.util.FileUtils
43496
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    32
 * @run main LauncherMessageTest
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    33
 * @summary LauncherHelper should not throw JNI error for LinkageError
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    34
 */
45286
cd809e28c082 8180887: move FileUtils to top level testlibrary
iignatyev
parents: 43496
diff changeset
    35
43496
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    36
import java.io.File;
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    37
import java.nio.file.Paths;
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    38
import java.util.ArrayList;
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    39
import java.util.List;
45286
cd809e28c082 8180887: move FileUtils to top level testlibrary
iignatyev
parents: 43496
diff changeset
    40
import jdk.test.lib.util.FileUtils;
43496
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    41
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    42
public class LauncherMessageTest {
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    43
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    44
    public static void main(String[] args) throws Exception {
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    45
        String userDir = System.getProperty("user.dir", ".");
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    46
        File testDir = new File(userDir, "test");
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    47
        List<String> srcContent = new ArrayList<>();
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    48
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    49
        // Try to create a test directory before proceeding further
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    50
        if (!testDir.mkdir()) {
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    51
            throw new Exception("Test failed: unable to create"
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    52
                    + " writable working directory "
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    53
                    + testDir.getAbsolutePath());
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    54
        }
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    55
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    56
        // Create test sub-directories for sources, classes and modules respectively
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    57
        File srcA = new File(testDir.getPath(), "srcA");
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    58
        srcA.mkdir();
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    59
        File srcB = new File(testDir.getPath(), "srcB");
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    60
        srcB.mkdir();
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    61
        File classesA = new File(testDir.getPath(), "classesA");
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    62
        classesA.mkdir();
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    63
        File classesB = new File(testDir.getPath(), "classesB");
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    64
        classesB.mkdir();
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    65
        File modules = new File(testDir.getPath(), "modules");
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    66
        modules.mkdir();
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    67
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    68
        // Define content and create module-info.java and corresponding source files
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    69
        File modAinfo = new File(srcA.getPath(), "module-info.java");
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    70
        srcContent.add("module mod.a { exports pkgA; }");
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    71
        TestHelper.createFile(modAinfo, srcContent);
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    72
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    73
        File classA = new File(srcA.getPath(), "ClassA.java");
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    74
        srcContent.clear();
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    75
        srcContent.add("package pkgA; public class ClassA { }");
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    76
        TestHelper.createFile(classA, srcContent);
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    77
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    78
        File modBinfo = new File(srcB.getPath(), "module-info.java");
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    79
        srcContent.clear();
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    80
        srcContent.add("module mod.b { requires mod.a; }");
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    81
        TestHelper.createFile(modBinfo, srcContent);
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    82
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    83
        File classB = new File(srcB.getPath(), "ClassB.java");
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    84
        srcContent.clear();
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    85
        srcContent.add("package pkgB;");
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    86
        srcContent.add("import pkgA.ClassA;");
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    87
        srcContent.add("public class ClassB extends ClassA {");
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    88
        srcContent.add("public static void main(String[] args) { } }");
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    89
        TestHelper.createFile(classB, srcContent);
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    90
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    91
        // Compile all source files and create Jars
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    92
        TestHelper.compile("-d", classesA.getPath(), classA.getPath(), modAinfo.getPath());
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    93
        TestHelper.createJar("cf", Paths.get(modules.getPath(), "mod.a.jar").toString(),
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    94
                "-C", classesA.getPath(), ".");
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    95
        TestHelper.compile("-d", classesB.getPath(), "--module-path", modules.getPath(),
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    96
                classB.getPath(), modBinfo.getPath());
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    97
        TestHelper.createJar("cf", Paths.get(modules.getPath(), "mod.b.jar").toString(),
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    98
                "-C", classesB.getPath(), ".");
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
    99
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   100
        // Delete the module-info.java and Jar file corresponding to mod.a
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   101
        FileUtils.deleteFileWithRetry(Paths.get(modAinfo.getPath()));
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   102
        FileUtils.deleteFileWithRetry(Paths.get(modules.getPath(), "mod.a.jar"));
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   103
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   104
        // Re-create module-info.java (by removing "exports pkgA;")
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   105
        // and corresponding Jar file
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   106
        srcContent.clear();
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   107
        srcContent.add("module mod.a { }");
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   108
        TestHelper.createFile(modAinfo, srcContent);
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   109
        TestHelper.compile("-d", classesA.getPath(), classA.getPath(), modAinfo.getPath());
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   110
        TestHelper.createJar("cf", Paths.get(modules.getPath(), "mod.a.jar").toString(),
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   111
                "-C", classesA.getPath(), ".");
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   112
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   113
        // Execute the main class
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   114
        String[] commands = {TestHelper.javaCmd, "--module-path", modules.getPath(),
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   115
            "-m", "mod.b/pkgB.ClassB"};
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   116
        TestHelper.TestResult result = TestHelper.doExec(commands);
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   117
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   118
        // Clean the test directory and check test status
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   119
        FileUtils.deleteFileTreeWithRetry(Paths.get(testDir.getPath()));
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   120
        if (result.isOK()) {
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   121
            throw new Exception("Test Passed Unexpectedly!");
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   122
        } else {
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   123
            result.testOutput.forEach(System.err::println);
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   124
            if (result.contains("JNI error")) {
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   125
                throw new Exception("Test Failed with JNI error!");
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   126
            }
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   127
        }
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   128
        System.out.println("Test passes, failed with expected error message");
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   129
    }
fbafb9f36e96 8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
diff changeset
   130
}