Fix brittle shmop test

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.
This commit is contained in:
Christoph M. Becker 2020-05-13 23:09:57 +02:00
parent 129fd647a1
commit 1892e3abaa

View 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);