Unit tests: Initialize gmm before wddm initialization

Change-Id: I751bd93248aa78731b9591f494eafcd12d3e6d82
This commit is contained in:
Mateusz Jablonski
2018-07-16 16:37:17 +02:00
committed by sys_ocldev
parent 70b1745c7a
commit 56557ca3a3
20 changed files with 156 additions and 90 deletions

View File

@@ -670,7 +670,8 @@ class DrmCommandStreamEnhancedFixture
DebugManagerStateRestore *dbgState;
void SetUp() {
ExecutionEnvironment *executionEnvironment = new ExecutionEnvironment;
executionEnvironment->initGmm(*platformDevices);
this->dbgState = new DebugManagerStateRestore();
//make sure this is disabled, we don't want test this now
DebugManager.flags.EnableForcePin.set(false);
@@ -681,7 +682,8 @@ class DrmCommandStreamEnhancedFixture
ASSERT_NE(nullptr, csr);
mm = reinterpret_cast<DrmMemoryManager *>(csr->createMemoryManager(false));
ASSERT_NE(nullptr, mm);
device = MockDevice::createWithMemoryManager<MockDevice>(platformDevices[0], mm);
executionEnvironment->memoryManager.reset(mm);
device = Device::create<MockDevice>(platformDevices[0], executionEnvironment);
ASSERT_NE(nullptr, device);
mm->device = device;
}

View File

@@ -1199,8 +1199,8 @@ TEST_F(DrmMemoryManagerTest, GivenMemoryManagerWhenAllocateGraphicsMemoryForImag
imgInfo.size = 4096u;
imgInfo.rowPitch = 512u;
ExecutionEnvironment execEnv;
execEnv.initGmm(*platformDevices);
ExecutionEnvironment executionEnvironment;
executionEnvironment.initGmm(*platformDevices);
auto queryGmm = MockGmm::queryImgParams(imgInfo);
auto imageGraphicsAllocation = memoryManager->allocateGraphicsMemoryForImage(imgInfo, queryGmm.get());
queryGmm.release();
@@ -1744,8 +1744,8 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenLockUnlockIsCalledOnAlloca
imgInfo.size = 4096u;
imgInfo.rowPitch = 512u;
ExecutionEnvironment execEnv;
execEnv.initGmm(*platformDevices);
ExecutionEnvironment executionEnvironment;
executionEnvironment.initGmm(*platformDevices);
auto queryGmm = MockGmm::queryImgParams(imgInfo);
auto allocation = memoryManager->allocateGraphicsMemoryForImage(imgInfo, queryGmm.get());
queryGmm.release();

View File

@@ -35,6 +35,7 @@
#include "runtime/os_interface/windows/wddm_device_command_stream.h"
#include "runtime/os_interface/windows/wddm_memory_manager.h"
#include "unit_tests/fixtures/gmm_environment_fixture.h"
#include "unit_tests/fixtures/memory_management_fixture.h"
#include "unit_tests/helpers/debug_manager_state_restore.h"
#include "unit_tests/mocks/mock_buffer.h"
@@ -56,29 +57,29 @@ using namespace ::testing;
class WddmCommandStreamFixture {
public:
DeviceCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME> *csr = nullptr;
MemoryManager *memManager = nullptr;
MockDevice *device = nullptr;
std::unique_ptr<MockDevice> device;
std::unique_ptr<MemoryManager> memManager;
std::unique_ptr<DeviceCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>> csr;
MockWddmMemoryManager *mockWddmMM = nullptr;
WddmMock *wddm = nullptr;
DebugManagerStateRestore stateRestore;
virtual void SetUp() {
device.reset(MockDevice::createWithNewExecutionEnvironment<MockDevice>(platformDevices[0]));
ASSERT_NE(nullptr, device);
wddm = static_cast<WddmMock *>(Wddm::createWddm(WddmInterfaceVersion::Wddm20));
ASSERT_NE(wddm, nullptr);
DebugManager.flags.CsrDispatchMode.set(static_cast<uint32_t>(DispatchMode::ImmediateDispatch));
csr = new WddmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>(*platformDevices[0], wddm);
csr.reset(new WddmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>(*platformDevices[0], wddm));
ASSERT_NE(nullptr, csr);
mockWddmMM = new MockWddmMemoryManager(wddm);
memManager = mockWddmMM;
csr->setMemoryManager(memManager);
memManager.reset(mockWddmMM);
csr->setMemoryManager(memManager.get());
device = MockDevice::createWithNewExecutionEnvironment<MockDevice>(platformDevices[0]);
ASSERT_NE(nullptr, device);
memManager->device = device;
memManager->device = device.get();
ASSERT_NE(nullptr, memManager);
}
@@ -86,9 +87,6 @@ class WddmCommandStreamFixture {
virtual void TearDown() {
mockWddmMM = nullptr;
delete csr->getTagAddress();
delete csr;
delete memManager;
delete device;
}
};
@@ -103,6 +101,8 @@ class WddmCommandStreamWithMockGdiFixture {
GraphicsAllocation *preemptionAllocation = nullptr;
virtual void SetUp() {
ExecutionEnvironment *executionEnvironment = new ExecutionEnvironment;
executionEnvironment->initGmm(*platformDevices);
wddm = static_cast<WddmMock *>(Wddm::createWddm(WddmInterfaceVersion::Wddm20));
gdi = new MockGdi();
wddm->gdi.reset(gdi);
@@ -113,10 +113,9 @@ class WddmCommandStreamWithMockGdiFixture {
memManager = csr->createMemoryManager(false);
ASSERT_NE(nullptr, memManager);
device = MockDevice::createWithMemoryManager<MockDevice>(platformDevices[0], memManager);
executionEnvironment->memoryManager.reset(memManager);
device = Device::create<MockDevice>(platformDevices[0], executionEnvironment);
ASSERT_NE(nullptr, device);
memManager->device = device;
if (device->getPreemptionMode() == PreemptionMode::MidThread) {
preemptionAllocation = memManager->allocateGraphicsMemory(1024);
}
@@ -132,18 +131,19 @@ class WddmCommandStreamWithMockGdiFixture {
}
};
typedef ::Test<WddmCommandStreamFixture> WddmCommandStreamTest;
typedef ::Test<WddmCommandStreamWithMockGdiFixture> WddmCommandStreamMockGdiTest;
typedef ::Test<WddmCommandStreamFixture> WddmDefaultTest;
using WddmCommandStreamTest = ::Test<WddmCommandStreamFixture>;
using WddmCommandStreamMockGdiTest = ::Test<WddmCommandStreamWithMockGdiFixture>;
using WddmDefaultTest = ::Test<WddmCommandStreamFixture>;
using DeviceCommandStreamTest = ::Test<GmmEnvironmentFixture>;
TEST(DeviceCommandStreamTest, CreateWddmCSR) {
TEST_F(DeviceCommandStreamTest, CreateWddmCSR) {
std::unique_ptr<DeviceCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>> csr(static_cast<DeviceCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME> *>(DeviceCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>::create(DEFAULT_TEST_PLATFORM::hwInfo, false)));
EXPECT_NE(nullptr, csr);
std::unique_ptr<Wddm> wddm(static_cast<WddmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME> *>(csr.get())->peekWddm());
EXPECT_NE(nullptr, wddm);
}
TEST(DeviceCommandStreamTest, CreateWddmCSRWithAubDump) {
TEST_F(DeviceCommandStreamTest, CreateWddmCSRWithAubDump) {
std::unique_ptr<DeviceCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>> csr(static_cast<DeviceCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME> *>(DeviceCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>::create(DEFAULT_TEST_PLATFORM::hwInfo, true)));
EXPECT_NE(nullptr, csr);
std::unique_ptr<Wddm> wddm(static_cast<WddmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME> *>(csr.get())->peekWddm());
@@ -434,7 +434,7 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllo
}
TEST_F(WddmCommandStreamTest, makeResident) {
WddmMemoryManager *wddmMM = reinterpret_cast<WddmMemoryManager *>(memManager);
WddmMemoryManager *wddmMM = reinterpret_cast<WddmMemoryManager *>(memManager.get());
GraphicsAllocation *commandBuffer = memManager->allocateGraphicsMemory(4096);
ASSERT_NE(nullptr, commandBuffer);
@@ -450,7 +450,7 @@ TEST_F(WddmCommandStreamTest, makeResident) {
}
TEST_F(WddmCommandStreamTest, makeNonResidentPutsAllocationInEvictionAllocations) {
WddmMemoryManager *wddmMM = reinterpret_cast<WddmMemoryManager *>(memManager);
WddmMemoryManager *wddmMM = reinterpret_cast<WddmMemoryManager *>(memManager.get());
GraphicsAllocation *commandBuffer = memManager->allocateGraphicsMemory(4096);
ASSERT_NE(nullptr, commandBuffer);
@@ -466,7 +466,7 @@ TEST_F(WddmCommandStreamTest, makeNonResidentPutsAllocationInEvictionAllocations
}
TEST_F(WddmCommandStreamTest, processEvictionPlacesAllAllocationsOnTrimCandidateList) {
WddmMemoryManager *wddmMM = reinterpret_cast<WddmMemoryManager *>(memManager);
WddmMemoryManager *wddmMM = reinterpret_cast<WddmMemoryManager *>(memManager.get());
GraphicsAllocation *allocation = memManager->allocateGraphicsMemory(4096);
GraphicsAllocation *allocation2 = memManager->allocateGraphicsMemory(4096);
@@ -487,7 +487,7 @@ TEST_F(WddmCommandStreamTest, processEvictionPlacesAllAllocationsOnTrimCandidate
}
TEST_F(WddmCommandStreamTest, processEvictionClearsEvictionAllocations) {
WddmMemoryManager *wddmMM = reinterpret_cast<WddmMemoryManager *>(memManager);
WddmMemoryManager *wddmMM = reinterpret_cast<WddmMemoryManager *>(memManager.get());
GraphicsAllocation *allocation = memManager->allocateGraphicsMemory(4096);
ASSERT_NE(nullptr, allocation);
@@ -506,7 +506,7 @@ TEST_F(WddmCommandStreamTest, processEvictionClearsEvictionAllocations) {
TEST_F(WddmCommandStreamTest, makeResidentNonResidentMemObj) {
GraphicsAllocation *gfxAllocation = memManager->allocateGraphicsMemory(256);
Buffer *buffer = new AlignedBuffer(gfxAllocation);
WddmMemoryManager *wddmMM = reinterpret_cast<WddmMemoryManager *>(memManager);
WddmMemoryManager *wddmMM = reinterpret_cast<WddmMemoryManager *>(memManager.get());
csr->makeResident(*buffer->getGraphicsAllocation());
EXPECT_EQ(0u, wddm->makeResidentResult.called);

View File

@@ -551,8 +551,8 @@ HWTEST_F(Wddm20InstrumentationTest, configureDeviceAddressSpaceOnInit) {
D3DKMT_HANDLE adapterHandle = ADAPTER_HANDLE;
D3DKMT_HANDLE deviceHandle = DEVICE_HANDLE;
const HardwareInfo hwInfo = *platformDevices[0];
ExecutionEnvironment execEnv;
execEnv.initGmm(&hwInfo);
ExecutionEnvironment executionEnvironment;
executionEnvironment.initGmm(&hwInfo);
BOOLEAN FtrL3IACoherency = hwInfo.pSkuTable->ftrL3IACoherency ? 1 : 0;
EXPECT_CALL(*gmmMem, configureDeviceAddressSpace(adapterHandle,
deviceHandle,
@@ -572,8 +572,8 @@ HWTEST_F(Wddm20InstrumentationTest, configureDeviceAddressSpaceOnInit) {
HWTEST_F(Wddm20InstrumentationTest, configureDeviceAddressSpaceNoAdapter) {
wddm->adapter = static_cast<D3DKMT_HANDLE>(0);
ExecutionEnvironment execEnv;
execEnv.initGmm(*platformDevices);
ExecutionEnvironment executionEnvironment;
executionEnvironment.initGmm(*platformDevices);
EXPECT_CALL(*gmmMem, configureDeviceAddressSpace(static_cast<D3DKMT_HANDLE>(0),
::testing::_,
::testing::_,
@@ -592,8 +592,8 @@ HWTEST_F(Wddm20InstrumentationTest, configureDeviceAddressSpaceNoAdapter) {
HWTEST_F(Wddm20InstrumentationTest, configureDeviceAddressSpaceNoDevice) {
wddm->device = static_cast<D3DKMT_HANDLE>(0);
ExecutionEnvironment execEnv;
execEnv.initGmm(*platformDevices);
ExecutionEnvironment executionEnvironment;
executionEnvironment.initGmm(*platformDevices);
EXPECT_CALL(*gmmMem, configureDeviceAddressSpace(::testing::_,
static_cast<D3DKMT_HANDLE>(0),
::testing::_,
@@ -612,8 +612,8 @@ HWTEST_F(Wddm20InstrumentationTest, configureDeviceAddressSpaceNoDevice) {
HWTEST_F(Wddm20InstrumentationTest, configureDeviceAddressSpaceNoEscFunc) {
wddm->gdi->escape = static_cast<PFND3DKMT_ESCAPE>(nullptr);
ExecutionEnvironment execEnv;
execEnv.initGmm(*platformDevices);
ExecutionEnvironment executionEnvironment;
executionEnvironment.initGmm(*platformDevices);
EXPECT_CALL(*gmmMem, configureDeviceAddressSpace(::testing::_,
::testing::_,
static_cast<PFND3DKMT_ESCAPE>(nullptr),

View File

@@ -22,6 +22,7 @@
#include "runtime/os_interface/windows/gdi_interface.h"
#include "runtime/os_interface/windows/wddm/wddm23.h"
#include "unit_tests/fixtures/gmm_environment_fixture.h"
#include "unit_tests/helpers/debug_manager_state_restore.h"
#include "unit_tests/mocks/mock_wddm23.h"
#include "unit_tests/os_interface/windows/gdi_dll_fixture.h"
@@ -29,8 +30,9 @@
using namespace OCLRT;
struct Wddm23Tests : public ::testing::Test, GdiDllFixture {
struct Wddm23Tests : public ::testing::Test, GdiDllFixture, public GmmEnvironmentFixture {
void SetUp() override {
GmmEnvironmentFixture::SetUp();
GdiDllFixture::SetUp();
wddm.reset(static_cast<WddmMock23 *>(Wddm::createWddm(WddmInterfaceVersion::Wddm23)));
wddm->registryReader.reset(new RegistryReaderMock());
@@ -38,6 +40,7 @@ struct Wddm23Tests : public ::testing::Test, GdiDllFixture {
void TearDown() override {
GdiDllFixture::TearDown();
GmmEnvironmentFixture::TearDown();
}
std::unique_ptr<WddmMock23> wddm;

View File

@@ -20,6 +20,7 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "unit_tests/fixtures/gmm_environment_fixture.h"
#include "unit_tests/mocks/mock_wddm20.h"
#include "test.h"
@@ -67,7 +68,7 @@ class WddmMockReserveAddress : public WddmMock {
uint32_t returnNullIter = 0;
};
using WddmReserveAddressTest = ::testing::Test;
using WddmReserveAddressTest = Test<GmmEnvironmentFixture>;
HWTEST_F(WddmReserveAddressTest, givenWddmWhenFirstIsSuccessfulThenReturnReserveAddress) {
std::unique_ptr<WddmMockReserveAddress> wddm(new WddmMockReserveAddress());

View File

@@ -23,6 +23,7 @@
#pragma once
#include "runtime/os_interface/windows/gdi_interface.h"
#include "unit_tests/fixtures/gmm_environment_fixture.h"
#include "unit_tests/mocks/mock_wddm20.h"
#include "unit_tests/os_interface/windows/mock_gdi_interface.h"
#include "unit_tests/os_interface/windows/gdi_dll_fixture.h"
@@ -30,46 +31,54 @@
#include "test.h"
namespace OCLRT {
struct WddmFixture {
virtual void SetUp() {
struct WddmFixture : public GmmEnvironmentFixture {
void SetUp() override {
GmmEnvironmentFixture::SetUp();
wddm.reset(static_cast<WddmMock *>(Wddm::createWddm(WddmInterfaceVersion::Wddm20)));
gdi = new MockGdi();
wddm->gdi.reset(gdi);
}
virtual void TearDown(){};
void TearDown() override {
GmmEnvironmentFixture::TearDown();
};
std::unique_ptr<WddmMock> wddm;
MockGdi *gdi = nullptr;
};
struct WddmFixtureWithMockGdiDll : public GdiDllFixture {
struct WddmFixtureWithMockGdiDll : public GmmEnvironmentFixture, public GdiDllFixture {
void SetUp() override {
GmmEnvironmentFixture::SetUp();
GdiDllFixture::SetUp();
wddm.reset(static_cast<WddmMock *>(Wddm::createWddm(WddmInterfaceVersion::Wddm20)));
}
void TearDown() override {
GdiDllFixture::TearDown();
GmmEnvironmentFixture::TearDown();
}
std::unique_ptr<WddmMock> wddm;
};
struct WddmInstrumentationGmmFixture {
virtual void SetUp() {
struct WddmInstrumentationGmmFixture : public GmmEnvironmentFixture {
void SetUp() override {
GmmEnvironmentFixture::SetUp();
wddm.reset(static_cast<WddmMock *>(Wddm::createWddm(WddmInterfaceVersion::Wddm20)));
gmmMem = new ::testing::NiceMock<GmockGmmMemory>();
wddm->gmmMemory.reset(gmmMem);
}
virtual void TearDown() {}
void TearDown() override {
GmmEnvironmentFixture::TearDown();
}
std::unique_ptr<WddmMock> wddm;
GmockGmmMemory *gmmMem = nullptr;
};
typedef Test<WddmFixture> WddmTest;
typedef Test<WddmFixtureWithMockGdiDll> WddmTestWithMockGdiDll;
typedef Test<WddmInstrumentationGmmFixture> WddmInstrumentationTest;
typedef ::testing::Test WddmTestSingle;
using WddmTest = Test<WddmFixture>;
using WddmTestWithMockGdiDll = Test<WddmFixtureWithMockGdiDll>;
using WddmInstrumentationTest = Test<WddmInstrumentationGmmFixture>;
using WddmTestSingle = ::testing::Test;
} // namespace OCLRT

View File

@@ -24,6 +24,7 @@
#include "runtime/gmm_helper/gmm_helper.h"
#include "runtime/os_interface/windows/wddm/wddm.h"
#include "runtime/os_interface/windows/wddm_allocation.h"
#include "unit_tests/fixtures/gmm_environment_fixture.h"
#include "unit_tests/os_interface/windows/mock_kmdaf_listener.h"
#include "unit_tests/os_interface/windows/mock_gdi_interface.h"
#include "unit_tests/os_interface/windows/mock_wddm_allocation.h"
@@ -53,14 +54,18 @@ class WddmWithKmDafMock : public Wddm {
};
};
class WddmKmDafListenerTest : public ::testing::Test {
class WddmKmDafListenerTest : public GmmEnvironmentFixture, public ::testing::Test {
public:
void SetUp() {
GmmEnvironmentFixture::SetUp();
wddmWithKmDafMock.reset(new WddmWithKmDafMock());
wddmWithKmDafMock->gdi.reset(new MockGdi());
wddmWithKmDafMock->init<DEFAULT_TEST_FAMILY_NAME>();
wddmWithKmDafMock->getFeatureTable()->ftrKmdDaf = true;
}
void TearDown() {
GmmEnvironmentFixture::TearDown();
}
std::unique_ptr<WddmWithKmDafMock> wddmWithKmDafMock;
};

View File

@@ -36,6 +36,7 @@ using namespace OCLRT;
using namespace ::testing;
void WddmMemoryManagerFixture::SetUp() {
GmmEnvironmentFixture::SetUp();
GdiDllFixture::SetUp();
wddm = static_cast<WddmMock *>(Wddm::createWddm(WddmInterfaceVersion::Wddm20));
ASSERT_NE(nullptr, wddm);

View File

@@ -26,6 +26,7 @@
#include "gmock/gmock.h"
#include "test.h"
#include "unit_tests/fixtures/gmm_environment_fixture.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/mocks/mock_gmm_page_table_mngr.h"
#include "unit_tests/mocks/mock_gmm.h"
@@ -37,10 +38,15 @@
using namespace OCLRT;
using namespace ::testing;
class WddmMemoryManagerFixture : public GdiDllFixture {
class WddmMemoryManagerFixture : public GmmEnvironmentFixture, public GdiDllFixture {
public:
void SetUp() override;
void TearDown() override {
GdiDllFixture::TearDown();
GmmEnvironmentFixture::TearDown();
}
template <typename FamiltyType>
void SetUpMm() {
EXPECT_TRUE(wddm->init<FamiltyType>());
@@ -60,9 +66,10 @@ class WddmMemoryManagerFixture : public GdiDllFixture {
typedef ::Test<WddmMemoryManagerFixture> WddmMemoryManagerTest;
class MockWddmMemoryManagerFixture {
class MockWddmMemoryManagerFixture : public GmmEnvironmentFixture {
public:
void SetUp() {
GmmEnvironmentFixture::SetUp();
wddm = static_cast<WddmMock *>(Wddm::createWddm(WddmInterfaceVersion::Wddm20));
gdi = new MockGdi();
wddm->gdi.reset(gdi);
@@ -81,7 +88,9 @@ class MockWddmMemoryManagerFixture {
ASSERT_NE(nullptr, memoryManager);
}
virtual void TearDown() {}
void TearDown() {
GmmEnvironmentFixture::TearDown();
}
std::unique_ptr<MockWddmMemoryManager> memoryManager;
WddmMock *wddm = nullptr;
MockGdi *gdi = nullptr;
@@ -118,11 +127,12 @@ class GmockWddm : public Wddm {
}
};
class WddmMemoryManagerFixtureWithGmockWddm {
class WddmMemoryManagerFixtureWithGmockWddm : public GmmEnvironmentFixture {
public:
MockWddmMemoryManager *memoryManager = nullptr;
void SetUp() {
GmmEnvironmentFixture::SetUp();
// wddm is deleted by memory manager
wddm = new NiceMock<GmockWddm>;
ASSERT_NE(nullptr, wddm);
@@ -140,6 +150,7 @@ class WddmMemoryManagerFixtureWithGmockWddm {
void TearDown() {
delete memoryManager;
wddm = nullptr;
GmmEnvironmentFixture::TearDown();
}
NiceMock<GmockWddm> *wddm;
@@ -193,6 +204,5 @@ class WddmMemoryManagerSimpleTest : public MockWddmMemoryManagerFixture, public
}
};
typedef ::testing::Test MockWddmMemoryManagerTest;
typedef MockWddmMemoryManagerTest OsAgnosticMemoryManagerUsingWddmTest;
using MockWddmMemoryManagerTest = ::Test<GmmEnvironmentFixture>;
using OsAgnosticMemoryManagerUsingWddmTest = MockWddmMemoryManagerTest;