summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorSean Finney <seanius@debian.org>2009-04-10 14:09:48 +0200
committerSean Finney <seanius@debian.org>2009-04-10 14:09:48 +0200
commitcd0b49c72aee33b3e44a9c589fcd93b9e1c7a64f (patch)
tree1315c623bb7d9dfa8d366fa9cd2c6834ceeb5da5 /scripts
parent9ea47aab740772adf0c69d8c94b208a464e599ea (diff)
downloadphp-cd0b49c72aee33b3e44a9c589fcd93b9e1c7a64f.tar.gz
Imported Upstream version 5.2.9.dfsg.1upstream/5.2.9.dfsg.1
Diffstat (limited to 'scripts')
-rw-r--r--scripts/dev/find_tested.php222
-rw-r--r--scripts/phpize.m481
2 files changed, 297 insertions, 6 deletions
diff --git a/scripts/dev/find_tested.php b/scripts/dev/find_tested.php
new file mode 100644
index 000000000..f95c46251
--- /dev/null
+++ b/scripts/dev/find_tested.php
@@ -0,0 +1,222 @@
+<?php
+
+
+$usage = <<<USAGE
+
+Usage: php find_tested.php [path_to_test_files] ([extension])
+
+Outputs test coverage information for functions and methods in csv format.
+Supplying an optional extension name outputs only information for functions and methods from that extension.
+
+Output format:
+Extension, Class Name, Method/Function Name, Test Status, Test Files
+
+A test status of "verify" for a method means that there is at least one other method of the same name, so test coverage must be verified manually.
+
+USAGE;
+
+
+/* method record fields */
+define("CLASS_NAME", "CLASS_NAME");
+define("METHOD_NAME", "METHOD_NAME");
+define("EXTENSION_NAME", "EXTENSION_NAME");
+define("IS_DUPLICATE", "IS_DUPLICATE");
+define("IS_TESTED", "IS_TESTED");
+define("TESTS", "TESTS");
+
+
+// process command line args
+$num_params = $argc;
+if ($num_params < 2 || $num_params > 3) {
+ die($usage);
+}
+
+$extension_test_path = $argv[1];
+
+if ($num_params == 3) {
+ $extension_name = $argv[2];
+
+ // check extension exists
+ $extensions = get_loaded_extensions();
+ if (!in_array($extension_name, $extensions)) {
+ echo "Error: extension $extension_name is not loaded. Loaded extensions:\n";
+ foreach($extensions as $extension) {
+ echo "$extension\n";
+ }
+ die();
+ }
+} else {
+ $extension_name = false;
+}
+
+
+$method_info = populate_method_info();
+
+if ($extension_name != false) {
+ // get only the methods from the extension we are querying
+ $extension_method_info = array();
+ foreach($method_info as $method_record) {
+ if (strcasecmp($extension_name, $method_record[EXTENSION_NAME]) == 0) {
+ $extension_method_info[] = $method_record;
+ }
+ }
+} else {
+ $extension_method_info = $method_info;
+}
+
+get_phpt_files($extension_test_path, $count, $phpt_files);
+
+$extension_method_info = mark_methods_as_tested($extension_method_info, $phpt_files);
+
+
+foreach($extension_method_info as $record) {
+ echo $record[EXTENSION_NAME] . ",";
+ echo $record[CLASS_NAME] . ",";
+ echo $record[METHOD_NAME] . ",";
+ echo $record[IS_TESTED] . ",";
+ echo $record[TESTS] . "\n";
+}
+
+/**
+ * Marks the "tested" status of methods in $method_info according
+ * to whether they are tested in $phpt_files
+ */
+function mark_methods_as_tested($method_info, $phpt_files) {
+
+ foreach($phpt_files as $phpt_file) {
+ $tested_functions = extract_tests($phpt_file);
+
+ foreach($tested_functions as $tested_function) {
+
+ // go through method info array marking this funtion as tested
+ foreach($method_info as &$current_method_record) {
+ if (strcasecmp($tested_function, $current_method_record[METHOD_NAME]) == 0) {
+ // matched the method name
+ if ($current_method_record[IS_DUPLICATE] == true) {
+ // we cannot be sure which class this method corresponds to,
+ // so mark method as needing to be verified
+ $current_method_record[IS_TESTED] = "verify";
+ } else {
+ $current_method_record[IS_TESTED] = "yes";
+ }
+ $current_method_record[TESTS] .= $phpt_file . "; ";
+ }
+ }
+ }
+ }
+ return $method_info;
+}
+
+/**
+ * returns an array containing a record for each defined method.
+ */
+function populate_method_info() {
+
+ $method_info = array();
+
+ // get functions
+ $all_functions = get_defined_functions();
+ $internal_functions = $all_functions["internal"];
+
+ foreach ($internal_functions as $function) {
+ // populate new method record
+ $function_record = array();
+ $function_record[CLASS_NAME] = "Function";
+ $function_record[METHOD_NAME] = $function;
+ $function_record[IS_TESTED] = "no";
+ $function_record[TESTS] = "";
+ $function_record[IS_DUPLICATE] = false;
+
+ // record the extension that the function belongs to
+ $reflectionFunction = new ReflectionFunction($function);
+ $extension = $reflectionFunction->getExtension();
+ if ($extension != null) {
+ $function_record[EXTENSION_NAME] = $extension->getName();
+ } else {
+ $function_record[EXTENSION_NAME] = "";
+ }
+ // insert new method record into info array
+ $method_info[] = $function_record;
+ }
+
+ // get methods
+ $all_classes = get_declared_classes();
+ foreach ($all_classes as $class) {
+ $reflectionClass = new ReflectionClass($class);
+ $methods = $reflectionClass->getMethods();
+ foreach ($methods as $method) {
+ // populate new method record
+ $new_method_record = array();
+ $new_method_record[CLASS_NAME] = $reflectionClass->getName();
+ $new_method_record[METHOD_NAME] = $method->getName();
+ $new_method_record[IS_TESTED] = "no";
+ $new_method_record[TESTS] = "";
+
+ $extension = $reflectionClass->getExtension();
+ if ($extension != null) {
+ $new_method_record[EXTENSION_NAME] = $extension->getName();
+ } else {
+ $new_method_record[EXTENSION_NAME] = "";
+ }
+
+ // check for duplicate method names
+ $new_method_record[IS_DUPLICATE] = false;
+ foreach ($method_info as &$current_record) {
+ if (strcmp($current_record[METHOD_NAME], $new_method_record[METHOD_NAME]) == 0) {
+ $new_method_record[IS_DUPLICATE] = true;
+ $current_record[IS_DUPLICATE] = true;
+ }
+ }
+ // insert new method record into info array
+ $method_info[] = $new_method_record;
+ }
+ }
+
+ return $method_info;
+}
+
+function get_phpt_files($dir, &$phpt_file_count, &$all_phpt)
+{
+ $thisdir = dir($dir.'/'); //include the trailing slash
+ while(($file = $thisdir->read()) !== false) {
+ if ($file != '.' && $file != '..') {
+ $path = $thisdir->path.$file;
+ if(is_dir($path) == true) {
+ get_phpt_files($path , $phpt_file_count , $all_phpt);
+ } else {
+ if (preg_match("/\w+\.phpt$/", $file)) {
+ $all_phpt[$phpt_file_count] = $path;
+ $phpt_file_count++;
+ }
+ }
+ }
+ }
+}
+
+function extract_tests($file) {
+ $code = file_get_contents($file);
+
+ if (!preg_match('/--FILE--\s*(.*)\s*--(EXPECTF|EXPECTREGEX|EXPECT)?--/is', $code, $r)) {
+// print "Unable to get code in ".$file."\n";
+ return array();
+ }
+
+ $tokens = token_get_all($r[1]);
+ $functions = array_filter($tokens, 'filter_functions');
+ $functions = array_map( 'map_token_value',$functions);
+ $functions = array_unique($functions);
+
+ return $functions;
+}
+
+function filter_functions($x) {
+ return $x[0] == 307;
+}
+
+function map_token_value($x) {
+ return $x[1];
+}
+
+
+?>
+
diff --git a/scripts/phpize.m4 b/scripts/phpize.m4
index c8a810294..ba668c889 100644
--- a/scripts/phpize.m4
+++ b/scripts/phpize.m4
@@ -21,6 +21,7 @@ abs_srcdir=`(cd $srcdir && pwd)`
abs_builddir=`pwd`
AC_PROG_CC
+PHP_DETECT_ICC
AC_PROG_CC_C_O
dnl Support systems with system libraries in e.g. /usr/lib64
@@ -58,25 +59,91 @@ AC_MSG_RESULT([$EXTENSION_DIR])
AC_MSG_CHECKING([for PHP installed headers prefix])
AC_MSG_RESULT([$phpincludedir])
+dnl Checks for PHP_DEBUG / ZEND_DEBUG / ZTS
+AC_MSG_CHECKING([if debug is enabled])
+old_CPPFLAGS=$CPPFLAGS
+CPPFLAGS="-I$phpincludedir"
+AC_EGREP_CPP(php_debug_is_enabled,[
+#include <main/php_config.h>
+#if ZEND_DEBUG
+php_debug_is_enabled
+#endif
+],[
+ PHP_DEBUG=yes
+],[
+ PHP_DEBUG=no
+])
+AC_MSG_RESULT([$PHP_DEBUG])
+
+AC_MSG_CHECKING([if zts is enabled])
+old_CPPFLAGS=$CPPFLAGS
+CPPFLAGS="-I$phpincludedir"
+AC_EGREP_CPP(php_zts_is_enabled,[
+#include <main/php_config.h>
+#if ZTS
+php_zts_is_enabled
+#endif
+],[
+ PHP_THREAD_SAFETY=yes
+],[
+ PHP_THREAD_SAFETY=no
+])
+CPPFLAGS=$old_CPPFLAGS
+AC_MSG_RESULT([$PHP_DEBUG])
+
+dnl Support for building and testing Zend extensions
+if test "$PHP_DEBUG" = "yes" && test "$PHP_THREAD_SAFETY" = "yes; then
+ ZEND_EXT_TYPE="zend_extension_debug_ts"
+elif test "$PHP_DEBUG" = "yes"; then
+ ZEND_EXT_TYPE="zend_extension_debug"
+elif test "$PHP_THREAD_SAFETY" = "yes; then
+ ZEND_EXT_TYPE="zend_extension_ts"
+else
+ ZEND_EXT_TYPE="zend_extension"
+fi
+PHP_SUBST(ZEND_EXT_TYPE)
+
+dnl Discard optimization flags when debugging is enabled
+if test "$PHP_DEBUG" = "yes"; then
+ PHP_DEBUG=1
+ ZEND_DEBUG=yes
+ changequote({,})
+ CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9s]*//g'`
+ CXXFLAGS=`echo "$CXXFLAGS" | $SED -e 's/-O[0-9s]*//g'`
+ changequote([,])
+ dnl add -O0 only if GCC or ICC is used
+ if test "$GCC" = "yes" || test "$ICC" = "yes"; then
+ CFLAGS="$CFLAGS -O0"
+ CXXFLAGS="$CXXFLAGS -O0"
+ fi
+else
+ PHP_DEBUG=0
+ ZEND_DEBUG=no
+fi
+
dnl Always shared
PHP_BUILD_SHARED
dnl Required programs
PHP_PROG_RE2C
PHP_PROG_AWK
-
+
sinclude(config.m4)
enable_static=no
enable_shared=yes
-dnl Only allow AC_PROG_CXX if it's explicitly called (by PHP_REQUIRE_CXX)
-dnl otherwise AC_PROG_LIBTOOL fails if there is no working C++ compiler
-AC_PROVIDE_IFELSE([PHP_REQUIRE_CXX], [AC_PROG_CXX], [undefine([AC_PROG_CXX])
-AC_DEFUN([AC_PROG_CXX], [])])
+dnl Only allow AC_PROG_CXX and AC_PROG_CXXCPP if they are explicitly called (by PHP_REQUIRE_CXX).
+dnl Otherwise AC_PROG_LIBTOOL fails if there is no working C++ compiler.
+AC_PROVIDE_IFELSE([PHP_REQUIRE_CXX], [], [
+ undefine([AC_PROG_CXX])
+ AC_DEFUN([AC_PROG_CXX], [])
+ undefine([AC_PROG_CXXCPP])
+ AC_DEFUN([AC_PROG_CXXCPP], [php_prog_cxxcpp=disabled])
+])
AC_PROG_LIBTOOL
-all_targets='$(PHP_MODULES)'
+all_targets='$(PHP_MODULES) $(PHP_ZEND_EX)'
install_targets="install-modules install-headers"
phplibdir="`pwd`/modules"
CPPFLAGS="$CPPFLAGS -DHAVE_CONFIG_H"
@@ -87,6 +154,8 @@ test "$prefix" = "NONE" && prefix="/usr/local"
test "$exec_prefix" = "NONE" && exec_prefix='$(prefix)'
PHP_SUBST(PHP_MODULES)
+PHP_SUBST(PHP_ZEND_EX)
+
PHP_SUBST(all_targets)
PHP_SUBST(install_targets)