2018-05-02 20:27:55 +08:00
|
|
|
/*
|
2022-04-20 22:12:20 +08:00
|
|
|
* Copyright (C) 2018-2022 Intel Corporation
|
2018-09-18 15:11:08 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
2018-05-02 20:27:55 +08:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-03-06 17:11:44 +08:00
|
|
|
#include "shared/source/source_level_debugger/source_level_debugger.h"
|
2021-12-20 19:02:31 +08:00
|
|
|
#include "shared/test/common/test_macros/mock_method_macros.h"
|
2018-05-02 20:27:55 +08:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2018-05-02 20:27:55 +08:00
|
|
|
|
|
|
|
class MockSourceLevelDebugger : public SourceLevelDebugger {
|
|
|
|
public:
|
|
|
|
using SourceLevelDebugger::debuggerLibrary;
|
|
|
|
using SourceLevelDebugger::deviceHandle;
|
|
|
|
|
|
|
|
MockSourceLevelDebugger() : SourceLevelDebugger(SourceLevelDebugger::loadDebugger()) {
|
|
|
|
this->deviceHandle = mockDeviceHandle;
|
|
|
|
}
|
|
|
|
|
|
|
|
MockSourceLevelDebugger(OsLibrary *library) : SourceLevelDebugger(library) {
|
|
|
|
this->deviceHandle = mockDeviceHandle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setActive(bool active) {
|
|
|
|
isActive = active;
|
|
|
|
}
|
2021-12-20 19:02:31 +08:00
|
|
|
|
|
|
|
bool isDebuggerActive() override {
|
|
|
|
return isActive;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isOptimizationDisabled() const override {
|
|
|
|
isOptimizationDisabledCalled++;
|
|
|
|
if (callBaseIsOptimizationDisabled) {
|
|
|
|
return SourceLevelDebugger::isOptimizationDisabled();
|
|
|
|
}
|
|
|
|
return isOptimizationDisabledResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutable uint32_t isOptimizationDisabledCalled = 0u;
|
|
|
|
bool isOptimizationDisabledResult = false;
|
|
|
|
|
|
|
|
bool notifySourceCode(const char *sourceCode, size_t size, std::string &filename) const override {
|
|
|
|
notifySourceCodeCalled++;
|
|
|
|
if (callBaseNotifySourceCode) {
|
|
|
|
return SourceLevelDebugger::notifySourceCode(sourceCode, size, filename);
|
|
|
|
}
|
|
|
|
return notifySourceCodeResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutable uint32_t notifySourceCodeCalled = 0u;
|
|
|
|
bool notifySourceCodeResult = false;
|
|
|
|
|
|
|
|
bool notifyKernelDebugData(const DebugData *debugData, const std::string &name, const void *isa, size_t isaSize) const override {
|
|
|
|
notifyKernelDebugDataCalled++;
|
|
|
|
if (callBaseNotifyKernelDebugData) {
|
|
|
|
return SourceLevelDebugger::notifyKernelDebugData(debugData, name, isa, isaSize);
|
|
|
|
}
|
|
|
|
return notifyKernelDebugDataResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutable uint32_t notifyKernelDebugDataCalled = 0u;
|
|
|
|
bool notifyKernelDebugDataResult = false;
|
|
|
|
|
|
|
|
bool notifyNewDevice(uint32_t deviceHandle) override {
|
|
|
|
notifyNewDeviceCalled++;
|
|
|
|
if (callBaseNotifyNewDevice) {
|
|
|
|
return SourceLevelDebugger::notifyNewDevice(deviceHandle);
|
|
|
|
}
|
|
|
|
return notifyNewDeviceResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutable uint32_t notifyNewDeviceCalled = 0u;
|
|
|
|
bool notifyNewDeviceResult = false;
|
|
|
|
|
|
|
|
bool initialize(bool useLocalMemory) override {
|
|
|
|
initializeCalled++;
|
|
|
|
if (callBaseInitialize) {
|
|
|
|
return SourceLevelDebugger::initialize(useLocalMemory);
|
|
|
|
}
|
|
|
|
return initializeResult;
|
|
|
|
}
|
|
|
|
|
2022-04-20 22:12:20 +08:00
|
|
|
size_t getSbaTrackingCommandsSize(size_t trackedAddressCount) override {
|
|
|
|
return sbaTrackingSize;
|
|
|
|
}
|
|
|
|
|
2021-12-20 19:02:31 +08:00
|
|
|
mutable uint32_t initializeCalled = 0u;
|
|
|
|
bool initializeResult = false;
|
|
|
|
|
|
|
|
ADDMETHOD_NOBASE(notifyDeviceDestruction, bool, false, ());
|
|
|
|
|
2018-05-02 20:27:55 +08:00
|
|
|
static const uint32_t mockDeviceHandle = 23;
|
2021-12-20 19:02:31 +08:00
|
|
|
bool callBaseIsOptimizationDisabled = false;
|
|
|
|
bool callBaseNotifySourceCode = false;
|
|
|
|
bool callBaseNotifyKernelDebugData = false;
|
|
|
|
bool callBaseNotifyNewDevice = false;
|
|
|
|
bool callBaseInitialize = false;
|
2022-04-20 22:12:20 +08:00
|
|
|
|
|
|
|
size_t sbaTrackingSize = 0;
|
2018-05-02 20:27:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class MockActiveSourceLevelDebugger : public SourceLevelDebugger {
|
|
|
|
public:
|
|
|
|
using SourceLevelDebugger::debuggerLibrary;
|
|
|
|
using SourceLevelDebugger::deviceHandle;
|
|
|
|
|
|
|
|
MockActiveSourceLevelDebugger() : SourceLevelDebugger(nullptr) {
|
|
|
|
this->deviceHandle = mockDeviceHandle;
|
|
|
|
isActive = true;
|
|
|
|
}
|
|
|
|
|
2018-05-11 19:30:07 +08:00
|
|
|
MockActiveSourceLevelDebugger(OsLibrary *library) : SourceLevelDebugger(library) {
|
2018-05-02 20:27:55 +08:00
|
|
|
this->deviceHandle = mockDeviceHandle;
|
|
|
|
isActive = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setActive(bool active) {
|
|
|
|
isActive = active;
|
|
|
|
}
|
|
|
|
bool isOptimizationDisabled() const override {
|
|
|
|
return isOptDisabled;
|
|
|
|
}
|
|
|
|
bool isDebuggerActive() override {
|
|
|
|
return isActive;
|
|
|
|
}
|
|
|
|
bool notifyNewDevice(uint32_t deviceHandle) override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool notifyDeviceDestruction() override {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool notifySourceCode(const char *sourceCode, size_t size, std::string &filename) const override {
|
|
|
|
filename = sourceCodeFilename;
|
|
|
|
return true;
|
|
|
|
}
|
2020-03-06 02:21:51 +08:00
|
|
|
bool notifyKernelDebugData(const DebugData *debugData, const std::string &name, const void *isa, size_t isaSize) const override {
|
2018-05-02 20:27:55 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool initialize(bool useLocalMemory) override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const uint32_t mockDeviceHandle = 23;
|
|
|
|
bool isOptDisabled = false;
|
|
|
|
std::string sourceCodeFilename;
|
2021-12-20 19:02:31 +08:00
|
|
|
};
|