bug55509.phpt 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. } elseif (PHP_OS == "WINNT") {
  47. $s = trim(shell_exec("wmic OS get FreeVirtualMemory /Value 2>nul"));
  48. $freeMemory = explode('=', $s)[1]*1;
  49. if ($freeMemory < 2.1*1024*1024) {
  50. die('skip Not enough memory.');
  51. }
  52. }
  53. ?>
  54. --INI--
  55. memory_limit=2100M
  56. --FILE--
  57. <?php
  58. $a1 = str_repeat("1", 1024 * 1024 * 1024 * 0.5);
  59. echo "1\n";
  60. $a2 = str_repeat("2", 1024 * 1024 * 1024 * 0.5);
  61. echo "2\n";
  62. $a3 = str_repeat("3", 1024 * 1024 * 1024 * 0.5);
  63. echo "3\n";
  64. $a4 = str_repeat("4", 1024 * 1024 * 1024 * 0.5);
  65. echo "4\n";
  66. $a5 = str_repeat("5", 1024 * 1024 * 1024 * 0.5);
  67. echo "5\n";
  68. ?>
  69. --EXPECTF--
  70. 1
  71. 2
  72. 3
  73. 4
  74. Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %sbug55509.php on line %d