Reorganization directory structure [2/n]

Change-Id: I47962d17d755e80dcd9476e1ed75560f433f6115
This commit is contained in:
kamdiedrich
2020-02-23 09:03:33 +01:00
committed by Jaroslaw Chodor
parent d015d3633f
commit e8852a68c4
1292 changed files with 171 additions and 142 deletions

View File

@@ -0,0 +1,17 @@
#
# Copyright (C) 2018-2020 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
set(IGDRCL_SRCS_tests_source_level_debugger
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/source_level_debugger_device_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source_level_debugger_csr_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source_level_debugger_tests.cpp
)
get_property(NEO_CORE_TESTS_SOURCE_LEVEL_DEBUGGER GLOBAL PROPERTY NEO_CORE_TESTS_SOURCE_LEVEL_DEBUGGER)
list(APPEND IGDRCL_SRCS_tests_source_level_debugger ${NEO_CORE_TESTS_SOURCE_LEVEL_DEBUGGER})
target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_source_level_debugger})

View File

@@ -0,0 +1,200 @@
/*
* Copyright (C) 2018-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "opencl/source/command_queue/command_queue_hw.h"
#include "opencl/source/source_level_debugger/source_level_debugger.h"
#include "test.h"
#include "fixtures/device_fixture.h"
#include "helpers/dispatch_flags_helper.h"
#include "helpers/execution_environment_helper.h"
#include "helpers/hw_parse.h"
#include "mocks/mock_builtins.h"
#include "mocks/mock_csr.h"
#include "mocks/mock_device.h"
#include "mocks/mock_graphics_allocation.h"
#include "mocks/mock_memory_manager.h"
#include <memory>
class CommandStreamReceiverWithActiveDebuggerTest : public ::testing::Test {
protected:
template <typename FamilyType>
auto createCSR() {
hwInfo = nullptr;
EnvironmentWithCsrWrapper environment;
environment.setCsrType<MockCsrHw2<FamilyType>>();
executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1);
hwInfo->capabilityTable = platformDevices[0]->capabilityTable;
hwInfo->capabilityTable.debuggerSupported = true;
auto mockMemoryManager = new MockMemoryManager(*executionEnvironment);
executionEnvironment->memoryManager.reset(mockMemoryManager);
device = std::make_unique<MockClDevice>(Device::create<MockDevice>(executionEnvironment, 0));
device->setSourceLevelDebuggerActive(true);
return static_cast<MockCsrHw2<FamilyType> *>(device->getDefaultEngine().commandStreamReceiver);
}
std::unique_ptr<MockClDevice> device;
ExecutionEnvironment *executionEnvironment = nullptr;
HardwareInfo *hwInfo = nullptr;
};
HWTEST_F(CommandStreamReceiverWithActiveDebuggerTest, givenCsrWithActiveDebuggerAndDisabledPreemptionWhenFlushTaskIsCalledThenSipKernelIsMadeResident) {
auto mockCsr = createCSR<FamilyType>();
CommandQueueHw<FamilyType> commandQueue(nullptr, device.get(), 0, false);
auto &commandStream = commandQueue.getCS(4096u);
DispatchFlags dispatchFlags = DispatchFlagsHelper::createDefaultDispatchFlags();
void *buffer = alignedMalloc(MemoryConstants::pageSize, MemoryConstants::pageSize64k);
std::unique_ptr<MockGraphicsAllocation> allocation(new MockGraphicsAllocation(buffer, MemoryConstants::pageSize));
std::unique_ptr<IndirectHeap> heap(new IndirectHeap(allocation.get()));
mockCsr->flushTask(commandStream,
0,
*heap.get(),
*heap.get(),
*heap.get(),
0,
dispatchFlags,
device->getDevice());
auto sipType = SipKernel::getSipKernelType(device->getHardwareInfo().platform.eRenderCoreFamily, true);
auto sipAllocation = device->getExecutionEnvironment()->getBuiltIns()->getSipKernel(sipType, device->getDevice()).getSipAllocation();
bool found = false;
for (auto allocation : mockCsr->copyOfAllocations) {
if (allocation == sipAllocation) {
found = true;
break;
}
}
EXPECT_TRUE(found);
alignedFree(buffer);
}
HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverWithActiveDebuggerTest, givenCsrWithActiveDebuggerAndDisabledPreemptionWhenFlushTaskIsCalledThenStateSipCmdIsProgrammed) {
using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS;
using STATE_SIP = typename FamilyType::STATE_SIP;
auto mockCsr = createCSR<FamilyType>();
if (device->getHardwareInfo().capabilityTable.defaultPreemptionMode == PreemptionMode::MidThread) {
CommandQueueHw<FamilyType> commandQueue(nullptr, device.get(), 0, false);
auto &commandStream = commandQueue.getCS(4096u);
auto &preambleStream = mockCsr->getCS(0);
DispatchFlags dispatchFlags = DispatchFlagsHelper::createDefaultDispatchFlags();
void *buffer = alignedMalloc(MemoryConstants::pageSize, MemoryConstants::pageSize64k);
std::unique_ptr<MockGraphicsAllocation> allocation(new MockGraphicsAllocation(buffer, MemoryConstants::pageSize));
std::unique_ptr<IndirectHeap> heap(new IndirectHeap(allocation.get()));
mockCsr->flushTask(commandStream,
0,
*heap.get(),
*heap.get(),
*heap.get(),
0,
dispatchFlags,
device->getDevice());
auto sipType = SipKernel::getSipKernelType(device->getHardwareInfo().platform.eRenderCoreFamily, true);
auto sipAllocation = device->getExecutionEnvironment()->getBuiltIns()->getSipKernel(sipType, device->getDevice()).getSipAllocation();
HardwareParse hwParser;
hwParser.parseCommands<FamilyType>(preambleStream);
auto itorStateBaseAddr = find<STATE_BASE_ADDRESS *>(hwParser.cmdList.begin(), hwParser.cmdList.end());
auto itorStateSip = find<STATE_SIP *>(hwParser.cmdList.begin(), hwParser.cmdList.end());
ASSERT_NE(hwParser.cmdList.end(), itorStateBaseAddr);
ASSERT_NE(hwParser.cmdList.end(), itorStateSip);
STATE_BASE_ADDRESS *sba = (STATE_BASE_ADDRESS *)*itorStateBaseAddr;
STATE_SIP *stateSipCmd = (STATE_SIP *)*itorStateSip;
EXPECT_LT(reinterpret_cast<void *>(sba), reinterpret_cast<void *>(stateSipCmd));
auto sipAddress = stateSipCmd->getSystemInstructionPointer();
EXPECT_EQ(sipAllocation->getGpuAddressToPatch(), sipAddress);
alignedFree(buffer);
}
}
HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverWithActiveDebuggerTest, givenCsrWithActiveDebuggerAndWhenFlushTaskIsCalledThenAlwaysProgramStateBaseAddressAndSip) {
using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS;
using STATE_SIP = typename FamilyType::STATE_SIP;
auto mockCsr = createCSR<FamilyType>();
if (device->getHardwareInfo().capabilityTable.defaultPreemptionMode == PreemptionMode::MidThread) {
mockCsr->overrideDispatchPolicy(DispatchMode::ImmediateDispatch);
CommandQueueHw<FamilyType> commandQueue(nullptr, device.get(), 0, false);
auto &commandStream = commandQueue.getCS(4096u);
auto &preambleStream = mockCsr->getCS(0);
DispatchFlags dispatchFlags = DispatchFlagsHelper::createDefaultDispatchFlags();
void *buffer = alignedMalloc(MemoryConstants::pageSize, MemoryConstants::pageSize64k);
std::unique_ptr<MockGraphicsAllocation> allocation(new MockGraphicsAllocation(buffer, MemoryConstants::pageSize));
std::unique_ptr<IndirectHeap> heap(new IndirectHeap(allocation.get()));
mockCsr->flushTask(commandStream,
0,
*heap.get(),
*heap.get(),
*heap.get(),
0,
dispatchFlags,
device->getDevice());
mockCsr->flushBatchedSubmissions();
mockCsr->flushTask(commandStream,
0,
*heap.get(),
*heap.get(),
*heap.get(),
0,
dispatchFlags,
device->getDevice());
auto sipType = SipKernel::getSipKernelType(device->getHardwareInfo().platform.eRenderCoreFamily, true);
auto sipAllocation = device->getExecutionEnvironment()->getBuiltIns()->getSipKernel(sipType, device->getDevice()).getSipAllocation();
HardwareParse hwParser;
hwParser.parseCommands<FamilyType>(preambleStream);
auto itorStateBaseAddr = find<STATE_BASE_ADDRESS *>(hwParser.cmdList.begin(), hwParser.cmdList.end());
auto itorStateSip = find<STATE_SIP *>(hwParser.cmdList.begin(), hwParser.cmdList.end());
ASSERT_NE(hwParser.cmdList.end(), itorStateBaseAddr);
ASSERT_NE(hwParser.cmdList.end(), itorStateSip);
auto itorStateBaseAddr2 = find<STATE_BASE_ADDRESS *>(std::next(itorStateBaseAddr), hwParser.cmdList.end());
auto itorStateSip2 = find<STATE_SIP *>(std::next(itorStateSip), hwParser.cmdList.end());
ASSERT_NE(hwParser.cmdList.end(), itorStateBaseAddr2);
ASSERT_NE(hwParser.cmdList.end(), itorStateSip2);
STATE_BASE_ADDRESS *sba = (STATE_BASE_ADDRESS *)*itorStateBaseAddr2;
STATE_SIP *stateSipCmd = (STATE_SIP *)*itorStateSip2;
EXPECT_LT(reinterpret_cast<void *>(sba), reinterpret_cast<void *>(stateSipCmd));
auto sipAddress = stateSipCmd->getSystemInstructionPointer();
EXPECT_EQ(sipAllocation->getGpuAddressToPatch(), sipAddress);
alignedFree(buffer);
}
}

View File

@@ -0,0 +1,57 @@
/*
* Copyright (C) 2018-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "core/unit_tests/helpers/debug_manager_state_restore.h"
#include "opencl/source/platform/platform.h"
#include "opencl/source/source_level_debugger/source_level_debugger.h"
#include "test.h"
#include "fixtures/device_fixture.h"
#include "mocks/mock_builtins.h"
#include "mocks/mock_device.h"
#include "mocks/mock_source_level_debugger.h"
using PreambleTest = ::testing::Test;
using namespace NEO;
class MockOsLibrary : public OsLibrary {
public:
void *getProcAddress(const std::string &procName) override {
return nullptr;
}
bool isLoaded() override {
return false;
}
};
class MockDeviceWithDebuggerActive : public MockDevice {
public:
MockDeviceWithDebuggerActive(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex) : MockDevice(executionEnvironment, deviceIndex) {}
void initializeCaps() override {
MockDevice::initializeCaps();
this->setDebuggerActive(true);
}
};
TEST(DeviceWithSourceLevelDebugger, givenDeviceWithSourceLevelDebuggerActiveWhenDeviceIsDestructedThenSourceLevelDebuggerIsNotified) {
ExecutionEnvironment *executionEnvironment = platform()->peekExecutionEnvironment();
auto gmock = new ::testing::NiceMock<GMockSourceLevelDebugger>(new MockOsLibrary);
executionEnvironment->debugger.reset(gmock);
auto device = std::unique_ptr<MockDevice>(MockDevice::create<MockDeviceWithDebuggerActive>(executionEnvironment, 0u));
std::unique_ptr<MockClDevice> pClDevice(new MockClDevice{device.get()});
EXPECT_CALL(*gmock, notifyDeviceDestruction()).Times(1);
device.release();
}
TEST(DeviceWithSourceLevelDebugger, givenDeviceWithSourceLevelDebuggerActiveWhenDeviceIsCreatedThenPreemptionIsDisabled) {
ExecutionEnvironment *executionEnvironment = platform()->peekExecutionEnvironment();
executionEnvironment->debugger.reset(new MockActiveSourceLevelDebugger(new MockOsLibrary));
auto device = std::unique_ptr<MockDevice>(MockDevice::create<MockDeviceWithDebuggerActive>(executionEnvironment, 0u));
EXPECT_EQ(PreemptionMode::Disabled, device->getPreemptionMode());
}

View File

@@ -0,0 +1,566 @@
/*
* Copyright (C) 2018-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "core/device/device.h"
#include "core/os_interface/os_interface.h"
#include "core/unit_tests/helpers/ult_hw_config.h"
#include "opencl/source/platform/platform.h"
#include "opencl/source/program/kernel_info.h"
#include "opencl/source/source_level_debugger/source_level_debugger.h"
#include "fixtures/device_fixture.h"
#include "helpers/execution_environment_helper.h"
#include "helpers/variable_backup.h"
#include "libult/source_level_debugger_library.h"
#include "mocks/mock_platform.h"
#include "mocks/mock_source_level_debugger.h"
#include <gtest/gtest.h>
#include <memory>
#include <string>
using namespace NEO;
using std::string;
using std::unique_ptr;
class DebuggerLibraryRestorer {
public:
DebuggerLibraryRestorer() {
restoreActiveState = DebuggerLibrary::getDebuggerActive();
restoreAvailableState = DebuggerLibrary::getLibraryAvailable();
}
~DebuggerLibraryRestorer() {
DebuggerLibrary::clearDebuggerLibraryInterceptor();
DebuggerLibrary::setDebuggerActive(restoreActiveState);
DebuggerLibrary::setLibraryAvailable(restoreAvailableState);
}
bool restoreActiveState = false;
bool restoreAvailableState = false;
};
TEST(SourceLevelDebugger, givenPlatformWhenItIsCreatedThenSourceLevelDebuggerIsCreatedInExecutionEnvironment) {
DebuggerLibraryRestorer restorer;
if (platformDevices[0]->capabilityTable.debuggerSupported) {
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(true);
auto executionEnvironment = new ExecutionEnvironment();
MockPlatform platform(*executionEnvironment);
platform.initializeWithNewDevices();
EXPECT_NE(nullptr, executionEnvironment->debugger);
}
}
TEST(SourceLevelDebugger, givenNoKernelDebuggerLibraryWhenSourceLevelDebuggerIsCreatedThenLibraryIsNotLoaded) {
DebuggerLibraryRestorer restorer;
DebuggerLibrary::setLibraryAvailable(false);
MockSourceLevelDebugger debugger;
EXPECT_EQ(nullptr, debugger.debuggerLibrary.get());
}
TEST(SourceLevelDebugger, givenKernelDebuggerLibraryAvailableWhenSourceLevelDebuggerIsConstructedThenLibraryIsLoaded) {
DebuggerLibraryRestorer restorer;
DebuggerLibrary::setLibraryAvailable(true);
MockSourceLevelDebugger debugger;
EXPECT_NE(nullptr, debugger.debuggerLibrary.get());
}
TEST(SourceLevelDebugger, givenKernelDebuggerLibraryAvailableWhenIsDebuggerActiveIsCalledThenFalseIsReturned) {
DebuggerLibraryRestorer restorer;
DebuggerLibrary::setLibraryAvailable(true);
MockSourceLevelDebugger debugger;
bool active = debugger.isDebuggerActive();
EXPECT_FALSE(active);
}
TEST(SourceLevelDebugger, givenKernelDebuggerLibraryActiveWhenIsDebuggerActiveIsCalledThenTrueIsReturned) {
DebuggerLibraryRestorer restorer;
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(true);
MockSourceLevelDebugger debugger;
bool active = debugger.isDebuggerActive();
EXPECT_TRUE(active);
}
TEST(SourceLevelDebugger, givenKernelDebuggerLibraryNotAvailableWhenIsDebuggerActiveIsCalledThenFalseIsReturned) {
DebuggerLibraryRestorer restorer;
DebuggerLibrary::setLibraryAvailable(false);
MockSourceLevelDebugger debugger;
bool active = debugger.isDebuggerActive();
EXPECT_FALSE(active);
}
TEST(SourceLevelDebugger, givenKernelDebuggerLibraryActiveWhenNotifySourceCodeIsCalledThenDebuggerLibraryFunctionIsCalled) {
DebuggerLibraryRestorer restorer;
DebuggerLibraryInterceptor interceptor;
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(true);
DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor);
MockSourceLevelDebugger debugger;
GfxDbgSourceCode argOut;
char fileName[] = "filename";
argOut.sourceName = fileName;
argOut.sourceNameMaxLen = sizeof(fileName);
interceptor.sourceCodeArgOut = &argOut;
const char source[] = "sourceCode";
string file;
debugger.notifySourceCode(source, sizeof(source), file);
EXPECT_TRUE(interceptor.sourceCodeCalled);
EXPECT_EQ(reinterpret_cast<GfxDeviceHandle>(static_cast<uint64_t>(MockSourceLevelDebugger::mockDeviceHandle)), interceptor.sourceCodeArgIn.hDevice);
EXPECT_EQ(source, interceptor.sourceCodeArgIn.sourceCode);
EXPECT_EQ(sizeof(source), interceptor.sourceCodeArgIn.sourceCodeSize);
EXPECT_NE(nullptr, interceptor.sourceCodeArgIn.sourceName);
EXPECT_NE(0u, interceptor.sourceCodeArgIn.sourceNameMaxLen);
EXPECT_STREQ(fileName, file.c_str());
}
TEST(SourceLevelDebugger, givenKernelDebuggerLibraryNotActiveWhenNotifySourceCodeIsCalledThenDebuggerLibraryFunctionIsNotCalled) {
DebuggerLibraryRestorer restorer;
DebuggerLibraryInterceptor interceptor;
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(false);
DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor);
MockSourceLevelDebugger debugger;
debugger.setActive(false);
const char source[] = "sourceCode";
string file;
debugger.notifySourceCode(source, sizeof(source), file);
EXPECT_FALSE(interceptor.sourceCodeCalled);
}
TEST(SourceLevelDebugger, givenKernelDebuggerLibraryActiveWhenNotifyNewDeviceIsCalledThenDebuggerLibraryFunctionIsCalled) {
DebuggerLibraryRestorer restorer;
DebuggerLibraryInterceptor interceptor;
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(true);
DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor);
MockSourceLevelDebugger debugger;
debugger.notifyNewDevice(4);
EXPECT_TRUE(interceptor.newDeviceCalled);
EXPECT_EQ(reinterpret_cast<GfxDeviceHandle>(static_cast<uint64_t>(4u)), interceptor.newDeviceArgIn.dh);
EXPECT_EQ(4u, debugger.deviceHandle);
}
TEST(SourceLevelDebugger, givenKernelDebuggerLibraryNotActiveWhenNotifyNewDeviceIsCalledThenDebuggerLibraryFunctionIsNotCalled) {
DebuggerLibraryRestorer restorer;
DebuggerLibraryInterceptor interceptor;
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(false);
DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor);
MockSourceLevelDebugger debugger;
debugger.setActive(false);
debugger.notifyNewDevice(4);
EXPECT_FALSE(interceptor.newDeviceCalled);
}
TEST(SourceLevelDebugger, givenKernelDebuggerLibraryActiveWhenIsOptimizationDisabledIsCalledThenDebuggerLibraryFunctionIsCalled) {
DebuggerLibraryRestorer restorer;
DebuggerLibraryInterceptor interceptor;
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(true);
DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor);
MockSourceLevelDebugger debugger;
bool isOptDisabled = debugger.isOptimizationDisabled();
EXPECT_FALSE(isOptDisabled);
EXPECT_TRUE(interceptor.optionCalled);
EXPECT_EQ(GfxDbgOptionNames::DBG_OPTION_IS_OPTIMIZATION_DISABLED, interceptor.optionArgIn.optionName);
EXPECT_NE(nullptr, interceptor.optionArgIn.value);
EXPECT_LT(0u, interceptor.optionArgIn.valueLen);
}
TEST(SourceLevelDebugger, givenKernelDebuggerLibraryNotActiveWhenIsOptimizationDisabledIsCalledThenDebuggerLibraryFunctionIsNotCalled) {
DebuggerLibraryRestorer restorer;
DebuggerLibraryInterceptor interceptor;
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor);
MockSourceLevelDebugger debugger;
debugger.setActive(false);
bool isOptDisabled = debugger.isOptimizationDisabled();
EXPECT_FALSE(isOptDisabled);
EXPECT_FALSE(interceptor.optionCalled);
}
TEST(SourceLevelDebugger, givenActiveDebuggerWhenGetDebuggerOptionReturnsZeroThenIsOptimizationDisabledReturnsFalse) {
DebuggerLibraryRestorer restorer;
DebuggerLibraryInterceptor interceptor;
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(true);
DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor);
char value = '1';
GfxDbgOption optionArgOut;
interceptor.optionArgOut = &optionArgOut;
interceptor.optionArgOut->value = &value;
interceptor.optionArgOut->valueLen = sizeof(value);
interceptor.optionRetVal = 0;
MockSourceLevelDebugger debugger;
bool isOptDisabled = debugger.isOptimizationDisabled();
EXPECT_FALSE(isOptDisabled);
}
TEST(SourceLevelDebugger, givenActiveDebuggerAndOptDisabledWhenGetDebuggerOptionReturnsNonZeroAndOneInValueThenIsOptimizationDisabledReturnsTrue) {
DebuggerLibraryRestorer restorer;
DebuggerLibraryInterceptor interceptor;
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(true);
DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor);
char value[2] = {'1', 0};
GfxDbgOption optionArgOut;
interceptor.optionArgOut = &optionArgOut;
interceptor.optionArgOut->value = value;
interceptor.optionArgOut->valueLen = sizeof(value);
interceptor.optionRetVal = 1;
MockSourceLevelDebugger debugger;
bool isOptDisabled = debugger.isOptimizationDisabled();
EXPECT_TRUE(isOptDisabled);
}
TEST(SourceLevelDebugger, givenActiveDebuggerAndOptDisabledWhenGetDebuggerOptionReturnsNonZeroAndZeroInValueThenIsOptimizationDisabledReturnsFalse) {
DebuggerLibraryRestorer restorer;
DebuggerLibraryInterceptor interceptor;
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(true);
DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor);
char value = '0';
GfxDbgOption optionArgOut;
interceptor.optionArgOut = &optionArgOut;
interceptor.optionArgOut->value = &value;
interceptor.optionArgOut->valueLen = sizeof(value);
interceptor.optionRetVal = 1;
MockSourceLevelDebugger debugger;
bool isOptDisabled = debugger.isOptimizationDisabled();
EXPECT_FALSE(isOptDisabled);
}
TEST(SourceLevelDebugger, givenKernelDebuggerLibraryActiveWhenNotifyKernelDebugDataIsCalledThenDebuggerLibraryFunctionIsCalled) {
DebuggerLibraryRestorer restorer;
DebuggerLibraryInterceptor interceptor;
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(true);
DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor);
MockSourceLevelDebugger debugger;
char isa[8];
char dbgIsa[10];
char visa[12];
KernelInfo info;
info.debugData.genIsa = dbgIsa;
info.debugData.vIsa = visa;
info.debugData.genIsaSize = sizeof(dbgIsa);
info.debugData.vIsaSize = sizeof(visa);
info.name = "debugKernel";
SKernelBinaryHeaderCommon kernelHeader;
kernelHeader.KernelHeapSize = sizeof(isa);
info.heapInfo.pKernelHeader = &kernelHeader;
info.heapInfo.pKernelHeap = isa;
debugger.notifyKernelDebugData(&info);
EXPECT_TRUE(interceptor.kernelDebugDataCalled);
EXPECT_EQ(static_cast<uint32_t>(IGFXDBG_CURRENT_VERSION), interceptor.kernelDebugDataArgIn.version);
EXPECT_EQ(reinterpret_cast<GfxDeviceHandle>(static_cast<uint64_t>(MockSourceLevelDebugger::mockDeviceHandle)), interceptor.kernelDebugDataArgIn.hDevice);
EXPECT_EQ(reinterpret_cast<GenRtProgramHandle>(0), interceptor.kernelDebugDataArgIn.hProgram);
EXPECT_EQ(dbgIsa, interceptor.kernelDebugDataArgIn.dbgGenIsaBuffer);
EXPECT_EQ(sizeof(dbgIsa), interceptor.kernelDebugDataArgIn.dbgGenIsaSize);
EXPECT_EQ(visa, interceptor.kernelDebugDataArgIn.dbgVisaBuffer);
EXPECT_EQ(sizeof(visa), interceptor.kernelDebugDataArgIn.dbgVisaSize);
EXPECT_EQ(kernelHeader.KernelHeapSize, interceptor.kernelDebugDataArgIn.KernelBinSize);
EXPECT_EQ(isa, interceptor.kernelDebugDataArgIn.kernelBinBuffer);
EXPECT_STREQ(info.name.c_str(), interceptor.kernelDebugDataArgIn.kernelName);
}
TEST(SourceLevelDebugger, givenNoVisaWhenNotifyKernelDebugDataIsCalledThenDebuggerLibraryFunctionIsNotCalled) {
DebuggerLibraryRestorer restorer;
DebuggerLibraryInterceptor interceptor;
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(true);
DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor);
MockSourceLevelDebugger debugger;
char isa[8];
char dbgIsa[10];
KernelInfo info;
info.debugData.genIsa = dbgIsa;
info.debugData.vIsa = nullptr;
info.debugData.genIsaSize = sizeof(dbgIsa);
info.debugData.vIsaSize = 0;
info.name = "debugKernel";
SKernelBinaryHeaderCommon kernelHeader;
kernelHeader.KernelHeapSize = sizeof(isa);
info.heapInfo.pKernelHeader = &kernelHeader;
info.heapInfo.pKernelHeap = isa;
debugger.notifyKernelDebugData(&info);
EXPECT_FALSE(interceptor.kernelDebugDataCalled);
}
TEST(SourceLevelDebugger, givenNoGenIsaWhenNotifyKernelDebugDataIsCalledThenDebuggerLibraryFunctionIsNotCalled) {
DebuggerLibraryRestorer restorer;
DebuggerLibraryInterceptor interceptor;
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(true);
DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor);
MockSourceLevelDebugger debugger;
char isa[8];
char visa[12];
KernelInfo info;
info.debugData.genIsa = nullptr;
info.debugData.vIsa = visa;
info.debugData.genIsaSize = 0;
info.debugData.vIsaSize = sizeof(visa);
info.name = "debugKernel";
SKernelBinaryHeaderCommon kernelHeader;
kernelHeader.KernelHeapSize = sizeof(isa);
info.heapInfo.pKernelHeader = &kernelHeader;
info.heapInfo.pKernelHeap = isa;
debugger.notifyKernelDebugData(&info);
EXPECT_FALSE(interceptor.kernelDebugDataCalled);
}
TEST(SourceLevelDebugger, givenKernelDebuggerLibraryNotActiveWhenNotifyKernelDebugDataIsCalledThenDebuggerLibraryFunctionIsNotCalled) {
DebuggerLibraryRestorer restorer;
DebuggerLibraryInterceptor interceptor;
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(false);
DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor);
MockSourceLevelDebugger debugger;
debugger.setActive(false);
KernelInfo info;
debugger.notifyKernelDebugData(&info);
EXPECT_FALSE(interceptor.kernelDebugDataCalled);
}
TEST(SourceLevelDebugger, givenKernelDebuggerLibraryActiveWhenInitializeIsCalledWithLocalMemoryUsageFalseThenDebuggerFunctionIsCalledWithCorrectArg) {
DebuggerLibraryRestorer restorer;
DebuggerLibraryInterceptor interceptor;
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(true);
DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor);
MockSourceLevelDebugger debugger;
debugger.initialize(false);
EXPECT_TRUE(interceptor.initCalled);
EXPECT_FALSE(interceptor.targetCapsArgIn.supportsLocalMemory);
}
TEST(SourceLevelDebugger, givenKernelDebuggerLibraryActiveWhenInitializeReturnsErrorThenIsActiveIsSetToFalse) {
DebuggerLibraryRestorer restorer;
DebuggerLibraryInterceptor interceptor;
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(true);
DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor);
MockSourceLevelDebugger debugger;
interceptor.initRetVal = IgfxdbgRetVal::IGFXDBG_FAILURE;
debugger.initialize(false);
EXPECT_TRUE(interceptor.initCalled);
EXPECT_FALSE(debugger.isDebuggerActive());
}
TEST(SourceLevelDebugger, givenKernelDebuggerLibraryActiveWhenInitializeIsCalledWithLocalMemoryUsageTrueThenDebuggerFunctionIsCalledWithCorrectArg) {
DebuggerLibraryRestorer restorer;
DebuggerLibraryInterceptor interceptor;
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(true);
DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor);
MockSourceLevelDebugger debugger;
debugger.initialize(true);
EXPECT_TRUE(interceptor.initCalled);
EXPECT_TRUE(interceptor.targetCapsArgIn.supportsLocalMemory);
}
TEST(SourceLevelDebugger, givenKernelDebuggerLibraryNotActiveWhenInitializeIsCalledThenDebuggerFunctionIsNotCalled) {
DebuggerLibraryRestorer restorer;
DebuggerLibraryInterceptor interceptor;
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(false);
DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor);
MockSourceLevelDebugger debugger;
debugger.initialize(false);
EXPECT_FALSE(interceptor.initCalled);
}
TEST(SourceLevelDebugger, givenKernelDebuggerLibraryActiveWhenDeviceIsConstructedThenDebuggerIsInitialized) {
DebuggerLibraryRestorer restorer;
if (platformDevices[0]->capabilityTable.debuggerSupported) {
DebuggerLibraryInterceptor interceptor;
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(true);
DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor);
unique_ptr<MockDevice> device(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
EXPECT_TRUE(interceptor.initCalled);
}
}
TEST(SourceLevelDebugger, givenKernelDebuggerLibraryActiveWhenDeviceImplIsCreatedThenDebuggerIsNotified) {
DebuggerLibraryRestorer restorer;
if (platformDevices[0]->capabilityTable.debuggerSupported) {
DebuggerLibraryInterceptor interceptor;
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(true);
DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor);
unique_ptr<MockDevice> device(MockDevice::createWithNewExecutionEnvironment<MockDevice>(*platformDevices));
unique_ptr<MockClDevice> pClDevice(new MockClDevice{device.get()});
EXPECT_TRUE(interceptor.newDeviceCalled);
uint32_t deviceHandleExpected = device->getGpgpuCommandStreamReceiver().getOSInterface() != nullptr ? device->getGpgpuCommandStreamReceiver().getOSInterface()->getDeviceHandle() : 0;
EXPECT_EQ(reinterpret_cast<GfxDeviceHandle>(static_cast<uint64_t>(deviceHandleExpected)), interceptor.newDeviceArgIn.dh);
pClDevice.reset();
device.release();
}
}
TEST(SourceLevelDebugger, givenKernelDebuggerLibraryActiveWhenDeviceImplIsCreatedWithOsCsrThenDebuggerIsNotifiedWithCorrectDeviceHandle) {
DebuggerLibraryRestorer restorer;
if (platformDevices[0]->capabilityTable.debuggerSupported) {
DebuggerLibraryInterceptor interceptor;
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(true);
DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor);
VariableBackup<UltHwConfig> backup(&ultHwConfig);
ultHwConfig.useHwCsr = true;
HardwareInfo *hwInfo = nullptr;
ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1);
hwInfo->capabilityTable.instrumentationEnabled = true;
unique_ptr<MockDevice> device(Device::create<MockDevice>(executionEnvironment, 0));
unique_ptr<MockClDevice> pClDevice(new MockClDevice{device.get()});
ASSERT_NE(nullptr, device->getGpgpuCommandStreamReceiver().getOSInterface());
EXPECT_TRUE(interceptor.newDeviceCalled);
uint32_t deviceHandleExpected = device->getGpgpuCommandStreamReceiver().getOSInterface()->getDeviceHandle();
EXPECT_EQ(reinterpret_cast<GfxDeviceHandle>(static_cast<uint64_t>(deviceHandleExpected)), interceptor.newDeviceArgIn.dh);
device.release();
}
}
TEST(SourceLevelDebugger, givenKernelDebuggerLibraryNotActiveWhenDeviceIsCreatedThenDebuggerIsNotCreatedInitializedAndNotNotified) {
DebuggerLibraryRestorer restorer;
DebuggerLibraryInterceptor interceptor;
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(false);
DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor);
unique_ptr<MockDevice> device(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
EXPECT_EQ(nullptr, device->getDebugger());
EXPECT_FALSE(interceptor.initCalled);
EXPECT_FALSE(interceptor.newDeviceCalled);
}
TEST(SourceLevelDebugger, givenTwoRootDevicesWhenSecondIsCreatedThenNotCreatingNewSourceLevelDebugger) {
DebuggerLibraryRestorer restorer;
if (platformDevices[0]->capabilityTable.debuggerSupported) {
DebuggerLibraryInterceptor interceptor;
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(true);
DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor);
ExecutionEnvironment *executionEnvironment = platform()->peekExecutionEnvironment();
executionEnvironment->prepareRootDeviceEnvironments(2);
std::unique_ptr<Device> device1(Device::create<MockDevice>(executionEnvironment, 0u));
EXPECT_NE(nullptr, executionEnvironment->memoryManager);
EXPECT_TRUE(interceptor.initCalled);
interceptor.initCalled = false;
std::unique_ptr<Device> device2(Device::create<MockDevice>(executionEnvironment, 1u));
EXPECT_NE(nullptr, executionEnvironment->memoryManager);
EXPECT_FALSE(interceptor.initCalled);
}
}
TEST(SourceLevelDebugger, givenMultipleRootDevicesWhenTheyAreCreatedTheyAllReuseTheSameSourceLevelDebugger) {
DebuggerLibraryRestorer restorer;
if (platformDevices[0]->capabilityTable.debuggerSupported) {
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(true);
ExecutionEnvironment *executionEnvironment = platform()->peekExecutionEnvironment();
executionEnvironment->prepareRootDeviceEnvironments(2);
std::unique_ptr<Device> device1(Device::create<NEO::MockDevice>(executionEnvironment, 0u));
auto sourceLevelDebugger = device1->getDebugger();
std::unique_ptr<Device> device2(Device::create<NEO::MockDevice>(executionEnvironment, 1u));
EXPECT_EQ(sourceLevelDebugger, device2->getDebugger());
}
}