Skip to content

Commit

Permalink
fix: add missing nullptr check in adjustRootDeviceEnvironments method
Browse files Browse the repository at this point in the history
Related-To: NEO-8166
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
Source: 16dd1eb
  • Loading branch information
JablonskiMateusz authored and Compute-Runtime-Automation committed Aug 4, 2023
1 parent bd724de commit 4afb8cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Expand Up @@ -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<DrmMemoryOperationsHandler *>(rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface.get());
drmMemoryOperationsHandler->setRootDeviceIndex(rootDeviceIndex);
Expand Down
Expand Up @@ -81,6 +81,7 @@ TEST(SortAndFilterDevicesDrmTest, whenSortingAndFilteringDevicesThenMemoryOperat
DebugManager.flags.CreateMultipleRootDevices.set(numRootDevices);
DebugManager.flags.ZE_AFFINITY_MASK.set("1,2,3,4,5");

VariableBackup<uint32_t> osContextCountBackup(&MemoryManager::maxOsContextCount);
VariableBackup<std::map<std::string, std::vector<std::string>>> directoryFilesMapBackup(&directoryFilesMap);
VariableBackup<const char *> pciDevicesDirectoryBackup(&Os::pciDevicesDirectory);
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
Expand Down Expand Up @@ -115,3 +116,17 @@ TEST(SortAndFilterDevicesDrmTest, whenSortingAndFilteringDevicesThenMemoryOperat
EXPECT_EQ(rootDeviceIndex, static_cast<DrmMemoryOperationsHandlerBind &>(*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<uint32_t> osContextCountBackup(&MemoryManager::maxOsContextCount);
ExecutionEnvironment executionEnvironment{};
bool success = DeviceFactory::prepareDeviceEnvironments(executionEnvironment);
EXPECT_TRUE(success);

EXPECT_EQ(0u, executionEnvironment.rootDeviceEnvironments.size());
}

0 comments on commit 4afb8cf

Please sign in to comment.