/* * Copyright (C) 2020-2023 Intel Corporation * * SPDX-License-Identifier: MIT * */ #pragma once #include "shared/source/debugger/debugger_l0.h" #include "shared/source/kernel/debug_data.h" extern NEO::DebugerL0CreateFn mockDebuggerL0HwFactory[]; namespace NEO { template struct WhiteBox; class MockDebuggerL0 : public NEO::DebuggerL0 { public: MockDebuggerL0(NEO::Device *device) : DebuggerL0(device) { isLegacyMode = false; } void captureStateBaseAddress(NEO::LinearStream &cmdStream, SbaAddresses sba, bool useFirstLevelBB) override{}; size_t getSbaTrackingCommandsSize(size_t trackedAddressCount) override { return 0; } size_t getSbaAddressLoadCommandsSize() override { return 0; }; void programSbaAddressLoad(NEO::LinearStream &cmdStream, uint64_t sbaGpuVa) override{}; }; template class MockDebuggerL0Hw : public NEO::DebuggerL0Hw { public: using NEO::DebuggerL0::perContextSbaAllocations; using NEO::DebuggerL0::sbaTrackingGpuVa; using NEO::DebuggerL0::singleAddressSpaceSbaTracking; using NEO::DebuggerL0::uuidL0CommandQueueHandle; MockDebuggerL0Hw(NEO::Device *device) : NEO::DebuggerL0Hw(device) {} ~MockDebuggerL0Hw() override = default; static NEO::DebuggerL0 *allocate(NEO::Device *device) { return new MockDebuggerL0Hw(device); } void captureStateBaseAddress(NEO::LinearStream &cmdStream, NEO::Debugger::SbaAddresses sba, bool useFirstLevelBB) override { captureStateBaseAddressCount++; NEO::DebuggerL0Hw::captureStateBaseAddress(cmdStream, sba, useFirstLevelBB); } size_t getSbaTrackingCommandsSize(size_t trackedAddressCount) override { getSbaTrackingCommandsSizeCount++; return NEO::DebuggerL0Hw::getSbaTrackingCommandsSize(trackedAddressCount); } void registerElfAndLinkWithAllocation(NEO::DebugData *debugData, NEO::GraphicsAllocation *isaAllocation) override { registerElfAndLinkCount++; lastReceivedElf = debugData->vIsa; NEO::DebuggerL0Hw::registerElfAndLinkWithAllocation(debugData, isaAllocation); } uint32_t registerElf(NEO::DebugData *debugData) override { registerElfCount++; lastReceivedElf = debugData->vIsa; if (elfHandleToReturn != std::numeric_limits::max()) { return elfHandleToReturn; } return NEO::DebuggerL0Hw::registerElf(debugData); } bool attachZebinModuleToSegmentAllocations(const StackVec &allocs, uint32_t &moduleHandle, uint32_t elfHandle) override { segmentCountWithAttachedModuleHandle = static_cast(allocs.size()); if (std::numeric_limits::max() != moduleHandleToReturn) { moduleHandle = moduleHandleToReturn; return true; } return NEO::DebuggerL0Hw::attachZebinModuleToSegmentAllocations(allocs, moduleHandle, elfHandle); } bool removeZebinModule(uint32_t moduleHandle) override { removedZebinModuleHandle = moduleHandle; return NEO::DebuggerL0Hw::removeZebinModule(moduleHandle); } void notifyCommandQueueCreated(NEO::Device *device) override { commandQueueCreatedCount++; NEO::DebuggerL0Hw::notifyCommandQueueCreated(device); } void notifyCommandQueueDestroyed(NEO::Device *device) override { commandQueueDestroyedCount++; NEO::DebuggerL0Hw::notifyCommandQueueDestroyed(device); } void registerAllocationType(NEO::GraphicsAllocation *allocation) override { registerAllocationTypeCount++; NEO::DebuggerL0Hw::registerAllocationType(allocation); } void notifyModuleCreate(void *module, uint32_t moduleSize, uint64_t moduleLoadAddress) override { notifyModuleCreateCount++; NEO::DebuggerL0Hw::notifyModuleCreate(module, moduleSize, moduleLoadAddress); } void notifyModuleDestroy(uint64_t moduleLoadAddress) override { notifyModuleDestroyCount++; NEO::DebuggerL0Hw::notifyModuleDestroy(moduleLoadAddress); } void notifyModuleLoadAllocations(NEO::Device *device, const StackVec &allocs) override { notifyModuleLoadAllocationsCapturedDevice = device; NEO::DebuggerL0Hw::notifyModuleLoadAllocations(device, allocs); } uint32_t captureStateBaseAddressCount = 0; uint32_t getSbaTrackingCommandsSizeCount = 0; uint32_t registerElfCount = 0; uint32_t registerElfAndLinkCount = 0; uint32_t commandQueueCreatedCount = 0; uint32_t commandQueueDestroyedCount = 0; uint32_t registerAllocationTypeCount = 0; uint32_t notifyModuleCreateCount = 0; uint32_t notifyModuleDestroyCount = 0; const char *lastReceivedElf = nullptr; uint32_t segmentCountWithAttachedModuleHandle = 0; uint32_t removedZebinModuleHandle = 0; uint32_t moduleHandleToReturn = std::numeric_limits::max(); uint32_t elfHandleToReturn = std::numeric_limits::max(); NEO::Device *notifyModuleLoadAllocationsCapturedDevice = nullptr; }; template <> struct WhiteBox : public NEO::DebuggerL0 { using BaseClass = NEO::DebuggerL0; using BaseClass::initDebuggingInOs; }; template struct MockDebuggerL0HwPopulateFactory { MockDebuggerL0HwPopulateFactory() { mockDebuggerL0HwFactory[productFamily] = MockDebuggerL0Hw::allocate; } }; } // namespace NEO