diff --git a/level_zero/sysman/source/shared/linux/zes_os_sysman_imp.cpp b/level_zero/sysman/source/shared/linux/zes_os_sysman_imp.cpp index ca4e9e5288..ac907c6d90 100644 --- a/level_zero/sysman/source/shared/linux/zes_os_sysman_imp.cpp +++ b/level_zero/sysman/source/shared/linux/zes_os_sysman_imp.cpp @@ -43,6 +43,7 @@ ze_result_t LinuxSysmanImp::init() { if (osInterface.getDriverModel()->getDriverModelType() != NEO::DriverModelType::drm) { return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; } + osInterface.getDriverModel()->cleanup(); pSysmanProductHelper = SysmanProductHelper::create(getProductFamily()); DEBUG_BREAK_IF(nullptr == pSysmanProductHelper); @@ -72,7 +73,6 @@ ze_result_t LinuxSysmanImp::init() { rootPath = NEO::getPciRootPath(myDeviceFd).value_or(""); pSysfsAccess->getRealPath(deviceDir, gtDevicePath); - osInterface.getDriverModel()->as()->cleanup(); pPmuInterface = PmuInterface::create(this); return result; } diff --git a/level_zero/sysman/test/unit_tests/sources/linux/test_sysman.cpp b/level_zero/sysman/test/unit_tests/sources/linux/test_sysman.cpp index 803662c04a..63bc2ff910 100644 --- a/level_zero/sysman/test/unit_tests/sources/linux/test_sysman.cpp +++ b/level_zero/sysman/test/unit_tests/sources/linux/test_sysman.cpp @@ -13,6 +13,7 @@ #include "level_zero/sysman/source/shared/linux/kmd_interface/sysman_kmd_interface.h" #include "level_zero/sysman/source/shared/linux/sysman_fs_access_interface.h" #include "level_zero/sysman/test/unit_tests/sources/linux/mock_sysman_fixture.h" +#include "level_zero/sysman/test/unit_tests/sources/linux/mocks/mock_sysman_product_helper.h" namespace NEO { namespace SysCalls { @@ -21,6 +22,7 @@ extern bool allowFakeDevicePath; } // namespace NEO namespace L0 { +extern bool sysmanInitFromCore; namespace Sysman { namespace ult { @@ -524,6 +526,23 @@ TEST(SysmanUnknownDriverModelTest, GivenDriverModelTypeIsNotDrmWhenExecutingSysm EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxSysmanImp->init()); } +TEST(SysmanTest, GivenDrmDriverModelWhenInitFailsDueToMissingZesInitSupportThenCleanupIsCalled) { + VariableBackup sysmanProductHelperBackup(&sysmanProductHelperFactory[defaultHwInfo->platform.eProductFamily], []() -> std::unique_ptr { return std::make_unique(); }); + VariableBackup sysmanInitFromCoreBackup(&sysmanInitFromCore, true); + auto execEnv = std::make_unique(); + execEnv->prepareRootDeviceEnvironments(1); + execEnv->rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(NEO::defaultHwInfo.get()); + execEnv->rootDeviceEnvironments[0]->osInterface = std::make_unique(); + execEnv->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::make_unique(NEO::DriverModelType::drm)); + + auto driverModel = static_cast(execEnv->rootDeviceEnvironments[0]->osInterface->getDriverModel()); + + auto pSysmanDeviceImp = std::make_unique(execEnv.release(), 0); + auto pLinuxSysmanImp = static_cast(pSysmanDeviceImp->pOsSysman); + EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxSysmanImp->init()); + EXPECT_EQ(1u, driverModel->cleanupCalled); +} + TEST(SysmanErrorCodeTest, GivenDifferentErrorCodesWhenCallingGetResultThenVerifyProperZeResultErrorIsReturned) { EXPECT_EQ(ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS, LinuxSysmanImp::getResult(EPERM)); EXPECT_EQ(ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS, LinuxSysmanImp::getResult(EACCES)); diff --git a/shared/test/common/mocks/mock_driver_model.h b/shared/test/common/mocks/mock_driver_model.h index 1e6e546c0b..cc55b9c734 100644 --- a/shared/test/common/mocks/mock_driver_model.h +++ b/shared/test/common/mocks/mock_driver_model.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Intel Corporation + * Copyright (C) 2022-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -11,6 +11,7 @@ #include "shared/source/os_interface/driver_info.h" #include "shared/source/os_interface/os_interface.h" #include "shared/test/common/helpers/default_hw_info.h" +#include "shared/test/common/test_macros/mock_method_macros.h" #include #include @@ -21,6 +22,7 @@ class MockDriverModel : public NEO::DriverModel { public: MockDriverModel() : MockDriverModel(NEO::DriverModelType::unknown) {} MockDriverModel(DriverModelType driverModelType) : DriverModel(driverModelType) {} + ADDMETHOD_NOBASE_VOIDRETURN(cleanup, ()); void setGmmInputArgs(void *args) override {}