changeset 9343:7e972ba1fe32

Fix Observability tests Reviewed-by: lfoltan, hseigel
author gtriantafill
date Tue, 03 Nov 2015 11:14:56 -0500
parents b96d0485a1a9
children e1b2092789e5
files test/runtime/modules/Visibility/XbootcpNoVisibility.java test/runtime/modules/observability3/Observability3.sh test/runtime/modules/observability3/Observability3_A.java test/runtime/modules/observability3/java/util/Observability3_B.java
diffstat 4 files changed, 77 insertions(+), 125 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/runtime/modules/Visibility/XbootcpNoVisibility.java	Tue Nov 03 11:14:56 2015 -0500
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2015, 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 Ensure that a class defined within a java.base package can not
+ *          be located via -Xbootclasspath/a
+ * @library /testlibrary
+ * @modules java.base/sun.misc
+ *          java.management
+ * @run main/othervm XbootcpNoVisibility
+ */
+
+import jdk.test.lib.*;
+
+public class XbootcpNoVisibility {
+    public static void main(String args[]) throws Exception {
+
+        String Vis3_B_src =
+                "package sun.util;" +
+                "public class Vis3_B { public void m() { System.out.println(\"In B's m()\"); } }";
+
+        ClassFileInstaller.writeClassToDisk("sun/util/Vis3_B",
+            InMemoryJavaCompiler.compile("sun.util.Vis3_B", Vis3_B_src), System.getProperty("test.classes"));
+
+        String Vis3_A_src =
+                "import sun.util.*;" +
+                "public class Vis3_A {" +
+                "    public static void main(String args[]) throws Exception {" +
+                        // Try loading a class within a named package in a module which has been defined
+                        // to the boot loader. In this situation, the class should only be attempted
+                        // to be loaded from the boot loader's module path which consists of:
+                        //   [-Xpatch]; exploded build | bootmodules.jimage
+                        //
+                        // Since the class is located on the boot loader's append path via
+                        // -Xbootclasspath/a specification, it should not be found.
+                "       try {" +
+                "               sun.util.Vis3_B b = new sun.util.Vis3_B();" +
+                "       } catch (NoClassDefFoundError e) {" +
+                "               System.out.println(\"XbootcpNoVisibility PASSED - " +
+                                                "test should throw exception\\n\");" +
+                "               return;" +
+                "       }" +
+                "       throw new RuntimeException(\"XbootcpNoVisibility FAILED - " +
+                                                    "test should have thrown exception\");" +
+                "    }" +
+                "}";
+
+        ClassFileInstaller.writeClassToDisk("Vis3_A",
+                InMemoryJavaCompiler.compile("Vis3_A", Vis3_A_src), System.getProperty("test.classes"));
+
+        new OutputAnalyzer(ProcessTools.createJavaProcessBuilder(
+                "-Xbootclasspath/a:.",
+                "Vis3_A")
+            .start()).shouldContain("XbootcpNoVisibility PASSED");
+    }
+}
--- a/test/runtime/modules/observability3/Observability3.sh	Wed Oct 21 13:21:33 2015 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,53 +0,0 @@
-# 
-#  Copyright (c) 2015, 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
-# @ignore
-# @summary Test attempt to load class within a package in a module defined to the boot loader via -Xbootclasspath/a. 
-
-set -e
-
-if [ -z "$TESTJAVA" ]; then
-  if [ $# -lt 1 ]; then exit 1; fi
-  TESTJAVA="$1"; shift
-  COMPILEJAVA="${TESTJAVA}"
-  TESTSRC="`pwd`"
-  TESTCLASSES="`pwd`"
-fi
-
-JAVAC="$COMPILEJAVA/bin/javac"
-JAVA="$TESTJAVA/bin/java"
-
-echo $TESTSRC
-
-rm -rf java
-rm -rf dummy_dir3
-mkdir dummy_dir3
-
-${JAVAC} -d . $TESTSRC/java/util/Observability3_B.java
-${JAVAC} -cp . -d . $TESTSRC/Observability3_A.java
-zip -m Observability3_B.zip java/util/Observability3_B.class
-rm -rf java/util/Observability3_B.class
-
-${JAVA} -Xbootclasspath/a:dummy_dir3 -Xbootclasspath/a:Observability3_B.zip Observability3_A
-exit $?
--- a/test/runtime/modules/observability3/Observability3_A.java	Wed Oct 21 13:21:33 2015 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 2015, 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.
- */
-
-import java.util.*;
-
-public class Observability3_A {
-    public static void main(String args[]) throws Exception {
-        try {
-            // Try loading a class within a named package in
-            // a module which has been defined to the boot
-            // loader. In this situation the class should only
-            // be attempted to be loaded from the boot loader's
-            // module path which consists of:
-            //   [-Xpatch]; exploded build | bootmodules.jimage
-            //
-            // Since the class is located on the boot loader's
-            // append path via -Xbootclasspath/a specification,
-            // it should not be found.
-            java.util.Observability3_B b = new java.util.Observability3_B();
-            b.m();
-        } catch (Error e) {
-            System.out.println("Observability3 PASSED - test should throw an exception\n");
-            return;
-        }
-        throw new RuntimeException("Observability3 FAILED - test should have thrown an exception caught above\n");
-    }
-}
--- a/test/runtime/modules/observability3/java/util/Observability3_B.java	Wed Oct 21 13:21:33 2015 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-/*
- * Copyright (c) 2015, 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.
- */
-
-package java.util;
-public class Observability3_B { public void m() { System.out.println("In B's m()"); } }