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 (JLM_Tests) #14562

Merged
merged 1 commit into from
Mar 30, 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
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_SM.java" />
<exclude name="org/openj9/test/java/lang/management/TestRegression_SM.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");
}
Copy link
Member

Choose a reason for hiding this comment

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

Is this a duplicated sub-test somewhere, otherwise, pls keep original version, and create one w/o System.setSecurityManager(new SecurityManager()).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this class is used at all

}
}

@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, 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 All @@ -24,14 +24,11 @@

import org.testng.annotations.Test;
import org.testng.log4testng.Logger;
import org.testng.Assert;
import org.testng.AssertJUnit;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;

import javax.management.MBeanServer;
import javax.management.MBeanServerConnection;

/**
Expand Down Expand Up @@ -79,19 +76,4 @@ public final void testBug452AgainstLocalVM() {
logger.debug("\n");
}
}

@Test
public final void testBug93006() {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

System.setSecurityManager(new SecurityManager());
AssertJUnit.assertNotNull(System.getSecurityManager());

try {
MBeanServer mbs2 = ManagementFactory.getPlatformMBeanServer();
Assert.fail("Should have thrown a SecurityException");
} catch (Exception e) {
AssertJUnit.assertTrue(e instanceof SecurityException);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*******************************************************************************
* 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 org.openj9.test.java.lang.management;

import org.testng.annotations.Test;
import org.testng.Assert;
import org.testng.AssertJUnit;
import java.lang.management.ManagementFactory;

import javax.management.MBeanServer;

/**
* Tests to catch regressions on reported bugs.
*/
@Test(groups = { "level.sanity" })
public class TestRegression_SM {

@Test
public final void testBug93006() {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

System.setSecurityManager(new SecurityManager());
AssertJUnit.assertNotNull(System.getSecurityManager());

try {
MBeanServer mbs2 = ManagementFactory.getPlatformMBeanServer();
Assert.fail("Should have thrown a SecurityException");
} catch (Exception e) {
AssertJUnit.assertTrue(e instanceof SecurityException);
}
}
}
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
Loading