changeset 110:230a711062c1

8008575: Re-integrate code coverage Reviewed-by: attila, hannesw Contributed-by: eugene.drobitko@oracle.com, ilya.dergalin@oracle.com
author lagergren
date Fri, 22 Feb 2013 11:27:40 +0100
parents 678da59a29b3
children 267cc4c85160
files make/build.xml make/code_coverage.xml make/project.properties
diffstat 3 files changed, 160 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/make/build.xml	Fri Feb 22 08:57:22 2013 +0100
+++ b/make/build.xml	Fri Feb 22 11:27:40 2013 +0100
@@ -24,8 +24,13 @@
 <project name="nashorn" default="all" basedir="..">
   <import file="build-nasgen.xml"/>
   <import file="build-benchmark.xml"/>
+  <import file="code_coverage.xml"/>
 
-  <target name="init">
+
+  <target name="init-conditions">
+    <!-- loading locally defined resources and properties. NB they owerwrite default ones defined later -->
+    <property file="${user.home}/.nashorn.project.local.properties"/>
+
     <loadproperties srcFile="make/project.properties"/>
     <path id="nashorn.ext.path">
       <pathelement location="${dist.dir}"/>
@@ -41,6 +46,22 @@
     <available property="asm.available" classname="jdk.internal.org.objectweb.asm.Type"/>
     <!-- check if testng.jar is avaiable -->
     <available property="testng.available" file="${file.reference.testng.jar}"/>
+
+	<!-- enable/disable make code coverage -->
+	<condition property="cc.enabled">
+		<istrue value="${make.code.coverage}" />
+	</condition>
+  </target>
+
+  <target name="init" depends="init-conditions, init-cc">
+
+	<!-- extends jvm args -->
+	<property name="run.test.jvmargs">${run.test.jvmargs.main}  ${run.test.cc.jvmargs}</property>
+	<property name="run.test.jvmargs.octane" value="${run.test.jvmargs.octane.main}  ${run.test.cc.jvmargs}" />
+
+    <echo message="run.test.jvmargs=${run.test.jvmargs}"/>
+    <echo message="run.test.jvmargs.octane=${run.test.jvmargs.octane}"/>
+
   </target>
 
   <target name="prepare" depends="init">
@@ -52,7 +73,7 @@
     <mkdir dir="${dist.javadoc.dir}"/>
   </target>
 
-  <target name="clean" depends="init, clean-nasgen">
+  <target name="clean" depends="init, clean-nasgen, init-cc-cleanup">
     <delete includeemptydirs="true">
       <fileset dir="${build.dir}" erroronmissingdir="false"/>
     </delete>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make/code_coverage.xml	Fri Feb 22 11:27:40 2013 +0100
@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ 
+ This code is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License version 2 only, as
+ published by the Free Software Foundation.
+ 
+ This code 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
+ version 2 for more details (a copy is included in the LICENSE file that
+ accompanied this code).
+ 
+ You should have received a copy of the GNU General Public License version
+ 2 along with this work; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ 
+ Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ or visit www.oracle.com if you need additional information or have any
+ questions.
+-->
+<project name="code-coverage" default="generate-code-coverage-report" basedir="..">
+
+  <!-- CODE COVERAGE -->
+  <target name="init-cc-enabled" if="${cc.enabled}">
+
+    <echo message="initialize [${jcov}] java coverage"/>
+
+
+    <property name="cc.report.dir" value="${cc.dir}/CC_${jcov}_report"/>
+    <property name="cc.merged.xml" value="${cc.dir}/CC_${jcov}_result-merged.xml"/>
+
+    <condition property="run.test.cc.jvmargs" value="${cc.dynamic.args}">
+      <equals arg1="${jcov}" arg2="dynamic" trim="true"/>
+    </condition>
+
+    <mkdir dir="${cc.dir}"/>
+
+    <!-- info -->
+    <echo message="jcov=${jcov}"/>
+    <echo message="cc.generate.template=${cc.generate.template}"/>
+    <echo message="cc.instrument=${cc.instrument}"/>
+    <echo message="run.test.cc.jvmargs=${run.test.cc.jvmargs}"/>
+    <echo message="cc.report.dir=${cc.report.dir}"/>
+    <echo message="cc.merged.xml=${cc.merged.xml}"/>
+  </target>
+
+  <target name="init-cc-disabled" unless="${cc.enabled}">
+    <property name="run.test.cc.jvmargs" value=""/>
+  </target>
+
+  <target name="init-cc" depends="init-cc-disabled, init-cc-enabled">
+    <property name="run.test.cc.jvmargs" value=""/>
+  </target>
+
+  <target name="init-cc-cleanup" if="${cc.enabled}">
+    <delete dir="${cc.dir}" failonerror="false" />
+  </target>
+
+  <target name="check-merging-files" depends="init">
+	<resourcecount property="cc.xmls">
+  		<filelist dir="${cc.dir}" files="*.xml" />
+	</resourcecount>	
+    <condition property="nothing-to-merge" value="true">
+      <equals arg1="${cc.xmls}" arg2="1" trim="true"/>
+    </condition>
+  </target>
+
+  <target name="fix-merging-files" depends="check-merging-files" if="${nothing-to-merge}">
+	<echo message="making pre-merge workaround"/>
+	<move todir="${cc.dir}" includeemptydirs="false">
+		<fileset dir="${cc.dir}">
+			<include name="*.xml"/>
+		</fileset>
+		<mapper type="glob" from="*.xml" to="CC_${jcov}_result-merged.xml"/>
+	</move>
+  </target>
+ 
+  <target name="merge-code-coverage" depends="fix-merging-files" unless="${nothing-to-merge}">
+	<echo message="merging files"/>
+    <fileset dir="${cc.dir}" id="cc.xmls">
+      <include name="**/*${jcov}*.xml"/>
+      <include name="**/CC_template.xml"/>
+    </fileset>
+
+    <pathconvert pathsep=" " property="cc.all.xmls" refid="cc.xmls"/>
+
+    <java classname="com.sun.tdk.jcov.Merger">
+      <arg value="-verbose"/>
+      <arg value="-output"/>
+      <arg value="${cc.merged.xml}"/>
+      <arg value="-exclude"/>
+      <arg value="com\.oracle\.nashorn\.runtime\.ScriptRuntime*"/>
+      <arg line="${cc.all.xmls}"/>
+      <classpath>
+        <pathelement location="${jcov.jar}"/>
+      </classpath>
+    </java>
+
+  </target>
+
+  <target name="generate-code-coverage-report" depends="merge-code-coverage">
+    <java classname="com.sun.tdk.jcov.RepGen">
+      <arg value="-verbose"/>
+<!--      <arg line ="-exclude_list CC.report.exclude"/> -->
+      <arg line="-output ${cc.report.dir}"/>
+      <arg value="${cc.merged.xml}"/>
+      <classpath>
+        <pathelement location="${jcov.jar}"/>
+      </classpath>
+    </java>
+  </target>
+
+
+</project>
--- a/make/project.properties	Fri Feb 22 08:57:22 2013 +0100
+++ b/make/project.properties	Fri Feb 22 11:27:40 2013 +0100
@@ -208,9 +208,9 @@
 
 #  -XX:+PrintCompilation -XX:+UnlockDiagnosticVMOptions -XX:+PrintNMethods
 # add '-Dtest.js.outofprocess' to run each test in a new sub-process
-run.test.jvmargs=-server -Xmx${run.test.xmx} -XX:-TieredCompilation -esa -ea -Dnashorn.debug=true -Dfile.encoding=UTF-8 
+run.test.jvmargs.main=-server -Xmx${run.test.xmx} -XX:-TieredCompilation -esa -ea -Dnashorn.debug=true -Dfile.encoding=UTF-8
 #-XX:+HeapDumpOnOutOfMemoryError -XX:-UseCompressedKlassPointers -XX:+PrintHeapAtGC -XX:ClassMetaspaceSize=300M  
-run.test.jvmargs.octane=-Xms${run.test.xms} ${run.test.jvmargs}
+run.test.jvmargs.octane.main=-Xms${run.test.xms} ${run.test.jvmargs}
 
 run.test.jvmsecurityargs=-Xverify:all -Djava.security.properties=${basedir}/make/java.security.override -Djava.security.manager -Djava.security.policy=${basedir}/build/nashorn.policy
 
@@ -224,3 +224,21 @@
 
 #timeout for performance tests in minutes
 octaneperf-sys-prop.timeout.value=10
+
+################
+# codecoverage #
+################
+	#enable/disable code coverage; please redifine in the ${user.home}/.nashorn.project.local.properties
+make.code.coverage=false
+	#type of codecoverage; one of static or dynamic. Now only dynamic is supported
+jcov=dynamic
+	#naming of CC results
+	#NB directory specified in the cc.dir will be cleaned up!!!
+cc.dir=${basedir}/../Codecoverage_Nashorn
+cc.result.file.name=cc_nashorn.xml
+	#dynamic CC parameters; please redefine in the ${user.home}/.nashorn.project.local.properties
+jcov2.lib.dir=${basedir}/../jcov2/lib
+jcov.jar=${jcov2.lib.dir}/jcov.jar
+cc.include=jdk\.nashorn\.*
+cc.exclude=jdk\.nashorn\.internal\.scripts\.*
+cc.dynamic.args=-javaagent:${jcov.jar}=include=${cc.include},exclude=${cc.exclude},type=all,verbose=0,file=${cc.dir}/${cc.result.file.name}