List:Commits« Previous MessageNext Message »
From:uwendel Date:August 29 2007 4:46pm
Subject:PHP mysqlnd svn commit: r961 - trunk/tests/ext/mysqli
View as plain text  
Author: uwendel
Date: 2007-08-29 18:46:10 +0200 (Wed, 29 Aug 2007)
New Revision: 961

Added:
   trunk/tests/ext/mysqli/mysqli_debug_mysqlnd_control_string.phpt
Log:
Testing control string options supported by mysqlnd. 
Two issues with mysqlnd:

 'n' clashes with libmysql and has a different meaning in mysqlnd
 'L' does not only print the line number but the file name as well
 


Added: trunk/tests/ext/mysqli/mysqli_debug_mysqlnd_control_string.phpt
===================================================================
--- trunk/tests/ext/mysqli/mysqli_debug_mysqlnd_control_string.phpt	2007-08-29 15:55:50
UTC (rev 960)
+++ trunk/tests/ext/mysqli/mysqli_debug_mysqlnd_control_string.phpt	2007-08-29 16:46:10
UTC (rev 961)
@@ -0,0 +1,96 @@
+--TEST--
+mysqli_debug() - control string options supported by both mysqlnd and libmysql
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifemb.inc');
+
+if (!function_exists('mysqli_debug'))
+ 	die("skip: mysqli_debug() not available");
+?>
+--FILE--
+<?php
+	require_once('connect.inc');;
+	require_once('table.inc');
+
+	function try_control_string($link, $control_string, $trace_file, $offset) {
+
+		@unlink($trace_file);
+		if (true !== ($tmp = @mysqli_debug($control_string))) {
+			printf("[%03d][control string '%s'] Expecting boolean/true, got %s/%s.\n",
+				$offset + 1,
+				$control_string,
+				gettype($tmp),
+				$tmp);
+			return false;
+		}
+
+		if (!$res = mysqli_query($link, 'SELECT * FROM test')) {
+			printf("[%03d][control string '%s'] [%d] %s.\n",
+				$offset + 2,
+				$control_string,
+				mysqli_errno($link),
+				mysqli_error($link));
+			return false;
+		}
+
+		clearstatcache();
+		if (!file_exists($trace_file)) {
+			printf("[%03d][control string '%s'] Trace file has not been written.\n",
+				$offset + 3,
+				$control_string,
+				gettype($tmp),
+				$tmp);
+			return false;
+		}
+
+		return trim(substr(file_get_contents($trace_file), 0, 100024));
+	}
+
+	$trace_file = sprintf('%s%s%s', sys_get_temp_dir(), DIRECTORY_SEPARATOR,
'mysqli_debug_phpt.trace');
+
+	$trace = try_control_string($link, ':d:t:O,' . $trace_file, $trace_file, 10);
+	if (!strstr($trace, 'SELECT * FROM test'))
+		printf("[015] SELECT query cannot be found in trace. Trace contents seems wrong.\n");
+
+	// T - gettimeofday() system call, system dependent format
+	// 16:57:03.350734 >mysql_real_query
+	$trace = try_control_string($link, ':d:t:O,' . $trace_file . ':T', $trace_file, 20);
+	if (!preg_match('@^[012]{0,1}[0-9]{1}:[0-5]{0,1}[0-9]{1}:[0-5]{0,1}[0-9]{1}@ismU',
$trace))
+		printf("[025] Timestamp not found. One reason could be that the test is borked and does
not recognize the format of the gettimeofday() system call. Check manually (and fix the
test, if needed :-)). First characters from trace are '%s'\n", substr($trace, 0, 80));
+
+	// i - add PID of the current process
+	// currently PHP is not multi-threaded, so it should be save to test for the PID of this
PHP process
+	if (false === ($pid = getmypid()))
+		$pid = "[\d]+";
+
+	$trace = try_control_string($link, ':d:t:O,' . $trace_file . ':i', $trace_file, 30);
+	if (!preg_match("@^" . $pid . "*@ismU", $trace))
+		printf("[035] Process ID has not been found, first characters from trace are '%s'\n",
substr($trace, 0, 80));
+
+	// L - line numbers
+	$trace = try_control_string($link, ':d:t:O,' . $trace_file . ':L', $trace_file, 40);
+	if (!preg_match("@^[\d]+@ismU", $trace))
+		printf("[045] Line numbers have not been found, first characters from trace are
'%s'\n", substr($trace, 0, 80));
+
+	// F - file name
+	$trace = try_control_string($link, ':d:t:O,' . $trace_file . ':F', $trace_file, 50);
+	// hopefully we'll never see a file name that's not covered by this regular
expression...
+	if (!preg_match("@^\s*[/\w\\\\d]+\.[ch]@ismU", $trace))
+		printf("[055] File names seem to be missing, first characters from trace are '%s'\n",
substr($trace, 0, 80));
+
+	// -n - print function nesting depth
+	$trace = try_control_string($link, ':d:t:O,' . $trace_file . ':n', $trace_file, 60);
+	if (!preg_match("@^\d+:@ismU", $trace))
+		printf("[065] Nesting level seem to be missing, first characters from trace are
'%s'\n", substr($trace, 0, 80));
+
+
+
+	mysqli_close($link);
+	print "done";
+	if ($IS_MYSQLND)
+		print "libmysql/DBUG package prints some debug info here.";
+	@unlink($trace_file);
+?>
+--EXPECTF--
+done%s
\ No newline at end of file

Thread
PHP mysqlnd svn commit: r961 - trunk/tests/ext/mysqliuwendel29 Aug