You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by dj...@apache.org on 2008/02/28 22:43:28 UTC

svn commit: r632125 - in /db/derby/code/trunk: ./ java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ java/testing/org/apache/derbyTesting/functionTests/tests/lang/ java/testing/org/apache/derbyTesting/functionTests/util/ java/testing/or...

Author: djd
Date: Thu Feb 28 13:43:25 2008
New Revision: 632125

URL: http://svn.apache.org/viewvc?rev=632125&view=rev
Log:
DERBY-3445 Adds ant targets to run the junit-all tests with EMMA code coverage.
Fixes some permission issues in tests when running coverage with EMMA.
DERBY-3153 Allows the junit-all tests to be run with ant 1.7 

Patch contributed by Vemund Østgaard Email: vemund at sun dot com

Modified:
    db/derby/code/trunk/build.xml
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.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/ServerPropertiesTest.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/util/derby_tests.policy
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SecurityManagerSetup.java
    db/derby/code/trunk/tools/ant/properties/extrapath.properties

Modified: db/derby/code/trunk/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/build.xml?rev=632125&r1=632124&r2=632125&view=diff
==============================================================================
--- db/derby/code/trunk/build.xml (original)
+++ db/derby/code/trunk/build.xml Thu Feb 28 13:43:25 2008
@@ -1850,9 +1850,14 @@
            jvm="${derby.junit.jvm}" maxmemory="512m"
            showoutput="yes"
            dir="junit_${derby.junit.timestamp}"
+           tempdir="junit_${derby.junit.timestamp}"
   	 	   errorproperty="tests.failed"
   	       failureproperty="tests.failed">
       <sysproperty key="derbyTesting.oldReleasePath" value="${derbyTesting.oldReleasePath}"/>
+      <!-- This property is needed to keep EMMA silent when measuring codecoverage -->
+      <sysproperty key="emma.verbosity.level" value="silent"/>
+      <!-- Use the system property below to debug lacking java security permissions -->
+<!--      <sysproperty key="java.security.debug" value="access:failure"/> -->
       <formatter type="xml"/>
   	 	
 <test name="org.apache.derbyTesting.functionTests.tests.jdbcapi.AutoloadTest"
@@ -1884,6 +1889,8 @@
 
       <classpath>
      	    <pathelement path="${derby.junit.classpath}"/>
+            <!-- ant 1.7 finds junit.jar if it is on the classpath of the <junit> task -->
+            <pathelement location="${junit}"/>
       </classpath>
     </junit>
   </target>
@@ -1935,6 +1942,7 @@
            jvm="${jdk16}/bin/java"
            showoutput="yes"
            dir="junit_${derby.junit.timestamp}"
+           tempdir="junit_${derby.junit.timestamp}"
   	 	   errorproperty="tests.failed"
   	       failureproperty="tests.failed">
       <formatter type="xml"/>
@@ -1943,6 +1951,7 @@
       	todir="junit_${derby.junit.timestamp}"/>
         <classpath>
        	    <pathelement path="${derby.junit.classpath}"/>
+            <pathelement location="${junit}"/>
         </classpath>
       </junit>	
   </target>
@@ -1953,6 +1962,7 @@
             fork="yes" forkmode="once"
             showoutput="yes"
             dir="junit_${derby.junit.timestamp}"
+            tempdir="junit_${derby.junit.timestamp}"
             errorproperty="tests.failed"
             failureproperty="tests.failed">
         <formatter type="xml"/>
@@ -1963,6 +1973,7 @@
         <classpath>
             <pathelement location="${out.pptesting.dir}"/>
             <pathelement location="${out.dir}"/>
+            <pathelement location="${junit}"/>
         </classpath>
     </junit>
   </target>
@@ -2026,5 +2037,74 @@
 	</target>
 	
 	
+
+<!-- =================================================================== -->
+<!--                         EMMA utility targets                       -->
+<!-- =================================================================== -->
+
+
+    <!-- directory that will contain the instrumented jar-files: -->
+    <property name="emmabase" value="${jarsdist.dir}/emma"/>
+    <property name="instrumented.jars" value="${emmabase}/lib"/>
+    <property name="instrumented.classes" value="${emmabase}/classes"/>
+
+    <target name="emma-clean">
+        <delete includeEmptyDirs="true">
+            <fileset dir="${emmabase}" includes="**"/>
+        </delete>
+    </target>
+    
+    <!-- These targets depend upon emma.jar and emma_ant.jar being installed under tools/java/ -->
+
+    <target name="emma-init" depends="initjars">
+        <!-- EMMA distribution: -->
+        <path id="emma.lib">
+            <pathelement location="${emma}"/>
+            <pathelement location="${emma_ant}"/>
+        </path>
+        <taskdef resource="emma_ant.properties" classpathref="emma.lib"/>
+        <mkdir dir="${emmabase}"/>
+    </target>
+    
+    <target name="emma-instrumentation" depends="emma-init,junit-init">
+        <!-- Apply emma instrumentation to the classes in instrpath and copy to destdir -->
+	<emma verbosity="verbose">
+            <instr outfile="junit_${derby.junit.timestamp}/coverage.em" destdir="${emmabase}" merge="true" mode="fullcopy">
+	        <instrpath>
+                    <pathelement path="${derby.jar.dir}/derby.jar"/>
+                    <pathelement path="${derby.jar.dir}/derbyclient.jar"/>
+                    <pathelement path="${derby.jar.dir}/derbynet.jar"/>
+                    <pathelement path="${derby.jar.dir}/derbytools.jar"/>
+                </instrpath>
+            </instr>
+	</emma>
+        <!-- Change the classpath used for junit tests to use the jars instrumented by EMMA -->
+        <property name="derby.junit.classpath" value="${emma}:${derby.jar.dir}/derbyTesting.jar:${instrumented.jars}/derby.jar:${instrumented.jars}/derbyclient.jar:${instrumented.jars}/derbynet.jar:${instrumented.jars}/derbytools.jar" />
+    </target>
+    
+    <target name="emma-all" depends="emma-instrumentation,junit-all">
+        <fail if="tests.failed">EMMA instrumented tests failed!</fail>
+    </target>
+
+    <target name="emma-report" depends="emma-all">
+        <emma>
+            <report verbosity="verbose" depth="method">
+                <sourcepath>
+                    <pathelement path="${derby.client.src.dir}" />
+                    <pathelement path="${derby.demo.src.dir}" />
+                    <pathelement path="${derby.drda.src.dir}" />
+                    <pathelement path="${derby.engine.src.dir}" />
+                    <pathelement path="${derby.shared.src.dir}" />
+                    <pathelement path="${derby.storeless.src.dir}" />
+                    <pathelement path="${derby.tools.src.dir}" />
+                </sourcepath>
+                <infileset dir="junit_${derby.junit.timestamp}" includes="coverage.em,coverage.ec" />
+                <!-- Three reports: txt, xml and html -->
+                <txt outfile="junit_${derby.junit.timestamp}/coverage.txt"/>
+                <xml outfile="junit_${derby.junit.timestamp}/coverage.xml"/>
+                <html outfile="junit_${derby.junit.timestamp}/coverage.html"/>
+            </report>
+        </emma>
+    </target>
 
 </project>

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.policy
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.policy?rev=632125&r1=632124&r2=632125&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.policy (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.policy Thu Feb 28 13:43:25 2008
@@ -208,6 +208,9 @@
     permission java.util.PropertyPermission "user.home", "read";
     permission java.io.FilePermission "${user.home}${/}junit.properties", "read";
     permission java.io.FilePermission "${user.home}${/}.junitsession", "write";
+
+    // This permission is needed when running the tests using ant 1.7
+    permission java.io.FilePermission "${user.dir}${/}*", "write";
 };
 
 // Due to a problem running tests/derbynet/CompatibilityTest in the old test
@@ -224,6 +227,9 @@
 // current one.
 grant codeBase "${derbyTesting.antjunit}" {
     permission java.lang.RuntimePermission "setIO";
+
+    // This permission is needed when running the tests using ant 1.7
+    permission java.io.FilePermission "${user.dir}${/}*", "write";
 };
 
 // functionTests.tests.lang.RoutineSecurityTest requires this grant

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=632125&r1=632124&r2=632125&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 Thu Feb 28 13:43:25 2008
@@ -443,6 +443,7 @@
 
         buffer.append( "java -classpath " );
         buffer.append( classpath );
+        buffer.append( " -Demma.verbosity.level=silent");
         buffer.append( " org.apache.derby.drda.NetworkServerControl -p " + portNumber + " " + commandSpecifics );
 
         final   String  command = buffer.toString();

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.policy
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.policy?rev=632125&r1=632124&r2=632125&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.policy (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.policy Thu Feb 28 13:43:25 2008
@@ -220,6 +220,9 @@
     permission java.util.PropertyPermission "user.home", "read";
     permission java.io.FilePermission "${user.home}${/}junit.properties", "read";
     permission java.io.FilePermission "${user.home}${/}.junitsession", "write";
+
+    // This permission is needed when running the tests using ant 1.7
+    permission java.io.FilePermission "${user.dir}${/}*", "write";
 };
 
 // Due to a problem running tests/derbynet/CompatibilityTest in the old test
@@ -236,6 +239,9 @@
 // current one.
 grant codeBase "${derbyTesting.antjunit}" {
     permission java.lang.RuntimePermission "setIO";
+
+    // This permission is needed when running the tests using ant 1.7
+    permission java.io.FilePermission "${user.dir}${/}*", "write";
 };
 
 // functionTests.tests.lang.RoutineSecurityTest requires this grant

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=632125&r1=632124&r2=632125&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 Thu Feb 28 13:43:25 2008
@@ -72,3 +72,30 @@
   permission java.security.SecurityPermission "getPolicy";
   permission java.lang.RuntimePermission "setIO"; 
 };
+
+grant codeBase "${derbyTesting.junit}" {
+    // This permission is needed when running the tests using ant 1.7
+    permission java.io.FilePermission "${user.dir}${/}*", "write";
+};
+
+// Ant's junit runner requires setOut to redirect the System output streams
+// to the forked JVM used when running junit tests inside Ant. Ant requires
+// forking the JVM if you want to run tests in a different directory than the
+// current one.
+grant codeBase "${derbyTesting.antjunit}" {
+    permission java.lang.RuntimePermission "setIO";
+
+    // This permission is needed when running the tests using ant 1.7
+    permission java.io.FilePermission "${user.dir}${/}*", "write";
+};
+
+// These permissions are needed when testing code instrumented with EMMA.
+// They are all related to writing coverage statistics to a file that by default
+// is named coverage.ec placed in the directory where the test is executed.
+// They will only be used if the emma.active system property property is set,
+// which should be set to "" for the permissions to be correct.
+grant {
+    permission java.util.PropertyPermission "${emma.active}user.dir", "read";
+    permission java.io.FilePermission "${emma.active}${user.dir}${/}coverage.ec", "read, write";
+    permission java.lang.RuntimePermission "${emma.active}writeFileDescriptor";
+};

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=632125&r1=632124&r2=632125&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 Thu Feb 28 13:43:25 2008
@@ -78,6 +78,12 @@
   permission java.security.SecurityPermission "insertProvider.SunJCE";
   permission java.security.SecurityPermission "insertProvider.IBMJCE";
  
+  // These permissions are needed when testing code instrumented with EMMA.
+  // They will only be used if the emma.active system property property is set,
+  // which should be set to "" for the permissions to be correct.
+  permission java.util.PropertyPermission "${emma.active}user.dir", "read";
+  permission java.io.FilePermission "${emma.active}${user.dir}${/}coverage.ec", "read, write";
+  permission java.lang.RuntimePermission "${emma.active}writeFileDescriptor";
 };
 
 //
@@ -157,7 +163,10 @@
   // streams. Currently the nist suite runs with useprocess=false.
   permission java.lang.RuntimePermission "setSecurityManager";
   permission java.security.SecurityPermission "getPolicy";
-  permission java.lang.RuntimePermission "setIO"; 
+  permission java.lang.RuntimePermission "setIO";  
+
+  // These permissions are needed when testing code instrumented with EMMA.
+  permission java.lang.RuntimePermission "${emma.active}writeFileDescriptor";
 };
 
 //
@@ -206,6 +215,14 @@
     permission java.util.PropertyPermission "user.home", "read";
     permission java.io.FilePermission "${user.home}${/}junit.properties", "read";
     permission java.io.FilePermission "${user.home}${/}.junitsession", "write";
+
+    // This permission is needed when running the tests using ant 1.7
+    permission java.io.FilePermission "${user.dir}${/}*", "write";
+  
+    // These permissions are needed when testing code instrumented with EMMA.
+    permission java.util.PropertyPermission "${emma.active}user.dir", "read";
+    permission java.io.FilePermission "${emma.active}${user.dir}${/}coverage.ec", "read, write";
+    permission java.lang.RuntimePermission "${emma.active}writeFileDescriptor";
 };
 
 // Due to a problem running tests/derbynet/CompatibilityTest in the old test
@@ -222,6 +239,14 @@
 // current one.
 grant codeBase "${derbyTesting.antjunit}" {
     permission java.lang.RuntimePermission "setIO";
+
+    // This permission is needed when running the tests using ant 1.7
+    permission java.io.FilePermission "${user.dir}${/}*", "write";
+
+    // These permissions are needed when testing code instrumented with EMMA.
+    permission java.util.PropertyPermission "${emma.active}user.dir", "read";
+    permission java.io.FilePermission "${emma.active}${user.dir}${/}coverage.ec", "read, write";
+    permission java.lang.RuntimePermission "${emma.active}writeFileDescriptor";
 };
 
 // functionTests.tests.lang.RoutineSecurityTest requires this grant
@@ -239,3 +264,12 @@
   permission java.io.FilePermission "${user.dir}${/}extin${/}-", "read";
 };
 
+
+// These permissions are needed when testing code instrumented with EMMA.
+// They are all related to writing coverage statistics to a file that by default
+// is named coverage.ec placed in the directory where the test is executed.
+grant codeBase "${derbyTesting.emma}" {
+    permission java.util.PropertyPermission "user.dir", "read";
+    permission java.io.FilePermission "${user.dir}${/}coverage.ec", "read, write";
+    permission java.lang.RuntimePermission "writeFileDescriptor";
+};

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=632125&r1=632124&r2=632125&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 Thu Feb 28 13:43:25 2008
@@ -257,6 +257,13 @@
         if (antjunit != null)
             classPathSet.setProperty("derbyTesting.antjunit", antjunit.toExternalForm());
 
+        // Load indirectly, normally no EMMA jars in the classpath.
+        // This property is needed to set correct permissions in policy files.
+        URL emma = getURL("com.vladium.emma.EMMAException");
+        if (emma != null) {
+            classPathSet.setProperty("emma.active", "");
+            classPathSet.setProperty("derbyTesting.emma", emma.toExternalForm());
+        }
 		
         /* When inserting XML values that use external DTD's, the JAXP
          * parser needs permission to read the DTD files.  So here we set

Modified: db/derby/code/trunk/tools/ant/properties/extrapath.properties
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/tools/ant/properties/extrapath.properties?rev=632125&r1=632124&r2=632125&view=diff
==============================================================================
--- db/derby/code/trunk/tools/ant/properties/extrapath.properties (original)
+++ db/derby/code/trunk/tools/ant/properties/extrapath.properties Thu Feb 28 13:43:25 2008
@@ -26,6 +26,8 @@
 xalan=${javatools.dir}/xslt4j-2_5_0/xalan.jar
 javacc=${javatools.dir}/javacc.jar
 junit=${javatools.dir}/junit.jar
+emma=${javatools.dir}/emma.jar
+emma_ant=${javatools.dir}/emma_ant.jar
 
 #
 # Compile-time extras