From c1203aa54105d073a3e5cd3fa2918b8248534121 Mon Sep 17 00:00:00 2001 From: rurban Date: Thu, 21 Oct 2004 12:03:34 +0000 Subject: [PATCH] memory regression suite git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@4058 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- tests/unit/_mem_pl.ploticus | 64 ++++++++++++++++++++++++++++++ tests/unit/combine_define.pl | 58 +++++++++++++++++++++++++++ tests/unit/lib/SetupWiki.php | 4 +- tests/unit/prepare_pl | 75 +++++++++++++++++++++++++++++++++++ tests/unit/runme_all | 23 ++++++++++- tests/unit/runme_basic | 4 +- tests/unit/runme_mem | 37 +++++++++++++++++ tests/unit/test.php | 77 +++++++++++++++++++++++++----------- 8 files changed, 316 insertions(+), 26 deletions(-) create mode 100644 tests/unit/_mem_pl.ploticus create mode 100755 tests/unit/combine_define.pl create mode 100755 tests/unit/prepare_pl create mode 100755 tests/unit/runme_mem diff --git a/tests/unit/_mem_pl.ploticus b/tests/unit/_mem_pl.ploticus new file mode 100644 index 000000000..272edc38d --- /dev/null +++ b/tests/unit/_mem_pl.ploticus @@ -0,0 +1,64 @@ +// single category lineplot, horizontal (bad) +#setifnotgiven legend = "max+0.1 max-0.5" + +#proc getdata + file: @resultdata + //fieldnameheader: yes + fieldnames: inc mem msg + delim: tab +#endproc + +#proc areadef + title: memory usage (KB) + titledetail: align=R + rectangle: 0.5 2.5 7.5 7 + yrange: 4000 36000 + xautorange: datafield=1 +// yrange: 11 1 + +#proc yaxis +// label: memory usage (KB) +// stubs: datafields=mem + stubs: inc 1000 + stubslide: +0.05 +// stubvert: yes + grid: color=orange +// gridskip: min + location: max +// tics: yes + +#proc xaxis + stubs: datafields=msg + stubvert: yes + grid: color=green +// location: max +// ticincrement: 100 1000 + +#proc lineplot + xfield: 1 + yfield: 2 + fill: green + gapmissing: yes + linedetails: color=blue + ptlabelfield: 2 + ptlabeldetails: adjust=0.05,0 size=7 align=L + //numbers: yes + //legendsampletype: line+symbol +#endproc + +#if X = Y + +#proc rangebar + datafield: mem + axis: x +#endproc + +#proc bars + lenfield: mem + locfield: msg + legendlabel: mem +#endproc + +#endif + +#endproc diff --git a/tests/unit/combine_define.pl b/tests/unit/combine_define.pl new file mode 100755 index 000000000..80671960f --- /dev/null +++ b/tests/unit/combine_define.pl @@ -0,0 +1,58 @@ +#!/usr/bin/perl +# combine the ploticus data files for all tested define combinations +# // inc mem msg => +# // test nr d1_t d1_f d2_t d2_f +#"testnowikiwords" 4 13408 13592 14880 15440 +#"testwikiword" 5 13408 13600 14880 15440 + +$prefix = shift || 'all'; +# @DEF should match the runme_mem tests: +# WIKIDB_NOCACHE_MARKUP ENABLE_PAGEPERM +@DEF = qw/ USECACHE ENABLE_USER_NEW /; +for $def (@DEF) { + for $bool (qw/true false/) { + $fn = sprintf("%s_%s_%s.data",$prefix,$def,$bool); + open F, "< $fn" || break; + $key = $def."_".$bool; + $i=1; + while () { + chomp; + if (/^\d+\t(\d+)\t(.+)/) { + $t{$i} = "$2" unless $t{$i}; + $m{$key}{$i++} = $1; + } + if (m|^// |) { + $p .= ($_."\n"); + } + } + $params = $p unless $params; + close F; + $max = $max < $i ? $i : $max; + } +} +$fn = $prefix."_combine_define.data"; +open F, "> $fn"; +print F "// test \tnr"; +for $def (@DEF) { + print F "\t",$def," (t/f)"; } +print F "\n"; + +$i=0; +while (++$i < $max) { + print F substr($t{$i},0,14); + print F "\t",$i; + for $def (@DEF) { + for $bool (qw/true false/) { + $key = $def."_".$bool; + $v = $m{$key}{$i} ? $m{$key}{$i} : '-1'; + print F "\t",$v; }} + print F "\n"; +} + +# add the PARAMS +print F "\n"; +$defs = " (".join('|',("pid",@DEF)).")="; +$defrx = qr($defs); +for (split(/\n/,$params)) { + print F $_,"\n" unless m/$defrx/; +} diff --git a/tests/unit/lib/SetupWiki.php b/tests/unit/lib/SetupWiki.php index 0c4aa6da3..9056dd19a 100644 --- a/tests/unit/lib/SetupWiki.php +++ b/tests/unit/lib/SetupWiki.php @@ -25,9 +25,9 @@ class SetupWiki extends phpwiki_TestCase { function testSetupWiki() { global $request; - print "Purge the testbox ... "; + //print "Purge the testbox ... "; purge_testbox(); - print "\n"; + //print "\n"; $dbi = $request->getDbh(); $dbi->deletePage('HomePage'); // possibly in cache diff --git a/tests/unit/prepare_pl b/tests/unit/prepare_pl new file mode 100755 index 000000000..e2858c8c6 --- /dev/null +++ b/tests/unit/prepare_pl @@ -0,0 +1,75 @@ +#!/bin/sh +# Memory regression helper. +# Create a .data file from a .result file, which can then be processed by combine_define.pl +# If the 2nd arg is not -nopl some ploticus file is also created. + +result=$1 +if [ ! -e $result.result ]; then + if [ -e $result ]; then result="`echo $result|sed s,.result,,`" + else + echo "$result.result missing" + exit + fi +fi + +perl -ne ' + BEGIN { $i=1; print "//inc\tmem\tmsg\n"; } + chomp; + if (/^-- MEMORY USAGE: (\d+)/) { + print "$i\t$1\t$msg\n"; $i++; + } elsif (/^(\w+)=(\S+)$/) { + $vars .= "// $_\n"; + } else { + $msg = $_; + } + END { print "\n// PARAMS:\n",$vars; } +' $result.result > $result.data + +today=`date` +echo "// CREATED=$today" >> $result.data + +# pl -png -o vbars.png -prefab vbars data=all_dba.data x=2 y=1 barwidth=line vals=yes ylbl="memory (kb)" title="dba cli-4.3.9WIN" xlbl="consecutive tests" stubvert=yes ygrid=yes ylbldet="adjust=-0.1,0" xlbldet="adjust=0,-1.2" + +# pl -png -o stack.png -prefab stack data=all_dba.data x=2 y=1 barwidth=line ylbl="memory (kb)" title="dba cli-4.3.9WIN" ygrid=yes ylbldet="adjust=-0.1,0" stubvert=yes stackarea=yes name=file name2=file name3=SQL name4=ADODB + +# pl -png -o all_$db.png -prefab vbars data=all_$db.data x=2 y=1 barwidth=line yfield=1 fill=redorange pointsym=none pointsym2=none + +if [ "x$2" = "x-nopl" ]; then exit; fi + +php_const() { + grep $1 $2|cut -d= -f2 +} +PHP_SAPI=`php_const PHP_SAPI $result.result` +PHP_SAPI=${PHP_SAPI:-cli} +PHP_OS=`php_const PHP_OS $result.result` +PHP_VERSION=`php_const PHP_VERSION $result.result` +PHPWIKI_VERSION=`php_const PHPWIKI_VERSION $result.result` +title="$PHP_SAPI-$PHP_OS-$PHP_VERSION $PHPWIKI_VERSION" +legendvars=`grep "// " $result.data|cut -c4-` + +# echo "Usage: pl -png -o $result.png $result.ploticus" +# basic memory usage graph for single test +cat > $result.ploticus <> "${prefix}_combine_define.data" +#pl -png -o all_$db.png -prefab vbars data=all_$db.data delim=tab x=2 y=1 xstep=2 barwidth=line ylbl="memory (kb)" title="$db $title" xlbl="consecutive tests" stubvert=yes ygrid=yes ylbldet="adjust=-0.1,0" xlbldet="adjust=0,-1.2" # vals=yes + + + diff --git a/tests/unit/test.php b/tests/unit/test.php index c235f6491..ef457e688 100644 --- a/tests/unit/test.php +++ b/tests/unit/test.php @@ -34,9 +34,11 @@ *****************************************************************/ // common cfg options are taken from config/config.ini -define('GROUP_METHOD', 'NONE'); -define('USE_DB_SESSION', false); +//TODO: let the user decide which constants to use: define="x=y" define('RATING_STORAGE', 'WIKIPAGE'); +define('GROUP_METHOD', 'NONE'); +//define('USE_DB_SESSION', false); +//define('ENABLE_USER_NEW', false); // memory usage: (8MB limit on certain servers) // setupwiki @@ -101,8 +103,8 @@ function printMemoryUsage($msg = '') { $oldmem = $mem; if (function_exists('memory_get_usage') and memory_get_usage()) { $mem = memory_get_usage(); - } elseif (function_exists('getrusage') and ($u = getrusage()) and !empty($u['ru_maxrss'])) { - $mem = $u['ru_maxrss']; + // } elseif (function_exists('getrusage') and ($u = getrusage()) and !empty($u['ru_maxrss'])) { + // $mem = $u['ru_maxrss']; } elseif (substr(PHP_OS,0,3)=='WIN') { // requires a newer cygwin // what we want is the process memory only: apache or php $pid = getmypid(); @@ -143,8 +145,10 @@ function printSimpleTrace($bt) { function assert_callback( $script, $line, $message ) { echo "assert failed: script ", $script," line ", $line," :"; echo "$message"; - echo "Traceback:\n"; - printSimpleTrace(debug_backtrace()); + if (function_exists('debug_backtrace')) { // >= 4.3.0 + echo "Traceback:\n"; + printSimpleTrace(debug_backtrace()); + } exit; } $foo = assert_options( ASSERT_CALLBACK, 'assert_callback'); @@ -222,6 +226,14 @@ function purge_testbox() { } } +function printConstant($v) { + echo "$v="; + if (defined($v)) { + if (constant($v) or constant($v)===0 or constant($v)==='0') echo constant($v); + else echo "false"; + } else echo "undefined"; + echo "\n"; +} #################################################################### # # End of preamble, run the test suite .. @@ -238,8 +250,8 @@ elseif (!ini_get("register_argc_argv")) echo "Could not read cmd args (register_argc_argv=Off?)\n"; // purge the testbox -$debug_level = 9; //_DEBUG_VERBOSE | _DEBUG_TRACE -$user_level = 1; // BOGO +$debug_level = 1; //was 9, _DEBUG_VERBOSE | _DEBUG_TRACE +$user_level = 1; // BOGO (conflicts with RateIt) // use argv (from cli) or tests (from browser) params to run only certain tests // avoid pear: Console::Getopt $alltests = array('InlineParserTest','HtmlParserTest','PageListTest','ListPagesTest', @@ -257,8 +269,9 @@ if (isset($HTTP_SERVER_VARS['REQUEST_METHOD'])) { } elseif (!empty($argv) and preg_match("/test\.php$/", $argv[0])) array_shift($argv); if (!empty($argv)) { - //support db=file db=dba test=SetupWiki test=DumpHtml debug=num + //support db=file db=dba test=SetupWiki test=DumpHtml debug=num -dconstant=value $runtests = array(); + $define = array(); $run_database_backends = array(); foreach ($argv as $arg) { if (preg_match("/^test=(.+)$/",$arg,$m) and in_array($m[1], $alltests)) @@ -269,7 +282,12 @@ if (!empty($argv)) { $debug_level = $m[1]; elseif (preg_match("/^level=(\d+)$/",$arg,$m)) $user_level = $m[1]; - elseif (in_array($arg, $alltests)) + elseif (preg_match("/^\-d(\w+)=(.+)$/",$arg,$m)) { + $define[$m[1]] = $m[2]; + if ($m[2] == 'true') $m[2] = true; + elseif ($m[2] == 'false') $m[2] = false; + if (!defined($m[1])) define($m[1], $m[2]); + } elseif (in_array($arg, $alltests)) $runtests[] = $arg; elseif ($debug_level & 1) echo "ignored arg: ", $arg, "\n"; @@ -279,12 +297,16 @@ if (!empty($argv)) { if (!empty($runtests)) $alltests = $runtests; if ($debug_level & 1) { + echo "PHP_SAPI=",php_sapi_name(), "\n"; echo "PHP_OS=",PHP_OS, "\n"; echo "PHP_VERSION=",PHP_VERSION, "\n"; echo "test=", join(",",$alltests),"\n"; echo "db=", join(",",$database_backends),"\n"; echo "debug=", $debug_level,"\n"; echo "level=", $user_level,"\n"; + if (!empty($define)) { + foreach ($define as $k => $v) printConstant($k); + } if ($debug_level & 8) { echo "pid=",getmypid(),"\n"; } @@ -295,23 +317,29 @@ if (!empty($argv)) { define('DEBUG', $debug_level); if (DEBUG & 8) - printMemoryUsage("before PEAR"); + printMemoryUsage("beforePEAR"); # Test files require_once 'PHPUnit.php'; if (DEBUG & 8) - printMemoryUsage("after PEAR, before PhpWiki"); + printMemoryUsage("beforePhpWiki"); define('PHPWIKI_NOMAIN', true); # Other needed files require_once $rootdir.'index.php'; require_once $rootdir.'lib/main.php'; -if ($debug_level & 9) { - // which constants affect memory? - foreach (explode(",","ENABLE_PAGEPERM,USECACHE,WIKIDB_NOCACHE_MARKUP") as $v) - echo "$v=",(defined($v) and constant($v)) ? constant($v) : "false","\n"; +if ($debug_level & 1) { + echo "\n"; + echo "PHPWIKI_VERSION=",PHPWIKI_VERSION, strstr(PHPWIKI_VERSION,"pre") ? strftime("-%Y%m%d") : "","\n"; + if ($debug_level & 9) { + // which constants affect memory? + foreach (explode(",","USECACHE,WIKIDB_NOCACHE_MARKUP,ENABLE_USER_NEW,ENABLE_PAGEPERM") as $v) { + printConstant($v); + } + } + echo "\n"; } global $ErrorManager; @@ -321,7 +349,7 @@ class MockRequest extends WikiRequest { function MockRequest(&$dbparams) { $this->_dbi = WikiDB::open($dbparams); $this->_user = new MockUser("a_user", $GLOBALS['user_level']); - $this->_group = WikiGroup::getGroup(); + $this->_group = new GroupNone(); $this->_args = array('pagename' => 'HomePage', 'action' => 'browse'); $this->Request(); } @@ -329,7 +357,7 @@ class MockRequest extends WikiRequest { if (is_object($this->_group)) return $this->_group; else // FIXME: this is set to "/f:" somewhere. - return WikiGroup::getGroup(); + return new GroupNone(); } } @@ -366,9 +394,8 @@ else { } */ include_once("themes/" . THEME . "/themeinfo.php"); - if (DEBUG & _DEBUG_TRACE) - printMemoryUsage("PhpWiki loaded, not initialized"); + printMemoryUsage("PhpWikiLoaded"); // save and restore all args for each test. class phpwiki_TestCase extends PHPUnit_TestCase { @@ -393,7 +420,7 @@ class phpwiki_TestCase extends PHPUnit_TestCase { foreach ($database_backends as $dbtype) { // if (DEBUG & _DEBUG_TRACE) - // printMemoryUsage("PHPUnit initialized"); + // printMemoryUsage("PHPUnitInitialized"); $DBParams['dbtype'] = $dbtype; $DBParams['directory'] = $cur_dir . '/.testbox'; @@ -404,8 +431,12 @@ foreach ($database_backends as $dbtype) { echo "Testing DB Backend \"$dbtype\" ...\n"; $request = new MockRequest($DBParams); + if ( ! ENABLE_USER_NEW ) { + $request->_user->_request =& $request; + $request->_user->_dbi =& $request->_dbi; + } if (DEBUG & _DEBUG_TRACE) - printMemoryUsage("PhpWiki initialized"); + printMemoryUsage("PhpWikiInitialized"); foreach ($alltests as $test) { $suite = new PHPUnit_TestSuite("phpwiki"); @@ -424,6 +455,8 @@ foreach ($database_backends as $dbtype) { echo $result->toString(); } } + + $request->chunkOutput(); unset($request); unset($suite); unset($result); -- 2.45.0