]> granicus.if.org Git - php/commitdiff
Implementing C-level Code coverage (--enable-gcov).
authorJohn Coggeshall <john@php.net>
Thu, 20 Oct 2005 00:18:23 +0000 (00:18 +0000)
committerJohn Coggeshall <john@php.net>
Thu, 20 Oct 2005 00:18:23 +0000 (00:18 +0000)
  o Requires LTP 1.4+ and libgcov

Makefile.gcov [new file with mode: 0644]
NEWS
configure.in
gen_php_cov [new file with mode: 0755]

diff --git a/Makefile.gcov b/Makefile.gcov
new file mode 100644 (file)
index 0000000..80ce36d
--- /dev/null
@@ -0,0 +1,18 @@
+
+.php_cov_info.ltpdata:
+       @mkdir -p .cov/; \
+       find . -name \*.gcda -o -name \*.gcno | sed -e 's/^\.\/\.cov\/.*//' | xargs --replace cp {} .cov/; \
+       find . -name \*.gcda -o -name \*.gcno | sed -e 's/^\.\/\.cov\/.*//' | sed -e 's/^\.\///' | xargs --max-args=1 dirname | sed -e 's/\/.*//' | xargs --replace ln -s `pwd`/{} `pwd`/.cov > /dev/null 2>&1; \
+       $(LTP) --directory .cov --output-file=.php_cov_info.ltpdata --capture; \
+
+cov: .php_cov_info.ltpdata
+
+cov-html: cov 
+       @$(LTP_GENHTML) -o cov_html/ .php_cov_info.ltpdata -t "PHP Code Coverage" -s;
+
+cov-clean:
+       find . -name \*.gcda -o -name \*.gcno -exec rm -f {} \;
+       rm -f .cov/*      # This is done first, since we are symlinked inside..
+       rm -Rf .cov       # Now remove the directory
+       rm -f .php_cov_info.ltpdata
+       rm -Rf cov_html
diff --git a/NEWS b/NEWS
index 788911f11d1fab233a20eae46cd083af993f02d3..aadfa438db21136d545cc5b9834f7a0e60a1d9a1 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? ????, PHP 6.0
+- C-level Code Coverage Instrumenting (John)
 - Unicode support. (Andrei, Dmitriy, et al)
 - Changed type hints so that they take "= NULL" as default value. (Marcus,
   Derick)
index 96cd90ba8a637da53d08273afe019d81e257b462..55daba0e0927eca7455444e6acfb228e67e1a13a 100644 (file)
@@ -597,6 +597,57 @@ dnl -------------------------------------------------------------------------
 PHP_CONFIGURE_PART(General settings)
 
 PHP_HELP_SEPARATOR([General settings:])
+PHP_ARG_ENABLE(gcov,  whether to include gcov symbols,
+[  --enable-gcov           Enable GCOV code coverage (requires LTP)], no, no)
+
+if test "$PHP_GCOV" = "yes"; then
+  AC_DEFUN([PHP_PROG_LTP],[
+
+    ltp_version_list="1.4"
+
+    AC_CHECK_PROG(LTP, lcov, lcov)
+    AC_CHECK_PROG(LTP_GENHTML, genhtml, genhtml)
+    if test "$LTP"; then
+      AC_CACHE_CHECK([for ltp version], php_cv_ltp_version, [
+        php_cv_ltp_version=invalid
+        ltp_version=`$LTP -v 2>/dev/null | $SED -e 's/^.* //'`
+        for ltp_check_version in $ltp_version_list; do
+          if test "$ltp_version" = "$ltp_check_version"; then
+            php_cv_ltp_version="$ltp_check_version (ok)"
+          fi
+        done
+      ])
+    else
+      ltp_msg="To enable code coverage reporting you must have one of the following LTP versions installed: $ltp_version_list"      
+      AC_MSG_ERROR([$ltp_msg])
+    fi
+
+    case $php_cv_ltp_version in
+      ""|invalid[)]
+        ltp_msg="You must have one of the following versions of LTP: $ltp_version_list (found: $ltp_version)."
+        AC_MSG_ERROR([$ltp_msg])
+        LTP="exit 0;"
+        ;;
+    esac
+
+    if test "$LTP_GENHTML" = ""; then
+       AC_MSG_ERROR([Could not find genhtml from the LTP package])
+    fi
+
+    PHP_SUBST(LTP)
+    PHP_SUBST(LTP_GENHTML)
+  ])
+
+  PHP_PROG_LTP
+  AC_CHECK_LIB(gcov, __gcov_open, [
+    PHP_ADD_LIBRARY(gcov)
+    AC_DEFINE(HAVE_GCOV, 1, [Whether you have gcov])
+    CFLAGS="$CFLAGS -O0 -fprofile-arcs -ftest-coverage"
+    PHP_ADD_MAKEFILE_FRAGMENT($abs_srcdir/Makefile.gcov,$abs_srcdir)
+  ], [
+    AC_MSG_ERROR([Problem with enabling gcov. Please check config.log for details.])
+  ])
+fi
 
 PHP_ARG_ENABLE(debug, whether to include debugging symbols,
 [  --enable-debug          Compile with debugging symbols], no, no)
diff --git a/gen_php_cov b/gen_php_cov
new file mode 100755 (executable)
index 0000000..7dcef6f
--- /dev/null
@@ -0,0 +1,70 @@
+#!/bin/sh
+
+cov_gen_clean()
+{
+   echo "Cleaning up stale gcov data"
+   find . -name \*.gcda -o -name \*.gcno | xargs rm -f
+   make cov-clean > /dev/null
+}
+
+cov_gen_check_cli()
+{
+   if test -x $php_version; then
+      check_gcov=`nm $php_version | grep '__gcov_open' | wc -l`
+      if test "$check_gcov" != "1"; then
+          echo "PHP CLI Found ($php_version) does not appear to have GCOV enabled"
+          echo "Please recompile with --enable-gcov or set PHP_EXEC"
+          exit 1
+      fi
+      echo "GCOV support in PHP confirmed"
+   else
+      echo "Could not find PHP binary (using $php_version)"
+      echo "Please compile the CLI version of PHP using the --enable-gcov flag"
+      exit 1
+   fi
+}
+
+cov_gen_usage()
+{
+    echo "$0 --[help] <cli executable>";
+}
+
+cov_gen_generate()
+{
+   echo "Confirming GCOV is available in PHP"
+   cov_gen_check_cli
+   cov_gen_clean
+   export NO_INTERACTION=1
+   export TEST_PHP_EXECUTABLE="$php_version"
+
+   echo "Running Test Suite (this is going to take awhile)"
+
+   $php_version -c ./php.ini-test run-tests.php > /dev/null
+   echo "Performing Code Coverage Analysis"
+   make cov > /dev/null
+   echo "Generating HTML report of Analysis"
+   make cov-html > /dev/null
+}
+
+while test $# != 0; do
+   case "$1" in
+      --help)
+        cov_gen_usage
+        exit 0
+        ;;
+      *)
+        if test -x $1; then
+            echo "Using PHP executable $1"
+            php_version="$1"
+            cov_gen_generate
+           exit 0
+        fi 
+        ;;
+    esac
+    shift
+done
+
+echo "Using Default Location for PHP executable"
+php_version="sapi/cli/php"
+cov_gen_generate
+exit 0