From 961db603b7172775b5cbb21ab7958d3659f444d4 Mon Sep 17 00:00:00 2001 From: rurban Date: Tue, 19 Oct 2004 16:19:12 +0000 Subject: [PATCH] some sample memory usage fix web argv handling git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@4051 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- tests/unit/lib/SetupWiki.php | 3 +- tests/unit/readme.html | 49 ++++++++++++++++----- tests/unit/test.php | 82 +++++++++++++++++++++++++++--------- 3 files changed, 102 insertions(+), 32 deletions(-) diff --git a/tests/unit/lib/SetupWiki.php b/tests/unit/lib/SetupWiki.php index 9937662d5..0c4aa6da3 100644 --- a/tests/unit/lib/SetupWiki.php +++ b/tests/unit/lib/SetupWiki.php @@ -25,8 +25,9 @@ class SetupWiki extends phpwiki_TestCase { function testSetupWiki() { global $request; - print "Purge the testbox .. "; + print "Purge the testbox ... "; purge_testbox(); + print "\n"; $dbi = $request->getDbh(); $dbi->deletePage('HomePage'); // possibly in cache diff --git a/tests/unit/readme.html b/tests/unit/readme.html index 2e50eee0d..62d5491cb 100644 --- a/tests/unit/readme.html +++ b/tests/unit/readme.html @@ -15,7 +15,7 @@ one, which do not use PHPUnit.

PHP

You might want to run these from the php command-line +href="http://www.php.net/features.commandline">command-line interface. It was experimental as of PHP 4.2.0 (php-cli), default as of PHP 4.3.0. @@ -53,8 +53,17 @@ If it is not installed, you can use 'pear' to install it:

Running these unit tests

You must be in the phpwiki/tests/unit subdirectory. Then use the php -command-line executable to run the tests. For example: +command-line executable to run the tests. +Defaults: +
+tests=all
+db=file,dba,SQL,ADODB
+debug=9
+level=1
+
+ +For example:
 phpwiki/tests/unit % ./test.php
 Run tests ..
@@ -64,19 +73,39 @@ ran 8 tests, 0 failures.
 Or for only some tests, give the test names on the commandline:
 
 
-phpwiki/tests/unit % php -Cq test.php SetupWiki DumpHtml
-Run tests .. Array
-(
-    [0] => SetupWiki
-    [1] => DumpHtml
-)
-Purge the testbox .. ran 4 tests, 0 failures.
+phpwiki/tests/unit % php -Cq test.php db=dba debug=1 test=SetupWiki test=DumpHtml
+test=SetupWiki,DumpHtml
+db=dba
+debug=1
+level=1
+pid=2544
+
+Testing DB Backend "dba" ...
+Purge the testbox ...
+ran 6 tests, 0 failures.
 
Or run it from the browser like this:
-http://localhost/phpwiki/test/unit/test.php?tests=SetupWiki,DumpHtml
+http://localhost/phpwiki/test/unit/test.php?db=dba&level=10
+http://localhost/phpwiki/test/unit/test.php?test=SetupWiki,DumpHtml&level=1
+  or
+http://localhost/phpwiki/test/unit/test.php?test[]=SetupWiki&test[]=DumpHtml&level=1
+
+ +

Memory Usage

+
+(8MB limit on certain servers)
+
+setupwiki
+cli:  Mem16712 => Mem16928
+web:  Mem21216 => Mem26332 (5MB)
+
+dumphtml
+cli: Mem20696 => Mem31240  (with USECACHE)
+cli: Mem20240 => Mem30212  (without USECACHE) (10MB)
+web: Mem29424 => Mem35400  (without USECACHE) (6MB)
 
diff --git a/tests/unit/test.php b/tests/unit/test.php index 8f55552c5..d0ebb58a0 100644 --- a/tests/unit/test.php +++ b/tests/unit/test.php @@ -39,6 +39,17 @@ define('GROUP_METHOD', 'NONE'); define('USE_DB_SESSION', false); define('RATING_STORAGE', 'WIKIPAGE'); +// memory usage: (8MB limit on certain servers) +// setupwiki +// cli: Mem16712 => Mem16928 +// web: Mem21216 => Mem26332 (5MB) + +// dumphtml: +// cli: Mem20696 => Mem31240 (with USECACHE) (10MB) +// cli: Mem20240 => Mem30212 (without USECACHE) (10MB) +// web: Mem29424 => Mem35400 (without USECACHE) (6MB) +//define('USECACHE', false); + // available database backends to test: $database_backends = array( 'file', @@ -72,6 +83,30 @@ ini_set('include_path', ini_get('include_path') . $ini_sep . $rootdir); $HTTP_SERVER_VARS['REMOTE_ADDR'] = '127.0.0.1'; $HTTP_SERVER_VARS['HTTP_USER_AGENT'] = "PHPUnit"; +function printMemoryUsage($msg = '') { + if ($msg) echo $msg,"\n"; + if ((defined('DEBUG') and (DEBUG & 8)) or !defined('DEBUG')) { + echo "-- MEMORY USAGE: "; + if (function_exists('memory_get_usage')) { + echo memory_get_usage(),"\n"; + } elseif (function_exists('getrusage')) { + $u = getrusage(); + echo $u['ru_maxrss'],"\n"; + } elseif (substr(PHP_OS,0,3)=='WIN') { // requires a newer cygwin + // what we want is the process memory only: apache or php + $pid = getmypid(); + // this works only if it's a cygwin process (apache or php) + //echo `cat /proc/$pid/statm |cut -f1`,"\n"; + // if it's native windows use something like this: + // (requires pslist from systinternals.com) + echo `pslist $pid|grep -A1 Mem|perl -ane"print \$F[5]"`,"\n"; + } else { + $pid = getmypid(); + echo `ps -eo%mem,rss,pid | grep $pid`,"\n"; + } + flush(); + } +} function printSimpleTrace($bt) { //print_r($bt); echo "Traceback:\n"; @@ -82,7 +117,6 @@ function printSimpleTrace($bt) { print " " . $elem['file'] . ':' . $elem['line'] . "\n"; } } - # Show lots of detail when an assert() in the code fails function assert_callback( $script, $line, $message ) { echo "assert failed: script ", $script," line ", $line," :"; @@ -101,6 +135,7 @@ if (defined('E_STRICT') and (E_ALL & E_STRICT)) // strict php5? error_reporting(E_ALL & ~E_STRICT); // exclude E_STRICT else error_reporting(E_ALL); // php4 + // This is too strict, fails on every notice and warning. /* function myErrorHandler$errno, $errstr, $errfile, $errline) { @@ -171,8 +206,6 @@ function purge_testbox() { # #################################################################### -# Test files -require_once 'PHPUnit.php'; # lib/config.php might do a cwd() if (isset($HTTP_SERVER_VARS['REQUEST_METHOD'])) @@ -188,7 +221,12 @@ $alltests = array('InlineParserTest','HtmlParserTest','PageListTest','ListPagesT if (isset($HTTP_SERVER_VARS['REQUEST_METHOD'])) { $argv = array(); foreach ($HTTP_GET_VARS as $key => $val) { - $argv[] = $key."=".$val; + if (is_array($val)) + foreach ($val as $v) $argv[] = $key."=".$v; + elseif (strstr($val,",") and in_array($key,array("test","db"))) + foreach (explode(",",$val) as $v) $argv[] = $key."=".$v; + else + $argv[] = $key."=".$val; } } elseif (!empty($argv) and preg_match("/test\.php$/", $argv[0])) array_shift($argv); @@ -226,6 +264,16 @@ if (!empty($argv)) { } define('DEBUG', $debug_level); + +if (DEBUG & 8) + printMemoryUsage("before PEAR"); + +# Test files +require_once 'PHPUnit.php'; + +if (DEBUG & 8) + printMemoryUsage("after PEAR, before PhpWiki"); + define('PHPWIKI_NOMAIN', true); # Other needed files require_once $rootdir.'index.php'; @@ -284,33 +332,25 @@ else { */ include_once("themes/" . THEME . "/themeinfo.php"); +if (DEBUG & _DEBUG_TRACE) + printMemoryUsage("after PhpWiki, before tests"); + // save and restore all args for each test. class phpwiki_TestCase extends PHPUnit_TestCase { function setUp() { global $request; $this->_savedargs = $request->_args; $request->_args = array(); + if (DEBUG & 1) { + echo $this->_name,"\n"; + flush(); + } } function tearDown() { global $request; $request->_args = $this->_savedargs; - if (DEBUG & _DEBUG_TRACE) { - echo "-- MEMORY USAGE: "; - if (isWindows()) { // requires a newer cygwin - // what we want is the process memory only: apache or php - $pid = getmypid(); - echo `cat /proc/$pid/statm |cut -f1`,"\n"; - } elseif (function_exists('memory_get_usage')) { - echo memory_get_usage(),"\n"; - } elseif (function_exists('getrusage')) { - $u = getrusage(); - echo $u['ru_maxrss'],"\n"; - } elseif (!isWindows()) { // only on unix, not on cygwin: - $pid = getmypid(); - echo `ps -eo%mem,rss,pid | grep $pid`,"\n"; - } - flush(); - } + if (DEBUG & _DEBUG_TRACE) + printMemoryUsage(); } } -- 2.45.0