test/jdk/java/io/pathNames/GeneralWin32.java
author tschatzl
Wed, 24 Jul 2019 11:49:39 +0200
changeset 57508 28ab01c06755
parent 47216 71c04702a3d5
permissions -rw-r--r--
8228388: Add information about dirty/skipped card for Merge HCC in G1 log Summary: Collect and print informatio about the number of processed cards during the Merge HCC phase to improve log output. Reviewed-by: kbarrett, sangheki
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
43108
9849ccac1f10 8156595: java/io/pathNames/GeneralWin32.java fail intermittently on windows-x64
amlu
parents: 21824
diff changeset
     2
 * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/* @test
17726
4aff99bf471b 8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents: 7668
diff changeset
    25
   @bug 4032066 4039597 4046914 4054511 4065189 4109131 4875229 6983520 8009258
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
   @summary General exhaustive test of win32 pathname handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
   @author Mark Reinhold
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
   @build General GeneralWin32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
   @run main/timeout=600 GeneralWin32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
public class GeneralWin32 extends General {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
     * Hardwired UNC pathnames used for testing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     * This test attempts to use the host and share names defined in this class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     * to test UNC pathnames.  The test will not fail if the host or share
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * don't exist, but it will print a warning saying that it was unable to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     * test UNC pathnames completely.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private static final String EXISTENT_UNC_HOST = "pc-cup01";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private static final String EXISTENT_UNC_SHARE = "pcdist";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static final String NONEXISTENT_UNC_HOST = "non-existent-unc-host";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private static final String NONEXISTENT_UNC_SHARE = "bogus-share";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /* Pathnames relative to working directory */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
17726
4aff99bf471b 8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents: 7668
diff changeset
    53
    private static void checkCaseLookup() throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        /* Use long names here to avoid 8.3 format, which Samba servers often
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
           force to lowercase */
43108
9849ccac1f10 8156595: java/io/pathNames/GeneralWin32.java fail intermittently on windows-x64
amlu
parents: 21824
diff changeset
    56
        File r = new File (workSubDir, "XyZzY0123");
9849ccac1f10 8156595: java/io/pathNames/GeneralWin32.java fail intermittently on windows-x64
amlu
parents: 21824
diff changeset
    57
        File d = new File(r, "FOO_bar_BAZ");
21824
123a828f30dc 8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents: 17924
diff changeset
    58
        File f = new File(d, "GLORPified");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        if (!f.exists()) {
21824
123a828f30dc 8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents: 17924
diff changeset
    60
            if (!d.exists()) {
123a828f30dc 8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents: 17924
diff changeset
    61
                if (!d.mkdirs()) {
123a828f30dc 8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents: 17924
diff changeset
    62
                    throw new RuntimeException("Can't create directory " + d);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            OutputStream o = new FileOutputStream(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            o.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        }
21824
123a828f30dc 8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents: 17924
diff changeset
    68
        File f2 = new File(d.getParent(), "mumble"); /* For later ud tests */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        if (!f2.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            OutputStream o = new FileOutputStream(f2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            o.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        /* Computing the canonical path of a Win32 file should expose the true
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
           case of filenames, rather than just using the input case */
17726
4aff99bf471b 8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents: 7668
diff changeset
    76
        File y = new File(userDir, f.getPath());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        String ans = y.getPath();
43108
9849ccac1f10 8156595: java/io/pathNames/GeneralWin32.java fail intermittently on windows-x64
amlu
parents: 21824
diff changeset
    78
        check(ans, workSubDir + File.separator + "XyZzY0123\\FOO_bar_BAZ\\GLORPified");
9849ccac1f10 8156595: java/io/pathNames/GeneralWin32.java fail intermittently on windows-x64
amlu
parents: 21824
diff changeset
    79
        check(ans, workSubDir + File.separator + "xyzzy0123\\foo_bar_baz\\glorpified");
9849ccac1f10 8156595: java/io/pathNames/GeneralWin32.java fail intermittently on windows-x64
amlu
parents: 21824
diff changeset
    80
        check(ans, workSubDir + File.separator + "XYZZY0123\\FOO_BAR_BAZ\\GLORPIFIED");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private static void checkWild(File f) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            f.getCanonicalPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        } catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        throw new Exception("Wildcard path not rejected: " + f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
17726
4aff99bf471b 8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents: 7668
diff changeset
    92
    private static void checkWildCards() throws Exception {
21824
123a828f30dc 8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents: 17924
diff changeset
    93
        File d = new File(userDir).getCanonicalFile();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        checkWild(new File(d, "*.*"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        checkWild(new File(d, "*.???"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        checkWild(new File(new File(d, "*.*"), "foo"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
21824
123a828f30dc 8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents: 17924
diff changeset
    99
    private static void checkRelativePaths(int depth) throws Exception {
17726
4aff99bf471b 8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents: 7668
diff changeset
   100
        checkCaseLookup();
4aff99bf471b 8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents: 7668
diff changeset
   101
        checkWildCards();
21824
123a828f30dc 8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents: 17924
diff changeset
   102
        // Make sure that an empty relative path is tested
123a828f30dc 8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents: 17924
diff changeset
   103
        checkNames(1, true, userDir + File.separator, "");
123a828f30dc 8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents: 17924
diff changeset
   104
        checkNames(depth, true, baseDir + File.separator,
123a828f30dc 8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents: 17924
diff changeset
   105
                   relative + File.separator);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /* Pathnames with drive specifiers */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private static char findInactiveDrive() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        for (char d = 'Z'; d >= 'E'; d--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            File df = new File(d + ":\\");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            if (!df.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        throw new RuntimeException("Can't find an inactive drive");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private static char findActiveDrive() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        for (char d = 'C'; d <= 'Z'; d--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            File df = new File(d + ":\\");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            if (df.exists()) return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        throw new RuntimeException("Can't find an active drive");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
43108
9849ccac1f10 8156595: java/io/pathNames/GeneralWin32.java fail intermittently on windows-x64
amlu
parents: 21824
diff changeset
   129
    private static void checkDrive(int depth, String drive, boolean exists)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        throws Exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    {
43108
9849ccac1f10 8156595: java/io/pathNames/GeneralWin32.java fail intermittently on windows-x64
amlu
parents: 21824
diff changeset
   132
        File df = new File(drive);
9849ccac1f10 8156595: java/io/pathNames/GeneralWin32.java fail intermittently on windows-x64
amlu
parents: 21824
diff changeset
   133
        String ans = exists ? df.getAbsolutePath() : drive;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        if (!ans.endsWith("\\"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            ans = ans + "\\";
43108
9849ccac1f10 8156595: java/io/pathNames/GeneralWin32.java fail intermittently on windows-x64
amlu
parents: 21824
diff changeset
   136
        checkNames(depth, false, ans, drive);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
21824
123a828f30dc 8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents: 17924
diff changeset
   139
    private static void checkDrivePaths(int depth) throws Exception {
43108
9849ccac1f10 8156595: java/io/pathNames/GeneralWin32.java fail intermittently on windows-x64
amlu
parents: 21824
diff changeset
   140
        checkDrive(depth, findActiveDrive() + ":" + workSubDir + File.separator, true);
9849ccac1f10 8156595: java/io/pathNames/GeneralWin32.java fail intermittently on windows-x64
amlu
parents: 21824
diff changeset
   141
        checkDrive(depth, findInactiveDrive() + ":", false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /* UNC pathnames */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
21824
123a828f30dc 8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents: 17924
diff changeset
   147
    private static void checkUncPaths(int depth) throws Exception {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        String s = ("\\\\" + NONEXISTENT_UNC_HOST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                    + "\\" + NONEXISTENT_UNC_SHARE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        ensureNon(s);
21824
123a828f30dc 8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents: 17924
diff changeset
   151
        checkSlashes(depth, false, s, s);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        s = "\\\\" + EXISTENT_UNC_HOST + "\\" + EXISTENT_UNC_SHARE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        if (!(new File(s)).exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            System.err.println("WARNING: " + s +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                               " does not exist, unable to test UNC pathnames");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
21824
123a828f30dc 8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents: 17924
diff changeset
   160
        checkSlashes(depth, false, s, s);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        if (File.separatorChar != '\\') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            /* This test is only valid on win32 systems */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if (args.length > 0) debug = true;
21824
123a828f30dc 8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents: 17924
diff changeset
   170
123a828f30dc 8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents: 17924
diff changeset
   171
        initTestData(3);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
21824
123a828f30dc 8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents: 17924
diff changeset
   173
        checkRelativePaths(3);
123a828f30dc 8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents: 17924
diff changeset
   174
        checkDrivePaths(2);
123a828f30dc 8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents: 17924
diff changeset
   175
        checkUncPaths(2);
17726
4aff99bf471b 8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents: 7668
diff changeset
   176
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
}