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' => 8*1024*1024,
19    'FreeBSD' => match(php_uname('m')) {
20        'amd64' => 512*1024*1024 - 4096,
21        'i386' => 64*1024*1024 - 4096,
22    },
23    'Linux' => match (getenv('GITHUB_ACTIONS')) {
24        'true' => 16*1024*1024, // https://github.com/actions/runner-images/pull/3328
25        default => 8*1024*1024,
26    },
27    'Windows NT' => 67108864 - 4*4096, // Set by sapi/cli/config.w32
28};
29
30printf("Expected max_size: 0x%x\n", $expectedMaxSize);
31printf("Actual   max_size: %s\n", $stack['max_size']);
32
33var_dump($stack['max_size'] === sprintf('0x%x', $expectedMaxSize));
34
35?>
36--EXPECTF--
37array(4) {
38  ["base"]=>
39  string(%d) "0x%x"
40  ["max_size"]=>
41  string(%d) "0x%x"
42  ["position"]=>
43  string(%d) "0x%x"
44  ["EG(stack_limit)"]=>
45  string(%d) "0x%x"
46}
47Expected max_size: 0x%x
48Actual   max_size: 0x%x
49bool(true)
50