From 115d700f49364c19b015ad3c837e0f5fba2b57fc Mon Sep 17 00:00:00 2001 From: Mateusz Hoppe Date: Wed, 10 Apr 2019 14:32:41 +0200 Subject: [PATCH] Add getter in Drm for memoryInfo Related-To: NEO-3014 Change-Id: I56c0e13b88d27f7c6b3816bf24342cdb04108dac Signed-off-by: Mateusz Hoppe --- runtime/os_interface/linux/drm_neo.h | 4 ++++ .../linux/drm_memory_info_tests.cpp | 19 ++++++++++++++----- unit_tests/os_interface/linux/drm_mock.h | 3 ++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/runtime/os_interface/linux/drm_neo.h b/runtime/os_interface/linux/drm_neo.h index f1dc8cf140..7d0fb9a673 100644 --- a/runtime/os_interface/linux/drm_neo.h +++ b/runtime/os_interface/linux/drm_neo.h @@ -72,6 +72,10 @@ class Drm { bool getSimplifiedMocsTableUsage() const; void queryMemoryInfo(); + MemoryInfo *getMemoryInfo() { + return memoryInfo.get(); + } + protected: bool useSimplifiedMocsTable = false; bool preemptionSupported = false; diff --git a/unit_tests/os_interface/linux/drm_memory_info_tests.cpp b/unit_tests/os_interface/linux/drm_memory_info_tests.cpp index bc0b8abfc8..5a9c66862f 100644 --- a/unit_tests/os_interface/linux/drm_memory_info_tests.cpp +++ b/unit_tests/os_interface/linux/drm_memory_info_tests.cpp @@ -12,6 +12,11 @@ using namespace NEO; +struct MemoryInfoImpl : public NEO::MemoryInfo { + MemoryInfoImpl() {} + ~MemoryInfoImpl() override{}; +}; + TEST(DrmTest, whenQueryingMemoryInfoThenMemoryInfoIsNotCreatedAndNoIoctlIsCalled) { std::unique_ptr drm = std::make_unique(); EXPECT_NE(nullptr, drm); @@ -22,11 +27,15 @@ TEST(DrmTest, whenQueryingMemoryInfoThenMemoryInfoIsNotCreatedAndNoIoctlIsCalled EXPECT_EQ(0u, drm->ioctlCallsCount); } -TEST(MemoryInfo, givenMemoryInfoImplementationWhenDestructingThenDestructorIsCalled) { - struct MemoryInfoImpl : public NEO::MemoryInfo { - MemoryInfoImpl() {} - ~MemoryInfoImpl() override{}; - }; +TEST(DrmTest, givenMemoryInfoWhenGetMemoryInfoIsCalledThenValidPtrIsReturned) { + std::unique_ptr drm = std::make_unique(); + EXPECT_NE(nullptr, drm); + drm->memoryInfo.reset(new MemoryInfoImpl); + + EXPECT_EQ(drm->memoryInfo.get(), drm->getMemoryInfo()); +} + +TEST(MemoryInfo, givenMemoryInfoImplementationWhenDestructingThenDestructorIsCalled) { MemoryInfoImpl memoryInfoImpl; } diff --git a/unit_tests/os_interface/linux/drm_mock.h b/unit_tests/os_interface/linux/drm_mock.h index ddaf767491..8a0a064483 100644 --- a/unit_tests/os_interface/linux/drm_mock.h +++ b/unit_tests/os_interface/linux/drm_mock.h @@ -23,7 +23,6 @@ using namespace NEO; #define I915_PARAM_HAS_PREEMPTION 0x806 #endif -static const int mockFd = 33; // Mock DRM class that responds to DRM_IOCTL_I915_GETPARAMs class DrmMock : public Drm { public: @@ -222,6 +221,8 @@ class DrmMock : public Drm { void setDeviceID(int deviceId) { this->deviceId = deviceId; } void setDeviceRevID(int revisionId) { this->revisionId = revisionId; } + static const int mockFd = 33; + int StoredEUVal = -1; int StoredSSVal = -1; int StoredDeviceID = 1;