1--TEST--
2Stack limit 010 - Check stack size detection against known defaults
3--EXTENSIONS--
4zend_test
5--SKIPIF--
6<?php
7if (!function_exists('zend_test_zend_call_stack_get')) die("skip zend_test_zend_call_stack_get() is not available");
8if (!getenv('STACK_LIMIT_DEFAULTS_CHECK')) { die('skip STACK_LIMIT_DEFAULTS_CHECK not set'); }
9?>
10--FILE--
11<?php
12
13$stack = zend_test_zend_call_stack_get();
14
15var_dump($stack);
16
17$expectedMaxSize = match(php_uname('s')) {
18    'Darwin' => match(php_uname('m')) {
19        'x86_64' => 8*1024*1024,
20        'arm64' => 8372224,
21    },
22    'FreeBSD' => match(php_uname('m')) {
23        'amd64' => 512*1024*1024 - 4096,
24        'i386' => 64*1024*1024 - 4096,
25    },
26    'Linux' => match (getenv('GITHUB_ACTIONS')) {
27        'true' => 16*1024*1024, // https://github.com/actions/runner-images/pull/3328
28        default => 8*1024*1024,
29    },
30    'SunOS' => 10 * 1024 * 1024,
31    'Windows NT' => 67108864 - 4*4096, // Set by sapi/cli/config.w32
32};
33
34printf("Expected max_size: 0x%x\n", $expectedMaxSize);
35printf("Actual   max_size: %s\n", $stack['max_size']);
36
37var_dump($stack['max_size'] === sprintf('0x%x', $expectedMaxSize));
38
39?>
40--EXPECTF--
41array(4) {
42  ["base"]=>
43  string(%d) "0x%x"
44  ["max_size"]=>
45  string(%d) "0x%x"
46  ["position"]=>
47  string(%d) "0x%x"
48  ["EG(stack_limit)"]=>
49  string(%d) "0x%x"
50}
51Expected max_size: 0x%x
52Actual   max_size: 0x%x
53bool(true)
54