* FYI: Updated java.lang.ThreadGroup throwpoint tests
@ 2006-05-05 12:28 Gary Benson
0 siblings, 0 replies; only message in thread
From: Gary Benson @ 2006-05-05 12:28 UTC (permalink / raw)
To: mauve-patches
[-- Attachment #1: Type: text/plain, Size: 181 bytes --]
Hi all,
This commit fixes similar problems with java.lang.ThreadGroup's
throwpoint tests to the problems with the Thread throwpoint checks
I committed the other day.
Cheers,
Gary
[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 14917 bytes --]
Index: ChangeLog
===================================================================
RCS file: /cvs/mauve/mauve/ChangeLog,v
retrieving revision 1.1605
diff -u -r1.1605 ChangeLog
--- ChangeLog 4 May 2006 14:48:19 -0000 1.1605
+++ ChangeLog 5 May 2006 12:26:00 -0000
@@ -1,3 +1,8 @@
+2006-05-05 Gary Benson <gbenson@redhat.com>
+
+ * gnu/testlet/java/lang/ThreadGroup/security.java: Rearranged to
+ work with class libraries other than Classpath.
+
2006-05-04 Gary Benson <gbenson@redhat.com>
* gnu/testlet/java/lang/Thread/security.java: Added some missing
Index: gnu/testlet/java/lang/ThreadGroup/security.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/lang/ThreadGroup/security.java,v
retrieving revision 1.1
diff -u -r1.1 security.java
--- gnu/testlet/java/lang/ThreadGroup/security.java 20 Feb 2006 11:56:05 -0000 1.1
+++ gnu/testlet/java/lang/ThreadGroup/security.java 5 May 2006 12:26:00 -0000
@@ -33,217 +33,298 @@
try {
harness.checkPoint("setup");
- ThreadGroup testGroup = Thread.currentThread().getThreadGroup();
- if (testGroup.getParent() == null)
- testGroup = new ThreadGroup(testGroup, "test group");
- harness.check(testGroup.getParent() != null);
-
- Permission[] modifyThreadGroup = new Permission[] {
- new RuntimePermission("modifyThreadGroup")};
-
- Permission[] modifyThread = new Permission[] {
- new RuntimePermission("modifyThread")};
-
- Permission[] stopThread = new Permission[] {
- new RuntimePermission("modifyThread"),
- new RuntimePermission("stopThread")};
+ // The default SecurityManager.checkAccess(ThreadGroup) method
+ // only checks permissions when the threadgroup in question is
+ // the system threadgroup, which is defined as the threadgroup
+ // with no parent.
+
+ ThreadGroup systemGroup = Thread.currentThread().getThreadGroup();
+ while (systemGroup.getParent() != null)
+ systemGroup = systemGroup.getParent();
- TestSecurityManager2 sm = new TestSecurityManager2(harness);
+ Thread testThread = new Thread(systemGroup, new TestRunner(harness));
+
+ testThread.start();
+ testThread.join();
+ }
+ catch (Throwable ex) {
+ harness.debug(ex);
+ harness.check(false, "Unexpected exception");
+ }
+ }
+
+ public static class TestRunner implements Runnable
+ {
+ private TestHarness harness;
+
+ public TestRunner(TestHarness harness)
+ {
+ this.harness = harness;
+ }
+
+ public void run()
+ {
try {
- sm.install();
+ ThreadGroup testGroup = Thread.currentThread().getThreadGroup();
+ harness.check(testGroup.getParent() == null);
- // throwpoint: java.lang.ThreadGroup-ThreadGroup(String)
- harness.checkPoint("ThreadGroup(String)");
- try {
- sm.prepareChecks(modifyThreadGroup);
- new ThreadGroup("test");
- sm.checkAllChecked(harness);
- }
- catch (SecurityException ex) {
- harness.debug(ex);
- harness.check(false, "unexpected check");
- }
+ ThreadGroup nonSystemGroup = new ThreadGroup(testGroup, "test group");
+ harness.check(nonSystemGroup.getParent() != null);
- // throwpoint: java.lang.ThreadGroup-ThreadGroup(ThreadGroup, String)
- harness.checkPoint("ThreadGroup(ThreadGroup, String)");
- try {
- sm.prepareChecks(modifyThreadGroup);
- new ThreadGroup(testGroup, "test");
- sm.checkAllChecked(harness);
- }
- catch (SecurityException ex) {
- harness.debug(ex);
- harness.check(false, "unexpected check");
- }
+ Permission[] modifyThreadGroup = new Permission[] {
+ new RuntimePermission("modifyThreadGroup")};
- // throwpoint: java.lang.ThreadGroup-checkAccess
- harness.checkPoint("checkAccess");
- try {
- sm.prepareChecks(modifyThreadGroup);
- testGroup.checkAccess();
- sm.checkAllChecked(harness);
- }
- catch (SecurityException ex) {
- harness.debug(ex);
- harness.check(false, "unexpected check");
- }
+ Permission[] modifyThread = new Permission[] {
+ new RuntimePermission("modifyThread")};
+
+ Permission[] stopThread = new Permission[] {
+ new RuntimePermission("modifyThread"),
+ new RuntimePermission("stopThread")};
- // throwpoint: java.lang.ThreadGroup-enumerate(Thread[])
- harness.checkPoint("enumerate(Thread[])");
+ TestSecurityManager2 sm = new TestSecurityManager2(harness);
try {
- sm.prepareChecks(modifyThreadGroup);
- testGroup.enumerate(new Thread[0]);
- sm.checkAllChecked(harness);
- }
- catch (SecurityException ex) {
- harness.debug(ex);
- harness.check(false, "unexpected check");
- }
+ sm.install();
- // throwpoint: java.lang.ThreadGroup-enumerate(Thread[], boolean)
- harness.checkPoint("enumerate(Thread[], boolean)");
- for (int i = 0; i <= 1; i++) {
+ // throwpoint: java.lang.ThreadGroup-ThreadGroup(String)
+ harness.checkPoint("ThreadGroup(String)");
+ try {
+ sm.prepareChecks(modifyThreadGroup);
+ new ThreadGroup("test");
+ sm.checkAllChecked(harness);
+ }
+ catch (SecurityException ex) {
+ harness.debug(ex);
+ harness.check(false, "unexpected check");
+ }
+
+ // throwpoint: java.lang.ThreadGroup-ThreadGroup(ThreadGroup, String)
+ harness.checkPoint("ThreadGroup(ThreadGroup, String)");
try {
sm.prepareChecks(modifyThreadGroup);
- testGroup.enumerate(new Thread[0], i == 1);
+ new ThreadGroup(testGroup, "test");
+ sm.checkAllChecked(harness);
+ }
+ catch (SecurityException ex) {
+ harness.debug(ex);
+ harness.check(false, "unexpected check");
+ }
+
+ // throwpoint: java.lang.ThreadGroup-checkAccess
+ harness.checkPoint("checkAccess");
+ try {
+ sm.prepareChecks(modifyThreadGroup);
+ testGroup.checkAccess();
+ sm.checkAllChecked(harness);
+ }
+ catch (SecurityException ex) {
+ harness.debug(ex);
+ harness.check(false, "unexpected check");
+ }
+
+ // throwpoint: java.lang.ThreadGroup-enumerate(Thread[])
+ harness.checkPoint("enumerate(Thread[])");
+ try {
+ sm.prepareChecks(modifyThreadGroup);
+ testGroup.enumerate(new Thread[0]);
sm.checkAllChecked(harness);
}
catch (SecurityException ex) {
harness.debug(ex);
harness.check(false, "unexpected check");
}
- }
- // throwpoint: java.lang.ThreadGroup-enumerate(ThreadGroup[])
- harness.checkPoint("enumerate(ThreadGroup[])");
- try {
- sm.prepareChecks(modifyThreadGroup);
- testGroup.enumerate(new ThreadGroup[0]);
- sm.checkAllChecked(harness);
- }
- catch (SecurityException ex) {
- harness.debug(ex);
- harness.check(false, "unexpected check");
- }
+ // throwpoint: java.lang.ThreadGroup-enumerate(Thread[], boolean)
+ harness.checkPoint("enumerate(Thread[], boolean)");
+ for (int i = 0; i <= 1; i++) {
+ try {
+ sm.prepareChecks(modifyThreadGroup);
+ testGroup.enumerate(new Thread[0], i == 1);
+ sm.checkAllChecked(harness);
+ }
+ catch (SecurityException ex) {
+ harness.debug(ex);
+ harness.check(false, "unexpected check");
+ }
+ }
- // throwpoint: java.lang.ThreadGroup-enumerate(ThreadGroup[], boolean)
- harness.checkPoint("enumerate(ThreadGroup[], boolean)");
- for (int i = 0; i <= 1; i++) {
+ // throwpoint: java.lang.ThreadGroup-enumerate(ThreadGroup[])
+ harness.checkPoint("enumerate(ThreadGroup[])");
try {
sm.prepareChecks(modifyThreadGroup);
- testGroup.enumerate(new ThreadGroup[0], i == 1);
+ testGroup.enumerate(new ThreadGroup[0]);
sm.checkAllChecked(harness);
}
catch (SecurityException ex) {
harness.debug(ex);
harness.check(false, "unexpected check");
}
- }
- // throwpoint: java.lang.ThreadGroup-getParent
- harness.checkPoint("getParent");
- try {
- sm.prepareChecks(modifyThreadGroup);
- testGroup.getParent();
- sm.checkAllChecked(harness);
- }
- catch (SecurityException ex) {
- harness.debug(ex);
- harness.check(false, "unexpected check");
- }
+ // throwpoint: java.lang.ThreadGroup-enumerate(ThreadGroup[], boolean)
+ harness.checkPoint("enumerate(ThreadGroup[], boolean)");
+ for (int i = 0; i <= 1; i++) {
+ try {
+ sm.prepareChecks(modifyThreadGroup);
+ testGroup.enumerate(new ThreadGroup[0], i == 1);
+ sm.checkAllChecked(harness);
+ }
+ catch (SecurityException ex) {
+ harness.debug(ex);
+ harness.check(false, "unexpected check");
+ }
+ }
+
+ // throwpoint: java.lang.ThreadGroup-getParent
+ harness.checkPoint("getParent");
+ try {
+ sm.prepareChecks(modifyThreadGroup);
+ nonSystemGroup.getParent();
+ sm.checkAllChecked(harness);
+ }
+ catch (SecurityException ex) {
+ harness.debug(ex);
+ harness.check(false, "unexpected check");
+ }
- // throwpoint: java.lang.ThreadGroup-setDaemon
- harness.checkPoint("setDaemon");
- try {
- sm.prepareChecks(modifyThreadGroup);
- testGroup.setDaemon(false);
- sm.checkAllChecked(harness);
- }
- catch (SecurityException ex) {
- harness.debug(ex);
- harness.check(false, "unexpected check");
- }
+ // throwpoint: java.lang.ThreadGroup-setDaemon
+ harness.checkPoint("setDaemon");
+ try {
+ sm.prepareChecks(modifyThreadGroup);
+ testGroup.setDaemon(false);
+ sm.checkAllChecked(harness);
+ }
+ catch (SecurityException ex) {
+ harness.debug(ex);
+ harness.check(false, "unexpected check");
+ }
- // throwpoint: java.lang.ThreadGroup-setMaxPriority
- harness.checkPoint("setMaxPriority");
- try {
- int priority = testGroup.getMaxPriority();
- sm.prepareChecks(modifyThreadGroup);
- testGroup.setMaxPriority(priority);
- sm.checkAllChecked(harness);
- }
- catch (SecurityException ex) {
- harness.debug(ex);
- harness.check(false, "unexpected check");
- }
+ // throwpoint: java.lang.ThreadGroup-setMaxPriority
+ harness.checkPoint("setMaxPriority");
+ try {
+ int priority = testGroup.getMaxPriority();
+ sm.prepareChecks(modifyThreadGroup);
+ testGroup.setMaxPriority(priority);
+ sm.checkAllChecked(harness);
+ }
+ catch (SecurityException ex) {
+ harness.debug(ex);
+ harness.check(false, "unexpected check");
+ }
- // throwpoint: java.lang.ThreadGroup-suspend
- harness.checkPoint("suspend");
- try {
- sm.prepareChecks(modifyThreadGroup);
- testGroup.suspend();
- sm.checkAllChecked(harness);
- }
- catch (SecurityException ex) {
- harness.debug(ex);
- harness.check(false, "unexpected check");
- }
+ // throwpoint: java.lang.ThreadGroup-suspend
+ harness.checkPoint("suspend");
+ try {
+ sm.prepareChecks(modifyThreadGroup, modifyThread, true);
+ testGroup.suspend();
+ harness.check(false, "shouldn't be reached");
+ }
+ catch (SecurityException ex) {
+ if (ex.getMessage().equals(TestSecurityManager2.successMessage)) {
+ harness.check(true);
+ }
+ else {
+ harness.debug(ex);
+ harness.check(false, "unexpected check");
+ }
+ }
- // throwpoint: java.lang.ThreadGroup-resume
- harness.checkPoint("resume");
- try {
- sm.prepareChecks(modifyThreadGroup);
- testGroup.resume();
- sm.checkAllChecked(harness);
- }
- catch (SecurityException ex) {
- harness.debug(ex);
- harness.check(false, "unexpected check");
- }
+ // throwpoint: java.lang.ThreadGroup-resume
+ harness.checkPoint("resume");
+ try {
+ sm.prepareChecks(modifyThreadGroup, modifyThread, true);
+ testGroup.resume();
+ harness.check(false, "shouldn't be reached");
+ }
+ catch (SecurityException ex) {
+ if (ex.getMessage().equals(TestSecurityManager2.successMessage)) {
+ harness.check(true);
+ }
+ else {
+ harness.debug(ex);
+ harness.check(false, "unexpected check");
+ }
+ }
- // throwpoint: java.lang.ThreadGroup-destroy
- harness.checkPoint("destroy");
- try {
- sm.prepareChecks(modifyThreadGroup);
- testGroup.destroy();
- sm.checkAllChecked(harness);
- }
- catch (SecurityException ex) {
- harness.debug(ex);
- harness.check(false, "unexpected check");
- }
+ // throwpoint: TODO: java.lang.ThreadGroup-destroy
+ // XXX I'm not sure you can test for this one. It's an
+ // XXX error to call this on a non-empty threadgroup, but
+ // XXX the check only happens for the system group which
+ // XXX will not be empty.
- // throwpoint: java.lang.ThreadGroup-interrupt
- harness.checkPoint("interrupt");
- try {
- sm.prepareChecks(modifyThreadGroup, modifyThread);
- testGroup.interrupt();
- sm.checkAllChecked(harness);
+ // throwpoint: java.lang.ThreadGroup-interrupt
+ harness.checkPoint("interrupt");
+ try {
+ sm.prepareChecks(modifyThreadGroup, modifyThread, true);
+ testGroup.interrupt();
+ harness.check(false, "shouldn't be reached");
+ }
+ catch (SecurityException ex) {
+ if (ex.getMessage().equals(TestSecurityManager2.successMessage)) {
+ harness.check(true);
+ }
+ else {
+ harness.debug(ex);
+ harness.check(false, "unexpected check");
+ }
+ }
+
+ // throwpoint: java.lang.ThreadGroup-stop
+ harness.checkPoint("stop");
+ try {
+ sm.prepareChecks(modifyThreadGroup, stopThread, true);
+ testGroup.stop();
+ harness.check(false, "shouldn't be reached");
+ }
+ catch (SecurityException ex) {
+ if (ex.getMessage().equals(TestSecurityManager2.successMessage)) {
+ harness.check(true);
+ }
+ else {
+ harness.debug(ex);
+ harness.check(false, "unexpected check");
+ }
+ }
}
- catch (SecurityException ex) {
- harness.debug(ex);
- harness.check(false, "unexpected check");
+ finally {
+ sm.uninstall();
}
- // throwpoint: java.lang.ThreadGroup-stop
- harness.checkPoint("stop");
+ sm = new SpecialSecurityManager(harness);
try {
- sm.prepareChecks(modifyThreadGroup, stopThread);
- testGroup.stop();
- sm.checkAllChecked(harness);
+ sm.install();
+
+ // throwpoint: java.lang.ThreadGroup-destroy
+ harness.checkPoint("destroy");
+ try {
+ sm.prepareChecks(modifyThreadGroup);
+ nonSystemGroup.destroy();
+ sm.checkAllChecked(harness);
+ }
+ catch (SecurityException ex) {
+ harness.debug(ex);
+ harness.check(false, "unexpected check");
+ }
}
- catch (SecurityException ex) {
- harness.debug(ex);
- harness.check(false, "unexpected check");
+ finally {
+ sm.uninstall();
}
}
- finally {
- sm.uninstall();
+ catch (Throwable ex) {
+ harness.debug(ex);
+ harness.check(false, "Unexpected exception");
}
}
- catch (Throwable ex) {
- harness.debug(ex);
- harness.check(false, "Unexpected exception");
+ }
+
+ public static class SpecialSecurityManager extends TestSecurityManager2
+ {
+ public SpecialSecurityManager(TestHarness harness)
+ {
+ super(harness);
+ }
+
+ public void checkAccess(ThreadGroup g)
+ {
+ checkPermission(new RuntimePermission("modifyThreadGroup"));
}
}
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-05-05 12:28 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-05-05 12:28 FYI: Updated java.lang.ThreadGroup throwpoint tests Gary Benson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).