test/tools/launcher/ExecutionEnvironment.java

Print this page




 123     }
 124     private void flagError(TestResult tr, String message) {
 125         System.err.println(tr);
 126         throw new RuntimeException(message);
 127     }
 128     /*
 129      * tests if the launcher pollutes the LD_LIBRARY_PATH variables ie. there
 130      * should not be any new variables or pollution/mutations of any kind, the
 131      * environment should be pristine.
 132      */
 133     @Test
 134     void testEcoFriendly() {
 135         TestResult tr = null;
 136 
 137         Map<String, String> env = new HashMap<>();
 138         for (String x : LD_PATH_STRINGS) {
 139             String pairs[] = x.split("=");
 140             env.put(pairs[0], pairs[1]);
 141         }
 142 
 143         tr = doExec(env, javaCmd, "-jar", testJarFile.getAbsolutePath());

 144 
 145         if (!tr.isNotZeroOutput()) {
 146             flagError(tr, "Error: No output at all. Did the test execute ?");
 147         }
 148 
 149         for (String x : LD_PATH_STRINGS) {
 150             if (!tr.contains(x)) {
 151                 flagError(tr, "FAIL: did not get <" + x + ">");
 152             }
 153         }
 154     }
 155 
 156     /*
 157      * ensures that there are no execs as long as we are in the same
 158      * data model
 159      */
 160     @Test
 161     void testNoExec() {
 162         Map<String, String> env = new HashMap<>();
 163         env.put(JLDEBUG_KEY, "true");
 164         TestResult tr = doExec(env, javaCmd, "-version");


 165         if (tr.testOutput.contains(EXPECTED_MARKER)) {
 166             flagError(tr, "testNoExec: found  warning <" + EXPECTED_MARKER +
 167                     "> the process execing ?");
 168         }
 169     }
 170 
 171     /*
 172      * This test ensures that LD_LIBRARY_PATH* values are interpreted by the VM
 173      * and the expected java.library.path behaviour.
 174      * For Generic platforms (All *nixes):
 175      *    * All LD_LIBRARY_PATH variable should be on java.library.path
 176      * For Solaris 32-bit
 177      *    * The LD_LIBRARY_PATH_32 should override LD_LIBRARY_PATH if specified
 178      * For Solaris 64-bit
 179      *    * The LD_LIBRARY_PATH_64 should override LD_LIBRARY_PATH if specified
 180      */
 181     @Test
 182     void testJavaLibraryPath() {
 183         TestResult tr = null;
 184 
 185         Map<String, String> env = new HashMap<>();
 186 
 187         if (TestHelper.isLinux || TestHelper.isMacOSX) {
 188             for (String x : LD_PATH_STRINGS) {
 189                 String pairs[] = x.split("=");
 190                 env.put(pairs[0], pairs[1]);
 191             }
 192 
 193             tr = doExec(env, javaCmd, "-jar", testJarFile.getAbsolutePath());

 194             verifyJavaLibraryPathGeneric(tr);
 195         } else {
 196             // no override
 197             env.clear();
 198             env.put(LD_LIBRARY_PATH, LD_LIBRARY_PATH_VALUE);
 199             tr = doExec(env, javaCmd, "-jar", testJarFile.getAbsolutePath());
 200             verifyJavaLibraryPathGeneric(tr);
 201 
 202             env.clear();
 203             for (String x : LD_PATH_STRINGS) {
 204                 String pairs[] = x.split("=");
 205                 env.put(pairs[0], pairs[1]);
 206             }
 207 
 208             // verify the override occurs for 64-bit system
 209             tr = doExec(env, javaCmd, "-jar", testJarFile.getAbsolutePath());
 210             verifyJavaLibraryPathOverride(tr, false);
 211         }
 212     }
 213 
 214     private void verifyJavaLibraryPathGeneric(TestResult tr) {
 215         if (!tr.matches("java.library.path=.*" + LD_LIBRARY_PATH_VALUE + ".*")) {


 227                 " java.library.path does not contain " +
 228                     (is32Bit ? LD_LIBRARY_PATH_32_VALUE : LD_LIBRARY_PATH_64_VALUE));
 229 
 230         }
 231         // make sure the generic value is absent
 232         if (!tr.notMatches("java.library.path=.*" + LD_LIBRARY_PATH_VALUE + ".*")) {
 233             flagError(tr, "verifyJavaLibraryPathOverride: " +
 234                     " java.library.path contains " + LD_LIBRARY_PATH_VALUE);
 235         }
 236     }
 237 
 238     /*
 239      * ensures we have indeed exec'ed the correct vm of choice, all VMs support
 240      * -server, however 32-bit VMs support -client and -server.
 241      */
 242     @Test
 243     void testVmSelection() {
 244 
 245         TestResult tr = null;
 246 
 247         if (is32Bit) {
 248             tr = doExec(javaCmd, "-client", "-version");
 249             if (!tr.matches(".*Client VM.*")) {
 250                 flagError(tr, "the expected vm -client did not launch");
 251             }
 252         }

 253         tr = doExec(javaCmd, "-server", "-version");
 254         if (!tr.matches(".*Server VM.*")) {
 255             flagError(tr, "the expected vm -server did not launch");
 256         }
 257     }

 258 
 259     /*
 260      * checks to see there is no extra libjvm.so than needed
 261      */
 262     @Test
 263     void testNoSymLink() {
 264         if (is64Bit) {
 265             return;
 266         }
 267 
 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     /*




 123     }
 124     private void flagError(TestResult tr, String message) {
 125         System.err.println(tr);
 126         throw new RuntimeException(message);
 127     }
 128     /*
 129      * tests if the launcher pollutes the LD_LIBRARY_PATH variables ie. there
 130      * should not be any new variables or pollution/mutations of any kind, the
 131      * environment should be pristine.
 132      */
 133     @Test
 134     void testEcoFriendly() {
 135         TestResult tr = null;
 136 
 137         Map<String, String> env = new HashMap<>();
 138         for (String x : LD_PATH_STRINGS) {
 139             String pairs[] = x.split("=");
 140             env.put(pairs[0], pairs[1]);
 141         }
 142 
 143         tr = doExec(env, javaCmd, haveServerVM ? "-server" : "-client",
 144                     "-jar", testJarFile.getAbsolutePath());
 145 
 146         if (!tr.isNotZeroOutput()) {
 147             flagError(tr, "Error: No output at all. Did the test execute ?");
 148         }
 149 
 150         for (String x : LD_PATH_STRINGS) {
 151             if (!tr.contains(x)) {
 152                 flagError(tr, "FAIL: did not get <" + x + ">");
 153             }
 154         }
 155     }
 156 
 157     /*
 158      * ensures that there are no execs as long as we are in the same
 159      * data model
 160      */
 161     @Test
 162     void testNoExec() {
 163         Map<String, String> env = new HashMap<>();
 164         env.put(JLDEBUG_KEY, "true");
 165         TestResult tr = doExec(env, javaCmd,
 166                                haveServerVM ? "-server" : "-client",
 167                                "-version");
 168         if (tr.testOutput.contains(EXPECTED_MARKER)) {
 169             flagError(tr, "testNoExec: found  warning <" + EXPECTED_MARKER +
 170                     "> the process execing ?");
 171         }
 172     }
 173 
 174     /*
 175      * This test ensures that LD_LIBRARY_PATH* values are interpreted by the VM
 176      * and the expected java.library.path behaviour.
 177      * For Generic platforms (All *nixes):
 178      *    * All LD_LIBRARY_PATH variable should be on java.library.path
 179      * For Solaris 32-bit
 180      *    * The LD_LIBRARY_PATH_32 should override LD_LIBRARY_PATH if specified
 181      * For Solaris 64-bit
 182      *    * The LD_LIBRARY_PATH_64 should override LD_LIBRARY_PATH if specified
 183      */
 184     @Test
 185     void testJavaLibraryPath() {
 186         TestResult tr = null;
 187 
 188         Map<String, String> env = new HashMap<>();
 189 
 190         if (TestHelper.isLinux || TestHelper.isMacOSX) {
 191             for (String x : LD_PATH_STRINGS) {
 192                 String pairs[] = x.split("=");
 193                 env.put(pairs[0], pairs[1]);
 194             }
 195 
 196             tr = doExec(env, javaCmd, haveServerVM ? "-server" : "-client",
 197                         "-jar", testJarFile.getAbsolutePath());
 198             verifyJavaLibraryPathGeneric(tr);
 199         } else { // Solaris
 200             // no override
 201             env.clear();
 202             env.put(LD_LIBRARY_PATH, LD_LIBRARY_PATH_VALUE);
 203             tr = doExec(env, javaCmd, "-jar", testJarFile.getAbsolutePath());
 204             verifyJavaLibraryPathGeneric(tr);
 205 
 206             env.clear();
 207             for (String x : LD_PATH_STRINGS) {
 208                 String pairs[] = x.split("=");
 209                 env.put(pairs[0], pairs[1]);
 210             }
 211 
 212             // verify the override occurs for 64-bit system
 213             tr = doExec(env, javaCmd, "-jar", testJarFile.getAbsolutePath());
 214             verifyJavaLibraryPathOverride(tr, false);
 215         }
 216     }
 217 
 218     private void verifyJavaLibraryPathGeneric(TestResult tr) {
 219         if (!tr.matches("java.library.path=.*" + LD_LIBRARY_PATH_VALUE + ".*")) {


 231                 " java.library.path does not contain " +
 232                     (is32Bit ? LD_LIBRARY_PATH_32_VALUE : LD_LIBRARY_PATH_64_VALUE));
 233 
 234         }
 235         // make sure the generic value is absent
 236         if (!tr.notMatches("java.library.path=.*" + LD_LIBRARY_PATH_VALUE + ".*")) {
 237             flagError(tr, "verifyJavaLibraryPathOverride: " +
 238                     " java.library.path contains " + LD_LIBRARY_PATH_VALUE);
 239         }
 240     }
 241 
 242     /*
 243      * ensures we have indeed exec'ed the correct vm of choice, all VMs support
 244      * -server, however 32-bit VMs support -client and -server.
 245      */
 246     @Test
 247     void testVmSelection() {
 248 
 249         TestResult tr = null;
 250 
 251         if (haveClientVM) {
 252             tr = doExec(javaCmd, "-client", "-version");
 253             if (!tr.matches(".*Client VM.*")) {
 254                 flagError(tr, "the expected vm -client did not launch");
 255             }
 256         }
 257         if (haveServerVM) {
 258             tr = doExec(javaCmd, "-server", "-version");
 259             if (!tr.matches(".*Server VM.*")) {
 260                 flagError(tr, "the expected vm -server did not launch");
 261             }
 262         }
 263     }
 264 
 265     /*
 266      * checks to see there is no extra libjvm.so than needed
 267      */
 268     @Test
 269     void testNoSymLink() {
 270         if (is64Bit) {
 271             return;
 272         }
 273 
 274         File symLink = null;
 275         String libPathPrefix = isSDK ? "jre/lib" : "/lib";
 276         symLink = new File(JAVAHOME, libPathPrefix +
 277                 getJreArch() + "/" + LIBJVM);
 278         if (symLink.exists()) {
 279             throw new RuntimeException("symlink exists " + symLink.getAbsolutePath());
 280         }
 281     }
 282 
 283     /*