2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2019-01-10 16:37:56 +08:00
|
|
|
* Copyright (C) 2017-2019 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unit_tests/mocks/mock_device.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2018-07-13 20:11:04 +08:00
|
|
|
#include "runtime/device/driver_info.h"
|
2019-02-18 20:59:16 +08:00
|
|
|
#include "runtime/os_interface/os_context.h"
|
2019-01-23 18:59:54 +08:00
|
|
|
#include "unit_tests/mocks/mock_execution_environment.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "unit_tests/mocks/mock_memory_manager.h"
|
2018-07-13 20:11:04 +08:00
|
|
|
#include "unit_tests/mocks/mock_ostime.h"
|
2018-09-28 13:19:14 +08:00
|
|
|
#include "unit_tests/tests_configuration.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-10-07 18:42:28 +08:00
|
|
|
bool MockDevice::createSingleDevice = true;
|
|
|
|
|
2019-05-06 18:33:44 +08:00
|
|
|
MockDevice::MockDevice()
|
|
|
|
: MockDevice(new MockExecutionEnvironment(), 0u) {
|
2019-02-27 17:06:14 +08:00
|
|
|
CommandStreamReceiver *commandStreamReceiver = createCommandStream(*this->executionEnvironment);
|
2018-09-11 21:55:04 +08:00
|
|
|
executionEnvironment->commandStreamReceivers.resize(getDeviceIndex() + 1);
|
2019-01-10 20:57:40 +08:00
|
|
|
executionEnvironment->commandStreamReceivers[getDeviceIndex()].resize(defaultEngineIndex + 1);
|
2018-11-28 16:02:55 +08:00
|
|
|
executionEnvironment->commandStreamReceivers[getDeviceIndex()][defaultEngineIndex].reset(commandStreamReceiver);
|
2018-07-20 15:01:58 +08:00
|
|
|
this->executionEnvironment->memoryManager = std::move(this->mockMemoryManager);
|
2019-01-10 20:57:40 +08:00
|
|
|
this->engines.resize(defaultEngineIndex + 1);
|
2018-11-29 18:39:10 +08:00
|
|
|
this->engines[defaultEngineIndex] = {commandStreamReceiver, nullptr};
|
2019-09-25 20:23:04 +08:00
|
|
|
initializeCaps();
|
2018-07-10 23:14:20 +08:00
|
|
|
}
|
2019-05-06 18:33:44 +08:00
|
|
|
|
|
|
|
MockDevice::MockDevice(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex)
|
2019-08-27 15:34:20 +08:00
|
|
|
: RootDevice(executionEnvironment, deviceIndex) {
|
2019-05-06 18:33:44 +08:00
|
|
|
auto &hwInfo = getHardwareInfo();
|
2019-05-08 22:00:24 +08:00
|
|
|
bool enableLocalMemory = HwHelper::get(hwInfo.platform.eRenderCoreFamily).getEnableLocalMemory(hwInfo);
|
2018-09-28 13:19:14 +08:00
|
|
|
bool aubUsage = (testMode == TestMode::AubTests) || (testMode == TestMode::AubTestsWithTbx);
|
2019-03-15 17:22:35 +08:00
|
|
|
this->mockMemoryManager.reset(new MemoryManagerCreate<OsAgnosticMemoryManager>(false, enableLocalMemory, aubUsage, *executionEnvironment));
|
2017-12-21 07:45:38 +08:00
|
|
|
this->osTime = MockOSTime::create();
|
2019-03-15 17:22:35 +08:00
|
|
|
executionEnvironment->setHwInfo(&hwInfo);
|
|
|
|
executionEnvironment->initializeMemoryManager();
|
2019-09-25 20:23:04 +08:00
|
|
|
initializeCaps();
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2019-10-07 18:42:28 +08:00
|
|
|
bool MockDevice::createDeviceImpl() {
|
|
|
|
if (MockDevice::createSingleDevice) {
|
|
|
|
return Device::createDeviceImpl();
|
|
|
|
}
|
|
|
|
return RootDevice::createDeviceImpl();
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
void MockDevice::setOSTime(OSTime *osTime) {
|
|
|
|
this->osTime.reset(osTime);
|
|
|
|
};
|
|
|
|
|
|
|
|
void MockDevice::setDriverInfo(DriverInfo *driverInfo) {
|
|
|
|
this->driverInfo.reset(driverInfo);
|
|
|
|
};
|
|
|
|
|
|
|
|
bool MockDevice::hasDriverInfo() {
|
|
|
|
return driverInfo.get() != nullptr;
|
|
|
|
};
|
|
|
|
|
2018-10-09 17:50:58 +08:00
|
|
|
void MockDevice::injectMemoryManager(MemoryManager *memoryManager) {
|
2018-10-11 17:19:49 +08:00
|
|
|
executionEnvironment->memoryManager.reset(memoryManager);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MockDevice::resetCommandStreamReceiver(CommandStreamReceiver *newCsr) {
|
2019-03-22 21:04:25 +08:00
|
|
|
resetCommandStreamReceiver(newCsr, defaultEngineIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MockDevice::resetCommandStreamReceiver(CommandStreamReceiver *newCsr, uint32_t engineIndex) {
|
2019-09-02 19:23:25 +08:00
|
|
|
UNRECOVERABLE_IF(getDeviceIndex() != 0u);
|
|
|
|
|
|
|
|
auto osContext = this->engines[engineIndex].osContext;
|
|
|
|
auto memoryManager = executionEnvironment->memoryManager.get();
|
|
|
|
auto registeredEngine = *memoryManager->getRegisteredEngineForCsr(engines[engineIndex].commandStreamReceiver);
|
|
|
|
|
|
|
|
registeredEngine.commandStreamReceiver = newCsr;
|
|
|
|
engines[engineIndex].commandStreamReceiver = newCsr;
|
|
|
|
memoryManager->getRegisteredEngines().emplace_back(registeredEngine);
|
|
|
|
osContext->incRefInternal();
|
|
|
|
newCsr->setupContext(*osContext);
|
2019-03-22 21:04:25 +08:00
|
|
|
executionEnvironment->commandStreamReceivers[getDeviceIndex()][engineIndex].reset(newCsr);
|
|
|
|
executionEnvironment->commandStreamReceivers[getDeviceIndex()][engineIndex]->initializeTagAllocation();
|
2019-06-28 03:33:05 +08:00
|
|
|
|
|
|
|
if (preemptionMode == PreemptionMode::MidThread || isSourceLevelDebuggerActive()) {
|
|
|
|
executionEnvironment->commandStreamReceivers[getDeviceIndex()][engineIndex]->createPreemptionAllocation();
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2019-05-06 18:33:44 +08:00
|
|
|
MockAlignedMallocManagerDevice::MockAlignedMallocManagerDevice(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex) : MockDevice(executionEnvironment, deviceIndex) {
|
2018-10-01 22:10:54 +08:00
|
|
|
this->mockMemoryManager.reset(new MockAllocSysMemAgnosticMemoryManager(*executionEnvironment));
|
2018-01-26 23:53:18 +08:00
|
|
|
}
|
2019-05-06 18:33:44 +08:00
|
|
|
FailDevice::FailDevice(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex)
|
|
|
|
: MockDevice(executionEnvironment, deviceIndex) {
|
2018-10-19 19:41:42 +08:00
|
|
|
this->mockMemoryManager.reset(new FailMemoryManager(*executionEnvironment));
|
|
|
|
}
|
2019-05-06 18:33:44 +08:00
|
|
|
FailDeviceAfterOne::FailDeviceAfterOne(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex)
|
|
|
|
: MockDevice(executionEnvironment, deviceIndex) {
|
2019-03-28 22:42:23 +08:00
|
|
|
this->mockMemoryManager.reset(new FailMemoryManager(1, *executionEnvironment));
|
2019-03-22 21:04:25 +08:00
|
|
|
}
|