| 1 |
/* |
| 2 |
* Copyright (C) 2024-2026 Intel Corporation |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "shared/test/common/test_macros/test.h" |
| 9 |
|
| 10 |
#include "level_zero/tools/test/unit_tests/sources/debug/debug_session_common.h" |
| 11 |
#include "level_zero/tools/test/unit_tests/sources/debug/mock_debug_session.h" |
| 12 |
|
| 13 |
namespace L0 { |
| 14 |
namespace ult { |
| 15 |
|
| 16 |
using DebugApiLinuxSipTest = Test<DebugApiFixture>; |
| 17 |
|
| 18 |
struct MockDebugSessionSip : public MockDebugSession { |
| 19 |
|
| 20 |
MockDebugSessionSip(const zet_debug_config_t &config, L0::Device *device) |
| 21 |
: MockDebugSession(config, device) {} |
| 22 |
|
| 23 |
bool testOpenSipWrapper(uint64_t contextHandle, uint64_t gpuVa) { |
| 24 |
NEO::MockDevice *neoDevice = static_cast<NEO::MockDevice *>(connectedDevice->getNEODevice()); |
| 25 |
return openSipWrapper(neoDevice, contextHandle, gpuVa); |
| 26 |
} |
| 27 |
|
| 28 |
bool testCloseSipWrapper(uint64_t contextHandle) { |
| 29 |
NEO::MockDevice *neoDevice = static_cast<NEO::MockDevice *>(connectedDevice->getNEODevice()); |
| 30 |
return closeSipWrapper(neoDevice, contextHandle); |
| 31 |
} |
| 32 |
}; |
| 33 |
|
| 34 |
TEST_F(DebugApiLinuxSipTest, GivenValidDeviceWhenOpenSipWrapperIsCalledThenFunctionExecutesSuccessfully) { |
| 35 |
zet_debug_config_t config = {}; |
| 36 |
config.pid = 0x1234; |
| 37 |
auto session = std::make_unique<MockDebugSessionSip>(config, device); |
| 38 |
ASSERT_NE(nullptr, session); |
| 39 |
|
| 40 |
EXPECT_TRUE(session->testOpenSipWrapper(0x1111, 0x2222)); |
| 41 |
} |
| 42 |
|
| 43 |
TEST_F(DebugApiLinuxSipTest, GivenValidDeviceWhenCloseSipWrapperIsCalledThenFunctionExecutesSuccessfully) { |
| 44 |
zet_debug_config_t config = {}; |
| 45 |
config.pid = 0x1234; |
| 46 |
auto session = std::make_unique<MockDebugSessionSip>(config, device); |
| 47 |
ASSERT_NE(nullptr, session); |
| 48 |
|
| 49 |
EXPECT_TRUE(session->testCloseSipWrapper(0x3333)); |
| 50 |
} |
| 51 |
|
| 52 |
struct MockDebugSessionSipRegisterAccess : public MockDebugSession { |
| 53 |
MockDebugSessionSipRegisterAccess(const zet_debug_config_t &config, L0::Device *device) |
| 54 |
: MockDebugSession(config, device) {} |
| 55 |
|
| 56 |
bool callGetRegisterAccessProperties(EuThread::ThreadId *threadId, uint32_t *pCount, zet_debug_regset_properties_t *pRegisterSetProperties) { |
| 57 |
// Directly invoke the base implementation (stub) to exercise code path. |
| 58 |
return DebugSessionImp::getRegisterAccessProperties(threadId, pCount, pRegisterSetProperties); |
| 59 |
} |
| 60 |
}; |
| 61 |
|
| 62 |
TEST_F(DebugApiLinuxSipTest, GivenStubImplementationWhenGetRegisterAccessPropertiesIsCalledThenReturnsTrueAndLeavesDataUnchanged) { |
| 63 |
zet_debug_config_t config = {}; |
| 64 |
config.pid = 0x5678; |
| 65 |
auto session = std::make_unique<MockDebugSessionSipRegisterAccess>(config, device); |
| 66 |
ASSERT_NE(nullptr, session); |
| 67 |
|
| 68 |
// Prepare properties array with sentinel values to verify they are not modified by stub. |
| 69 |
zet_debug_regset_properties_t props[2] = {}; |
| 70 |
props[0].type = ZET_DEBUG_REGSET_TYPE_GRF_INTEL_GPU; |
| 71 |
props[0].count = 123u; // sentinel |
| 72 |
props[1].type = ZET_DEBUG_REGSET_TYPE_ACC_INTEL_GPU; |
| 73 |
props[1].count = 456u; // sentinel |
| 74 |
uint32_t count = 2u; // number of entries in props |
| 75 |
|
| 76 |
// Call with nullptr thread id (stub does not use it) to keep setup minimal. |
| 77 |
bool result = session->callGetRegisterAccessProperties(nullptr, &count, props); |
| 78 |
|
| 79 |
EXPECT_TRUE(result); |
| 80 |
// Verify sentinel values remain unchanged. |
| 81 |
EXPECT_EQ(123u, props[0].count); |
| 82 |
EXPECT_EQ(456u, props[1].count); |
| 83 |
// Count should also remain unchanged. |
| 84 |
EXPECT_EQ(2u, count); |
| 85 |
} |
| 86 |
|
| 87 |
struct MockDebugSessionGetThreadSipCounter : public MockDebugSession { |
| 88 |
MockDebugSessionGetThreadSipCounter(const zet_debug_config_t &config, L0::Device *device) |
| 89 |
: MockDebugSession(config, device) {} |
| 90 |
|
| 91 |
bool callGetThreadSipCounter(const void *stateSaveArea, L0::EuThread *thread, const NEO::StateSaveAreaHeader *stateSaveAreaHeader, uint64_t *sipThreadCounter) { |
| 92 |
// Directly invoke the base implementation to test the stub. |
| 93 |
return DebugSessionImp::getThreadSipCounter(stateSaveArea, thread, stateSaveAreaHeader, sipThreadCounter); |
| 94 |
} |
| 95 |
}; |
| 96 |
|
| 97 |
TEST_F(DebugApiLinuxSipTest, GivenGetThreadSipCounterImplementationWhenGetThreadSipCounterIsCalledThenReturnsFalse) { |
| 98 |
zet_debug_config_t config = {}; |
| 99 |
config.pid = 0x9999; |
| 100 |
auto session = std::make_unique<MockDebugSessionGetThreadSipCounter>(config, device); |
| 101 |
ASSERT_NE(nullptr, session); |
| 102 |
|
| 103 |
uint64_t sipThreadCounter = 0xDEADBEEF; // sentinel value |
| 104 |
bool result = session->callGetThreadSipCounter(nullptr, nullptr, nullptr, &sipThreadCounter); |
| 105 |
|
| 106 |
EXPECT_FALSE(result); |
| 107 |
// Verify that sipThreadCounter was not modified by the stub |
| 108 |
EXPECT_EQ(0xDEADBEEF, sipThreadCounter); |
| 109 |
} |
| 110 |
|
| 111 |
} // namespace ult |
| 112 |
} // namespace L0 |