| 1 |
/* |
| 2 |
* Copyright (C) 2021-2026 Intel Corporation |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "shared/test/common/helpers/debug_manager_state_restore.h" |
| 9 |
#include "shared/test/common/helpers/stream_capture.h" |
| 10 |
#include "shared/test/common/helpers/variable_backup.h" |
| 11 |
#include "shared/test/common/mocks/mock_device.h" |
| 12 |
#include "shared/test/common/mocks/mock_io_functions.h" |
| 13 |
#include "shared/test/common/mocks/mock_sip.h" |
| 14 |
#include "shared/test/common/mocks/ult_device_factory.h" |
| 15 |
#include "shared/test/common/test_macros/hw_test.h" |
| 16 |
|
| 17 |
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h" |
| 18 |
#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h" |
| 19 |
#include "level_zero/core/test/unit_tests/mocks/mock_device.h" |
| 20 |
#include "level_zero/tools/source/debug/debug_handlers.h" |
| 21 |
#include "level_zero/tools/test/unit_tests/sources/debug/debug_session_common.h" |
| 22 |
#include "level_zero/tools/test/unit_tests/sources/debug/mock_debug_session.h" |
| 23 |
#include "level_zero/zet_intel_gpu_debug.h" |
| 24 |
|
| 25 |
namespace L0 { |
| 26 |
namespace ult { |
| 27 |
|
| 28 |
using DebugApiTest = Test<DebugApiFixture>; |
| 29 |
using MultiTileDebugApiTest = Test<MultipleDevicesWithCustomHwInfo>; |
| 30 |
|
| 31 |
TEST_F(DebugApiTest, givenDeviceWhenGettingDebugPropertiesThenNoFlagIsSet) { |
| 32 |
zet_device_debug_properties_t debugProperties = {}; |
| 33 |
debugProperties.flags = ZET_DEVICE_DEBUG_PROPERTY_FLAG_FORCE_UINT32; |
| 34 |
|
| 35 |
auto result = zetDeviceGetDebugProperties(device->toHandle(), &debugProperties); |
| 36 |
|
| 37 |
EXPECT_EQ(ZE_RESULT_SUCCESS, result); |
| 38 |
EXPECT_EQ(0u, debugProperties.flags); |
| 39 |
} |
| 40 |
|
| 41 |
TEST_F(DebugApiTest, givenDeviceWhenCallingDebugAttachThenErrorIsReturned) { |
| 42 |
zet_debug_config_t config = {}; |
| 43 |
config.pid = 0x1234; |
| 44 |
zet_debug_session_handle_t debugSession = nullptr; |
| 45 |
|
| 46 |
auto result = zetDebugAttach(device->toHandle(), &config, &debugSession); |
| 47 |
|
| 48 |
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, result); |
| 49 |
EXPECT_EQ(nullptr, debugSession); |
| 50 |
} |
| 51 |
|
| 52 |
TEST_F(DebugApiTest, givenDebugAttachSupportedInOsWhenCallingDebugAttachThenSuccessIsReturned) { |
| 53 |
zet_debug_config_t config = {}; |
| 54 |
config.pid = 0x1234; |
| 55 |
|
| 56 |
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(new OsInterfaceWithDebugAttach); |
| 57 |
|
| 58 |
L0::Device *l0Device = static_cast<Device *>(device); |
| 59 |
auto sessionMock = new MockDebugSession(config, device, true); |
| 60 |
sessionMock->initialize(); |
| 61 |
l0Device->setDebugSession(sessionMock); |
| 62 |
|
| 63 |
zet_debug_session_handle_t debugSession = nullptr; |
| 64 |
auto result = zetDebugAttach(device->toHandle(), &config, &debugSession); |
| 65 |
|
| 66 |
EXPECT_EQ(ZE_RESULT_SUCCESS, result); |
| 67 |
EXPECT_NE(nullptr, debugSession); |
| 68 |
|
| 69 |
zet_debug_session_handle_t debugSession2 = nullptr; |
| 70 |
result = zetDebugAttach(device->toHandle(), &config, &debugSession2); |
| 71 |
|
| 72 |
EXPECT_EQ(ZE_RESULT_SUCCESS, result); |
| 73 |
EXPECT_EQ(debugSession, debugSession2); |
| 74 |
} |
| 75 |
|
| 76 |
TEST_F(DebugApiTest, givenDebugSessionWithPidWhenCallingDebugAttachForOtherPidThenErrorUnsupportedIsReturned) { |
| 77 |
zet_debug_config_t config = {}; |
| 78 |
config.pid = 0x1234; |
| 79 |
|
| 80 |
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(new OsInterfaceWithDebugAttach); |
| 81 |
|
| 82 |
L0::Device *l0Device = static_cast<Device *>(device); |
| 83 |
auto sessionMock = new MockDebugSession(config, device, true); |
| 84 |
sessionMock->initialize(); |
| 85 |
l0Device->setDebugSession(sessionMock); |
| 86 |
|
| 87 |
zet_debug_session_handle_t debugSession = nullptr; |
| 88 |
auto result = zetDebugAttach(device->toHandle(), &config, &debugSession); |
| 89 |
|
| 90 |
EXPECT_EQ(ZE_RESULT_SUCCESS, result); |
| 91 |
EXPECT_NE(nullptr, debugSession); |
| 92 |
|
| 93 |
zet_debug_session_handle_t debugSession2 = nullptr; |
| 94 |
config.pid = 0x1111; |
| 95 |
result = zetDebugAttach(device->toHandle(), &config, &debugSession2); |
| 96 |
|
| 97 |
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, result); |
| 98 |
EXPECT_EQ(nullptr, debugSession2); |
| 99 |
} |
| 100 |
|
| 101 |
TEST_F(MultiTileDebugApiTest, givenDebugSessionWithPidWhenCallingDebugAttachForOtherPidThenErrorUnsupportedIsReturned) { |
| 102 |
zet_debug_config_t config = {}; |
| 103 |
config.pid = 0x1234; |
| 104 |
|
| 105 |
L0::Device *device = driverHandle->devices[0]; |
| 106 |
L0::Device *l0Device = static_cast<Device *>(device); |
| 107 |
auto neoDevice = device->getNEODevice(); |
| 108 |
auto osInterface = new OsInterfaceWithDebugAttach; |
| 109 |
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.reset(osInterface); |
| 110 |
auto subDevice0 = neoDevice->getSubDevice(0)->getSpecializedDevice<Device>(); |
| 111 |
auto subDevice1 = neoDevice->getSubDevice(1)->getSpecializedDevice<Device>(); |
| 112 |
|
| 113 |
auto sessionMock = new MockDebugSession(config, device, false); |
| 114 |
sessionMock->initialize(); |
| 115 |
l0Device->setDebugSession(sessionMock); |
| 116 |
|
| 117 |
zet_debug_session_handle_t debugSession = nullptr; |
| 118 |
auto result = zetDebugAttach(subDevice0->toHandle(), &config, &debugSession); |
| 119 |
|
| 120 |
EXPECT_EQ(ZE_RESULT_SUCCESS, result); |
| 121 |
EXPECT_NE(nullptr, debugSession); |
| 122 |
|
| 123 |
zet_debug_session_handle_t debugSession2 = nullptr; |
| 124 |
config.pid = 0x1111; |
| 125 |
result = zetDebugAttach(subDevice1->toHandle(), &config, &debugSession2); |
| 126 |
|
| 127 |
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, result); |
| 128 |
EXPECT_EQ(nullptr, debugSession2); |
| 129 |
} |
| 130 |
|
| 131 |
TEST_F(DebugApiTest, givenSubDeviceWhenCallingDebugAttachThenErrorIsReturned) { |
| 132 |
zet_debug_config_t config = {}; |
| 133 |
config.pid = 0x1234; |
| 134 |
zet_debug_session_handle_t debugSession = nullptr; |
| 135 |
|
| 136 |
MockDeviceImp mockDevice(neoDevice); |
| 137 |
mockDevice.isSubdevice = true; |
| 138 |
|
| 139 |
auto result = zetDebugAttach(mockDevice.toHandle(), &config, &debugSession); |
| 140 |
|
| 141 |
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, result); |
| 142 |
EXPECT_EQ(nullptr, debugSession); |
| 143 |
} |
| 144 |
|
| 145 |
using isDebugSupportedProduct = IsWithinProducts<IGFX_DG1, IGFX_PTL>; |
| 146 |
HWTEST2_F(DebugApiTest, givenDeviceWhenDebugAttachIsAvaialbleThenGetPropertiesReturnsCorrectFlag, isDebugSupportedProduct) { |
| 147 |
zet_device_debug_properties_t debugProperties = {}; |
| 148 |
debugProperties.flags = ZET_DEVICE_DEBUG_PROPERTY_FLAG_FORCE_UINT32; |
| 149 |
|
| 150 |
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(new OsInterfaceWithDebugAttach); |
| 151 |
|
| 152 |
auto result = zetDeviceGetDebugProperties(device->toHandle(), &debugProperties); |
| 153 |
|
| 154 |
EXPECT_EQ(ZE_RESULT_SUCCESS, result); |
| 155 |
EXPECT_EQ(ZET_DEVICE_DEBUG_PROPERTY_FLAG_ATTACH, debugProperties.flags); |
| 156 |
} |
| 157 |
|
| 158 |
using isDebugNotSupportedProduct = IsAtMostProduct<IGFX_ALDERLAKE_N>; |
| 159 |
HWTEST2_F(DebugApiTest, givenDeviceWhenDebugIsNotSupportedThenGetPropertiesReturnsCorrectFlag, isDebugNotSupportedProduct) { |
| 160 |
zet_device_debug_properties_t debugProperties = {}; |
| 161 |
debugProperties.flags = ZET_DEVICE_DEBUG_PROPERTY_FLAG_FORCE_UINT32; |
| 162 |
|
| 163 |
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(new OsInterfaceWithDebugAttach); |
| 164 |
|
| 165 |
auto result = zetDeviceGetDebugProperties(device->toHandle(), &debugProperties); |
| 166 |
|
| 167 |
EXPECT_EQ(ZE_RESULT_SUCCESS, result); |
| 168 |
EXPECT_EQ(0u, debugProperties.flags); |
| 169 |
} |
| 170 |
|
| 171 |
TEST_F(DebugApiTest, givenStateSaveAreaHeaderUnavailableWhenGettingDebugPropertiesThenAttachFlagIsNotReturned) { |
| 172 |
zet_device_debug_properties_t debugProperties = {}; |
| 173 |
debugProperties.flags = ZET_DEVICE_DEBUG_PROPERTY_FLAG_FORCE_UINT32; |
| 174 |
|
| 175 |
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(new OsInterfaceWithDebugAttach); |
| 176 |
mockBuiltins->stateSaveAreaHeader.clear(); |
| 177 |
|
| 178 |
auto result = zetDeviceGetDebugProperties(device->toHandle(), &debugProperties); |
| 179 |
|
| 180 |
EXPECT_EQ(ZE_RESULT_SUCCESS, result); |
| 181 |
EXPECT_EQ(0u, debugProperties.flags); |
| 182 |
} |
| 183 |
|
| 184 |
TEST_F(DebugApiTest, givenTileAttachedDisabledAndSubDeviceWhenDebugAttachIsAvaialbleThenGetPropertiesReturnsNoFlag) { |
| 185 |
DebugManagerStateRestore restorer; |
| 186 |
NEO::debugManager.flags.ExperimentalEnableTileAttach.set(0); |
| 187 |
|
| 188 |
zet_device_debug_properties_t debugProperties = {}; |
| 189 |
debugProperties.flags = ZET_DEVICE_DEBUG_PROPERTY_FLAG_FORCE_UINT32; |
| 190 |
|
| 191 |
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(new OsInterfaceWithDebugAttach); |
| 192 |
|
| 193 |
MockDeviceImp mockDevice(neoDevice); |
| 194 |
mockDevice.isSubdevice = true; |
| 195 |
|
| 196 |
auto result = zetDeviceGetDebugProperties(mockDevice.toHandle(), &debugProperties); |
| 197 |
|
| 198 |
EXPECT_EQ(ZE_RESULT_SUCCESS, result); |
| 199 |
EXPECT_EQ(0u, debugProperties.flags); |
| 200 |
} |
| 201 |
|
| 202 |
TEST_F(DebugApiTest, givenDeviceWithDebugSessionWhenDebugAttachIsCalledThenSessionHandleIsReturned) { |
| 203 |
zet_debug_config_t config = {}; |
| 204 |
config.pid = 0x1234; |
| 205 |
|
| 206 |
MockDeviceImp mockDevice(neoDevice); |
| 207 |
mockDevice.debugSession.reset(new DebugSessionMock(config, &mockDevice)); |
| 208 |
|
| 209 |
zet_debug_session_handle_t debugSession = nullptr; |
| 210 |
auto result = zetDebugAttach(mockDevice.toHandle(), &config, &debugSession); |
| 211 |
|
| 212 |
EXPECT_EQ(ZE_RESULT_SUCCESS, result); |
| 213 |
EXPECT_EQ(mockDevice.debugSession->toHandle(), debugSession); |
| 214 |
} |
| 215 |
|
| 216 |
TEST_F(DebugApiTest, givenDeviceWithDebugSessionWhenDebugDetachIsCalledThenSuccessIsReturnedAndSessionDeleted) { |
| 217 |
zet_debug_config_t config = {}; |
| 218 |
config.pid = 0x1234; |
| 219 |
|
| 220 |
MockDeviceImp mockDevice(neoDevice); |
| 221 |
mockDevice.debugSession.reset(new DebugSessionMock(config, &mockDevice)); |
| 222 |
|
| 223 |
zet_debug_session_handle_t debugSession = mockDevice.debugSession->toHandle(); |
| 224 |
auto result = zetDebugDetach(debugSession); |
| 225 |
|
| 226 |
EXPECT_EQ(ZE_RESULT_SUCCESS, result); |
| 227 |
EXPECT_EQ(nullptr, mockDevice.debugSession); |
| 228 |
} |
| 229 |
|
| 230 |
TEST_F(DebugApiTest, givenDeviceWithoutSessionWhenDebugDetachIsCalledThenSuccessIsReturned) { |
| 231 |
MockDeviceImp mockDevice(neoDevice); |
| 232 |
|
| 233 |
zet_debug_session_handle_t debugSession = 0; |
| 234 |
auto result = zetDebugDetach(debugSession); |
| 235 |
|
| 236 |
EXPECT_EQ(ZE_RESULT_SUCCESS, result); |
| 237 |
EXPECT_EQ(nullptr, mockDevice.debugSession); |
| 238 |
} |
| 239 |
|
| 240 |
TEST_F(DebugApiTest, WhenUnsupportedFunctionCalledThenErrorIsReturned) { |
| 241 |
zet_debug_config_t config = {}; |
| 242 |
config.pid = 0x1234; |
| 243 |
|
| 244 |
MockDeviceImp mockDevice(neoDevice); |
| 245 |
mockDevice.debugSession.reset(new DebugSessionMock(config, &mockDevice)); |
| 246 |
|
| 247 |
zet_debug_session_handle_t session = mockDevice.debugSession->toHandle(); |
| 248 |
|
| 249 |
auto result = L0::DebugApiHandlers::debugReadEvent(session, 0, nullptr); |
| 250 |
EXPECT_EQ(result, ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); |
| 251 |
|
| 252 |
ze_device_thread_t thread = {}; |
| 253 |
result = L0::DebugApiHandlers::debugInterrupt(session, thread); |
| 254 |
EXPECT_EQ(result, ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); |
| 255 |
|
| 256 |
result = L0::DebugApiHandlers::debugResume(session, thread); |
| 257 |
EXPECT_EQ(result, ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); |
| 258 |
|
| 259 |
result = L0::DebugApiHandlers::debugReadMemory(session, thread, nullptr, 0, nullptr); |
| 260 |
EXPECT_EQ(result, ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); |
| 261 |
|
| 262 |
result = L0::DebugApiHandlers::debugWriteMemory(session, thread, nullptr, 0, nullptr); |
| 263 |
EXPECT_EQ(result, ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); |
| 264 |
|
| 265 |
result = L0::DebugApiHandlers::debugAcknowledgeEvent(session, nullptr); |
| 266 |
EXPECT_EQ(result, ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); |
| 267 |
|
| 268 |
uint32_t type = {0}; |
| 269 |
result = L0::DebugApiHandlers::debugReadRegisters(session, thread, type, 0, 0, nullptr); |
| 270 |
EXPECT_EQ(result, ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); |
| 271 |
|
| 272 |
result = L0::DebugApiHandlers::debugWriteRegisters(session, thread, type, 0, 0, nullptr); |
| 273 |
EXPECT_EQ(result, ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); |
| 274 |
} |
| 275 |
|
| 276 |
TEST_F(DebugApiTest, givenNullCountPointerWhenGetRegisterSetPropertiesCalledThenInvalidNullPointerIsReturned) { |
| 277 |
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_POINTER, zetDebugGetRegisterSetProperties(device->toHandle(), nullptr, nullptr)); |
| 278 |
} |
| 279 |
|
| 280 |
TEST_F(DebugApiTest, givenZeroCountWhenGetRegisterSetPropertiesCalledThenCorrectCountIsSet) { |
| 281 |
uint32_t count = 0; |
| 282 |
EXPECT_EQ(ZE_RESULT_SUCCESS, zetDebugGetRegisterSetProperties(device->toHandle(), &count, nullptr)); |
| 283 |
EXPECT_EQ(13u, count); |
| 284 |
} |
| 285 |
|
| 286 |
TEST_F(DebugApiTest, givenZeroCountWhenGetRegisterSetPropertiesCalledWithV3HeaderThenCorrectCountIsSet) { |
| 287 |
uint32_t count = 0; |
| 288 |
setUpV3Header(); |
| 289 |
EXPECT_EQ(ZE_RESULT_SUCCESS, zetDebugGetRegisterSetProperties(device->toHandle(), &count, nullptr)); |
| 290 |
EXPECT_EQ(17u, count); |
| 291 |
} |
| 292 |
|
| 293 |
TEST_F(DebugApiTest, givenGetRegisterSetPropertiesCalledAndExtraSpaceIsProvidedThenCorrectPropertiesReturned) { |
| 294 |
uint32_t count = 100; |
| 295 |
std::vector<zet_debug_regset_properties_t> regsetProps(count); |
| 296 |
EXPECT_EQ(ZE_RESULT_SUCCESS, zetDebugGetRegisterSetProperties(device->toHandle(), &count, regsetProps.data())); |
| 297 |
EXPECT_EQ(13u, count); |
| 298 |
} |
| 299 |
|
| 300 |
TEST_F(DebugApiTest, givenNoStateSaveHeaderWhenGettingRegSetPropertiesThenZeroCountIsReturned) { |
| 301 |
uint32_t count = 10; |
| 302 |
std::vector<zet_debug_regset_properties_t> regsetProps(count); |
| 303 |
|
| 304 |
mockBuiltins->stateSaveAreaHeader.clear(); |
| 305 |
|
| 306 |
EXPECT_EQ(ZE_RESULT_SUCCESS, zetDebugGetRegisterSetProperties(device->toHandle(), &count, regsetProps.data())); |
| 307 |
EXPECT_EQ(0u, count); |
| 308 |
} |
| 309 |
|
| 310 |
TEST_F(DebugApiTest, givenNonZeroCountAndNullRegsetPointerWhenGetRegisterSetPropertiesCalledTheniInvalidNullPointerIsReturned) { |
| 311 |
uint32_t count = 12; |
| 312 |
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_POINTER, zetDebugGetRegisterSetProperties(device->toHandle(), &count, nullptr)); |
| 313 |
} |
| 314 |
|
| 315 |
TEST_F(DebugApiTest, givenSsaHeaderVersionGreaterThan3WhenGetRegisterSetPropertiesCalledThenUnknownIsReturned) { |
| 316 |
auto stateSaveAreaHeader = MockSipData::createStateSaveAreaHeader(3); |
| 317 |
auto versionHeader = &reinterpret_cast<SIP::StateSaveAreaHeader *>(stateSaveAreaHeader.data())->versionHeader; |
| 318 |
versionHeader->version.major = 99; |
| 319 |
mockBuiltins->stateSaveAreaHeader = stateSaveAreaHeader; |
| 320 |
uint32_t count = 0; |
| 321 |
EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, zetDebugGetRegisterSetProperties(device->toHandle(), &count, nullptr)); |
| 322 |
} |
| 323 |
|
| 324 |
TEST_F(DebugApiTest, givenSIPHeaderHasZeroSizeMMEThenNotExposedAsRegset) { |
| 325 |
mockBuiltins = new MockBuiltins(); |
| 326 |
mockBuiltins->stateSaveAreaHeader = MockSipData::createStateSaveAreaHeader(2, 128, 0); |
| 327 |
MockRootDeviceEnvironment::resetBuiltins(neoDevice->executionEnvironment->rootDeviceEnvironments[0].get(), mockBuiltins); |
| 328 |
uint32_t count = 0; |
| 329 |
EXPECT_EQ(ZE_RESULT_SUCCESS, zetDebugGetRegisterSetProperties(device->toHandle(), &count, nullptr)); |
| 330 |
EXPECT_EQ(12u, count); |
| 331 |
|
| 332 |
std::vector<zet_debug_regset_properties_t> regsetProps(count); |
| 333 |
EXPECT_EQ(ZE_RESULT_SUCCESS, zetDebugGetRegisterSetProperties(device->toHandle(), &count, regsetProps.data())); |
| 334 |
EXPECT_EQ(12u, count); |
| 335 |
for (auto prop : regsetProps) { |
| 336 |
EXPECT_NE(prop.type, ZET_DEBUG_REGSET_TYPE_MME_INTEL_GPU); |
| 337 |
} |
| 338 |
} |
| 339 |
|
| 340 |
TEST_F(DebugApiTest, givenSIPHeaderGRFCountNotEqualTo128ThenGetRegisterSetPropertiesReturns128) { |
| 341 |
static_cast<MockBuiltins *>(neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.get())->stateSaveAreaHeader = |
| 342 |
MockSipData::createStateSaveAreaHeader(2, 256); |
| 343 |
uint32_t count = 0; |
| 344 |
EXPECT_EQ(ZE_RESULT_SUCCESS, zetDebugGetRegisterSetProperties(device->toHandle(), &count, nullptr)); |
| 345 |
|
| 346 |
std::vector<zet_debug_regset_properties_t> regsetProps(count); |
| 347 |
EXPECT_EQ(ZE_RESULT_SUCCESS, zetDebugGetRegisterSetProperties(device->toHandle(), &count, regsetProps.data())); |
| 348 |
ASSERT_EQ(13u, count); |
| 349 |
|
| 350 |
for (uint32_t i = 0; i < count; i++) { |
| 351 |
if (regsetProps[i].type == ZET_DEBUG_REGSET_TYPE_GRF_INTEL_GPU) { |
| 352 |
EXPECT_EQ(128u, regsetProps[i].count); |
| 353 |
break; |
| 354 |
} |
| 355 |
} |
| 356 |
} |
| 357 |
|
| 358 |
TEST_F(DebugApiTest, givenGetRegisterSetPropertiesCalledWithV3HeaderCorrectPropertiesReturned) { |
| 359 |
|
| 360 |
setUpV3Header(); |
| 361 |
uint32_t count = 0; |
| 362 |
EXPECT_EQ(ZE_RESULT_SUCCESS, zetDebugGetRegisterSetProperties(device->toHandle(), &count, nullptr)); |
| 363 |
EXPECT_EQ(17u, count); |
| 364 |
|
| 365 |
std::vector<zet_debug_regset_properties_t> regsetProps(count); |
| 366 |
EXPECT_EQ(ZE_RESULT_SUCCESS, zetDebugGetRegisterSetProperties(device->toHandle(), &count, regsetProps.data())); |
| 367 |
|
| 368 |
EXPECT_EQ(17u, count); |
| 369 |
|
| 370 |
auto validateRegsetProps = [](const zet_debug_regset_properties_t ®setProps, |
| 371 |
zet_debug_regset_type_intel_gpu_t type, zet_debug_regset_flags_t flags, |
| 372 |
uint32_t num, uint32_t bits, uint32_t bytes) { |
| 373 |
EXPECT_EQ(regsetProps.stype, ZET_STRUCTURE_TYPE_DEBUG_REGSET_PROPERTIES); |
| 374 |
EXPECT_EQ(regsetProps.pNext, nullptr); |
| 375 |
EXPECT_EQ(regsetProps.type, type); |
| 376 |
EXPECT_EQ(regsetProps.version, 0u); |
| 377 |
EXPECT_EQ(regsetProps.generalFlags, flags); |
| 378 |
EXPECT_EQ(regsetProps.count, num); |
| 379 |
EXPECT_EQ(regsetProps.bitSize, bits); |
| 380 |
EXPECT_EQ(regsetProps.byteSize, bytes); |
| 381 |
}; |
| 382 |
|
| 383 |
validateRegsetProps(regsetProps[0], ZET_DEBUG_REGSET_TYPE_GRF_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 128, 512, 64); |
| 384 |
validateRegsetProps(regsetProps[1], ZET_DEBUG_REGSET_TYPE_ADDR_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 1, 256, 32); |
| 385 |
validateRegsetProps(regsetProps[2], ZET_DEBUG_REGSET_TYPE_FLAG_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 2, 32, 4); |
| 386 |
validateRegsetProps(regsetProps[3], ZET_DEBUG_REGSET_TYPE_CE_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE, 1, 32, 4); |
| 387 |
validateRegsetProps(regsetProps[4], ZET_DEBUG_REGSET_TYPE_SR_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 2, 160, 20); |
| 388 |
validateRegsetProps(regsetProps[5], ZET_DEBUG_REGSET_TYPE_CR_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 1, 128, 16); |
| 389 |
validateRegsetProps(regsetProps[6], ZET_DEBUG_REGSET_TYPE_TDR_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE, 1, 128, 16); |
| 390 |
validateRegsetProps(regsetProps[7], ZET_DEBUG_REGSET_TYPE_ACC_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 10, 256, 32); |
| 391 |
validateRegsetProps(regsetProps[8], ZET_DEBUG_REGSET_TYPE_MME_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 1, 256, 32); |
| 392 |
validateRegsetProps(regsetProps[9], ZET_DEBUG_REGSET_TYPE_SP_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 1, 128, 16); |
| 393 |
validateRegsetProps(regsetProps[10], ZET_DEBUG_REGSET_TYPE_DBG_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 1, 64, 8); |
| 394 |
validateRegsetProps(regsetProps[11], ZET_DEBUG_REGSET_TYPE_FC_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 1, 32, 4); |
| 395 |
validateRegsetProps(regsetProps[12], ZET_DEBUG_REGSET_TYPE_MSG_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 1, 64, 8); |
| 396 |
validateRegsetProps(regsetProps[13], ZET_DEBUG_REGSET_TYPE_MODE_FLAGS_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE, 1, 32, 4); |
| 397 |
validateRegsetProps(regsetProps[14], ZET_DEBUG_REGSET_TYPE_DEBUG_SCRATCH_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE, 2, 64, 8); |
| 398 |
validateRegsetProps(regsetProps[15], ZET_DEBUG_REGSET_TYPE_THREAD_SCRATCH_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE, 2, 64, 8); |
| 399 |
validateRegsetProps(regsetProps[16], ZET_DEBUG_REGSET_TYPE_SCALAR_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 1, 64, 8); |
| 400 |
} |
| 401 |
|
| 402 |
TEST_F(DebugApiTest, givenGetRegisterSetPropertiesCalledWhenV3HeaderHeaplessThenCorrectPropertiesReturned) { |
| 403 |
|
| 404 |
setUpV3HeaderWithoutHeapless(); |
| 405 |
uint32_t count = 0; |
| 406 |
EXPECT_EQ(ZE_RESULT_SUCCESS, zetDebugGetRegisterSetProperties(device->toHandle(), &count, nullptr)); |
| 407 |
EXPECT_EQ(17u, count); |
| 408 |
|
| 409 |
std::vector<zet_debug_regset_properties_t> regsetProps(count); |
| 410 |
EXPECT_EQ(ZE_RESULT_SUCCESS, zetDebugGetRegisterSetProperties(device->toHandle(), &count, regsetProps.data())); |
| 411 |
|
| 412 |
EXPECT_EQ(17u, count); |
| 413 |
|
| 414 |
auto validateRegsetProps = [](const zet_debug_regset_properties_t ®setProps, |
| 415 |
zet_debug_regset_type_intel_gpu_t type, zet_debug_regset_flags_t flags, |
| 416 |
uint32_t num, uint32_t bits, uint32_t bytes) { |
| 417 |
EXPECT_EQ(regsetProps.stype, ZET_STRUCTURE_TYPE_DEBUG_REGSET_PROPERTIES); |
| 418 |
EXPECT_EQ(regsetProps.pNext, nullptr); |
| 419 |
EXPECT_EQ(regsetProps.type, type); |
| 420 |
EXPECT_EQ(regsetProps.version, 0u); |
| 421 |
EXPECT_EQ(regsetProps.generalFlags, flags); |
| 422 |
EXPECT_EQ(regsetProps.count, num); |
| 423 |
EXPECT_EQ(regsetProps.bitSize, bits); |
| 424 |
EXPECT_EQ(regsetProps.byteSize, bytes); |
| 425 |
}; |
| 426 |
|
| 427 |
validateRegsetProps(regsetProps[0], ZET_DEBUG_REGSET_TYPE_GRF_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 128, 512, 64); |
| 428 |
validateRegsetProps(regsetProps[1], ZET_DEBUG_REGSET_TYPE_ADDR_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 1, 256, 32); |
| 429 |
validateRegsetProps(regsetProps[2], ZET_DEBUG_REGSET_TYPE_FLAG_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 2, 32, 4); |
| 430 |
validateRegsetProps(regsetProps[3], ZET_DEBUG_REGSET_TYPE_CE_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE, 1, 32, 4); |
| 431 |
validateRegsetProps(regsetProps[4], ZET_DEBUG_REGSET_TYPE_SR_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 2, 160, 20); |
| 432 |
validateRegsetProps(regsetProps[5], ZET_DEBUG_REGSET_TYPE_CR_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 1, 128, 16); |
| 433 |
validateRegsetProps(regsetProps[6], ZET_DEBUG_REGSET_TYPE_TDR_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE, 1, 128, 16); |
| 434 |
validateRegsetProps(regsetProps[7], ZET_DEBUG_REGSET_TYPE_ACC_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 10, 256, 32); |
| 435 |
validateRegsetProps(regsetProps[8], ZET_DEBUG_REGSET_TYPE_MME_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 1, 256, 32); |
| 436 |
validateRegsetProps(regsetProps[9], ZET_DEBUG_REGSET_TYPE_SP_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 1, 128, 16); |
| 437 |
validateRegsetProps(regsetProps[10], ZET_DEBUG_REGSET_TYPE_SBA_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE, ZET_DEBUG_SBA_COUNT_INTEL_GPU, 64, 8); |
| 438 |
validateRegsetProps(regsetProps[11], ZET_DEBUG_REGSET_TYPE_DBG_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 1, 64, 8); |
| 439 |
validateRegsetProps(regsetProps[12], ZET_DEBUG_REGSET_TYPE_FC_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 1, 32, 4); |
| 440 |
validateRegsetProps(regsetProps[13], ZET_DEBUG_REGSET_TYPE_MSG_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 1, 64, 8); |
| 441 |
validateRegsetProps(regsetProps[14], ZET_DEBUG_REGSET_TYPE_MODE_FLAGS_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE, 1, 32, 4); |
| 442 |
validateRegsetProps(regsetProps[15], ZET_DEBUG_REGSET_TYPE_DEBUG_SCRATCH_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE, 2, 64, 8); |
| 443 |
validateRegsetProps(regsetProps[16], ZET_DEBUG_REGSET_TYPE_SCALAR_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 1, 64, 8); |
| 444 |
} |
| 445 |
|
| 446 |
TEST_F(DebugApiTest, givenGetRegisterSetPropertiesCalledCorrectPropertiesReturned) { |
| 447 |
uint32_t count = 0; |
| 448 |
EXPECT_EQ(ZE_RESULT_SUCCESS, zetDebugGetRegisterSetProperties(device->toHandle(), &count, nullptr)); |
| 449 |
EXPECT_EQ(13u, count); |
| 450 |
|
| 451 |
std::vector<zet_debug_regset_properties_t> regsetProps(count); |
| 452 |
EXPECT_EQ(ZE_RESULT_SUCCESS, zetDebugGetRegisterSetProperties(device->toHandle(), &count, regsetProps.data())); |
| 453 |
|
| 454 |
EXPECT_EQ(13u, count); |
| 455 |
|
| 456 |
auto validateRegsetProps = [](const zet_debug_regset_properties_t ®setProps, |
| 457 |
zet_debug_regset_type_intel_gpu_t type, zet_debug_regset_flags_t flags, |
| 458 |
uint32_t num, uint32_t bits, uint32_t bytes) { |
| 459 |
EXPECT_EQ(regsetProps.stype, ZET_STRUCTURE_TYPE_DEBUG_REGSET_PROPERTIES); |
| 460 |
EXPECT_EQ(regsetProps.pNext, nullptr); |
| 461 |
EXPECT_EQ(regsetProps.type, type); |
| 462 |
EXPECT_EQ(regsetProps.version, 0u); |
| 463 |
EXPECT_EQ(regsetProps.generalFlags, flags); |
| 464 |
EXPECT_EQ(regsetProps.count, num); |
| 465 |
EXPECT_EQ(regsetProps.bitSize, bits); |
| 466 |
EXPECT_EQ(regsetProps.byteSize, bytes); |
| 467 |
}; |
| 468 |
|
| 469 |
validateRegsetProps(regsetProps[0], ZET_DEBUG_REGSET_TYPE_GRF_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 128, 256, 32); |
| 470 |
validateRegsetProps(regsetProps[1], ZET_DEBUG_REGSET_TYPE_ADDR_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 1, 256, 32); |
| 471 |
validateRegsetProps(regsetProps[2], ZET_DEBUG_REGSET_TYPE_FLAG_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 2, 32, 4); |
| 472 |
validateRegsetProps(regsetProps[3], ZET_DEBUG_REGSET_TYPE_CE_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE, 1, 32, 4); |
| 473 |
validateRegsetProps(regsetProps[4], ZET_DEBUG_REGSET_TYPE_SR_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 2, 128, 16); |
| 474 |
validateRegsetProps(regsetProps[5], ZET_DEBUG_REGSET_TYPE_CR_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 1, 128, 16); |
| 475 |
validateRegsetProps(regsetProps[6], ZET_DEBUG_REGSET_TYPE_TDR_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE, 1, 128, 16); |
| 476 |
validateRegsetProps(regsetProps[7], ZET_DEBUG_REGSET_TYPE_ACC_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 10, 256, 32); |
| 477 |
validateRegsetProps(regsetProps[8], ZET_DEBUG_REGSET_TYPE_MME_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 1, 256, 32); |
| 478 |
validateRegsetProps(regsetProps[9], ZET_DEBUG_REGSET_TYPE_SP_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 1, 128, 16); |
| 479 |
validateRegsetProps(regsetProps[10], ZET_DEBUG_REGSET_TYPE_SBA_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE, ZET_DEBUG_SBA_COUNT_INTEL_GPU, 64, 8); |
| 480 |
validateRegsetProps(regsetProps[11], ZET_DEBUG_REGSET_TYPE_DBG_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 1, 64, 8); |
| 481 |
validateRegsetProps(regsetProps[12], ZET_DEBUG_REGSET_TYPE_FC_INTEL_GPU, ZET_DEBUG_REGSET_FLAG_READABLE | ZET_DEBUG_REGSET_FLAG_WRITEABLE, 1, 32, 4); |
| 482 |
} |
| 483 |
|
| 484 |
TEST(DebugSessionTest, givenDebugSessionWhenConvertingToAndFromHandleCorrectHandleAndPointerIsReturned) { |
| 485 |
zet_debug_config_t config = {}; |
| 486 |
config.pid = 0x1234; |
| 487 |
|
| 488 |
NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get(), 0)); |
| 489 |
MockDeviceImp mockDevice(neoDevice); |
| 490 |
auto debugSession = std::make_unique<DebugSessionMock>(config, &mockDevice); |
| 491 |
L0::DebugSession *session = debugSession.get(); |
| 492 |
|
| 493 |
zet_debug_session_handle_t debugSessionHandle = debugSession->toHandle(); |
| 494 |
auto sessionFromHandle = L0::DebugSession::fromHandle(session); |
| 495 |
|
| 496 |
EXPECT_NE(nullptr, debugSessionHandle); |
| 497 |
EXPECT_EQ(session, sessionFromHandle); |
| 498 |
} |
| 499 |
|
| 500 |
TEST(DebugSessionTest, givenDebugSessionWhenGettingConnectedDeviceThenCorrectDeviceIsReturned) { |
| 501 |
zet_debug_config_t config = {}; |
| 502 |
config.pid = 0x1234; |
| 503 |
|
| 504 |
NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get(), 0)); |
| 505 |
MockDeviceImp mockDevice(neoDevice); |
| 506 |
auto debugSession = std::make_unique<DebugSessionMock>(config, &mockDevice); |
| 507 |
L0::DebugSession *session = debugSession.get(); |
| 508 |
|
| 509 |
auto device = session->getConnectedDevice(); |
| 510 |
|
| 511 |
EXPECT_EQ(&mockDevice, device); |
| 512 |
} |
| 513 |
|
| 514 |
TEST(DebugSessionTest, givenDeviceWithDebugSessionWhenRemoveCalledThenSessionIsNotDeleted) { |
| 515 |
zet_debug_config_t config = {}; |
| 516 |
config.pid = 0x1234; |
| 517 |
|
| 518 |
NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get(), 0)); |
| 519 |
MockDeviceImp mockDevice(neoDevice); |
| 520 |
auto debugSession = std::make_unique<DebugSessionMock>(config, &mockDevice); |
| 521 |
L0::DebugSession *session = debugSession.get(); |
| 522 |
mockDevice.debugSession.reset(session); |
| 523 |
mockDevice.removeDebugSession(); |
| 524 |
|
| 525 |
EXPECT_EQ(nullptr, mockDevice.debugSession.get()); |
| 526 |
} |
| 527 |
|
| 528 |
TEST(DebugSessionTest, givenTileAttachDisabledAndSubDeviceWhenCreatingSessionThenNullptrReturned) { |
| 529 |
DebugManagerStateRestore restorer; |
| 530 |
NEO::debugManager.flags.ExperimentalEnableTileAttach.set(0); |
| 531 |
|
| 532 |
zet_debug_config_t config = {}; |
| 533 |
config.pid = 0x1234; |
| 534 |
|
| 535 |
NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get(), 0)); |
| 536 |
MockDeviceImp mockDevice(neoDevice); |
| 537 |
mockDevice.isSubdevice = true; |
| 538 |
|
| 539 |
ze_result_t result = ZE_RESULT_ERROR_DEVICE_LOST; |
| 540 |
auto session = mockDevice.createDebugSession(config, result, false); |
| 541 |
|
| 542 |
EXPECT_EQ(nullptr, session); |
| 543 |
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, result); |
| 544 |
} |
| 545 |
|
| 546 |
TEST(DebugSessionTest, givenTileAttachDisabledAndSubDeviceWhenDebugAttachCalledThenErrorReturned) { |
| 547 |
DebugManagerStateRestore restorer; |
| 548 |
NEO::debugManager.flags.ExperimentalEnableTileAttach.set(0); |
| 549 |
|
| 550 |
zet_debug_config_t config = {}; |
| 551 |
config.pid = 0x1234; |
| 552 |
|
| 553 |
auto neoDevice = std::unique_ptr<NEO::MockDevice>(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get(), 0)); |
| 554 |
neoDevice->incRefInternal(); |
| 555 |
auto neoSubdevice = std::unique_ptr<NEO::SubDevice>(neoDevice->createSubDevice(0)); |
| 556 |
|
| 557 |
auto mockDevice = std::make_unique<MockDeviceImp>(neoSubdevice.get()); |
| 558 |
mockDevice->isSubdevice = true; |
| 559 |
|
| 560 |
ze_result_t result = ZE_RESULT_ERROR_DEVICE_LOST; |
| 561 |
zet_debug_session_handle_t debugSession = nullptr; |
| 562 |
result = zetDebugAttach(mockDevice->toHandle(), &config, &debugSession); |
| 563 |
|
| 564 |
EXPECT_EQ(nullptr, debugSession); |
| 565 |
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, result); |
| 566 |
} |
| 567 |
|
| 568 |
TEST(DebugSessionTest, givenRootDeviceWhenCreatingSessionThenResultReturnedIsCorrect) { |
| 569 |
zet_debug_config_t config = {}; |
| 570 |
config.pid = 0x1234; |
| 571 |
|
| 572 |
NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get(), 0)); |
| 573 |
|
| 574 |
auto osInterface = new OsInterfaceWithDebugAttach; |
| 575 |
osInterface->debugAttachAvailable = false; |
| 576 |
|
| 577 |
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.reset(osInterface); |
| 578 |
MockDeviceImp mockDevice(neoDevice); |
| 579 |
mockDevice.isSubdevice = false; |
| 580 |
|
| 581 |
ze_result_t result = ZE_RESULT_ERROR_DEVICE_LOST; |
| 582 |
auto session = mockDevice.createDebugSession(config, result, true); |
| 583 |
|
| 584 |
EXPECT_EQ(nullptr, session); |
| 585 |
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, result); |
| 586 |
} |
| 587 |
|
| 588 |
TEST_F(DebugApiTest, givenZeAffinityMaskAndEnabledDebugMessagesWhenDebugAttachCalledThenMessageIsPrinted) { |
| 589 |
DebugManagerStateRestore restorer; |
| 590 |
NEO::debugManager.flags.PrintDebugMessages.set(1); |
| 591 |
|
| 592 |
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0); |
| 593 |
std::unordered_map<std::string, std::string> mockableEnvs = {{"ZE_AFFINITY_MASK", "0.1"}}; |
| 594 |
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs); |
| 595 |
|
| 596 |
zet_debug_config_t config = {}; |
| 597 |
config.pid = 0x1234; |
| 598 |
|
| 599 |
MockDeviceImp mockDevice(neoDevice); |
| 600 |
mockDevice.debugSession.reset(new DebugSessionMock(config, &mockDevice)); |
| 601 |
|
| 602 |
StreamCapture capture; |
| 603 |
capture.captureStdout(); |
| 604 |
zet_debug_session_handle_t debugSession = nullptr; |
| 605 |
zetDebugAttach(mockDevice.toHandle(), &config, &debugSession); |
| 606 |
|
| 607 |
std::string output = capture.getCapturedStdout(); |
| 608 |
EXPECT_EQ(std::string("ZE_AFFINITY_MASK is not recommended while using program debug API\n"), output); |
| 609 |
} |
| 610 |
|
| 611 |
TEST_F(DebugApiTest, givenReadDebugScratchRegisterCalledThenSuccessIsReturned) { |
| 612 |
zet_debug_config_t config = {}; |
| 613 |
config.pid = 0x1234; |
| 614 |
|
| 615 |
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(new OsInterfaceWithDebugAttach); |
| 616 |
|
| 617 |
L0::Device *l0Device = static_cast<Device *>(device); |
| 618 |
auto session = new MockDebugSession(config, device, true); |
| 619 |
session->initialize(); |
| 620 |
l0Device->setDebugSession(session); |
| 621 |
SIP::version version = {3, 0, 0}; |
| 622 |
initStateSaveArea(session->stateSaveAreaHeader, version, device); |
| 623 |
ze_device_thread_t stoppedThread = {0, 0, 0, 0}; |
| 624 |
EuThread::ThreadId stoppedThreadId{0, stoppedThread}; |
| 625 |
session->allThreads[stoppedThreadId]->stopThread(1u); |
| 626 |
session->allThreads[stoppedThreadId]->reportAsStopped(); |
| 627 |
uint64_t scratch[2]; |
| 628 |
EXPECT_EQ(ZE_RESULT_SUCCESS, zetDebugReadRegisters(session->toHandle(), {0, 0, 0, 0}, ZET_DEBUG_REGSET_TYPE_DEBUG_SCRATCH_INTEL_GPU, 0, 2, scratch)); |
| 629 |
EXPECT_EQ(scratch[0], 0u); |
| 630 |
EXPECT_EQ(scratch[1], 0u); |
| 631 |
} |
| 632 |
|
| 633 |
TEST_F(DebugApiTest, givenReadModeRegisterCalledThenSuccessIsReturned) { |
| 634 |
zet_debug_config_t config = {}; |
| 635 |
config.pid = 0x1234; |
| 636 |
|
| 637 |
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(new OsInterfaceWithDebugAttach); |
| 638 |
|
| 639 |
L0::Device *l0Device = static_cast<Device *>(device); |
| 640 |
auto session = new MockDebugSession(config, device, true); |
| 641 |
session->initialize(); |
| 642 |
l0Device->setDebugSession(session); |
| 643 |
SIP::version version = {3, 0, 0}; |
| 644 |
initStateSaveArea(session->stateSaveAreaHeader, version, device); |
| 645 |
ze_device_thread_t stoppedThread = {0, 0, 0, 0}; |
| 646 |
EuThread::ThreadId stoppedThreadId{0, stoppedThread}; |
| 647 |
session->allThreads[stoppedThreadId]->stopThread(1u); |
| 648 |
session->allThreads[stoppedThreadId]->reportAsStopped(); |
| 649 |
uint32_t modeFlags; |
| 650 |
EXPECT_EQ(ZE_RESULT_SUCCESS, zetDebugReadRegisters(session->toHandle(), {0, 0, 0, 0}, ZET_DEBUG_REGSET_TYPE_MODE_FLAGS_INTEL_GPU, 0, 1, &modeFlags)); |
| 651 |
} |
| 652 |
|
| 653 |
} // namespace ult |
| 654 |
} // namespace L0 |