From f279683b5deec18caf1f9b5a2ce7eb9ecc2e0e8b Mon Sep 17 00:00:00 2001 From: Maciej Kaszynski Date: Tue, 19 May 2026 10:05:23 +0100 Subject: [PATCH] Making tests create, and download core dumps --- .../test_incorrect_config_non_reporting.py | 2 +- tests/integration/smoke/smoke.py | 2 +- tests/utils/plugins/localhost.py | 8 +++++++ tests/utils/testing_utils/setup_test.py | 21 +++++++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/tests/integration/incorrect_config_non_reporting/test_incorrect_config_non_reporting.py b/tests/integration/incorrect_config_non_reporting/test_incorrect_config_non_reporting.py index c131c4cd..911cbfe9 100644 --- a/tests/integration/incorrect_config_non_reporting/test_incorrect_config_non_reporting.py +++ b/tests/integration/incorrect_config_non_reporting/test_incorrect_config_non_reporting.py @@ -12,7 +12,7 @@ # ******************************************************************************* import logging from tests.utils.testing_utils.run_until_file_deployed import run_until_file_deployed -from tests.utils.testing_utils.setup_test import setup_test +from tests.utils.testing_utils.setup_test import setup_test, download_core_dumps from tests.utils.testing_utils.test_results import assert_test_results from attribute_plugin import add_test_properties diff --git a/tests/integration/smoke/smoke.py b/tests/integration/smoke/smoke.py index 08d9f282..4fa1527c 100644 --- a/tests/integration/smoke/smoke.py +++ b/tests/integration/smoke/smoke.py @@ -12,7 +12,7 @@ # ******************************************************************************* import logging from tests.utils.testing_utils.run_until_file_deployed import run_until_file_deployed -from tests.utils.testing_utils.setup_test import setup_test +from tests.utils.testing_utils.setup_test import setup_test, download_core_dumps from tests.utils.testing_utils.test_results import assert_test_results from attribute_plugin import add_test_properties diff --git a/tests/utils/plugins/localhost.py b/tests/utils/plugins/localhost.py index 09d4e831..bdc2ddff 100644 --- a/tests/utils/plugins/localhost.py +++ b/tests/utils/plugins/localhost.py @@ -19,6 +19,7 @@ import time from pathlib import Path from typing import List +import resource import pytest @@ -127,6 +128,12 @@ def download(self, remote_path: str, local_path: str) -> None: def execute_async( self, binary_path: str, args=None, cwd: str = "/", **kwargs ) -> LocalAsyncProcess: + def _set_core_unlimited(): + """Function to set core dump limit in the subshell.""" + resource.setrlimit( + resource.RLIMIT_CORE, (resource.RLIM_INFINITY, resource.RLIM_INFINITY) + ) + cmd = ["fakeroot", "--", binary_path] + (args or []) cmd_logger = logging.getLogger(Path(binary_path).name) output_lines: List[str] = [] @@ -135,6 +142,7 @@ def execute_async( cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + preexec_fn=_set_core_unlimited, cwd=cwd, start_new_session=True, # Start under a new process group ) diff --git a/tests/utils/testing_utils/setup_test.py b/tests/utils/testing_utils/setup_test.py index c34fdd31..e3d4197a 100644 --- a/tests/utils/testing_utils/setup_test.py +++ b/tests/utils/testing_utils/setup_test.py @@ -39,3 +39,24 @@ def setup_test(request, target): assert res == 0, f"Couldn't extract tar {remote_tar}" logger.info("Test case setup finished") + + +@pytest.fixture(autouse=True, scope="function") +def download_core_dumps(target, remote_test_dir, test_output_dir): + """Downloads any core dump files from the remote after a test completes.""" + yield + + res, stdout = target.execute(f"find {remote_test_dir} -name 'core*' -type f") + if res != 0: + return + core_files = stdout.decode().strip().splitlines() + for remote_path in core_files: + remote_path = remote_path.strip() + if not remote_path: + continue + local_path = test_output_dir / Path(remote_path).name + try: + target.download(remote_path, str(local_path)) + logger.info(f"Downloaded core dump: {remote_path} -> {local_path}") + except Exception as e: + logger.warning(f"Failed to download core dump {remote_path}: {e}")