From ef02827cd9c46297cc920d0300402989e62a9042 Mon Sep 17 00:00:00 2001 From: Maciej Dziuban Date: Tue, 30 Oct 2018 15:33:55 +0100 Subject: [PATCH] Add tests for locking in trimResidency() Change-Id: Iddbecedae9cf21a4e5232dcac5d145962623e7d6 Signed-off-by: Maciej Dziuban --- .../windows/wddm_residency_controller.h | 2 +- .../wddm_residency_controller_tests.cpp | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/runtime/os_interface/windows/wddm_residency_controller.h b/runtime/os_interface/windows/wddm_residency_controller.h index 56926403cd..bbe076c7f6 100644 --- a/runtime/os_interface/windows/wddm_residency_controller.h +++ b/runtime/os_interface/windows/wddm_residency_controller.h @@ -25,7 +25,7 @@ class WddmResidencyController { public: WddmResidencyController(Wddm &wddm, uint32_t osContextId); - std::unique_lock acquireLock(); + MOCKABLE_VIRTUAL std::unique_lock acquireLock(); std::unique_lock acquireTrimCallbackLock(); WddmAllocation *getTrimCandidateHead(); diff --git a/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp b/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp index 60fa357bbd..05f33e7090 100644 --- a/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp @@ -28,6 +28,13 @@ class MockWddmResidencyController : public WddmResidencyController { using WddmResidencyController::trimResidency; using WddmResidencyController::trimResidencyToBudget; using WddmResidencyController::WddmResidencyController; + + uint32_t acquireLockCallCount = 0u; + + std::unique_lock acquireLock() override { + acquireLockCallCount++; + return WddmResidencyController::acquireLock(); + } }; struct WddmResidencyControllerTest : ::testing::Test { @@ -690,3 +697,33 @@ TEST_F(WddmResidencyControllerWithGdiTest, givenThreeAllocationsAlignedSizeBigge EXPECT_FALSE(allocation2.getResidencyData().resident); EXPECT_TRUE(allocation3.getResidencyData().resident); } + +using WddmResidencyControllerLockTest = WddmResidencyControllerWithGdiTest; + +TEST_F(WddmResidencyControllerLockTest, givenPeriodicTrimWhenTrimmingResidencyThenLockOnce) { + D3DKMT_TRIMNOTIFICATION trimNotification = {0}; + trimNotification.Flags.PeriodicTrim = 1; + trimNotification.NumBytesToTrim = 0; + + residencyController->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim); + EXPECT_EQ(1, residencyController->acquireLockCallCount); +} + +TEST_F(WddmResidencyControllerLockTest, givenTrimToBudgetWhenTrimmingResidencyThenLockOnce) { + D3DKMT_TRIMNOTIFICATION trimNotification = {0}; + trimNotification.Flags.TrimToBudget = 1; + trimNotification.NumBytesToTrim = 0; + + residencyController->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim); + EXPECT_EQ(1, residencyController->acquireLockCallCount); +} + +TEST_F(WddmResidencyControllerLockTest, givenPeriodicTrimAndTrimToBudgetWhenTrimmingResidencyThenLockTwice) { + D3DKMT_TRIMNOTIFICATION trimNotification = {0}; + trimNotification.Flags.PeriodicTrim = 1; + trimNotification.Flags.TrimToBudget = 1; + trimNotification.NumBytesToTrim = 0; + + residencyController->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim); + EXPECT_EQ(2, residencyController->acquireLockCallCount); +}