1 /*
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
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 */
95 * @return The list of VM options with -J prefix
96 */
97 public static List<String> getForwardVmOptions() {
98 String[] opts = safeSplitString(VM_OPTIONS);
99 for (int i = 0; i < opts.length; i++) {
100 opts[i] = "-J" + opts[i];
101 }
102 return Arrays.asList(opts);
103 }
104
105 /**
106 * Returns the default JTReg arguments for a jvm running a test.
107 * This is the combination of JTReg arguments test.vm.opts and test.java.opts.
108 * @return An array of options, or an empty array if no opptions.
109 */
110 public static String[] getTestJavaOpts() {
111 List<String> opts = new ArrayList<String>();
112 Collections.addAll(opts, safeSplitString(VM_OPTIONS));
113 Collections.addAll(opts, safeSplitString(JAVA_OPTIONS));
114 return opts.toArray(new String[0]);
115 }
116
117 /**
118 * Combines given arguments with default JTReg arguments for a jvm running a test.
119 * This is the combination of JTReg arguments test.vm.opts and test.java.opts
120 * @return The combination of JTReg test java options and user args.
121 */
122 public static String[] addTestJavaOpts(String... userArgs) {
123 List<String> opts = new ArrayList<String>();
124 Collections.addAll(opts, getTestJavaOpts());
125 Collections.addAll(opts, userArgs);
126 return opts.toArray(new String[0]);
127 }
128
129 /**
130 * Removes any options specifying which GC to use, for example "-XX:+UseG1GC".
131 * Removes any options matching: -XX:(+/-)Use*GC
132 * Used when a test need to set its own GC version. Then any
133 * GC specified by the framework must first be removed.
134 * @return A copy of given opts with all GC options removed.
|
1 /*
2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
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 */
95 * @return The list of VM options with -J prefix
96 */
97 public static List<String> getForwardVmOptions() {
98 String[] opts = safeSplitString(VM_OPTIONS);
99 for (int i = 0; i < opts.length; i++) {
100 opts[i] = "-J" + opts[i];
101 }
102 return Arrays.asList(opts);
103 }
104
105 /**
106 * Returns the default JTReg arguments for a jvm running a test.
107 * This is the combination of JTReg arguments test.vm.opts and test.java.opts.
108 * @return An array of options, or an empty array if no opptions.
109 */
110 public static String[] getTestJavaOpts() {
111 List<String> opts = new ArrayList<String>();
112 Collections.addAll(opts, safeSplitString(VM_OPTIONS));
113 Collections.addAll(opts, safeSplitString(JAVA_OPTIONS));
114 return opts.toArray(new String[0]);
115 }
116
117 /**
118 * Returns the default JTReg arguments for a jvm running a test without
119 * options that matches regular expressions in {@code filters}.
120 * This is the combination of JTReg arguments test.vm.opts and test.java.opts.
121 * @param filters Regular expressions used to filter out options.
122 * @return An array of options, or an empty array if no options.
123 */
124 public static String[] getFilteredTestJavaOpts(String... filters) {
125 String options[] = getTestJavaOpts();
126
127 if (filters.length == 0) {
128 return options;
129 }
130
131 List<String> filteredOptions = new ArrayList<>(options.length);
132 Pattern patterns[] = new Pattern[filters.length];
133 for (int i = 0; i < filters.length; i++) {
134 patterns[i] = Pattern.compile(filters[i]);
135 }
136
137 for (String option : options) {
138 boolean matched = false;
139 for (int i = 0; i < patterns.length && !matched; i++) {
140 Matcher matcher = patterns[i].matcher(option);
141 matched = matcher.find();
142 }
143 if (!matched) {
144 filteredOptions.add(option);
145 }
146 }
147
148 return filteredOptions.toArray(new String[filteredOptions.size()]);
149 }
150
151 /**
152 * Combines given arguments with default JTReg arguments for a jvm running a test.
153 * This is the combination of JTReg arguments test.vm.opts and test.java.opts
154 * @return The combination of JTReg test java options and user args.
155 */
156 public static String[] addTestJavaOpts(String... userArgs) {
157 List<String> opts = new ArrayList<String>();
158 Collections.addAll(opts, getTestJavaOpts());
159 Collections.addAll(opts, userArgs);
160 return opts.toArray(new String[0]);
161 }
162
163 /**
164 * Removes any options specifying which GC to use, for example "-XX:+UseG1GC".
165 * Removes any options matching: -XX:(+/-)Use*GC
166 * Used when a test need to set its own GC version. Then any
167 * GC specified by the framework must first be removed.
168 * @return A copy of given opts with all GC options removed.
|