From a361ca1e3fcdf070af714c723feba55c9cade154 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Wed, 14 May 2025 15:58:57 +0000 Subject: [PATCH] test: improve logging in unit tests include API name unify tests timeout/sigabrt message across OSes Signed-off-by: Mateusz Jablonski --- .../test/common/ult_specific_config_l0.cpp | 4 ++++ .../test/unit_test/linux/main_linux_dll.cpp | 1 + .../ocloc_tests_configuration.cpp | 5 +++-- .../unit_test/ult_specific_config_ocl.cpp | 3 +++ .../common/helpers/custom_event_listener.h | 19 ++++++++++--------- .../os_interface/linux/signal_utils.cpp | 9 +++++---- .../os_interface/windows/signal_utils.cpp | 11 ++++++----- shared/test/unit_test/ult_specific_config.cpp | 1 + 8 files changed, 33 insertions(+), 20 deletions(-) diff --git a/level_zero/core/test/common/ult_specific_config_l0.cpp b/level_zero/core/test/common/ult_specific_config_l0.cpp index 691a87574f..abf29452ea 100644 --- a/level_zero/core/test/common/ult_specific_config_l0.cpp +++ b/level_zero/core/test/common/ult_specific_config_l0.cpp @@ -14,6 +14,10 @@ namespace L0 { extern std::vector<_ze_driver_handle_t *> *globalDriverHandles; } +namespace NEO { +const char *apiName = "L0"; +} + using namespace NEO; void cleanTestHelpers() { delete L0::globalDriverHandles; diff --git a/opencl/test/unit_test/linux/main_linux_dll.cpp b/opencl/test/unit_test/linux/main_linux_dll.cpp index ac0e894076..7a915237d7 100644 --- a/opencl/test/unit_test/linux/main_linux_dll.cpp +++ b/opencl/test/unit_test/linux/main_linux_dll.cpp @@ -51,6 +51,7 @@ namespace NEO { class OsLibrary; void __attribute__((destructor)) platformsDestructor(); extern const DeviceDescriptor deviceDescriptorTable[]; +const char *apiName = "OCL"; } // namespace NEO NEO::OsLibrary *setAdapterInfo(const PLATFORM *platform, const GT_SYSTEM_INFO *gtSystemInfo, uint64_t gpuAddressSpace) { diff --git a/opencl/test/unit_test/offline_compiler/ocloc_tests_configuration.cpp b/opencl/test/unit_test/offline_compiler/ocloc_tests_configuration.cpp index a1a4bb79c2..41bb205db1 100644 --- a/opencl/test/unit_test/offline_compiler/ocloc_tests_configuration.cpp +++ b/opencl/test/unit_test/offline_compiler/ocloc_tests_configuration.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2024 Intel Corporation + * Copyright (C) 2021-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -11,5 +11,6 @@ unsigned int ultIterationMaxTimeInS = 90; #else unsigned int ultIterationMaxTimeInS = 45; #endif -const char *executionName = "OCLOC"; +const char *executionName = "ULT"; +const char *apiName = "OCLOC"; } // namespace NEO diff --git a/opencl/test/unit_test/ult_specific_config_ocl.cpp b/opencl/test/unit_test/ult_specific_config_ocl.cpp index e71a21e324..0038ae0162 100644 --- a/opencl/test/unit_test/ult_specific_config_ocl.cpp +++ b/opencl/test/unit_test/ult_specific_config_ocl.cpp @@ -12,6 +12,9 @@ #include "opencl/test/unit_test/ult_config_listener.h" #include "test_files_setup.h" +namespace NEO { +const char *apiName = "OCL"; +} using namespace NEO; void applyWorkarounds() { diff --git a/shared/test/common/helpers/custom_event_listener.h b/shared/test/common/helpers/custom_event_listener.h index 4f373f779c..7531f13bfd 100644 --- a/shared/test/common/helpers/custom_event_listener.h +++ b/shared/test/common/helpers/custom_event_listener.h @@ -18,7 +18,8 @@ extern std::string lastTest; namespace NEO { extern const char *executionName; -} +extern const char *apiName; +} // namespace NEO class CCustomEventListener : public ::testing::TestEventListener { public: @@ -114,28 +115,28 @@ class CCustomEventListener : public ::testing::TestEventListener { if (unitTest.Failed()) { ultStatus = "FAILED"; } - auto executionNameLen = strlen(NEO::executionName); + auto targetNameLen = strlen(NEO::apiName) + 1 + strlen(NEO::executionName); if (hardwarePrefix != "---") { - paddingS = std::string(hardwarePrefix.length() + executionNameLen, ' '); - paddingE = std::string(hardwarePrefix.length() + executionNameLen, '='); + paddingS = std::string(hardwarePrefix.length() + targetNameLen, ' '); + paddingE = std::string(hardwarePrefix.length() + targetNameLen, '='); fprintf( stdout, "\n" "%s==================\n" - "== %s %ss %s ==\n" + "== %s %s %ss %s ==\n" "%s==================\n", - paddingE.c_str(), hardwarePrefix.c_str(), NEO::executionName, ultStatus.c_str(), paddingE.c_str()); + paddingE.c_str(), hardwarePrefix.c_str(), NEO::apiName, NEO::executionName, ultStatus.c_str(), paddingE.c_str()); } else { - paddingE = std::string(executionNameLen, '='); + paddingE = std::string(targetNameLen, '='); fprintf( stdout, "\n" "%s==================\n" - "== %ss %s ==\n" + "== %s %ss %s ==\n" "%s==================\n", - paddingE.c_str(), NEO::executionName, ultStatus.c_str(), paddingE.c_str()); + paddingE.c_str(), NEO::apiName, NEO::executionName, ultStatus.c_str(), paddingE.c_str()); } fprintf( diff --git a/shared/test/common/os_interface/linux/signal_utils.cpp b/shared/test/common/os_interface/linux/signal_utils.cpp index 05ba3d3017..efb30e1338 100644 --- a/shared/test/common/os_interface/linux/signal_utils.cpp +++ b/shared/test/common/os_interface/linux/signal_utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2024 Intel Corporation + * Copyright (C) 2022-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -17,6 +17,7 @@ std::string lastTest(""); namespace NEO { extern const unsigned int ultIterationMaxTimeInS; extern const char *executionName; +extern const char *apiName; } // namespace NEO int newStdOut = -1; @@ -26,7 +27,7 @@ void handleSIGABRT(int signal) { if (newStdOut != -1) { dup2(newStdOut, 1); } - std::cout << "SIGABRT in " << NEO::executionName << ", on: " << lastTest << std::endl; + std::cout << "SIGABRT in " << NEO::apiName << " " << NEO::executionName << ", on: " << lastTest << std::endl; if (sigaction(SIGABRT, &oldSigAbrt, nullptr) == -1) { std::cout << "FATAL: cannot fatal SIGABRT handler" << std::endl; std::cout << "FATAL: try SEGV" << std::endl; @@ -44,7 +45,7 @@ void handleSIGALRM(int signal) { if (newStdOut != -1) { dup2(newStdOut, 1); } - std::cout << "Tests timeout in " << NEO::executionName << ", "; + std::cout << "Tests timeout in " << NEO::apiName << " " << NEO::executionName << ","; if (clock_gettime(CLOCK_MONOTONIC_RAW, &alrmTimeSpec) == 0) { auto deltaSec = alrmTimeSpec.tv_sec - startTimeSpec.tv_sec; std::cout << " after: " << deltaSec << " seconds"; @@ -57,7 +58,7 @@ void handleSIGSEGV(int signal) { if (newStdOut != -1) { dup2(newStdOut, 1); } - std::cout << "SIGSEGV in " << NEO::executionName << ", on: " << lastTest << std::endl; + std::cout << "SIGSEGV in " << NEO::apiName << " " << NEO::executionName << ", on: " << lastTest << std::endl; abort(); } diff --git a/shared/test/common/os_interface/windows/signal_utils.cpp b/shared/test/common/os_interface/windows/signal_utils.cpp index 0fc8986b74..b65d12b5e1 100644 --- a/shared/test/common/os_interface/windows/signal_utils.cpp +++ b/shared/test/common/os_interface/windows/signal_utils.cpp @@ -21,6 +21,7 @@ std::string lastTest(""); static int newStdOut = -1; namespace NEO { +extern const char *apiName; extern const char *executionName; extern unsigned int ultIterationMaxTimeInS; } // namespace NEO @@ -39,7 +40,7 @@ void handleSIGABRT(int sigNo) { if (newStdOut != -1) { _dup2(newStdOut, 1); } - std::cout << "SIGABRT on: " << lastTest << std::endl; + std::cout << "SIGABRT in " << NEO::apiName << " " << NEO::executionName << ", on: " << lastTest << std::endl; signal(SIGABRT, oldSigAbrt); raise(sigNo); } @@ -92,20 +93,20 @@ int setAlarm(bool enableAlarm) { std::cout << "set timeout to: " << alarmTimeInS << " seconds" << std::endl; threadStarted = true; std::chrono::high_resolution_clock::time_point startTime, endTime; - std::chrono::milliseconds elapsedTime{}; + std::chrono::milliseconds elapsedTimeInMs{}; startTime = std::chrono::high_resolution_clock::now(); do { std::this_thread::yield(); std::this_thread::sleep_for(std::chrono::milliseconds(1)); endTime = std::chrono::high_resolution_clock::now(); - elapsedTime = std::chrono::duration_cast(endTime - startTime); + elapsedTimeInMs = std::chrono::duration_cast(endTime - startTime); if (!abortOnTimeout) { return; } - } while (abortOnTimeout && elapsedTime.count() < alarmTimeInS * 1000); + } while (abortOnTimeout && elapsedTimeInMs.count() < alarmTimeInS * 1000); if (abortOnTimeout) { - printf("timeout on: %s\n", lastTest.c_str()); + printf("Tests timeout in %s %s, after %u seconds on %s\n", NEO::apiName, NEO::executionName, static_cast(elapsedTimeInMs.count() / 1000), lastTest.c_str()); abort(); } }); diff --git a/shared/test/unit_test/ult_specific_config.cpp b/shared/test/unit_test/ult_specific_config.cpp index 022dbc21ca..790b42b8aa 100644 --- a/shared/test/unit_test/ult_specific_config.cpp +++ b/shared/test/unit_test/ult_specific_config.cpp @@ -38,6 +38,7 @@ void CpuPageFaultManager::allowCPUMemoryEviction(bool evict, void *ptr, PageFaul void RootDeviceEnvironment::initApiGfxCoreHelper() { } +const char *apiName = "SHARED"; } // namespace NEO