Skip to content

Commit

Permalink
Set java.security.manager property for tests in JDK18+
Browse files Browse the repository at this point in the history
Tests which use System.setSecurityManager need to explicitly set the
java.security.manager property in JDK18+.

Impacted Java8andUp tests:
- JCL_TEST_Java-Security
- JCL_TEST_Java-Lang
- JCL_TEST_Java-Lang-Invoke
- JCL_TEST_Java-Lang_ClassLoader
- JCL_TEST_Java-Internals
- JCL_TEST_IBM-VM
- JCL_TEST_Java-Lang-Ref

Impacted JLM_Tests:
- JLM_Tests_IBMinternal
- TestMemoryMXBean

Impacted Jsr292 tests:
- jsr292Test
- jsr292BootstrapTest

Impacted cmdLineTests:
- J9security
- proxyFieldAccess

Signed-off-by: Babneet Singh <[email protected]>
  • Loading branch information
babsingh committed Feb 3, 2022
1 parent 075f02d commit bd6425f
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 23 deletions.
7 changes: 4 additions & 3 deletions test/functional/JLM_Tests/playlist.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<!--
Copyright (c) 2016, 2021 IBM Corp. and others
Copyright (c) 2016, 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 @@ -21,6 +21,7 @@
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
-->
<playlist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../TKG/playlist.xsd">
<include>$(TEST_ROOT)$(D)functional$(D)variables.mk</include>
<test>
<testCaseName>JLM_Tests_interface_SE80</testCaseName>
<variations>
Expand Down Expand Up @@ -64,7 +65,7 @@
<variation>NoOptions</variation>
<variation>-XX:+HeapManagementMXBeanCompatibility</variation>
</variations>
<command>$(JAVA_COMMAND) $(JVM_OPTIONS) \
<command>$(JAVA_COMMAND) $(JAVA_SECURITY_MANAGER) $(JVM_OPTIONS) \
--add-exports=jdk.management/com.ibm.lang.management.internal=ALL-UNNAMED --add-exports=java.management/com.ibm.java.lang.management.internal=ALL-UNNAMED \
-XX:SharedCacheHardLimit=16m -Xscmx1m -Xshareclasses:name=testJLM,reset \
-cp $(Q)$(RESOURCES_DIR)$(P)$(TESTNG)$(P)$(TEST_RESROOT)$(D)jlm_tests.jar$(Q) \
Expand Down Expand Up @@ -190,7 +191,7 @@
<variation>NoOptions</variation>
<variation>-XX:+HeapManagementMXBeanCompatibility</variation>
</variations>
<command>$(JAVA_COMMAND) $(JVM_OPTIONS) \
<command>$(JAVA_COMMAND) $(JAVA_SECURITY_MANAGER) $(JVM_OPTIONS) \
--add-exports=jdk.management/com.ibm.lang.management.internal=ALL-UNNAMED --add-exports=java.management/com.ibm.java.lang.management.internal=ALL-UNNAMED \
-XX:SharedCacheHardLimit=16m -Xscmx1m -Xshareclasses:name=testJLM,reset \
-cp $(Q)$(RESOURCES_DIR)$(P)$(TESTNG)$(P)$(TEST_RESROOT)$(D)jlm_tests.jar$(Q) \
Expand Down
4 changes: 3 additions & 1 deletion test/functional/Java8andUp/java8andUpSettings.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##############################################################################
# Copyright (c) 2018, 2021 IBM Corp. and others
# Copyright (c) 2018, 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 @@ -20,6 +20,8 @@
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
##############################################################################

include $(TEST_ROOT)$(D)functional$(D)variables.mk

ADD_MODULE_JAVA_SE_EE=
# java.se.ee should only used for jdk 9 and 10
# if JDK_VERSION is 9 10
Expand Down
10 changes: 5 additions & 5 deletions test/functional/Java8andUp/playlist.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<!--
Copyright (c) 2016, 2021 IBM Corp. and others
Copyright (c) 2016, 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 Down Expand Up @@ -1013,7 +1013,7 @@
<variation>-XX:RecreateClassfileOnload</variation>
<variation>-XX:+CompactStrings</variation>
</variations>
<command>$(JAVA_COMMAND) $(JVM_OPTIONS) -verbose:stacktrace -Djava.security.policy=$(Q)$(TEST_RESROOT)$(D)java.policy$(Q) \
<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 \
Expand Down Expand Up @@ -1113,7 +1113,7 @@
<variation>-Xshareclasses:none</variation>
<variation>-Xshareclasses:none -XX:RecreateClassfileOnload</variation>
</variations>
<command>$(JAVA_COMMAND) $(JVM_OPTIONS) -verbose:stacktrace -Djava.security.policy=$(Q)$(TEST_RESROOT)$(D)java.policy$(Q) \
<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 \
Expand Down Expand Up @@ -1362,7 +1362,7 @@
</variations>
<command>$(MKDIR) -p $(REPORTDIR); \
cd $(REPORTDIR); \
$(JAVA_COMMAND) $(JVM_OPTIONS) -verbose:stacktrace \
$(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) \
Expand Down Expand Up @@ -1459,7 +1459,7 @@
<variations>
<variation>NoOptions</variation>
</variations>
<command>$(JAVA_COMMAND) $(JVM_OPTIONS) -verbose:stacktrace \
<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.vm=ALL-UNNAMED \
--add-exports java.base/com.ibm.oti.util=ALL-UNNAMED \
Expand Down
10 changes: 5 additions & 5 deletions test/functional/Jsr292/playlist.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<!--
Copyright (c) 2016, 2021 IBM Corp. and others
Copyright (c) 2016, 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 Down Expand Up @@ -111,7 +111,7 @@
<variation>NoOptions</variation>
<variation>Mode195</variation>
</variations>
<command>$(JAVA_COMMAND) $(JVM_OPTIONS) \
<command>$(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) \
Expand Down Expand Up @@ -200,7 +200,7 @@
<variations>
<variation>-Xjit:count=0</variation>
</variations>
<command>$(JAVA_COMMAND) $(JVM_OPTIONS) \
<command>$(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) \
Expand Down Expand Up @@ -257,7 +257,7 @@
<variations>
<variation>NoOptions</variation>
</variations>
<command>$(JAVA_COMMAND) $(JVM_OPTIONS) \
<command>$(JAVA_COMMAND) $(JAVA_SECURITY_MANAGER) $(JVM_OPTIONS) \
--add-opens=java.base/java.lang=ALL-UNNAMED --add-exports java.base/jdk.internal.reflect=ALL-UNNAMED \
-Xbootclasspath/a:$(Q)$(TEST_RESROOT)$(D)jsr292bootstrap.jar$(Q) \
-cp $(Q)$(TEST_RESROOT)$(D)jsr292test.jar$(P)$(RESOURCES_DIR)$(P)$(TESTNG)$(Q) \
Expand All @@ -281,7 +281,7 @@
<variations>
<variation>Mode195</variation>
</variations>
<command>$(JAVA_COMMAND) $(JVM_OPTIONS) \
<command>$(JAVA_COMMAND) $(JAVA_SECURITY_MANAGER) $(JVM_OPTIONS) \
--add-opens=java.base/java.lang=ALL-UNNAMED --add-exports java.base/jdk.internal.reflect=ALL-UNNAMED \
-Xbootclasspath/a:$(Q)$(TEST_RESROOT)$(D)jsr292bootstrap.jar$(Q) \
-cp $(Q)$(TEST_RESROOT)$(D)jsr292test.jar$(P)$(RESOURCES_DIR)$(P)$(TESTNG)$(Q) \
Expand Down
5 changes: 3 additions & 2 deletions test/functional/Jsr292/variables.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##############################################################################
# Copyright (c) 2018, 2018 IBM Corp. and others
# Copyright (c) 2018, 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 @@ -20,8 +20,9 @@
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
##############################################################################

include $(TEST_ROOT)$(D)functional$(D)variables.mk

XMLSUFFIX=
ifeq ($(JDK_VERSION), 8)
XMLSUFFIX=_8
endif
endif
5 changes: 3 additions & 2 deletions test/functional/cmdLineTests/J9security/playlist.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<!--
Copyright (c) 2016, 2021 IBM Corp. and others
Copyright (c) 2016, 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 @@ -21,6 +21,7 @@
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
-->
<playlist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../TKG/playlist.xsd">
<include>$(TEST_ROOT)$(D)functional$(D)variables.mk</include>
<test>
<testCaseName>cmdLineTester_J9securityTests_SE80</testCaseName>
<variations>
Expand Down Expand Up @@ -55,7 +56,7 @@
<command>$(JAVA_COMMAND) $(JVM_OPTIONS) -Xdump \
-DMODULE_ADDEXPORTS_OPTION=$(Q)--add-exports$(Q) -DMODULE_ADDEXPORTS_VALUE=$(Q)java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED$(Q) \
-DTESTJ9SECURITYJARPATH=$(Q)$(TEST_RESROOT)$(D)$(Q) -DRESJAR=$(CMDLINETESTER_RESJAR) \
-DEXE=$(SQ)$(JAVA_COMMAND) $(JVM_OPTIONS) -Xdump$(SQ) -jar $(CMDLINETESTER_JAR) -config $(Q)$(TEST_RESROOT)$(D)j9SecurityTest.xml$(Q) \
-DEXE=$(SQ)$(JAVA_COMMAND) $(JAVA_SECURITY_MANAGER) $(JVM_OPTIONS) -Xdump$(SQ) -jar $(CMDLINETESTER_JAR) -config $(Q)$(TEST_RESROOT)$(D)j9SecurityTest.xml$(Q) \
-explainExcludes -nonZeroExitWhenError; \
$(TEST_STATUS)</command>
<levels>
Expand Down
20 changes: 15 additions & 5 deletions test/functional/cmdLineTests/proxyFieldAccess/playlist.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<!--
Copyright (c) 2016, 2021 IBM Corp. and others
Copyright (c) 2016, 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 @@ -21,13 +21,18 @@
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
-->
<playlist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../TKG/playlist.xsd">
<include>$(TEST_ROOT)$(D)functional$(D)variables.mk</include>
<test>
<testCaseName>cmdLineTester_ProxyFieldAccess_SE80</testCaseName>
<variations>
<variation>NoOptions</variation>
</variations>
<command>$(JAVA_COMMAND) $(JVM_OPTIONS) -Xdump -DTESTPROXYFIELDACCESSJAR=$(Q)$(TEST_RESROOT)$(D)testproxyfieldaccess.jar$(Q) -DTESTDIR=$(Q)$(TEST_RESROOT)$(Q) -DRESJAR=$(CMDLINETESTER_RESJAR) -DEXE=$(SQ)$(JAVA_COMMAND) $(JVM_OPTIONS) -Xdump$(SQ) -jar $(CMDLINETESTER_JAR) -config $(Q)$(TEST_RESROOT)$(D)testproxyfieldaccess.xml$(Q) -explainExcludes -nonZeroExitWhenError -xids all,$(PLATFORM),$(VARIATION) $(CMDLINETESTER_XLIST); \
${TEST_STATUS}</command>
<command>$(JAVA_COMMAND) $(JVM_OPTIONS) -Xdump \
-DTESTPROXYFIELDACCESSJAR=$(Q)$(TEST_RESROOT)$(D)testproxyfieldaccess.jar$(Q) \
-DTESTDIR=$(Q)$(TEST_RESROOT)$(Q) -DRESJAR=$(CMDLINETESTER_RESJAR) \
-DEXE=$(SQ)$(JAVA_COMMAND) $(JVM_OPTIONS) -Xdump$(SQ) -jar $(CMDLINETESTER_JAR) -config $(Q)$(TEST_RESROOT)$(D)testproxyfieldaccess.xml$(Q) \
-explainExcludes -nonZeroExitWhenError -xids all,$(PLATFORM),$(VARIATION) $(CMDLINETESTER_XLIST); \
${TEST_STATUS}</command>
<levels>
<level>sanity</level>
</levels>
Expand All @@ -42,13 +47,18 @@
<version>8</version>
</versions>
</test>

<test>
<testCaseName>cmdLineTester_ProxyFieldAccess</testCaseName>
<variations>
<variation>NoOptions</variation>
</variations>
<command>$(JAVA_COMMAND) $(JVM_OPTIONS) -Xdump -DTESTPROXYFIELDACCESSJAR=$(Q)$(TEST_RESROOT)$(D)testproxyfieldaccess.jar$(Q) -DTESTDIR=$(Q)$(TEST_RESROOT)$(Q) -DRESJAR=$(CMDLINETESTER_RESJAR) -DEXE=$(SQ)$(JAVA_COMMAND) $(JVM_OPTIONS) --add-opens=java.base/java.lang=ALL-UNNAMED --add-reads java.base=jdk.unsupported --add-opens=java.base/java.lang=ALL-UNNAMED -Xdump$(SQ) -jar $(CMDLINETESTER_JAR) -config $(Q)$(TEST_RESROOT)$(D)testproxyfieldaccess.xml$(Q) -explainExcludes -nonZeroExitWhenError -xids all,$(PLATFORM),$(VARIATION) $(CMDLINETESTER_XLIST); \
${TEST_STATUS}</command>
<command>$(JAVA_COMMAND) $(JVM_OPTIONS) -Xdump \
-DTESTPROXYFIELDACCESSJAR=$(Q)$(TEST_RESROOT)$(D)testproxyfieldaccess.jar$(Q) \
-DTESTDIR=$(Q)$(TEST_RESROOT)$(Q) -DRESJAR=$(CMDLINETESTER_RESJAR) \
-DEXE=$(SQ)$(JAVA_COMMAND) $(JAVA_SECURITY_MANAGER) $(JVM_OPTIONS) --add-opens=java.base/java.lang=ALL-UNNAMED --add-reads java.base=jdk.unsupported --add-opens=java.base/java.lang=ALL-UNNAMED -Xdump$(SQ) -jar $(CMDLINETESTER_JAR) -config $(Q)$(TEST_RESROOT)$(D)testproxyfieldaccess.xml$(Q) \
-explainExcludes -nonZeroExitWhenError -xids all,$(PLATFORM),$(VARIATION) $(CMDLINETESTER_XLIST); \
${TEST_STATUS}</command>
<levels>
<level>sanity</level>
</levels>
Expand Down
30 changes: 30 additions & 0 deletions test/functional/variables.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
##############################################################################
# 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
##############################################################################

# In JDK18+, java.security.manager == null behaves as -Djava.security.manager=disallow.
# In JDK17-, java.security.manager == null behaves as -Djava.security.manager=allow.
# For OpenJ9 tests to work as expected, -Djava.security.manager=allow behaviour is
# needed in JDK18+.
JAVA_SECURITY_MANAGER=
ifeq ($(filter 8 9 10 11 12 13 14 15 16 17, $(JDK_VERSION)),)
JAVA_SECURITY_MANAGER=-Djava.security.manager=allow
endif

0 comments on commit bd6425f

Please sign in to comment.