From f24e2ca6768f792b88118556de38995be685bff0 Mon Sep 17 00:00:00 2001 From: vstojilj Date: Mon, 15 Sep 2025 15:58:41 +0200 Subject: [PATCH] SWDEV-546865 - Disable core dumps when running tests (#880) * SWDEV-546865 - Disable core dumps when running tests * SWDEV-546865 - Disable core dumps only for tests that require it --- .../catch/include/hip_test_common.hh | 30 +++++++++++++++++++ .../errorHandling/hipGetLastErrorOnAbort.cc | 12 ++++++++ 2 files changed, 42 insertions(+) diff --git a/projects/hip-tests/catch/include/hip_test_common.hh b/projects/hip-tests/catch/include/hip_test_common.hh index 22716158d9..133cfe3cef 100644 --- a/projects/hip-tests/catch/include/hip_test_common.hh +++ b/projects/hip-tests/catch/include/hip_test_common.hh @@ -36,6 +36,10 @@ THE SOFTWARE. #include #include "hip_test_features.hh" +#if HT_LINUX +#include +#endif + #ifdef TEST_CLOCK_CYCLE #define clock_function() clock64() #else @@ -634,3 +638,29 @@ class BlockingContext { } \ HIP_CHECK(hipStreamDestroy(stream)); \ } + +// Manage core dumps in specific tests which require it disabled (e.g., hipGetLastErrorOnAbort.cc) +#if HT_LINUX +#define DISABLE_CORE_DUMPS() \ + struct rlimit core_limit; \ + bool rlimit_saved = false; \ + if (getrlimit(RLIMIT_CORE, &core_limit) == 0) { \ + if (core_limit.rlim_cur != 0) { \ + struct rlimit new_limit; \ + new_limit.rlim_cur = 0; \ + new_limit.rlim_max = core_limit.rlim_max; \ + if (setrlimit(RLIMIT_CORE, &new_limit) == 0) { \ + rlimit_saved = true; \ + } \ + } \ + } + +#define RESTORE_CORE_DUMPS() \ + if (rlimit_saved) { \ + setrlimit(RLIMIT_CORE, &core_limit); \ + rlimit_saved = false; \ + } +#else +#define DISABLE_CORE_DUMPS() +#define RESTORE_CORE_DUMPS() +#endif diff --git a/projects/hip-tests/catch/unit/errorHandling/hipGetLastErrorOnAbort.cc b/projects/hip-tests/catch/unit/errorHandling/hipGetLastErrorOnAbort.cc index 3f84eef06e..1570e55ed6 100644 --- a/projects/hip-tests/catch/unit/errorHandling/hipGetLastErrorOnAbort.cc +++ b/projects/hip-tests/catch/unit/errorHandling/hipGetLastErrorOnAbort.cc @@ -46,6 +46,8 @@ static __global__ void squareKernel(int* arr) { * - HIP_VERSION >= 7.0 */ TEST_CASE("Unit_hipGetLastError_KernelFailure_ValidAndInvalidOperations") { + DISABLE_CORE_DUMPS(); + int* devMem = nullptr; HIP_CHECK(hipMalloc(&devMem, sizeBytes)); REQUIRE(devMem != nullptr); @@ -83,6 +85,8 @@ TEST_CASE("Unit_hipGetLastError_KernelFailure_ValidAndInvalidOperations") { ret = hipGetLastError(); REQUIRE(ret == hipErrorIllegalAddress); + + RESTORE_CORE_DUMPS(); } /** @@ -106,6 +110,8 @@ TEST_CASE("Unit_hipGetLastError_KernelFailure_TwoDevices") { return; } + DISABLE_CORE_DUMPS(); + // Perform Invalid operation on Device 0 HIP_CHECK(hipSetDevice(0)); @@ -147,6 +153,8 @@ TEST_CASE("Unit_hipGetLastError_KernelFailure_TwoDevices") { ret = hipGetLastError(); REQUIRE(ret == expectedError); + + RESTORE_CORE_DUMPS(); } /** @@ -163,6 +171,8 @@ TEST_CASE("Unit_hipGetLastError_KernelFailure_TwoDevices") { * - HIP_VERSION >= 7.0 */ TEST_CASE("Unit_hipGetLastError_KernelFailure_TwoStreams") { + DISABLE_CORE_DUMPS(); + int* devMem = nullptr; HIP_CHECK(hipMalloc(&devMem, sizeBytes)); REQUIRE(devMem != nullptr); @@ -197,4 +207,6 @@ TEST_CASE("Unit_hipGetLastError_KernelFailure_TwoStreams") { ret = hipGetLastError(); REQUIRE(ret == hipErrorIllegalAddress); + + RESTORE_CORE_DUMPS(); }