test/hotspot/jtreg/runtime/appcds/DirClasspathTest.java
changeset 54927 1512d88b24c6
parent 51990 6003e034cdd8
equal deleted inserted replaced
54926:d4e7ccaf1445 54927:1512d88b24c6
     1 /*
     1 /*
     2  * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    25 /*
    25 /*
    26  * @test
    26  * @test
    27  * @summary Handling of directories in -cp is based on the classlist
    27  * @summary Handling of directories in -cp is based on the classlist
    28  * @requires vm.cds
    28  * @requires vm.cds
    29  * @library /test/lib
    29  * @library /test/lib
       
    30  * @modules jdk.jartool/sun.tools.jar
    30  * @compile test-classes/Hello.java
    31  * @compile test-classes/Hello.java
       
    32  * @compile test-classes/Super.java
    31  * @run driver DirClasspathTest
    33  * @run driver DirClasspathTest
    32  */
    34  */
    33 
    35 
    34 import jdk.test.lib.Platform;
    36 import jdk.test.lib.Platform;
    35 import jdk.test.lib.process.OutputAnalyzer;
    37 import jdk.test.lib.process.OutputAnalyzer;
    40 import java.util.Arrays;
    42 import java.util.Arrays;
    41 
    43 
    42 public class DirClasspathTest {
    44 public class DirClasspathTest {
    43     private static final int MAX_PATH = 260;
    45     private static final int MAX_PATH = 260;
    44 
    46 
       
    47     // We add helloJar into the classpath to be compatible with TestCommon.DYNAMIC_DUMP
       
    48     static OutputAnalyzer doDump(String path, String classList[],
       
    49                                         String... suffix) throws Exception {
       
    50         String helloJar = JarBuilder.getOrCreateHelloJar();
       
    51         return TestCommon.dump(helloJar + File.pathSeparator + path, classList, suffix);
       
    52     }
       
    53 
    45     public static void main(String[] args) throws Exception {
    54     public static void main(String[] args) throws Exception {
    46         File dir = new File(System.getProperty("user.dir"));
    55         File dir = new File(System.getProperty("user.dir"));
    47         File emptydir = new File(dir, "emptydir");
    56         File emptydir = new File(dir, "emptydir");
    48         emptydir.mkdir();
    57         emptydir.mkdir();
       
    58 
    49 
    59 
    50         /////////////////////////////////////////////////////////////////
    60         /////////////////////////////////////////////////////////////////
    51         // The classlist only contains boot class in following test cases
    61         // The classlist only contains boot class in following test cases
    52         /////////////////////////////////////////////////////////////////
    62         /////////////////////////////////////////////////////////////////
    53         String bootClassList[] = {"java/lang/Object"};
    63         String bootClassList[] = {"java/lang/Object"};
    54 
    64 
    55         // Empty dir in -cp: should be OK
    65         // Empty dir in -cp: should be OK
    56         OutputAnalyzer output;
    66         OutputAnalyzer output;
    57         output = TestCommon.dump(emptydir.getPath(), bootClassList, "-Xlog:class+path=info");
    67         output = doDump(emptydir.getPath(), bootClassList, "-Xlog:class+path=info");
    58         TestCommon.checkDump(output);
    68         TestCommon.checkDump(output);
    59 
    69 
    60         // Long path to empty dir in -cp: should be OK
    70         // Long path to empty dir in -cp: should be OK
    61         Path classDir = Paths.get(System.getProperty("test.classes"));
    71         Path classDir = Paths.get(System.getProperty("test.classes"));
    62         Path destDir = classDir;
    72         Path destDir = classDir;
    69         }
    79         }
    70         File longDir = destDir.toFile();
    80         File longDir = destDir.toFile();
    71         longDir.mkdir();
    81         longDir.mkdir();
    72         File subDir = new File(longDir, "subdir");
    82         File subDir = new File(longDir, "subdir");
    73         subDir.mkdir();
    83         subDir.mkdir();
    74         output = TestCommon.dump(subDir.getPath(), bootClassList, "-Xlog:class+path=info");
    84         output = doDump(subDir.getPath(), bootClassList, "-Xlog:class+path=info");
    75         TestCommon.checkDump(output);
    85         TestCommon.checkDump(output);
    76 
    86 
    77         // Non-empty dir in -cp: should be OK
    87         // Non-empty dir in -cp: should be OK
    78         // <dir> is not empty because it has at least one subdirectory, i.e., <emptydir>
    88         // <dir> is not empty because it has at least one subdirectory, i.e., <emptydir>
    79         output = TestCommon.dump(dir.getPath(), bootClassList, "-Xlog:class+path=info");
    89         output = doDump(dir.getPath(), bootClassList, "-Xlog:class+path=info");
    80         TestCommon.checkDump(output);
    90         TestCommon.checkDump(output);
    81 
    91 
    82         // Long path to non-empty dir in -cp: should be OK
    92         // Long path to non-empty dir in -cp: should be OK
    83         // <dir> is not empty because it has at least one subdirectory, i.e., <emptydir>
    93         // <dir> is not empty because it has at least one subdirectory, i.e., <emptydir>
    84         output = TestCommon.dump(longDir.getPath(), bootClassList, "-Xlog:class+path=info");
    94         output = doDump(longDir.getPath(), bootClassList, "-Xlog:class+path=info");
    85         TestCommon.checkDump(output);
    95         TestCommon.checkDump(output);
    86 
    96 
    87         /////////////////////////////////////////////////////////////////
    97         /////////////////////////////////////////////////////////////////
    88         // The classlist contains non-boot class in following test cases
    98         // The classlist contains non-boot class in following test cases
    89         /////////////////////////////////////////////////////////////////
    99         /////////////////////////////////////////////////////////////////
    90         String appClassList[] = {"java/lang/Object", "com/sun/tools/javac/Main"};
   100         String appClassList[] = {"java/lang/Object", "com/sun/tools/javac/Main"};
    91 
   101 
    92         // Non-empty dir in -cp: should be OK (as long as no classes were loaded from there)
   102         // Non-empty dir in -cp: should be OK (as long as no classes were loaded from there)
    93         output = TestCommon.dump(dir.getPath(), appClassList, "-Xlog:class+path=info");
   103         output = doDump(dir.getPath(), appClassList, "-Xlog:class+path=info");
    94         TestCommon.checkDump(output);
   104         TestCommon.checkDump(output);
    95 
   105 
    96         // Long path to non-empty dir in -cp: should be OK (as long as no classes were loaded from there)
   106         // Long path to non-empty dir in -cp: should be OK (as long as no classes were loaded from there)
    97         output = TestCommon.dump(longDir.getPath(), appClassList, "-Xlog:class+path=info");
   107         output = doDump(longDir.getPath(), appClassList, "-Xlog:class+path=info");
    98         TestCommon.checkDump(output);
   108         TestCommon.checkDump(output);
    99 
   109 
   100         /////////////////////////////////////////////////////////////////
   110         /////////////////////////////////////////////////////////////////
   101         // Loading an app class from a directory
   111         // Loading an app class from a directory
   102         /////////////////////////////////////////////////////////////////
   112         /////////////////////////////////////////////////////////////////
   103         String appClassList2[] = {"Hello", "java/lang/Object", "com/sun/tools/javac/Main"};
   113         String appClassList2[] = {"Super", "java/lang/Object", "com/sun/tools/javac/Main"};
   104         // Non-empty dir in -cp: should report error if a class is loaded from it
   114         // Non-empty dir in -cp: should report error if a class is loaded from it
   105         output = TestCommon.dump(classDir.toString(), appClassList2, "-Xlog:class+path=info");
   115         output = doDump(classDir.toString(), appClassList2, "-Xlog:class+path=info,class+load=trace");
   106         output.shouldNotHaveExitValue(0);
   116         output.shouldNotHaveExitValue(0);
   107         output.shouldContain("Cannot have non-empty directory in paths");
   117         output.shouldContain("Cannot have non-empty directory in paths");
   108 
   118 
   109         // Long path to non-empty dir in -cp: should report error if a class is loaded from it
   119         // Long path to non-empty dir in -cp: should report error if a class is loaded from it
   110         File srcClass = new File(classDir.toFile(), "Hello.class");
   120         File srcClass = new File(classDir.toFile(), "Super.class");
   111         File destClass = new File(longDir, "Hello.class");
   121         File destClass = new File(longDir, "Super.class");
   112         Files.copy(srcClass.toPath(), destClass.toPath());
   122         Files.copy(srcClass.toPath(), destClass.toPath());
   113         output = TestCommon.dump(longDir.getPath(), appClassList2, "-Xlog:class+path=info");
   123         output = doDump(longDir.getPath(), appClassList2, "-Xlog:class+path=info");
   114         output.shouldNotHaveExitValue(0);
   124         output.shouldNotHaveExitValue(0);
   115         output.shouldContain("Cannot have non-empty directory in paths");
   125         output.shouldContain("Cannot have non-empty directory in paths");
   116     }
   126     }
   117 }
   127 }