test/hotspot/jtreg/runtime/appcds/DirClasspathTest.java
author ccheung
Thu, 04 Jan 2018 22:47:38 -0800
changeset 48611 4d7a4fad8190
parent 48469 7312ae4465d6
child 49931 840e26123940
permissions -rw-r--r--
8192927: os::dir_is_empty is incorrect on Windows Summary: Check file names in a directory. It is empty if only the "." and ".." files exist. Use unicode version of windows APIs to handle long path. Reviewed-by: iklam, sspitsyn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48191
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
     1
/*
48611
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
     2
 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
48191
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
     4
 *
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
     8
 *
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    13
 * accompanied this code).
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    14
 *
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    18
 *
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    21
 * questions.
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    22
 *
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    23
 */
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    24
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    25
/*
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    26
 * @test
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    27
 * @summary AppCDS handling of directories in -cp
48469
7312ae4465d6 8193672: [test] Enhance vm.cds property to check for all conditions required to run CDS tests
iklam
parents: 48191
diff changeset
    28
 * @requires vm.cds
48191
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    29
 * @library /test/lib
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    30
 * @run main DirClasspathTest
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    31
 */
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    32
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    33
import jdk.test.lib.Platform;
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    34
import jdk.test.lib.process.OutputAnalyzer;
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    35
import java.io.File;
48611
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    36
import java.nio.file.Path;
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    37
import java.nio.file.Paths;
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    38
import java.util.Arrays;
48191
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    39
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    40
public class DirClasspathTest {
48611
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    41
    private static final int MAX_PATH = 260;
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    42
48191
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    43
    public static void main(String[] args) throws Exception {
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    44
        File dir = new File(System.getProperty("user.dir"));
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    45
        File emptydir = new File(dir, "emptydir");
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    46
        emptydir.mkdir();
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    47
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    48
        // Empty dir in -cp: should be OK
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    49
        OutputAnalyzer output;
48611
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    50
        String classList[] = {"java/lang/Object"};
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    51
        output = TestCommon.dump(emptydir.getPath(), classList, "-Xlog:class+path=info");
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    52
        TestCommon.checkDump(output);
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    53
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    54
        // Long path to empty dir in -cp: should be OK
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    55
        Path classDir = Paths.get(System.getProperty("test.classes"));
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    56
        Path destDir = classDir;
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    57
        int subDirLen = MAX_PATH - classDir.toString().length() - 2;
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    58
        if (subDirLen > 0) {
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    59
            char[] chars = new char[subDirLen];
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    60
            Arrays.fill(chars, 'x');
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    61
            String subPath = new String(chars);
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    62
            destDir = Paths.get(System.getProperty("test.classes"), subPath);
48191
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    63
        }
48611
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    64
        File longDir = destDir.toFile();
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    65
        longDir.mkdir();
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    66
        File subDir = new File(longDir, "subdir");
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    67
        subDir.mkdir();
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    68
        output = TestCommon.dump(subDir.getPath(), classList, "-Xlog:class+path=info");
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    69
        TestCommon.checkDump(output);
48191
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    70
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    71
        // Non-empty dir in -cp: should fail
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    72
        // <dir> is not empty because it has at least one subdirectory, i.e., <emptydir>
48611
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    73
        output = TestCommon.dump(dir.getPath(), classList, "-Xlog:class+path=info");
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    74
        output.shouldNotHaveExitValue(0);
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    75
        output.shouldContain("CDS allows only empty directories in archived classpaths");
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    76
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    77
        // Long path to non-empty dir in -cp: should fail
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    78
        // <dir> is not empty because it has at least one subdirectory, i.e., <emptydir>
4d7a4fad8190 8192927: os::dir_is_empty is incorrect on Windows
ccheung
parents: 48469
diff changeset
    79
        output = TestCommon.dump(longDir.getPath(), classList, "-Xlog:class+path=info");
48191
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    80
        output.shouldNotHaveExitValue(0);
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    81
        output.shouldContain("CDS allows only empty directories in archived classpaths");
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    82
    }
d8a62bea95d3 8190809: JVM crashes while generating appcds for classpath with empty directory entry
iklam
parents:
diff changeset
    83
}