Skip to content

Commit ef02827

Browse files
Add tests for locking in trimResidency()
Change-Id: Iddbecedae9cf21a4e5232dcac5d145962623e7d6 Signed-off-by: Maciej Dziuban <maciej.dziuban@intel.com>
1 parent 53b32bc commit ef02827

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

runtime/os_interface/windows/wddm_residency_controller.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class WddmResidencyController {
2525
public:
2626
WddmResidencyController(Wddm &wddm, uint32_t osContextId);
2727

28-
std::unique_lock<SpinLock> acquireLock();
28+
MOCKABLE_VIRTUAL std::unique_lock<SpinLock> acquireLock();
2929
std::unique_lock<SpinLock> acquireTrimCallbackLock();
3030

3131
WddmAllocation *getTrimCandidateHead();

unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ class MockWddmResidencyController : public WddmResidencyController {
2828
using WddmResidencyController::trimResidency;
2929
using WddmResidencyController::trimResidencyToBudget;
3030
using WddmResidencyController::WddmResidencyController;
31+
32+
uint32_t acquireLockCallCount = 0u;
33+
34+
std::unique_lock<SpinLock> acquireLock() override {
35+
acquireLockCallCount++;
36+
return WddmResidencyController::acquireLock();
37+
}
3138
};
3239

3340
struct WddmResidencyControllerTest : ::testing::Test {
@@ -690,3 +697,33 @@ TEST_F(WddmResidencyControllerWithGdiTest, givenThreeAllocationsAlignedSizeBigge
690697
EXPECT_FALSE(allocation2.getResidencyData().resident);
691698
EXPECT_TRUE(allocation3.getResidencyData().resident);
692699
}
700+
701+
using WddmResidencyControllerLockTest = WddmResidencyControllerWithGdiTest;
702+
703+
TEST_F(WddmResidencyControllerLockTest, givenPeriodicTrimWhenTrimmingResidencyThenLockOnce) {
704+
D3DKMT_TRIMNOTIFICATION trimNotification = {0};
705+
trimNotification.Flags.PeriodicTrim = 1;
706+
trimNotification.NumBytesToTrim = 0;
707+
708+
residencyController->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim);
709+
EXPECT_EQ(1, residencyController->acquireLockCallCount);
710+
}
711+
712+
TEST_F(WddmResidencyControllerLockTest, givenTrimToBudgetWhenTrimmingResidencyThenLockOnce) {
713+
D3DKMT_TRIMNOTIFICATION trimNotification = {0};
714+
trimNotification.Flags.TrimToBudget = 1;
715+
trimNotification.NumBytesToTrim = 0;
716+
717+
residencyController->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim);
718+
EXPECT_EQ(1, residencyController->acquireLockCallCount);
719+
}
720+
721+
TEST_F(WddmResidencyControllerLockTest, givenPeriodicTrimAndTrimToBudgetWhenTrimmingResidencyThenLockTwice) {
722+
D3DKMT_TRIMNOTIFICATION trimNotification = {0};
723+
trimNotification.Flags.PeriodicTrim = 1;
724+
trimNotification.Flags.TrimToBudget = 1;
725+
trimNotification.NumBytesToTrim = 0;
726+
727+
residencyController->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim);
728+
EXPECT_EQ(2, residencyController->acquireLockCallCount);
729+
}

0 commit comments

Comments
 (0)