hotspot/test/runtime/modules/IgnoreModulePropertiesTest.java
author alanb
Fri, 10 Feb 2017 09:03:55 +0000
changeset 43665 4bb003cad9b9
parent 42904 15a62ca574e9
child 44317 03d9626d3874
permissions -rw-r--r--
8173393: Module system implementation refresh (2/2017) Reviewed-by: lfoltan, acorn, mchung Contributed-by: alan.bateman@oracle.com, george.triantafillou@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40244
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
     1
/*
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
     4
 *
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
     8
 *
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    13
 * accompanied this code).
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    14
 *
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    18
 *
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    21
 * questions.
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    22
 */
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    23
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    24
/*
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    25
 * @test
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    26
 * @bug 8136930
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    27
 * @summary Test that the VM ignores explicitly specified module internal properties.
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    28
 * @modules java.base/jdk.internal.misc
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40244
diff changeset
    29
 * @library /test/lib
40244
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    30
 */
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    31
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40244
diff changeset
    32
import jdk.test.lib.process.OutputAnalyzer;
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40244
diff changeset
    33
import jdk.test.lib.process.ProcessTools;
40244
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    34
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    35
// Test that the VM ignores module related properties such as "jdk.module.addmods"
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    36
// and jdk.module.addreads.0" that can only be set using module options.
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    37
public class IgnoreModulePropertiesTest {
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    38
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    39
    // Test that the specified property and its value are ignored.  If the VM accepted
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    40
    // the property and value then an exception would be thrown because the value is
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    41
    // bogus for that property.  But, since the property is ignored no exception is
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    42
    // thrown.
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    43
    public static void testProperty(String prop, String value) throws Exception {
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    44
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    45
            "-D" + prop + "=" + value, "-version");
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    46
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    47
        output.shouldContain("java version ");
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    48
        output.shouldHaveExitValue(0);
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    49
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    50
        // Ensure that the property and its value aren't available.
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    51
        if (System.getProperty(prop) != null) {
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    52
            throw new RuntimeException(
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    53
                "Unexpected non-null value for property " + prop);
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    54
        }
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    55
    }
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    56
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    57
    // For options of the form "option=value", check that an exception gets thrown for
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    58
    // the illegal value and then check that its corresponding property is handled
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    59
    // correctly.
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    60
    public static void testOption(String option, String value,
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    61
                                  String prop, String result) throws Exception {
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    62
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    63
            option + "=" + value, "-version");
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    64
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    65
        output.shouldContain(result);
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    66
        testProperty(prop, value);
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    67
    }
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    68
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    69
    public static void main(String[] args) throws Exception {
43665
4bb003cad9b9 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42904
diff changeset
    70
        testOption("--add-modules", "java.sqlx", "jdk.module.addmods.0", "java.lang.module.FindException");
4bb003cad9b9 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42904
diff changeset
    71
        testOption("--limit-modules", "java.sqlx", "jdk.module.limitmods", "java.lang.module.FindException");
41466
64ceb6e0264a 8167511: IgnoreModulePropertiesTest.java needs update for JDK-8162401
mchung
parents: 40631
diff changeset
    72
        testOption("--add-reads", "xyzz=yyzd", "jdk.module.addreads.0", "WARNING: Unknown module: xyzz");
64ceb6e0264a 8167511: IgnoreModulePropertiesTest.java needs update for JDK-8162401
mchung
parents: 40631
diff changeset
    73
        testOption("--add-exports", "java.base/xyzz=yyzd", "jdk.module.addexports.0",
64ceb6e0264a 8167511: IgnoreModulePropertiesTest.java needs update for JDK-8162401
mchung
parents: 40631
diff changeset
    74
                   "WARNING: package xyzz not in java.base");
42904
15a62ca574e9 8171815: [TESTBUG] Update expected failure message in runtime/modules/IgnoreModulePropertiesTest.java
dholmes
parents: 42307
diff changeset
    75
        testOption("--patch-module", "=d", "jdk.module.patch.0", "Unable to parse --patch-module");
40244
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    76
    }
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    77
}