db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r1447388 - in /db/derby/code/trunk: ./ java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ java...
Date Mon, 18 Feb 2013 16:45:48 GMT
Author: kristwaa
Date: Mon Feb 18 16:45:48 2013
New Revision: 1447388

URL: http://svn.apache.org/r1447388
Log:
DERBY-6067: JaCoCo fails with missing permissions when writing results

Added a "jacoco.active" property, which will grant the required privileges to
JaCoCo (or more specifically, all code bases) when set to the empty string ("").
Enabled logic to disable the security manager when spawning processes and at
the same time obtaining code coverage with JaCoCo.
Added comment in build.xml, explaining what derby.tests.jacoco.agent is for.

Patch file: derby-6067-1b-fix_privileges.diff

Modified:
    db/derby/code/trunk/build.xml
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/RuntimeInfoTest.policy
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SysinfoTest.policy
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/noAbortPermission.policy
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/LDAPTests.policy
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SecurityPolicyReloadingTest.initial.policy
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/Derby3980DeadlockTest.policy
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SecurityManagerSetup.java

Modified: db/derby/code/trunk/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/build.xml?rev=1447388&r1=1447387&r2=1447388&view=diff
==============================================================================
--- db/derby/code/trunk/build.xml (original)
+++ db/derby/code/trunk/build.xml Mon Feb 18 16:45:48 2013
@@ -2329,6 +2329,9 @@
     <!-- Set a dummy value for the JaCoCo agent option when running without
          JaCoCo for code coverage. Required because ant doesn't (yet) handle
          empty variables passed to jvmarg. See also target jacoco-enable. -->
+    <!-- The purpose of the system property derby.tests.jacoco.agent is to
+         allow the Derby test framework to pass on the correct -javaagent
+         option when spawning VMs. -->
     <condition property="derby.tests.jacoco.agent" value="-Dderby.dummy.prop=X">
       <not>
         <isset property="derby.tests.jacoco.agent"/>            

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/RuntimeInfoTest.policy
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/RuntimeInfoTest.policy?rev=1447388&r1=1447387&r2=1447388&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/RuntimeInfoTest.policy
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/RuntimeInfoTest.policy
Mon Feb 18 16:45:48 2013
@@ -375,6 +375,11 @@ grant {
   permission java.lang.RuntimePermission "${emma.active}writeFileDescriptor";
 };
 
+// Grant the required permissions for JaCoCo (code coverage tool).
+grant {
+  permission java.io.FilePermission "${jacoco.active}${user.dir}${/}*", "read, write";
+};
+
 // When inserting XML values that use external DTD's, the JAXP parser
 // needs permission to read the DTD files.  We assume that all DTD
 // files will be copied to extin/ by whichever tests need them.  So

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java?rev=1447388&r1=1447387&r2=1447388&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java
Mon Feb 18 16:45:48 2013
@@ -330,7 +330,7 @@ public class SecureServerTest extends Ba
 
         assertEquals( myName + ": serverCameUp = " + serverCameUp, _outcome.serverShouldComeUp(),
serverCameUp );
 
-        if (!runsWithEmma()) {
+        if (!(runsWithEmma() || runsWithJaCoCo())) {
             // With Emma we run without the security manager, so we can't
             // assert on seeing it.
             assertTrue( myName + "\nExpected: " +

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SysinfoTest.policy
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SysinfoTest.policy?rev=1447388&r1=1447387&r2=1447388&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SysinfoTest.policy
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SysinfoTest.policy
Mon Feb 18 16:45:48 2013
@@ -381,6 +381,11 @@ grant {
   permission java.lang.RuntimePermission "${emma.active}writeFileDescriptor";
 };
 
+// Grant the required permissions for JaCoCo (code coverage tool).
+grant {
+  permission java.io.FilePermission "${jacoco.active}${user.dir}${/}*", "read, write";
+};
+
 // When inserting XML values that use external DTD's, the JAXP parser
 // needs permission to read the DTD files.  We assume that all DTD
 // files will be copied to extin/ by whichever tests need them.  So

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/noAbortPermission.policy
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/noAbortPermission.policy?rev=1447388&r1=1447387&r2=1447388&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/noAbortPermission.policy
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/noAbortPermission.policy
Mon Feb 18 16:45:48 2013
@@ -368,6 +368,11 @@ grant {
   permission java.lang.RuntimePermission "${emma.active}writeFileDescriptor";
 };
 
+// Grant the required permissions for JaCoCo (code coverage tool).
+grant {
+  permission java.io.FilePermission "${jacoco.active}${user.dir}${/}*", "read, write";
+};
+
 // When inserting XML values that use external DTD's, the JAXP parser
 // needs permission to read the DTD files.  We assume that all DTD
 // files will be copied to extin/ by whichever tests need them.  So

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/LDAPTests.policy
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/LDAPTests.policy?rev=1447388&r1=1447387&r2=1447388&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/LDAPTests.policy
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/LDAPTests.policy
Mon Feb 18 16:45:48 2013
@@ -348,6 +348,11 @@ grant {
   permission java.lang.RuntimePermission "${emma.active}writeFileDescriptor";
 };
 
+// Grant the required permissions for JaCoCo (code coverage tool).
+grant {
+  permission java.io.FilePermission "${jacoco.active}${user.dir}${/}*", "read, write";
+};
+
 // When inserting XML values that use external DTD's, the JAXP parser
 // needs permission to read the DTD files.  We assume that all DTD
 // files will be copied to extin/ by whichever tests need them.  So

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SecurityPolicyReloadingTest.initial.policy
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SecurityPolicyReloadingTest.initial.policy?rev=1447388&r1=1447387&r2=1447388&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SecurityPolicyReloadingTest.initial.policy
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SecurityPolicyReloadingTest.initial.policy
Mon Feb 18 16:45:48 2013
@@ -105,3 +105,8 @@ grant {
     permission java.io.FilePermission "${emma.active}${user.dir}${/}coverage.ec", "read,
write";
     permission java.lang.RuntimePermission "${emma.active}writeFileDescriptor";
 };
+
+// Grant the required permissions for JaCoCo (code coverage tool).
+grant {
+  permission java.io.FilePermission "${jacoco.active}${user.dir}${/}*", "read, write";
+};

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/Derby3980DeadlockTest.policy
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/Derby3980DeadlockTest.policy?rev=1447388&r1=1447387&r2=1447388&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/Derby3980DeadlockTest.policy
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/Derby3980DeadlockTest.policy
Mon Feb 18 16:45:48 2013
@@ -370,6 +370,11 @@ grant {
   permission java.lang.RuntimePermission "${emma.active}writeFileDescriptor";
 };
 
+// Grant the required permissions for JaCoCo (code coverage tool).
+grant {
+  permission java.io.FilePermission "${jacoco.active}${user.dir}${/}*", "read, write";
+};
+
 // When inserting XML values that use external DTD's, the JAXP parser
 // needs permission to read the DTD files.  We assume that all DTD
 // files will be copied to extin/ by whichever tests need them.  So

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy?rev=1447388&r1=1447387&r2=1447388&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy
Mon Feb 18 16:45:48 2013
@@ -416,6 +416,11 @@ grant {
   permission java.lang.RuntimePermission "${emma.active}writeFileDescriptor";
 };
 
+// Grant the required permissions for JaCoCo (code coverage tool).
+grant {
+  permission java.io.FilePermission "${jacoco.active}${user.dir}${/}*", "read, write";
+};
+
 // When inserting XML values that use external DTD's, the JAXP parser
 // needs permission to read the DTD files.  We assume that all DTD
 // files will be copied to extin/ by whichever tests need them.  So

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java?rev=1447388&r1=1447387&r2=1447388&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java Mon Feb
18 16:45:48 2013
@@ -817,9 +817,7 @@ public abstract class BaseTestCase
     }
 
     public static boolean runsWithJaCoCo() {
-        String agentProp = getSystemProperty(JACOCO_AGENT_PROP);
-        // Additional logic due to the use of a dummy property in build.xml
-        return agentProp != null && agentProp.startsWith("-javaagent");
+        return SecurityManagerSetup.jacocoEnabled;
     }
 
     /**

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java?rev=1447388&r1=1447387&r2=1447388&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java
Mon Feb 18 16:45:48 2013
@@ -331,7 +331,8 @@ final public class NetworkServerTestSetu
         // running with Emma we don't run with the security manager, as the
         // default server policy doesn't contain needed permissions and,
         // additionally, Emma sources do not use doPrivileged blocks anyway.
-        if (!TestConfiguration.loadingFromJars() || BaseTestCase.runsWithEmma())
+        if (!TestConfiguration.loadingFromJars() ||
+                BaseTestCase.runsWithEmma() || BaseTestCase.runsWithJaCoCo())
         {
             boolean setNoSecurityManager = true;
             for (int i = 0; i < systemProperties.length; i++)

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SecurityManagerSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SecurityManagerSetup.java?rev=1447388&r1=1447387&r2=1447388&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SecurityManagerSetup.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SecurityManagerSetup.java
Mon Feb 18 16:45:48 2013
@@ -88,7 +88,20 @@ public final class SecurityManagerSetup 
 		externalSecurityManagerInstalled = determineClasspath();
         
 	}
-	
+
+    static final boolean jacocoEnabled = checkIfJacocoIsRunning();
+    private static boolean checkIfJacocoIsRunning() {
+        return ((Boolean)AccessController.doPrivileged(new PrivilegedAction() {
+                public Object run() {
+                    if (getURL("org.jacoco.agent.rt.RT") != null) {
+                        System.setProperty("jacoco.active", "");
+                        return Boolean.TRUE;
+                    }
+                    return Boolean.FALSE;
+                }
+		})).booleanValue();
+    }
+
 	private final String decoratorPolicyResource;
     /** An additional policy to install (may be {@code null}). */
     private final String additionalPolicyResource;
@@ -339,7 +352,7 @@ public final class SecurityManagerSetup 
         if (emma != null) {
             classPathSet.setProperty("emma.active", "");
         }
-		
+
         /* When inserting XML values that use external DTD's, the JAXP
          * parser needs permission to read the DTD files.  So here we set
          * a property to hold the location of the JAXP implementation
@@ -430,6 +443,8 @@ public final class SecurityManagerSetup 
             return getURL(Class.forName(className));
         } catch (ClassNotFoundException e) {
             return null;
+        } catch (NoClassDefFoundError e) {
+            return null;
         }
     }
 	



Mime
View raw message