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