Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate tests that rely on SecurityManager (Java8andUp) #14442

Merged
merged 1 commit into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 41 additions & 27 deletions test/functional/Java8andUp/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-excepti
<property name="src" location="src" />
<property name="src_80" location="src_80" />
<property name="src_90" location="src_90" />
<property name="src_110_up" location="src_110_up" />
<property name="scr_DupClassNameTest" location="scr_DupClassNameTest" />
<property name="build" location="bin" />
<property name="build_resource" location="resource" />
Expand Down Expand Up @@ -264,33 +265,46 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-excepti

<property name="addExports" value="--add-exports java.base/com.ibm.oti.vm=ALL-UNNAMED --add-exports java.base/com.ibm.oti.util=ALL-UNNAMED --add-exports java.base/jdk.internal.vm.annotation=ALL-UNNAMED --add-exports java.base/jdk.internal.misc=ALL-UNNAMED --add-exports java.base/jdk.internal.reflect=ALL-UNNAMED --add-exports java.base/com.ibm.jit.crypto=ALL-UNNAMED --add-exports java.base/com.ibm.jit=ALL-UNNAMED --add-exports java.base/com.ibm.oti.reflect=ALL-UNNAMED --add-exports java.base/openj9.internal.tools.attach.target=ALL-UNNAMED --add-exports jdk.jcmd/openj9.tools.attach.diagnostics.info=ALL-UNNAMED --add-exports jdk.attach/com.ibm.tools.attach.attacher=ALL-UNNAMED" />
<echo>===addExports: ${addExports}</echo>
<javac srcdir="${src}" destdir="${build}" debug="true" fork="true" executable="${compiler.javac}" includeAntRuntime="false" encoding="ISO-8859-1">
<src path="${src}" />
<src path="src_110_up" />
<src path="${src_version}" />
<src path="${src_90_jcl}" />
<src path="${src_access}" />
<src path="${TestUtilities}" />
<src path="${TestUtilitiesJ9}" />
<src path="${transformerListener}" />
<compilerarg line='${addExports}' />
<compilerarg line='${addExports_90_jcl}' />
<compilerarg line='${addExports_version}' />
<compilerarg line='--add-modules openj9.sharedclasses' />
<!-- PR117298 -->
<exclude name="**/Cmvc194280.java" />
<exclude name="**/resources/**" />
<!-- requires special compilation methods -->
<exclude name="**/NoSuchMethod/**" />
<classpath>
<pathelement location="${LIB_DIR}/asm-all.jar" />
<pathelement location="${LIB_DIR}/testng.jar" />
<pathelement location="${LIB_DIR}/jcommander.jar" />
<pathelement location="${LIB_DIR}/commons-cli.jar" />
<pathelement location="${LIB_DIR}/javassist.jar" />
<pathelement location="${LIB_DIR}/jaxb-api.jar" />
</classpath>
</javac>

<property name="srcpath" location="${src}:${src_110_up}:${src_version}:${src_90_jcl}:${src_access}:${TestUtilities}:${TestUtilitiesJ9}:${transformerListener}" />
<!-- first two excludes are from PR117298, third exclude requires special compilation methods -->
<property name="commonExcludes" value="**/Cmvc194280.java,**/resources/**,**/NoSuchMethod/**" />
<path id="build.cp">
<fileset dir="${LIB_DIR}/" includes="asm-all.jar"/>
<fileset dir="${LIB_DIR}/" includes="testng.jar"/>
<fileset dir="${LIB_DIR}/" includes="jcommander.jar"/>
<fileset dir="${LIB_DIR}/" includes="commons-cli.jar"/>
<fileset dir="${LIB_DIR}/" includes="javassist.jar"/>
<fileset dir="${LIB_DIR}/" includes="jaxb-api.jar"/>
</path>
<property name="commonArgs" value="${addExports} ${addExports_90_jcl} ${addExports_version} --add-modules openj9.sharedclasses" />
<if>
<matches string="${JDK_VERSION}" pattern="^(1[1-8])$$" />
<then>
<!-- Java 11-18 -->
<javac srcdir="${srcpath}" excludes="${commonExcludes}" destdir="${build}" debug="true" fork="true" executable="${compiler.javac}" includeAntRuntime="false" encoding="ISO-8859-1" classpathref="build.cp">
<compilerarg line='${commonArgs}' />
</javac>
</then>
<else>
<!-- Java 19+ (SecurityManager removed) -->
<javac srcdir="${srcpath}" excludes="${commonExcludes}" destdir="${build}" debug="true" fork="true" executable="${compiler.javac}" includeAntRuntime="false" encoding="ISO-8859-1" classpathref="build.cp">
<compilerarg line='${commonArgs}' />
<!-- exclude tests that depend on SecurityManager -->
<exclude name="org/openj9/test/java/security/Test_AccessController.java" />
<exclude name="org/openj9/test/java/security/Test_AccessControlContext.java" />
<exclude name="org/openj9/test/java/lang/Test_Class_SM.java" />
<exclude name="org/openj9/test/java/lang/Test_System_SM.java" />
<exclude name="org/openj9/test/java/lang/Test_Thread_SM.java" />
<exclude name="org/openj9/test/java/lang/Test_ThreadGroup_SM.java" />
<exclude name="org/openj9/test/java/lang/invoke/Test_MethodHandleInfo_SM.java" />
<exclude name="org/openj9/test/java/lang/Test_ClassLoader_SM.java" />
<exclude name="org/openj9/test/java/lang/Test_J9VMInternals_SM.java" />
<exclude name="org/openj9/test/java/lang/Test_J9VMInternalsImpl_SM.java" />
<exclude name="org/openj9/test/vm/Test_VM.java" />
</javac>
</else>
</if>
</else>
</if>
</target>
Expand Down
179 changes: 172 additions & 7 deletions test/functional/Java8andUp/playlist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,52 @@
<impl>ibm</impl>
</impls>
</test>
<test>
<testCaseName>JCL_Test_SM</testCaseName>
<variations>
<variation>NoOptions</variation>
<variation>-XX:RecreateClassfileOnload</variation>
<variation>-XX:+CompactStrings</variation>
</variations>
<command>$(JAVA_COMMAND) $(JAVA_SECURITY_MANAGER) $(JVM_OPTIONS) -verbose:stacktrace -Djava.security.policy=$(Q)$(TEST_RESROOT)$(D)java.policy$(Q) \
-Drowset.provider.classname=org.openj9.resources.classloader.CustomSyncProvider \
--add-modules openj9.sharedclasses $(ADD_MODULE_JAVA_SE_EE) \
--add-exports java.base/com.ibm.oti.vm=ALL-UNNAMED \
--add-exports java.base/com.ibm.oti.util=ALL-UNNAMED \
--add-exports java.base/jdk.internal.vm.annotation=ALL-UNNAMED \
--add-exports java.base/jdk.internal.misc=ALL-UNNAMED $(ADD_EXPORTS_JDK_INTERNAL_REFLECT) \
--add-exports java.base/com.ibm.jit.crypto=ALL-UNNAMED \
--add-exports java.base/com.ibm.oti.reflect=ALL-UNNAMED \
--add-exports java.base/sun.net.www.protocol.jrt=ALL-UNNAMED \
--add-opens=java.base/java.lang=ALL-UNNAMED \
--add-opens=java.base/java.security=ALL-UNNAMED \
$(ADD_EXPORTS_JDK_INTERNAL_ACCESS) \
-cp $(Q)$(RESOURCES_DIR)$(P)$(TESTNG)$(P)$(TEST_RESROOT)$(D)GeneralTest.jar$(P)$(TEST_RESROOT)$(D)TestResources.jar$(P)$(LIB_DIR)$(D)asm-all.jar$(JAXB_API_JAR)$(Q) \
org.testng.TestNG -d $(REPORTDIR) $(Q)$(TEST_RESROOT)$(D)testng_sm.xml$(Q) \
-testnames \
JCL_TEST_Java-Lang_SM,\
JCL_TEST_Java-Lang-Invoke_SM,\
JCL_TEST_Java-Lang_ClassLoader_SM,\
JCL_TEST_IBM-VM_SM \
-groups $(TEST_GROUP) \
-excludegroups $(DEFAULT_EXCLUDE); \
$(TEST_STATUS)</command>
<levels>
<level>sanity</level>
</levels>
<groups>
<group>functional</group>
</groups>
<versions>
<version>11</version>
<version>17</version>
<version>18</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only 11/17/18 are required.

</versions>
<impls>
<impl>openj9</impl>
<impl>ibm</impl>
</impls>
</test>
<test>
<testCaseName>JCL_Test_Native</testCaseName>
<variations>
Expand Down Expand Up @@ -1169,6 +1215,51 @@
<impl>ibm</impl>
</impls>
</test>
<test>
<testCaseName>JCL_Test_SM_none_SCC</testCaseName>
<variations>
<variation>-Xshareclasses:none</variation>
<variation>-Xshareclasses:none -XX:RecreateClassfileOnload</variation>
</variations>
<command>$(JAVA_COMMAND) $(JAVA_SECURITY_MANAGER) $(JVM_OPTIONS) -verbose:stacktrace -Djava.security.policy=$(Q)$(TEST_RESROOT)$(D)java.policy$(Q) \
-Drowset.provider.classname=org.openj9.resources.classloader.CustomSyncProvider \
--add-modules openj9.sharedclasses $(ADD_MODULE_JAVA_SE_EE) \
--add-exports java.base/com.ibm.oti.vm=ALL-UNNAMED \
--add-exports java.base/com.ibm.oti.util=ALL-UNNAMED \
--add-exports java.base/jdk.internal.vm.annotation=ALL-UNNAMED \
--add-exports java.base/jdk.internal.misc=ALL-UNNAMED $(ADD_EXPORTS_JDK_INTERNAL_REFLECT) \
--add-exports java.base/com.ibm.jit.crypto=ALL-UNNAMED \
--add-exports java.base/com.ibm.oti.reflect=ALL-UNNAMED \
--add-exports java.base/sun.net.www.protocol.jrt=ALL-UNNAMED \
--add-opens=java.base/java.lang=ALL-UNNAMED \
--add-opens=java.base/java.security=ALL-UNNAMED \
$(ADD_EXPORTS_JDK_INTERNAL_ACCESS) \
-cp $(Q)$(RESOURCES_DIR)$(P)$(TESTNG)$(P)$(TEST_RESROOT)$(D)GeneralTest.jar$(P)$(TEST_RESROOT)$(D)TestResources.jar$(P)$(LIB_DIR)$(D)asm-all.jar$(JAXB_API_JAR)$(Q) \
org.testng.TestNG -d $(REPORTDIR) $(Q)$(TEST_RESROOT)$(D)testng_sm.xml$(Q) \
-testnames \
JCL_TEST_Java-Lang_SM,\
JCL_TEST_Java-Lang-Invoke_SM,\
JCL_TEST_Java-Lang_ClassLoader_SM,\
JCL_TEST_IBM-VM_SM \
-groups $(TEST_GROUP) \
-excludegroups $(DEFAULT_EXCLUDE); \
$(TEST_STATUS)</command>
<levels>
<level>sanity</level>
</levels>
<groups>
<group>functional</group>
</groups>
<versions>
<version>11</version>
<version>17</version>
<version>18</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only need 11/17/18, assuming this is a SM version of JCL_Test_none_SCC which is for 11+.

</versions>
<impls>
<impl>openj9</impl>
<impl>ibm</impl>
</impls>
</test>
<test>
<testCaseName>JCL_Test_none_SCC_Native</testCaseName>
<variations>
Expand Down Expand Up @@ -1264,19 +1355,22 @@
<command>$(JAVA_COMMAND) $(JVM_OPTIONS) -verbose:stacktrace -Djava.security.policy=$(Q)$(TEST_RESROOT)$(D)java.policy$(Q) \
-cp $(Q)$(RESOURCES_DIR)$(P)$(TESTNG)$(P)$(TEST_RESROOT)$(D)GeneralTest.jar$(P)$(TEST_RESROOT)$(D)TestResources.jar$(P)$(LIB_DIR)$(D)asm-all.jar$(Q) \
-Drowset.provider.classname=org.openj9.resources.classloader.CustomSyncProvider \
org.testng.TestNG -d $(REPORTDIR) $(Q)$(TEST_RESROOT)$(D)testng.xml$(Q) \
org.testng.TestNG -d $(REPORTDIR) $(Q)$(TEST_RESROOT)$(D)testng_sm.xml$(Q) \
-testnames \
JCL_TEST_Test-TypeAnnotation,\
JCL_TEST_Test-Annotation,\
JCL_TEST_Test-Annotation-Identity,\
JCL_TEST_Test-Annotation-ClassLoader,\
JCL_TEST_Test-Annotation-Package,\
JCL_TEST_Java-Lang_ClassLoader,\
JCL_TEST_Java-Lang_ClassLoader_SM,\
JCL_TEST_Test-Defects,\
JCL_TEST_Test-UnsafeFence,\
JCL_TEST_IBM-VM,\
JCL_TEST_Java-Lang,\
JCL_TEST_Java-Lang_SM,\
JCL_TEST_Java-Lang-Invoke,\
JCL_TEST_Java-Lang-Invoke_SM,\
JCL_TEST_Java-Lang-Ref,\
JCL_TEST_Java-Lang-Reflect,\
JCL_TEST_Java-Math,\
Expand Down Expand Up @@ -1383,15 +1477,48 @@
-groups $(TEST_GROUP) \
-excludegroups $(DEFAULT_EXCLUDE); \
$(TEST_STATUS)</command>
<platformRequirements>^vm.hrt</platformRequirements>
<levels>
<level>sanity</level>
</levels>
<groups>
<group>functional</group>
</groups>
<versions>
<version>9+</version>
<version>11</version>
<version>17</version>
<version>18</version>
</versions>
<impls>
<impl>openj9</impl>
<impl>ibm</impl>
</impls>
</test>
<test>
<testCaseName>J9VMInternals_Test_SM</testCaseName>
<variations>
<variation>NoOptions</variation>
</variations>
<command>$(MKDIR) -p $(REPORTDIR); \
cd $(REPORTDIR); \
$(JAVA_COMMAND) $(JAVA_SECURITY_MANAGER) $(JVM_OPTIONS) -verbose:stacktrace \
-Djava.security.policy=$(Q)$(TEST_RESROOT)$(D)java.policy$(Q) \
-Xbootclasspath/a:$(TEST_RESROOT)$(D)TestResources.jar \
-cp $(Q)$(RESOURCES_DIR)$(P)$(TESTNG)$(P)$(TEST_RESROOT)$(D)GeneralTest.jar$(P)$(TEST_RESROOT)$(D)TestResources.jar$(P)$(LIB_DIR)$(D)asm-all.jar$(Q) \
org.testng.TestNG -d $(REPORTDIR) $(Q)$(TEST_RESROOT)$(D)testng_sm.xml$(Q) \
-testnames JCL_TEST_Java-Internals_SM \
-groups $(TEST_GROUP) \
-excludegroups $(DEFAULT_EXCLUDE); \
$(TEST_STATUS)</command>
<levels>
<level>sanity</level>
</levels>
<groups>
<group>functional</group>
</groups>
<versions>
<version>11</version>
<version>17</version>
<version>18</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only 11/17/18 are needed.

</versions>
<impls>
<impl>openj9</impl>
Expand All @@ -1410,8 +1537,10 @@
-Djava.security.policy=$(Q)$(TEST_RESROOT)$(D)java.policy$(Q) \
-Xbootclasspath/a:$(TEST_RESROOT)$(D)TestResources.jar \
-cp $(Q)$(RESOURCES_DIR)$(P)$(TESTNG)$(P)$(TEST_RESROOT)$(D)GeneralTest.jar$(P)$(TEST_RESROOT)$(D)TestResources.jar$(P)$(LIB_DIR)$(D)asm-all.jar$(Q) \
org.testng.TestNG -d $(REPORTDIR) $(Q)$(TEST_RESROOT)$(D)testng.xml$(Q) \
-testnames JCL_TEST_Java-Internals \
org.testng.TestNG -d $(REPORTDIR) $(Q)$(TEST_RESROOT)$(D)testng_sm.xml$(Q) \
-testnames \
JCL_TEST_Java-Internals,\
JCL_TEST_Java-Internals_SM \
-groups $(TEST_GROUP) \
-excludegroups $(DEFAULT_EXCLUDE); \
$(TEST_STATUS)</command>
Expand Down Expand Up @@ -1443,8 +1572,10 @@
-Djava.security.policy=$(Q)$(TEST_RESROOT)$(D)testacc.policy$(Q) \
-Xbootclasspath/a:$(TEST_RESROOT)$(D)TestResources.jar \
-cp $(Q)$(RESOURCES_DIR)$(P)$(TESTNG)$(P)$(TEST_RESROOT)$(D)GeneralTest.jar$(P)$(TEST_RESROOT)$(D)TestResources.jar$(P)$(LIB_DIR)$(D)asm-all.jar$(Q) \
org.testng.TestNG -d $(REPORTDIR) $(Q)$(TEST_RESROOT)$(D)testng.xml$(Q) \
-testnames JCL_TEST_Java-Security \
org.testng.TestNG -d $(REPORTDIR) $(Q)$(TEST_RESROOT)$(D)testng_sm.xml$(Q) \
-testnames \
JCL_TEST_Java-Security,\
JCL_TEST_Java-Security_SM \
-groups $(TEST_GROUP) \
-excludegroups $(DEFAULT_EXCLUDE); \
$(TEST_STATUS)</command>
Expand Down Expand Up @@ -1504,6 +1635,40 @@
<impl>ibm</impl>
</impls>
</test>
<test>
<testCaseName>JCL_TEST_Java-Security_SM</testCaseName>
<variations>
<variation>NoOptions</variation>
</variations>
<command>$(JAVA_COMMAND) $(JAVA_SECURITY_MANAGER) $(JVM_OPTIONS) -verbose:stacktrace \
--add-modules openj9.sharedclasses $(ADD_MODULE_JAVA_SE_EE) \
--add-exports java.base/com.ibm.oti.util=ALL-UNNAMED \
--add-opens=java.base/java.lang=ALL-UNNAMED \
--add-opens=java.base/java.security=ALL-UNNAMED \
-Djava.security.policy=$(Q)$(TEST_RESROOT)$(D)testacc.policy$(Q) \
-Xbootclasspath/a:$(TEST_RESROOT)$(D)TestResources.jar \
-cp $(Q)$(RESOURCES_DIR)$(P)$(TESTNG)$(P)$(TEST_RESROOT)$(D)GeneralTest.jar$(P)$(TEST_RESROOT)$(D)TestResources.jar$(P)$(LIB_DIR)$(D)asm-all.jar$(Q) \
org.testng.TestNG -d $(REPORTDIR) $(Q)$(TEST_RESROOT)$(D)testng_sm.xml$(Q) \
-testnames JCL_TEST_Java-Security_SM \
-groups $(TEST_GROUP) \
-excludegroups $(DEFAULT_EXCLUDE); \
$(TEST_STATUS)</command>
<levels>
<level>sanity</level>
</levels>
<groups>
<group>functional</group>
</groups>
<versions>
<version>11</version>
<version>17</version>
<version>18</version>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will also have to add to versions. (Is there a better way than listing all the versions individually?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@renfeiw @llxia do we support something like <version>8-18</version>?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently we don't, we can have something like this in the future.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we have a plan to add something like [8,18]. But we also need to support it in the internal perl tkg as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only 11/17/18 are required.

</versions>
<impls>
<impl>openj9</impl>
<impl>ibm</impl>
</impls>
</test>
<test>
<testCaseName>JCL_Test_JITHelpers_SE80</testCaseName>
<command>$(JAVA_COMMAND) $(JVM_OPTIONS) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.testng.AssertJUnit;

/*******************************************************************************
* Copyright (c) 2010, 2018 IBM Corp. and others
* Copyright (c) 2010, 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
Expand All @@ -29,8 +29,6 @@
*******************************************************************************/
import java.net.URL;
import java.net.URLClassLoader;
import java.security.AccessController;
import java.security.PrivilegedAction;
import javax.xml.bind.annotation.XmlSchema;

@Test(groups = { "level.sanity" })
Expand Down Expand Up @@ -123,16 +121,12 @@ private static String toString(Class<?> clazz) {
}

private static ClassLoader getClassLoader(final Class<?> clazz) {
return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
public ClassLoader run() {
ClassLoader cl = null;
try {
cl = clazz.getClassLoader();
} catch (SecurityException ex) {
}
return cl;
}
});
ClassLoader cl = null;
try {
cl = clazz.getClassLoader();
} catch (SecurityException ex) {
}
return cl;
}

}
Loading