From 961ad2358f14da18fa93a8236c387983dfb3a6d7 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Thu, 12 Jan 2023 11:25:25 +0000 Subject: [PATCH] DawnTest: try to more robustly handle device lost. Deferred exepectations didn't handle device loss gracefully and would crash, which meant all future tests were skipped. Instead of crashing, skip the expectation, the test will fail anyway because the device was lost. Bug: None Change-Id: If143f00a5ed9d2ddd5a923da7c771b1f40d80962 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/116861 Commit-Queue: Corentin Wallez Reviewed-by: Loko Kung Kokoro: Kokoro --- src/dawn/tests/DawnTest.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/dawn/tests/DawnTest.cpp b/src/dawn/tests/DawnTest.cpp index 4466bc90be..ad1167da26 100644 --- a/src/dawn/tests/DawnTest.cpp +++ b/src/dawn/tests/DawnTest.cpp @@ -1454,14 +1454,19 @@ void DawnTestBase::MapSlotsSynchronously() { // static void DawnTestBase::SlotMapCallback(WGPUBufferMapAsyncStatus status, void* userdata_) { - DAWN_ASSERT(status == WGPUBufferMapAsyncStatus_Success); - + DAWN_ASSERT(status == WGPUBufferMapAsyncStatus_Success || + status == WGPUBufferMapAsyncStatus_DeviceLost); std::unique_ptr userdata(static_cast(userdata_)); DawnTestBase* test = userdata->test; - ReadbackSlot* slot = &test->mReadbackSlots[userdata->slot]; - - slot->mappedData = slot->buffer.GetConstMappedRange(); test->mNumPendingMapOperations--; + + ReadbackSlot* slot = &test->mReadbackSlots[userdata->slot]; + if (status == WGPUBufferMapAsyncStatus_Success) { + slot->mappedData = slot->buffer.GetConstMappedRange(); + ASSERT(slot->mappedData != nullptr); + } else { + slot->mappedData = nullptr; + } } void DawnTestBase::ResolveExpectations() { @@ -1471,6 +1476,13 @@ void DawnTestBase::ResolveExpectations() { // Get a pointer to the mapped copy of the data for the expectation. const char* data = static_cast(mReadbackSlots[expectation.readbackSlot].mappedData); + + // Handle the case where the device was lost so the expected data couldn't be read back. + if (data == nullptr) { + dawn::InfoLog() << "Skipping deferred expectation because the device was lost"; + continue; + } + data += expectation.readbackOffset; uint32_t size;