1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
/*
* Copyright (C) 2022-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/debugger/debugger_l0.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/kernel/debug_data.h"
#include "shared/source/os_interface/os_interface.h"
#include "shared/test/common/fixtures/device_fixture.h"
#include "shared/test/common/libult/linux/drm_mock.h"
#include "shared/test/common/mocks/linux/mock_drm_allocation.h"
#include "shared/test/common/mocks/mock_device.h"
#include "shared/test/common/mocks/mock_l0_debugger.h"
#include "shared/test/common/test_macros/hw_test.h"
#include "shared/test/common/test_macros/test.h"
#include <algorithm>
#include <memory>
using namespace NEO;
struct L0DebuggerSharedLinuxFixture {
void setUp() {
setUp(nullptr);
}
void setUp(HardwareInfo *hwInfo) {
auto executionEnvironment = new NEO::ExecutionEnvironment();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->setDebuggingMode(NEO::DebuggingMode::online);
executionEnvironment->rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(hwInfo ? hwInfo : defaultHwInfo.get());
executionEnvironment->initializeMemoryManager();
auto osInterface = new OSInterface();
drmMock = new DrmMockResources(*executionEnvironment->rootDeviceEnvironments[0]);
executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(osInterface);
executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<Drm>(drmMock));
neoDevice.reset(NEO::MockDevice::create<NEO::MockDevice>(executionEnvironment, 0u));
auto rootDeviceEnvironment = neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0].get();
rootDeviceEnvironment->initDebuggerL0(neoDevice.get());
}
void tearDown() {
drmMock = nullptr;
};
std::unique_ptr<NEO::MockDevice> neoDevice = nullptr;
DrmMockResources *drmMock = nullptr;
};
using L0DebuggerSharedLinuxTest = Test<L0DebuggerSharedLinuxFixture>;
TEST_F(L0DebuggerSharedLinuxTest, givenNoOSInterfaceThenRegisterElfDoesNothing) {
NEO::OSInterface *osInterfaceTmp = neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.release();
NEO::DebugData debugData;
debugData.vIsa = "01234567890";
debugData.vIsaSize = 10;
drmMock->registeredDataSize = 0;
neoDevice->getL0Debugger()->registerElf(&debugData);
EXPECT_EQ(static_cast<size_t>(0u), drmMock->registeredDataSize);
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.reset(osInterfaceTmp);
}
TEST_F(L0DebuggerSharedLinuxTest, givenNoOSInterfaceThenRegisterElfAndLinkWithAllocationDoesNothing) {
NEO::OSInterface *osInterfaceTmp = neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.release();
NEO::DebugData debugData;
debugData.vIsa = "01234567890";
debugData.vIsaSize = 10;
drmMock->registeredDataSize = 0;
MockDrmAllocation isaAllocation(neoDevice->getRootDeviceIndex(), AllocationType::kernelIsa, MemoryPool::system4KBPages);
MockBufferObject bo(neoDevice->getRootDeviceIndex(), drmMock, 3, 0, 0, 1);
isaAllocation.bufferObjects[0] = &bo;
neoDevice->getL0Debugger()->registerElfAndLinkWithAllocation(&debugData, &isaAllocation);
EXPECT_EQ(static_cast<size_t>(0u), drmMock->registeredDataSize);
EXPECT_EQ(0u, isaAllocation.bufferObjects[0]->getBindExtHandles().size());
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.reset(osInterfaceTmp);
}
struct SingleAddressSpaceLinuxFixture : public Test<NEO::DeviceFixture> {
void SetUp() override {
Test<NEO::DeviceFixture>::SetUp();
}
void TearDown() override {
Test<NEO::DeviceFixture>::TearDown();
}
};
HWTEST_F(SingleAddressSpaceLinuxFixture, givenDebuggingModeOfflineWhenDebuggerIsCreatedThenItHasCorrectSingleAddressSpaceValue) {
auto debugger = std::make_unique<MockDebuggerL0Hw<FamilyType>>(pDevice);
debugger->initialize();
EXPECT_FALSE(debugger->singleAddressSpaceSbaTracking);
pDevice->getExecutionEnvironment()->setDebuggingMode(DebuggingMode::offline);
debugger = std::make_unique<MockDebuggerL0Hw<FamilyType>>(pDevice);
debugger->initialize();
EXPECT_TRUE(debugger->singleAddressSpaceSbaTracking);
}
|