Repository: zookeeper Updated Branches: refs/heads/branch-3.5 82f17bb94 -> 02413d4ef
ZOOKEEPER-2968: Add C client code coverage tests ZOOKEEPER-2968: Add C client code coverage tests This PR adds a new ant target 'c_coverage_report' which generates coverage report for the ZK C client. The report is generated to build/c_coverage/report in html format. As a requirement, lcov has to be installed prior to running target 'c_coverage_report'. An additional check was added to 'check-cppunit-makefile' to ensure that the Makefile gets deleted and regenerated without the coverage compiler flags when running targets without --enable-gcov. Author: Mark Fenes <[email protected]> Reviewers: [email protected] Closes #467 from mfenes/ZOOKEEPER-2968 and squashes the following commits: d8757821a [Mark Fenes] ZOOKEEPER-2968: Add C client code coverage tests 3c9022622 [Mark Fenes] ZOOKEEPER-2968: Add C client code coverage tests Change-Id: Id4bd05afbff2447c593427eff5f133c3d88048d3 (cherry picked from commit a35690cd60c1d5010454056b7011e3abbbbe9116) Signed-off-by: Patrick Hunt <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/zookeeper/repo Commit: http://git-wip-us.apache.org/repos/asf/zookeeper/commit/02413d4e Tree: http://git-wip-us.apache.org/repos/asf/zookeeper/tree/02413d4e Diff: http://git-wip-us.apache.org/repos/asf/zookeeper/diff/02413d4e Branch: refs/heads/branch-3.5 Commit: 02413d4eff5463352be1877dfd8497a604a900ed Parents: 82f17bb Author: Mark Fenes <[email protected]> Authored: Thu May 31 12:57:21 2018 -0700 Committer: Patrick Hunt <[email protected]> Committed: Thu May 31 12:57:54 2018 -0700 ---------------------------------------------------------------------- build.xml | 55 ++++++++++++++++++++++++++++++++++++++++++++++++- src/c/Makefile.am | 6 ++++++ src/c/configure.ac | 6 ++++++ 3 files changed, 66 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zookeeper/blob/02413d4e/build.xml ---------------------------------------------------------------------- diff --git a/build.xml b/build.xml index 83c2956..f595b42 100644 --- a/build.xml +++ b/build.xml @@ -511,11 +511,15 @@ xmlns:cs="antlib:com.puppycrawl.tools.checkstyle.ant"> <env key="ACLOCAL" value="aclocal -I ${cppunit.m4}"/> </exec> <mkdir dir="${build.dir}/c" /> + <condition property="enable.gcov.arg" value="--enable-gcov" else=""> + <equals arg1="${enable.gcov}" arg2="true"/> + </condition> <exec executable="${c.src.dir}/configure" dir="${build.dir}/c" failonerror="yes"> <env key="base_dir" value="${basedir}"/> <env key="CALLER" value="ANT"/> <arg value="--prefix=${build.dir}/c/build/${package.prefix}"/> + <arg line="${enable.gcov.arg}"/> </exec> <property name="c.build" value="${build.dir}/c/build"/> <exec dir="${build.dir}/c" executable="make" failonerror="true"> @@ -1332,7 +1336,29 @@ xmlns:cs="antlib:com.puppycrawl.tools.checkstyle.ant"> </condition> </target> - <target name="check-cppunit-makefile" depends="init" > + <target name="verify-cppunit-makefile-gcov"> + <fileset id="fileset.makefile.gcov.enabled" dir="${test.cppunit.dir}" erroronmissingdir="false"> + <include name="Makefile"/> + <containsregexp expression="^[^#]+-ftest-coverage.*$"/> + </fileset> + <condition property="makefile.gcov.enabled"> + <resourcecount when="greater" count="0" refid="fileset.makefile.gcov.enabled"/> + </condition> + <echo message="makefile.gcov.enabled = ${makefile.gcov.enabled}"/> + <condition property="delete.cppunit.makefile"> + <and> + <isset property="makefile.gcov.enabled"/> + <not><equals arg1="${enable.gcov}" arg2="true"/></not> + </and> + </condition> + <echo message="delete.cppunit.makefile = ${delete.cppunit.makefile}"/> + </target> + + <target name="delete-cppunit-makefile" if="delete.cppunit.makefile"> + <delete file="${test.cppunit.dir}/Makefile"/> + </target> + + <target name="check-cppunit-makefile" depends="init,verify-cppunit-makefile-gcov,delete-cppunit-makefile" > <condition property="need.cppunit.makefile"> <not> <available file="${test.cppunit.dir}/Makefile"/> </not> </condition> @@ -1362,11 +1388,15 @@ xmlns:cs="antlib:com.puppycrawl.tools.checkstyle.ant"> <param name="cppunit" value="true"/> </antcall> <mkdir dir="${test.cppunit.dir}"/> + <condition property="enable.gcov.arg" value="--enable-gcov" else=""> + <equals arg1="${enable.gcov}" arg2="true"/> + </condition> <exec executable="${c.src.dir}/configure" dir="${test.cppunit.dir}" failonerror="yes"> <env key="base_dir" value="${basedir}"/> <env key="CALLER" value="ANT"/> <arg value="--prefix=${test.cppunit.dir}"/> + <arg line="${enable.gcov.arg}"/> </exec> </target> @@ -1485,6 +1515,29 @@ xmlns:cs="antlib:com.puppycrawl.tools.checkstyle.ant"> </clover-report> </target> + <target name="c_coverage_report" description="Runs coverage report for ZK C client code."> + <!-- delete configure and make files so that they get regenerated with coverage enabled --> + <delete file="${c.src.dir}/configure"/> + <delete file="${test.cppunit.dir}/Makefile"/> + <subant target="test-core-cppunit" failonerror="false"> + <property name="enable.gcov" value="true"/> + <fileset dir="." file="build.xml"/> + </subant> + <mkdir dir="${build.dir}/c_coverage" /> + <copy todir="${build.dir}/c" verbose="true" overwrite="true" failonerror="true"> + <fileset dir="${build.dir}/test/test-cppunit/.libs"> + <include name="*.gcno"/> + <include name="*.gcda"/> + </fileset> + </copy> + <exec dir="${build.dir}/c" executable="lcov"> + <arg line="-t testname -o ZK_C_client.info -c -d ."/> + </exec> + <exec dir="${build.dir}/c_coverage" executable="genhtml"> + <arg line="-o report ${build.dir}/c/ZK_C_client.info"/> + </exec> + </target> + <!-- Run with 'ant -Dfindbugs.home="path to Findbugs directory" findbugs --> <property name="findbugs.home" value="" /> <target name="findbugs" depends="check-for-findbugs, jar" if="findbugs.present"> http://git-wip-us.apache.org/repos/asf/zookeeper/blob/02413d4e/src/c/Makefile.am ---------------------------------------------------------------------- diff --git a/src/c/Makefile.am b/src/c/Makefile.am index b956b92..4b4c61a 100644 --- a/src/c/Makefile.am +++ b/src/c/Makefile.am @@ -10,6 +10,12 @@ AM_CPPFLAGS = -I${srcdir}/include -I${srcdir}/tests -I${srcdir}/generated $(SOLA AM_CFLAGS = -Wall -Werror -Wdeclaration-after-statement AM_CXXFLAGS = -Wall $(USEIPV6) +# Additional flags for coverage testing (if enabled) +if ENABLEGCOV + AM_CFLAGS += -fprofile-arcs -ftest-coverage + AM_LDFLAGS = -lgcov +endif + LIB_LDFLAGS = -no-undefined -version-info 2 $(SOLARIS_LIB_LDFLAGS) pkginclude_HEADERS = include/zookeeper.h include/zookeeper_version.h include/zookeeper_log.h include/proto.h include/recordio.h generated/zookeeper.jute.h http://git-wip-us.apache.org/repos/asf/zookeeper/blob/02413d4e/src/c/configure.ac ---------------------------------------------------------------------- diff --git a/src/c/configure.ac b/src/c/configure.ac index bb15c54..0a6ea1a 100644 --- a/src/c/configure.ac +++ b/src/c/configure.ac @@ -86,6 +86,12 @@ else fi fi +# Check whether to enable gcov (coverage test) +AC_ARG_ENABLE(gcov, [AS_HELP_STRING([--enable-gcov],[enable coverage test])]) +AC_MSG_CHECKING([whether to enable gcov]) +AS_IF([test "x${enable_gcov}" = "xyes"],AC_MSG_RESULT([yes]),AC_MSG_RESULT([no])) +AM_CONDITIONAL([ENABLEGCOV],[test "x${enable_gcov}" = "xyes"]) + AC_ARG_WITH([syncapi], [AS_HELP_STRING([--with-syncapi],[build with support for SyncAPI [default=yes]])], [],[with_syncapi=yes])
