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 /** 25 * @test 26 * @summary Basic test of VM::getRuntimeArguments 27 * @library /lib/testlibrary 28 * @modules java.base/jdk.internal.misc 29 * java.compact3 30 * jdk.zipfs 31 * @run testng RuntimeArguments 32 */ 33 34 import java.util.Arrays; 35 import java.util.List; 36 import java.util.stream.Stream; 37 import jdk.internal.misc.VM; 38 import jdk.testlibrary.ProcessTools; 39 import org.testng.annotations.DataProvider; 40 import org.testng.annotations.Test; 41 import static org.testng.Assert.*; 42 43 public class RuntimeArguments { 44 static final String TEST_CLASSES = System.getProperty("test.classes"); 45 46 @DataProvider(name = "options") 47 public Object[][] options() { 48 return new Object[][] { 49 { // CLI options 50 List.of("--add-exports", 51 "java.base/jdk.internal.misc=ALL-UNNAMED", 52 "--add-exports", 53 "java.base/jdk.internal.perf=ALL-UNNAMED", 54 "--add-modules", 55 "jdk.zipfs"), 56 // expected runtime arguments 57 List.of("--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED", 58 "--add-exports=java.base/jdk.internal.perf=ALL-UNNAMED", 59 "--add-modules=jdk.zipfs") 60 }, 61 { // CLI options 62 List.of("--add-exports", 63 "java.base/jdk.internal.misc=ALL-UNNAMED", 64 "--add-modules", 65 "jdk.zipfs", 66 "--limit-modules", 67 "java.compact3"), 68 // expected runtime arguments 69 List.of("--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED", 70 "--add-modules=jdk.zipfs", 71 "--limit-modules=java.compact3"), 72 }, 73 }; 74 }; 75 76 public static void main(String... expected) { 77 String[] vmArgs = VM.getRuntimeArguments(); 78 if (!Arrays.equals(vmArgs, expected)) { 79 throw new RuntimeException(Arrays.toString(vmArgs) + 80 " != " + Arrays.toString(expected)); 81 } 82 } 83 84 @Test(dataProvider = "options") 85 public void test(List<String> args, List<String> expected) throws Exception { 86 // launch a test program 87 // $ java <runtime-arguments> -classpath <cpath> RuntimeArguments <expected> 88 89 Stream<String> options = Stream.concat(args.stream(), 90 Stream.of("-classpath", TEST_CLASSES, "RuntimeArguments")); 91 | 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 /** 25 * @test 26 * @summary Basic test of VM::getRuntimeArguments 27 * @library /lib/testlibrary 28 * @modules java.base/jdk.internal.misc 29 * jdk.zipfs 30 * @run testng RuntimeArguments 31 */ 32 33 import java.util.Arrays; 34 import java.util.List; 35 import java.util.stream.Stream; 36 import jdk.internal.misc.VM; 37 import jdk.testlibrary.ProcessTools; 38 import org.testng.annotations.DataProvider; 39 import org.testng.annotations.Test; 40 import static org.testng.Assert.*; 41 42 public class RuntimeArguments { 43 static final String TEST_CLASSES = System.getProperty("test.classes"); 44 45 @DataProvider(name = "options") 46 public Object[][] options() { 47 return new Object[][] { 48 { // CLI options 49 List.of("--add-exports", 50 "java.base/jdk.internal.misc=ALL-UNNAMED", 51 "--add-exports", 52 "java.base/jdk.internal.perf=ALL-UNNAMED", 53 "--add-modules", 54 "jdk.zipfs"), 55 // expected runtime arguments 56 List.of("--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED", 57 "--add-exports=java.base/jdk.internal.perf=ALL-UNNAMED", 58 "--add-modules=jdk.zipfs") 59 }, 60 { // CLI options 61 List.of("--add-exports", 62 "java.base/jdk.internal.misc=ALL-UNNAMED", 63 "--add-modules", 64 "jdk.zipfs", 65 "--limit-modules", 66 "java.logging,java.xml,jdk.charsets,jdk.zipfs"), 67 // expected runtime arguments 68 List.of("--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED", 69 "--add-modules=jdk.zipfs", 70 "--limit-modules=java.logging,java.xml,jdk.charsets,jdk.zipfs"), 71 }, 72 }; 73 }; 74 75 public static void main(String... expected) { 76 String[] vmArgs = VM.getRuntimeArguments(); 77 if (!Arrays.equals(vmArgs, expected)) { 78 throw new RuntimeException(Arrays.toString(vmArgs) + 79 " != " + Arrays.toString(expected)); 80 } 81 } 82 83 @Test(dataProvider = "options") 84 public void test(List<String> args, List<String> expected) throws Exception { 85 // launch a test program 86 // $ java <runtime-arguments> -classpath <cpath> RuntimeArguments <expected> 87 88 Stream<String> options = Stream.concat(args.stream(), 89 Stream.of("-classpath", TEST_CLASSES, "RuntimeArguments")); 90 |