2007-11-20 11:07:22 +00:00
|
|
|
<?php
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
/**
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2007-11-20 11:07:22 +00:00
|
|
|
|
2009-08-03 21:56:41 +00:00
|
|
|
require_once( dirname(__FILE__) . '/commandLine.inc' );
|
2007-11-20 11:07:22 +00:00
|
|
|
|
|
|
|
|
$wgHooks['BeforeParserFetchTemplateAndtitle'][] = 'PPFuzzTester::templateHook';
|
|
|
|
|
|
|
|
|
|
class PPFuzzTester {
|
|
|
|
|
var $hairs = array(
|
2008-01-24 04:29:56 +00:00
|
|
|
'[[', ']]', '{{', '{{', '}}', '}}', '{{{', '}}}',
|
2007-11-20 11:07:22 +00:00
|
|
|
'<', '>', '<nowiki', '<gallery', '</nowiki>', '</gallery>', '<nOwIkI>', '</NoWiKi>',
|
2008-01-21 16:36:08 +00:00
|
|
|
'<!--' , '-->',
|
2007-11-20 11:07:22 +00:00
|
|
|
"\n==", "==\n",
|
|
|
|
|
'|', '=', "\n", ' ', "\t", "\x7f",
|
2008-01-21 16:36:08 +00:00
|
|
|
'~~', '~~~', '~~~~', 'subst:',
|
2007-11-20 11:07:22 +00:00
|
|
|
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
|
|
|
|
|
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
|
2008-01-21 16:36:08 +00:00
|
|
|
|
|
|
|
|
// extensions
|
|
|
|
|
//'<ref>', '</ref>', '<references/>',
|
2007-11-20 11:07:22 +00:00
|
|
|
);
|
|
|
|
|
var $minLength = 0;
|
|
|
|
|
var $maxLength = 20;
|
|
|
|
|
var $maxTemplates = 5;
|
2008-01-21 16:36:08 +00:00
|
|
|
//var $outputTypes = array( 'OT_HTML', 'OT_WIKI', 'OT_PREPROCESS' );
|
|
|
|
|
var $entryPoints = array( 'testSrvus', 'testPst', 'testPreprocess' );
|
2008-01-24 04:29:56 +00:00
|
|
|
var $verbose = false;
|
2007-11-20 11:07:22 +00:00
|
|
|
static $currentTest = false;
|
|
|
|
|
|
|
|
|
|
function execute() {
|
|
|
|
|
if ( !file_exists( 'results' ) ) {
|
|
|
|
|
mkdir( 'results' );
|
|
|
|
|
}
|
|
|
|
|
if ( !is_dir( 'results' ) ) {
|
|
|
|
|
echo "Unable to create 'results' directory\n";
|
|
|
|
|
exit( 1 );
|
|
|
|
|
}
|
2008-01-24 04:29:56 +00:00
|
|
|
$overallStart = microtime( true );
|
|
|
|
|
$reportInterval = 1000;
|
|
|
|
|
for ( $i = 1; true; $i++ ) {
|
|
|
|
|
$t = -microtime( true );
|
2007-11-20 11:07:22 +00:00
|
|
|
try {
|
|
|
|
|
self::$currentTest = new PPFuzzTest( $this );
|
|
|
|
|
self::$currentTest->execute();
|
2008-01-24 04:29:56 +00:00
|
|
|
$passed = 'passed';
|
2007-11-20 11:07:22 +00:00
|
|
|
} catch ( MWException $e ) {
|
|
|
|
|
$testReport = self::$currentTest->getReport();
|
|
|
|
|
$exceptionReport = $e->getText();
|
|
|
|
|
$hash = md5( $testReport );
|
|
|
|
|
file_put_contents( "results/ppft-$hash.in", serialize( self::$currentTest ) );
|
|
|
|
|
file_put_contents( "results/ppft-$hash.fail",
|
|
|
|
|
"Input:\n$testReport\n\nException report:\n$exceptionReport\n" );
|
|
|
|
|
print "Test $hash failed\n";
|
2008-01-24 04:29:56 +00:00
|
|
|
$passed = 'failed';
|
2007-11-20 11:07:22 +00:00
|
|
|
}
|
2008-01-24 04:29:56 +00:00
|
|
|
$t += microtime( true );
|
|
|
|
|
|
|
|
|
|
if ( $this->verbose ) {
|
|
|
|
|
printf( "Test $passed in %.3f seconds\n", $t );
|
|
|
|
|
print self::$currentTest->getReport();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$reportMetric = ( microtime( true ) - $overallStart ) / $i * $reportInterval;
|
|
|
|
|
if ( $reportMetric > 25 ) {
|
|
|
|
|
if ( substr( $reportInterval, 0, 1 ) === '1' ) {
|
|
|
|
|
$reportInterval /= 2;
|
|
|
|
|
} else {
|
|
|
|
|
$reportInterval /= 5;
|
|
|
|
|
}
|
|
|
|
|
} elseif ( $reportMetric < 4 ) {
|
|
|
|
|
if ( substr( $reportInterval, 0, 1 ) === '1' ) {
|
|
|
|
|
$reportInterval *= 5;
|
|
|
|
|
} else {
|
|
|
|
|
$reportInterval *= 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( $i % $reportInterval == 0 ) {
|
2007-11-20 11:07:22 +00:00
|
|
|
print "$i tests done\n";
|
|
|
|
|
/*
|
|
|
|
|
$testReport = self::$currentTest->getReport();
|
|
|
|
|
$filename = 'results/ppft-' . md5( $testReport ) . '.pass';
|
|
|
|
|
file_put_contents( $filename, "Input:\n$testReport\n" );*/
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-01-24 04:29:56 +00:00
|
|
|
wfLogProfilingData();
|
2007-11-20 11:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
2008-01-24 04:29:56 +00:00
|
|
|
function makeInputText( $max = false ) {
|
|
|
|
|
if ( $max === false ) {
|
|
|
|
|
$max = $this->maxLength;
|
|
|
|
|
}
|
|
|
|
|
$length = mt_rand( $this->minLength, $max );
|
2007-11-20 11:07:22 +00:00
|
|
|
$s = '';
|
|
|
|
|
for ( $i = 0; $i < $length; $i++ ) {
|
|
|
|
|
$hairIndex = mt_rand( 0, count( $this->hairs ) - 1 );
|
|
|
|
|
$s .= $this->hairs[$hairIndex];
|
|
|
|
|
}
|
|
|
|
|
// Send through the UTF-8 normaliser
|
|
|
|
|
// This resolves a few differences between the old preprocessor and the
|
|
|
|
|
// XML-based one, which doesn't like illegals and converts line endings.
|
|
|
|
|
// It's done by the MW UI, so it's a reasonably legitimate thing to do.
|
2010-01-04 08:28:50 +00:00
|
|
|
global $wgContLang;
|
|
|
|
|
$s = $wgContLang->normalize( $s );
|
2007-11-20 11:07:22 +00:00
|
|
|
return $s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function makeTitle() {
|
|
|
|
|
return Title::newFromText( mt_rand( 0, 1000000 ), mt_rand( 0, 10 ) );
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-21 16:36:08 +00:00
|
|
|
/*
|
2007-11-20 11:07:22 +00:00
|
|
|
function pickOutputType() {
|
|
|
|
|
$count = count( $this->outputTypes );
|
|
|
|
|
return $this->outputTypes[ mt_rand( 0, $count - 1 ) ];
|
2008-01-21 16:36:08 +00:00
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
function pickEntryPoint() {
|
|
|
|
|
$count = count( $this->entryPoints );
|
|
|
|
|
return $this->entryPoints[ mt_rand( 0, $count - 1 ) ];
|
2007-11-20 11:07:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PPFuzzTest {
|
2008-01-24 04:29:56 +00:00
|
|
|
var $templates, $mainText, $title, $entryPoint, $output;
|
2007-11-20 11:07:22 +00:00
|
|
|
|
|
|
|
|
function __construct( $tester ) {
|
2008-01-24 04:29:56 +00:00
|
|
|
global $wgMaxSigChars;
|
2007-11-20 11:07:22 +00:00
|
|
|
$this->parent = $tester;
|
|
|
|
|
$this->mainText = $tester->makeInputText();
|
|
|
|
|
$this->title = $tester->makeTitle();
|
2008-01-21 16:36:08 +00:00
|
|
|
//$this->outputType = $tester->pickOutputType();
|
|
|
|
|
$this->entryPoint = $tester->pickEntryPoint();
|
2008-01-24 04:29:56 +00:00
|
|
|
$this->nickname = $tester->makeInputText( $wgMaxSigChars + 10);
|
2008-01-21 16:36:08 +00:00
|
|
|
$this->fancySig = (bool)mt_rand( 0, 1 );
|
2007-11-20 11:07:22 +00:00
|
|
|
$this->templates = array();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function templateHook( $title ) {
|
|
|
|
|
$titleText = $title->getPrefixedDBkey();
|
2008-01-21 16:36:08 +00:00
|
|
|
|
2007-11-20 11:07:22 +00:00
|
|
|
if ( !isset( $this->templates[$titleText] ) ) {
|
|
|
|
|
$finalTitle = $title;
|
|
|
|
|
if ( count( $this->templates ) >= $this->parent->maxTemplates ) {
|
|
|
|
|
// Too many templates
|
|
|
|
|
$text = false;
|
|
|
|
|
} else {
|
|
|
|
|
if ( !mt_rand( 0, 1 ) ) {
|
|
|
|
|
// Redirect
|
|
|
|
|
$finalTitle = $this->parent->makeTitle();
|
|
|
|
|
}
|
|
|
|
|
if ( !mt_rand( 0, 5 ) ) {
|
|
|
|
|
// Doesn't exist
|
|
|
|
|
$text = false;
|
|
|
|
|
} else {
|
|
|
|
|
$text = $this->parent->makeInputText();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$this->templates[$titleText] = array(
|
|
|
|
|
'text' => $text,
|
|
|
|
|
'finalTitle' => $finalTitle );
|
|
|
|
|
}
|
|
|
|
|
return $this->templates[$titleText];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function execute() {
|
2008-01-21 16:36:08 +00:00
|
|
|
global $wgParser, $wgUser;
|
|
|
|
|
|
|
|
|
|
$wgUser = new PPFuzzUser;
|
|
|
|
|
$wgUser->mName = 'Fuzz';
|
|
|
|
|
$wgUser->mFrom = 'name';
|
|
|
|
|
$wgUser->ppfz_test = $this;
|
|
|
|
|
|
2007-11-20 11:07:22 +00:00
|
|
|
$options = new ParserOptions;
|
|
|
|
|
$options->setTemplateCallback( array( $this, 'templateHook' ) );
|
2008-01-24 04:29:56 +00:00
|
|
|
$options->setTimestamp( wfTimestampNow() );
|
|
|
|
|
$this->output = call_user_func( array( $wgParser, $this->entryPoint ), $this->mainText, $this->title->getPrefixedText(), $options );
|
|
|
|
|
return $this->output;
|
2007-11-20 11:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getReport() {
|
|
|
|
|
$s = "Title: " . $this->title->getPrefixedDBkey() . "\n" .
|
2008-01-21 16:36:08 +00:00
|
|
|
// "Output type: {$this->outputType}\n" .
|
|
|
|
|
"Entry point: {$this->entryPoint}\n" .
|
|
|
|
|
"User: " . ( $this->fancySig ? 'fancy' : 'no-fancy' ) . ' ' . var_export( $this->nickname, true ) . "\n" .
|
2007-11-20 11:07:22 +00:00
|
|
|
"Main text: " . var_export( $this->mainText, true ) . "\n";
|
|
|
|
|
foreach ( $this->templates as $titleText => $template ) {
|
|
|
|
|
$finalTitle = $template['finalTitle'];
|
|
|
|
|
if ( $finalTitle != $titleText ) {
|
|
|
|
|
$s .= "[[$titleText]] -> [[$finalTitle]]: " . var_export( $template['text'], true ) . "\n";
|
|
|
|
|
} else {
|
|
|
|
|
$s .= "[[$titleText]]: " . var_export( $template['text'], true ) . "\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-01-24 04:29:56 +00:00
|
|
|
$s .= "Output: " . var_export( $this->output, true ) . "\n";
|
2007-11-20 11:07:22 +00:00
|
|
|
return $s;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-21 16:36:08 +00:00
|
|
|
class PPFuzzUser extends User {
|
|
|
|
|
var $ppfz_test;
|
|
|
|
|
|
2008-01-24 04:29:56 +00:00
|
|
|
function load() {
|
|
|
|
|
if ( $this->mDataLoaded ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$this->mDataLoaded = true;
|
|
|
|
|
$this->loadDefaults( $this->mName );
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-21 16:36:08 +00:00
|
|
|
function getOption( $option, $defaultOverride = '' ) {
|
|
|
|
|
if ( $option === 'fancysig' ) {
|
|
|
|
|
return $this->ppfz_test->fancySig;
|
|
|
|
|
} elseif ( $option === 'nickname' ) {
|
|
|
|
|
return $this->ppfz_test->nickname;
|
|
|
|
|
} else {
|
|
|
|
|
return parent::getOption( $option, $defaultOverride );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-20 11:07:22 +00:00
|
|
|
ini_set( 'memory_limit', '50M' );
|
|
|
|
|
if ( isset( $args[0] ) ) {
|
|
|
|
|
$testText = file_get_contents( $args[0] );
|
|
|
|
|
if ( !$testText ) {
|
|
|
|
|
print "File not found\n";
|
|
|
|
|
exit( 1 );
|
|
|
|
|
}
|
|
|
|
|
$test = unserialize( $testText );
|
|
|
|
|
$result = $test->execute();
|
2008-01-24 04:29:56 +00:00
|
|
|
print "Test passed.\n";
|
2007-11-20 11:07:22 +00:00
|
|
|
} else {
|
|
|
|
|
$tester = new PPFuzzTester;
|
2008-01-24 04:29:56 +00:00
|
|
|
$tester->verbose = isset( $options['verbose'] );
|
2007-11-20 11:07:22 +00:00
|
|
|
$tester->execute();
|
|
|
|
|
}
|