Skip to content

Commit 3a5227f

Browse files
Improve MockGmmMemory usage
Change-Id: I5edfe5a09c743d1672631a62be588e2aed55fd46
1 parent d1aaf2e commit 3a5227f

File tree

4 files changed

+13
-33
lines changed

4 files changed

+13
-33
lines changed

unit_tests/mocks/mock_gmm_memory.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,7 @@
2626
using namespace ::testing;
2727

2828
namespace OCLRT {
29-
30-
namespace MockGmmMemory {
31-
MockType MockGmmMemoryFlag = MockType::MockDummy;
32-
}
33-
3429
GmmMemory *GmmMemory::create() {
35-
if (MockGmmMemory::MockGmmMemoryFlag == MockGmmMemory::MockType::MockDummy) {
36-
return new MockGmmMemoryDummy();
37-
} else {
38-
GmockGmmMemory *gmmMemory = new NiceMock<GmockGmmMemory>();
39-
ON_CALL(*gmmMemory, getInternalGpuVaRangeLimit()).WillByDefault(::testing::Return(OCLRT::windowsMinAddress));
40-
return gmmMemory;
41-
}
30+
return new MockGmmMemory();
4231
}
43-
4432
} // namespace OCLRT

unit_tests/mocks/mock_gmm_memory.h

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,11 @@
2727

2828
namespace OCLRT {
2929

30-
namespace MockGmmMemory {
31-
enum MockType {
32-
MockDummy,
33-
MockInstrumentation
34-
};
35-
36-
extern MockType MockGmmMemoryFlag;
37-
} // namespace MockGmmMemory
38-
39-
class MockGmmMemoryDummy : public GmmMemory {
30+
class MockGmmMemory : public GmmMemory {
4031
public:
41-
~MockGmmMemoryDummy() = default;
32+
~MockGmmMemory() = default;
4233

43-
MockGmmMemoryDummy() = default;
34+
MockGmmMemory() = default;
4435

4536
bool configureDeviceAddressSpace(GMM_ESCAPE_HANDLE hAdapter,
4637
GMM_ESCAPE_HANDLE hDevice,
@@ -50,11 +41,11 @@ class MockGmmMemoryDummy : public GmmMemory {
5041
BOOLEAN SparseReady,
5142
BOOLEAN BDWL3Coherency,
5243
GMM_GFX_SIZE_T SizeOverride,
53-
GMM_GFX_SIZE_T SlmGfxSpaceReserve) {
44+
GMM_GFX_SIZE_T SlmGfxSpaceReserve) override {
5445
return true;
5546
}
5647

57-
uintptr_t getInternalGpuVaRangeLimit() {
48+
uintptr_t getInternalGpuVaRangeLimit() override {
5849
return OCLRT::windowsMinAddress;
5950
}
6051
};
@@ -76,6 +67,8 @@ class GmockGmmMemory : public GmmMemory {
7667
GMM_GFX_SIZE_T SizeOverride,
7768
GMM_GFX_SIZE_T SlmGfxSpaceReserve));
7869

79-
MOCK_METHOD0(getInternalGpuVaRangeLimit, uintptr_t());
70+
uintptr_t getInternalGpuVaRangeLimit() override {
71+
return OCLRT::windowsMinAddress;
72+
}
8073
};
8174
} // namespace OCLRT

unit_tests/mocks/mock_wddm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class WddmMock : public Wddm {
5353
using Wddm::device;
5454
using Wddm::gdi;
5555
using Wddm::getSystemInfo;
56+
using Wddm::gmmMemory;
5657
using Wddm::pagingQueue;
5758

5859
WddmMock() : Wddm(){};

unit_tests/os_interface/windows/wddm_fixture.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,11 @@ struct WddmFixtureWithMockGdiDll : public GdiDllFixture {
5656

5757
struct WddmInstrumentationGmmFixture {
5858
virtual void SetUp() {
59-
MockGmmMemory::MockGmmMemoryFlag = MockGmmMemory::MockType::MockInstrumentation;
6059
wddm.reset(static_cast<WddmMock *>(Wddm::createWddm()));
61-
gmmMem = static_cast<GmockGmmMemory *>(wddm->getGmmMemory());
62-
}
63-
virtual void TearDown() {
64-
MockGmmMemory::MockGmmMemoryFlag = MockGmmMemory::MockType::MockDummy;
60+
gmmMem = new ::testing::NiceMock<GmockGmmMemory>();
61+
wddm->gmmMemory.reset(gmmMem);
6562
}
63+
virtual void TearDown() {}
6664

6765
std::unique_ptr<WddmMock> wddm;
6866
GmockGmmMemory *gmmMem = nullptr;

0 commit comments

Comments
 (0)