jdk/test/sun/management/jmxremote/bootstrap/CustomLauncherTest.java
changeset 21802 b36494ddf19e
parent 21662 b37eb0c9db8d
child 21822 12f13ba496cd
equal deleted inserted replaced
21801:b8a5ff5f0c2a 21802:b36494ddf19e
    23 
    23 
    24 import java.io.File;
    24 import java.io.File;
    25 import java.nio.file.FileSystem;
    25 import java.nio.file.FileSystem;
    26 import java.nio.file.FileSystems;
    26 import java.nio.file.FileSystems;
    27 import java.nio.file.Files;
    27 import java.nio.file.Files;
       
    28 import java.nio.file.LinkOption;
    28 import java.nio.file.Path;
    29 import java.nio.file.Path;
       
    30 import java.nio.file.attribute.PosixFilePermission;
       
    31 import java.util.HashSet;
       
    32 import java.util.Set;
    29 import java.util.concurrent.TimeUnit;
    33 import java.util.concurrent.TimeUnit;
    30 import java.util.concurrent.atomic.AtomicReference;
    34 import java.util.concurrent.atomic.AtomicReference;
    31 
    35 
    32 import jdk.testlibrary.ProcessTools;
    36 import jdk.testlibrary.ProcessTools;
    33 
    37 
    34 /**
    38 /**
    35  * @test
    39  * @test
    36  * @bug 6434402 8004926
    40  * @bug 6434402 8004926
    37  * @library /lib/testlibrary
    41  * @library /lib/testlibrary
    38  * @build TestManager TestApplication CustomLauncherTest
    42  * @build TestManager TestApplication CustomLauncherTest
    39  * @run main CustomLauncherTest
    43  * @run main/othervm CustomLauncherTest
    40  * @author Jaroslav Bachorik
    44  * @author Jaroslav Bachorik
    41  */
    45  */
    42 public class CustomLauncherTest {
    46 public class CustomLauncherTest {
    43     private static final  String TEST_CLASSES = System.getProperty("test.classes");
    47     private static final  String TEST_CLASSES = System.getProperty("test.classes");
    44     private static final  String TEST_JDK = System.getProperty("test.jdk");
    48     private static final  String TEST_JDK = System.getProperty("test.jdk");
    65             case "x86_64":
    69             case "x86_64":
    66             case "amd64": {
    70             case "amd64": {
    67                 ARCH = "amd64";
    71                 ARCH = "amd64";
    68                 break;
    72                 break;
    69             }
    73             }
       
    74             case "sparc":
       
    75                 ARCH = "sparcv9";
       
    76                 break;
    70             default: {
    77             default: {
    71                 ARCH = osarch;
    78                 ARCH = osarch;
    72             }
    79             }
    73         }
    80         }
    74         LIBARCH = ARCH.equals("i586") ? "i386" : ARCH;
    81         LIBARCH = ARCH.equals("i586") ? "i386" : ARCH;
    99 
   106 
   100         String LAUNCHER = TEST_SRC + File.separator + PLATFORM + "-" + ARCH +
   107         String LAUNCHER = TEST_SRC + File.separator + PLATFORM + "-" + ARCH +
   101                           File.separator + "launcher";
   108                           File.separator + "launcher";
   102 
   109 
   103         final FileSystem FS = FileSystems.getDefault();
   110         final FileSystem FS = FileSystems.getDefault();
   104         final boolean hasLauncher = Files.isExecutable(FS.getPath(LAUNCHER));
   111         Path launcherPath = FS.getPath(LAUNCHER);
       
   112 
       
   113         final boolean hasLauncher = Files.isRegularFile(launcherPath, LinkOption.NOFOLLOW_LINKS)&&
       
   114                                     Files.isReadable(launcherPath);
   105         if (!hasLauncher) {
   115         if (!hasLauncher) {
   106             System.out.println("Launcher [" + LAUNCHER + "] does not exist. Skipping the test.");
   116             System.out.println("Launcher [" + LAUNCHER + "] does not exist. Skipping the test.");
   107             return;
   117             return;
   108         }
   118         }
   109 
   119 
   112             throw new Error("Unable to locate 'libjvm.so' in " + TEST_JDK);
   122             throw new Error("Unable to locate 'libjvm.so' in " + TEST_JDK);
   113         }
   123         }
   114 
   124 
   115         Process serverPrc = null, clientPrc = null;
   125         Process serverPrc = null, clientPrc = null;
   116 
   126 
       
   127         final Set<PosixFilePermission> launcherOrigPerms =
       
   128             Files.getPosixFilePermissions(launcherPath, LinkOption.NOFOLLOW_LINKS);
   117         try {
   129         try {
       
   130             // It is impossible to store an executable file in the source control
       
   131             // We need to set the executable flag here
       
   132             if (!Files.isExecutable(launcherPath)) {
       
   133                 Set<PosixFilePermission> perms = new HashSet<>(launcherOrigPerms);
       
   134                 perms.add(PosixFilePermission.OWNER_EXECUTE);
       
   135                 Files.setPosixFilePermissions(launcherPath, perms);
       
   136             }
       
   137 
   118             System.out.println("Starting custom launcher:");
   138             System.out.println("Starting custom launcher:");
   119             System.out.println("=========================");
   139             System.out.println("=========================");
   120             System.out.println("  launcher  : " + LAUNCHER);
   140             System.out.println("  launcher  : " + LAUNCHER);
   121             System.out.println("  libjvm    : " + libjvmPath.toString());
   141             System.out.println("  libjvm    : " + libjvmPath.toString());
   122             System.out.println("  classpath : " + TEST_CLASSES);
   142             System.out.println("  classpath : " + TEST_CLASSES);
   175 
   195 
   176             if (clientExitCode != 0 || serverExitCode != 0) {
   196             if (clientExitCode != 0 || serverExitCode != 0) {
   177                 throw new Error("Test failed");
   197                 throw new Error("Test failed");
   178             }
   198             }
   179         } finally {
   199         } finally {
       
   200             // Let's restore the original launcher permissions
       
   201             Files.setPosixFilePermissions(launcherPath, launcherOrigPerms);
   180             if (clientPrc != null) {
   202             if (clientPrc != null) {
   181                 clientPrc.destroy();
   203                 clientPrc.destroy();
   182                 clientPrc.waitFor();
   204                 clientPrc.waitFor();
   183             }
   205             }
   184             if (serverPrc != null) {
   206             if (serverPrc != null) {