25 require_once __DIR__ .
'/commandLine.inc';
27 $wgHooks[
'BeforeParserFetchTemplateAndtitle'][] =
'PPFuzzTester::templateHook';
31 '[[',
']]',
'{{',
'{{',
'}}',
'}}',
'{{{',
'}}}',
32 '<',
'>',
'<nowiki',
'<gallery',
'</nowiki>',
'</gallery>',
'<nOwIkI>',
'</NoWiKi>',
35 '|',
'=',
"\n",
' ',
"\t",
"\x7f",
36 '~~',
'~~~',
'~~~~',
'subst:',
37 'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
38 'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
47 public $entryPoints = [
'testSrvus',
'testPst',
'testPreprocess' ];
56 if ( !file_exists(
'results' ) ) {
59 if ( !is_dir(
'results' ) ) {
60 echo
"Unable to create 'results' directory\n";
63 $overallStart = microtime(
true );
64 $reportInterval = 1000;
65 for ( $i = 1;
true; $i++ ) {
66 $t = -microtime(
true );
69 self::$currentTest->execute();
71 }
catch ( Exception
$e ) {
72 $testReport = self::$currentTest->getReport();
73 $exceptionReport =
$e->getText();
74 $hash = md5( $testReport );
75 file_put_contents(
"results/ppft-$hash.in",
serialize( self::$currentTest ) );
76 file_put_contents(
"results/ppft-$hash.fail",
77 "Input:\n$testReport\n\nException report:\n$exceptionReport\n" );
78 print
"Test $hash failed\n";
81 $t += microtime(
true );
84 printf(
"Test $passed in %.3f seconds\n",
$t );
85 print self::$currentTest->getReport();
88 $reportMetric = ( microtime(
true ) - $overallStart ) / $i * $reportInterval;
89 if ( $reportMetric > 25 ) {
90 if ( substr( $reportInterval, 0, 1 ) ===
'1' ) {
95 } elseif ( $reportMetric < 4 ) {
96 if ( substr( $reportInterval, 0, 1 ) ===
'1' ) {
102 if ( $i % $reportInterval == 0 ) {
103 print
"$i tests done\n";
113 if ( $max ===
false ) {
116 $length = mt_rand( $this->minLength, $max );
118 for ( $i = 0; $i < $length; $i++ ) {
119 $hairIndex = mt_rand( 0,
count( $this->hairs ) - 1 );
120 $s .= $this->hairs[$hairIndex];
143 $count =
count( $this->entryPoints );
145 return $this->entryPoints[mt_rand( 0, $count - 1 )];
154 $this->parent = $tester;
155 $this->mainText = $tester->makeInputText();
156 $this->
title = $tester->makeTitle();
158 $this->entryPoint = $tester->pickEntryPoint();
160 $this->fancySig = (bool)mt_rand( 0, 1 );
161 $this->templates = [];
169 $titleText =
$title->getPrefixedDBkey();
171 if ( !isset( $this->templates[$titleText] ) ) {
173 if (
count( $this->templates ) >= $this->parent->maxTemplates ) {
177 if ( !mt_rand( 0, 1 ) ) {
179 $finalTitle = $this->parent->makeTitle();
181 if ( !mt_rand( 0, 5 ) ) {
185 $text = $this->parent->makeInputText();
188 $this->templates[$titleText] = [
190 'finalTitle' => $finalTitle ];
193 return $this->templates[$titleText];
205 $options->setTemplateCallback( [ $this,
'templateHook' ] );
207 $this->
output = call_user_func(
218 $s =
"Title: " . $this->
title->getPrefixedDBkey() .
"\n" .
220 "Entry point: {$this->entryPoint}\n" .
221 "User: " . ( $this->fancySig ?
'fancy' :
'no-fancy' ) .
222 ' ' . var_export( $this->nickname,
true ) .
"\n" .
223 "Main text: " . var_export( $this->mainText,
true ) .
"\n";
224 foreach ( $this->templates
as $titleText =>
$template ) {
226 if ( $finalTitle != $titleText ) {
227 $s .=
"[[$titleText]] -> [[$finalTitle]]: " . var_export(
$template[
'text'],
true ) .
"\n";
229 $s .=
"[[$titleText]]: " . var_export(
$template[
'text'],
true ) .
"\n";
232 $s .=
"Output: " . var_export( $this->
output,
true ) .
"\n";
242 if ( $this->mDataLoaded ) {
245 $this->mDataLoaded =
true;
249 function getOption( $oname, $defaultOverride =
null, $ignoreHidden =
false ) {
250 if ( $oname ===
'fancysig' ) {
251 return $this->ppfz_test->fancySig;
252 } elseif ( $oname ===
'nickname' ) {
253 return $this->ppfz_test->nickname;
255 return parent::getOption( $oname, $defaultOverride, $ignoreHidden );
260 ini_set(
'memory_limit',
'50M' );
261 if ( isset(
$args[0] ) ) {
262 $testText = file_get_contents(
$args[0] );
264 print
"File not found\n";
269 print
"Test passed.\n";