2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2017-11-14 18:15:09 +08:00
|
|
|
* Copyright (c) 2017 - 2018, Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2018-07-13 20:11:04 +08:00
|
|
|
#include "runtime/device/device.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/helpers/options.h"
|
|
|
|
#include "runtime/indirect_heap/indirect_heap.h"
|
2018-07-13 20:11:04 +08:00
|
|
|
#include "test.h"
|
|
|
|
#include "unit_tests/fixtures/device_fixture.h"
|
2017-11-14 18:15:09 +08:00
|
|
|
#include "unit_tests/helpers/debug_manager_state_restore.h"
|
2018-07-13 20:11:04 +08:00
|
|
|
#include "unit_tests/libult/create_command_stream.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "unit_tests/libult/ult_command_stream_receiver.h"
|
|
|
|
#include "unit_tests/mocks/mock_context.h"
|
2018-03-09 21:48:42 +08:00
|
|
|
#include "unit_tests/mocks/mock_csr.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
using namespace OCLRT;
|
|
|
|
|
2018-03-30 02:37:43 +08:00
|
|
|
typedef Test<DeviceFixture> DeviceTest;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
TEST_F(DeviceTest, Create) {
|
|
|
|
EXPECT_NE(nullptr, pDevice);
|
|
|
|
}
|
|
|
|
|
2018-04-24 19:06:49 +08:00
|
|
|
TEST_F(DeviceTest, givenDeviceWhenGetProductAbbrevThenReturnsHardwarePrefix) {
|
|
|
|
const auto productAbbrev = pDevice->getProductAbbrev();
|
|
|
|
const auto hwPrefix = hardwarePrefix[pDevice->getHardwareInfo().pPlatform->eProductFamily];
|
|
|
|
EXPECT_EQ(hwPrefix, productAbbrev);
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
TEST_F(DeviceTest, getCommandStreamReceiver) {
|
|
|
|
EXPECT_NE(nullptr, &pDevice->getCommandStreamReceiver());
|
|
|
|
}
|
|
|
|
|
2018-01-17 23:23:51 +08:00
|
|
|
TEST_F(DeviceTest, givenDeviceWhenPeekCommandStreamReceiverIsCalledThenCommandStreamReceiverIsReturned) {
|
|
|
|
EXPECT_NE(nullptr, pDevice->peekCommandStreamReceiver());
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
TEST_F(DeviceTest, getSupportedClVersion) {
|
|
|
|
auto version = pDevice->getSupportedClVersion();
|
|
|
|
auto version2 = pDevice->getHardwareInfo().capabilityTable.clVersionSupport;
|
|
|
|
|
|
|
|
EXPECT_EQ(version, version2);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DeviceTest, getTagAddress) {
|
|
|
|
auto pTagAddress = pDevice->getTagAddress();
|
|
|
|
ASSERT_NE(nullptr, const_cast<uint32_t *>(pTagAddress));
|
|
|
|
EXPECT_EQ(initialHardwareTag, *pTagAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DeviceTest, WhenGetOSTimeThenNotNull) {
|
2018-07-25 23:12:44 +08:00
|
|
|
auto pDevice = std::unique_ptr<Device>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
OSTime *osTime = pDevice->getOSTime();
|
|
|
|
ASSERT_NE(nullptr, osTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DeviceTest, GivenDebugVariableForcing32BitAllocationsWhenDeviceIsCreatedThenMemoryManagerHasForce32BitFlagSet) {
|
|
|
|
DebugManager.flags.Force32bitAddressing.set(true);
|
2018-07-25 23:12:44 +08:00
|
|
|
auto pDevice = std::unique_ptr<Device>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
|
2017-12-21 07:45:38 +08:00
|
|
|
if (is64bit) {
|
|
|
|
EXPECT_TRUE(pDevice->getDeviceInfo().force32BitAddressess);
|
|
|
|
EXPECT_TRUE(pDevice->getMemoryManager()->peekForce32BitAllocations());
|
|
|
|
} else {
|
|
|
|
EXPECT_FALSE(pDevice->getDeviceInfo().force32BitAddressess);
|
|
|
|
EXPECT_FALSE(pDevice->getMemoryManager()->peekForce32BitAllocations());
|
|
|
|
}
|
|
|
|
DebugManager.flags.Force32bitAddressing.set(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DeviceTest, retainAndRelease) {
|
|
|
|
ASSERT_NE(nullptr, pDevice);
|
|
|
|
|
|
|
|
pDevice->retain();
|
|
|
|
pDevice->retain();
|
|
|
|
pDevice->retain();
|
|
|
|
ASSERT_EQ(1, pDevice->getReference());
|
|
|
|
|
|
|
|
ASSERT_FALSE(pDevice->release().isUnused());
|
|
|
|
ASSERT_EQ(1, pDevice->getReference());
|
|
|
|
}
|
|
|
|
|
2017-11-14 18:15:09 +08:00
|
|
|
TEST_F(DeviceTest, getEngineTypeDefault) {
|
|
|
|
auto pTestDevice = std::unique_ptr<Device>(createWithUsDeviceId(0));
|
|
|
|
|
|
|
|
EngineType actualEngineType = pDevice->getEngineType();
|
2018-07-25 23:12:44 +08:00
|
|
|
EngineType defaultEngineType = pDevice->getHardwareInfo().capabilityTable.defaultEngineType;
|
2017-11-14 18:15:09 +08:00
|
|
|
|
|
|
|
EXPECT_EQ(defaultEngineType, actualEngineType);
|
|
|
|
}
|
2018-01-18 16:09:01 +08:00
|
|
|
|
2018-02-12 18:48:31 +08:00
|
|
|
TEST_F(DeviceTest, givenDebugVariableOverrideEngineTypeWhenDeviceIsCreatedThenUseDebugNotDefaul) {
|
|
|
|
EngineType expectedEngine = EngineType::ENGINE_VCS;
|
|
|
|
DebugManagerStateRestore dbgRestorer;
|
|
|
|
DebugManager.flags.NodeOrdinal.set(static_cast<int32_t>(expectedEngine));
|
|
|
|
auto pTestDevice = std::unique_ptr<Device>(createWithUsDeviceId(0));
|
|
|
|
|
|
|
|
EngineType actualEngineType = pTestDevice->getEngineType();
|
2018-07-25 23:12:44 +08:00
|
|
|
EngineType defaultEngineType = pDevice->getHardwareInfo().capabilityTable.defaultEngineType;
|
2018-02-12 18:48:31 +08:00
|
|
|
|
|
|
|
EXPECT_NE(defaultEngineType, actualEngineType);
|
|
|
|
EXPECT_EQ(expectedEngine, actualEngineType);
|
|
|
|
}
|
|
|
|
|
2018-03-09 21:48:42 +08:00
|
|
|
TEST(DeviceCleanup, givenDeviceWhenItIsDestroyedThenFlushBatchedSubmissionsIsCalled) {
|
2018-07-03 16:00:12 +08:00
|
|
|
auto mockDevice = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
|
2018-03-09 21:48:42 +08:00
|
|
|
MockCommandStreamReceiver *csr = new MockCommandStreamReceiver;
|
|
|
|
mockDevice->resetCommandStreamReceiver(csr);
|
|
|
|
int flushedBatchedSubmissionsCalledCount = 0;
|
|
|
|
csr->flushBatchedSubmissionsCallCounter = &flushedBatchedSubmissionsCalledCount;
|
|
|
|
mockDevice.reset(nullptr);
|
|
|
|
|
|
|
|
EXPECT_EQ(1, flushedBatchedSubmissionsCalledCount);
|
2018-03-30 02:37:43 +08:00
|
|
|
}
|
2018-06-06 16:34:51 +08:00
|
|
|
|
|
|
|
TEST(DeviceCreation, givenSelectedAubCsrInDebugVarsWhenDeviceIsCreatedThenIsSimulationReturnsTrue) {
|
|
|
|
DebugManagerStateRestore dbgRestorer;
|
|
|
|
DebugManager.flags.SetCommandStreamReceiver.set(CommandStreamReceiverType::CSR_AUB);
|
|
|
|
|
|
|
|
overrideCommandStreamReceiverCreation = true;
|
2018-07-03 16:00:12 +08:00
|
|
|
auto mockDevice = std::unique_ptr<Device>(MockDevice::createWithNewExecutionEnvironment<Device>(nullptr));
|
2018-06-06 16:34:51 +08:00
|
|
|
EXPECT_TRUE(mockDevice->isSimulation());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DeviceCreation, givenSelectedTbxCsrInDebugVarsWhenDeviceIsCreatedThenIsSimulationReturnsTrue) {
|
|
|
|
DebugManagerStateRestore dbgRestorer;
|
|
|
|
DebugManager.flags.SetCommandStreamReceiver.set(CommandStreamReceiverType::CSR_TBX);
|
|
|
|
|
|
|
|
overrideCommandStreamReceiverCreation = true;
|
2018-07-03 16:00:12 +08:00
|
|
|
auto device = std::unique_ptr<Device>(MockDevice::createWithNewExecutionEnvironment<Device>(nullptr));
|
2018-06-06 16:34:51 +08:00
|
|
|
EXPECT_TRUE(device->isSimulation());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DeviceCreation, givenSelectedTbxWithAubCsrInDebugVarsWhenDeviceIsCreatedThenIsSimulationReturnsTrue) {
|
|
|
|
DebugManagerStateRestore dbgRestorer;
|
|
|
|
DebugManager.flags.SetCommandStreamReceiver.set(CommandStreamReceiverType::CSR_TBX_WITH_AUB);
|
|
|
|
|
|
|
|
overrideCommandStreamReceiverCreation = true;
|
2018-07-03 16:00:12 +08:00
|
|
|
auto device = std::unique_ptr<Device>(MockDevice::createWithNewExecutionEnvironment<Device>(nullptr));
|
2018-06-06 16:34:51 +08:00
|
|
|
EXPECT_TRUE(device->isSimulation());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DeviceCreation, givenHwWithAubCsrInDebugVarsWhenDeviceIsCreatedThenIsSimulationReturnsFalse) {
|
|
|
|
DebugManagerStateRestore dbgRestorer;
|
|
|
|
DebugManager.flags.SetCommandStreamReceiver.set(CommandStreamReceiverType::CSR_HW_WITH_AUB);
|
|
|
|
|
2018-07-03 16:00:12 +08:00
|
|
|
auto device = std::unique_ptr<Device>(MockDevice::createWithNewExecutionEnvironment<Device>(nullptr));
|
2018-06-06 16:34:51 +08:00
|
|
|
EXPECT_FALSE(device->isSimulation());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DeviceCreation, givenDefaultHwCsrInDebugVarsWhenDeviceIsCreatedThenIsSimulationReturnsFalse) {
|
|
|
|
int32_t defaultHwCsr = CommandStreamReceiverType::CSR_HW;
|
|
|
|
EXPECT_EQ(defaultHwCsr, DebugManager.flags.SetCommandStreamReceiver.get());
|
|
|
|
|
2018-07-03 16:00:12 +08:00
|
|
|
auto device = std::unique_ptr<Device>(MockDevice::createWithNewExecutionEnvironment<Device>(nullptr));
|
2018-06-06 16:34:51 +08:00
|
|
|
EXPECT_FALSE(device->isSimulation());
|
|
|
|
}
|
2018-07-11 16:32:17 +08:00
|
|
|
|
|
|
|
TEST(DeviceCreation, givenFtrSimulationModeFlagTrueWhenNoOtherSimulationFlagsArePresentThenIsSimulationReturnsTrue) {
|
|
|
|
FeatureTable skuTable = *platformDevices[0]->pSkuTable;
|
|
|
|
skuTable.ftrSimulationMode = true;
|
|
|
|
|
|
|
|
HardwareInfo hwInfo = {platformDevices[0]->pPlatform, &skuTable, platformDevices[0]->pWaTable,
|
|
|
|
platformDevices[0]->pSysInfo, platformDevices[0]->capabilityTable};
|
|
|
|
|
|
|
|
int32_t defaultHwCsr = CommandStreamReceiverType::CSR_HW;
|
|
|
|
EXPECT_EQ(defaultHwCsr, DebugManager.flags.SetCommandStreamReceiver.get());
|
|
|
|
|
|
|
|
bool simulationFromDeviceId = hwInfo.capabilityTable.isSimulation(hwInfo.pPlatform->usDeviceID);
|
|
|
|
EXPECT_FALSE(simulationFromDeviceId);
|
|
|
|
|
|
|
|
auto device = std::unique_ptr<Device>(MockDevice::createWithNewExecutionEnvironment<Device>(&hwInfo));
|
|
|
|
EXPECT_TRUE(device->isSimulation());
|
|
|
|
}
|