@@ -137,23 +137,25 @@ function main()
137
137
global $ DETAILED , $ PHP_FAILED_TESTS , $ SHOW_ONLY_GROUPS , $ argc , $ argv , $ cfg ,
138
138
$ cfgfiles , $ cfgtypes , $ conf_passed , $ end_time , $ environment ,
139
139
$ exts_skipped , $ exts_tested , $ exts_to_test , $ failed_tests_file ,
140
- $ html_file , $ html_output , $ ignored_by_ext , $ ini_overwrites , $ is_switch ,
140
+ $ ignored_by_ext , $ ini_overwrites , $ is_switch ,
141
141
$ just_save_results , $ log_format , $ matches , $ no_clean , $ no_file_cache ,
142
142
$ optionals , $ output_file , $ pass_option_n , $ pass_options ,
143
143
$ pattern_match , $ php , $ php_cgi , $ phpdbg , $ preload , $ redir_tests ,
144
144
$ repeat , $ result_tests_file , $ slow_min_ms , $ start_time , $ switch ,
145
145
$ temp_source , $ temp_target , $ temp_urlbase , $ test_cnt , $ test_dirs ,
146
146
$ test_files , $ test_idx , $ test_list , $ test_results , $ testfile ,
147
- $ user_tests , $ valgrind , $ sum_results , $ shuffle , $ file_cache ;
147
+ $ user_tests , $ valgrind , $ sum_results , $ shuffle , $ file_cache, $ outputHandler ;
148
148
// Parallel testing
149
149
global $ workers , $ workerID ;
150
150
151
151
define ('IS_WINDOWS ' , substr (PHP_OS , 0 , 3 ) == "WIN " );
152
152
153
+ $ outputHandler = new OutputHandler ();
154
+
153
155
$ workerID = 0 ;
154
- if (getenv ( " TEST_PHP_WORKER " )) {
156
+ if (is_worker_mode ( )) {
155
157
$ workerID = intval (getenv ("TEST_PHP_WORKER " ));
156
- run_worker ();
158
+ run_worker ($ workerID );
157
159
return ;
158
160
}
159
161
@@ -378,8 +380,6 @@ function main()
378
380
379
381
$ just_save_results = false ;
380
382
$ valgrind = null ;
381
- $ html_output = false ;
382
- $ html_file = null ;
383
383
$ temp_source = null ;
384
384
$ temp_target = null ;
385
385
$ temp_urlbase = null ;
@@ -607,8 +607,9 @@ function main()
607
607
}
608
608
break ;
609
609
case '--html ' :
610
- $ html_file = fopen ($ argv [++$ i ], 'wt ' );
611
- $ html_output = is_resource ($ html_file );
610
+ $ html_output_filename = $ argv [++$ i ];
611
+ $ outputHandler ->setHtmlOutputFilename ($ html_output_filename );
612
+ $ outputHandler ->clearHtmlFile ();
612
613
break ;
613
614
case '--version ' :
614
615
echo '$Id$ ' . "\n" ;
@@ -691,7 +692,7 @@ function main()
691
692
usort ($ test_files , "test_sort " );
692
693
$ start_time = time ();
693
694
694
- if (!$ html_output ) {
695
+ if (!$ outputHandler -> isHtmlEnabled () ) {
695
696
echo "Running selected tests. \n" ;
696
697
} else {
697
698
show_start ($ start_time );
@@ -701,7 +702,7 @@ function main()
701
702
run_all_tests ($ test_files , $ environment );
702
703
$ end_time = time ();
703
704
704
- if ($ html_output ) {
705
+ if ($ outputHandler -> isHtmlEnabled () ) {
705
706
show_end ($ end_time );
706
707
}
707
708
@@ -719,14 +720,14 @@ function main()
719
720
}
720
721
721
722
compute_summary ();
722
- if ($ html_output ) {
723
- fwrite ( $ html_file , "<hr/> \n" . get_summary (false , true ));
723
+ if ($ outputHandler -> isHtmlEnabled () ) {
724
+ $ outputHandler -> writeHtml ( "<hr/> \n" . get_summary (false , true ));
724
725
}
725
726
echo "===================================================================== " ;
726
727
echo get_summary (false , false );
727
728
728
- if ($ html_output ) {
729
- fclose ( $ html_file ) ;
729
+ if ($ outputHandler -> isHtmlEnabled () ) {
730
+ $ outputHandler -> closeHtmlHandle (); ;
730
731
}
731
732
732
733
if ($ output_file != '' && $ just_save_results ) {
@@ -792,8 +793,8 @@ function main()
792
793
show_end ($ end_time );
793
794
show_summary ();
794
795
795
- if ($ html_output ) {
796
- fclose ( $ html_file );
796
+ if ($ outputHandler -> isHtmlEnabled () ) {
797
+ $ outputHandler -> closeHtmlHandle ( );
797
798
}
798
799
799
800
save_or_mail_results ();
@@ -1282,7 +1283,7 @@ function system_with_timeout($commandline, $env = null, $stdin = null, $captureS
1282
1283
1283
1284
function run_all_tests ($ test_files , $ env , $ redir_tested = null )
1284
1285
{
1285
- global $ test_results , $ failed_tests_file , $ result_tests_file , $ php , $ test_idx , $ file_cache ;
1286
+ global $ test_results , $ failed_tests_file , $ result_tests_file , $ php , $ test_idx , $ file_cache, $ outputHandler ;
1286
1287
// Parallel testing
1287
1288
global $ PHP_FAILED_TESTS , $ workers , $ workerID , $ workerSock ;
1288
1289
@@ -1351,7 +1352,8 @@ function run_all_tests($test_files, $env, $redir_tested = null)
1351
1352
/** The heart of parallel testing. */
1352
1353
function run_all_tests_parallel ($ test_files , $ env , $ redir_tested )
1353
1354
{
1354
- global $ workers , $ test_idx , $ test_cnt , $ test_results , $ failed_tests_file , $ result_tests_file , $ PHP_FAILED_TESTS , $ shuffle , $ SHOW_ONLY_GROUPS , $ valgrind ;
1355
+ global $ workers , $ test_idx , $ test_cnt , $ test_results , $ failed_tests_file , $ result_tests_file , $ PHP_FAILED_TESTS ,
1356
+ $ shuffle , $ SHOW_ONLY_GROUPS , $ valgrind , $ outputHandler ;
1355
1357
1356
1358
// The PHP binary running run-tests.php, and run-tests.php itself
1357
1359
// This PHP executable is *not* necessarily the same as the tested version
@@ -1412,7 +1414,7 @@ function run_all_tests_parallel($test_files, $env, $redir_tested)
1412
1414
// Don't start more workers than test files.
1413
1415
$ workers = max (1 , min ($ workers , count ($ test_files )));
1414
1416
1415
- echo "Spawning workers… " ;
1417
+ echo "Spawning workers ... " ;
1416
1418
1417
1419
// We use sockets rather than STDIN/STDOUT for comms because on Windows,
1418
1420
// those can't be non-blocking for some reason.
@@ -1455,10 +1457,18 @@ function run_all_tests_parallel($test_files, $env, $redir_tested)
1455
1457
error ("Failed to accept connection from worker $ i " );
1456
1458
}
1457
1459
1460
+ $ htmlOutputHandlerSettings = [];
1461
+ if ($ outputHandler ->isHtmlEnabled ()) {
1462
+ $ htmlOutputHandlerSettings ['filename ' ] = $ outputHandler ->getHtmlOutputFilename ();
1463
+ }
1464
+
1458
1465
$ greeting = base64_encode (serialize ([
1459
1466
"type " => "hello " ,
1460
1467
"workerID " => $ i ,
1461
1468
"GLOBALS " => $ GLOBALS ,
1469
+ 'output_handler ' => [
1470
+ 'html ' => $ htmlOutputHandlerSettings
1471
+ ],
1462
1472
"constants " => [
1463
1473
"INIT_DIR " => INIT_DIR ,
1464
1474
"TEST_PHP_SRCDIR " => TEST_PHP_SRCDIR ,
@@ -1688,9 +1698,9 @@ function kill_children(array $children)
1688
1698
}
1689
1699
}
1690
1700
1691
- function run_worker ()
1701
+ function run_worker ($ workerID )
1692
1702
{
1693
- global $ workerID , $ workerSock ;
1703
+ global $ workerSock , $ outputHandler ;
1694
1704
1695
1705
$ sockUri = getenv ("TEST_PHP_URI " );
1696
1706
@@ -1721,6 +1731,10 @@ function run_worker()
1721
1731
define ($ const , $ value );
1722
1732
}
1723
1733
1734
+ if (isset ($ greeting ["output_handler " ]['html ' ]['filename ' ])) {
1735
+ $ outputHandler ->setHtmlOutputFilename ($ greeting ["output_handler " ]['html ' ]['filename ' ]);
1736
+ }
1737
+
1724
1738
send_message ($ workerSock , [
1725
1739
"type " => "hello_reply " ,
1726
1740
"workerID " => $ workerID
@@ -1775,14 +1789,15 @@ function show_file_block($file, $block, $section = null)
1775
1789
//
1776
1790
function run_test ($ php , $ file , $ env )
1777
1791
{
1778
- global $ log_format , $ ini_overwrites , $ PHP_FAILED_TESTS ;
1792
+ global $ outputHandler , $ log_format , $ ini_overwrites , $ PHP_FAILED_TESTS ;
1779
1793
global $ pass_options , $ DETAILED , $ IN_REDIRECT , $ test_cnt , $ test_idx ;
1780
1794
global $ valgrind , $ temp_source , $ temp_target , $ cfg , $ environment ;
1781
1795
global $ no_clean ;
1782
1796
global $ SHOW_ONLY_GROUPS ;
1783
1797
global $ no_file_cache ;
1784
1798
global $ slow_min_ms ;
1785
1799
global $ preload , $ file_cache ;
1800
+
1786
1801
// Parallel testing
1787
1802
global $ workerID ;
1788
1803
$ temp_filenames = null ;
@@ -3187,45 +3202,44 @@ function get_summary($show_ext_summary, $show_html)
3187
3202
3188
3203
function show_start ($ start_time )
3189
3204
{
3190
- global $ html_output , $ html_file ;
3205
+ global $ outputHandler ;
3191
3206
3192
- if ($ html_output ) {
3193
- fwrite ($ html_file , "<h2>Time Start: " . date ('Y-m-d H:i:s ' , $ start_time ) . "</h2> \n" );
3194
- fwrite ($ html_file , "<table> \n" );
3207
+ if ($ outputHandler ->isHtmlEnabled ()) {
3208
+ $ outputHandler ->writeHtml ("<h2>Time Start: " . date ('Y-m-d H:i:s ' , $ start_time ) . "</h2> \n<table> \n" );
3195
3209
}
3196
3210
3197
3211
echo "TIME START " . date ('Y-m-d H:i:s ' , $ start_time ) . "\n===================================================================== \n" ;
3198
3212
}
3199
3213
3200
3214
function show_end ($ end_time )
3201
3215
{
3202
- global $ html_output , $ html_file ;
3216
+ global $ outputHandler ;
3203
3217
3204
- if ($ html_output ) {
3205
- fwrite ( $ html_file , "</table> \n" );
3206
- fwrite ( $ html_file , "<h2>Time End: " . date ('Y-m-d H:i:s ' , $ end_time ) . "</h2> \n" );
3218
+ if ($ outputHandler -> isHtmlEnabled () ) {
3219
+ $ outputHandler -> writeHtml ( "</table> \n" );
3220
+ $ outputHandler -> writeHtml ( "<h2>Time End: " . date ('Y-m-d H:i:s ' , $ end_time ) . "</h2> \n" );
3207
3221
}
3208
3222
3209
3223
echo "===================================================================== \nTIME END " . date ('Y-m-d H:i:s ' , $ end_time ) . "\n" ;
3210
3224
}
3211
3225
3212
3226
function show_summary ()
3213
3227
{
3214
- global $ html_output , $ html_file ;
3228
+ global $ outputHandler ;
3215
3229
3216
- if ($ html_output ) {
3217
- fwrite ( $ html_file , "<hr/> \n" . get_summary (true , true ));
3230
+ if ($ outputHandler -> isHtmlEnabled () ) {
3231
+ $ outputHandler -> writeHtml ( "<hr/> \n" . get_summary (true , true ));
3218
3232
}
3219
3233
3220
3234
echo get_summary (true , false );
3221
3235
}
3222
3236
3223
3237
function show_redirect_start ($ tests , $ tested , $ tested_file )
3224
3238
{
3225
- global $ html_output , $ html_file , $ line_length , $ SHOW_ONLY_GROUPS ;
3239
+ global $ outputHandler , $ line_length , $ SHOW_ONLY_GROUPS ;
3226
3240
3227
- if ($ html_output ) {
3228
- fwrite ( $ html_file , "<tr><td colspan='3'>---> $ tests ( $ tested [ $ tested_file]) begin</td></tr> \n" );
3241
+ if ($ outputHandler -> isHtmlEnabled () ) {
3242
+ $ outputHandler -> writeHtml ( "<tr><td colspan='3'>---> $ tests ( $ tested [ $ tested_file]) begin</td></tr> \n" );
3229
3243
}
3230
3244
3231
3245
if (!$ SHOW_ONLY_GROUPS || in_array ('REDIRECT ' , $ SHOW_ONLY_GROUPS )) {
@@ -3237,10 +3251,10 @@ function show_redirect_start($tests, $tested, $tested_file)
3237
3251
3238
3252
function show_redirect_ends ($ tests , $ tested , $ tested_file )
3239
3253
{
3240
- global $ html_output , $ html_file , $ line_length , $ SHOW_ONLY_GROUPS ;
3254
+ global $ outputHandler , $ line_length , $ SHOW_ONLY_GROUPS ;
3241
3255
3242
- if ($ html_output ) {
3243
- fwrite ( $ html_file , "<tr><td colspan='3'>---> $ tests ( $ tested [ $ tested_file]) done</td></tr> \n" );
3256
+ if ($ outputHandler -> isHtmlEnabled () ) {
3257
+ $ outputHandler -> writeHtml ( "<tr><td colspan='3'>---> $ tests ( $ tested [ $ tested_file]) done</td></tr> \n" );
3244
3258
}
3245
3259
3246
3260
if (!$ SHOW_ONLY_GROUPS || in_array ('REDIRECT ' , $ SHOW_ONLY_GROUPS )) {
@@ -3282,15 +3296,14 @@ function parse_conflicts(string $text): array
3282
3296
3283
3297
function show_result ($ result , $ tested , $ tested_file , $ extra = '' , $ temp_filenames = null )
3284
3298
{
3285
- global $ html_output , $ html_file , $ temp_target , $ temp_urlbase , $ line_length , $ SHOW_ONLY_GROUPS ;
3286
-
3299
+ global $ temp_target , $ temp_urlbase , $ line_length , $ SHOW_ONLY_GROUPS , $ outputHandler ;
3287
3300
if (!$ SHOW_ONLY_GROUPS || in_array ($ result , $ SHOW_ONLY_GROUPS )) {
3288
3301
echo "$ result $ tested [ $ tested_file] $ extra \n" ;
3289
3302
} elseif (!$ SHOW_ONLY_GROUPS ) {
3290
3303
clear_show_test ();
3291
3304
}
3292
3305
3293
- if ($ html_output ) {
3306
+ if ($ outputHandler -> isHtmlEnabled () ) {
3294
3307
if (isset ($ temp_filenames ['file ' ]) && file_exists ($ temp_filenames ['file ' ])) {
3295
3308
$ url = str_replace ($ temp_target , $ temp_urlbase , $ temp_filenames ['file ' ]);
3296
3309
$ tested = "<a href=' $ url'> $ tested</a> " ;
@@ -3321,8 +3334,7 @@ function show_result($result, $tested, $tested_file, $extra = '', $temp_filename
3321
3334
$ mem = " " ;
3322
3335
}
3323
3336
3324
- fwrite (
3325
- $ html_file ,
3337
+ $ outputHandler ->writeHtml (
3326
3338
"<tr> " .
3327
3339
"<td> $ result</td> " .
3328
3340
"<td> $ tested</td> " .
@@ -3692,6 +3704,7 @@ public function wrapCommand($cmd, $memcheck_filename, $check_all)
3692
3704
}
3693
3705
}
3694
3706
3707
+
3695
3708
function init_output_buffers ()
3696
3709
{
3697
3710
// Delete as much output buffers as possible.
@@ -3703,6 +3716,11 @@ function init_output_buffers()
3703
3716
}
3704
3717
}
3705
3718
3719
+ function is_worker_mode ()
3720
+ {
3721
+ return getenv ("TEST_PHP_WORKER " );
3722
+ }
3723
+
3706
3724
function check_proc_open_function_exists ()
3707
3725
{
3708
3726
if (!function_exists ('proc_open ' )) {
@@ -3719,4 +3737,79 @@ function check_proc_open_function_exists()
3719
3737
}
3720
3738
}
3721
3739
3740
+ class OutputHandler
3741
+ {
3742
+
3743
+ /**
3744
+ * @var null|string
3745
+ */
3746
+ private $ htmlOutputFilename = null ;
3747
+
3748
+ /**
3749
+ * @var null|resource
3750
+ */
3751
+ private $ htmlHandle = null ;
3752
+
3753
+ /**
3754
+ * @param string $outputFilename
3755
+ */
3756
+ public function setHtmlOutputFilename ($ outputFilename )
3757
+ {
3758
+ $ this ->htmlOutputFilename = $ outputFilename ;
3759
+ }
3760
+
3761
+ public function clearHtmlFile ()
3762
+ {
3763
+ ftruncate ($ this ->getHtmlFileHandle (), 0 );
3764
+ }
3765
+
3766
+ /**
3767
+ * @return string
3768
+ */
3769
+ public function getHtmlOutputFilename ()
3770
+ {
3771
+ if ($ this ->htmlOutputFilename === null ) {
3772
+ throw new \Exception ('No output filename has been set. ' );
3773
+ }
3774
+
3775
+ return $ this ->htmlOutputFilename ;
3776
+ }
3777
+
3778
+ /**
3779
+ * @return false|resource
3780
+ */
3781
+ public function getHtmlFileHandle ()
3782
+ {
3783
+ if ($ this ->htmlHandle !== null ) {
3784
+ return $ this ->htmlHandle ;
3785
+ }
3786
+
3787
+ $ this ->fileHandle = fopen ($ this ->getHtmlOutputFilename (), 'at+ ' );
3788
+
3789
+ return $ this ->fileHandle ;
3790
+ }
3791
+
3792
+ /**
3793
+ * @return bool
3794
+ */
3795
+ public function isHtmlEnabled ()
3796
+ {
3797
+ return !empty ($ this ->htmlOutputFilename ) && is_resource ($ this ->getHtmlFileHandle ());
3798
+ }
3799
+
3800
+ public function closeHtmlHandle ()
3801
+ {
3802
+ fclose ($ this ->getHtmlFileHandle ());
3803
+ }
3804
+
3805
+ /**
3806
+ * @param $content
3807
+ */
3808
+ public function writeHtml ($ content )
3809
+ {
3810
+ fwrite ($ this ->getHtmlFileHandle (), $ content );
3811
+ }
3812
+
3813
+ }
3814
+
3722
3815
main ();
0 commit comments