From 87b4651a2b7530da4f77739ff10a659eb9c470c5 Mon Sep 17 00:00:00 2001
From: dixyes <dixyes@gmail.com>
Date: Fri, 29 Nov 2024 17:58:07 +0800
Subject: [PATCH] Skip tests using memory limit when zend mm not enabled

---
 .../swow_coroutine/edge_case_of_kill_001.phpt   |  7 +++++++
 .../swow_coroutine/edge_case_of_kill_002.phpt   |  7 +++++++
 .../in_shutdown/bailout_in_main.phpt            | 11 ++++++++++-
 .../bailout_in_shutdown_functions.phpt          | 17 +++++++++++++++--
 .../in_shutdown/bailout_in_sub_coroutine.phpt   | 12 +++++++++++-
 5 files changed, 50 insertions(+), 4 deletions(-)

diff --git a/ext/tests/swow_coroutine/edge_case_of_kill_001.phpt b/ext/tests/swow_coroutine/edge_case_of_kill_001.phpt
index e996a52d..3c1162d6 100644
--- a/ext/tests/swow_coroutine/edge_case_of_kill_001.phpt
+++ b/ext/tests/swow_coroutine/edge_case_of_kill_001.phpt
@@ -3,7 +3,14 @@ swow_coroutine: edge case of kill
 --SKIPIF--
 <?php
 require __DIR__ . '/../include/skipif.php';
+
+if (memory_get_usage() == 0) {
+    // zend mm not enabled, skip test
+    exit("SKIP: zend mm not enabled");
+}
 ?>
+--INI--
+memory_limit=32M
 --FILE--
 <?php
 require __DIR__ . '/../include/bootstrap.php';
diff --git a/ext/tests/swow_coroutine/edge_case_of_kill_002.phpt b/ext/tests/swow_coroutine/edge_case_of_kill_002.phpt
index d291ac5a..a3b15196 100644
--- a/ext/tests/swow_coroutine/edge_case_of_kill_002.phpt
+++ b/ext/tests/swow_coroutine/edge_case_of_kill_002.phpt
@@ -3,7 +3,14 @@ swow_coroutine: edge case of kill
 --SKIPIF--
 <?php
 require __DIR__ . '/../include/skipif.php';
+
+if (memory_get_usage() == 0) {
+    // zend mm not enabled, skip test
+    exit("SKIP: zend mm not enabled");
+}
 ?>
+--INI--
+memory_limit=32M
 --FILE--
 <?php
 require __DIR__ . '/../include/bootstrap.php';
diff --git a/ext/tests/swow_coroutine/in_shutdown/bailout_in_main.phpt b/ext/tests/swow_coroutine/in_shutdown/bailout_in_main.phpt
index 543efa80..74a9c36e 100644
--- a/ext/tests/swow_coroutine/in_shutdown/bailout_in_main.phpt
+++ b/ext/tests/swow_coroutine/in_shutdown/bailout_in_main.phpt
@@ -3,7 +3,14 @@ swow_coroutine: bailout in main
 --SKIPIF--
 <?php
 require __DIR__ . '/../../include/skipif.php';
+
+if (memory_get_usage() == 0) {
+    // zend mm not enabled, skip test
+    exit("SKIP: zend mm not enabled");
+}
 ?>
+--INI--
+memory_limit=32M
 --FILE--
 <?php
 require __DIR__ . '/../../include/bootstrap.php';
@@ -22,8 +29,10 @@ for ($c = 0; $c < TEST_MAX_CONCURRENCY; $c++) {
     });
 }
 
-echo str_repeat('X', 128 * 1024 * 1024);
+$str128M = str_repeat('X', 128 * 1024 * 1024);
+var_dump(md5($str128M));
 
+echo "Never here\n";
 ?>
 --EXPECTF--
 %AFatal error: [Fatal error in main] Allowed memory size of %d bytes exhausted%A (tried to allocate %d bytes)
diff --git a/ext/tests/swow_coroutine/in_shutdown/bailout_in_shutdown_functions.phpt b/ext/tests/swow_coroutine/in_shutdown/bailout_in_shutdown_functions.phpt
index d8a1f687..e96dbfb0 100644
--- a/ext/tests/swow_coroutine/in_shutdown/bailout_in_shutdown_functions.phpt
+++ b/ext/tests/swow_coroutine/in_shutdown/bailout_in_shutdown_functions.phpt
@@ -3,7 +3,14 @@ swow_coroutine: bailout in shutdown functions
 --SKIPIF--
 <?php
 require __DIR__ . '/../../include/skipif.php';
+
+if (memory_get_usage() == 0) {
+    // zend mm not enabled, skip test
+    exit("SKIP: zend mm not enabled");
+}
 ?>
+--INI--
+memory_limit=32M
 --FILE--
 <?php
 require __DIR__ . '/../../include/bootstrap.php';
@@ -15,7 +22,10 @@ use function Swow\Sync\waitAll;
 register_shutdown_function(static function (): void {
     Assert::same(Coroutine::count(), TEST_MAX_CONCURRENCY + 2);
     echo sprintf("\nCoroutine count: %d\n", Coroutine::count());
-    echo str_repeat('X', 128 * 1024 * 1024 + 1);
+    $str128M = str_repeat('X', 128 * 1024 * 1024 + 1);
+    var_dump(md5($str128M));
+
+    echo "Never here\n";
 });
 
 for ($c = 0; $c < TEST_MAX_CONCURRENCY; $c++) {
@@ -26,7 +36,10 @@ for ($c = 0; $c < TEST_MAX_CONCURRENCY; $c++) {
 }
 
 Coroutine::run(static function (): void {
-    echo str_repeat('X', 128 * 1024 * 1024);
+    $str128M = str_repeat('X', 128 * 1024 * 1024);
+    var_dump(md5($str128M));
+
+    echo "Never here\n";
 });
 
 waitAll();
diff --git a/ext/tests/swow_coroutine/in_shutdown/bailout_in_sub_coroutine.phpt b/ext/tests/swow_coroutine/in_shutdown/bailout_in_sub_coroutine.phpt
index a0160f20..4a4f1d9b 100644
--- a/ext/tests/swow_coroutine/in_shutdown/bailout_in_sub_coroutine.phpt
+++ b/ext/tests/swow_coroutine/in_shutdown/bailout_in_sub_coroutine.phpt
@@ -3,7 +3,14 @@ swow_coroutine: bailout in main
 --SKIPIF--
 <?php
 require __DIR__ . '/../../include/skipif.php';
+
+if (memory_get_usage() == 0) {
+    // zend mm not enabled, skip test
+    exit("SKIP: zend mm not enabled");
+}
 ?>
+--INI--
+memory_limit=32M
 --FILE--
 <?php
 require __DIR__ . '/../../include/bootstrap.php';
@@ -25,7 +32,10 @@ for ($c = 0; $c < TEST_MAX_CONCURRENCY; $c++) {
 }
 
 Coroutine::run(static function (): void {
-    echo str_repeat('X', 128 * 1024 * 1024);
+    $str128M = str_repeat('X', 128 * 1024 * 1024);
+    var_dump(md5($str128M));
+
+    echo "Never here\n";
 });
 
 waitAll();