From 16dd1ebd9a0eecae8e43ab0973129ce044ca706c Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Wed, 12 Jul 2023 12:17:35 +0000 Subject: [PATCH] fix: add missing nullptr check in adjustRootDeviceEnvironments method Related-To: NEO-8166 Signed-off-by: Mateusz Jablonski --- .../execution_environment_drm_or_wddm.cpp | 2 +- .../linux/device_factory_tests_linux.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/shared/source/execution_environment/execution_environment_drm_or_wddm.cpp b/shared/source/execution_environment/execution_environment_drm_or_wddm.cpp index 419ad19163..ccb950fe60 100644 --- a/shared/source/execution_environment/execution_environment_drm_or_wddm.cpp +++ b/shared/source/execution_environment/execution_environment_drm_or_wddm.cpp @@ -14,7 +14,7 @@ namespace NEO { void ExecutionEnvironment::adjustRootDeviceEnvironments() { - if (rootDeviceEnvironments[0]->osInterface->getDriverModel()->getDriverModelType() == DriverModelType::DRM) { + if (!rootDeviceEnvironments.empty() && rootDeviceEnvironments[0]->osInterface->getDriverModel()->getDriverModelType() == DriverModelType::DRM) { for (auto rootDeviceIndex = 0u; rootDeviceIndex < rootDeviceEnvironments.size(); rootDeviceIndex++) { auto drmMemoryOperationsHandler = static_cast(rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface.get()); drmMemoryOperationsHandler->setRootDeviceIndex(rootDeviceIndex); diff --git a/shared/test/unit_test/os_interface/linux/device_factory_tests_linux.cpp b/shared/test/unit_test/os_interface/linux/device_factory_tests_linux.cpp index 5f4f87c9f1..d3158fde62 100644 --- a/shared/test/unit_test/os_interface/linux/device_factory_tests_linux.cpp +++ b/shared/test/unit_test/os_interface/linux/device_factory_tests_linux.cpp @@ -81,6 +81,7 @@ TEST(SortAndFilterDevicesDrmTest, whenSortingAndFilteringDevicesThenMemoryOperat DebugManager.flags.CreateMultipleRootDevices.set(numRootDevices); DebugManager.flags.ZE_AFFINITY_MASK.set("1,2,3,4,5"); + VariableBackup osContextCountBackup(&MemoryManager::maxOsContextCount); VariableBackup>> directoryFilesMapBackup(&directoryFilesMap); VariableBackup pciDevicesDirectoryBackup(&Os::pciDevicesDirectory); VariableBackup mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int { @@ -115,3 +116,17 @@ TEST(SortAndFilterDevicesDrmTest, whenSortingAndFilteringDevicesThenMemoryOperat EXPECT_EQ(rootDeviceIndex, static_cast(*executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface).getRootDeviceIndex()); } } + +TEST(DeviceFactoryAffinityMaskTest, whenAffinityMaskDoesNotSelectAnyDeviceThenEmptyEnvironmentIsReturned) { + static const auto numRootDevices = 6; + DebugManagerStateRestore dbgRestorer; + DebugManager.flags.CreateMultipleRootDevices.set(numRootDevices); + DebugManager.flags.ZE_AFFINITY_MASK.set("100"); + + VariableBackup osContextCountBackup(&MemoryManager::maxOsContextCount); + ExecutionEnvironment executionEnvironment{}; + bool success = DeviceFactory::prepareDeviceEnvironments(executionEnvironment); + EXPECT_TRUE(success); + + EXPECT_EQ(0u, executionEnvironment.rootDeviceEnvironments.size()); +}