From cc21de48d2afe946ec839c330d4c418a9bdc764c Mon Sep 17 00:00:00 2001 From: Florian Engelhardt Date: Wed, 10 Jul 2024 12:29:58 +0200 Subject: [PATCH] standardize memory check and support docker environments --- Zend/tests/bug55509.phpt | 45 ++----------------- ext/gmp/tests/gmp_setbit_long.phpt | 24 ++++------ ...le_get_contents_file_put_contents_5gb.phpt | 23 ++-------- sapi/cli/tests/upload_2G.phpt | 21 ++------- 4 files changed, 17 insertions(+), 96 deletions(-) diff --git a/Zend/tests/bug55509.phpt b/Zend/tests/bug55509.phpt index 1ae5b04f8a0df..e0fd526be708f 100644 --- a/Zend/tests/bug55509.phpt +++ b/Zend/tests/bug55509.phpt @@ -12,49 +12,10 @@ if ($zend_mm_enabled === "0") { } if (getenv("SKIP_SLOW_TESTS")) die("skip slow test"); -// check the available memory -if (PHP_OS == 'Linux') { - $lines = file('/proc/meminfo'); - $infos = array(); - foreach ($lines as $line) { - $tmp = explode(":", $line); - $index = strtolower($tmp[0]); - $value = (int)ltrim($tmp[1], " ")*1024; - $infos[$index] = $value; - } - $freeMemory = $infos['memfree']+$infos['buffers']+$infos['cached']; - if ($freeMemory < 2100*1024*1024) { - die('skip Not enough memory.'); - } -} -elseif (PHP_OS == 'FreeBSD') { - $lines = explode("\n",`sysctl -a`); - $infos = array(); - foreach ($lines as $line) { - if (!$line){ - continue; - } - $tmp = explode(":", $line); - if (count($tmp) < 2) { - continue; - } - $index = strtolower($tmp[0]); - $value = trim($tmp[1], " "); - $infos[$index] = $value; - } - $freeMemory = ($infos['vm.stats.vm.v_inactive_count']*$infos['hw.pagesize']) - +($infos['vm.stats.vm.v_cache_count']*$infos['hw.pagesize']) - +($infos['vm.stats.vm.v_free_count']*$infos['hw.pagesize']); - if ($freeMemory < 2100*1024*1024) { - die('skip Not enough memory.'); - } -} elseif (PHP_OS == "WINNT") { - $s = trim(shell_exec("wmic OS get FreeVirtualMemory /Value 2>nul")); - $freeMemory = explode('=', $s)[1]*1; - if ($freeMemory < 2.1*1024*1024) { - die('skip Not enough memory.'); - } +include(__DIR__.'../../../tests/utils.php'); +if(!has_enough_memory(2.1 * 1024 * 1024 * 1024)) { + die('skip Reason: Insufficient RAM (should be 2.1GB)'); } ?> --INI-- diff --git a/ext/gmp/tests/gmp_setbit_long.phpt b/ext/gmp/tests/gmp_setbit_long.phpt index 08927e9a2ee7f..8f9238cde9f47 100644 --- a/ext/gmp/tests/gmp_setbit_long.phpt +++ b/ext/gmp/tests/gmp_setbit_long.phpt @@ -3,23 +3,15 @@ gmp_setbit() with large index --EXTENSIONS-- gmp --SKIPIF-- - - - --FILE-- 3) { - $enough_free_ram = true; - } - } - } -} - -if (empty($enough_free_ram)) { - die(sprintf("skip need +3G free RAM, but only %01.2f available", $free_ram)); +include(__DIR__.'../../../tests/utils.php'); +if(!has_enough_memory(3 * 1024 * 1024 * 1024)) { // 3 GB + die('skip Reason: Insufficient RAM (should be 3GB)'); } if (getenv('TRAVIS')) {