From 739e781fd8e6ef6b891f1b48ea0293bacc8f7764 Mon Sep 17 00:00:00 2001 From: shubham kumar Date: Mon, 12 Aug 2024 13:33:15 +0000 Subject: [PATCH] fix(sysman): Fix sysman APIs taking incorrect path Related-To: NEO-12291 Signed-off-by: shubham kumar --- .../unit_tests/sources/linux/test_sysman_driver.cpp | 11 ++++++++++- level_zero/tools/source/sysman/sysman.cpp | 9 ++++++++- .../unit_tests/sources/sysman/linux/test_sysman.cpp | 11 +++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/level_zero/sysman/test/unit_tests/sources/linux/test_sysman_driver.cpp b/level_zero/sysman/test/unit_tests/sources/linux/test_sysman_driver.cpp index c7c25b163a..b81f37d727 100644 --- a/level_zero/sysman/test/unit_tests/sources/linux/test_sysman_driver.cpp +++ b/level_zero/sysman/test/unit_tests/sources/linux/test_sysman_driver.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -12,6 +12,7 @@ #include "shared/test/common/mocks/mock_execution_environment.h" #include "shared/test/common/os_interface/linux/sys_calls_linux_ult.h" +#include "level_zero/core/source/driver/driver.h" #include "level_zero/sysman/source/device/sysman_device.h" #include "level_zero/sysman/source/driver/sysman_driver_handle.h" #include "level_zero/sysman/source/driver/sysman_driver_handle_imp.h" @@ -331,6 +332,14 @@ TEST_F(SysmanDriverHandleTest, EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result); } +TEST(SysmanDriverInit, GivenValidSysmanImpObjectWhenCallingInitWithSysmanInitFromCoreSetAsTrueThenSysmanInitFails) { + L0::sysmanInitFromCore = true; + std::unique_ptr pSysmanDriverImp = std::make_unique(); + EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, pSysmanDriverImp->driverInit(0)); + EXPECT_FALSE(L0::Sysman::sysmanOnlyInit); + L0::sysmanInitFromCore = false; +} + } // namespace ult } // namespace Sysman } // namespace L0 diff --git a/level_zero/tools/source/sysman/sysman.cpp b/level_zero/tools/source/sysman/sysman.cpp index 5337a2fa20..fc796ff899 100644 --- a/level_zero/tools/source/sysman/sysman.cpp +++ b/level_zero/tools/source/sysman/sysman.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -13,6 +13,7 @@ #include "level_zero/core/source/device/device_imp.h" #include "level_zero/core/source/driver/driver.h" #include "level_zero/core/source/driver/driver_handle_imp.h" +#include "level_zero/sysman/source/driver/sysman_driver.h" #include "level_zero/tools/source/sysman/os_sysman_driver.h" #include "level_zero/tools/source/sysman/sysman_imp.h" @@ -34,6 +35,12 @@ void DeviceImp::createSysmanHandle(bool isSubDevice) { } SysmanDevice *SysmanDeviceHandleContext::init(ze_device_handle_t coreDevice) { + if (L0::Sysman::sysmanOnlyInit) { + NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, + "%s", "Sysman Initialization already happened via zesInit\n"); + return nullptr; + } + SysmanDeviceImp *sysmanDevice = new SysmanDeviceImp(coreDevice); DEBUG_BREAK_IF(!sysmanDevice); if (ZE_RESULT_SUCCESS != sysmanDevice->init()) { diff --git a/level_zero/tools/test/unit_tests/sources/sysman/linux/test_sysman.cpp b/level_zero/tools/test/unit_tests/sources/sysman/linux/test_sysman.cpp index 113ee175b2..91aec819c8 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/linux/test_sysman.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/linux/test_sysman.cpp @@ -11,6 +11,7 @@ #include "shared/test/common/os_interface/linux/sys_calls_linux_ult.h" #include "shared/test/common/test_macros/test.h" +#include "level_zero/sysman/source/driver/sysman_driver.h" #include "level_zero/tools/source/sysman/diagnostics/linux/os_diagnostics_imp.h" #include "level_zero/tools/source/sysman/events/linux/os_events_imp.h" #include "level_zero/tools/source/sysman/firmware/linux/os_firmware_imp.h" @@ -216,6 +217,16 @@ TEST_F(SysmanDeviceFixture, GivenValidDeviceHandleButSysmanInitFailsThenValidNul EXPECT_EQ(pSysmanDevice, nullptr); } +TEST_F(SysmanDeviceFixture, GivenValidDeviceHandleWithSysmanOnlyInitSetAsTrueThenSysmanInitFailsAndValidNullptrReceived) { + ze_device_handle_t hSysman = device->toHandle(); + L0::Sysman::sysmanOnlyInit = true; + L0::sysmanInitFromCore = false; + auto pSysmanDevice = L0::SysmanDeviceHandleContext::init(hSysman); + EXPECT_EQ(pSysmanDevice, nullptr); + EXPECT_FALSE(L0::sysmanInitFromCore); + L0::Sysman::sysmanOnlyInit = false; +} + TEST_F(SysmanDeviceFixture, GivenSetValidDrmHandleForDeviceWhenDoingOsSysmanDeviceInitThenSameDrmHandleIsRetrieved) { EXPECT_EQ(&pLinuxSysmanImp->getDrm(), device->getOsInterface().getDriverModel()->as()); }