test/tools/launcher/ExecutionEnvironment.java

Print this page




  31 
  32 /*
  33  * This tests for various things as follows:
  34  * Ensures that:
  35  *   1. uneccessary execs do not occur
  36  *   2. the environment is pristine,  users environment variable wrt.
  37  *      LD_LIBRARY_PATH if set are not modified in any way.
  38  *   3. the correct vm is chosen with -server and -client options
  39  *   4. the VM on Solaris correctly interprets the LD_LIBRARY_PATH32
  40  *      and LD_LIBRARY_PATH64 variables if set by the user, ie.
  41  *      i. on 32 bit systems:
  42  *         a. if LD_LIBRARY_PATH32 is set it will override LD_LIBRARY_PATH
  43  *         b. LD_LIBRARY_PATH64 is ignored if set
  44  *      ii. on 64 bit systems:
  45  *            a. if LD_LIBRARY_PATH64 is set it will override LD_LIBRARY_PATH
  46  *            b. LD_LIBRARY_PATH32 is ignored if set
  47  *   5. no extra symlink exists on Solaris ie.
  48  *      jre/lib/$arch/libjvm.so -> client/libjvm.so
  49  *   6. Since 32-bit Solaris is no longer supported we continue to ensure that
  50  *      the appropriate paths are ignored or used, additionally we also test to
  51  *      ensure the 64-bit isadir exists and contains appopriate links.
  52  * TODO:
  53  *      a. perhaps we need to add a test to audit all environment variables are
  54  *         in pristine condition after the launch, there may be a few that the
  55  *         launcher may add as implementation details.
  56  *      b. add a pldd for solaris to ensure only one libjvm.so is linked
  57  */
  58 import java.io.File;
  59 import java.io.FileNotFoundException;
  60 import java.io.IOException;
  61 import java.nio.file.DirectoryStream;
  62 import java.nio.file.Files;
  63 import java.nio.file.Path;
  64 import java.util.ArrayList;
  65 import java.util.HashMap;
  66 import java.util.List;
  67 import java.util.Map;
  68 import static java.nio.file.LinkOption.*;

  69 
  70 
  71 public class ExecutionEnvironment extends TestHelper {
  72     static final String LD_LIBRARY_PATH    = TestHelper.isMacOSX
  73             ? "DYLD_LIBRARY_PATH"
  74             : "LD_LIBRARY_PATH";
  75     static final String LD_LIBRARY_PATH_32 = LD_LIBRARY_PATH + "_32";
  76     static final String LD_LIBRARY_PATH_64 = LD_LIBRARY_PATH + "_64";
  77 
  78     // Note: these paths need not exist on the filesytem
  79     static final String LD_LIBRARY_PATH_VALUE    = "/Bridge/On/The/River/Kwai";
  80     static final String LD_LIBRARY_PATH_32_VALUE = "/Lawrence/Of/Arabia";
  81     static final String LD_LIBRARY_PATH_64_VALUE = "/A/Passage/To/India";
  82 
  83     static final String[] LD_PATH_STRINGS = {
  84         LD_LIBRARY_PATH + "=" + LD_LIBRARY_PATH_VALUE,
  85         LD_LIBRARY_PATH_32 + "=" + LD_LIBRARY_PATH_32_VALUE,
  86         LD_LIBRARY_PATH_64 + "=" + LD_LIBRARY_PATH_64_VALUE
  87     };
  88 


 267         File symLink = null;
 268         String libPathPrefix = isSDK ? "jre/lib" : "/lib";
 269         symLink = new File(JAVAHOME, libPathPrefix +
 270                 getJreArch() + "/" + LIBJVM);
 271         if (symLink.exists()) {
 272             throw new RuntimeException("symlink exists " + symLink.getAbsolutePath());
 273         }
 274     }
 275 
 276     /*
 277      * verify if all the symlinks in the images are created correctly,
 278      * only on solaris, this test works only on images.
 279      */
 280     @Test
 281     void testSymLinks() throws Exception {
 282         if (!isSolaris)
 283             return;
 284         verifySymLinks(JAVA_BIN);
 285         verifySymLinks(JAVA_JRE_BIN);
 286     }



 287      private void verifySymLinks(String bindir) throws IOException {
 288         File binDir = new File(bindir);
 289         System.err.println("verifying links in: " + bindir);
 290         File isaDir = new File(binDir, getArch()).getAbsoluteFile();
 291         if (!isaDir.exists()) {
 292             throw new RuntimeException("dir: " + isaDir + " does not exist");
 293         }
 294         try (DirectoryStream<Path> ds = Files.newDirectoryStream(binDir.toPath())) {
 295             for (Path p : ds) {
 296                 if (Files.isDirectory(p, NOFOLLOW_LINKS))

 297                     continue;

 298                 Path link = new File(isaDir, p.getFileName().toString()).toPath();
 299                 if (Files.isSymbolicLink(link)) {
 300                     Path target = Files.readSymbolicLink(link);
 301                     if (target.startsWith("..") && p.endsWith(target.getFileName()))

 302                         continue;

 303                     System.err.println("target:" + target);
 304                     System.err.println("file:" + p);
 305                 }
 306                 throw new RuntimeException("could not find link to " + p);
 307             }
 308         }
 309 
 310     }
 311     public static void main(String... args) throws Exception {
 312         if (isWindows) {
 313             System.err.println("Warning: test not applicable to windows");
 314             return;
 315         }
 316         ExecutionEnvironment ee = new ExecutionEnvironment();
 317         ee.run(args);
 318     }
 319 }


  31 
  32 /*
  33  * This tests for various things as follows:
  34  * Ensures that:
  35  *   1. uneccessary execs do not occur
  36  *   2. the environment is pristine,  users environment variable wrt.
  37  *      LD_LIBRARY_PATH if set are not modified in any way.
  38  *   3. the correct vm is chosen with -server and -client options
  39  *   4. the VM on Solaris correctly interprets the LD_LIBRARY_PATH32
  40  *      and LD_LIBRARY_PATH64 variables if set by the user, ie.
  41  *      i. on 32 bit systems:
  42  *         a. if LD_LIBRARY_PATH32 is set it will override LD_LIBRARY_PATH
  43  *         b. LD_LIBRARY_PATH64 is ignored if set
  44  *      ii. on 64 bit systems:
  45  *            a. if LD_LIBRARY_PATH64 is set it will override LD_LIBRARY_PATH
  46  *            b. LD_LIBRARY_PATH32 is ignored if set
  47  *   5. no extra symlink exists on Solaris ie.
  48  *      jre/lib/$arch/libjvm.so -> client/libjvm.so
  49  *   6. Since 32-bit Solaris is no longer supported we continue to ensure that
  50  *      the appropriate paths are ignored or used, additionally we also test to
  51  *      ensure the 64-bit isadir exists and contains appropriate links.
  52  * TODO:
  53  *      a. perhaps we need to add a test to audit all environment variables are
  54  *         in pristine condition after the launch, there may be a few that the
  55  *         launcher may add as implementation details.
  56  *      b. add a pldd for solaris to ensure only one libjvm.so is linked
  57  */
  58 import java.io.File;
  59 import java.io.FileNotFoundException;
  60 import java.io.IOException;
  61 import java.nio.file.DirectoryStream;
  62 import java.nio.file.Files;
  63 import java.nio.file.Path;
  64 import java.util.ArrayList;
  65 import java.util.HashMap;
  66 import java.util.List;
  67 import java.util.Map;
  68 import static java.nio.file.LinkOption.*;
  69 import java.util.regex.Pattern;
  70 
  71 
  72 public class ExecutionEnvironment extends TestHelper {
  73     static final String LD_LIBRARY_PATH    = TestHelper.isMacOSX
  74             ? "DYLD_LIBRARY_PATH"
  75             : "LD_LIBRARY_PATH";
  76     static final String LD_LIBRARY_PATH_32 = LD_LIBRARY_PATH + "_32";
  77     static final String LD_LIBRARY_PATH_64 = LD_LIBRARY_PATH + "_64";
  78 
  79     // Note: these paths need not exist on the filesytem
  80     static final String LD_LIBRARY_PATH_VALUE    = "/Bridge/On/The/River/Kwai";
  81     static final String LD_LIBRARY_PATH_32_VALUE = "/Lawrence/Of/Arabia";
  82     static final String LD_LIBRARY_PATH_64_VALUE = "/A/Passage/To/India";
  83 
  84     static final String[] LD_PATH_STRINGS = {
  85         LD_LIBRARY_PATH + "=" + LD_LIBRARY_PATH_VALUE,
  86         LD_LIBRARY_PATH_32 + "=" + LD_LIBRARY_PATH_32_VALUE,
  87         LD_LIBRARY_PATH_64 + "=" + LD_LIBRARY_PATH_64_VALUE
  88     };
  89 


 268         File symLink = null;
 269         String libPathPrefix = isSDK ? "jre/lib" : "/lib";
 270         symLink = new File(JAVAHOME, libPathPrefix +
 271                 getJreArch() + "/" + LIBJVM);
 272         if (symLink.exists()) {
 273             throw new RuntimeException("symlink exists " + symLink.getAbsolutePath());
 274         }
 275     }
 276 
 277     /*
 278      * verify if all the symlinks in the images are created correctly,
 279      * only on solaris, this test works only on images.
 280      */
 281     @Test
 282     void testSymLinks() throws Exception {
 283         if (!isSolaris)
 284             return;
 285         verifySymLinks(JAVA_BIN);
 286         verifySymLinks(JAVA_JRE_BIN);
 287     }
 288     // exclude non-consequential binaries or scripts co-packaged in install
 289     private Pattern symlinkExcludes = Pattern.compile(".*jvisualvm.*");
 290 
 291     private void verifySymLinks(String bindir) throws IOException {
 292         File binDir = new File(bindir);
 293         System.err.println("verifying links in: " + bindir);
 294         File isaDir = new File(binDir, getArch()).getAbsoluteFile();
 295         if (!isaDir.exists()) {
 296             throw new RuntimeException("dir: " + isaDir + " does not exist");
 297         }
 298         try (DirectoryStream<Path> ds = Files.newDirectoryStream(binDir.toPath())) {
 299             for (Path p : ds) {
 300                 if (symlinkExcludes.matcher(p.toString()).matches() ||
 301                         Files.isDirectory(p, NOFOLLOW_LINKS)) {
 302                     continue;
 303                 }
 304                 Path link = new File(isaDir, p.getFileName().toString()).toPath();
 305                 if (Files.isSymbolicLink(link)) {
 306                     Path target = Files.readSymbolicLink(link);
 307                     if (target.startsWith("..") && p.endsWith(target.getFileName())) {
 308                         // System.out.println(target + " OK");
 309                         continue;
 310                     }
 311                     System.err.println("target:" + target);
 312                     System.err.println("file:" + p);
 313                 }
 314                 throw new RuntimeException("could not find link to " + p);
 315             }
 316         }
 317 
 318     }
 319     public static void main(String... args) throws Exception {
 320         if (isWindows) {
 321             System.err.println("Warning: test not applicable to windows");
 322             return;
 323         }
 324         ExecutionEnvironment ee = new ExecutionEnvironment();
 325         ee.run(args);
 326     }
 327 }