Skip to content

run-tests: use the EXTENSIONS section for skipping #6787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

MaxSem
Copy link
Contributor

@MaxSem MaxSem commented Mar 18, 2021

Currently, most skip checks are just for making sure an extension is
available. Even with recent addition of skip caching, this makes tests
needlessly slow:

  • Checks for the same extension in its tests can have small differences
    impacting cacheability.
  • Even identical skip checks in two tests can still be executed twice if
    they're run by different workers.

To remedy this, I'm repurposing the existing --EXTENSIONS-- section of
.phpt files to specify wjich extensions are required for current test to
run. Current behavior:

  1. If the extension is already visible to PHP, all is good
  2. If it isn't, assume it's present as a shared module and attempt to add
    it via a command line parameter
  3. If that works, all is good
  4. If it doesn't, PHP fails with a cryptic error message trying to
    execute the test itself

After this commit:

  1. and 2) are kept unchanged
  2. Check if shared extension file from 2) is actually present
  3. Skip the test if it isn't

Other benefits include clear skip reasons (vs. sometimes none in many
current skip checks) and moving test information from code to metadata,
opening more opportunities for search and analysis.

Since --EXTENSIONS-- is barely ever used, this change poses no risk of
hidden failures.

As a demonstration of the new approach, this commit migrates one
extension to it. If merged, I will migrate other extensions in
subsequent PRs.

@nikic
Copy link
Member

nikic commented Mar 18, 2021

tests/run-test/extensions-nonexistent.phpt failed

@MaxSem MaxSem force-pushed the extensions branch 2 times, most recently from 0320ad5 to 596f96d Compare March 18, 2021 15:57
@MaxSem
Copy link
Contributor Author

MaxSem commented Mar 18, 2021

Ignores be damned...

@mvorisek
Copy link
Contributor

mvorisek commented Mar 19, 2021

I would like to see something more abstract, not only for extensions, like:

ext-sodium
platform-windows
x86 / x64 / arm64

etc.

@MaxSem
Copy link
Contributor Author

MaxSem commented Mar 19, 2021

Yep, I have plans for --PLATFORM-- after that :)

@nikic
Copy link
Member

nikic commented Mar 19, 2021

Windows:

========DIFF========
001+ 'TEST_PHP_JUNIT' is not recognized as an internal or external command,
001- .*tests="1" failures="0" errors="0" skip="1".*
002+ operable program or batch file.
003+ Test runner finished with exit code 1
========DONE========
FAIL phpt EXTENSIONS directive - extension not found [C:\projects\php-src\tests\run-test\extensions-nonexistent.phpt]

The CI results on azure look completely broken, but not sure if that's due to this PR or you just hit a bad master revision.

--FILE--
<?php
var_dump(extension_loaded('openssl'));
?>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?> terminators in test files should be kept, to make tests directly runnable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, though there are a lot of existing tests missing these.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, last year I added thousands of such terminators, but it was still not comprehensive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can make run-tests warn on such tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run-tests is also used by extensions, so warnings are problematic. Maybe add this to tidy.php instead.

Currently, most skip checks are just for making sure an extension is
available. Even with recent addition of skip caching, this makes tests
needlessly slow:
* Checks for the same extension in its tests can have small differences
  impacting cacheability.
* Even identical skip checks in two tests can still be executed twice if
  they're run by different workers.

To remedy this, I'm repurposing the existing --EXTENSIONS-- section of
.phpt files to specify wjich extensions are required for current test to
run. Current behavior:
1) If the extension is already visible to PHP, all is good
2) If it isn't, assume it's present as a shared module and attempt to add
   it via a command line parameter
3) If that works, all is good
4) If it doesn't, PHP fails with a cryptic error message trying to
   execute the test itself

After this commit:
1) and 2) are kept unchanged
3) Check if shared extension file from 2) is actually present
4) Skip the test if it isn't

Other benefits include clear skip reasons (vs. sometimes none in many
current skip checks) and moving test information from code to metadata,
opening more opportunities for search and analysis.

Since --EXTENSIONS-- is barely ever used, this change poses no risk of
hidden failures.

As a demonstration of the new approach, this commit migrates one
extension to it. If merged, I will migrate other extensions in
subsequent PRs.
@php-pulls php-pulls closed this in 6c9a056 Mar 22, 2021
MaxSem added a commit to MaxSem/php-src that referenced this pull request Mar 22, 2021
For rationale, see php#6787

Extensions migrated in this part:
* bcmath
* bz2
* calendar
* com_dotnet
* ctype
@cmb69
Copy link
Member

cmb69 commented Mar 22, 2021

Just seen this; very nice! That may also give the opportunity to improve the performance of the tests on Windows, by only loading the required extenstions in advance. The --with-test-ini-ext-exclude config option which is set in build_task.bat might make that trivial.

php-pulls pushed a commit that referenced this pull request Mar 22, 2021
For rationale, see #6787

Extensions migrated in this part:
* bcmath
* bz2
* calendar
* com_dotnet
* ctype

Closes GH-6797.
MaxSem added a commit to MaxSem/php-src that referenced this pull request Mar 31, 2021
For rationale, see php#6787

Make extension checks lowercase, add a special case for opcache
that has internal name not matching .so filename.

Extensions migrated in part 2:
* dom
* exif
* fileinfo
* ffi
Girgias pushed a commit that referenced this pull request Apr 1, 2021
For rationale, see #6787

Make extension checks lowercase, add a special case for opcache
that has internal name not matching .so filename.

Extensions migrated in part 2:
* dom
* exif
* fileinfo
* ffi
MaxSem added a commit to MaxSem/php-src that referenced this pull request Apr 2, 2021
For rationale, see php#6787

Extensions migrated in part 3:
* ftp
* gmp
* iconv
* opcache
MaxSem added a commit to MaxSem/php-src that referenced this pull request Apr 2, 2021
For rationale, see php#6787

Extensions migrated in part 3:
* ftp
* gmp
* iconv
* opcache
* shmop
MaxSem added a commit to MaxSem/php-src that referenced this pull request Apr 3, 2021
For rationale, see php#6787

Extensions migrated in part 3:
* ftp
* gmp
* iconv
* opcache
* shmop
MaxSem added a commit to MaxSem/php-src that referenced this pull request Apr 3, 2021
For rationale, see php#6787

Extensions migrated in part 3:
* ftp
* gmp
* iconv
* opcache
* shmop
nikic pushed a commit that referenced this pull request Apr 3, 2021
For rationale, see #6787

Extensions migrated in part 3:
* ftp
* gmp
* iconv
* opcache
* shmop
kamil-tekiela pushed a commit to kamil-tekiela/php-src that referenced this pull request Apr 4, 2021
For rationale, see php#6787

Make extension checks lowercase, add a special case for opcache
that has internal name not matching .so filename.

Extensions migrated in part 2:
* dom
* exif
* fileinfo
* ffi
kamil-tekiela pushed a commit to kamil-tekiela/php-src that referenced this pull request Apr 4, 2021
For rationale, see php#6787

Extensions migrated in part 3:
* ftp
* gmp
* iconv
* opcache
* shmop
MaxSem added a commit to MaxSem/php-src that referenced this pull request Apr 6, 2021
For rationale, see php#6787

Extensions migrated in part 4:
* simplexml
* skeleton
* soap
* spl
* sqlite3
* sysvmsg
* sysvsem
* tidy
MaxSem added a commit to MaxSem/php-src that referenced this pull request Apr 7, 2021
For rationale, see php#6787

Extensions migrated in part 4:
* simplexml
* skeleton
* soap
* spl
* sqlite3
* sysvmsg
* sysvsem
* tidy - also removed a check for an ancient dependency version
nikic pushed a commit that referenced this pull request Apr 8, 2021
For rationale, see #6787

Extensions migrated in part 4:
* simplexml
* skeleton
* soap
* spl
* sqlite3
* sysvmsg
* sysvsem
* tidy - also removed a check for an ancient dependency version
@carusogabriel
Copy link
Contributor

@MaxSem Can we document this at http://qa.php.net/write-test.php?

@MaxSem MaxSem deleted the extensions branch April 17, 2021 15:33
@MaxSem
Copy link
Contributor Author

MaxSem commented Apr 18, 2021

@cmb69
Copy link
Member

cmb69 commented May 16, 2021

I just realized that this may not work as expected when all tests are supposed to be run, due to:

php-src/run-tests.php

Lines 863 to 865 in 048cb9b

// load list of enabled extensions
save_text($info_file,
'<?php echo str_replace("Zend OPcache", "opcache", implode(",", get_loaded_extensions())); ?>');

Unless we want to change run-tests.php, the test runner itself would have to be run with all (relevant) extensions loaded.

PS: no, it's not the test runner itself, but rather the TEST_PHP_EXECUTABLE, what defeats the purpose of this PR (only for all tests; testing individual extension tests suites works fine).

@nikic
Copy link
Member

nikic commented May 16, 2021

@cmb69 We should probably adjust that to include both loaded and loadable extensions. Should be fairly simple?

@cmb69
Copy link
Member

cmb69 commented May 16, 2021

@nikic, we could do something like:

 run-tests.php | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/run-tests.php b/run-tests.php
index 3c7189b24d..e767598e67 100755
--- a/run-tests.php
+++ b/run-tests.php
@@ -861,8 +861,21 @@ More .INIs  : " , (function_exists(\'php_ini_scanned_files\') ? str_replace("\n"
     @unlink($info_file);
 
     // load list of enabled extensions
-    save_text($info_file,
-        '<?php echo str_replace("Zend OPcache", "opcache", implode(",", get_loaded_extensions())); ?>');
+    save_text($info_file, <<<'PHP'
+        <?php
+        echo str_replace("Zend OPcache", "opcache", implode(",", get_loaded_extensions()));
+        $ext_dir = ini_get("extension_dir");
+        foreach (scandir($ext_dir) as $file) {
+            if (!preg_match('/^(?:php_)?([_a-zA-Z0-9]+)\.(?:so|dll)$/', $file, $matches)) {
+                continue;
+            }
+            $ext = $matches[1];
+            if (!extension_loaded($ext) && @dl($file)) {
+                echo ",", $ext;
+            }
+        }
+        ?>
+    PHP);
     $exts_to_test = explode(',', `$php $pass_options $info_params $no_file_cache "$info_file"`);
     // check for extensions that need special handling and regenerate
     $info_params_ex = [

But for AppVeyor this would mean that tests would be run for snmp,pdo_firebird,ldap,imap,ftp, although these tests would always be skipped. Might still be a performance improvement in the long run. I'll submit a PR ASAP.

cmb69 added a commit to cmb69/php-src that referenced this pull request May 16, 2021
PR php#6787 changed the behavior of the `--EXTENSIONS--` section, so that
not yet loaded extensions are dynamically loaded if possible.  However,
when no tests are specified for the runner, only tests for already
loaded extensions are run, what defeats the purpose of the improvement
of the `--EXTENSIONS--` behavior.  We cater to that by detecting
loadable extensions, and also run their tests.
cmb69 added a commit to cmb69/php-src that referenced this pull request May 16, 2021
cmb69 added a commit that referenced this pull request May 22, 2021
cmb69 added a commit that referenced this pull request May 27, 2021
PR #6787 changed the behavior of the `--EXTENSIONS--` section, so that
not yet loaded extensions are dynamically loaded if possible.  However,
when no tests are specified for the runner, only tests for already
loaded extensions are run, what defeats the purpose of the improvement
of the `--EXTENSIONS--` behavior.  We cater to that by detecting
loadable extensions, and also run their tests.
@MaxSem
Copy link
Contributor Author

MaxSem commented Jul 31, 2021

Yep, I have plans for --PLATFORM-- after that :)

🎆 #7325 🎆

cmb69 added a commit that referenced this pull request Dec 30, 2021
This is only properly supported as of PHP 8.1.0[1], and may cause
spurious test failures for older versions[2].

[1] <#6787>
[2] <https://ci.appveyor.com/project/php/php-src/builds/42044075/job/tk4138s43p1953hx>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants