test/jdk/tools/jimage/JImageExtractTest.java
author erikj
Tue, 09 Oct 2018 14:17:50 -0700
branchihse-runtestprebuilt-branch
changeset 56945 35914fe36a9c
parent 50994 09776f847bf4
child 55122 d4475420fb9a
permissions -rw-r--r--
Handle space in JTREG_KEYWORDS. Introduce TEST_OPTS_JAVA_OPTIONS. Set individual test timeouts to 300. Fix InstrumentationTest to handle deep work dir paths better.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42167
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
     1
/*
48915
b417304c811b 8198380: tools/jimage/JImageExtractTest.java failing
alanb
parents: 48699
diff changeset
     2
 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
42167
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
     4
 *
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
     7
 * published by the Free Software Foundation.
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
     8
 *
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    13
 * accompanied this code).
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    14
 *
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    18
 *
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    21
 * questions.
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    22
 */
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    23
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    24
/*
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    25
 * @test
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    26
 * @summary Tests to verify jimage 'extract' action
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    27
 * @library /test/lib
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    28
 * @modules jdk.jlink/jdk.tools.jimage
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    29
 * @build jdk.test.lib.Asserts
56945
35914fe36a9c Handle space in JTREG_KEYWORDS. Introduce TEST_OPTS_JAVA_OPTIONS. Set individual test timeouts to 300. Fix InstrumentationTest to handle deep work dir paths better.
erikj
parents: 50994
diff changeset
    30
 * @run main/othervm/timeout=300 JImageExtractTest
42167
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    31
 */
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    32
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    33
import java.io.IOException;
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    34
import java.nio.file.Files;
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    35
import java.nio.file.Path;
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    36
import java.nio.file.Paths;
50994
09776f847bf4 8198405: JImageExtractTest.java & JImageListTest.java failed in Windows.
sdama
parents: 50981
diff changeset
    37
import java.nio.file.attribute.*;
42167
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    38
import java.util.Arrays;
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    39
import java.util.HashSet;
50994
09776f847bf4 8198405: JImageExtractTest.java & JImageListTest.java failed in Windows.
sdama
parents: 50981
diff changeset
    40
import java.util.List;
42167
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    41
import java.util.Set;
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    42
import java.util.stream.Collectors;
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    43
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    44
import static jdk.test.lib.Asserts.assertEquals;
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    45
import static jdk.test.lib.Asserts.assertTrue;
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    46
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    47
public class JImageExtractTest extends JImageCliTest {
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    48
    public void testExtract() throws IOException {
50981
ce27f6e0734d 8198819: tools/jimage/JImageExtractTest.java, fails intermittently at testExtract (macos)
sdama
parents: 48915
diff changeset
    49
        Set<Path> notJImageModules = Files.walk(Paths.get("."),1).collect(Collectors.toSet());
42167
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    50
        jimage("extract", getImagePath())
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    51
                .assertSuccess()
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    52
                .resultChecker(r -> {
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    53
                    assertTrue(r.output.isEmpty(), "Output is not expected");
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    54
                });
50981
ce27f6e0734d 8198819: tools/jimage/JImageExtractTest.java, fails intermittently at testExtract (macos)
sdama
parents: 48915
diff changeset
    55
        verifyExplodedImage(Paths.get("."), notJImageModules);
42167
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    56
    }
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    57
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    58
    public void testExtractHelp() {
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    59
        for (String opt : Arrays.asList("-h", "--help")) {
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    60
            jimage("extract", "--help")
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    61
                    .assertSuccess()
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    62
                    .resultChecker(r -> {
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    63
                        // extract  -  descriptive text
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    64
                        assertMatches("\\s+extract\\s+-\\s+.*", r.output);
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    65
                    });
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    66
        }
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    67
    }
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    68
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    69
    public void testExtractToDir() throws IOException {
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    70
        Path tmp = Files.createTempDirectory(Paths.get("."), getClass().getName());
50981
ce27f6e0734d 8198819: tools/jimage/JImageExtractTest.java, fails intermittently at testExtract (macos)
sdama
parents: 48915
diff changeset
    71
        Set<Path> notJImageModules = Files.walk(tmp,1).collect(Collectors.toSet());
42167
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    72
        jimage("extract", "--dir", tmp.toString(), getImagePath())
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    73
                .assertSuccess()
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    74
                .resultChecker(r -> {
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    75
                    assertTrue(r.output.isEmpty(), "Output is not expected");
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    76
                });
50981
ce27f6e0734d 8198819: tools/jimage/JImageExtractTest.java, fails intermittently at testExtract (macos)
sdama
parents: 48915
diff changeset
    77
        verifyExplodedImage(tmp, notJImageModules);
42167
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    78
    }
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    79
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    80
    public void testExtractNoImageSpecified() {
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    81
        jimage("extract", "")
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    82
                .assertFailure()
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    83
                .assertShowsError();
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    84
    }
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    85
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    86
    public void testExtractNotAnImage() throws IOException {
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    87
        Path tmp = Files.createTempFile(Paths.get("."), getClass().getName(), "not_an_image");
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    88
        jimage("extract", tmp.toString())
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    89
                .assertFailure()
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    90
                .assertShowsError();
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    91
    }
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    92
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    93
    public void testExtractNotExistingImage() throws IOException {
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    94
        Path tmp = Paths.get(".", "not_existing_image");
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    95
        Files.deleteIfExists(tmp);
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    96
        jimage("extract", tmp.toString())
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    97
                .assertFailure()
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    98
                .assertShowsError();
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
    99
    }
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   100
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   101
    public void testExtractToUnspecifiedDir() {
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   102
        jimage("extract", "--dir", "--", getImagePath())
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   103
                .assertFailure()
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   104
                .assertShowsError();
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   105
    }
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   106
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   107
    public void testExtractToNotExistingDir() throws IOException {
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   108
        Path tmp = Files.createTempDirectory(Paths.get("."), getClass().getName());
50981
ce27f6e0734d 8198819: tools/jimage/JImageExtractTest.java, fails intermittently at testExtract (macos)
sdama
parents: 48915
diff changeset
   109
        Set<Path> notJImageModules = Files.walk(tmp,1).collect(Collectors.toSet());
42167
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   110
        Files.delete(tmp);
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   111
        jimage("extract", "--dir", tmp.toString(), getImagePath())
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   112
                .assertSuccess()
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   113
                .resultChecker(r -> {
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   114
                    assertTrue(r.output.isEmpty(), "Output is not expected");
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   115
                });
50981
ce27f6e0734d 8198819: tools/jimage/JImageExtractTest.java, fails intermittently at testExtract (macos)
sdama
parents: 48915
diff changeset
   116
        verifyExplodedImage(tmp, notJImageModules);
42167
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   117
    }
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   118
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   119
    public void testExtractFromDir() {
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   120
        Path imagePath = Paths.get(getImagePath());
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   121
        Path imageDirPath = imagePath.subpath(0, imagePath.getNameCount() - 1);
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   122
        jimage("extract", imageDirPath.toString())
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   123
                .assertFailure()
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   124
                .assertShowsError();
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   125
    }
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   126
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   127
    public void testExtractToDirBySymlink() throws IOException {
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   128
        Path tmp = Files.createTempDirectory(Paths.get("."), getClass().getName());
48699
f4e628259d1b 8194229: tools/jmod/JmodTest.jtr fails when no privilege to create sym link on windows
mchung
parents: 47216
diff changeset
   129
        Path symlink;
42167
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   130
        try {
48699
f4e628259d1b 8194229: tools/jmod/JmodTest.jtr fails when no privilege to create sym link on windows
mchung
parents: 47216
diff changeset
   131
            symlink = Files.createSymbolicLink(Paths.get(".", "symlink"), tmp);
f4e628259d1b 8194229: tools/jmod/JmodTest.jtr fails when no privilege to create sym link on windows
mchung
parents: 47216
diff changeset
   132
        } catch (IOException|UnsupportedOperationException e) {
42167
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   133
            // symlinks are not supported
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   134
            // nothing to test
48699
f4e628259d1b 8194229: tools/jmod/JmodTest.jtr fails when no privilege to create sym link on windows
mchung
parents: 47216
diff changeset
   135
            return;
42167
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   136
        }
50981
ce27f6e0734d 8198819: tools/jimage/JImageExtractTest.java, fails intermittently at testExtract (macos)
sdama
parents: 48915
diff changeset
   137
        Set<Path> notJImageModules = Files.walk(tmp,1).collect(Collectors.toSet());
48699
f4e628259d1b 8194229: tools/jmod/JmodTest.jtr fails when no privilege to create sym link on windows
mchung
parents: 47216
diff changeset
   138
        jimage("extract", "--dir", symlink.toString(), getImagePath())
f4e628259d1b 8194229: tools/jmod/JmodTest.jtr fails when no privilege to create sym link on windows
mchung
parents: 47216
diff changeset
   139
                .assertSuccess()
f4e628259d1b 8194229: tools/jmod/JmodTest.jtr fails when no privilege to create sym link on windows
mchung
parents: 47216
diff changeset
   140
                .resultChecker(r -> {
f4e628259d1b 8194229: tools/jmod/JmodTest.jtr fails when no privilege to create sym link on windows
mchung
parents: 47216
diff changeset
   141
                    assertTrue(r.output.isEmpty(), "Output is not expected");
f4e628259d1b 8194229: tools/jmod/JmodTest.jtr fails when no privilege to create sym link on windows
mchung
parents: 47216
diff changeset
   142
                });
50981
ce27f6e0734d 8198819: tools/jimage/JImageExtractTest.java, fails intermittently at testExtract (macos)
sdama
parents: 48915
diff changeset
   143
        verifyExplodedImage(tmp, notJImageModules);
42167
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   144
    }
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   145
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   146
    public void testExtractToReadOnlyDir() throws IOException {
50994
09776f847bf4 8198405: JImageExtractTest.java & JImageListTest.java failed in Windows.
sdama
parents: 50981
diff changeset
   147
        Path filePath = Files.createTempDirectory(Paths.get("."), getClass().getName());
09776f847bf4 8198405: JImageExtractTest.java & JImageListTest.java failed in Windows.
sdama
parents: 50981
diff changeset
   148
        Set<String> supportedAttr = filePath.getFileSystem().supportedFileAttributeViews();
09776f847bf4 8198405: JImageExtractTest.java & JImageListTest.java failed in Windows.
sdama
parents: 50981
diff changeset
   149
        if (supportedAttr.contains("posix")) {
09776f847bf4 8198405: JImageExtractTest.java & JImageListTest.java failed in Windows.
sdama
parents: 50981
diff changeset
   150
            Files.setPosixFilePermissions(filePath, PosixFilePermissions.fromString("r-xr--r--"));
09776f847bf4 8198405: JImageExtractTest.java & JImageListTest.java failed in Windows.
sdama
parents: 50981
diff changeset
   151
        } else if (supportedAttr.contains("acl")) {
09776f847bf4 8198405: JImageExtractTest.java & JImageListTest.java failed in Windows.
sdama
parents: 50981
diff changeset
   152
            System.out.println("Entered into acl block");
09776f847bf4 8198405: JImageExtractTest.java & JImageListTest.java failed in Windows.
sdama
parents: 50981
diff changeset
   153
            UserPrincipal fileOwner = Files.getOwner(filePath);
09776f847bf4 8198405: JImageExtractTest.java & JImageListTest.java failed in Windows.
sdama
parents: 50981
diff changeset
   154
            AclFileAttributeView view = Files.getFileAttributeView(filePath, AclFileAttributeView.class);
09776f847bf4 8198405: JImageExtractTest.java & JImageListTest.java failed in Windows.
sdama
parents: 50981
diff changeset
   155
            AclEntry entry = AclEntry.newBuilder()
09776f847bf4 8198405: JImageExtractTest.java & JImageListTest.java failed in Windows.
sdama
parents: 50981
diff changeset
   156
                                     .setType(AclEntryType.DENY)
09776f847bf4 8198405: JImageExtractTest.java & JImageListTest.java failed in Windows.
sdama
parents: 50981
diff changeset
   157
                                     .setPrincipal(fileOwner)
09776f847bf4 8198405: JImageExtractTest.java & JImageListTest.java failed in Windows.
sdama
parents: 50981
diff changeset
   158
                                     .setPermissions(AclEntryPermission.WRITE_DATA)
09776f847bf4 8198405: JImageExtractTest.java & JImageListTest.java failed in Windows.
sdama
parents: 50981
diff changeset
   159
                                     .setFlags(AclEntryFlag.FILE_INHERIT, AclEntryFlag.DIRECTORY_INHERIT)
09776f847bf4 8198405: JImageExtractTest.java & JImageListTest.java failed in Windows.
sdama
parents: 50981
diff changeset
   160
                                     .build();
09776f847bf4 8198405: JImageExtractTest.java & JImageListTest.java failed in Windows.
sdama
parents: 50981
diff changeset
   161
            List<AclEntry> acl = view.getAcl();
09776f847bf4 8198405: JImageExtractTest.java & JImageListTest.java failed in Windows.
sdama
parents: 50981
diff changeset
   162
            acl.add(0, entry);
09776f847bf4 8198405: JImageExtractTest.java & JImageListTest.java failed in Windows.
sdama
parents: 50981
diff changeset
   163
            view.setAcl(acl);
50981
ce27f6e0734d 8198819: tools/jimage/JImageExtractTest.java, fails intermittently at testExtract (macos)
sdama
parents: 48915
diff changeset
   164
        }
50994
09776f847bf4 8198405: JImageExtractTest.java & JImageListTest.java failed in Windows.
sdama
parents: 50981
diff changeset
   165
        jimage("extract", "--dir", filePath.toString(), getImagePath())
42167
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   166
                .assertFailure()
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   167
                .assertShowsError();
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   168
    }
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   169
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   170
    public void testExtractToNotEmptyDir() throws IOException {
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   171
        Path tmp = Files.createTempDirectory(Paths.get("."), getClass().getName());
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   172
        Files.createFile(Paths.get(tmp.toString(), ".not_empty"));
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   173
        jimage("extract", "--dir", tmp.toString(), getImagePath())
48915
b417304c811b 8198380: tools/jimage/JImageExtractTest.java failing
alanb
parents: 48699
diff changeset
   174
                .assertSuccess()
b417304c811b 8198380: tools/jimage/JImageExtractTest.java failing
alanb
parents: 48699
diff changeset
   175
                .resultChecker(r -> {
b417304c811b 8198380: tools/jimage/JImageExtractTest.java failing
alanb
parents: 48699
diff changeset
   176
                    assertTrue(r.output.isEmpty(), "Output is not expected");
b417304c811b 8198380: tools/jimage/JImageExtractTest.java failing
alanb
parents: 48699
diff changeset
   177
                });
42167
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   178
    }
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   179
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   180
    public void testExtractToFile() throws IOException {
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   181
        Path tmp = Files.createTempFile(Paths.get("."), getClass().getName(), "not_a_dir");
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   182
        jimage("extract", "--dir", tmp.toString(), getImagePath())
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   183
                .assertFailure()
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   184
                .assertShowsError();
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   185
    }
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   186
50981
ce27f6e0734d 8198819: tools/jimage/JImageExtractTest.java, fails intermittently at testExtract (macos)
sdama
parents: 48915
diff changeset
   187
    private void verifyExplodedImage(Path imagePath, Set<Path> notJImageModules) throws IOException {
42167
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   188
        Set<Path> allModules = Files.walk(imagePath, 1).collect(Collectors.toSet());
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   189
        assertTrue(allModules.stream().anyMatch(p -> "java.base".equals(p.getFileName().toString())),
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   190
                "Exploded image contains java.base module.");
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   191
        Set<Path> badModules = allModules.stream()
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   192
                .filter(p -> !Files.exists(p.resolve("module-info.class")))
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   193
                .collect(Collectors.toSet());
50981
ce27f6e0734d 8198819: tools/jimage/JImageExtractTest.java, fails intermittently at testExtract (macos)
sdama
parents: 48915
diff changeset
   194
        // filter bad modules which are not part of jimage
ce27f6e0734d 8198819: tools/jimage/JImageExtractTest.java, fails intermittently at testExtract (macos)
sdama
parents: 48915
diff changeset
   195
        badModules.removeAll(notJImageModules);
ce27f6e0734d 8198819: tools/jimage/JImageExtractTest.java, fails intermittently at testExtract (macos)
sdama
parents: 48915
diff changeset
   196
        assertEquals(badModules, new HashSet<Path>() {{}},
42167
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   197
                "There are no exploded modules with missing 'module-info.class'");
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   198
    }
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   199
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   200
    public static void main(String[] args) throws Throwable {
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   201
        new JImageExtractTest().runTests();
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   202
    }
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   203
}
312b1ca6b1df 8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff changeset
   204