jdk/test/sun/management/jmxremote/bootstrap/CustomLauncherTest.java
author jbachorik
Mon, 18 Nov 2013 15:25:15 +0100
changeset 21802 b36494ddf19e
parent 21662 b37eb0c9db8d
child 21822 12f13ba496cd
permissions -rw-r--r--
8027163: sun/management/jmxremote/bootstrap/CustomLauncherTest.java should be updated for jdk8 removal of solaris-32bit support Reviewed-by: sla
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21367
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
     1
/*
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
     4
 *
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
     7
 * published by the Free Software Foundation.
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
     8
 *
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    13
 * accompanied this code).
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    14
 *
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    18
 *
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    21
 * questions.
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    22
 */
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    23
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    24
import java.io.File;
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    25
import java.nio.file.FileSystem;
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    26
import java.nio.file.FileSystems;
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    27
import java.nio.file.Files;
21802
b36494ddf19e 8027163: sun/management/jmxremote/bootstrap/CustomLauncherTest.java should be updated for jdk8 removal of solaris-32bit support
jbachorik
parents: 21662
diff changeset
    28
import java.nio.file.LinkOption;
21367
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    29
import java.nio.file.Path;
21802
b36494ddf19e 8027163: sun/management/jmxremote/bootstrap/CustomLauncherTest.java should be updated for jdk8 removal of solaris-32bit support
jbachorik
parents: 21662
diff changeset
    30
import java.nio.file.attribute.PosixFilePermission;
b36494ddf19e 8027163: sun/management/jmxremote/bootstrap/CustomLauncherTest.java should be updated for jdk8 removal of solaris-32bit support
jbachorik
parents: 21662
diff changeset
    31
import java.util.HashSet;
b36494ddf19e 8027163: sun/management/jmxremote/bootstrap/CustomLauncherTest.java should be updated for jdk8 removal of solaris-32bit support
jbachorik
parents: 21662
diff changeset
    32
import java.util.Set;
21367
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    33
import java.util.concurrent.TimeUnit;
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    34
import java.util.concurrent.atomic.AtomicReference;
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    35
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    36
import jdk.testlibrary.ProcessTools;
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    37
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    38
/**
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    39
 * @test
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    40
 * @bug 6434402 8004926
21404
0e54d286d846 8027358: sun/management/jmxremote/bootstrap/LocalManagementTest.java failing since JDK-8004926
jbachorik
parents: 21367
diff changeset
    41
 * @library /lib/testlibrary
21367
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    42
 * @build TestManager TestApplication CustomLauncherTest
21802
b36494ddf19e 8027163: sun/management/jmxremote/bootstrap/CustomLauncherTest.java should be updated for jdk8 removal of solaris-32bit support
jbachorik
parents: 21662
diff changeset
    43
 * @run main/othervm CustomLauncherTest
21367
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    44
 * @author Jaroslav Bachorik
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    45
 */
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    46
public class CustomLauncherTest {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    47
    private static final  String TEST_CLASSES = System.getProperty("test.classes");
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    48
    private static final  String TEST_JDK = System.getProperty("test.jdk");
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    49
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    50
    private static final  String TEST_SRC = System.getProperty("test.src");
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    51
    private static final  String OSNAME = System.getProperty("os.name");
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    52
    private static final  String ARCH;
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    53
    private static final  String LIBARCH;
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    54
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    55
    static {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    56
        // magic with os.arch
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    57
        String osarch = System.getProperty("os.arch");
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    58
        switch (osarch) {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    59
            case "i386":
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    60
            case "i486":
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    61
            case "i586":
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    62
            case "i686":
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    63
            case "i786":
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    64
            case "i886":
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    65
            case "i986": {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    66
                ARCH = "i586";
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    67
                break;
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    68
            }
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    69
            case "x86_64":
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    70
            case "amd64": {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    71
                ARCH = "amd64";
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    72
                break;
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    73
            }
21802
b36494ddf19e 8027163: sun/management/jmxremote/bootstrap/CustomLauncherTest.java should be updated for jdk8 removal of solaris-32bit support
jbachorik
parents: 21662
diff changeset
    74
            case "sparc":
b36494ddf19e 8027163: sun/management/jmxremote/bootstrap/CustomLauncherTest.java should be updated for jdk8 removal of solaris-32bit support
jbachorik
parents: 21662
diff changeset
    75
                ARCH = "sparcv9";
b36494ddf19e 8027163: sun/management/jmxremote/bootstrap/CustomLauncherTest.java should be updated for jdk8 removal of solaris-32bit support
jbachorik
parents: 21662
diff changeset
    76
                break;
21367
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    77
            default: {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    78
                ARCH = osarch;
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    79
            }
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    80
        }
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    81
        LIBARCH = ARCH.equals("i586") ? "i386" : ARCH;
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    82
    }
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    83
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    84
    public static void main(String[] args) throws Exception {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    85
        if (TEST_CLASSES == null || TEST_CLASSES.isEmpty()) {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    86
            System.out.println("Test is designed to be run from jtreg only");
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    87
            return;
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    88
        }
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    89
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    90
        String PLATFORM = "";
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    91
        switch (OSNAME.toLowerCase()) {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    92
            case "linux": {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    93
                PLATFORM = "linux";
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    94
                break;
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    95
            }
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    96
            case "sunos": {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    97
                PLATFORM = "solaris";
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    98
                break;
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
    99
            }
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   100
            default: {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   101
                System.out.println("Test not designed to run on this operating " +
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   102
                                   "system (" + OSNAME + "), skipping...");
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   103
                return;
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   104
            }
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   105
        }
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   106
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   107
        String LAUNCHER = TEST_SRC + File.separator + PLATFORM + "-" + ARCH +
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   108
                          File.separator + "launcher";
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   109
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   110
        final FileSystem FS = FileSystems.getDefault();
21802
b36494ddf19e 8027163: sun/management/jmxremote/bootstrap/CustomLauncherTest.java should be updated for jdk8 removal of solaris-32bit support
jbachorik
parents: 21662
diff changeset
   111
        Path launcherPath = FS.getPath(LAUNCHER);
b36494ddf19e 8027163: sun/management/jmxremote/bootstrap/CustomLauncherTest.java should be updated for jdk8 removal of solaris-32bit support
jbachorik
parents: 21662
diff changeset
   112
b36494ddf19e 8027163: sun/management/jmxremote/bootstrap/CustomLauncherTest.java should be updated for jdk8 removal of solaris-32bit support
jbachorik
parents: 21662
diff changeset
   113
        final boolean hasLauncher = Files.isRegularFile(launcherPath, LinkOption.NOFOLLOW_LINKS)&&
b36494ddf19e 8027163: sun/management/jmxremote/bootstrap/CustomLauncherTest.java should be updated for jdk8 removal of solaris-32bit support
jbachorik
parents: 21662
diff changeset
   114
                                    Files.isReadable(launcherPath);
21367
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   115
        if (!hasLauncher) {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   116
            System.out.println("Launcher [" + LAUNCHER + "] does not exist. Skipping the test.");
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   117
            return;
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   118
        }
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   119
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   120
        Path libjvmPath = findLibjvm(FS);
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   121
        if (libjvmPath == null) {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   122
            throw new Error("Unable to locate 'libjvm.so' in " + TEST_JDK);
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   123
        }
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   124
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   125
        Process serverPrc = null, clientPrc = null;
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   126
21802
b36494ddf19e 8027163: sun/management/jmxremote/bootstrap/CustomLauncherTest.java should be updated for jdk8 removal of solaris-32bit support
jbachorik
parents: 21662
diff changeset
   127
        final Set<PosixFilePermission> launcherOrigPerms =
b36494ddf19e 8027163: sun/management/jmxremote/bootstrap/CustomLauncherTest.java should be updated for jdk8 removal of solaris-32bit support
jbachorik
parents: 21662
diff changeset
   128
            Files.getPosixFilePermissions(launcherPath, LinkOption.NOFOLLOW_LINKS);
21367
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   129
        try {
21802
b36494ddf19e 8027163: sun/management/jmxremote/bootstrap/CustomLauncherTest.java should be updated for jdk8 removal of solaris-32bit support
jbachorik
parents: 21662
diff changeset
   130
            // It is impossible to store an executable file in the source control
b36494ddf19e 8027163: sun/management/jmxremote/bootstrap/CustomLauncherTest.java should be updated for jdk8 removal of solaris-32bit support
jbachorik
parents: 21662
diff changeset
   131
            // We need to set the executable flag here
b36494ddf19e 8027163: sun/management/jmxremote/bootstrap/CustomLauncherTest.java should be updated for jdk8 removal of solaris-32bit support
jbachorik
parents: 21662
diff changeset
   132
            if (!Files.isExecutable(launcherPath)) {
b36494ddf19e 8027163: sun/management/jmxremote/bootstrap/CustomLauncherTest.java should be updated for jdk8 removal of solaris-32bit support
jbachorik
parents: 21662
diff changeset
   133
                Set<PosixFilePermission> perms = new HashSet<>(launcherOrigPerms);
b36494ddf19e 8027163: sun/management/jmxremote/bootstrap/CustomLauncherTest.java should be updated for jdk8 removal of solaris-32bit support
jbachorik
parents: 21662
diff changeset
   134
                perms.add(PosixFilePermission.OWNER_EXECUTE);
b36494ddf19e 8027163: sun/management/jmxremote/bootstrap/CustomLauncherTest.java should be updated for jdk8 removal of solaris-32bit support
jbachorik
parents: 21662
diff changeset
   135
                Files.setPosixFilePermissions(launcherPath, perms);
b36494ddf19e 8027163: sun/management/jmxremote/bootstrap/CustomLauncherTest.java should be updated for jdk8 removal of solaris-32bit support
jbachorik
parents: 21662
diff changeset
   136
            }
b36494ddf19e 8027163: sun/management/jmxremote/bootstrap/CustomLauncherTest.java should be updated for jdk8 removal of solaris-32bit support
jbachorik
parents: 21662
diff changeset
   137
21367
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   138
            System.out.println("Starting custom launcher:");
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   139
            System.out.println("=========================");
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   140
            System.out.println("  launcher  : " + LAUNCHER);
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   141
            System.out.println("  libjvm    : " + libjvmPath.toString());
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   142
            System.out.println("  classpath : " + TEST_CLASSES);
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   143
            ProcessBuilder server = new ProcessBuilder(LAUNCHER, libjvmPath.toString(), TEST_CLASSES, "TestApplication");
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   144
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   145
            final AtomicReference<String> port = new AtomicReference<>();
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   146
            final AtomicReference<String> pid = new AtomicReference<>();
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   147
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   148
            serverPrc = ProcessTools.startProcess(
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   149
                "Launcher",
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   150
                server,
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   151
                (String line) -> {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   152
                    if (line.startsWith("port:")) {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   153
                         port.set(line.split("\\:")[1]);
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   154
                     } else  if (line.startsWith("pid:")) {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   155
                         pid.set(line.split("\\:")[1]);
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   156
                     } else if (line.startsWith("waiting")) {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   157
                         return true;
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   158
                     }
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   159
                     return false;
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   160
                },
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   161
                5,
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   162
                TimeUnit.SECONDS
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   163
            );
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   164
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   165
            System.out.println("Attaching test manager:");
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   166
            System.out.println("=========================");
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   167
            System.out.println("  PID           : " + pid.get());
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   168
            System.out.println("  shutdown port : " + port.get());
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   169
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   170
            ProcessBuilder client = ProcessTools.createJavaProcessBuilder(
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   171
                "-cp",
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   172
                TEST_CLASSES +
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   173
                    File.pathSeparator +
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   174
                    TEST_JDK +
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   175
                    File.separator +
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   176
                    "lib" +
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   177
                    File.separator +
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   178
                    "tools.jar",
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   179
                "TestManager",
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   180
                pid.get(),
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   181
                port.get(),
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   182
                "true"
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   183
            );
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   184
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   185
            clientPrc = ProcessTools.startProcess(
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   186
                "TestManager",
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   187
                client,
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   188
                (String line) -> line.startsWith("Starting TestManager for PID"),
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   189
                10,
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   190
                TimeUnit.SECONDS
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   191
            );
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   192
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   193
            int clientExitCode = clientPrc.waitFor();
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   194
            int serverExitCode = serverPrc.waitFor();
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   195
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   196
            if (clientExitCode != 0 || serverExitCode != 0) {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   197
                throw new Error("Test failed");
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   198
            }
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   199
        } finally {
21802
b36494ddf19e 8027163: sun/management/jmxremote/bootstrap/CustomLauncherTest.java should be updated for jdk8 removal of solaris-32bit support
jbachorik
parents: 21662
diff changeset
   200
            // Let's restore the original launcher permissions
b36494ddf19e 8027163: sun/management/jmxremote/bootstrap/CustomLauncherTest.java should be updated for jdk8 removal of solaris-32bit support
jbachorik
parents: 21662
diff changeset
   201
            Files.setPosixFilePermissions(launcherPath, launcherOrigPerms);
21367
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   202
            if (clientPrc != null) {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   203
                clientPrc.destroy();
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   204
                clientPrc.waitFor();
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   205
            }
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   206
            if (serverPrc != null) {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   207
                serverPrc.destroy();
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   208
                serverPrc.waitFor();
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   209
            }
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   210
        }
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   211
    }
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   212
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   213
    private static Path findLibjvm(FileSystem FS) {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   214
        Path libjvmPath = findLibjvm(FS.getPath(TEST_JDK, "jre", "lib", LIBARCH));
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   215
        if (libjvmPath == null) {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   216
            libjvmPath = findLibjvm(FS.getPath(TEST_JDK, "lib", LIBARCH));
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   217
        }
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   218
        return libjvmPath;
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   219
    }
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   220
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   221
    private static Path findLibjvm(Path libPath) {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   222
        // ARCH/libjvm.so -> ARCH/server/libjvm.so -> ARCH/client/libjvm.so
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   223
        Path libjvmPath = libPath.resolve("libjvm.so");
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   224
        if (isFileOk(libjvmPath)) {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   225
            return libjvmPath;
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   226
        }
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   227
        libjvmPath = libPath.resolve("server/libjvm.so");
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   228
        if (isFileOk(libjvmPath)) {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   229
            return libjvmPath;
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   230
        }
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   231
        libjvmPath = libPath.resolve("client/libjvm.so");
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   232
        if (isFileOk(libPath)) {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   233
            return libjvmPath;
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   234
        }
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   235
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   236
        return null;
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   237
    }
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   238
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   239
    private static boolean isFileOk(Path path) {
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   240
        return Files.isRegularFile(path) && Files.isReadable(path);
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   241
    }
679b312e3c5b 8004926: sun/management/jmxremote/bootstrap/CustomLauncherTest.sh oftenly times out
jbachorik
parents:
diff changeset
   242
}