LoseForTesting can only be called once

Bug: chromium:1061878, dawn:68
Change-Id: Ieb35bdefc22299f828fe21e43d85fefabf500e27
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17140
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Natasha Lee <natlee@microsoft.com>
This commit is contained in:
Natasha Lee 2020-03-17 15:03:18 +00:00 committed by Commit Bot service account
parent 1f0596818d
commit 31eacb90f1
2 changed files with 16 additions and 0 deletions

View File

@ -196,6 +196,10 @@ namespace dawn_native {
}
void DeviceBase::LoseForTesting() {
if (mLossStatus == LossStatus::AlreadyLost) {
return;
}
mLossStatus = LossStatus::BeingLost;
// Assert that errors are device loss so that we can continue with destruction
AssertAndIgnoreDeviceLossError(WaitForIdleForDestruction());

View File

@ -459,4 +459,16 @@ TEST_P(DeviceLostTest, FenceSignalTickOnCompletion) {
EXPECT_EQ(fence.GetCompletedValue(), 2u);
}
// Test that LostForTesting can only be called on one time
TEST_P(DeviceLostTest, LoseForTestingOnce) {
// First LoseForTesting call should occur normally
SetCallbackAndLoseForTesting();
// Second LoseForTesting call should result in no callbacks. The LoseForTesting will return
// without doing anything when it sees that device has already been lost.
device.SetDeviceLostCallback(ToMockDeviceLostCallback, this);
EXPECT_CALL(*mockDeviceLostCallback, Call(_, this)).Times(0);
device.LoseForTesting();
}
DAWN_INSTANTIATE_TEST(DeviceLostTest, D3D12Backend(), VulkanBackend());