changeset 39062:93c6e022db74

8159630: Add new test for jdk.internal.misc.VM::getRuntimeArguments Reviewed-by: lancea
author mchung
date Fri, 17 Jun 2016 14:37:00 -0700
parents 0a7abfc4f4b0
children 500967b1216c
files jdk/src/java.base/share/classes/jdk/internal/misc/VM.java jdk/test/jdk/internal/misc/VM/RuntimeArguments.java
diffstat 2 files changed, 90 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/java.base/share/classes/jdk/internal/misc/VM.java	Fri Jun 17 15:57:28 2016 -0400
+++ b/jdk/src/java.base/share/classes/jdk/internal/misc/VM.java	Fri Jun 17 14:37:00 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -487,8 +487,6 @@
      *
      * If VM options file is specified via -XX:VMOptionsFile, the vm options
      * file is read and expanded in place of -XX:VMOptionFile option.
-     *
-     * Open issue with -XX:Flags (see JDK-8157979)
      */
     public static native String[] getRuntimeArguments();
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/jdk/internal/misc/VM/RuntimeArguments.java	Fri Jun 17 14:37:00 2016 -0700
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @summary Basic test of VM::getRuntimeArguments
+ * @library /lib/testlibrary
+ * @modules java.base/jdk.internal.misc
+ * @run testng RuntimeArguments
+ */
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Stream;
+import jdk.internal.misc.VM;
+import jdk.testlibrary.ProcessTools;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+import static org.testng.Assert.*;
+
+public class RuntimeArguments {
+    static final String TEST_CLASSES = System.getProperty("test.classes");
+
+    @DataProvider(name = "options")
+    public Object[][] options() {
+        return new Object[][] {
+            { // CLI options
+              List.of("-XaddExports:java.base/jdk.internal.misc=ALL-UNNAMED",
+                      "-XaddExports:java.base/jdk.internal.perf=ALL-UNNAMED",
+                      "-addmods", "jdk.zipfs"),
+              // expected runtime arguments
+              List.of("-Djdk.launcher.addexports.0=java.base/jdk.internal.misc=ALL-UNNAMED",
+                      "-Djdk.launcher.addexports.1=java.base/jdk.internal.perf=ALL-UNNAMED",
+                      "-Djdk.launcher.addmods=jdk.zipfs")
+            },
+            { // CLI options
+              List.of("-XaddExports:java.base/jdk.internal.misc=ALL-UNNAMED",
+                      "-addmods", "jdk.zipfs",
+                      "-limitmods", "java.compact3"),
+              // expected runtime arguments
+              List.of("-Djdk.launcher.addexports.0=java.base/jdk.internal.misc=ALL-UNNAMED",
+                      "-Djdk.launcher.addmods=jdk.zipfs", "-Djdk.launcher.limitmods=java.compact3")
+            },
+        };
+    };
+
+    public static void main(String... expected) {
+        String[] vmArgs = VM.getRuntimeArguments();
+        if (!Arrays.equals(vmArgs, expected)) {
+            throw new RuntimeException(Arrays.toString(vmArgs) +
+                " != " + Arrays.toString(expected));
+        }
+    }
+
+    @Test(dataProvider = "options")
+    public void test(List<String> args, List<String> expected) throws Exception {
+        // launch a test program
+        // $ java <runtime-arguments> -classpath <cpath> RuntimeArguments <expected>
+
+        Stream<String> options = Stream.concat(args.stream(),
+            Stream.of("-classpath", TEST_CLASSES, "RuntimeArguments"));
+
+        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
+            Stream.concat(options, expected.stream())
+                  .toArray(String[]::new)
+        );
+        ProcessTools.executeProcess(pb).shouldHaveExitValue(0);
+    }
+}