From ahughes@redhat.com Tue May 11 21:12:00 2010 From: ahughes@redhat.com (Andrew John Hughes) Date: Tue, 11 May 2010 21:12:00 -0000 Subject: FYI: Test for PR43536 Message-ID: <20100511211152.GA8263@rivendell.middle-earth.co.uk> This patch adds a test to Mauve which ensures all known Collection implementations in java.util and java.util.concurrent meet the requirements of remove(Object). Others may be added later. 2010-05-11 Andrew John Hughes PR classpath/43536 * gnu/testlet/java/util/Collection/Test.java: New test ensuring all Collection implementations meet the requirements of remove(Object). -- Andrew :) Free Java Software Engineer Red Hat, Inc. (http://www.redhat.com) Support Free Java! Contribute to GNU Classpath and the OpenJDK http://www.gnu.org/software/classpath http://openjdk.java.net PGP Key: 94EFD9D8 (http://subkeys.pgp.net) Fingerprint = F8EF F1EA 401E 2E60 15FA 7927 142C 2591 94EF D9D8 -------------- next part -------------- Index: gnu/testlet/java/util/Collection/Test.java =================================================================== RCS file: gnu/testlet/java/util/Collection/Test.java diff -N gnu/testlet/java/util/Collection/Test.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/util/Collection/Test.java 11 May 2010 20:11:59 -0000 @@ -0,0 +1,155 @@ +// Tags: JDK1.5 + +// Copyright (C) 2010 Andrew John Hughes + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +package gnu.testlet.java.util.Collection; + +import gnu.testlet.TestHarness; +import gnu.testlet.Testlet; + +import java.util.Collection; + +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.Delayed; +import java.util.concurrent.TimeUnit; + +/** + * Some tests for the remove() method in the {@link List} interface. + */ +public class Test implements Testlet +{ + + private TestHarness harness; + + /** + * Runs the test using the specified harness. + * + * @param harness the test harness (null not permitted). + */ + public void test(TestHarness harness) + { + this.harness = harness; + testClass(java.util.concurrent.ArrayBlockingQueue.class); + testClass(java.util.ArrayDeque.class); + testClass(java.util.ArrayList.class); + testClass(java.util.concurrent.ConcurrentLinkedQueue.class); + testClass(java.util.concurrent.ConcurrentSkipListSet.class); + testClass(java.util.concurrent.CopyOnWriteArrayList.class); + testClass(java.util.concurrent.CopyOnWriteArraySet.class); + testClass(java.util.concurrent.DelayQueue.class); + testClass(java.util.EnumSet.class); + testClass(java.util.HashSet.class); + testClass(java.util.concurrent.LinkedBlockingQueue.class); + testClass(java.util.LinkedHashSet.class); + testClass(java.util.LinkedList.class); + testClass(java.util.concurrent.PriorityBlockingQueue.class); + testClass(java.util.PriorityQueue.class); + testClass(java.util.Stack.class); + testClass(java.util.concurrent.SynchronousQueue.class); + testClass(java.util.TreeSet.class); + testClass(java.util.Vector.class); + } + + /** + * Tests the given {@link java.util.Collection} class. + * + * @param cls the class to test. + */ + public void testClass(Class cls) + { + harness.checkPoint(cls.getName()); + Collection result = null; + try + { + result = (Collection) cls.newInstance(); + } + catch (Exception e) + { + harness.debug(e); + } + if (result != null) + { + testRemove(result); + } + } + + /** + * Test the {@link Collection#remove(Object)} method of + * the given collection. + * + * @param coll the collection to test. + */ + public void testRemove(Collection coll) + { + /** + * Use Delayed Object so DelayQueue + * and sorted collections work. + */ + Delayed obj = new Delayed() + { + public long getDelay(TimeUnit unit) + { + return unit.convert(10, TimeUnit.MINUTES); + } + public int compareTo(Delayed o) + { + Long other = o.getDelay(TimeUnit.NANOSECONDS); + return other.compareTo(getDelay(TimeUnit.NANOSECONDS)); + } + }; + String type = coll.getClass().getName(); + + harness.check(coll.remove(obj) == false, + "Object is not present in empty " + type); + + boolean result = false; + try + { + result = coll.remove(null); + } + catch (NullPointerException e) + { + /* Collection does not support null elements */ + } + harness.check(result == false, "Null is not present in empty " + type); + + /* Can't do post-addition tests if no capacity */ + if (coll instanceof BlockingQueue && + ((BlockingQueue) coll).remainingCapacity() == 0) + return; + + coll.add(obj); + harness.check(coll.remove(obj) == true, + "Object is present in non-empty " + type); + + result = true; + try + { + coll.add(null); + result = coll.remove(null); + } + catch (NullPointerException e) + { + /* Collection does not support null elements */ + } + harness.check(result == true, "Null is present in non-empty " + type); + } + +} From ahughes@redhat.com Wed Dec 1 21:02:00 2010 From: ahughes@redhat.com (Dr Andrew John Hughes) Date: Wed, 01 Dec 2010 21:02:00 -0000 Subject: FYI: Recent test case additions Message-ID: <20101201210156.GS23577@rivendell.middle-earth.co.uk> I've added a number of new test cases to Mauve as a result of investigating http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42390 The earlier four below test for the first four issues in the bug. While running these, I found that they would fail, despite the security checks being present in the code. It appears that the TestSecurityManager uses a Policy object to check for security calls and this is ignored by the default SecurityManager on most GNU Classpath VMs. The latest change below adds a test to Mauve for this. I'll push a fix for GNU Classpath's VMAccessController shortly, but my testing shows that at least CACAO, JamVM and gij have their own copy that needs updating. 2010-12-01 Andrew John Hughes * gnu/testlet/TestSecurityManager.java: Fix whitespace. * gnu/testlet/java/security/Policy/setPolicy.java: Test that the default security manager actually uses the currently established policy. Our TestSecurityManager relies on this. 2010-11-24 Andrew John Hughes PR classpath/42390 * gnu/testlet/java/security/ProtectionDomain/Security.java New test to ensure toString() does a getPolicy check when not in debugging mode. 2010-11-15 Andrew John Hughes PR classpath/42390 * gnu/testlet/java/io/File/security.java: Add security manager checks for deleteOnExit, exists, canRead, isFile, isDirectory, isHidden, lastModified, length, canWrite, mkdir, mkdirs, setLastModified. 2010-11-15 Andrew John Hughes PR classpath/42390 * gnu/testlet/java/util/logging/LogManager/Security.java: Add test for addPropertyChangeListener and removePropertyChangeListener SecurityManager checks. 2010-11-15 Andrew John Hughes PR classpath/42390 * Makefile.in, * aclocal.m4, * configure: Regenerated. * gnu/testlet/java/io/ObjectOutputStream/security.java: Add tests for ObjectOutputStream(OutputStream) as reported in PR classpath/42390. -- Andrew :) Free Java Software Engineer Red Hat, Inc. (http://www.redhat.com) Support Free Java! Contribute to GNU Classpath and IcedTea http://www.gnu.org/software/classpath http://icedtea.classpath.org PGP Key: 94EFD9D8 (http://subkeys.pgp.net) Fingerprint = F8EF F1EA 401E 2E60 15FA 7927 142C 2591 94EF D9D8 From ahughes@redhat.com Mon Dec 13 17:39:00 2010 From: ahughes@redhat.com (Dr Andrew John Hughes) Date: Mon, 13 Dec 2010 17:39:00 -0000 Subject: FYI: Add getSimpleName test Message-ID: <20101213173851.GC24855@rivendell.middle-earth.co.uk> Attached is a new test for java.lang.Class#getSimpleName contributed by Pekka Enberg and extended by myself to check anonymous classes. 2010-12-13 Andrew John Hughes * gnu/testlet/java/lang/Class/GetSimpleName.java: Add tests for anonymous classes. 2010-12-12 Pekka Enberg * gnu/testlet/java/lang/Class/GetSimpleName.java: Add tests for primitive, Object, array and inner classes. -- Andrew :) Free Java Software Engineer Red Hat, Inc. (http://www.redhat.com) Support Free Java! Contribute to GNU Classpath and IcedTea http://www.gnu.org/software/classpath http://icedtea.classpath.org PGP Key: 94EFD9D8 (http://subkeys.pgp.net) Fingerprint = F8EF F1EA 401E 2E60 15FA 7927 142C 2591 94EF D9D8 -------------- next part -------------- Index: gnu/testlet/java/lang/Class/GetSimpleName.java =================================================================== RCS file: gnu/testlet/java/lang/Class/GetSimpleName.java diff -N gnu/testlet/java/lang/Class/GetSimpleName.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/lang/Class/GetSimpleName.java 13 Dec 2010 15:41:45 -0000 @@ -0,0 +1,59 @@ +/* Copyright (C) 2010 Pekka Enberg + Copyright (C) 2010 Red Hat, Inc. + + This file is part of Mauve. + + Mauve is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + Mauve is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Mauve; see the file COPYING. If not, write to + the Free Software Foundation, 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +// Tags: JDK1.5 + +package gnu.testlet.java.lang.Class; + +import gnu.testlet.Testlet; +import gnu.testlet.TestHarness; + +import java.lang.reflect.Array; + +public class GetSimpleName implements Testlet +{ + + public void test(TestHarness harness) + { + Class anon = (new Object() { + public String toString() { return "Hello!"; } + }).getClass(); + Class anonArray = Array.newInstance(anon, 1).getClass(); + + harness.check(int.class.getSimpleName(), "int", + "Primitive type class"); + harness.check(int[].class.getSimpleName(), "int[]", + "Primitive type one-dimensional array class"); + harness.check(int[][].class.getSimpleName(), "int[][]", + "Primitive type multi-dimensional array class"); + harness.check(Object[].class.getSimpleName(), "Object[]", + "Object type one-dimensional array class"); + harness.check(Object.class.getSimpleName(), "Object", + "Object type class"); + harness.check(InnerClass.class.getSimpleName(), "InnerClass", + "Inner class"); + harness.check(anon.getSimpleName(), "", "Anonymous class"); + harness.check(anonArray.getSimpleName(), "[]", "Anonymous array class"); + } + + public static class InnerClass { }; + +} From ahughes@redhat.com Sat Dec 25 01:15:00 2010 From: ahughes@redhat.com (Dr Andrew John Hughes) Date: Sat, 25 Dec 2010 01:15:00 -0000 Subject: FYI: Test if Policy.implies(Permission) is called for domains with AllPermission Message-ID: <20101225011449.GA28846@rivendell.middle-earth.co.uk> I found the following issue when trying to work out why OpenJDK would only pass some permission checks to the Policy object and Classpath VMs would pass them all, causing tests using gnu.testlet.TestSecurityManager to fail. It turns out OpenJDK doesn't bother to check the policy if the domain already has AllPermission (as it obviously already has permission regardless of what the policy says). This adds a Mauve test to check for this behaviour. I'm also committing a patch to Classpath to implement this behaviour. 2010-12-24 Andrew John Hughes * gnu/testlet/java/security/ProtectionDomain/Implies.java: Check if Policy.implies(Permission) is called if the protection domain is already known to have AllPermission. -- Andrew :) Free Java Software Engineer Red Hat, Inc. (http://www.redhat.com) Support Free Java! Contribute to GNU Classpath and IcedTea http://www.gnu.org/software/classpath http://icedtea.classpath.org PGP Key: 94EFD9D8 (http://subkeys.pgp.net) Fingerprint = F8EF F1EA 401E 2E60 15FA 7927 142C 2591 94EF D9D8 -------------- next part -------------- Index: gnu/testlet/java/security/ProtectionDomain/Implies.java =================================================================== RCS file: gnu/testlet/java/security/ProtectionDomain/Implies.java diff -N gnu/testlet/java/security/ProtectionDomain/Implies.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/security/ProtectionDomain/Implies.java 25 Dec 2010 01:08:41 -0000 @@ -0,0 +1,73 @@ +// Copyright (C) 2010 Red Hat, Inc. +// Written by Andrew John Hughes + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +// Tags: JDK1.4 + +package gnu.testlet.java.security.ProtectionDomain; + +import gnu.testlet.Testlet; +import gnu.testlet.TestHarness; + +import java.security.AllPermission; +import java.security.CodeSource; +import java.security.Permission; +import java.security.Permissions; +import java.security.PermissionCollection; +import java.security.Policy; +import java.security.ProtectionDomain; +import java.security.SecurityPermission; + +/** + * Tests whether Policy.implies(Permission) is called + * when the domain has AllPermission as one of its permissions. + */ +public class Implies implements Testlet +{ + + private boolean called = false; + + public void test(TestHarness harness) + { + Policy.setPolicy(new Policy() + { + public boolean implies(ProtectionDomain domain, + Permission perm) + { + if (perm.getName().equals("TestPermission")) + called = true; + return true; + } + public void refresh() {} + public PermissionCollection getPermissions(CodeSource codesource) + { + return null; + } + }); + + System.setSecurityManager(new SecurityManager()); + PermissionCollection coll = new Permissions(); + coll.add(new AllPermission()); + ProtectionDomain pd = new ProtectionDomain(null, coll, + Implies.class.getClassLoader(), null); + pd.implies(new SecurityPermission("TestPermission")); + harness.check(!called, "Policy was not checked due to AllPermission"); + } + +}