Skip to content

Commit be6e80c

Browse files
committed
Test Suite Cleanups
1 parent 6bc375f commit be6e80c

File tree

1 file changed

+59
-30
lines changed

1 file changed

+59
-30
lines changed

run-tests.php

Lines changed: 59 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* Minimum required PHP version: 7.0.0
3232
*/
3333

34-
function show_usage()
34+
function show_usage(): void
3535
{
3636
echo <<<HELP
3737
Synopsis:
@@ -146,10 +146,9 @@ function main()
146146

147147
define('IS_WINDOWS', substr(PHP_OS, 0, 3) == "WIN");
148148

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);
153152
return;
154153
}
155154

@@ -443,18 +442,11 @@ function main()
443442

444443
switch ($switch) {
445444
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]);
455446
break;
456447
case 'r':
457448
case 'l':
449+
// @Dragoonis
458450
$test_list = file($argv[++$i]);
459451
if ($test_list) {
460452
foreach ($test_list as $test) {
@@ -1080,7 +1072,7 @@ function test_sort($a, $b)
10801072
// Send Email to QA Team
10811073
//
10821074

1083-
function mail_qa_team($data, $status = false)
1075+
function mail_qa_team($data, $status = false): bool
10841076
{
10851077
$url_bits = parse_url(QA_SUBMISSION_PAGE);
10861078

@@ -1119,7 +1111,7 @@ function mail_qa_team($data, $status = false)
11191111
fwrite($fs, "\r\n\r\n");
11201112
fclose($fs);
11211113

1122-
return 1;
1114+
return true;
11231115
}
11241116

11251117
//
@@ -1381,7 +1373,7 @@ function run_all_tests_parallel($test_files, $env, $redir_tested)
13811373
}
13821374

13831375
// 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);
13851377

13861378
echo "Spawning $workers workers... ";
13871379

@@ -1643,15 +1635,15 @@ function run_all_tests_parallel($test_files, $env, $redir_tested)
16431635
}
16441636
}
16451637

1646-
function send_message($stream, array $message)
1638+
function send_message($stream, array $message): void
16471639
{
16481640
$blocking = stream_get_meta_data($stream)["blocked"];
16491641
stream_set_blocking($stream, true);
16501642
fwrite($stream, base64_encode(serialize($message)) . "\n");
16511643
stream_set_blocking($stream, $blocking);
16521644
}
16531645

1654-
function kill_children(array $children)
1646+
function kill_children(array $children): void
16551647
{
16561648
foreach ($children as $child) {
16571649
if ($child) {
@@ -1660,9 +1652,9 @@ function kill_children(array $children)
16601652
}
16611653
}
16621654

1663-
function run_worker()
1655+
function run_worker($workerID): void
16641656
{
1665-
global $workerID, $workerSock;
1657+
global $workerSock;
16661658

16671659
$sockUri = getenv("TEST_PHP_URI");
16681660

@@ -1819,15 +1811,7 @@ function run_test($php, $file, $env)
18191811
}
18201812

18211813
// 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)) {
18311815
$bork_info = 'Unknown section "' . $section . '"';
18321816
}
18331817

@@ -3613,4 +3597,49 @@ function check_proc_open_function_exists()
36133597
}
36143598
}
36153599

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+
36163645
main();

0 commit comments

Comments
 (0)