]> granicus.if.org Git - php/commitdiff
run-tests: use the EXTENSIONS section for skipping
authorMax Semenik <maxsem.wiki@gmail.com>
Thu, 18 Mar 2021 11:53:14 +0000 (14:53 +0300)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 22 Mar 2021 08:53:38 +0000 (09:53 +0100)
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.

Closes GH-6787.

28 files changed:
ext/sodium/tests/bug78114.phpt
ext/sodium/tests/bug78516.phpt
ext/sodium/tests/crypto_aead.phpt
ext/sodium/tests/crypto_auth.phpt
ext/sodium/tests/crypto_box.phpt
ext/sodium/tests/crypto_generichash.phpt
ext/sodium/tests/crypto_hex.phpt
ext/sodium/tests/crypto_kdf.phpt
ext/sodium/tests/crypto_kx.phpt
ext/sodium/tests/crypto_scalarmult.phpt
ext/sodium/tests/crypto_secretbox.phpt
ext/sodium/tests/crypto_secretstream.phpt
ext/sodium/tests/crypto_shorthash.phpt
ext/sodium/tests/crypto_sign.phpt
ext/sodium/tests/crypto_stream.phpt
ext/sodium/tests/exception_trace_without_args.phpt
ext/sodium/tests/inc_add.phpt
ext/sodium/tests/installed.phpt
ext/sodium/tests/pwhash_argon2i.phpt
ext/sodium/tests/pwhash_scrypt.phpt
ext/sodium/tests/sodium_error_001.phpt
ext/sodium/tests/utils.phpt
ext/sodium/tests/version.phpt
run-tests.php
tests/run-test/bug75042-2.phpt [deleted file]
tests/run-test/bug75042-3.phpt [deleted file]
tests/run-test/extensions-shared.phpt [moved from tests/run-test/bug75042.phpt with 91% similarity]
tests/run-test/extensions-static.phpt [new file with mode: 0644]

index 6d7df4348faa9c203264470bdbb4bda5b5434b97..b988c09ec23f83759bc30b4ebc1192eee498b86e 100644 (file)
@@ -1,9 +1,7 @@
 --TEST--
 Bug #78114 (segfault when calling sodium_* functions from eval)
---SKIPIF--
-<?php
-if (!extension_loaded('sodium')) die('skip sodium extension not available');
-?>
+--EXTENSIONS--
+sodium
 --FILE--
 <?php
 try {
index 0347d332730ef89ca3d440fb7a7958ace7706355..90852a6967db99ca4aebeb505304aa51e8cd9f68 100644 (file)
@@ -1,8 +1,9 @@
 --TEST--
 Bug #78516 (password_hash(): Memory cost is not in allowed range)
+--EXTENSIONS--
+sodium
 --SKIPIF--
 <?php
-if (!extension_loaded('sodium')) die('skip sodium extension not available');
 if (!defined('PASSWORD_ARGON2ID')) die('skip PASSWORD_ARGON2ID not available');
 ?>
 --FILE--
index a54a1c7dc67582d654ff8c9e825952c231e2b3e1..0da84194bbcdfd38f1f7a78b57d9d9acdc2ab679 100644 (file)
@@ -1,8 +1,9 @@
 --TEST--
 Check for libsodium AEAD
+--EXTENSIONS--
+sodium
 --SKIPIF--
 <?php
-if (!extension_loaded("sodium")) print "skip extension not loaded";
 if (!defined('SODIUM_CRYPTO_AEAD_AES256GCM_NPUBBYTES')) print "skip libsodium without AESGCM";
 ?>
 --FILE--
index 58d8350078b369c7d86ae042062b209bf0eed9ee..8f262414beb80d13e0ec7aa08ebabc027354407e 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 Check for libsodium auth
---SKIPIF--
-<?php if (!extension_loaded("sodium")) print "skip"; ?>
+--EXTENSIONS--
+sodium
 --FILE--
 <?php
 $msg = random_bytes(1000);
index 3a55717d53ce6aa701dd54e65af764052a5ebd4a..f77ec1601cf350e7534e3f2db559ba4b5094d711 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 Check for libsodium box
---SKIPIF--
-<?php if (!extension_loaded("sodium")) print "skip"; ?>
+--EXTENSIONS--
+sodium
 --FILE--
 <?php
 $keypair = sodium_crypto_box_keypair();
index 5a7b0c4285048fca243e5db014c9ac1cb5a05c41..58f519af5ceb17c01c6495113b83d707e80281bd 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 Check for libsodium generichash
---SKIPIF--
-<?php if (!extension_loaded("sodium")) print "skip"; ?>
+--EXTENSIONS--
+sodium
 --FILE--
 <?php
 $q = sodium_crypto_generichash('msg');
index 0f872ee8676ba86b1dca6a9419d2b0a81166e9f4..3f989a1f11bab5cb30cc82ce5139f30c0071aeb3 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 Check for libsodium bin2hex
---SKIPIF--
-<?php if (!extension_loaded("sodium")) print "skip"; ?>
+--EXTENSIONS--
+sodium
 --FILE--
 <?php
 $bin = random_bytes(random_int(1, 1000));
index c9f0949ed0f60c0285d090dd84eb7fede3556905..970a87988dc09170cf0bc742d7dd11a425ccef86 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 Check for libsodium KDF
---SKIPIF--
-<?php if (!extension_loaded("sodium")) print "skip"; ?>
+--EXTENSIONS--
+sodium
 --FILE--
 <?php
 $key = sodium_crypto_kdf_keygen();
index a1dd00a0a73d0f76eaf8f64e312d6844eefe8593..5a278f685bce6f7b7c4f7f6059f632b4a0f02df3 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 Check for libsodium-based key exchange
---SKIPIF--
-<?php if (!extension_loaded("sodium")) print "skip"; ?>
+--EXTENSIONS--
+sodium
 --FILE--
 <?php
 $client_seed = sodium_hex2bin('0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef');
index 2636963e32d8bd33916fe45e39c99608ead9a496..8dda46c99e9cc2cf816674bdb01b77935ee00318 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 Check for libsodium scalarmult
---SKIPIF--
-<?php if (!extension_loaded("sodium")) print "skip"; ?>
+--EXTENSIONS--
+sodium
 --FILE--
 <?php
 $n = sodium_hex2bin("5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb");
index b9d4d1ccfe5dc61d5869020ac9bc9dfabd12bb8f..075b0c60e3548a8d04483907e84a7a09528cea7f 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 Check for libsodium secretbox
---SKIPIF--
-<?php if (!extension_loaded("sodium")) print "skip"; ?>
+--EXTENSIONS--
+sodium
 --FILE--
 <?php
 $nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
index 24896e15b263abf89e29f994c49fbf9fe46cafeb..1267ecd8afa6d3d5969f19294eb8b1040f361118 100644 (file)
@@ -1,8 +1,9 @@
 --TEST--
 Check for libsodium secretstream
+--EXTENSIONS--
+sodium
 --SKIPIF--
 <?php
-if (!extension_loaded("sodium")) print "skip extension not loaded";
 if (!defined('SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_ABYTES')) print "skip libsodium without secretbytes";
 ?>
 --FILE--
index 68bffc823b00b0562038e16eb6e1f432eb1e2e15..c5cc2334a68a2ba15facd32ec4a4aa5c1ecff052 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 Check for libsodium shorthash
---SKIPIF--
-<?php if (!extension_loaded("sodium")) print "skip"; ?>
+--EXTENSIONS--
+sodium
 --FILE--
 <?php
 $m1 = 'message';
index 14e0c49e91e18e1d57f6ce57c6cc165e088453b1..e1a2343a206b441181931c0939f605764ccc083f 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 Check for libsodium ed25519 signatures
---SKIPIF--
-<?php if (!extension_loaded("sodium")) print "skip"; ?>
+--EXTENSIONS--
+sodium
 --FILE--
 <?php
 $keypair = sodium_crypto_sign_keypair();
index 27e163c071aa71f63e462f3ad86f920f72399779..46f174e15b60d8d41185901210a850c69af80d18 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 Check for libsodium stream
---SKIPIF--
-<?php if (!extension_loaded("sodium")) print "skip"; ?>
+--EXTENSIONS--
+sodium
 --FILE--
 <?php
 $nonce = random_bytes(SODIUM_CRYPTO_STREAM_NONCEBYTES);
index 4885f9309331da33e66314b3aa4d71f165e70220..aa39d5610f626a552e9f2f267512f15d24cbd4bf 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 SodiumException backtraces do not contain function arguments
---SKIPIF--
-<?php if (!extension_loaded("sodium")) print "skip"; ?>
+--EXTENSIONS--
+sodium
 --FILE--
 <?php
 
index 23410d140c7b809e00b3a34b6e153a39c846e4ac..7652cf851eb2a5bda5e0b05c9241d5c9f2abf5c9 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 increment and add edge cases
---SKIPIF--
-<?php if (!extension_loaded("sodium")) print "skip"; ?>
+--EXTENSIONS--
+sodium
 --FILE--
 <?php
 
index f004efa714529561af7071f3fa21857cf9af4b0c..e2c3b730377d568f11fec288dcb0160c24d61dca 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 Check for sodium presence
---SKIPIF--
-<?php if (!extension_loaded("sodium")) print "skip"; ?>
+--EXTENSIONS--
+sodium
 --FILE--
 <?php
 echo "sodium extension is available";
index aee90bd6face5fbfb6e8a65a9a1c9ee1b7a44d16..90f77304196f7cafd69832677a4354c1133742bf 100644 (file)
@@ -1,7 +1,9 @@
 --TEST--
 Check for libsodium argon2i
+--EXTENSIONS--
+sodium
 --SKIPIF--
-<?php if (!extension_loaded("sodium")) print "skip";
+<?php
 if (!defined('SODIUM_CRYPTO_PWHASH_SALTBYTES')) print "skip libsodium without argon2i"; ?>
 --FILE--
 <?php
index 8e02f7ba0e8f20efbba3a76e67b62cf2462fd13b..59b5647a9118d0e971572117b221d6803c77d797 100644 (file)
@@ -1,7 +1,9 @@
 --TEST--
 Check for libsodium scrypt
+--EXTENSIONS--
+sodium
 --SKIPIF--
-<?php if (!extension_loaded("sodium")) print "skip";
+<?php
 if (!defined('SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_SALTBYTES')) print "skip libsodium without scrypt"; ?>
 --FILE--
 <?php
index a78d071a10eea2d85a7c0b5243616c57fdfa2495..b290ebd8a5af5be255b3b951f3e2d8e973f08b4b 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 TypeErrors will not contain param values in backtrace
---SKIPIF--
-<?php if (!extension_loaded("sodium")) die("skip ext/sodium required"); ?>
+--EXTENSIONS--
+sodium
 --FILE--
 <?php
 declare(strict_types=1);
index 944a25ca2238a3eb895959cbb58f3e87f666991c..66969a60bdf452c4f6051c83b1396897ce39528e 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 Check for libsodium utils
---SKIPIF--
-<?php if (!extension_loaded("sodium")) print "skip"; ?>
+--EXTENSIONS--
+sodium
 --FILE--
 <?php
 $a = 'test';
index e9495d7a44ac6c482da0faf15e93759b8a8d0589..2c8b3a108e6f9d9164f95c9120ecf5c4dd882c3f 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 Check for libsodium version
---SKIPIF--
-<?php if (!extension_loaded("sodium")) print "skip"; ?>
+--EXTENSIONS--
+sodium
 --FILE--
 <?php
 echo strlen(SODIUM_LIBRARY_VERSION) >= 5;
index 825718407c2c145ee3352c1d9accbabcf9c5e43a..ad1311bb8d12cbc23c1865c719574a3a3e305591 100755 (executable)
@@ -2057,15 +2057,26 @@ TEST $file
         $extensions = preg_split("/[\n\r]+/", trim($test->getSection('EXTENSIONS')));
         [$ext_dir, $loaded] = $skipCache->getExtensions("$php $pass_options $extra_options $ext_params $no_file_cache");
         $ext_prefix = IS_WINDOWS ? "php_" : "";
+        $missing = [];
         foreach ($extensions as $req_ext) {
             if (!in_array($req_ext, $loaded)) {
                 if ($req_ext == 'opcache') {
-                    $ini_settings['zend_extension'][] = $ext_dir . DIRECTORY_SEPARATOR . $ext_prefix . $req_ext . '.' . PHP_SHLIB_SUFFIX;
+                    $ext_file = $ext_dir . DIRECTORY_SEPARATOR . $ext_prefix . $req_ext . '.' . PHP_SHLIB_SUFFIX;
+                    $ini_settings['zend_extension'][] = $ext_file;
                 } else {
-                    $ini_settings['extension'][] = $ext_dir . DIRECTORY_SEPARATOR . $ext_prefix . $req_ext . '.' . PHP_SHLIB_SUFFIX;
+                    $ext_file = $ext_dir . DIRECTORY_SEPARATOR . $ext_prefix . $req_ext . '.' . PHP_SHLIB_SUFFIX;
+                    $ini_settings['extension'][] = $ext_file;
+                }
+                if (!is_readable($ext_file)) {
+                    $missing[] = $req_ext;
                 }
             }
         }
+        if ($missing) {
+            $message = 'Required extension' . (count($missing) > 1 ? 's' : '')
+                . ' missing: ' . implode(', ', $missing);
+            return skip_test($tested, $tested_file, $shortname, $message);
+        }
     }
 
     // additional ini overwrites
diff --git a/tests/run-test/bug75042-2.phpt b/tests/run-test/bug75042-2.phpt
deleted file mode 100644 (file)
index 2c5718a..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
---TEST--
-phpt EXTENSIONS directive with static module
---EXTENSIONS--
-SPL
---FILE--
-<?php
-var_dump(extension_loaded('spl'));
-?>
---EXPECT--
-bool(true)
diff --git a/tests/run-test/bug75042-3.phpt b/tests/run-test/bug75042-3.phpt
deleted file mode 100644 (file)
index 5a30143..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
---TEST--
-phpt EXTENSIONS directive with nonexistent shared module
---INI--
-error_log=
-display_startup_errors=1
-display_errors=1
---EXTENSIONS--
-nonexistentsharedmodule
---FILE--
-<?php
-?>
---EXPECTF--
-Warning: PHP Startup: Unable to load dynamic library '%snonexistentsharedmodule.%s' %A
similarity index 91%
rename from tests/run-test/bug75042.phpt
rename to tests/run-test/extensions-shared.phpt
index a7979d6b5ed6ecbfad848e3001f2af3385790f6b..e8d9b52aa98a925d12b65209a854adee629035c6 100644 (file)
@@ -1,5 +1,7 @@
 --TEST--
-phpt EXTENSIONS directive with shared module
+phpt EXTENSIONS directive - shared module
+--EXTENSIONS--
+openssl
 --SKIPIF--
 <?php
 $php = getenv('TEST_PHP_EXECUTABLE');
@@ -8,8 +10,7 @@ if (false !== stripos(`$php -n -m`, 'openssl')) {
 }
 $ext_module = ini_get('extension_dir') . DIRECTORY_SEPARATOR . (substr(PHP_OS, 0, 3) === "WIN" ? "php_openssl." : "openssl.") . PHP_SHLIB_SUFFIX;
 if( !file_exists($ext_module) ) die('skip openssl shared extension not found');
---EXTENSIONS--
-openssl
+
 --FILE--
 <?php
 var_dump(extension_loaded('openssl'));
diff --git a/tests/run-test/extensions-static.phpt b/tests/run-test/extensions-static.phpt
new file mode 100644 (file)
index 0000000..19e883e
--- /dev/null
@@ -0,0 +1,9 @@
+--TEST--
+phpt EXTENSIONS directive - static extension is present
+--EXTENSIONS--
+standard
+--FILE--
+<?php
+var_dump(extension_loaded('standard'));
+--EXPECT--
+bool(true)