Add tests for locking in trimResidency()

Change-Id: Iddbecedae9cf21a4e5232dcac5d145962623e7d6
Signed-off-by: Maciej Dziuban <maciej.dziuban@intel.com>
This commit is contained in:
Maciej Dziuban
2018-10-30 15:33:55 +01:00
committed by sys_ocldev
parent 53b32bc6ba
commit ef02827cd9
2 changed files with 38 additions and 1 deletions

View File

@@ -28,6 +28,13 @@ class MockWddmResidencyController : public WddmResidencyController {
using WddmResidencyController::trimResidency;
using WddmResidencyController::trimResidencyToBudget;
using WddmResidencyController::WddmResidencyController;
uint32_t acquireLockCallCount = 0u;
std::unique_lock<SpinLock> 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);
}