DawnTest: Make error/device loss mocks StrictMocks

Any unhandled error or device loss in the tests that are not expected
should cause a test failure. Mocks other than StrictMock will not cause
a failure and instead just write to stdout (or not write at all).

Fixed: dawn:1412
Change-Id: I2dd108da8fa6ba2cd7967790de4d7fa4b9f821ae
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/89600
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Loko Kung <lokokung@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Corentin Wallez 2022-05-10 17:06:34 +00:00 committed by Dawn LUCI CQ
parent 636e3d0111
commit a439e7b89c
2 changed files with 21 additions and 19 deletions

View File

@ -955,10 +955,17 @@ std::pair<wgpu::Device, WGPUDevice> DawnTestBase::CreateDeviceImpl(std::string i
auto devices = mWireHelper->RegisterDevice(mBackendAdapter.CreateDevice(&deviceDescriptor));
wgpu::Device device = devices.first;
// Set up the mocks for uncaptured errors and device loss. The loss of the device is expected
// to happen at the end of the test so at it directly.
device.SetUncapturedErrorCallback(mDeviceErrorCallback.Callback(),
mDeviceErrorCallback.MakeUserdata(device.Get()));
device.SetDeviceLostCallback(mDeviceLostCallback.Callback(),
mDeviceLostCallback.MakeUserdata(device.Get()));
EXPECT_CALL(mDeviceLostCallback,
Call(WGPUDeviceLostReason_Destroyed, testing::_, device.Get()))
.Times(testing::AtMost(1));
device.SetLoggingCallback(
[](WGPULoggingType type, char const* message, void*) {
switch (type) {
@ -977,6 +984,7 @@ std::pair<wgpu::Device, WGPUDevice> DawnTestBase::CreateDeviceImpl(std::string i
}
},
nullptr);
return devices;
}
@ -1050,33 +1058,26 @@ void DawnTestBase::TearDown() {
}
void DawnTestBase::DestroyDevice(wgpu::Device device) {
wgpu::Device resolvedDevice;
if (device != nullptr) {
resolvedDevice = device;
} else {
wgpu::Device resolvedDevice = device;
if (resolvedDevice == nullptr) {
resolvedDevice = this->device;
}
EXPECT_CALL(mDeviceLostCallback,
Call(WGPUDeviceLostReason_Destroyed, testing::_, resolvedDevice.Get()))
.Times(1);
// No expectation is added because the expectations for this kind of destruction is set up as
// soon as the device is created.
resolvedDevice.Destroy();
FlushWire();
testing::Mock::VerifyAndClearExpectations(&mDeviceLostCallback);
}
void DawnTestBase::LoseDeviceForTesting(wgpu::Device device) {
wgpu::Device resolvedDevice;
if (device != nullptr) {
resolvedDevice = device;
} else {
wgpu::Device resolvedDevice = device;
if (resolvedDevice == nullptr) {
resolvedDevice = this->device;
}
EXPECT_CALL(mDeviceLostCallback,
Call(WGPUDeviceLostReason_Undefined, testing::_, resolvedDevice.Get()))
.Times(1);
resolvedDevice.LoseForTesting();
FlushWire();
testing::Mock::VerifyAndClearExpectations(&mDeviceLostCallback);
}
std::ostringstream& DawnTestBase::AddBufferExpectation(const char* file,

View File

@ -351,10 +351,11 @@ class DawnTestBase {
size_t mLastWarningCount = 0;
// Mock callbacks tracking errors and destruction. Device lost is a nice mock since tests that
// do not care about device destruction can ignore the callback entirely.
testing::MockCallback<WGPUErrorCallback> mDeviceErrorCallback;
testing::MockCallback<WGPUDeviceLostCallback> mDeviceLostCallback;
// Mock callbacks tracking errors and destruction. These are strict mocks because any errors or
// device loss that aren't expected should result in test failures and not just some warnings
// printed to stdout.
testing::StrictMock<testing::MockCallback<WGPUErrorCallback>> mDeviceErrorCallback;
testing::StrictMock<testing::MockCallback<WGPUDeviceLostCallback>> mDeviceLostCallback;
// Helper methods to implement the EXPECT_ macros
std::ostringstream& AddBufferExpectation(const char* file,