Debian Codegraph @

level_zero/tools/test/unit_tests/sources/debug/debug_session_registers_access.cpp

raw
1 /*
2 * Copyright (C) 2023-2026 Intel Corporation
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 */
7
8 #include "level_zero/tools/test/unit_tests/sources/debug/debug_session_registers_access.h"
9
10 #include "shared/test/common/mocks/mock_device.h"
11 #include "shared/test/common/mocks/mock_product_helper.h"
12
13 #include "level_zero/core/test/unit_tests/mocks/mock_device.h"
14 #include "level_zero/tools/test/unit_tests/sources/debug/mock_debug_session.h"
15 namespace L0 {
16 namespace ult {
17 DebugSessionRegistersAccess::DebugSessionRegistersAccess() = default;
18 DebugSessionRegistersAccess::~DebugSessionRegistersAccess() = default;
19
20 void DebugSessionRegistersAccessV3::setUp() {
21 zet_debug_config_t config = {};
22 config.pid = 0x1234;
23 auto hwInfo = *NEO::defaultHwInfo.get();
24
25 neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0);
26 mockDevice = std::make_unique<MockDeviceImp>(neoDevice);
27
28 session = std::make_unique<MockDebugSession>(config, mockDevice.get(), true, 3);
29
30 session->allThreads[stoppedThreadId]->stopThread(1u);
31 session->allThreads[stoppedThreadId]->reportAsStopped();
32 }
33
34 void setIsScratchInGrf(NEO::MockDevice *neoDevice, bool value) {
35 auto mockProductHelper = std::make_unique<NEO::MockProductHelper>();
36 mockProductHelper->isScratchSpaceBasePointerInGrfResult = value;
37 neoDevice->getRootDeviceEnvironmentRef().productHelper = std::move(mockProductHelper);
38 }
39
40 void DebugSessionRegistersAccessScratchV3::setUp() {
41 DebugSessionRegistersAccessV3::setUp();
42 setIsScratchInGrf(neoDevice, true);
43 }
44
45 void DebugSessionRegistersAccess::setUp() {
46 zet_debug_config_t config = {};
47 config.pid = 0x1234;
48 auto hwInfo = *NEO::defaultHwInfo.get();
49
50 neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0);
51 mockDevice = std::make_unique<MockDeviceImp>(neoDevice);
52
53 session = std::make_unique<MockDebugSession>(config, mockDevice.get());
54
55 session->allThreads[stoppedThreadId]->stopThread(1u);
56 session->allThreads[stoppedThreadId]->reportAsStopped();
57 }
58
59 void DebugSessionRegistersAccessScratch::setUp() {
60 DebugSessionRegistersAccess::setUp();
61 setIsScratchInGrf(neoDevice, true);
62 }
63
64 void DebugSessionRegistersAccess::tearDown() {
65 }
66
67 void DebugSessionRegistersAccess::dumpRegisterState() {
68 if (session->stateSaveAreaHeader.size() == 0) {
69 return;
70 }
71 auto pStateSaveAreaHeader = reinterpret_cast<NEO::StateSaveAreaHeader *>(session->stateSaveAreaHeader.data());
72
73 if (pStateSaveAreaHeader->versionHeader.version.major >= 3) {
74 for (uint32_t thread = 0; thread < pStateSaveAreaHeader->regHeaderV3.num_threads_per_eu; thread++) {
75 EuThread::ThreadId threadId(0, 0, 0, 0, thread);
76 auto threadSlotOffset = session->calculateThreadSlotOffset(threadId);
77
78 auto srMagicOffset = threadSlotOffset + pStateSaveAreaHeader->regHeaderV3.sr_magic_offset;
79 SIP::sr_ident srMagic;
80 srMagic.count = 1;
81 srMagic.version.major = pStateSaveAreaHeader->versionHeader.version.major;
82
83 session->writeGpuMemory(0, reinterpret_cast<char *>(&srMagic), sizeof(srMagic), reinterpret_cast<uint64_t>(pStateSaveAreaHeader) + srMagicOffset);
84 }
85 } else {
86 for (uint32_t thread = 0; thread < pStateSaveAreaHeader->regHeader.num_threads_per_eu; thread++) {
87 EuThread::ThreadId threadId(0, 0, 0, 0, thread);
88 auto threadSlotOffset = session->calculateThreadSlotOffset(threadId);
89
90 auto srMagicOffset = threadSlotOffset + pStateSaveAreaHeader->regHeader.sr_magic_offset;
91 SIP::sr_ident srMagic;
92 srMagic.count = 1;
93 srMagic.version.major = pStateSaveAreaHeader->versionHeader.version.major;
94
95 session->writeGpuMemory(0, reinterpret_cast<char *>(&srMagic), sizeof(srMagic), reinterpret_cast<uint64_t>(pStateSaveAreaHeader) + srMagicOffset);
96 }
97 }
98 }
99
100 } // namespace ult
101 } // namespace L0