feature: Support for External Sip Lib Open/Close

Related-To: NEO-13739

Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
This commit is contained in:
Neil R. Spruit
2025-09-10 21:07:41 +00:00
committed by Compute-Runtime-Automation
parent 4ae656e2ce
commit 150f5d2183
10 changed files with 218 additions and 3 deletions

View File

@@ -33,6 +33,100 @@ extern std::map<std::string, std::stringstream> virtualFileList;
namespace L0 {
namespace ult {
TEST(DebugSessionTest, GivenValidArgsWhenReadSipMemoryCalledThenReturnsSizeAndReadsMemory) {
zet_debug_config_t config = {};
config.pid = 0x1234;
auto hwInfo = *NEO::defaultHwInfo.get();
ze_result_t returnValue = ZE_RESULT_SUCCESS;
std::unique_ptr<DriverHandleImp> driverHandle(new DriverHandleImp);
auto neoDevice = std::unique_ptr<NEO::Device>(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), false, &returnValue));
ASSERT_NE(nullptr, device);
auto sessionMock = std::make_unique<MockDebugSession>(config, device.get());
DebugSessionImp::SipMemoryAccessArgs args = {};
args.debugSession = sessionMock.get();
args.contextHandle = 0x1234;
args.gpuVa = 0x1000;
constexpr uint32_t size = 16;
char destination[size] = {};
sessionMock->readGpuMemoryCallCount = 0;
uint32_t ret = DebugSessionImp::readSipMemory(&args, 0x10, size, destination);
EXPECT_EQ(size, ret);
EXPECT_EQ(1u, sessionMock->readGpuMemoryCallCount);
}
TEST(DebugSessionTest, GivenReadGpuMemoryFailsWhenReadSipMemoryCalledThenReturnsZero) {
zet_debug_config_t config = {};
config.pid = 0x1234;
auto hwInfo = *NEO::defaultHwInfo.get();
ze_result_t returnValue = ZE_RESULT_SUCCESS;
std::unique_ptr<DriverHandleImp> driverHandle(new DriverHandleImp);
auto neoDevice = std::unique_ptr<NEO::Device>(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), false, &returnValue));
ASSERT_NE(nullptr, device);
auto sessionMock = std::make_unique<MockDebugSession>(config, device.get());
DebugSessionImp::SipMemoryAccessArgs args = {};
args.debugSession = sessionMock.get();
args.contextHandle = 0x1234;
args.gpuVa = 0x1000;
sessionMock->forcereadGpuMemoryFailOnCount = 1;
char destination[8] = {};
uint32_t ret = DebugSessionImp::readSipMemory(&args, 0, 8, destination);
EXPECT_EQ(0u, ret);
}
TEST(DebugSessionTest, GivenValidArgsWhenWriteSipMemoryCalledThenReturnsSizeAndWritesMemory) {
zet_debug_config_t config = {};
config.pid = 0x1234;
auto hwInfo = *NEO::defaultHwInfo.get();
ze_result_t returnValue = ZE_RESULT_SUCCESS;
std::unique_ptr<DriverHandleImp> driverHandle(new DriverHandleImp);
auto neoDevice = std::unique_ptr<NEO::Device>(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), false, &returnValue));
ASSERT_NE(nullptr, device);
auto sessionMock = std::make_unique<MockDebugSession>(config, device.get());
DebugSessionImp::SipMemoryAccessArgs args = {};
args.debugSession = sessionMock.get();
args.contextHandle = 0x5678;
args.gpuVa = 0x2000;
constexpr uint32_t size = 32;
char source[size] = {1, 2, 3, 4};
sessionMock->writeGpuMemoryCallCount = 0;
uint32_t ret = DebugSessionImp::writeSipMemory(&args, 0x20, size, source);
EXPECT_EQ(size, ret);
EXPECT_EQ(1u, sessionMock->writeGpuMemoryCallCount);
}
TEST(DebugSessionTest, GivenWriteGpuMemoryFailsWhenWriteSipMemoryCalledThenReturnsZero) {
zet_debug_config_t config = {};
config.pid = 0x1234;
auto hwInfo = *NEO::defaultHwInfo.get();
ze_result_t returnValue = ZE_RESULT_SUCCESS;
std::unique_ptr<DriverHandleImp> driverHandle(new DriverHandleImp);
auto neoDevice = std::unique_ptr<NEO::Device>(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), false, &returnValue));
ASSERT_NE(nullptr, device);
auto sessionMock = std::make_unique<MockDebugSession>(config, device.get());
DebugSessionImp::SipMemoryAccessArgs args = {};
args.debugSession = sessionMock.get();
args.contextHandle = 0x5678;
args.gpuVa = 0x2000;
sessionMock->forceWriteGpuMemoryFailOnCount = 1;
char source[8] = {5, 6, 7, 8};
uint32_t ret = DebugSessionImp::writeSipMemory(&args, 0, 8, source);
EXPECT_EQ(0u, ret);
}
using DebugSessionTest = ::testing::Test;
TEST(DeviceWithDebugSessionTest, GivenSlicesEnabledWithEarlierSlicesDisabledThenAllThreadsIsPopulatedCorrectly) {

View File

@@ -1,5 +1,5 @@
#
# Copyright (C) 2022-2024 Intel Corporation
# Copyright (C) 2022-2025 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
@@ -11,6 +11,8 @@ if(UNIX)
${CMAKE_CURRENT_SOURCE_DIR}/test_debug_api_linux_xe.cpp
${CMAKE_CURRENT_SOURCE_DIR}/debug_session_fixtures_linux_xe.h
${CMAKE_CURRENT_SOURCE_DIR}/debug_session_fixtures_linux_xe.cpp
${CMAKE_CURRENT_SOURCE_DIR}/${BRANCH_DIR_SUFFIX}/test_debug_external_sip.cpp
)
endif()

View File

@@ -0,0 +1,52 @@
/*
* Copyright (C) 2024-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/test/common/test_macros/test.h"
#include "level_zero/tools/test/unit_tests/sources/debug/linux/xe/debug_session_fixtures_linux_xe.h"
namespace L0 {
namespace ult {
using DebugApiLinuxTestXe = Test<DebugApiLinuxXeFixture>;
struct MockDebugSessionLinuxXeMasterSip : public MockDebugSessionLinuxXe {
MockDebugSessionLinuxXeMasterSip(const zet_debug_config_t &config, L0::Device *device, int debugFd)
: MockDebugSessionLinuxXe(config, device, debugFd) {}
bool testOpenSipWrapper(uint64_t contextHandle, uint64_t gpuVa) {
NEO::MockDevice *neoDevice = static_cast<NEO::MockDevice *>(connectedDevice->getNEODevice());
return openSipWrapper(neoDevice, contextHandle, gpuVa);
}
bool testCloseSipWrapper(uint64_t contextHandle) {
NEO::MockDevice *neoDevice = static_cast<NEO::MockDevice *>(connectedDevice->getNEODevice());
return closeSipWrapper(neoDevice, contextHandle);
}
};
TEST_F(DebugApiLinuxTestXe, GivenValidDeviceWhenOpenSipWrapperIsCalledThenFunctionExecutesSuccessfully) {
zet_debug_config_t config = {};
config.pid = 0x1234;
auto session = std::make_unique<MockDebugSessionLinuxXeMasterSip>(config, device, 10);
ASSERT_NE(nullptr, session);
EXPECT_TRUE(session->testOpenSipWrapper(0x1111, 0x2222));
}
TEST_F(DebugApiLinuxTestXe, GivenValidDeviceWhenCloseSipWrapperIsCalledThenFunctionExecutesSuccessfully) {
zet_debug_config_t config = {};
config.pid = 0x1234;
auto session = std::make_unique<MockDebugSessionLinuxXeMasterSip>(config, device, 10);
ASSERT_NE(nullptr, session);
EXPECT_TRUE(session->testCloseSipWrapper(0x3333));
}
} // namespace ult
} // namespace L0