From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24440 invoked by alias); 5 May 2006 12:28:58 -0000 Received: (qmail 24427 invoked by uid 22791); 5 May 2006 12:28:55 -0000 X-Spam-Check-By: sourceware.org Received: from gbenson.demon.co.uk (HELO gbenson.demon.co.uk) (80.177.220.214) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 05 May 2006 12:28:44 +0000 Received: from slippy.wire.rat ([192.168.1.1]) by gbenson.demon.co.uk with esmtp (Exim 3.36 #1) id 1FbzQH-0000d9-00 for mauve-patches@sources.redhat.com; Fri, 05 May 2006 13:28:41 +0100 Received: from slippy.wire.rat (localhost.localdomain [127.0.0.1]) by slippy.wire.rat (8.13.1/8.13.1) with ESMTP id k45CSeKV006344 for ; Fri, 5 May 2006 13:28:40 +0100 Received: (from gary@localhost) by slippy.wire.rat (8.13.1/8.13.1/Submit) id k45CSeF7006343 for mauve-patches@sources.redhat.com; Fri, 5 May 2006 13:28:40 +0100 Date: Fri, 05 May 2006 12:28:00 -0000 From: Gary Benson To: mauve-patches@sources.redhat.com Subject: FYI: Updated java.lang.ThreadGroup throwpoint tests Message-ID: <20060505122838.GC5185@redhat.com> Mail-Followup-To: mauve-patches@sources.redhat.com Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="LZvS9be/3tNcYl/X" Content-Disposition: inline X-IsSubscribed: yes Mailing-List: contact mauve-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: mauve-patches-owner@sourceware.org X-SW-Source: 2006/txt/msg00308.txt.bz2 --LZvS9be/3tNcYl/X Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 181 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 --LZvS9be/3tNcYl/X Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=patch Content-length: 14917 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 + + * gnu/testlet/java/lang/ThreadGroup/security.java: Rearranged to + work with class libraries other than Classpath. + 2006-05-04 Gary Benson * 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")); } } } --LZvS9be/3tNcYl/X--