Skip to content

Commit 6c9a056

Browse files
MaxSemnikic
authored andcommitted
run-tests: use the EXTENSIONS section for skipping
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.
1 parent a3e1082 commit 6c9a056

28 files changed

+74
-71
lines changed

ext/sodium/tests/bug78114.phpt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
--TEST--
22
Bug #78114 (segfault when calling sodium_* functions from eval)
3-
--SKIPIF--
4-
<?php
5-
if (!extension_loaded('sodium')) die('skip sodium extension not available');
6-
?>
3+
--EXTENSIONS--
4+
sodium
75
--FILE--
86
<?php
97
try {

ext/sodium/tests/bug78516.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
--TEST--
22
Bug #78516 (password_hash(): Memory cost is not in allowed range)
3+
--EXTENSIONS--
4+
sodium
35
--SKIPIF--
46
<?php
5-
if (!extension_loaded('sodium')) die('skip sodium extension not available');
67
if (!defined('PASSWORD_ARGON2ID')) die('skip PASSWORD_ARGON2ID not available');
78
?>
89
--FILE--

ext/sodium/tests/crypto_aead.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
--TEST--
22
Check for libsodium AEAD
3+
--EXTENSIONS--
4+
sodium
35
--SKIPIF--
46
<?php
5-
if (!extension_loaded("sodium")) print "skip extension not loaded";
67
if (!defined('SODIUM_CRYPTO_AEAD_AES256GCM_NPUBBYTES')) print "skip libsodium without AESGCM";
78
?>
89
--FILE--

ext/sodium/tests/crypto_auth.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--TEST--
22
Check for libsodium auth
3-
--SKIPIF--
4-
<?php if (!extension_loaded("sodium")) print "skip"; ?>
3+
--EXTENSIONS--
4+
sodium
55
--FILE--
66
<?php
77
$msg = random_bytes(1000);

ext/sodium/tests/crypto_box.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--TEST--
22
Check for libsodium box
3-
--SKIPIF--
4-
<?php if (!extension_loaded("sodium")) print "skip"; ?>
3+
--EXTENSIONS--
4+
sodium
55
--FILE--
66
<?php
77
$keypair = sodium_crypto_box_keypair();

ext/sodium/tests/crypto_generichash.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--TEST--
22
Check for libsodium generichash
3-
--SKIPIF--
4-
<?php if (!extension_loaded("sodium")) print "skip"; ?>
3+
--EXTENSIONS--
4+
sodium
55
--FILE--
66
<?php
77
$q = sodium_crypto_generichash('msg');

ext/sodium/tests/crypto_hex.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--TEST--
22
Check for libsodium bin2hex
3-
--SKIPIF--
4-
<?php if (!extension_loaded("sodium")) print "skip"; ?>
3+
--EXTENSIONS--
4+
sodium
55
--FILE--
66
<?php
77
$bin = random_bytes(random_int(1, 1000));

ext/sodium/tests/crypto_kdf.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--TEST--
22
Check for libsodium KDF
3-
--SKIPIF--
4-
<?php if (!extension_loaded("sodium")) print "skip"; ?>
3+
--EXTENSIONS--
4+
sodium
55
--FILE--
66
<?php
77
$key = sodium_crypto_kdf_keygen();

ext/sodium/tests/crypto_kx.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--TEST--
22
Check for libsodium-based key exchange
3-
--SKIPIF--
4-
<?php if (!extension_loaded("sodium")) print "skip"; ?>
3+
--EXTENSIONS--
4+
sodium
55
--FILE--
66
<?php
77
$client_seed = sodium_hex2bin('0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef');

ext/sodium/tests/crypto_scalarmult.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--TEST--
22
Check for libsodium scalarmult
3-
--SKIPIF--
4-
<?php if (!extension_loaded("sodium")) print "skip"; ?>
3+
--EXTENSIONS--
4+
sodium
55
--FILE--
66
<?php
77
$n = sodium_hex2bin("5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb");

0 commit comments

Comments
 (0)