test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/RelativePath.java
author coleenp
Mon, 29 Jul 2019 10:34:20 -0400
changeset 57567 b000362a89a0
parent 55524 test/hotspot/jtreg/runtime/appcds/dynamicArchive/RelativePath.java@b279ae9843b8
child 57705 7cf02b2c1455
permissions -rw-r--r--
8202339: [TESTBUG] Consolidate the tests in runtime/SharedArchiveFile and runtime/appcds Summary: add top level cds directory and adjust test groups Reviewed-by: mseledtsov, ccheung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55524
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
     1
/*
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
     4
 *
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
     8
 *
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    13
 * accompanied this code).
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    14
 *
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    18
 *
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    21
 * questions.
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    22
 *
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    23
 */
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    24
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    25
/*
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    26
 * @test
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    27
 * @summary Test relative paths specified in the -cp.
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    28
 * @requires vm.cds
57567
b000362a89a0 8202339: [TESTBUG] Consolidate the tests in runtime/SharedArchiveFile and runtime/appcds
coleenp
parents: 55524
diff changeset
    29
 * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
55524
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    30
 * @modules java.base/jdk.internal.misc
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    31
 *          java.management
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    32
 *          jdk.jartool/sun.tools.jar
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    33
 * @compile ../test-classes/Hello.java
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    34
 * @compile ../test-classes/HelloMore.java
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    35
 * @run driver RelativePath
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    36
 */
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    37
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    38
import java.io.File;
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    39
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    40
public class RelativePath extends DynamicArchiveTestBase {
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    41
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    42
    public static void main(String[] args) throws Exception {
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    43
        runTest(AppendClasspath::testDefaultBase);
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    44
    }
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    45
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    46
    static void testDefaultBase() throws Exception {
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    47
        String topArchiveName = getNewArchiveName("top");
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    48
        doTest(topArchiveName);
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    49
    }
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    50
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    51
    private static void doTest(String topArchiveName) throws Exception {
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    52
        String appJar = JarBuilder.getOrCreateHelloJar();
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    53
        String appJar2 = JarBuilder.build("AppendClasspath_HelloMore", "HelloMore");
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    54
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    55
        int idx = appJar.lastIndexOf(File.separator);
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    56
        String jarName = appJar.substring(idx + 1);
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    57
        String jarDir = appJar.substring(0, idx);
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    58
        // relative path starting with "."
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    59
        runWithRelativePath(null, topArchiveName, jarDir,
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    60
            "-Xlog:class+load",
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    61
            "-Xlog:cds+dynamic=debug,cds=debug",
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    62
            "-cp", "." + File.separator + "hello.jar" + File.pathSeparator + appJar2,
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    63
            "HelloMore")
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    64
            .assertNormalExit(output -> {
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    65
                    output.shouldContain("Hello source: shared objects file")
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    66
                          .shouldContain("Hello World ... More")
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    67
                          .shouldHaveExitValue(0);
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    68
                });
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    69
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    70
        // relative path starting with ".."
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    71
        idx = jarDir.lastIndexOf(File.separator);
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    72
        String jarSubDir = jarDir.substring(idx + 1);
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    73
        runWithRelativePath(null, topArchiveName, jarDir,
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    74
            "-Xlog:class+load",
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    75
            "-Xlog:cds+dynamic=debug,cds=debug",
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    76
            "-cp",
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    77
            ".." + File.separator + jarSubDir + File.separator + "hello.jar" + File.pathSeparator + appJar2,
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    78
            "HelloMore")
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    79
            .assertNormalExit(output -> {
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    80
                    output.shouldContain("Hello source: shared objects file")
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    81
                          .shouldContain("Hello World ... More")
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    82
                          .shouldHaveExitValue(0);
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    83
                });
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    84
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    85
    }
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
diff changeset
    86
}