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 (Jsr292) #14580

Merged
merged 1 commit into from
Apr 8, 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
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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();
Expand Down
46 changes: 26 additions & 20 deletions test/functional/Jsr292/build.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>

<!--
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 @@ -189,25 +189,31 @@
</javac>
</then>
<else>
<javac srcdir="${src}" destdir="${build}" debug="true" fork="true" executable="${compiler.javac}" includeAntRuntime="false" encoding="ISO-8859-1">
<src path="${src}" />
<src path="${transformerListener}" />
<src path="${TestUtilities}" />
<!-- exclude non test files for indyn test -->
<exclude name="**/indyn/BootstrapMethods.java" />
<exclude name="**/indyn/ComplexIndyGenerator.java" />
<exclude name="**/indyn/Helper.java" />
<exclude name="**/indyn/SimpleIndyGenerator.java" />
<exclude name="**/CrossPackageHelper.java"/>
<exclude name="**/attachAPI/**" />
<classpath>
<pathelement location="${bootstrapBuild}"/>
<pathelement location="${LIB_DIR}/asm-all.jar" />
<pathelement location="${LIB_DIR}/junit4.jar" />
<pathelement location="${LIB_DIR}/testng.jar"/>
<pathelement location="${LIB_DIR}/jcommander.jar"/>
</classpath>
</javac>
<property name="srcpath" location="${src}:${transformerListener}:${TestUtilities}" />
<!-- exclude non test files for indyn test -->
<property name="commonExcludes" value="**/indyn/BootstrapMethods.java,**/indyn/ComplexIndyGenerator.java,**/indyn/Helper.java,**/indyn/SimpleIndyGenerator.java,**/CrossPackageHelper.java,**/attachAPI/**" />
<path id="build.cp">
<pathelement location="${bootstrapBuild}/"/>
<fileset dir="${LIB_DIR}/" includes="asm-all.jar"/>
<fileset dir="${LIB_DIR}/" includes="junit4.jar"/>
<fileset dir="${LIB_DIR}/" includes="testng.jar"/>
<fileset dir="${LIB_DIR}/" includes="jcommander.jar"/>
</path>
<if>
<matches string="${JDK_VERSION}" pattern="^(9|(1[0-8]))$$" />
<then>
<!-- Java 9-18 -->
<javac srcdir="${srcpath}" excludes="${commonExcludes}" destdir="${build}" debug="true" fork="true" executable="${compiler.javac}" includeAntRuntime="false" encoding="ISO-8859-1" classpathref="build.cp">
</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">
<!-- exclude tests that depend on SecurityManager -->
<exclude name="com/ibm/j9/jsr292/MethodTypeTests_SM.java"/>
</javac>
</else>
</if>
</else>
</if>
</target>
Expand Down
81 changes: 74 additions & 7 deletions test/functional/Jsr292/playlist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,16 @@
</impls>
</test>
<test>
<testCaseName>jsr292Test_jdk9_jdk10</testCaseName>
<testCaseName>jsr292Test_jdk8_sm</testCaseName>
<variations>
<variation>NoOptions</variation>
<variation>Mode195</variation>
</variations>
<command>$(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)</command>
Expand All @@ -101,9 +100,12 @@
<group>functional</group>
</groups>
<versions>
<version>9</version>
<version>10</version>
<version>8</version>
</versions>
<impls>
<impl>openj9</impl>
<impl>ibm</impl>
</impls>
</test>
<test>
<testCaseName>jsr292Test</testCaseName>
Expand Down Expand Up @@ -137,6 +139,40 @@
<impl>ibm</impl>
</impls>
</test>
<test>
<testCaseName>jsr292Test_SM</testCaseName>
<variations>
<variation>NoOptions</variation>
<variation>Mode195</variation>
</variations>
<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) \
org.testng.TestNG -d $(REPORTDIR) $(Q)$(TEST_RESROOT)$(D)testng_sm.xml$(Q) \
-testnames jsr292Test_SM \
-groups $(TEST_GROUP) \
-excludegroups $(DEFAULT_EXCLUDE); \
$(TEST_STATUS)</command>
<levels>
<level>extended</level>
</levels>
<groups>
<group>functional</group>
</groups>
<versions>
<version>11</version>
<version>17</version>
<version>18</version>
</versions>
<!--
TODO: Further investigation is needed for running against non-openj9 sdk
-->
<impls>
<impl>openj9</impl>
<impl>ibm</impl>
</impls>
</test>
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of add -testnames jsr292Test_SM in different test targets , could we just have one jsr292Test_SM target? And add <version>8</version> and <variation>-Xjit:count=0</variation> in this jsr292Test_SM target? Did I miss anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems like jsr292Test_jdk8 and jsr292Test_jdk8_special are the same (with variation changes) but jsr292Test_JitCount0_jdk8 has an extra testname jsr292Test_optional and platform requirement ^arch.arm. The first two could probably be merged but why are they separate to begin with? If I merge the new SM tests then the non SM tests should be merged as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

The first two could probably be merged but why are they separate to begin with?

I am not sure the details, but I think these tests were added in the early days. And the test framework (TKG) might have limited ability back then, which resulted in separated targets.

If I merge the new SM tests then the non SM tests should be merged as well.

I was thinking to keep this PR simple and only deal with SM tests. And we can have a separate PR for cleaning up non SM tests later. But it is up to you. I am ok either way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The github diff was messy when I tried to merge everything so I merged just the SM tests instead

<test>
<testCaseName>jsr292Test_jdk12</testCaseName>
<variations>
Expand Down Expand Up @@ -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)</command>
Expand Down Expand Up @@ -224,6 +260,37 @@
<impl>ibm</impl>
</impls>
</test>
<test>
<testCaseName>jsr292Test_JitCount0_SM</testCaseName>
<variations>
<variation>-Xjit:count=0</variation>
</variations>
<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) \
org.testng.TestNG -d $(REPORTDIR) $(Q)$(TEST_RESROOT)$(D)testng_sm.xml$(Q) \
-testnames jsr292Test_SM \
-groups $(TEST_GROUP) \
-excludegroups $(DEFAULT_EXCLUDE); \
$(TEST_STATUS)</command>
<platformRequirements>^arch.arm</platformRequirements>
<levels>
<level>extended</level>
</levels>
<groups>
<group>functional</group>
</groups>
<versions>
<version>11</version>
<version>17</version>
<version>18</version>
</versions>
<impls>
<impl>openj9</impl>
<impl>ibm</impl>
</impls>
</test>
<test>
<testCaseName>jsr292BootstrapTest_jdk8</testCaseName>
<variations>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
8 changes: 7 additions & 1 deletion test/functional/Jsr292/testng_8.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
Copyright (c) 2016, 2018 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 @@ -54,6 +54,12 @@
</classes>
</test>

<test name="jsr292Test_SM">
<classes>
<class name="com.ibm.j9.jsr292.MethodTypeTests_SM"/>
</classes>
</test>

<!--
The following tests are used to check whether some specific methods are correctly compiled by JIT.
If the JIT is not ON or with count=0 parameter, then there is no point to enable these tests.
Expand Down
32 changes: 32 additions & 0 deletions test/functional/Jsr292/testng_sm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
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
-->

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="jsr292 SecurityManager suite" parallel="none" verbose="2">
<test name="jsr292Test_SM">
<classes>
<class name="com.ibm.j9.jsr292.MethodTypeTests_SM"/>
</classes>
</test>
</suite>