@@ -122,6 +122,8 @@ function show_usage()
122
122
HELP ;
123
123
}
124
124
125
+ include ('tests-util/OutputHandler.php ' );
126
+
125
127
/**
126
128
* One function to rule them all, one function to find them, one function to
127
129
* bring them all and in the darkness bind them.
@@ -137,23 +139,25 @@ function main()
137
139
global $ DETAILED , $ PHP_FAILED_TESTS , $ SHOW_ONLY_GROUPS , $ argc , $ argv , $ cfg ,
138
140
$ cfgfiles , $ cfgtypes , $ conf_passed , $ end_time , $ environment ,
139
141
$ exts_skipped , $ exts_tested , $ exts_to_test , $ failed_tests_file ,
140
- $ html_file , $ html_output , $ ignored_by_ext , $ ini_overwrites , $ is_switch ,
142
+ $ ignored_by_ext , $ ini_overwrites , $ is_switch ,
141
143
$ just_save_results , $ log_format , $ matches , $ no_clean , $ no_file_cache ,
142
144
$ optionals , $ output_file , $ pass_option_n , $ pass_options ,
143
145
$ pattern_match , $ php , $ php_cgi , $ phpdbg , $ preload , $ redir_tests ,
144
146
$ repeat , $ result_tests_file , $ slow_min_ms , $ start_time , $ switch ,
145
147
$ temp_source , $ temp_target , $ temp_urlbase , $ test_cnt , $ test_dirs ,
146
148
$ test_files , $ test_idx , $ test_list , $ test_results , $ testfile ,
147
- $ user_tests , $ valgrind , $ sum_results , $ shuffle , $ file_cache ;
149
+ $ user_tests , $ valgrind , $ sum_results , $ shuffle , $ file_cache, $ outputHandler ;
148
150
// Parallel testing
149
151
global $ workers , $ workerID ;
150
152
151
153
define ('IS_WINDOWS ' , substr (PHP_OS , 0 , 3 ) == "WIN " );
152
154
155
+ $ outputHandler = new OutputHandler ();
156
+
153
157
$ workerID = 0 ;
154
- if (getenv ( " TEST_PHP_WORKER " )) {
158
+ if (is_worker_mode ( )) {
155
159
$ workerID = intval (getenv ("TEST_PHP_WORKER " ));
156
- run_worker ();
160
+ run_worker ($ workerID );
157
161
return ;
158
162
}
159
163
@@ -378,8 +382,6 @@ function main()
378
382
379
383
$ just_save_results = false ;
380
384
$ valgrind = null ;
381
- $ html_output = false ;
382
- $ html_file = null ;
383
385
$ temp_source = null ;
384
386
$ temp_target = null ;
385
387
$ temp_urlbase = null ;
@@ -607,8 +609,9 @@ function main()
607
609
}
608
610
break ;
609
611
case '--html ' :
610
- $ html_file = fopen ($ argv [++$ i ], 'wt ' );
611
- $ html_output = is_resource ($ html_file );
612
+ $ html_output_filename = $ argv [++$ i ];
613
+ $ outputHandler ->setHtmlOutputFilename ($ html_output_filename );
614
+ $ outputHandler ->clearHtmlFile ();
612
615
break ;
613
616
case '--version ' :
614
617
echo '$Id$ ' . "\n" ;
@@ -691,7 +694,7 @@ function main()
691
694
usort ($ test_files , "test_sort " );
692
695
$ start_time = time ();
693
696
694
- if (!$ html_output ) {
697
+ if (!$ outputHandler -> isHtmlEnabled () ) {
695
698
echo "Running selected tests. \n" ;
696
699
} else {
697
700
show_start ($ start_time );
@@ -701,7 +704,7 @@ function main()
701
704
run_all_tests ($ test_files , $ environment );
702
705
$ end_time = time ();
703
706
704
- if ($ html_output ) {
707
+ if ($ outputHandler -> isHtmlEnabled () ) {
705
708
show_end ($ end_time );
706
709
}
707
710
@@ -719,14 +722,14 @@ function main()
719
722
}
720
723
721
724
compute_summary ();
722
- if ($ html_output ) {
723
- fwrite ( $ html_file , "<hr/> \n" . get_summary (false , true ));
725
+ if ($ outputHandler -> isHtmlEnabled () ) {
726
+ $ outputHandler -> writeHtml ( "<hr/> \n" . get_summary (false , true ));
724
727
}
725
728
echo "===================================================================== " ;
726
729
echo get_summary (false , false );
727
730
728
- if ($ html_output ) {
729
- fclose ( $ html_file ) ;
731
+ if ($ outputHandler -> isHtmlEnabled () ) {
732
+ $ outputHandler -> closeHtmlHandle (); ;
730
733
}
731
734
732
735
if ($ output_file != '' && $ just_save_results ) {
@@ -792,8 +795,8 @@ function main()
792
795
show_end ($ end_time );
793
796
show_summary ();
794
797
795
- if ($ html_output ) {
796
- fclose ( $ html_file );
798
+ if ($ outputHandler -> isHtmlEnabled () ) {
799
+ $ outputHandler -> closeHtmlHandle ( );
797
800
}
798
801
799
802
save_or_mail_results ();
@@ -1282,7 +1285,7 @@ function system_with_timeout($commandline, $env = null, $stdin = null, $captureS
1282
1285
1283
1286
function run_all_tests ($ test_files , $ env , $ redir_tested = null )
1284
1287
{
1285
- global $ test_results , $ failed_tests_file , $ result_tests_file , $ php , $ test_idx , $ file_cache ;
1288
+ global $ test_results , $ failed_tests_file , $ result_tests_file , $ php , $ test_idx , $ file_cache, $ outputHandler ;
1286
1289
// Parallel testing
1287
1290
global $ PHP_FAILED_TESTS , $ workers , $ workerID , $ workerSock ;
1288
1291
@@ -1351,7 +1354,8 @@ function run_all_tests($test_files, $env, $redir_tested = null)
1351
1354
/** The heart of parallel testing. */
1352
1355
function run_all_tests_parallel ($ test_files , $ env , $ redir_tested )
1353
1356
{
1354
- global $ workers , $ test_idx , $ test_cnt , $ test_results , $ failed_tests_file , $ result_tests_file , $ PHP_FAILED_TESTS , $ shuffle , $ SHOW_ONLY_GROUPS , $ valgrind ;
1357
+ global $ workers , $ test_idx , $ test_cnt , $ test_results , $ failed_tests_file , $ result_tests_file , $ PHP_FAILED_TESTS ,
1358
+ $ shuffle , $ SHOW_ONLY_GROUPS , $ valgrind , $ outputHandler ;
1355
1359
1356
1360
// The PHP binary running run-tests.php, and run-tests.php itself
1357
1361
// This PHP executable is *not* necessarily the same as the tested version
@@ -1412,7 +1416,7 @@ function run_all_tests_parallel($test_files, $env, $redir_tested)
1412
1416
// Don't start more workers than test files.
1413
1417
$ workers = max (1 , min ($ workers , count ($ test_files )));
1414
1418
1415
- echo "Spawning workers… " ;
1419
+ echo "Spawning workers ... " ;
1416
1420
1417
1421
// We use sockets rather than STDIN/STDOUT for comms because on Windows,
1418
1422
// those can't be non-blocking for some reason.
@@ -1455,10 +1459,18 @@ function run_all_tests_parallel($test_files, $env, $redir_tested)
1455
1459
error ("Failed to accept connection from worker $ i " );
1456
1460
}
1457
1461
1462
+ $ htmlOutputHandlerSettings = [];
1463
+ if ($ outputHandler ->isHtmlEnabled ()) {
1464
+ $ htmlOutputHandlerSettings ['filename ' ] = $ outputHandler ->getHtmlOutputFilename ();
1465
+ }
1466
+
1458
1467
$ greeting = base64_encode (serialize ([
1459
1468
"type " => "hello " ,
1460
1469
"workerID " => $ i ,
1461
1470
"GLOBALS " => $ GLOBALS ,
1471
+ 'output_handler ' => [
1472
+ 'html ' => $ htmlOutputHandlerSettings
1473
+ ],
1462
1474
"constants " => [
1463
1475
"INIT_DIR " => INIT_DIR ,
1464
1476
"TEST_PHP_SRCDIR " => TEST_PHP_SRCDIR ,
@@ -1688,9 +1700,9 @@ function kill_children(array $children)
1688
1700
}
1689
1701
}
1690
1702
1691
- function run_worker ()
1703
+ function run_worker ($ workerID )
1692
1704
{
1693
- global $ workerID , $ workerSock ;
1705
+ global $ workerSock , $ outputHandler ;
1694
1706
1695
1707
$ sockUri = getenv ("TEST_PHP_URI " );
1696
1708
@@ -1721,6 +1733,10 @@ function run_worker()
1721
1733
define ($ const , $ value );
1722
1734
}
1723
1735
1736
+ if (isset ($ greeting ["output_handler " ]['html ' ]['filename ' ])) {
1737
+ $ outputHandler ->setHtmlOutputFilename ($ greeting ["output_handler " ]['html ' ]['filename ' ]);
1738
+ }
1739
+
1724
1740
send_message ($ workerSock , [
1725
1741
"type " => "hello_reply " ,
1726
1742
"workerID " => $ workerID
@@ -1775,14 +1791,15 @@ function show_file_block($file, $block, $section = null)
1775
1791
//
1776
1792
function run_test ($ php , $ file , $ env )
1777
1793
{
1778
- global $ log_format , $ ini_overwrites , $ PHP_FAILED_TESTS ;
1794
+ global $ outputHandler , $ log_format , $ ini_overwrites , $ PHP_FAILED_TESTS ;
1779
1795
global $ pass_options , $ DETAILED , $ IN_REDIRECT , $ test_cnt , $ test_idx ;
1780
1796
global $ valgrind , $ temp_source , $ temp_target , $ cfg , $ environment ;
1781
1797
global $ no_clean ;
1782
1798
global $ SHOW_ONLY_GROUPS ;
1783
1799
global $ no_file_cache ;
1784
1800
global $ slow_min_ms ;
1785
1801
global $ preload , $ file_cache ;
1802
+
1786
1803
// Parallel testing
1787
1804
global $ workerID ;
1788
1805
$ temp_filenames = null ;
@@ -3187,45 +3204,44 @@ function get_summary($show_ext_summary, $show_html)
3187
3204
3188
3205
function show_start ($ start_time )
3189
3206
{
3190
- global $ html_output , $ html_file ;
3207
+ global $ outputHandler ;
3191
3208
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" );
3209
+ if ($ outputHandler ->isHtmlEnabled ()) {
3210
+ $ outputHandler ->writeHtml ("<h2>Time Start: " . date ('Y-m-d H:i:s ' , $ start_time ) . "</h2> \n<table> \n" );
3195
3211
}
3196
3212
3197
3213
echo "TIME START " . date ('Y-m-d H:i:s ' , $ start_time ) . "\n===================================================================== \n" ;
3198
3214
}
3199
3215
3200
3216
function show_end ($ end_time )
3201
3217
{
3202
- global $ html_output , $ html_file ;
3218
+ global $ outputHandler ;
3203
3219
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" );
3220
+ if ($ outputHandler -> isHtmlEnabled () ) {
3221
+ $ outputHandler -> writeHtml ( "</table> \n" );
3222
+ $ outputHandler -> writeHtml ( "<h2>Time End: " . date ('Y-m-d H:i:s ' , $ end_time ) . "</h2> \n" );
3207
3223
}
3208
3224
3209
3225
echo "===================================================================== \nTIME END " . date ('Y-m-d H:i:s ' , $ end_time ) . "\n" ;
3210
3226
}
3211
3227
3212
3228
function show_summary ()
3213
3229
{
3214
- global $ html_output , $ html_file ;
3230
+ global $ outputHandler ;
3215
3231
3216
- if ($ html_output ) {
3217
- fwrite ( $ html_file , "<hr/> \n" . get_summary (true , true ));
3232
+ if ($ outputHandler -> isHtmlEnabled () ) {
3233
+ $ outputHandler -> writeHtml ( "<hr/> \n" . get_summary (true , true ));
3218
3234
}
3219
3235
3220
3236
echo get_summary (true , false );
3221
3237
}
3222
3238
3223
3239
function show_redirect_start ($ tests , $ tested , $ tested_file )
3224
3240
{
3225
- global $ html_output , $ html_file , $ line_length , $ SHOW_ONLY_GROUPS ;
3241
+ global $ outputHandler , $ line_length , $ SHOW_ONLY_GROUPS ;
3226
3242
3227
- if ($ html_output ) {
3228
- fwrite ( $ html_file , "<tr><td colspan='3'>---> $ tests ( $ tested [ $ tested_file]) begin</td></tr> \n" );
3243
+ if ($ outputHandler -> isHtmlEnabled () ) {
3244
+ $ outputHandler -> writeHtml ( "<tr><td colspan='3'>---> $ tests ( $ tested [ $ tested_file]) begin</td></tr> \n" );
3229
3245
}
3230
3246
3231
3247
if (!$ SHOW_ONLY_GROUPS || in_array ('REDIRECT ' , $ SHOW_ONLY_GROUPS )) {
@@ -3237,10 +3253,10 @@ function show_redirect_start($tests, $tested, $tested_file)
3237
3253
3238
3254
function show_redirect_ends ($ tests , $ tested , $ tested_file )
3239
3255
{
3240
- global $ html_output , $ html_file , $ line_length , $ SHOW_ONLY_GROUPS ;
3256
+ global $ outputHandler , $ line_length , $ SHOW_ONLY_GROUPS ;
3241
3257
3242
- if ($ html_output ) {
3243
- fwrite ( $ html_file , "<tr><td colspan='3'>---> $ tests ( $ tested [ $ tested_file]) done</td></tr> \n" );
3258
+ if ($ outputHandler -> isHtmlEnabled () ) {
3259
+ $ outputHandler -> writeHtml ( "<tr><td colspan='3'>---> $ tests ( $ tested [ $ tested_file]) done</td></tr> \n" );
3244
3260
}
3245
3261
3246
3262
if (!$ SHOW_ONLY_GROUPS || in_array ('REDIRECT ' , $ SHOW_ONLY_GROUPS )) {
@@ -3282,15 +3298,14 @@ function parse_conflicts(string $text): array
3282
3298
3283
3299
function show_result ($ result , $ tested , $ tested_file , $ extra = '' , $ temp_filenames = null )
3284
3300
{
3285
- global $ html_output , $ html_file , $ temp_target , $ temp_urlbase , $ line_length , $ SHOW_ONLY_GROUPS ;
3286
-
3301
+ global $ temp_target , $ temp_urlbase , $ line_length , $ SHOW_ONLY_GROUPS , $ outputHandler ;
3287
3302
if (!$ SHOW_ONLY_GROUPS || in_array ($ result , $ SHOW_ONLY_GROUPS )) {
3288
3303
echo "$ result $ tested [ $ tested_file] $ extra \n" ;
3289
3304
} elseif (!$ SHOW_ONLY_GROUPS ) {
3290
3305
clear_show_test ();
3291
3306
}
3292
3307
3293
- if ($ html_output ) {
3308
+ if ($ outputHandler -> isHtmlEnabled () ) {
3294
3309
if (isset ($ temp_filenames ['file ' ]) && file_exists ($ temp_filenames ['file ' ])) {
3295
3310
$ url = str_replace ($ temp_target , $ temp_urlbase , $ temp_filenames ['file ' ]);
3296
3311
$ tested = "<a href=' $ url'> $ tested</a> " ;
@@ -3321,8 +3336,7 @@ function show_result($result, $tested, $tested_file, $extra = '', $temp_filename
3321
3336
$ mem = " " ;
3322
3337
}
3323
3338
3324
- fwrite (
3325
- $ html_file ,
3339
+ $ outputHandler ->writeHtml (
3326
3340
"<tr> " .
3327
3341
"<td> $ result</td> " .
3328
3342
"<td> $ tested</td> " .
@@ -3703,6 +3717,11 @@ function init_output_buffers()
3703
3717
}
3704
3718
}
3705
3719
3720
+ function is_worker_mode ()
3721
+ {
3722
+ return getenv ("TEST_PHP_WORKER " );
3723
+ }
3724
+
3706
3725
function check_proc_open_function_exists ()
3707
3726
{
3708
3727
if (!function_exists ('proc_open ' )) {
0 commit comments