]> granicus.if.org Git - php/commitdiff
Fix brittle shmop test
authorChristoph M. Becker <cmbecker69@gmx.de>
Wed, 13 May 2020 21:09:57 +0000 (23:09 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Wed, 13 May 2020 21:25:28 +0000 (23:25 +0200)
To solve bug #70886, the test uses random keys to prevent collisions;
however, this is not guaranteed, and as such it may even collide with
other tests in the shmop test suite.  The proper solution would be to
use a single key (which could be randomly generated), but to actually
`shmop_close()` after each `shmop_delete()`.  This would, however, not
work on Windows due to bug #65987.  Therefore we use three different
keys for now.

ext/shmop/tests/002.phpt

index 3206f90776b15c86a614f5596752721049688d2f..94d536a1758a6349a05bff7b3f7a316877a826d0 100644 (file)
@@ -13,37 +13,34 @@ edgarsandi - <edgar.r.sandi@gmail.com>
 ?>
 --FILE--
 <?php
-       $hex_shm_id = function(){
-               return mt_rand(1338, 9999);
-       };
 
 echo PHP_EOL, '## shmop_open function tests ##';
        // warning outputs: 4 parameters expected
        var_dump($shm_id = shmop_open());
 
        // warning outputs: invalid flag when the flags length != 1
-       var_dump(shmop_open($hex_shm_id(), '', 0644, 1024));
+       var_dump(shmop_open(1338, '', 0644, 1024));
 
        // warning outputs: invalid access mode
-       var_dump(shmop_open($hex_shm_id(), 'b', 0644, 1024));
+       var_dump(shmop_open(1338, 'b', 0644, 1024));
 
        // warning outputs: unable to attach or create shared memory segment
        var_dump(shmop_open(null, 'a', 0644, 1024));
 
        // warning outputs: Shared memory segment size must be greater than zero
-       var_dump(shmop_open($hex_shm_id(), "c", 0666, 0));
+       var_dump(shmop_open(1338, "c", 0666, 0));
 
 echo PHP_EOL, '## shmop_read function tests ##';
        // warning outputs: 3 parameters expected
        var_dump(shmop_read());
 
        // warning outputs: start is out of range
-       $shm_id = shmop_open($hex_shm_id(), 'n', 0600, 1024);
+       $shm_id = shmop_open(1338, 'n', 0600, 1024);
        var_dump(shmop_read($shm_id, -10, 0));
        shmop_delete($shm_id);
 
        // warning outputs: count is out of range
-       $shm_id = shmop_open($hex_shm_id(), 'n', 0600, 1024);
+       $shm_id = shmop_open(1339, 'n', 0600, 1024);
        var_dump(shmop_read($shm_id, 0, -10));
        shmop_delete($shm_id);
 
@@ -52,7 +49,7 @@ echo PHP_EOL, '## shmop_write function tests ##';
        var_dump(shmop_write());
 
        // warning outputs: offset out of range
-       $shm_id = shmop_open($hex_shm_id(), 'n', 0600, 1024);
+       $shm_id = shmop_open(1340, 'n', 0600, 1024);
        var_dump(shmop_write($shm_id, 'text to try write', -10));
        shmop_delete($shm_id);