From b4ace616b2ad003acf71e2707b3092419048b2c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Wed, 16 Oct 2024 11:29:32 +0200 Subject: [PATCH 1/7] run-tests: Fix getting stuck when the test process dies uncleanly When a test process spawns a subprocess that keeps STDOUT open and then dies uncleanly, while writing something to STDERR `run-tests.php` would erroneously attempt to read from `STDOUT` and then get blocked until the subprocess dies (which might never happen). --- .../run-tests_stuck_when_subprocess_exists.phpt | 16 ++++++++++++++++ run-tests.php | 8 ++++---- 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 ext/zend_test/tests/run-tests_stuck_when_subprocess_exists.phpt diff --git a/ext/zend_test/tests/run-tests_stuck_when_subprocess_exists.phpt b/ext/zend_test/tests/run-tests_stuck_when_subprocess_exists.phpt new file mode 100644 index 0000000000000..51d49cf65376b --- /dev/null +++ b/ext/zend_test/tests/run-tests_stuck_when_subprocess_exists.phpt @@ -0,0 +1,16 @@ +--TEST-- +run-tests: Does not get stuck when a test spawns a subprocess and dies uncleanly. +--EXTENSIONS-- +posix +--FILE-- + +--EXPECTF-- +foo%A +Termsig=9 diff --git a/run-tests.php b/run-tests.php index 5add428aaddc5..d2f56aea7df4e 100755 --- a/run-tests.php +++ b/run-tests.php @@ -1229,10 +1229,10 @@ function system_with_timeout( } if ($n > 0) { - if ($captureStdOut) { - $line = fread($pipes[1], 8192); - } elseif ($captureStdErr) { - $line = fread($pipes[2], 8192); + if ($captureStdOut && isset($r[1])) { + $line = fread($r[1], 8192); + } elseif ($captureStdErr && isset($r[2])) { + $line = fread($r[2], 8192); } else { $line = ''; } From fa40c223140233adad214092a7c1a8f742e6673a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Wed, 16 Oct 2024 11:54:38 +0200 Subject: [PATCH 2/7] Unbreak SKIPIF --- ext/openssl/tests/stream_server_reneg_limit.phpt | 2 +- ext/phar/tests/tar/bug70417.phpt | 2 +- ext/standard/tests/file/bug81145.phpt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/openssl/tests/stream_server_reneg_limit.phpt b/ext/openssl/tests/stream_server_reneg_limit.phpt index d661e9dc42331..02fdea822488e 100644 --- a/ext/openssl/tests/stream_server_reneg_limit.phpt +++ b/ext/openssl/tests/stream_server_reneg_limit.phpt @@ -5,7 +5,7 @@ openssl --SKIPIF-- /dev/null', $out, $code); if ($code > 0) die("skip couldn't locate openssl binary"); if(substr(PHP_OS, 0, 3) == 'WIN') { die('skip not suitable for Windows'); diff --git a/ext/phar/tests/tar/bug70417.phpt b/ext/phar/tests/tar/bug70417.phpt index 4d98a18954cc3..1189978761816 100644 --- a/ext/phar/tests/tar/bug70417.phpt +++ b/ext/phar/tests/tar/bug70417.phpt @@ -6,7 +6,7 @@ zlib --SKIPIF-- /dev/null', $out, $status); if ($status !== 0) { die("skip lsof(8) not available"); } diff --git a/ext/standard/tests/file/bug81145.phpt b/ext/standard/tests/file/bug81145.phpt index f3258ff6019e9..b57633a09022d 100644 --- a/ext/standard/tests/file/bug81145.phpt +++ b/ext/standard/tests/file/bug81145.phpt @@ -8,7 +8,7 @@ if (disk_free_space(__DIR__) < 0x220000000) die("skip insuffient disk space"); if (PHP_OS_FAMILY !== "Windows") { $src = __DIR__ . "/bug81145_src.bin"; define('SIZE_4G', 0x100000000); - exec("fallocate -l " . (SIZE_4G-0x100) . " " . escapeshellarg($src), $output, $status); + exec("fallocate -l " . (SIZE_4G-0x100) . " " . escapeshellarg($src) . " 2> /dev/null", $output, $status); if ($status !== 0) die("skip fallocate() not supported"); @unlink(__DIR__ . "/bug81145_src.bin"); } From ba180e6b9c94664989e38be2746a0fc2847d2603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Wed, 16 Oct 2024 11:57:20 +0200 Subject: [PATCH 3/7] Install lsof in CI --- .github/actions/apt-x32/action.yml | 1 + .github/actions/apt-x64/action.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/actions/apt-x32/action.yml b/.github/actions/apt-x32/action.yml index 879300f992747..9dbccdbc7934d 100644 --- a/.github/actions/apt-x32/action.yml +++ b/.github/actions/apt-x32/action.yml @@ -45,6 +45,7 @@ runs: libxslt1-dev:i386 \ libzip-dev:i386 \ locales \ + lsof \ make \ pkg-config:i386 \ re2c \ diff --git a/.github/actions/apt-x64/action.yml b/.github/actions/apt-x64/action.yml index 4e1a03dd58cc5..17c8d13344932 100644 --- a/.github/actions/apt-x64/action.yml +++ b/.github/actions/apt-x64/action.yml @@ -13,6 +13,7 @@ runs: locales \ ldap-utils \ openssl \ + lsof \ slapd \ language-pack-de \ libgmp-dev \ From f2dec0b9d57f264560f1bb0fb151fc98836a2b11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Wed, 16 Oct 2024 12:29:24 +0200 Subject: [PATCH 4/7] Make SNMP shut up properly --- ext/snmp/snmp.c | 14 +++++++------- ext/snmp/tests/bug64159.phpt | 2 -- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c index 299d2d8fd08c8..b3711204ef642 100644 --- a/ext/snmp/snmp.c +++ b/ext/snmp/snmp.c @@ -1997,6 +1997,13 @@ PHP_MINIT_FUNCTION(snmp) { netsnmp_log_handler *logh; + /* Disable logging, use exit status'es and related variabled to detect errors */ + shutdown_snmp_logging(); + logh = netsnmp_register_loghandler(NETSNMP_LOGHANDLER_NONE, LOG_ERR); + if (logh) { + logh->pri_max = LOG_ERR; + } + init_snmp("snmpapp"); /* net-snmp corrupts the CTYPE locale during initialization. */ zend_reset_lc_ctype_locale(); @@ -2006,13 +2013,6 @@ PHP_MINIT_FUNCTION(snmp) netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PERSIST_STATE, 1); #endif - /* Disable logging, use exit status'es and related variabled to detect errors */ - shutdown_snmp_logging(); - logh = netsnmp_register_loghandler(NETSNMP_LOGHANDLER_NONE, LOG_ERR); - if (logh) { - logh->pri_max = LOG_ERR; - } - memcpy(&php_snmp_object_handlers, &std_object_handlers, sizeof(zend_object_handlers)); php_snmp_object_handlers.read_property = php_snmp_read_property; php_snmp_object_handlers.write_property = php_snmp_write_property; diff --git a/ext/snmp/tests/bug64159.phpt b/ext/snmp/tests/bug64159.phpt index e7cdbd5437796..74a3e3a93e6d9 100644 --- a/ext/snmp/tests/bug64159.phpt +++ b/ext/snmp/tests/bug64159.phpt @@ -22,6 +22,4 @@ var_dump(("ab8283f948419b2d24d22f44a80b17d3" === md5(snmpget($hostname, $communi ?> --EXPECTF-- -MIB search path: %s -Cannot find module (noneXistent): At line %d in (%s) bool(true) From f5973c82bafdda65fdba554b79152604e38d2a2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Wed, 16 Oct 2024 12:34:09 +0200 Subject: [PATCH 5/7] Try to fix FreeBSD? --- run-tests.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/run-tests.php b/run-tests.php index d2f56aea7df4e..8dd7a2eb8d686 100755 --- a/run-tests.php +++ b/run-tests.php @@ -1229,10 +1229,10 @@ function system_with_timeout( } if ($n > 0) { - if ($captureStdOut && isset($r[1])) { - $line = fread($r[1], 8192); - } elseif ($captureStdErr && isset($r[2])) { - $line = fread($r[2], 8192); + if ($captureStdOut && \in_array($pipes[1], $r)) { + $line = fread($pipes[1], 8192); + } elseif ($captureStdErr && in_array($pipes[2], $r)) { + $line = fread($pipes[2], 8192); } else { $line = ''; } From 94df160347ef0e18083ea02f9fdd07d73372f1aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 5 Nov 2024 15:13:00 +0100 Subject: [PATCH 6/7] Fix EOF handling --- run-tests.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/run-tests.php b/run-tests.php index 8dd7a2eb8d686..34194cb97414c 100755 --- a/run-tests.php +++ b/run-tests.php @@ -1209,7 +1209,7 @@ function system_with_timeout( $timeout *= 3; } - while (true) { + do { /* hide errors from interrupted syscalls */ $r = $pipes; $w = null; @@ -1229,20 +1229,16 @@ function system_with_timeout( } if ($n > 0) { - if ($captureStdOut && \in_array($pipes[1], $r)) { + if ($captureStdOut && in_array($pipes[1], $r)) { $line = fread($pipes[1], 8192); } elseif ($captureStdErr && in_array($pipes[2], $r)) { $line = fread($pipes[2], 8192); } else { $line = ''; } - if (strlen($line) == 0) { - /* EOF */ - break; - } $data .= $line; } - } + } while (!feof($pipes[1]) || !feof($pipes[2])); $stat = proc_get_status($proc); From ff3c6ed993826b1a8d6ead376826217a50740b0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 5 Nov 2024 15:13:24 +0100 Subject: [PATCH 7/7] Fix timeout handling --- run-tests.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-tests.php b/run-tests.php index 34194cb97414c..ee1fcabcadda9 100755 --- a/run-tests.php +++ b/run-tests.php @@ -1225,7 +1225,7 @@ function system_with_timeout( /* timed out */ $data .= "\n ** ERROR: process timed out **\n"; proc_terminate($proc, 9); - return $data; + break; } if ($n > 0) {