3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 package optionsvalidation;
25
26 import com.sun.tools.attach.VirtualMachine;
27 import com.sun.tools.attach.AttachOperationFailedException;
28 import java.util.ArrayList;
29 import java.util.List;
30 import jdk.test.lib.DynamicVMOption;
31 import jdk.test.lib.OutputAnalyzer;
32 import jdk.test.lib.Platform;
33 import jdk.test.lib.ProcessTools;
34 import jdk.test.lib.dcmd.CommandExecutor;
35 import jdk.test.lib.dcmd.JMXExecutor;
36 import sun.tools.attach.HotSpotVirtualMachine;
37
38 import static optionsvalidation.JVMOptionsUtils.failedMessage;
39 import static optionsvalidation.JVMOptionsUtils.printOutputContent;
40
41 public abstract class JVMOption {
42
43 /**
44 * Executor for JCMD
45 */
46 private final static CommandExecutor executor = new JMXExecutor();
47
48 private final static boolean isClient = Platform.isClient();
49
50 /**
51 * Name of the tested parameter
52 */
53 protected String name;
54
55 /**
56 * Range is defined for option inside VM
57 */
58 protected boolean withRange;
59
60 /**
61 * Prepend string which added before testing option to the command line
62 */
63 private final List<String> prepend;
64 private final StringBuilder prependString;
65
66 protected JVMOption() {
67 this.prepend = new ArrayList<>();
68 prependString = new StringBuilder();
69 withRange = false;
327 return failedTests;
328 }
329
330 /**
331 * Run java with passed parameter and check the result depending on the
332 * 'valid' parameter
333 *
334 * @param param tested parameter passed to the JVM
335 * @param valid indicates whether the JVM should fail or not
336 * @return true - if test passed
337 * @throws Exception if java process can not be started
338 */
339 private boolean runJavaWithParam(String optionValue, boolean valid) throws Exception {
340 int exitCode;
341 boolean result = true;
342 String value = optionValue.substring(optionValue.lastIndexOf("=") + 1);
343 String fullOptionString = prependString.toString() + optionValue;
344 List<String> runJava = new ArrayList<>();
345 OutputAnalyzer out;
346
347 if (isClient) {
348 runJava.add("-client");
349 }
350
351 runJava.addAll(prepend);
352 runJava.add(optionValue);
353 runJava.add(JVMOptionsUtils.class.getName());
354
355 out = new OutputAnalyzer(ProcessTools.createJavaProcessBuilder(runJava.toArray(new String[0])).start());
356
357 exitCode = out.getExitValue();
358
359 if (out.getOutput().contains("A fatal error has been detected by the Java Runtime Environment")) {
360 /* Always consider "fatal error" in output as fail */
361 failedMessage(name, fullOptionString, valid, "JVM output reports a fatal error. JVM exited with code " + exitCode + "!");
362 printOutputContent(out);
363 result = false;
364 } else if (valid == true) {
365 if ((exitCode != 0) && (exitCode != 1)) {
366 failedMessage(name, fullOptionString, valid, "JVM exited with unexpected error code = " + exitCode);
367 printOutputContent(out);
368 result = false;
369 } else if ((exitCode == 1) && (out.getOutput().isEmpty() == true)) {
370 failedMessage(name, fullOptionString, valid, "JVM exited with error(exitcode == 1)"
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package optionsvalidation;
24
25 import com.sun.tools.attach.VirtualMachine;
26 import com.sun.tools.attach.AttachOperationFailedException;
27 import java.util.ArrayList;
28 import java.util.List;
29 import jdk.test.lib.DynamicVMOption;
30 import jdk.test.lib.OutputAnalyzer;
31 import jdk.test.lib.ProcessTools;
32 import jdk.test.lib.dcmd.CommandExecutor;
33 import jdk.test.lib.dcmd.JMXExecutor;
34 import sun.tools.attach.HotSpotVirtualMachine;
35
36 import static optionsvalidation.JVMOptionsUtils.failedMessage;
37 import static optionsvalidation.JVMOptionsUtils.printOutputContent;
38 import static optionsvalidation.JVMOptionsUtils.VMType;
39
40 public abstract class JVMOption {
41
42 /**
43 * Executor for JCMD
44 */
45 private final static CommandExecutor executor = new JMXExecutor();
46
47 /**
48 * Name of the tested parameter
49 */
50 protected String name;
51
52 /**
53 * Range is defined for option inside VM
54 */
55 protected boolean withRange;
56
57 /**
58 * Prepend string which added before testing option to the command line
59 */
60 private final List<String> prepend;
61 private final StringBuilder prependString;
62
63 protected JVMOption() {
64 this.prepend = new ArrayList<>();
65 prependString = new StringBuilder();
66 withRange = false;
324 return failedTests;
325 }
326
327 /**
328 * Run java with passed parameter and check the result depending on the
329 * 'valid' parameter
330 *
331 * @param param tested parameter passed to the JVM
332 * @param valid indicates whether the JVM should fail or not
333 * @return true - if test passed
334 * @throws Exception if java process can not be started
335 */
336 private boolean runJavaWithParam(String optionValue, boolean valid) throws Exception {
337 int exitCode;
338 boolean result = true;
339 String value = optionValue.substring(optionValue.lastIndexOf("=") + 1);
340 String fullOptionString = prependString.toString() + optionValue;
341 List<String> runJava = new ArrayList<>();
342 OutputAnalyzer out;
343
344 if (VMType != null) {
345 runJava.add(VMType);
346 }
347 runJava.addAll(prepend);
348 runJava.add(optionValue);
349 runJava.add(JVMOptionsUtils.class.getName());
350
351 out = new OutputAnalyzer(ProcessTools.createJavaProcessBuilder(runJava.toArray(new String[0])).start());
352
353 exitCode = out.getExitValue();
354
355 if (out.getOutput().contains("A fatal error has been detected by the Java Runtime Environment")) {
356 /* Always consider "fatal error" in output as fail */
357 failedMessage(name, fullOptionString, valid, "JVM output reports a fatal error. JVM exited with code " + exitCode + "!");
358 printOutputContent(out);
359 result = false;
360 } else if (valid == true) {
361 if ((exitCode != 0) && (exitCode != 1)) {
362 failedMessage(name, fullOptionString, valid, "JVM exited with unexpected error code = " + exitCode);
363 printOutputContent(out);
364 result = false;
365 } else if ((exitCode == 1) && (out.getOutput().isEmpty() == true)) {
366 failedMessage(name, fullOptionString, valid, "JVM exited with error(exitcode == 1)"
|