1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
|
/*
* Copyright (C) 2023-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/helpers/constants.h"
#include "shared/source/helpers/product_config_helper.h"
#include "shared/source/os_interface/device_factory.h"
#include "shared/source/release_helper/release_helper.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/default_hw_info.h"
#include "shared/test/common/helpers/device_caps_reader_test_helper.h"
#include "shared/test/common/helpers/gtest_helpers.h"
#include "shared/test/common/helpers/stream_capture.h"
#include "shared/test/common/mocks/mock_execution_environment.h"
#include "shared/test/common/mocks/mock_product_helper.h"
#include "shared/test/common/test_macros/hw_test.h"
using namespace NEO;
struct DeviceFactoryTests : ::testing::Test {
void SetUp() override {
ProductConfigHelper productConfigHelper{};
auto &aotInfos = productConfigHelper.getDeviceAotInfo();
for (const auto &aotInfo : aotInfos) {
if (aotInfo.hwInfo->platform.eProductFamily == productFamily) {
productConfig = aotInfo.aotConfig.value;
if (!aotInfo.deviceAcronyms.empty()) {
productAcronym = aotInfo.deviceAcronyms.front().str();
} else if (!aotInfo.rtlIdAcronyms.empty()) {
productAcronym = aotInfo.rtlIdAcronyms.front().str();
}
break;
}
}
}
DebugManagerStateRestore restore;
uint32_t productConfig;
std::string productAcronym;
};
TEST_F(DeviceFactoryTests, givenHwIpVersionOverrideWhenPrepareDeviceEnvironmentsForProductFamilyOverrideIsCalledThenCorrectValueIsSet) {
ExecutionEnvironment executionEnvironment{};
auto config = defaultHwInfo.get()->ipVersion.value;
debugManager.flags.OverrideHwIpVersion.set(config);
bool success = DeviceFactory::prepareDeviceEnvironmentsForProductFamilyOverride(executionEnvironment);
EXPECT_TRUE(success);
EXPECT_EQ(config, executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo()->ipVersion.value);
EXPECT_NE(0u, executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo()->platform.usDeviceID);
}
TEST_F(DeviceFactoryTests, givenHwIpVersionOverrideWhenPrepareDeviceEnvironmentsForProductFamilyOverrideIsCalledThenReleaseHelperContainsCorrectIpVersion) {
ExecutionEnvironment executionEnvironment{};
auto config = defaultHwInfo.get()->ipVersion.value;
debugManager.flags.OverrideHwIpVersion.set(config);
bool success = DeviceFactory::prepareDeviceEnvironmentsForProductFamilyOverride(executionEnvironment);
ASSERT_TRUE(success);
auto *releaseHelper = executionEnvironment.rootDeviceEnvironments[0]->getReleaseHelper();
if (releaseHelper == nullptr) {
GTEST_SKIP();
}
class ReleaseHelperExpose : public ReleaseHelper {
public:
using ReleaseHelper::hardwareIpVersion;
};
ReleaseHelperExpose *exposedReleaseHelper = static_cast<ReleaseHelperExpose *>(releaseHelper);
EXPECT_EQ(config, exposedReleaseHelper->hardwareIpVersion.value);
}
TEST_F(DeviceFactoryTests, givenHwIpVersionAndDeviceIdOverrideWhenPrepareDeviceEnvironmentsForProductFamilyOverrideIsCalledThenCorrectValueIsSet) {
ExecutionEnvironment executionEnvironment{};
auto config = defaultHwInfo.get()->ipVersion.value;
debugManager.flags.OverrideHwIpVersion.set(config);
debugManager.flags.ForceDeviceId.set("0x1234");
bool success = DeviceFactory::prepareDeviceEnvironmentsForProductFamilyOverride(executionEnvironment);
EXPECT_TRUE(success);
EXPECT_EQ(config, executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo()->ipVersion.value);
EXPECT_EQ(0x1234, executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo()->platform.usDeviceID);
}
TEST_F(DeviceFactoryTests, givenProductFamilyOverrideWhenPrepareDeviceEnvironmentsIsCalledThenCorrectValueIsSet) {
if (productAcronym.empty()) {
GTEST_SKIP();
}
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
debugManager.flags.ProductFamilyOverride.set(productAcronym);
bool success = DeviceFactory::prepareDeviceEnvironmentsForProductFamilyOverride(executionEnvironment);
EXPECT_TRUE(success);
EXPECT_EQ(productConfig, executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo()->ipVersion.value);
}
TEST_F(DeviceFactoryTests, givenHwIpVersionAndProductFamilyOverrideWhenPrepareDeviceEnvironmentsIsCalledThenCorrectValueIsSet) {
if (productAcronym.empty()) {
GTEST_SKIP();
}
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
debugManager.flags.OverrideHwIpVersion.set(0x1234u);
debugManager.flags.ProductFamilyOverride.set(productAcronym);
bool success = DeviceFactory::prepareDeviceEnvironmentsForProductFamilyOverride(executionEnvironment);
EXPECT_TRUE(success);
EXPECT_EQ(0x1234u, executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo()->ipVersion.value);
}
TEST_F(DeviceFactoryTests, givenDisabledRcsWhenPrepareDeviceEnvironmentsCalledThenSetFtrFlag) {
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
bool success = DeviceFactory::prepareDeviceEnvironmentsForProductFamilyOverride(executionEnvironment);
ASSERT_TRUE(success);
auto releaseHelper = executionEnvironment.rootDeviceEnvironments[0]->getReleaseHelper();
if (releaseHelper == nullptr) {
EXPECT_TRUE(executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo()->featureTable.flags.ftrRcsNode);
} else {
EXPECT_NE(executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo()->featureTable.flags.ftrRcsNode, releaseHelper->isRcsExposureDisabled());
}
}
TEST_F(DeviceFactoryTests, givenMultipleDevicesWhenInitializeResourcesSucceedsForAtLeastOneDeviceThenSuccessIsReturned) {
DebugManagerStateRestore restorer;
debugManager.flags.CreateMultipleRootDevices.set(3);
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get(), true, 3u);
EXPECT_EQ(3u, executionEnvironment.rootDeviceEnvironments.size());
auto rootDeviceEnvironment0 = static_cast<MockRootDeviceEnvironment *>(executionEnvironment.rootDeviceEnvironments[0].get());
auto rootDeviceEnvironment1 = static_cast<MockRootDeviceEnvironment *>(executionEnvironment.rootDeviceEnvironments[1].get());
auto rootDeviceEnvironment2 = static_cast<MockRootDeviceEnvironment *>(executionEnvironment.rootDeviceEnvironments[2].get());
rootDeviceEnvironment0->initOsInterfaceResults.push_back(true);
rootDeviceEnvironment0->initOsInterfaceExpectedCallCount = 1u;
// making rootDeviceEnvironment1 returning false on first call and true on second call
rootDeviceEnvironment1->initOsInterfaceResults.push_back(false);
rootDeviceEnvironment1->initOsInterfaceResults.push_back(true);
rootDeviceEnvironment1->initOsInterfaceExpectedCallCount = 2u;
rootDeviceEnvironment2->initOsInterfaceExpectedCallCount = 0u;
bool success = DeviceFactory::prepareDeviceEnvironments(executionEnvironment);
ASSERT_TRUE(success);
EXPECT_EQ(2u, executionEnvironment.rootDeviceEnvironments.size());
EXPECT_EQ(1u, rootDeviceEnvironment0->initOsInterfaceCalled);
EXPECT_EQ(2u, rootDeviceEnvironment1->initOsInterfaceCalled);
}
TEST_F(DeviceFactoryTests, givenMultipleDevicesWhenInitializeResourcesFailsForAllDevicesThenFailureIsReturned) {
DebugManagerStateRestore restorer;
debugManager.flags.CreateMultipleRootDevices.set(3);
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get(), true, 3u);
EXPECT_EQ(3u, executionEnvironment.rootDeviceEnvironments.size());
auto rootDeviceEnvironment0 = static_cast<MockRootDeviceEnvironment *>(executionEnvironment.rootDeviceEnvironments[0].get());
auto rootDeviceEnvironment1 = static_cast<MockRootDeviceEnvironment *>(executionEnvironment.rootDeviceEnvironments[1].get());
auto rootDeviceEnvironment2 = static_cast<MockRootDeviceEnvironment *>(executionEnvironment.rootDeviceEnvironments[2].get());
// making root device environment failing three times (once per device)
rootDeviceEnvironment0->initOsInterfaceResults.push_back(false);
rootDeviceEnvironment0->initOsInterfaceResults.push_back(false);
rootDeviceEnvironment0->initOsInterfaceResults.push_back(false);
rootDeviceEnvironment0->initOsInterfaceExpectedCallCount = 3u;
rootDeviceEnvironment1->initOsInterfaceExpectedCallCount = 0u;
rootDeviceEnvironment2->initOsInterfaceExpectedCallCount = 0u;
bool success = DeviceFactory::prepareDeviceEnvironments(executionEnvironment);
EXPECT_FALSE(success);
EXPECT_EQ(0u, executionEnvironment.rootDeviceEnvironments.size());
}
TEST_F(DeviceFactoryTests, givenFailedAilInitializationResultWhenPrepareDeviceEnvironmentsIsCalledThenReturnFalse) {
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
auto mockRootDeviceEnvironment = static_cast<MockRootDeviceEnvironment *>(executionEnvironment.rootDeviceEnvironments[0].get());
mockRootDeviceEnvironment->ailInitializationResult = false;
bool res = DeviceFactory::prepareDeviceEnvironmentsForProductFamilyOverride(executionEnvironment);
EXPECT_FALSE(res);
}
struct DeviceFactoryOverrideTest : public ::testing::Test {
MockExecutionEnvironment executionEnvironment{defaultHwInfo.get()};
};
TEST_F(DeviceFactoryOverrideTest, givenDebugFlagSetWhenPrepareDeviceEnvironmentsIsCalledThenOverrideGpuAddressSpace) {
DebugManagerStateRestore restore;
debugManager.flags.OverrideGpuAddressSpace.set(12);
bool success = DeviceFactory::prepareDeviceEnvironments(executionEnvironment);
EXPECT_TRUE(success);
EXPECT_EQ(maxNBitValue(12), executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo()->capabilityTable.gpuAddressSpace);
}
TEST_F(DeviceFactoryOverrideTest, givenDebugFlagSetWhenPrepareDeviceEnvironmentsForProductFamilyOverrideIsCalledThenOverrideGpuAddressSpace) {
DebugManagerStateRestore restore;
debugManager.flags.OverrideGpuAddressSpace.set(12);
bool success = DeviceFactory::prepareDeviceEnvironmentsForProductFamilyOverride(executionEnvironment);
EXPECT_TRUE(success);
EXPECT_EQ(maxNBitValue(12), executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo()->capabilityTable.gpuAddressSpace);
}
TEST_F(DeviceFactoryOverrideTest, givenDebugFlagSetWhenPrepareDeviceEnvironmentsIsCalledThenOverrideRevision) {
DebugManagerStateRestore restore;
debugManager.flags.OverrideRevision.set(3);
bool success = DeviceFactory::prepareDeviceEnvironments(executionEnvironment);
EXPECT_TRUE(success);
EXPECT_EQ(3u, executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo()->platform.usRevId);
}
TEST_F(DeviceFactoryOverrideTest, givenDebugFlagSetWhenPrepareDeviceEnvironmentsForProductFamilyOverrideIsCalledThenOverrideRevision) {
DebugManagerStateRestore restore;
debugManager.flags.OverrideRevision.set(3);
bool success = DeviceFactory::prepareDeviceEnvironmentsForProductFamilyOverride(executionEnvironment);
EXPECT_TRUE(success);
EXPECT_EQ(3u, executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo()->platform.usRevId);
}
TEST_F(DeviceFactoryOverrideTest, givenDebugFlagWithoutZeroXWhenPrepareDeviceEnvironmentsForProductFamilyOverrideIsCalledThenOverrideDeviceIdToHexValue) {
DebugManagerStateRestore restore;
debugManager.flags.ForceDeviceId.set("1234");
bool success = DeviceFactory::prepareDeviceEnvironmentsForProductFamilyOverride(executionEnvironment);
EXPECT_TRUE(success);
EXPECT_EQ(0x1234u, executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo()->platform.usDeviceID);
}
TEST_F(DeviceFactoryOverrideTest, givenDebugFlagWithZeroXWhenPrepareDeviceEnvironmentsForProductFamilyOverrideIsCalledThenOverrideDeviceIdToHexValue) {
DebugManagerStateRestore restore;
debugManager.flags.ForceDeviceId.set("0x1234");
bool success = DeviceFactory::prepareDeviceEnvironmentsForProductFamilyOverride(executionEnvironment);
EXPECT_TRUE(success);
EXPECT_EQ(0x1234u, executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo()->platform.usDeviceID);
}
TEST_F(DeviceFactoryOverrideTest, givenDebugFlagSetWhenPrepareDeviceEnvironmentsIsCalledThenOverrideSlmSize) {
DebugManagerStateRestore restore;
debugManager.flags.OverrideSlmSize.set(123);
bool success = DeviceFactory::prepareDeviceEnvironments(executionEnvironment);
EXPECT_TRUE(success);
EXPECT_EQ(123u, executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo()->capabilityTable.maxProgrammableSlmSize);
EXPECT_EQ(123u, executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo()->gtSystemInfo.SLMSizeInKb);
}
TEST_F(DeviceFactoryOverrideTest, givenDebugFlagSetWhenPrepareDeviceEnvironmentsForProductFamilyOverrideIsCalledThenOverrideSlmSize) {
DebugManagerStateRestore restore;
debugManager.flags.OverrideSlmSize.set(123);
bool success = DeviceFactory::prepareDeviceEnvironmentsForProductFamilyOverride(executionEnvironment);
EXPECT_TRUE(success);
EXPECT_EQ(123u, executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo()->capabilityTable.maxProgrammableSlmSize);
EXPECT_EQ(123u, executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo()->gtSystemInfo.SLMSizeInKb);
}
TEST_F(DeviceFactoryOverrideTest, givenDebugFlagSetWhenPrepareDeviceEnvironmentsIsCalledThenOverrideRegionCount) {
DebugManagerStateRestore restore;
debugManager.flags.OverrideRegionCount.set(123);
EXPECT_TRUE(DeviceFactory::prepareDeviceEnvironments(executionEnvironment));
EXPECT_EQ(123u, executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo()->featureTable.regionCount);
}
TEST_F(DeviceFactoryOverrideTest, givenDebugFlagSetWhenPrepareDeviceEnvironmentsForProductFamilyOverrideIsCalledThenOverrideRegionCount) {
DebugManagerStateRestore restore;
debugManager.flags.OverrideRegionCount.set(123);
EXPECT_TRUE(DeviceFactory::prepareDeviceEnvironmentsForProductFamilyOverride(executionEnvironment));
EXPECT_EQ(123u, executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo()->featureTable.regionCount);
}
TEST_F(DeviceFactoryOverrideTest, givenInvalidPlatformStringWhenPrepareDeviceEnvironmentsForProductFamilyOverrideIsCalledThenFailureIsReturned) {
DebugManagerStateRestore restore;
debugManager.flags.ProductFamilyOverride.set("invalid");
EXPECT_FALSE(DeviceFactory::prepareDeviceEnvironmentsForProductFamilyOverride(executionEnvironment));
}
TEST_F(DeviceFactoryOverrideTest, givenFailedProductHelperSetupHardwareInfoWhenPreparingDeviceEnvironmentsForProductFamilyOverrideThenFalseIsReturned) {
DebugManagerStateRestore stateRestore;
debugManager.flags.SetCommandStreamReceiver.set(static_cast<int>(CommandStreamReceiverType::tbx));
struct MyMockProductHelper : MockProductHelper {
std::unique_ptr<DeviceCapsReader> getDeviceCapsReader(aub_stream::AubManager &aubManager) const override {
std::vector<uint32_t> caps;
return std::make_unique<DeviceCapsReaderMock>(caps);
}
};
auto productHelper = new MyMockProductHelper();
productHelper->setupHardwareInfoResult = false;
executionEnvironment.rootDeviceEnvironments[0]->productHelper.reset(productHelper);
auto rc = DeviceFactory::prepareDeviceEnvironmentsForProductFamilyOverride(executionEnvironment);
EXPECT_EQ(false, rc);
EXPECT_EQ(1u, productHelper->setupHardwareInfoCalled);
}
TEST_F(DeviceFactoryOverrideTest, givenDefaultHwInfoWhenPrepareDeviceEnvironmentsForProductFamilyOverrideIsCalledThenSlmSizeInKbEqualsMaxProgrammableSlmSize) {
DebugManagerStateRestore restore;
bool success = DeviceFactory::prepareDeviceEnvironmentsForProductFamilyOverride(executionEnvironment);
EXPECT_TRUE(success);
auto hwInfo = executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo();
EXPECT_EQ(hwInfo->capabilityTable.maxProgrammableSlmSize, hwInfo->gtSystemInfo.SLMSizeInKb);
}
HWTEST_F(DeviceFactoryOverrideTest, GivenAubModeWhenValidateDeviceFlagsThenIsProperMessagePrintedAndValueReturned) {
DebugManagerStateRestore restorer;
debugManager.flags.SetCommandStreamReceiver.set(static_cast<int32_t>(CommandStreamReceiverType::aub));
std::string expectedMissingProductFamilyStderrSubstr("Missing override for product family, required to set flag ProductFamilyOverride in non hw mode\n");
std::string expectedMissingHardwareInfoStderrSubstr("Missing override for hardware info, required to set flag HardwareInfoOverride in non hw mode\n");
auto defaultProductFamily = hardwarePrefix[defaultHwInfo.get()->platform.eProductFamily];
auto &productHelper = executionEnvironment.rootDeviceEnvironments[0]->getProductHelper();
StreamCapture capture;
{
debugManager.flags.ProductFamilyOverride.set("unk");
debugManager.flags.HardwareInfoOverride.set("default");
capture.captureStderr();
EXPECT_FALSE(DeviceFactory::validateDeviceFlags(productHelper));
auto capturedStderr = capture.getCapturedStderr();
EXPECT_TRUE(hasSubstr(capturedStderr, expectedMissingProductFamilyStderrSubstr));
EXPECT_TRUE(hasSubstr(capturedStderr, expectedMissingHardwareInfoStderrSubstr));
}
{
debugManager.flags.ProductFamilyOverride.set(defaultProductFamily);
debugManager.flags.HardwareInfoOverride.set("default");
capture.captureStderr();
EXPECT_FALSE(DeviceFactory::validateDeviceFlags(productHelper));
auto capturedStderr = capture.getCapturedStderr();
EXPECT_FALSE(hasSubstr(capturedStderr, expectedMissingProductFamilyStderrSubstr));
EXPECT_TRUE(hasSubstr(capturedStderr, expectedMissingHardwareInfoStderrSubstr));
}
{
debugManager.flags.ProductFamilyOverride.set("unk");
debugManager.flags.HardwareInfoOverride.set("1x1x1");
capture.captureStderr();
EXPECT_FALSE(DeviceFactory::validateDeviceFlags(productHelper));
auto capturedStderr = capture.getCapturedStderr();
EXPECT_TRUE(hasSubstr(capturedStderr, expectedMissingProductFamilyStderrSubstr));
EXPECT_FALSE(hasSubstr(capturedStderr, expectedMissingHardwareInfoStderrSubstr));
}
{
debugManager.flags.ProductFamilyOverride.set(defaultProductFamily);
debugManager.flags.HardwareInfoOverride.set("1x1x1");
capture.captureStderr();
EXPECT_TRUE(DeviceFactory::validateDeviceFlags(productHelper));
auto capturedStderr = capture.getCapturedStderr();
EXPECT_FALSE(hasSubstr(capturedStderr, expectedMissingProductFamilyStderrSubstr));
EXPECT_FALSE(hasSubstr(capturedStderr, expectedMissingHardwareInfoStderrSubstr));
}
{
debugManager.flags.SetCommandStreamReceiver.set(static_cast<int32_t>(CommandStreamReceiverType::hardware));
capture.captureStderr();
EXPECT_TRUE(DeviceFactory::validateDeviceFlags(productHelper));
auto capturedStderr = capture.getCapturedStderr();
EXPECT_FALSE(hasSubstr(capturedStderr, expectedMissingProductFamilyStderrSubstr));
EXPECT_FALSE(hasSubstr(capturedStderr, expectedMissingHardwareInfoStderrSubstr));
}
}
|