Skip to content

Commit 4afb8cf

Browse files
fix: add missing nullptr check in adjustRootDeviceEnvironments method
Related-To: NEO-8166 Signed-off-by: Mateusz Jablonski <[email protected]> Source: 16dd1eb
1 parent bd724de commit 4afb8cf

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

shared/source/execution_environment/execution_environment_drm_or_wddm.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace NEO {
1515

1616
void ExecutionEnvironment::adjustRootDeviceEnvironments() {
17-
if (rootDeviceEnvironments[0]->osInterface->getDriverModel()->getDriverModelType() == DriverModelType::DRM) {
17+
if (!rootDeviceEnvironments.empty() && rootDeviceEnvironments[0]->osInterface->getDriverModel()->getDriverModelType() == DriverModelType::DRM) {
1818
for (auto rootDeviceIndex = 0u; rootDeviceIndex < rootDeviceEnvironments.size(); rootDeviceIndex++) {
1919
auto drmMemoryOperationsHandler = static_cast<DrmMemoryOperationsHandler *>(rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface.get());
2020
drmMemoryOperationsHandler->setRootDeviceIndex(rootDeviceIndex);

shared/test/unit_test/os_interface/linux/device_factory_tests_linux.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ TEST(SortAndFilterDevicesDrmTest, whenSortingAndFilteringDevicesThenMemoryOperat
8181
DebugManager.flags.CreateMultipleRootDevices.set(numRootDevices);
8282
DebugManager.flags.ZE_AFFINITY_MASK.set("1,2,3,4,5");
8383

84+
VariableBackup<uint32_t> osContextCountBackup(&MemoryManager::maxOsContextCount);
8485
VariableBackup<std::map<std::string, std::vector<std::string>>> directoryFilesMapBackup(&directoryFilesMap);
8586
VariableBackup<const char *> pciDevicesDirectoryBackup(&Os::pciDevicesDirectory);
8687
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
@@ -115,3 +116,17 @@ TEST(SortAndFilterDevicesDrmTest, whenSortingAndFilteringDevicesThenMemoryOperat
115116
EXPECT_EQ(rootDeviceIndex, static_cast<DrmMemoryOperationsHandlerBind &>(*executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface).getRootDeviceIndex());
116117
}
117118
}
119+
120+
TEST(DeviceFactoryAffinityMaskTest, whenAffinityMaskDoesNotSelectAnyDeviceThenEmptyEnvironmentIsReturned) {
121+
static const auto numRootDevices = 6;
122+
DebugManagerStateRestore dbgRestorer;
123+
DebugManager.flags.CreateMultipleRootDevices.set(numRootDevices);
124+
DebugManager.flags.ZE_AFFINITY_MASK.set("100");
125+
126+
VariableBackup<uint32_t> osContextCountBackup(&MemoryManager::maxOsContextCount);
127+
ExecutionEnvironment executionEnvironment{};
128+
bool success = DeviceFactory::prepareDeviceEnvironments(executionEnvironment);
129+
EXPECT_TRUE(success);
130+
131+
EXPECT_EQ(0u, executionEnvironment.rootDeviceEnvironments.size());
132+
}

0 commit comments

Comments
 (0)