Path: blob/master/test/hotspot/jtreg/runtime/CommandLine/VMOptionsFile/TestVMOptionsFile.java
41153 views
/*1* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 8061999 8135195 813655226* @summary Test "-XX:VMOptionsFile" VM option27* @library /test/lib28* @modules java.base/jdk.internal.misc29* @modules jdk.management30* @run driver TestVMOptionsFile31*/3233import java.io.File;34import java.io.FileWriter;35import java.io.IOException;36import java.nio.file.Files;37import java.nio.file.Paths;38import java.nio.file.Path;39import java.nio.file.attribute.PosixFilePermissions;40import java.nio.file.attribute.AclEntry;41import java.nio.file.attribute.AclEntryPermission;42import java.nio.file.attribute.AclEntryType;43import java.nio.file.attribute.AclFileAttributeView;44import java.nio.file.attribute.UserPrincipal;45import java.nio.file.StandardCopyOption;46import java.util.ArrayList;47import java.util.Arrays;48import java.util.LinkedHashSet;49import java.util.List;50import java.util.Properties;51import java.util.Set;52import jdk.test.lib.Asserts;53import jdk.test.lib.management.DynamicVMOption;54import jdk.test.lib.process.OutputAnalyzer;55import jdk.test.lib.process.ProcessTools;5657public class TestVMOptionsFile {5859/* Various valid VM Option files */60private static final String VM_OPTION_FILE_EMPTY = "optionfile_empty";61private static final String VM_OPTION_FILE_TABS_AND_SPACES = "optionfile_only_tabsandspaces";62private static final String VM_OPTION_FILE_1 = "optionfile_1";63private static final String VM_OPTION_FILE_2 = "optionFILE_2";64private static final String VM_OPTION_FILE_3 = "optionfile_3";65private static final String VM_OPTION_FILE_QUOTE = "optionfile_quote";66private static final String VM_OPTION_FILE_BIG = "optionfile_big";67private static final int REPEAT_COUNT = 512;68/* Name of the file with flags for VM_OPTION_FILE_2 Option file */69private static final String FLAGS_FILE = "flags_file";70/* VM Option file with a lot of options with quote on separate lines */71private static final String VM_OPTION_FILE_LOT_OF_OPTIONS_QUOTE = "optionfile_lot_of_options_quote";72/* Number of properties defined in VM_OPTION_FILE_LOT_OF_OPTIONS_QUOTE */73private static final int NUM_OF_PROP_IN_FILE_LOT_OF_OPTIONS_QUOTE = 70;74/* VM Option file with long property */75private static final String VM_OPTION_FILE_WITH_LONG_PROPERTY = "optionfile_long_property";76private static final String LONG_PROPERTY_NAME = "veryl'" + String.format("%1536s", "").replace(' ', 'o') + "ng'name";77private static final String LONG_PROPERTY_VALUE = String.format("%2096s", "").replaceAll(" ", "long");78/* 2 VM Option files with unmatched quotes */79private static final String VM_OPTION_FILE_UNMATCHED_QUOTE_1 = "optionfile_unmatched_quote_1";80private static final String VM_OPTION_FILE_UNMATCHED_QUOTE_2 = "optionfile_unmatched_quote_2";81/* VM Option file with bad option in it */82private static final String VM_OPTION_FILE_WITH_BAD_OPTION = "optionfile_bad_option";83/* VM Option file with "-XX:VMOptionsFile=" option in it */84private static final String VM_OPTION_FILE_WITH_VM_OPTION_FILE = "optionfile_with_optionfile";85/* VM Option file with "-XX:VMOptionsFile=" option in it, where file is the same option file */86private static final String VM_OPTION_FILE_WITH_SAME_VM_OPTION_FILE = "optionfile_with_same_optionfile";87/* VM Option file without read permissions(not accessible) */88private static final String VM_OPTION_FILE_WITHOUT_READ_PERMISSIONS = "optionfile_wo_read_perm";89/* VM Option file which does not exist */90private static final String NOT_EXISTING_FILE = "not_exist_junk2123";9192/* JAVA_TOOL_OPTIONS environment variable */93private static final String JAVA_TOOL_OPTIONS = "JAVA_TOOL_OPTIONS";94/* _JAVA_OPTIONS environment variable */95private static final String JAVA_OPTIONS = "_JAVA_OPTIONS";9697/* Exit code for JVM, zero - for success, non-zero for failure */98private static final int JVM_SUCCESS = 0;99private static final int JVM_FAIL_WITH_EXIT_CODE_1 = 1;100101/* Current working directory */102private static final String CURRENT_DIR = System.getProperty("user.dir");103104/* Source directory */105private static final String SOURCE_DIR = System.getProperty("test.src", ".");106107/* VM Options which are passed to the JVM */108private static final List<String> VMParams = new ArrayList<>();109/* Argument passed to the PrintPropertyAndOptions.main */110private static final Set<String> appParams = new LinkedHashSet<>();111112private static OutputAnalyzer output;113114private static final String PRINT_PROPERTY_FORMAT = "Property %s=%s";115private static final String PRINT_VM_OPTION_FORMAT = "Virtual Machine option %s=%s";116117/*118* Get absoulte path to file from folder with sources119*/120private static String getAbsolutePathFromSource(String fileName) {121return SOURCE_DIR + File.separator + fileName;122}123124/*125* Make file non-readable by modifying its permissions.126* If file supports "posix" attributes, then modify it.127* Otherwise check for "acl" attributes.128*/129private static void makeFileNonReadable(String file) throws IOException {130Path filePath = Paths.get(file);131Set<String> supportedAttr = filePath.getFileSystem().supportedFileAttributeViews();132133if (supportedAttr.contains("posix")) {134Files.setPosixFilePermissions(filePath, PosixFilePermissions.fromString("-w--w----"));135} else if (supportedAttr.contains("acl")) {136UserPrincipal fileOwner = Files.getOwner(filePath);137138AclFileAttributeView view = Files.getFileAttributeView(filePath, AclFileAttributeView.class);139140AclEntry entry = AclEntry.newBuilder()141.setType(AclEntryType.DENY)142.setPrincipal(fileOwner)143.setPermissions(AclEntryPermission.READ_DATA)144.build();145146List<AclEntry> acl = view.getAcl();147acl.add(0, entry);148view.setAcl(acl);149}150}151152private static void copyFromSource(String fileName) throws IOException {153Files.copy(Paths.get(getAbsolutePathFromSource(fileName)),154Paths.get(fileName), StandardCopyOption.REPLACE_EXISTING);155}156157private static void createOptionFiles() throws IOException {158FileWriter fw = new FileWriter(VM_OPTION_FILE_WITH_VM_OPTION_FILE);159160/* Create VM option file with following parameters "-XX:VMOptionFile=<absolute_path_to_the_VM_option_file> */161fw.write("-XX:VMOptionsFile=" + getAbsolutePathFromSource(VM_OPTION_FILE_1));162fw.close();163164/* Create VM option file with following parameters "-XX:MinHeapFreeRatio=12 -XX:VMOptionFile=<absolute_path_to_the_same_VM_option_file> */165fw = new FileWriter(VM_OPTION_FILE_WITH_SAME_VM_OPTION_FILE);166fw.write("-XX:MinHeapFreeRatio=12 -XX:VMOptionsFile=" + (new File(VM_OPTION_FILE_WITH_SAME_VM_OPTION_FILE)).getCanonicalPath());167fw.close();168169/* Create VM option file with long property */170fw = new FileWriter(VM_OPTION_FILE_WITH_LONG_PROPERTY);171fw.write("-D" + LONG_PROPERTY_NAME + "=" + LONG_PROPERTY_VALUE);172fw.close();173174/* Create big VM option file */175fw = new FileWriter(VM_OPTION_FILE_BIG);176fw.write("-XX:MinHeapFreeRatio=17\n");177for (int i = 0; i < REPEAT_COUNT; i++) {178if (i == REPEAT_COUNT / 2) {179fw.write("-XX:+PrintVMOptions ");180}181fw.write("-Dmy.property=value" + (i + 1) + "\n");182}183fw.write("-XX:MaxHeapFreeRatio=85\n");184fw.close();185186/* Copy valid VM option file and change its permission to make it not accessible */187Files.copy(Paths.get(getAbsolutePathFromSource(VM_OPTION_FILE_1)),188Paths.get(VM_OPTION_FILE_WITHOUT_READ_PERMISSIONS),189StandardCopyOption.REPLACE_EXISTING);190191makeFileNonReadable(VM_OPTION_FILE_WITHOUT_READ_PERMISSIONS);192193/* Copy valid VM option file to perform test with relative path */194copyFromSource(VM_OPTION_FILE_2);195196/* Copy flags file to the current working folder */197copyFromSource(FLAGS_FILE);198199/* Create a new empty file */200new File(VM_OPTION_FILE_EMPTY).createNewFile();201}202203/*204* Add parameters to the VM Parameters list205*/206private static void addVMParam(String... params) {207VMParams.addAll(Arrays.asList(params));208}209210/*211* Add VM option name to the application arguments list212*/213private static void addVMOptionsToCheck(String... params) {214for (String param : params) {215appParams.add("vmoption=" + param);216}217}218219/*220* Add property to the VM Params list and to the application arguments list221*/222private static void addProperty(String propertyName, String propertyValue) {223addVMParam("-D" + propertyName + "=" + propertyValue);224}225226/*227* Add "-XX:VMOptionsfile" parameter to the VM Params list228*/229private static void addVMOptionsFile(String fileName) {230addVMParam("-XX:VMOptionsFile=" + fileName);231}232233private static void outputShouldContain(String expectedString) {234output.shouldContain(expectedString);235}236237private static void outputShouldNotContain(String expectedString) {238output.shouldNotContain(expectedString);239}240241private static ProcessBuilder createProcessBuilder() throws Exception {242ProcessBuilder pb;243List<String> runJava = new ArrayList<>();244245runJava.addAll(VMParams);246runJava.add(PrintPropertyAndOptions.class.getName());247runJava.addAll(appParams);248249pb = ProcessTools.createJavaProcessBuilder(runJava);250251VMParams.clear();252appParams.clear();253254return pb;255}256257private static void runJavaCheckExitValue(ProcessBuilder pb, int expectedExitValue) throws Exception {258output = new OutputAnalyzer(pb.start());259output.shouldHaveExitValue(expectedExitValue);260}261262private static void runJavaCheckExitValue(int expectedExitValue) throws Exception {263runJavaCheckExitValue(createProcessBuilder(), expectedExitValue);264}265266/*267* Update environment variable in passed ProcessBuilder object to the passed value268*/269private static void updateEnvironment(ProcessBuilder pb, String name, String value) {270pb.environment().put(name, value);271}272273/*274* Check property value by examining output275*/276private static void checkProperty(String property, String expectedValue) {277outputShouldContain(String.format(PRINT_PROPERTY_FORMAT, property, expectedValue));278}279280/*281* Check VM Option value by examining output282*/283private static void checkVMOption(String vmOption, String expectedValue) {284outputShouldContain(String.format(PRINT_VM_OPTION_FORMAT, vmOption, expectedValue));285}286287private static void testVMOptions() throws Exception {288ProcessBuilder pb;289290/* Check that empty VM Option file is accepted without errors */291addVMOptionsFile(VM_OPTION_FILE_EMPTY);292293runJavaCheckExitValue(JVM_SUCCESS);294295/* Check that VM Option file with tabs and spaces is accepted without errors */296addVMOptionsFile(getAbsolutePathFromSource(VM_OPTION_FILE_TABS_AND_SPACES));297298runJavaCheckExitValue(JVM_SUCCESS);299300/* Check that parameters are gotten from first VM Option file. Pass absolute path to the VM Option file */301addVMParam("-showversion");302addVMOptionsFile(getAbsolutePathFromSource(VM_OPTION_FILE_1));303addVMOptionsToCheck("SurvivorRatio", "MinHeapFreeRatio");304305runJavaCheckExitValue(JVM_SUCCESS);306outputShouldContain("interpreted mode");307checkProperty("optfile_1", "option_file_1");308checkVMOption("SurvivorRatio", "16");309checkVMOption("MinHeapFreeRatio", "22");310311/*312* Check that parameters are gotten from second VM Option file which also contains flags file.313* Flags file and option file contains NewRatio, but since options from VM Option file314* are processed later NewRatio should be set to value from VM Option file315* Pass relative path to the VM Option file in form "vmoptionfile"316*/317addVMOptionsFile(VM_OPTION_FILE_2);318addVMOptionsToCheck("UseGCOverheadLimit", "NewRatio", "MinHeapFreeRatio", "MaxFDLimit", "AlwaysPreTouch");319320runJavaCheckExitValue(JVM_SUCCESS);321checkProperty("javax.net.ssl.keyStorePassword", "someVALUE123+");322checkVMOption("UseGCOverheadLimit", "true");323checkVMOption("NewRatio", "4");324checkVMOption("MinHeapFreeRatio", "3");325checkVMOption("MaxFDLimit", "true");326checkVMOption("AlwaysPreTouch", "false");327328/* Check that parameters are gotten from third VM Option file which contains a mix of the options */329addVMParam("-showversion");330addVMOptionsFile(getAbsolutePathFromSource(VM_OPTION_FILE_3));331addVMOptionsToCheck("UseGCOverheadLimit", "NewRatio");332333runJavaCheckExitValue(JVM_SUCCESS);334outputShouldContain("interpreted mode");335checkProperty("other.secret.data", "qwerty");336checkProperty("property", "second");337checkVMOption("UseGCOverheadLimit", "false");338checkVMOption("NewRatio", "16");339340/* Check that quotes are processed normally in VM Option file */341addVMParam("-showversion");342addVMOptionsFile(getAbsolutePathFromSource(VM_OPTION_FILE_QUOTE));343addVMOptionsToCheck("ErrorFile");344345runJavaCheckExitValue(JVM_SUCCESS);346347outputShouldContain("interpreted mode");348checkProperty("my.quote.single", "Property in single quote. Here a double qoute\" Add some slashes \\/");349checkProperty("my.quote.double", "Double qoute. Include single '.");350checkProperty("javax.net.ssl.trustStorePassword", "data @+NEW");351checkVMOption("ErrorFile", "./my error file");352353/*354* Verify that VM Option file accepts a file with 70 properties and with two options on separate355* lines and properties that use quotes a lot.356*/357addVMOptionsFile(getAbsolutePathFromSource(VM_OPTION_FILE_LOT_OF_OPTIONS_QUOTE));358addVMOptionsToCheck("MinHeapFreeRatio", "MaxHeapFreeRatio");359360runJavaCheckExitValue(JVM_SUCCESS);361362for (int i = 1; i <= NUM_OF_PROP_IN_FILE_LOT_OF_OPTIONS_QUOTE; i++) {363checkProperty(String.format("prop%02d", i), String.format("%02d", i));364}365checkVMOption("MinHeapFreeRatio", "7");366checkVMOption("MaxHeapFreeRatio", "96");367368/*369* Verify that VM Option file accepts a file with very long property.370*/371addVMOptionsFile(VM_OPTION_FILE_WITH_LONG_PROPERTY);372373runJavaCheckExitValue(JVM_SUCCESS);374375checkProperty(LONG_PROPERTY_NAME.replaceAll("'", ""), LONG_PROPERTY_VALUE);376377/*378* Verify that VM Option file accepts a big VM Option file379*/380addVMOptionsFile(VM_OPTION_FILE_BIG);381addVMOptionsToCheck("MinHeapFreeRatio");382addVMOptionsToCheck("MaxHeapFreeRatio");383384runJavaCheckExitValue(JVM_SUCCESS);385386outputShouldContain("VM option '+PrintVMOptions'");387checkProperty("my.property", "value" + REPEAT_COUNT);388checkVMOption("MinHeapFreeRatio", "17");389checkVMOption("MaxHeapFreeRatio", "85");390391/* Pass VM Option file in _JAVA_OPTIONS environment variable */392addVMParam("-showversion");393addVMOptionsToCheck("SurvivorRatio", "MinHeapFreeRatio");394pb = createProcessBuilder();395396updateEnvironment(pb, JAVA_OPTIONS, "-XX:VMOptionsFile=" + getAbsolutePathFromSource(VM_OPTION_FILE_1));397398runJavaCheckExitValue(pb, JVM_SUCCESS);399outputShouldContain("interpreted mode");400checkProperty("optfile_1", "option_file_1");401checkVMOption("SurvivorRatio", "16");402checkVMOption("MinHeapFreeRatio", "22");403404/* Pass VM Option file in JAVA_TOOL_OPTIONS environment variable */405addVMOptionsToCheck("UseGCOverheadLimit", "NewRatio", "MinHeapFreeRatio", "MaxFDLimit", "AlwaysPreTouch");406pb = createProcessBuilder();407408updateEnvironment(pb, JAVA_TOOL_OPTIONS, "-XX:VMOptionsFile=" + VM_OPTION_FILE_2);409410runJavaCheckExitValue(pb, JVM_SUCCESS);411checkProperty("javax.net.ssl.keyStorePassword", "someVALUE123+");412checkVMOption("UseGCOverheadLimit", "true");413checkVMOption("NewRatio", "4");414checkVMOption("MinHeapFreeRatio", "3");415checkVMOption("MaxFDLimit", "true");416checkVMOption("AlwaysPreTouch", "false");417}418419private static ProcessBuilder prepareTestCase(int testCase) throws Exception {420ProcessBuilder pb;421422Asserts.assertTrue(0 < testCase && testCase < 6, "testCase should be from 1 to 5");423424addVMParam("-showversion");425addVMOptionsToCheck("MinHeapFreeRatio", "SurvivorRatio", "NewRatio");426427if (testCase < 5) {428addVMParam("-XX:Flags=flags_file", "-XX:-PrintVMOptions");429addProperty("shared.property", "command_line_before");430addProperty("clb", "unique_command_line_before");431addVMParam("-XX:MinHeapFreeRatio=7");432}433434if (testCase < 4) {435addVMOptionsFile(getAbsolutePathFromSource(VM_OPTION_FILE_1));436}437438if (testCase < 3) {439addVMParam("-XX:MinHeapFreeRatio=9", "-XX:-PrintVMOptions");440addProperty("shared.property", "command_line_after");441addProperty("cla", "unique_command_line_after");442}443444/* Create ProcessBuilder after all setup is done to update environment variables */445pb = createProcessBuilder();446447if (testCase < 2) {448updateEnvironment(pb, JAVA_OPTIONS, "-Dshared.property=somevalue -Djo=unique_java_options "449+ "-XX:MinHeapFreeRatio=18 -Dshared.property=java_options -XX:MinHeapFreeRatio=11 -XX:+PrintVMOptions");450}451452if (testCase < 6) {453updateEnvironment(pb, JAVA_TOOL_OPTIONS, "-Dshared.property=qwerty -Djto=unique_java_tool_options "454+ "-XX:MinHeapFreeRatio=15 -Dshared.property=java_tool_options -XX:MinHeapFreeRatio=6 -XX:+PrintVMOptions");455}456457return pb;458}459460private static void testVMOptionsLastArgumentsWins() throws Exception {461ProcessBuilder pb;462463/*464* "shared.property" property and "MinHeapFreeRatio" XX VM Option are defined465* in flags file, JAVA_TOOL_OPTIONS and _JAVA_OPTIONS environment variables,466* on command line before VM Option file, on command line after VM Option file467* and also in VM Option file. Verify that last argument wins. Also check468* unique properties and VM Options.469* Here is the order of options processing and last argument wins:470* 1) Flags file471* 2) JAVA_TOOL_OPTIONS environment variables472* 3) Pseudo command line from launcher473* 4) _JAVA_OPTIONS474* In every category arguments processed from left to right and from up to down475* and the last processed arguments wins, i.e. if argument is defined several476* times the value of argument will be equal to the last processed argument.477*478* "shared.property" property and "MinHeapFreeRatio" should be equal to the479* value from _JAVA_OPTIONS environment variable480*/481pb = prepareTestCase(1);482483runJavaCheckExitValue(pb, JVM_SUCCESS);484485outputShouldContain("interpreted mode");486outputShouldContain("VM option '+PrintVMOptions'");487checkProperty("shared.property", "java_options");488checkVMOption("MinHeapFreeRatio", "11");489/* Each category defines its own properties */490checkProperty("jto", "unique_java_tool_options");491checkProperty("jo", "unique_java_options");492checkProperty("clb", "unique_command_line_before");493checkProperty("optfile_1", "option_file_1");494checkProperty("cla", "unique_command_line_after");495/* SurvivorRatio defined only in VM Option file */496checkVMOption("SurvivorRatio", "16");497/* NewRatio defined only in flags file */498checkVMOption("NewRatio", "5");499500/*501* The same as previous but without _JAVA_OPTIONS environment variable.502* "shared.property" property and "MinHeapFreeRatio" should be equal to the503* value from pseudo command line after VM Option file504*/505pb = prepareTestCase(2);506507runJavaCheckExitValue(pb, JVM_SUCCESS);508509outputShouldContain("interpreted mode");510outputShouldNotContain("VM option '+PrintVMOptions'");511checkProperty("shared.property", "command_line_after");512checkVMOption("MinHeapFreeRatio", "9");513514/*515* The same as previous but without arguments in pseudo command line after516* VM Option file.517* "shared.property" property and "MinHeapFreeRatio" should be equal to the518* value from VM Option file.519*/520pb = prepareTestCase(3);521522runJavaCheckExitValue(pb, JVM_SUCCESS);523524outputShouldContain("interpreted mode");525outputShouldContain("VM option '+PrintVMOptions'");526checkProperty("shared.property", "vmoptfile");527checkVMOption("MinHeapFreeRatio", "22");528529/*530* The same as previous but without arguments in VM Option file.531* "shared.property" property and "MinHeapFreeRatio" should be equal to the532* value from pseudo command line.533*/534pb = prepareTestCase(4);535536runJavaCheckExitValue(pb, JVM_SUCCESS);537538outputShouldNotContain("VM option '+PrintVMOptions'");539checkProperty("shared.property", "command_line_before");540checkVMOption("MinHeapFreeRatio", "7");541542/*543* The same as previous but without arguments from pseudo command line.544* "shared.property" property and "MinHeapFreeRatio" should be equal to the545* value from JAVA_TOOL_OPTIONS environment variable.546*/547pb = prepareTestCase(5);548549runJavaCheckExitValue(pb, JVM_SUCCESS);550551outputShouldContain("VM option '+PrintVMOptions'");552checkProperty("shared.property", "java_tool_options");553checkVMOption("MinHeapFreeRatio", "6");554}555556private static void testVMOptionsInvalid() throws Exception {557ProcessBuilder pb;558559/* Pass directory instead of file */560addVMOptionsFile(CURRENT_DIR);561562runJavaCheckExitValue(JVM_FAIL_WITH_EXIT_CODE_1);563564/* Pass not existing file */565addVMOptionsFile(getAbsolutePathFromSource(NOT_EXISTING_FILE));566567runJavaCheckExitValue(JVM_FAIL_WITH_EXIT_CODE_1);568outputShouldContain("Could not open options file");569570/* Pass VM option file with bad option */571addVMOptionsFile(getAbsolutePathFromSource(VM_OPTION_FILE_WITH_BAD_OPTION));572573runJavaCheckExitValue(JVM_FAIL_WITH_EXIT_CODE_1);574outputShouldContain("Unrecognized VM option");575576/* Pass VM option file with same VM option file option in it */577addVMOptionsFile(VM_OPTION_FILE_WITH_SAME_VM_OPTION_FILE);578579runJavaCheckExitValue(JVM_FAIL_WITH_EXIT_CODE_1);580outputShouldContain("A VM options file may not refer to a VM options file. Specification of '-XX:VMOptionsFile=<file-name>' in the options file");581582/* Pass VM option file with VM option file option in it */583addVMOptionsFile(VM_OPTION_FILE_WITH_VM_OPTION_FILE);584585runJavaCheckExitValue(JVM_FAIL_WITH_EXIT_CODE_1);586outputShouldContain("A VM options file may not refer to a VM options file. Specification of '-XX:VMOptionsFile=<file-name>' in the options file");587588/* Pass VM option file which is not accessible (without read permissions) */589addVMOptionsFile(getAbsolutePathFromSource(VM_OPTION_FILE_WITHOUT_READ_PERMISSIONS));590591runJavaCheckExitValue(JVM_FAIL_WITH_EXIT_CODE_1);592outputShouldContain("Could not open options file");593594/* Pass two VM option files */595addVMOptionsFile(getAbsolutePathFromSource(VM_OPTION_FILE_1));596addVMOptionsFile(VM_OPTION_FILE_2);597598runJavaCheckExitValue(JVM_FAIL_WITH_EXIT_CODE_1);599outputShouldContain("is already specified in the");600601/* Pass empty option file i.e. pass "-XX:VMOptionsFile=" */602addVMOptionsFile("");603604runJavaCheckExitValue(JVM_FAIL_WITH_EXIT_CODE_1);605outputShouldContain("Could not open options file");606607/* Pass VM option file with unmatched single quote */608addVMOptionsFile(getAbsolutePathFromSource(VM_OPTION_FILE_UNMATCHED_QUOTE_1));609610runJavaCheckExitValue(JVM_FAIL_WITH_EXIT_CODE_1);611outputShouldContain("Unmatched quote in");612613/* Pass VM option file with unmatched double quote in X option */614addVMOptionsFile(getAbsolutePathFromSource(VM_OPTION_FILE_UNMATCHED_QUOTE_2));615616runJavaCheckExitValue(JVM_FAIL_WITH_EXIT_CODE_1);617outputShouldContain("Unmatched quote in");618}619620public static void main(String[] args) throws Exception {621/*622* Preparation before actual testing - create two VM Option files623* which contains VM Option file in it and copy other files to the624* current working folder625*/626createOptionFiles();627628testVMOptions(); /* Test VM Option file general functionality */629testVMOptionsLastArgumentsWins(); /* Verify that last argument wins */630testVMOptionsInvalid(); /* Test invalid VM Option file functionality */631632}633634public static class PrintPropertyAndOptions {635636public static void main(String[] arguments) {637String vmOption;638Properties properties = System.getProperties();639640for (String propertyName : properties.stringPropertyNames()) {641System.out.println(String.format(PRINT_PROPERTY_FORMAT, propertyName, System.getProperty(propertyName, "NOT DEFINED")));642}643644for (String arg : arguments) {645if (arg.startsWith("vmoption=")) {646vmOption = arg.substring(9);647System.out.println(String.format(PRINT_VM_OPTION_FORMAT, vmOption, new DynamicVMOption(vmOption).getValue()));648}649}650}651}652}653654655