|
| 1 | +--TEST-- |
| 2 | +shmop error conditions on Windows |
| 3 | +--EXTENSIONS-- |
| 4 | +shmop |
| 5 | +--SKIPIF-- |
| 6 | +<?php |
| 7 | +if (PHP_OS_FAMILY !== "Windows") die("skip for Windows only"); |
| 8 | +?> |
| 9 | +--FILE-- |
| 10 | +<?php |
| 11 | +echo "duplicate segment: "; |
| 12 | +$key = 0xFEEDBEEF; |
| 13 | +$shm1 = shmop_open($key, 'n', 0644, 1024); |
| 14 | +$shm2 = shmop_open($key, 'n', 0644, 1024); |
| 15 | +echo ($shm1 && !$shm2) ? "ok\n" : "failed\n"; |
| 16 | +shmop_delete($shm1); |
| 17 | + |
| 18 | +echo "non-existent attach: "; |
| 19 | +$shm = shmop_open(0xDEADC0DE, 'a', 0644, 0); |
| 20 | +echo ($shm === false) ? "ok\n" : "failed\n"; |
| 21 | + |
| 22 | +echo "non-existent write: "; |
| 23 | +$shm = shmop_open(0xBADF00D, 'w', 0644, 0); |
| 24 | +echo ($shm === false) ? "ok\n" : "failed\n"; |
| 25 | + |
| 26 | +echo "zero size: "; |
| 27 | +try { |
| 28 | + shmop_open(0x12340000, 'n', 0644, 0); |
| 29 | + echo "failed\n"; |
| 30 | +} catch (ValueError $e) { |
| 31 | + echo "ok\n"; |
| 32 | +} |
| 33 | + |
| 34 | +echo "write/read test: "; |
| 35 | +$key = 0xC0FFEE00; |
| 36 | +$shm_c = shmop_open($key, 'c', 0644, 1024); |
| 37 | +$shm_w = shmop_open($key, 'w', 0644, 0); |
| 38 | +$shm_a = shmop_open($key, 'a', 0644, 0); |
| 39 | +if ($shm_c && $shm_w && $shm_a) { |
| 40 | + $data = "test data"; |
| 41 | + $written = shmop_write($shm_w, $data, 0); |
| 42 | + $read = shmop_read($shm_a, 0, strlen($data)); |
| 43 | + echo ($read === $data) ? "ok\n" : "failed\n"; |
| 44 | + shmop_delete($shm_c); |
| 45 | +} else { |
| 46 | + echo "failed\n"; |
| 47 | +} |
| 48 | + |
| 49 | +echo "multiple segments: "; |
| 50 | +$segments = []; |
| 51 | +for ($i = 0; $i < 3; $i++) { |
| 52 | + $shm = shmop_open(0xA0000000 + $i, 'c', 0644, 256); |
| 53 | + if ($shm) $segments[] = $shm; |
| 54 | +} |
| 55 | +echo (count($segments) === 3) ? "ok\n" : "failed\n"; |
| 56 | +foreach ($segments as $shm) { |
| 57 | + shmop_delete($shm); |
| 58 | +} |
| 59 | + |
| 60 | +echo "large segment: "; |
| 61 | +$shm = shmop_open(0xBEEF0000, 'n', 0644, 1024 * 1024); |
| 62 | +if ($shm) { |
| 63 | + echo (shmop_size($shm) >= 1024 * 1024) ? "ok\n" : "failed\n"; |
| 64 | + shmop_delete($shm); |
| 65 | +} else { |
| 66 | + echo "failed\n"; |
| 67 | +} |
| 68 | +?> |
| 69 | +--EXPECTF-- |
| 70 | +duplicate segment: |
| 71 | +Warning: shmop_open(): Unable to attach or create shared memory segment%s in %s on line %d |
| 72 | +ok |
| 73 | +non-existent attach: |
| 74 | +Warning: shmop_open(): Unable to attach or create shared memory segment%s in %s on line %d |
| 75 | +ok |
| 76 | +non-existent write: |
| 77 | +Warning: shmop_open(): Unable to attach or create shared memory segment%s in %s on line %d |
| 78 | +ok |
| 79 | +zero size: ok |
| 80 | +write/read test: ok |
| 81 | +multiple segments: ok |
| 82 | +large segment: ok |
0 commit comments