From a28445ca7e2076e74af887e87b0604d9b7ac51f4 Mon Sep 17 00:00:00 2001 From: Eric Yang Date: Wed, 23 Feb 2022 09:45:07 -0800 Subject: [PATCH] Separate tests that rely on SecurityManager (Jsr292) SecurityManager will be removed in a future jdk. Separate tests that rely on it so that they can be easily disabled in the future. Issue: #14412 Signed-off-by: Eric Yang --- .../bootstrap/CallerSensitiveClass.java | 4 +- test/functional/Jsr292/build.xml | 46 ++++++----- test/functional/Jsr292/playlist.xml | 81 +++++++++++++++++-- .../com/ibm/j9/jsr292/MethodTypeTests.java | 29 +------ .../com/ibm/j9/jsr292/MethodTypeTests_SM.java | 60 ++++++++++++++ test/functional/Jsr292/testng_8.xml | 8 +- test/functional/Jsr292/testng_sm.xml | 32 ++++++++ 7 files changed, 202 insertions(+), 58 deletions(-) create mode 100644 test/functional/Jsr292/src/com/ibm/j9/jsr292/MethodTypeTests_SM.java create mode 100644 test/functional/Jsr292/testng_sm.xml diff --git a/test/functional/Jsr292/bootstrap_src_90/com/ibm/j9/jsr292/bootstrap/CallerSensitiveClass.java b/test/functional/Jsr292/bootstrap_src_90/com/ibm/j9/jsr292/bootstrap/CallerSensitiveClass.java index 925e85a3ab9..78d27727585 100644 --- a/test/functional/Jsr292/bootstrap_src_90/com/ibm/j9/jsr292/bootstrap/CallerSensitiveClass.java +++ b/test/functional/Jsr292/bootstrap_src_90/com/ibm/j9/jsr292/bootstrap/CallerSensitiveClass.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2018 IBM Corp. and others + * Copyright (c) 2014, 2022 IBM Corp. and others * * This program and the accompanying materials are made available under * the terms of the Eclipse Public License 2.0 which accompanies this @@ -21,7 +21,7 @@ *******************************************************************************/ package com.ibm.j9.jsr292.bootstrap; -public class CallerSensitiveClass extends SecurityManager { +public class CallerSensitiveClass { @jdk.internal.reflect.CallerSensitive public void callerSensitiveMethod() { Class c = jdk.internal.reflect.Reflection.getCallerClass(); diff --git a/test/functional/Jsr292/build.xml b/test/functional/Jsr292/build.xml index 187a332a728..7f2a1692426 100644 --- a/test/functional/Jsr292/build.xml +++ b/test/functional/Jsr292/build.xml @@ -1,7 +1,7 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/functional/Jsr292/playlist.xml b/test/functional/Jsr292/playlist.xml index 11cac72d356..58655ae1c00 100644 --- a/test/functional/Jsr292/playlist.xml +++ b/test/functional/Jsr292/playlist.xml @@ -80,17 +80,16 @@ - jsr292Test_jdk9_jdk10 + jsr292Test_jdk8_sm NoOptions Mode195 $(JAVA_COMMAND) $(JVM_OPTIONS) \ - --add-opens=java.base/java.lang=ALL-UNNAMED \ -Djava.security.policy=$(Q)$(TEST_RESROOT)$(D)java.policy$(Q) \ -cp $(Q)$(TEST_RESROOT)$(D)jsr292test.jar$(P)$(RESOURCES_DIR)$(P)$(TESTNG)$(P)$(LIB_DIR)$(D)asm-all.jar$(Q) \ - org.testng.TestNG -d $(REPORTDIR) $(Q)$(TEST_RESROOT)$(D)testng.xml$(Q) \ - -testnames jsr292Test,jsr292Test_optional \ + org.testng.TestNG -d $(REPORTDIR) $(Q)$(TEST_RESROOT)$(D)testng_8.xml$(Q) \ + -testnames jsr292Test_SM \ -groups $(TEST_GROUP) \ -excludegroups $(DEFAULT_EXCLUDE); \ $(TEST_STATUS) @@ -101,9 +100,12 @@ functional - 9 - 10 + 8 + + openj9 + ibm + jsr292Test @@ -137,6 +139,40 @@ ibm + + jsr292Test_SM + + NoOptions + Mode195 + + $(JAVA_COMMAND) $(JAVA_SECURITY_MANAGER) $(JVM_OPTIONS) \ + --add-opens=java.base/java.lang=ALL-UNNAMED \ + -Djava.security.policy=$(Q)$(TEST_RESROOT)$(D)java.policy$(Q) \ + -cp $(Q)$(TEST_RESROOT)$(D)jsr292test.jar$(P)$(RESOURCES_DIR)$(P)$(TESTNG)$(P)$(LIB_DIR)$(D)asm-all.jar$(Q) \ + org.testng.TestNG -d $(REPORTDIR) $(Q)$(TEST_RESROOT)$(D)testng_sm.xml$(Q) \ + -testnames jsr292Test_SM \ + -groups $(TEST_GROUP) \ + -excludegroups $(DEFAULT_EXCLUDE); \ + $(TEST_STATUS) + + extended + + + functional + + + 11 + 17 + 18 + + + + openj9 + ibm + + jsr292Test_jdk12 @@ -176,7 +212,7 @@ -Djava.security.policy=$(Q)$(TEST_RESROOT)$(D)java.policy$(Q) \ -cp $(Q)$(TEST_RESROOT)$(D)jsr292test.jar$(P)$(RESOURCES_DIR)$(P)$(TESTNG)$(P)$(LIB_DIR)$(D)asm-all.jar$(Q) \ org.testng.TestNG -d $(REPORTDIR) $(Q)$(TEST_RESROOT)$(D)testng_8.xml$(Q) \ - -testnames jsr292Test \ + -testnames jsr292Test,jsr292Test_SM \ -groups $(TEST_GROUP) \ -excludegroups $(DEFAULT_EXCLUDE); \ $(TEST_STATUS) @@ -224,6 +260,37 @@ ibm + + jsr292Test_JitCount0_SM + + -Xjit:count=0 + + $(JAVA_COMMAND) $(JAVA_SECURITY_MANAGER) $(JVM_OPTIONS) \ + --add-opens=java.base/java.lang=ALL-UNNAMED \ + -Djava.security.policy=$(Q)$(TEST_RESROOT)$(D)java.policy$(Q) \ + -cp $(Q)$(TEST_RESROOT)$(D)jsr292test.jar$(P)$(RESOURCES_DIR)$(P)$(TESTNG)$(P)$(LIB_DIR)$(D)asm-all.jar$(Q) \ + org.testng.TestNG -d $(REPORTDIR) $(Q)$(TEST_RESROOT)$(D)testng_sm.xml$(Q) \ + -testnames jsr292Test_SM \ + -groups $(TEST_GROUP) \ + -excludegroups $(DEFAULT_EXCLUDE); \ + $(TEST_STATUS) + ^arch.arm + + extended + + + functional + + + 11 + 17 + 18 + + + openj9 + ibm + + jsr292BootstrapTest_jdk8 diff --git a/test/functional/Jsr292/src/com/ibm/j9/jsr292/MethodTypeTests.java b/test/functional/Jsr292/src/com/ibm/j9/jsr292/MethodTypeTests.java index be677ab86da..c9c70075f82 100644 --- a/test/functional/Jsr292/src/com/ibm/j9/jsr292/MethodTypeTests.java +++ b/test/functional/Jsr292/src/com/ibm/j9/jsr292/MethodTypeTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2001, 2018 IBM Corp. and others + * Copyright (c) 2001, 2022 IBM Corp. and others * * This program and the accompanying materials are made available under * the terms of the Eclipse Public License 2.0 which accompanies this @@ -23,7 +23,6 @@ import org.testng.annotations.Test; import org.testng.AssertJUnit; -import java.io.*; import java.lang.invoke.MethodType; import java.util.ArrayList; import java.util.List; @@ -569,30 +568,4 @@ public void test_Wrap()throws Throwable { mType = mType.wrap(); AssertJUnit.assertFalse( mType.hasPrimitives() ); } - - /** - * Ensure that MethodTypes serialization works. Runs with the SecurityManager enabled. - */ - @Test(groups = { "level.extended" }) - public void test_SerializeGenericMethodType() throws IOException, ClassNotFoundException { - Class returnType = String.class; - Class paramType = Class.class; - MethodType mt = MethodType.methodType(returnType, paramType); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos); - oos.writeObject(mt); - oos.close(); - ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - System.setSecurityManager(new SecurityManager()); - try { - MethodType newMT = (MethodType) ois.readObject(); - - // Validate MethodType constructed from serialized data - AssertJUnit.assertEquals(returnType, newMT.returnType()); - AssertJUnit.assertEquals(paramType, newMT.parameterType(0)); - } finally { - ois.close(); - System.setSecurityManager(null); - } - } } diff --git a/test/functional/Jsr292/src/com/ibm/j9/jsr292/MethodTypeTests_SM.java b/test/functional/Jsr292/src/com/ibm/j9/jsr292/MethodTypeTests_SM.java new file mode 100644 index 00000000000..20f37fac6d9 --- /dev/null +++ b/test/functional/Jsr292/src/com/ibm/j9/jsr292/MethodTypeTests_SM.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2022, 2022 IBM Corp. and others + * + * This program and the accompanying materials are made available under + * the terms of the Eclipse Public License 2.0 which accompanies this + * distribution and is available at https://www.eclipse.org/legal/epl-2.0/ + * or the Apache License, Version 2.0 which accompanies this distribution and + * is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * This Source Code may also be made available under the following + * Secondary Licenses when the conditions for such availability set + * forth in the Eclipse Public License, v. 2.0 are satisfied: GNU + * General Public License, version 2 with the GNU Classpath + * Exception [1] and GNU General Public License, version 2 with the + * OpenJDK Assembly Exception [2]. + * + * [1] https://www.gnu.org/software/classpath/license.html + * [2] http://openjdk.java.net/legal/assembly-exception.html + * + * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception + *******************************************************************************/ +package com.ibm.j9.jsr292; + +import org.testng.annotations.Test; +import org.testng.AssertJUnit; +import java.io.*; +import java.lang.invoke.MethodType; + +/** + * @author mesbah + * This class contains tests for the MethodType API. + */ +public class MethodTypeTests_SM { + + /** + * Ensure that MethodTypes serialization works. Runs with the SecurityManager enabled. + */ + @Test(groups = { "level.extended" }) + public void test_SerializeGenericMethodType() throws IOException, ClassNotFoundException { + Class returnType = String.class; + Class paramType = Class.class; + MethodType mt = MethodType.methodType(returnType, paramType); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + oos.writeObject(mt); + oos.close(); + ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); + System.setSecurityManager(new SecurityManager()); + try { + MethodType newMT = (MethodType) ois.readObject(); + + // Validate MethodType constructed from serialized data + AssertJUnit.assertEquals(returnType, newMT.returnType()); + AssertJUnit.assertEquals(paramType, newMT.parameterType(0)); + } finally { + ois.close(); + System.setSecurityManager(null); + } + } +} diff --git a/test/functional/Jsr292/testng_8.xml b/test/functional/Jsr292/testng_8.xml index 11e9acbc187..de61575cbed 100644 --- a/test/functional/Jsr292/testng_8.xml +++ b/test/functional/Jsr292/testng_8.xml @@ -1,7 +1,7 @@ + + + + + + + + +