31
31
* Minimum required PHP version: 7.0.0
32
32
*/
33
33
34
- function show_usage ()
34
+ function show_usage (): void
35
35
{
36
36
echo <<<HELP
37
37
Synopsis:
@@ -146,10 +146,9 @@ function main()
146
146
147
147
define ('IS_WINDOWS ' , substr (PHP_OS , 0 , 3 ) == "WIN " );
148
148
149
- $ workerID = 0 ;
150
- if (getenv ("TEST_PHP_WORKER " )) {
151
- $ workerID = intval (getenv ("TEST_PHP_WORKER " ));
152
- run_worker ();
149
+ $ workerID = get_worker_id ();
150
+ if ($ workerID ) {
151
+ run_worker ($ workerID );
153
152
return ;
154
153
}
155
154
@@ -443,18 +442,11 @@ function main()
443
442
444
443
switch ($ switch ) {
445
444
case 'j ' :
446
- $ workers = substr ($ argv [$ i ], 2 );
447
- if (!preg_match ('/^\d+$/ ' , $ workers ) || $ workers == 0 ) {
448
- error ("' $ workers' is not a valid number of workers, try e.g. -j16 for 16 workers " );
449
- }
450
- $ workers = intval ($ workers , 10 );
451
- // Don't use parallel testing infrastructure if there is only one worker.
452
- if ($ workers === 1 ) {
453
- $ workers = null ;
454
- }
445
+ $ workers = get_number_of_workers ($ argv [$ i ]);
455
446
break ;
456
447
case 'r ' :
457
448
case 'l ' :
449
+ // @Dragoonis
458
450
$ test_list = file ($ argv [++$ i ]);
459
451
if ($ test_list ) {
460
452
foreach ($ test_list as $ test ) {
@@ -1080,7 +1072,7 @@ function test_sort($a, $b)
1080
1072
// Send Email to QA Team
1081
1073
//
1082
1074
1083
- function mail_qa_team ($ data , $ status = false )
1075
+ function mail_qa_team ($ data , $ status = false ): bool
1084
1076
{
1085
1077
$ url_bits = parse_url (QA_SUBMISSION_PAGE );
1086
1078
@@ -1119,7 +1111,7 @@ function mail_qa_team($data, $status = false)
1119
1111
fwrite ($ fs , "\r\n\r\n" );
1120
1112
fclose ($ fs );
1121
1113
1122
- return 1 ;
1114
+ return true ;
1123
1115
}
1124
1116
1125
1117
//
@@ -1381,7 +1373,7 @@ function run_all_tests_parallel($test_files, $env, $redir_tested)
1381
1373
}
1382
1374
1383
1375
// Don't start more workers than test files.
1384
- $ workers = max ( 1 , min ( $ workers , count ( $ test_files)) );
1376
+ $ workers = get_max_workers_from_test_files ( $ workers , $ test_files );
1385
1377
1386
1378
echo "Spawning $ workers workers... " ;
1387
1379
@@ -1643,15 +1635,15 @@ function run_all_tests_parallel($test_files, $env, $redir_tested)
1643
1635
}
1644
1636
}
1645
1637
1646
- function send_message ($ stream , array $ message )
1638
+ function send_message ($ stream , array $ message ): void
1647
1639
{
1648
1640
$ blocking = stream_get_meta_data ($ stream )["blocked " ];
1649
1641
stream_set_blocking ($ stream , true );
1650
1642
fwrite ($ stream , base64_encode (serialize ($ message )) . "\n" );
1651
1643
stream_set_blocking ($ stream , $ blocking );
1652
1644
}
1653
1645
1654
- function kill_children (array $ children )
1646
+ function kill_children (array $ children ): void
1655
1647
{
1656
1648
foreach ($ children as $ child ) {
1657
1649
if ($ child ) {
@@ -1660,9 +1652,9 @@ function kill_children(array $children)
1660
1652
}
1661
1653
}
1662
1654
1663
- function run_worker ()
1655
+ function run_worker ($ workerID ): void
1664
1656
{
1665
- global $ workerID , $ workerSock ;
1657
+ global $ workerSock ;
1666
1658
1667
1659
$ sockUri = getenv ("TEST_PHP_URI " );
1668
1660
@@ -1819,15 +1811,7 @@ function run_test($php, $file, $env)
1819
1811
}
1820
1812
1821
1813
// check for unknown sections
1822
- if (!in_array ($ section , array (
1823
- 'EXPECT ' , 'EXPECTF ' , 'EXPECTREGEX ' , 'EXPECTREGEX_EXTERNAL ' , 'EXPECT_EXTERNAL ' , 'EXPECTF_EXTERNAL ' , 'EXPECTHEADERS ' ,
1824
- 'POST ' , 'POST_RAW ' , 'GZIP_POST ' , 'DEFLATE_POST ' , 'PUT ' , 'GET ' , 'COOKIE ' , 'ARGS ' ,
1825
- 'FILE ' , 'FILEEOF ' , 'FILE_EXTERNAL ' , 'REDIRECTTEST ' ,
1826
- 'CAPTURE_STDIO ' , 'STDIN ' , 'CGI ' , 'PHPDBG ' ,
1827
- 'INI ' , 'ENV ' , 'EXTENSIONS ' ,
1828
- 'SKIPIF ' , 'XFAIL ' , 'XLEAK ' , 'CLEAN ' ,
1829
- 'CREDITS ' , 'DESCRIPTION ' , 'CONFLICTS ' , 'WHITESPACE_SENSITIVE ' ,
1830
- ))) {
1814
+ if (is_section_unknown ($ section )) {
1831
1815
$ bork_info = 'Unknown section " ' . $ section . '" ' ;
1832
1816
}
1833
1817
@@ -3613,4 +3597,49 @@ function check_proc_open_function_exists()
3613
3597
}
3614
3598
}
3615
3599
3600
+
3601
+
3602
+
3603
+ function get_number_of_workers ($ workers ): int
3604
+ {
3605
+ $ cleanWorkers = substr ($ workers , 2 );
3606
+ if (!preg_match ('/^\d+$/ ' , $ cleanWorkers ) || $ cleanWorkers == 0 ) {
3607
+ error ("' $ workers' is not a valid number of workers, try e.g. -j16 for 16 workers " );
3608
+ }
3609
+ $ cleanWorkers = intval ($ cleanWorkers , 10 );
3610
+ // Don't use parallel testing infrastructure if there is only one worker.
3611
+ if ($ cleanWorkers === 1 ) {
3612
+ $ cleanWorkers = null ;
3613
+ }
3614
+
3615
+ return $ cleanWorkers ;
3616
+ }
3617
+
3618
+ function get_max_workers_from_test_files ($ workers , $ test_files ): int
3619
+ {
3620
+ return max (1 , min ($ workers , count ($ test_files )));
3621
+ }
3622
+
3623
+ function get_worker_id (): int
3624
+ {
3625
+ if (!getenv ("TEST_PHP_WORKER " )) {
3626
+ return 0 ;
3627
+ }
3628
+
3629
+ return intval (getenv ("TEST_PHP_WORKER " ));
3630
+ }
3631
+
3632
+ function is_section_unknown (string $ section ): bool
3633
+ {
3634
+ return !in_array ($ section , array (
3635
+ 'EXPECT ' , 'EXPECTF ' , 'EXPECTREGEX ' , 'EXPECTREGEX_EXTERNAL ' , 'EXPECT_EXTERNAL ' , 'EXPECTF_EXTERNAL ' , 'EXPECTHEADERS ' ,
3636
+ 'POST ' , 'POST_RAW ' , 'GZIP_POST ' , 'DEFLATE_POST ' , 'PUT ' , 'GET ' , 'COOKIE ' , 'ARGS ' ,
3637
+ 'FILE ' , 'FILEEOF ' , 'FILE_EXTERNAL ' , 'REDIRECTTEST ' ,
3638
+ 'CAPTURE_STDIO ' , 'STDIN ' , 'CGI ' , 'PHPDBG ' ,
3639
+ 'INI ' , 'ENV ' , 'EXTENSIONS ' ,
3640
+ 'SKIPIF ' , 'XFAIL ' , 'XLEAK ' , 'CLEAN ' ,
3641
+ 'CREDITS ' , 'DESCRIPTION ' , 'CONFLICTS ' , 'WHITESPACE_SENSITIVE ' ,
3642
+ ));
3643
+ }
3644
+
3616
3645
main ();
0 commit comments