29 * @run main/othervm ExecutionEnvironment 30 */ 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 90 static final File testJarFile = new File("EcoFriendly.jar"); 91 253 } 254 } 255 256 /* 257 * checks to see there is no extra libjvm.so than needed 258 */ 259 @Test 260 void testNoSymLink() { 261 if (is64Bit) { 262 return; 263 } 264 265 File symLink = null; 266 String libPathPrefix = isSDK ? "jre/lib" : "/lib"; 267 symLink = new File(JAVAHOME, libPathPrefix + 268 getJreArch() + "/" + LIBJVM); 269 if (symLink.exists()) { 270 throw new RuntimeException("symlink exists " + symLink.getAbsolutePath()); 271 } 272 } 273 274 /* 275 * verify if all the symlinks in the images are created correctly, 276 * only on solaris, this test works only on images. 277 */ 278 @Test 279 void testSymLinks() throws Exception { 280 if (!isSolaris) 281 return; 282 verifySymLinks(JAVA_BIN); 283 verifySymLinks(JAVA_JRE_BIN); 284 } 285 // exclude non-consequential binaries or scripts co-packaged in other 286 // build phases 287 private final String excludeRE = 288 ".*jvisualvm.*" + 289 "|.*javaws.*" + 290 "|.*ControlPanel.*" + 291 "|.*java-rmi.cgi" + 292 "|.*jcontrol.*"; 293 private final Pattern symlinkExcludes = Pattern.compile(excludeRE); 294 295 private void verifySymLinks(String bindir) throws IOException { 296 File binDir = new File(bindir); 297 System.err.println("verifying links in: " + bindir); 298 File isaDir = new File(binDir, getArch()).getAbsoluteFile(); 299 if (!isaDir.exists()) { 300 throw new RuntimeException("dir: " + isaDir + " does not exist"); 301 } 302 try (DirectoryStream<Path> ds = Files.newDirectoryStream(binDir.toPath())) { 303 for (Path p : ds) { 304 if (symlinkExcludes.matcher(p.toString()).matches() || 305 Files.isDirectory(p, NOFOLLOW_LINKS)) { 306 continue; 307 } 308 Path link = new File(isaDir, p.getFileName().toString()).toPath(); 309 if (Files.isSymbolicLink(link)) { 310 Path target = Files.readSymbolicLink(link); 311 if (target.startsWith("..") && p.endsWith(target.getFileName())) { 312 // System.out.println(target + " OK"); 313 continue; 314 } 315 System.err.println("target:" + target); 316 System.err.println("file:" + p); 317 } 318 throw new RuntimeException("could not find link to " + p); 319 } 320 } 321 322 } 323 public static void main(String... args) throws Exception { 324 if (isWindows) { 325 System.err.println("Warning: test not applicable to windows"); 326 return; 327 } 328 ExecutionEnvironment ee = new ExecutionEnvironment(); 329 ee.run(args); 330 } 331 } | 29 * @run main/othervm ExecutionEnvironment 30 */ 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 * TODO: 50 * a. perhaps we need to add a test to audit all environment variables are 51 * in pristine condition after the launch, there may be a few that the 52 * launcher may add as implementation details. 53 * b. add a pldd for solaris to ensure only one libjvm.so is linked 54 */ 55 import java.io.File; 56 import java.io.FileNotFoundException; 57 import java.util.ArrayList; 58 import java.util.HashMap; 59 import java.util.List; 60 import java.util.Map; 61 62 public class ExecutionEnvironment extends TestHelper { 63 static final String LD_LIBRARY_PATH = TestHelper.isMacOSX 64 ? "DYLD_LIBRARY_PATH" 65 : "LD_LIBRARY_PATH"; 66 static final String LD_LIBRARY_PATH_32 = LD_LIBRARY_PATH + "_32"; 67 static final String LD_LIBRARY_PATH_64 = LD_LIBRARY_PATH + "_64"; 68 69 // Note: these paths need not exist on the filesytem 70 static final String LD_LIBRARY_PATH_VALUE = "/Bridge/On/The/River/Kwai"; 71 static final String LD_LIBRARY_PATH_32_VALUE = "/Lawrence/Of/Arabia"; 72 static final String LD_LIBRARY_PATH_64_VALUE = "/A/Passage/To/India"; 73 74 static final String[] LD_PATH_STRINGS = { 75 LD_LIBRARY_PATH + "=" + LD_LIBRARY_PATH_VALUE, 76 LD_LIBRARY_PATH_32 + "=" + LD_LIBRARY_PATH_32_VALUE, 77 LD_LIBRARY_PATH_64 + "=" + LD_LIBRARY_PATH_64_VALUE 78 }; 79 80 static final File testJarFile = new File("EcoFriendly.jar"); 81 243 } 244 } 245 246 /* 247 * checks to see there is no extra libjvm.so than needed 248 */ 249 @Test 250 void testNoSymLink() { 251 if (is64Bit) { 252 return; 253 } 254 255 File symLink = null; 256 String libPathPrefix = isSDK ? "jre/lib" : "/lib"; 257 symLink = new File(JAVAHOME, libPathPrefix + 258 getJreArch() + "/" + LIBJVM); 259 if (symLink.exists()) { 260 throw new RuntimeException("symlink exists " + symLink.getAbsolutePath()); 261 } 262 } 263 public static void main(String... args) throws Exception { 264 if (isWindows) { 265 System.err.println("Warning: test not applicable to windows"); 266 return; 267 } 268 ExecutionEnvironment ee = new ExecutionEnvironment(); 269 ee.run(args); 270 } 271 } |