bug55509.phpt 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. --TEST--
  2. Bug #55509 (segfault on x86_64 using more than 2G memory)
  3. --SKIPIF--
  4. <?php
  5. if (PHP_INT_SIZE == 4) {
  6. die('skip Not for 32-bits OS');
  7. }
  8. $zend_mm_enabled = getenv("USE_ZEND_ALLOC");
  9. if ($zend_mm_enabled === "0") {
  10. die("skip Zend MM disabled");
  11. }
  12. if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
  13. // check the available memory
  14. if (PHP_OS == 'Linux') {
  15. $lines = file('/proc/meminfo');
  16. $infos = array();
  17. foreach ($lines as $line) {
  18. $tmp = explode(":", $line);
  19. $index = strtolower($tmp[0]);
  20. $value = (int)ltrim($tmp[1], " ")*1024;
  21. $infos[$index] = $value;
  22. }
  23. $freeMemory = $infos['memfree']+$infos['buffers']+$infos['cached'];
  24. if ($freeMemory < 2100*1024*1024) {
  25. die('skip Not enough memory.');
  26. }
  27. }
  28. elseif (PHP_OS == 'FreeBSD') {
  29. $lines = explode("\n",`sysctl -a`);
  30. $infos = array();
  31. foreach ($lines as $line) {
  32. if(!$line){
  33. continue;
  34. }
  35. $tmp = explode(":", $line);
  36. $index = strtolower($tmp[0]);
  37. $value = trim($tmp[1], " ");
  38. $infos[$index] = $value;
  39. }
  40. $freeMemory = ($infos['vm.stats.vm.v_inactive_count']*$infos['hw.pagesize'])
  41. +($infos['vm.stats.vm.v_cache_count']*$infos['hw.pagesize'])
  42. +($infos['vm.stats.vm.v_free_count']*$infos['hw.pagesize']);
  43. if ($freeMemory < 2100*1024*1024) {
  44. die('skip Not enough memory.');
  45. }
  46. }
  47. ?>
  48. --INI--
  49. memory_limit=2100M
  50. --FILE--
  51. <?php
  52. $a1 = str_repeat("1", 1024 * 1024 * 1024 * 0.5);
  53. echo "1\n";
  54. $a2 = str_repeat("2", 1024 * 1024 * 1024 * 0.5);
  55. echo "2\n";
  56. $a3 = str_repeat("3", 1024 * 1024 * 1024 * 0.5);
  57. echo "3\n";
  58. $a4 = str_repeat("4", 1024 * 1024 * 1024 * 0.5);
  59. echo "4\n";
  60. $a5 = str_repeat("5", 1024 * 1024 * 1024 * 0.5);
  61. echo "5\n";
  62. ?>
  63. --EXPECTF--
  64. 1
  65. 2
  66. 3
  67. 4
  68. Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %sbug55509.php on line %d