5 require __DIR__ .
'/../../maintenance/Maintenance.php';
8 define(
'MW_PARSER_TEST', 1 );
17 parent::__construct();
18 $this->
addDescription(
'Run a fuzz test on the parser, until it segfaults ' .
19 'or throws an exception' );
20 $this->
addOption(
'file',
'Use the specified file as a dictionary, ' .
21 ' or leave blank to use parserTests.txt',
false,
true,
true );
23 $this->
addOption(
'seed',
'Start the fuzz test from the specified seed',
false,
true );
27 self::requireTestsAutoloader();
33 $this->seed = intval( $this->
getOption(
'seed', 1 ) ) - 1;
47 $dictSize = strlen( $dict );
48 $logMaxLength = log( $this->maxFuzzTestLength );
50 $teardown = $this->parserTest->staticSetup();
51 $teardown = $this->parserTest->setupDatabase( $teardown );
52 $teardown = $this->parserTest->setupUploads( $teardown );
63 ini_set(
'memory_limit', $this->
memoryLimit * 1048576 * 2 );
73 mt_srand( ++$this->seed );
74 $totalLength = mt_rand( 1, $this->maxFuzzTestLength );
77 while ( strlen( $input ) < $totalLength ) {
78 $logHairLength = mt_rand( 0, 1000000 ) / 1000000 * $logMaxLength;
79 $hairLength = min( intval( exp( $logHairLength ) ), $dictSize );
80 $offset = mt_rand( 0, $dictSize - $hairLength );
81 $input .= substr( $dict, $offset, $hairLength );
84 $perTestTeardown = $this->parserTest->perTestSetup( $fakeTest );
85 $parser = $this->parserTest->getParser();
96 echo
"Test failed with seed {$this->seed}\n";
98 printf(
"string(%d) \"%s\"\n\n", strlen( $input ), $input );
105 ScopedCallback::consume( $perTestTeardown );
107 if ( $numTotal % 100 == 0 ) {
108 $usage = intval( memory_get_usage(
true ) / $this->
memoryLimit / 1048576 * 100 );
109 echo
"{$this->seed}: $numSuccess/$numTotal (mem: $usage%)\n";
110 if ( $usage >= 100 ) {
111 echo
"Out of memory:\n";
114 foreach ( $memStats
as $name => $usage ) {
115 echo
"$name: $usage\n";
117 if ( function_exists(
'hphpd_break' ) ) {
137 $classes = get_declared_classes();
139 foreach ( $classes
as $class ) {
140 $rc =
new ReflectionClass( $class );
141 $props = $rc->getStaticProperties();
143 $methods = $rc->getMethods();
145 foreach ( $methods
as $method ) {
146 $memStats[$class] += $this->
guessVarSize( $method->getStaticVariables() );
150 $functions = get_defined_functions();
152 foreach ( $functions[
'user']
as $function ) {
153 $rf =
new ReflectionFunction( $function );
154 $memStats[
"$function()"] = $this->
guessVarSize( $rf->getStaticVariables() );
168 MediaWiki\suppressWarnings();
170 MediaWiki\restoreWarnings();
184 foreach ( $filenames
as $filename ) {
185 $contents = file_get_contents( $filename );
187 '/!!\s*(input|wikitext)\n(.*?)\n!!\s*(result|html|html\/\*|html\/php)/s',
193 $dict .= $match .
"\n";
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException'returning false will NOT prevent logging $e
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
fuzzTest($filenames)
Run a fuzz test series Draw input from a set of test files.
require_once RUN_MAINTENANCE_IF_MAIN
static newFromUser($user)
Get a ParserOptions object from a given user.
addOption($name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
This is a TestRecorder representing a collection of other TestRecorders.
namespace and then decline to actually register it file or subcat img or subcat $title
getMemoryBreakdown()
Get a memory usage breakdown.
addDescription($text)
Set the description text.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
getOption($name, $default=null)
Get an option, or return the default.
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
memoryLimit()
Normally we disable the memory_limit when running admin scripts.
getFuzzInput($filenames)
Get an input dictionary from a set of parser test files.
guessVarSize($var)
Estimate the size of the input variable.
static applyInitialConfig()
This should be called before Setup.php, e.g.
static makeTitle($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Allows to change the fields on the form that will be generated $name