2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2019-01-10 09:37:56 +01:00
|
|
|
* Copyright (C) 2017-2019 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-18 09:11:08 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "unit_tests/mocks/mock_device.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2018-07-13 14:11:04 +02:00
|
|
|
#include "runtime/device/driver_info.h"
|
2019-02-18 13:59:16 +01:00
|
|
|
#include "runtime/os_interface/os_context.h"
|
2019-01-23 11:59:54 +01:00
|
|
|
#include "unit_tests/mocks/mock_execution_environment.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
#include "unit_tests/mocks/mock_memory_manager.h"
|
2018-07-13 14:11:04 +02:00
|
|
|
#include "unit_tests/mocks/mock_ostime.h"
|
2018-09-27 22:19:14 -07:00
|
|
|
#include "unit_tests/tests_configuration.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
using namespace OCLRT;
|
|
|
|
|
|
2018-06-29 09:12:40 +02:00
|
|
|
MockDevice::MockDevice(const HardwareInfo &hwInfo)
|
2019-01-23 11:59:54 +01:00
|
|
|
: MockDevice(hwInfo, new MockExecutionEnvironment(&hwInfo), 0u) {
|
2019-02-27 10:06:14 +01:00
|
|
|
CommandStreamReceiver *commandStreamReceiver = createCommandStream(*this->executionEnvironment);
|
2018-09-11 15:55:04 +02:00
|
|
|
executionEnvironment->commandStreamReceivers.resize(getDeviceIndex() + 1);
|
2019-01-10 13:57:40 +01:00
|
|
|
executionEnvironment->commandStreamReceivers[getDeviceIndex()].resize(defaultEngineIndex + 1);
|
2018-11-28 09:02:55 +01:00
|
|
|
executionEnvironment->commandStreamReceivers[getDeviceIndex()][defaultEngineIndex].reset(commandStreamReceiver);
|
2018-07-20 09:01:58 +02:00
|
|
|
this->executionEnvironment->memoryManager = std::move(this->mockMemoryManager);
|
2019-01-10 13:57:40 +01:00
|
|
|
this->engines.resize(defaultEngineIndex + 1);
|
2018-11-29 11:39:10 +01:00
|
|
|
this->engines[defaultEngineIndex] = {commandStreamReceiver, nullptr};
|
2018-07-10 17:14:20 +02:00
|
|
|
}
|
2018-10-19 13:41:42 +02:00
|
|
|
MockDevice::MockDevice(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex)
|
2018-09-11 11:28:19 +02:00
|
|
|
: Device(hwInfo, executionEnvironment, deviceIndex) {
|
2019-02-12 10:56:27 +01:00
|
|
|
bool enableLocalMemory = HwHelper::get(hwInfo.pPlatform->eRenderCoreFamily).getEnableLocalMemory(hwInfo);
|
2018-09-27 22:19:14 -07:00
|
|
|
bool aubUsage = (testMode == TestMode::AubTests) || (testMode == TestMode::AubTestsWithTbx);
|
2019-03-15 10:22:35 +01:00
|
|
|
this->mockMemoryManager.reset(new MemoryManagerCreate<OsAgnosticMemoryManager>(false, enableLocalMemory, aubUsage, *executionEnvironment));
|
2017-12-21 00:45:38 +01:00
|
|
|
this->osTime = MockOSTime::create();
|
|
|
|
|
mockWaTable = *hwInfo.pWaTable;
|
2019-03-15 10:22:35 +01:00
|
|
|
executionEnvironment->setHwInfo(&hwInfo);
|
|
|
|
|
executionEnvironment->initializeMemoryManager();
|
2017-12-21 00:45:38 +01: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 11:50:58 +02:00
|
|
|
void MockDevice::injectMemoryManager(MemoryManager *memoryManager) {
|
2018-10-11 11:19:49 +02:00
|
|
|
executionEnvironment->memoryManager.reset(memoryManager);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MockDevice::resetCommandStreamReceiver(CommandStreamReceiver *newCsr) {
|
2019-03-22 14:04:25 +01: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 13:59:16 +01:00
|
|
|
|
2019-03-22 14:04:25 +01:00
|
|
|
auto osContext = this->engines[engineIndex].osContext;
|
2019-02-18 13:59:16 +01:00
|
|
|
executionEnvironment->memoryManager->getRegisteredEngines()[osContext->getContextId()].commandStreamReceiver = newCsr;
|
2019-03-22 14:04:25 +01:00
|
|
|
this->engines[engineIndex].commandStreamReceiver->setupContext(*osContext);
|
2018-10-01 16:10:54 +02:00
|
|
|
UNRECOVERABLE_IF(getDeviceIndex() != 0u);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
2018-09-11 11:28:19 +02:00
|
|
|
MockAlignedMallocManagerDevice::MockAlignedMallocManagerDevice(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex) : MockDevice(hwInfo, executionEnvironment, deviceIndex) {
|
2018-10-01 16:10:54 +02:00
|
|
|
this->mockMemoryManager.reset(new MockAllocSysMemAgnosticMemoryManager(*executionEnvironment));
|
2018-01-26 16:53:18 +01:00
|
|
|
}
|
2018-10-19 13:41:42 +02: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 14:04:25 +01:00
|
|
|
}
|