From a3d706e63a47afedf95361b912603fc11ae783b8 Mon Sep 17 00:00:00 2001 From: Karim Shamazov Date: Wed, 25 Mar 2026 14:29:28 +0300 Subject: [PATCH 1/3] add err test --- tests/python/tests/diagnostic/php/index.php | 58 ++++++++++++++++++- .../python/tests/diagnostic/test_backtrace.py | 33 +++-------- tests/python/tests/diagnostic/test_err.py | 15 +++++ 3 files changed, 81 insertions(+), 25 deletions(-) create mode 100644 tests/python/tests/diagnostic/test_err.py diff --git a/tests/python/tests/diagnostic/php/index.php b/tests/python/tests/diagnostic/php/index.php index e72f8ec830..dd7597ff1f 100644 --- a/tests/python/tests/diagnostic/php/index.php +++ b/tests/python/tests/diagnostic/php/index.php @@ -76,7 +76,7 @@ function forkable() { return wait($f); } -function main() { +function test_backtrace() { foreach (json_decode(file_get_contents('php://input')) as $action) { switch ($action["op"]) { case "check_main_trace": @@ -109,5 +109,61 @@ function main() { } } +function make_custom_exception() { + return err('TEST', 'London is the capital of Great Britain'); +} + +function check_exception(Exception $e) { + if ($e->getFile() != 'index.php') + return 'expected "index.php" but "' . $e->getFile() . '" found'; + + if ($e->getLine() != 113) + return 'expected 113 but ' . $e->getLine() . ' found'; + + if ($e->getCode() != 0) + return 'expected 0 but ' . $e->getCode() . ' found'; + + if ($e->getMessage() != 'ERR_TEST: London is the capital of Great Britain') + return 'expected "ERR_TEST: London is the capital of Great Britain" but "' . $e->getMessage() . '" found'; + + return 'ok'; +} + +function test_err() { + foreach (json_decode(file_get_contents('php://input')) as $action) { + switch ($action["op"]) { + case "just_make": + $e = make_custom_exception(); + $res = check_exception($e); + echo $res; + break; + case "throw_catch": + try { + throw make_custom_exception(); + } catch (Exception $e) { + $res = check_exception($e); + } + echo $res; + break; + default: + echo "unknown operation"; + return; + } + } +} + +function main() { + switch ($_SERVER["PHP_SELF"]) { + case "/test_backtrace": + test_backtrace(); + break; + case "/test_err": + test_err(); + break; + default: + critical_error("unknown test"); + } +} + main(); diff --git a/tests/python/tests/diagnostic/test_backtrace.py b/tests/python/tests/diagnostic/test_backtrace.py index d4dda2ab49..ced6026c2c 100644 --- a/tests/python/tests/diagnostic/test_backtrace.py +++ b/tests/python/tests/diagnostic/test_backtrace.py @@ -6,35 +6,20 @@ class TestBacktrace(WebServerAutoTestCase): @classmethod def extra_kphp2cpp_options(cls): return {"KPHP_EXTRA_CXXFLAGS" : "-O0 -g"} - - def test_main_fork_trace(self): - resp = self.web_server.http_post( - json=[ - {"op": "check_main_trace"}, - ]) + + def query(self, op: str): + resp = self.web_server.http_post(uri="/test_backtrace", json=[{"op": op}]) self.assertEqual(resp.text, "ok") self.assertEqual(resp.status_code, 200) + def test_main_fork_trace(self): + self.query("check_main_trace") + def test_fork_trace(self): - resp = self.web_server.http_post( - json=[ - {"op": "check_fork_trace"}, - ]) - self.assertEqual(resp.text, "ok") - self.assertEqual(resp.status_code, 200) + self.query("check_fork_trace") def test_fork_switch_trace(self): - resp = self.web_server.http_post( - json=[ - {"op": "check_fork_switch_trace"}, - ]) - self.assertEqual(resp.text, "ok") - self.assertEqual(resp.status_code, 200) + self.query("check_fork_switch_trace") def test_nested_fork_trace(self): - resp = self.web_server.http_post( - json=[ - {"op": "check_nested_fork_trace"}, - ]) - self.assertEqual(resp.text, "ok") - self.assertEqual(resp.status_code, 200) + self.query("check_nested_fork_trace") diff --git a/tests/python/tests/diagnostic/test_err.py b/tests/python/tests/diagnostic/test_err.py new file mode 100644 index 0000000000..05a3c9ab69 --- /dev/null +++ b/tests/python/tests/diagnostic/test_err.py @@ -0,0 +1,15 @@ +import pytest +from python.lib.testcase import WebServerAutoTestCase + + +class TestErr(WebServerAutoTestCase): + def query(self, op: str): + resp = self.web_server.http_post(uri="/test_err", json=[{"op": op}]) + self.assertEqual(resp.text, "ok") + self.assertEqual(resp.status_code, 200) + + def test_just_make(self): + self.query("just_make") + + def test_throw_catch(self): + self.query("throw_catch") From 05a8bf2c3fd624cf9312354f1a80485187f14a4e Mon Sep 17 00:00:00 2001 From: Karim Shamazov Date: Wed, 25 Mar 2026 15:38:20 +0300 Subject: [PATCH 2/3] extend and enable ob tests --- tests/phpt/dl/482_ob.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/phpt/dl/482_ob.php b/tests/phpt/dl/482_ob.php index c2efd9b99e..d44fb10271 100644 --- a/tests/phpt/dl/482_ob.php +++ b/tests/phpt/dl/482_ob.php @@ -1,9 +1,14 @@ -@ok k2_skip +@ok Date: Wed, 25 Mar 2026 15:53:36 +0300 Subject: [PATCH 3/3] shuffle before sort --- tests/phpt/dl/495_sort.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/phpt/dl/495_sort.php b/tests/phpt/dl/495_sort.php index 040b8cd398..e61a35c07e 100644 --- a/tests/phpt/dl/495_sort.php +++ b/tests/phpt/dl/495_sort.php @@ -44,6 +44,8 @@ function cmp ($a, $b) { $to_sort[rand(0, 1000000000)] = rand(0, 1000000000); } +shuffle ($to_sort); + asort ($to_sort); krsort ($to_sort);