test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/RelativePath.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 57705 7cf02b2c1455
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
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
57705
7cf02b2c1455 8229267: [TESTBUG] Remove unnecessary @modules dependencies in CDS tests
iklam
parents: 57567
diff changeset
    30
 * @modules jdk.jartool/sun.tools.jar
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
    31
 * @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
    32
 * @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
    33
 * @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
    34
 */
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
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
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
    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
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
    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 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
    41
        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
    42
    }
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
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
    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
    45
        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
    46
        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
    47
    }
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
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
    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
    50
        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
    51
        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
    52
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
        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
    54
        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
    55
        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
    56
        // 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
    57
        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
    58
            "-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
    59
            "-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
    60
            "-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
    61
            "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
    62
            .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
    63
                    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
    64
                          .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
    65
                          .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
    66
                });
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
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
        // 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
    69
        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
    70
        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
    71
        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
    72
            "-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
    73
            "-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
    74
            "-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
    75
            ".." + 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
    76
            "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
    77
            .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
    78
                    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
    79
                          .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
    80
                          .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
    81
                });
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
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
}