Skip to content

Commit

Permalink
Separate tests that rely on SecurityManager (JLM_Tests)
Browse files Browse the repository at this point in the history
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: eclipse-openj9#14412
Signed-off-by: Eric Yang <[email protected]>
  • Loading branch information
EricYangIBM authored and pshipton committed Mar 3, 2022
1 parent afec275 commit 0135170
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 37 deletions.
38 changes: 25 additions & 13 deletions test/functional/JLM_Tests/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 @@ -81,18 +81,30 @@
</else>
</if>
<property name="TestUtilitiesExports" value="--add-exports java.base/openj9.internal.tools.attach.target=ALL-UNNAMED" />
<javac srcdir="${src}" destdir="${build}" debug="true" fork="true" executable="${compiler.javac}" includeAntRuntime="false" encoding="ISO-8859-1">
<src path="${src}" />
<src path="${src_90}" />
<src path="${transformerListener}" />
<src path="${TestUtilities}" />
<compilerarg line='${addExports} ${TestUtilitiesExports}' />
<classpath>
<pathelement location="${LIB_DIR}/testng.jar" />
<pathelement location="${LIB_DIR}/jcommander.jar" />
<pathelement location="${LIB_DIR}/commons-exec.jar" />
</classpath>
</javac>
<property name="srcpath" location="${src}:${src_90}:${transformerListener}:${TestUtilities}" />
<path id="build.cp">
<fileset dir="${LIB_DIR}/" includes="testng.jar"/>
<fileset dir="${LIB_DIR}/" includes="jcommander.jar"/>
<fileset dir="${LIB_DIR}/" includes="commons-exec.jar"/>
</path>
<if>
<matches string="${JDK_VERSION}" pattern="^(9|(1[0-8]))$$" />
<then>
<!-- Java 9-18 -->
<javac srcdir="${srcpath}" destdir="${build}" debug="true" fork="true" executable="${compiler.javac}" includeAntRuntime="false" encoding="ISO-8859-1" classpathref="build.cp">
<compilerarg line='${addExports} ${TestUtilitiesExports}' />
</javac>
</then>
<else>
<!-- Java 19+ (SecurityManager removed) -->
<javac srcdir="${srcpath}" destdir="${build}" debug="true" fork="true" executable="${compiler.javac}" includeAntRuntime="false" encoding="ISO-8859-1" classpathref="build.cp">
<compilerarg line='${addExports} ${TestUtilitiesExports}' />
<!-- exclude tests that depend on SecurityManager -->
<exclude name="org/openj9/test/java/lang/management/TestSharedClassMemoryMXBean.java" />
<exclude name="org/openj9/test/java/lang/management/TestRegression.java" />
</javac>
</else>
</if>
</else>
</if>
</target>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2020 IBM Corp. and others
* Copyright (c) 2005, 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 @@ -62,7 +62,6 @@
import com.ibm.lang.management.MemoryMXBean;

import org.openj9.test.util.VersionCheck;
import org.openj9.test.util.process.Task;

// These classes are not public API.
import com.ibm.java.lang.management.internal.MemoryNotificationInfoUtil;
Expand Down Expand Up @@ -148,20 +147,6 @@ protected void tearDown() throws Exception {
}
}

static class ClassForTestMaxHeapSize implements Task {
@Override
public void run() throws Exception {
System.setSecurityManager(new SecurityManager());
MemoryMXBean bean = (MemoryMXBean)ManagementFactory.getMemoryMXBean();
Thread.sleep(2000);
long size = bean.getMinHeapSize();
bean.setMaxHeapSize(size + 1024);
if (size + 1024 != bean.getMaxHeapSize()) {
throw new RuntimeException("not equal");
}
}
}

@Test
public final void testGetAttribute() {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2018 IBM Corp. and others
* Copyright (c) 2005, 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 @@ -51,14 +51,16 @@ protected void tearDown() throws Exception {

@Test
public void testVerboseSetting() {
if (System.getSecurityManager() == null) {
try {
String val1 = System.getProperty("com.ibm.lang.management.verbose");

if (val1 != null) {
AssertJUnit.assertTrue(ManagementUtils.VERBOSE_MODE);
} else {
AssertJUnit.assertFalse(ManagementUtils.VERBOSE_MODE);
} // end else com.ibm.lang.management.verbose was already set
} catch (SecurityException e) {
/* Security Manager was set; ignore */
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2020 IBM Corp. and others
* Copyright (c) 2005, 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 @@ -174,10 +174,12 @@ public final void testGetAttribute() {
AssertJUnit.assertNotNull(mbs.getAttribute(objName, "SystemProperties"));
AssertJUnit.assertTrue(mbs.getAttribute(objName, "SystemProperties") instanceof TabularData);
AssertJUnit.assertTrue(((TabularData)(mbs.getAttribute(objName, "SystemProperties"))).size() > 0);
if (System.getSecurityManager() == null) {
try {
AssertJUnit.assertTrue(((TabularData)(mbs.getAttribute(objName, "SystemProperties"))).size() ==
System.getProperties().size());
} // end if no security manager
} catch (SecurityException e) {
/* Security Manager was set; ignore */
}

AssertJUnit.assertNotNull(mbs.getAttribute(objName, "Uptime"));
AssertJUnit.assertTrue(mbs.getAttribute(objName, "Uptime") instanceof Long);
Expand Down Expand Up @@ -332,8 +334,10 @@ public final void testGetSystemProperties() {
AssertJUnit.assertTrue(props instanceof Map);
AssertJUnit.assertTrue(props.size() > 0);

if (System.getSecurityManager() == null) {
try {
AssertJUnit.assertTrue(props.size() == System.getProperties().size());
} catch (SecurityException e) {
/* Security Manager was set; ignore */
}
}

Expand Down Expand Up @@ -506,7 +510,7 @@ else if (attribs.get(name).type.equals(TabularData.class.getName())) {
// the SystemProperties.
TabularData td = (TabularData)value;
AssertJUnit.assertTrue(td.size() > 0);
if (System.getSecurityManager() == null) {
try {
Properties props = System.getProperties();
AssertJUnit.assertTrue(td.size() == props.size());
Enumeration<?> propNames = props.propertyNames();
Expand All @@ -515,7 +519,9 @@ else if (attribs.get(name).type.equals(TabularData.class.getName())) {
String propVal = props.getProperty(property);
AssertJUnit.assertEquals(propVal, td.get(new String[] { property }).get("value"));
} // end while
} // end if no security manager
} catch (SecurityException e) {
/* Security Manager was set; ignore */
}
} // end else a String array expected
} // end if a known attribute
else {
Expand Down

0 comments on commit 0135170

Please sign in to comment.