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
|
|
|
|
2018-06-29 15:12:40 +08:00
|
|
|
MockDevice::MockDevice(const HardwareInfo &hwInfo)
|
2019-01-23 18:59:54 +08:00
|
|
|
: MockDevice(hwInfo, new MockExecutionEnvironment(&hwInfo), 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};
|
2018-07-10 23:14:20 +08:00
|
|
|
}
|
2018-10-19 19:41:42 +08:00
|
|
|
MockDevice::MockDevice(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex)
|
2018-09-11 17:28:19 +08:00
|
|
|
: Device(hwInfo, executionEnvironment, deviceIndex) {
|
2019-02-12 17:56:27 +08:00
|
|
|
bool enableLocalMemory = HwHelper::get(hwInfo.pPlatform->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();
|
|
|
|
mockWaTable = *hwInfo.pWaTable;
|
2019-03-15 17:22:35 +08:00
|
|
|
executionEnvironment->setHwInfo(&hwInfo);
|
|
|
|
executionEnvironment->initializeMemoryManager();
|
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) {
|
|
|
|
executionEnvironment->commandStreamReceivers[getDeviceIndex()][engineIndex].reset(newCsr);
|
|
|
|
executionEnvironment->commandStreamReceivers[getDeviceIndex()][engineIndex]->initializeTagAllocation();
|
|
|
|
executionEnvironment->commandStreamReceivers[getDeviceIndex()][engineIndex]->setPreemptionCsrAllocation(preemptionAllocation);
|
|
|
|
this->engines[engineIndex].commandStreamReceiver = newCsr;
|
2019-02-18 20:59:16 +08:00
|
|
|
|
2019-03-22 21:04:25 +08:00
|
|
|
auto osContext = this->engines[engineIndex].osContext;
|
2019-02-18 20:59:16 +08:00
|
|
|
executionEnvironment->memoryManager->getRegisteredEngines()[osContext->getContextId()].commandStreamReceiver = newCsr;
|
2019-03-22 21:04:25 +08:00
|
|
|
this->engines[engineIndex].commandStreamReceiver->setupContext(*osContext);
|
2018-10-01 22:10:54 +08:00
|
|
|
UNRECOVERABLE_IF(getDeviceIndex() != 0u);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-09-11 17:28:19 +08:00
|
|
|
MockAlignedMallocManagerDevice::MockAlignedMallocManagerDevice(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex) : MockDevice(hwInfo, executionEnvironment, deviceIndex) {
|
2018-10-01 22:10:54 +08:00
|
|
|
this->mockMemoryManager.reset(new MockAllocSysMemAgnosticMemoryManager(*executionEnvironment));
|
2018-01-26 23:53:18 +08:00
|
|
|
}
|
2018-10-19 19:41:42 +08:00
|
|
|
FailDevice::FailDevice(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex)
|
|
|
|
: MockDevice(hwInfo, executionEnvironment, deviceIndex) {
|
|
|
|
this->mockMemoryManager.reset(new FailMemoryManager(*executionEnvironment));
|
|
|
|
}
|
|
|
|
FailDeviceAfterOne::FailDeviceAfterOne(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex)
|
|
|
|
: MockDevice(hwInfo, executionEnvironment, deviceIndex) {
|
|
|
|
this->mockMemoryManager.reset(new FailMemoryManager(1));
|
2019-03-22 21:04:25 +08:00
|
|
|
}
|