mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-20 02:15:43 +00:00
Make unittests and fuzzers use webgpu.h
BUG=dawn:22 Change-Id: Iff5465ad7a9456f9c6b2ee380af748b3afc129b7 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/12741 Commit-Queue: Kai Ninomiya <kainino@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
cab352c2f6
commit
45b51f5df7
@@ -20,11 +20,11 @@ using namespace testing;
|
||||
|
||||
class MockDevicePopErrorScopeCallback {
|
||||
public:
|
||||
MOCK_METHOD3(Call, void(DawnErrorType type, const char* message, void* userdata));
|
||||
MOCK_METHOD3(Call, void(WGPUErrorType type, const char* message, void* userdata));
|
||||
};
|
||||
|
||||
static std::unique_ptr<MockDevicePopErrorScopeCallback> mockDevicePopErrorScopeCallback;
|
||||
static void ToMockDevicePopErrorScopeCallback(DawnErrorType type,
|
||||
static void ToMockDevicePopErrorScopeCallback(WGPUErrorType type,
|
||||
const char* message,
|
||||
void* userdata) {
|
||||
mockDevicePopErrorScopeCallback->Call(type, message, userdata);
|
||||
@@ -46,73 +46,71 @@ class ErrorScopeValidationTest : public ValidationTest {
|
||||
|
||||
// Test the simple success case.
|
||||
TEST_F(ErrorScopeValidationTest, Success) {
|
||||
device.PushErrorScope(dawn::ErrorFilter::Validation);
|
||||
device.PushErrorScope(wgpu::ErrorFilter::Validation);
|
||||
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(DAWN_ERROR_TYPE_NO_ERROR, _, this)).Times(1);
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(WGPUErrorType_NoError, _, this)).Times(1);
|
||||
device.PopErrorScope(ToMockDevicePopErrorScopeCallback, this);
|
||||
}
|
||||
|
||||
// Test the simple case where the error scope catches an error.
|
||||
TEST_F(ErrorScopeValidationTest, CatchesError) {
|
||||
device.PushErrorScope(dawn::ErrorFilter::Validation);
|
||||
device.PushErrorScope(wgpu::ErrorFilter::Validation);
|
||||
|
||||
dawn::BufferDescriptor desc = {};
|
||||
desc.usage = static_cast<dawn::BufferUsage>(DAWN_BUFFER_USAGE_FORCE32);
|
||||
wgpu::BufferDescriptor desc = {};
|
||||
desc.usage = static_cast<wgpu::BufferUsage>(WGPUBufferUsage_Force32);
|
||||
device.CreateBuffer(&desc);
|
||||
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(DAWN_ERROR_TYPE_VALIDATION, _, this))
|
||||
.Times(1);
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(WGPUErrorType_Validation, _, this)).Times(1);
|
||||
device.PopErrorScope(ToMockDevicePopErrorScopeCallback, this);
|
||||
}
|
||||
|
||||
// Test that errors bubble to the parent scope if not handled by the current scope.
|
||||
TEST_F(ErrorScopeValidationTest, ErrorBubbles) {
|
||||
device.PushErrorScope(dawn::ErrorFilter::Validation);
|
||||
device.PushErrorScope(dawn::ErrorFilter::OutOfMemory);
|
||||
device.PushErrorScope(wgpu::ErrorFilter::Validation);
|
||||
device.PushErrorScope(wgpu::ErrorFilter::OutOfMemory);
|
||||
|
||||
dawn::BufferDescriptor desc = {};
|
||||
desc.usage = static_cast<dawn::BufferUsage>(DAWN_BUFFER_USAGE_FORCE32);
|
||||
wgpu::BufferDescriptor desc = {};
|
||||
desc.usage = static_cast<wgpu::BufferUsage>(WGPUBufferUsage_Force32);
|
||||
device.CreateBuffer(&desc);
|
||||
|
||||
// OutOfMemory does not match Validation error.
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(DAWN_ERROR_TYPE_NO_ERROR, _, this)).Times(1);
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(WGPUErrorType_NoError, _, this)).Times(1);
|
||||
device.PopErrorScope(ToMockDevicePopErrorScopeCallback, this);
|
||||
|
||||
// Parent validation error scope captures the error.
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(DAWN_ERROR_TYPE_VALIDATION, _, this + 1))
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(WGPUErrorType_Validation, _, this + 1))
|
||||
.Times(1);
|
||||
device.PopErrorScope(ToMockDevicePopErrorScopeCallback, this + 1);
|
||||
}
|
||||
|
||||
// Test that if an error scope matches an error, it does not bubble to the parent scope.
|
||||
TEST_F(ErrorScopeValidationTest, HandledErrorsStopBubbling) {
|
||||
device.PushErrorScope(dawn::ErrorFilter::OutOfMemory);
|
||||
device.PushErrorScope(dawn::ErrorFilter::Validation);
|
||||
device.PushErrorScope(wgpu::ErrorFilter::OutOfMemory);
|
||||
device.PushErrorScope(wgpu::ErrorFilter::Validation);
|
||||
|
||||
dawn::BufferDescriptor desc = {};
|
||||
desc.usage = static_cast<dawn::BufferUsage>(DAWN_BUFFER_USAGE_FORCE32);
|
||||
wgpu::BufferDescriptor desc = {};
|
||||
desc.usage = static_cast<wgpu::BufferUsage>(WGPUBufferUsage_Force32);
|
||||
device.CreateBuffer(&desc);
|
||||
|
||||
// Inner scope catches the error.
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(DAWN_ERROR_TYPE_VALIDATION, _, this))
|
||||
.Times(1);
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(WGPUErrorType_Validation, _, this)).Times(1);
|
||||
device.PopErrorScope(ToMockDevicePopErrorScopeCallback, this);
|
||||
|
||||
// Parent scope does not see the error.
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(DAWN_ERROR_TYPE_NO_ERROR, _, this + 1))
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(WGPUErrorType_NoError, _, this + 1))
|
||||
.Times(1);
|
||||
device.PopErrorScope(ToMockDevicePopErrorScopeCallback, this + 1);
|
||||
}
|
||||
|
||||
// Test that if no error scope handles an error, it goes to the device UncapturedError callback
|
||||
TEST_F(ErrorScopeValidationTest, UnhandledErrorsMatchUncapturedErrorCallback) {
|
||||
device.PushErrorScope(dawn::ErrorFilter::OutOfMemory);
|
||||
device.PushErrorScope(wgpu::ErrorFilter::OutOfMemory);
|
||||
|
||||
dawn::BufferDescriptor desc = {};
|
||||
desc.usage = static_cast<dawn::BufferUsage>(DAWN_BUFFER_USAGE_FORCE32);
|
||||
wgpu::BufferDescriptor desc = {};
|
||||
desc.usage = static_cast<wgpu::BufferUsage>(WGPUBufferUsage_Force32);
|
||||
ASSERT_DEVICE_ERROR(device.CreateBuffer(&desc));
|
||||
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(DAWN_ERROR_TYPE_NO_ERROR, _, this)).Times(1);
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(WGPUErrorType_NoError, _, this)).Times(1);
|
||||
device.PopErrorScope(ToMockDevicePopErrorScopeCallback, this);
|
||||
}
|
||||
|
||||
@@ -123,9 +121,9 @@ TEST_F(ErrorScopeValidationTest, PushPopBalanced) {
|
||||
|
||||
// Too many pops
|
||||
{
|
||||
device.PushErrorScope(dawn::ErrorFilter::Validation);
|
||||
device.PushErrorScope(wgpu::ErrorFilter::Validation);
|
||||
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(DAWN_ERROR_TYPE_NO_ERROR, _, this + 1))
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(WGPUErrorType_NoError, _, this + 1))
|
||||
.Times(1);
|
||||
device.PopErrorScope(ToMockDevicePopErrorScopeCallback, this + 1);
|
||||
|
||||
@@ -136,13 +134,13 @@ TEST_F(ErrorScopeValidationTest, PushPopBalanced) {
|
||||
// Test that error scopes do not call their callbacks until after an enclosed Queue::Submit
|
||||
// completes
|
||||
TEST_F(ErrorScopeValidationTest, CallbackAfterQueueSubmit) {
|
||||
dawn::Queue queue = device.CreateQueue();
|
||||
wgpu::Queue queue = device.CreateQueue();
|
||||
|
||||
device.PushErrorScope(dawn::ErrorFilter::OutOfMemory);
|
||||
device.PushErrorScope(wgpu::ErrorFilter::OutOfMemory);
|
||||
queue.Submit(0, nullptr);
|
||||
device.PopErrorScope(ToMockDevicePopErrorScopeCallback, this);
|
||||
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(DAWN_ERROR_TYPE_NO_ERROR, _, this)).Times(1);
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(WGPUErrorType_NoError, _, this)).Times(1);
|
||||
|
||||
// Side effects of Queue::Submit only are seen after Tick()
|
||||
device.Tick();
|
||||
@@ -151,16 +149,16 @@ TEST_F(ErrorScopeValidationTest, CallbackAfterQueueSubmit) {
|
||||
// Test that parent error scopes do not call their callbacks until after an enclosed Queue::Submit
|
||||
// completes
|
||||
TEST_F(ErrorScopeValidationTest, CallbackAfterQueueSubmitNested) {
|
||||
dawn::Queue queue = device.CreateQueue();
|
||||
wgpu::Queue queue = device.CreateQueue();
|
||||
|
||||
device.PushErrorScope(dawn::ErrorFilter::OutOfMemory);
|
||||
device.PushErrorScope(dawn::ErrorFilter::OutOfMemory);
|
||||
device.PushErrorScope(wgpu::ErrorFilter::OutOfMemory);
|
||||
device.PushErrorScope(wgpu::ErrorFilter::OutOfMemory);
|
||||
queue.Submit(0, nullptr);
|
||||
device.PopErrorScope(ToMockDevicePopErrorScopeCallback, this);
|
||||
device.PopErrorScope(ToMockDevicePopErrorScopeCallback, this + 1);
|
||||
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(DAWN_ERROR_TYPE_NO_ERROR, _, this)).Times(1);
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(DAWN_ERROR_TYPE_NO_ERROR, _, this + 1))
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(WGPUErrorType_NoError, _, this)).Times(1);
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(WGPUErrorType_NoError, _, this + 1))
|
||||
.Times(1);
|
||||
|
||||
// Side effects of Queue::Submit only are seen after Tick()
|
||||
@@ -169,18 +167,18 @@ TEST_F(ErrorScopeValidationTest, CallbackAfterQueueSubmitNested) {
|
||||
|
||||
// Test a callback that returns asynchronously followed by a synchronous one
|
||||
TEST_F(ErrorScopeValidationTest, AsynchronousThenSynchronous) {
|
||||
dawn::Queue queue = device.CreateQueue();
|
||||
wgpu::Queue queue = device.CreateQueue();
|
||||
|
||||
device.PushErrorScope(dawn::ErrorFilter::OutOfMemory);
|
||||
device.PushErrorScope(wgpu::ErrorFilter::OutOfMemory);
|
||||
queue.Submit(0, nullptr);
|
||||
device.PopErrorScope(ToMockDevicePopErrorScopeCallback, this);
|
||||
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(DAWN_ERROR_TYPE_NO_ERROR, _, this + 1))
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(WGPUErrorType_NoError, _, this + 1))
|
||||
.Times(1);
|
||||
device.PushErrorScope(dawn::ErrorFilter::OutOfMemory);
|
||||
device.PushErrorScope(wgpu::ErrorFilter::OutOfMemory);
|
||||
device.PopErrorScope(ToMockDevicePopErrorScopeCallback, this + 1);
|
||||
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(DAWN_ERROR_TYPE_NO_ERROR, _, this)).Times(1);
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(WGPUErrorType_NoError, _, this)).Times(1);
|
||||
|
||||
// Side effects of Queue::Submit only are seen after Tick()
|
||||
device.Tick();
|
||||
@@ -188,12 +186,12 @@ TEST_F(ErrorScopeValidationTest, AsynchronousThenSynchronous) {
|
||||
|
||||
// Test that if the device is destroyed before the callback occurs, it is called with UNKNOWN.
|
||||
TEST_F(ErrorScopeValidationTest, DeviceDestroyedBeforeCallback) {
|
||||
dawn::Queue queue = device.CreateQueue();
|
||||
wgpu::Queue queue = device.CreateQueue();
|
||||
|
||||
device.PushErrorScope(dawn::ErrorFilter::OutOfMemory);
|
||||
device.PushErrorScope(wgpu::ErrorFilter::OutOfMemory);
|
||||
queue.Submit(0, nullptr);
|
||||
device.PopErrorScope(ToMockDevicePopErrorScopeCallback, this);
|
||||
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(DAWN_ERROR_TYPE_UNKNOWN, _, this)).Times(1);
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(WGPUErrorType_Unknown, _, this)).Times(1);
|
||||
device = nullptr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user