mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-17 00:47:13 +00:00
Nuke Builders Part 1: remove the testing BufferBuilder.
This requires deleting wire tests for builders that were using it, and leads to small simplifications in the WireTest harness. Also allows removing the BuilderBase class from dawn_native. BUG=dawn:125 Change-Id: I3cbac609207aa652cdc9d37e0b700cce3ac6e093 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/6120 Reviewed-by: Kai Ninomiya <kainino@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
f856903154
commit
0ae00a187d
@@ -21,7 +21,7 @@ using namespace dawn_wire;
|
||||
|
||||
class WireArgumentTests : public WireTest {
|
||||
public:
|
||||
WireArgumentTests() : WireTest(true) {
|
||||
WireArgumentTests() {
|
||||
}
|
||||
~WireArgumentTests() override = default;
|
||||
};
|
||||
|
||||
@@ -19,7 +19,7 @@ using namespace dawn_wire;
|
||||
|
||||
class WireBasicTests : public WireTest {
|
||||
public:
|
||||
WireBasicTests() : WireTest(true) {
|
||||
WireBasicTests() {
|
||||
}
|
||||
~WireBasicTests() override = default;
|
||||
};
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace {
|
||||
|
||||
class WireBufferMappingTests : public WireTest {
|
||||
public:
|
||||
WireBufferMappingTests() : WireTest(true) {
|
||||
WireBufferMappingTests() {
|
||||
}
|
||||
~WireBufferMappingTests() override = default;
|
||||
|
||||
|
||||
@@ -1,251 +0,0 @@
|
||||
// Copyright 2019 The Dawn Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "tests/unittests/wire/WireTest.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace dawn_wire;
|
||||
|
||||
namespace {
|
||||
|
||||
// Mock classes to add expectations on the wire calling callbacks
|
||||
class MockDeviceErrorCallback {
|
||||
public:
|
||||
MOCK_METHOD2(Call, void(const char* message, DawnCallbackUserdata userdata));
|
||||
};
|
||||
|
||||
std::unique_ptr<StrictMock<MockDeviceErrorCallback>> mockDeviceErrorCallback;
|
||||
void ToMockDeviceErrorCallback(const char* message, DawnCallbackUserdata userdata) {
|
||||
mockDeviceErrorCallback->Call(message, userdata);
|
||||
}
|
||||
|
||||
class MockBuilderErrorCallback {
|
||||
public:
|
||||
MOCK_METHOD4(Call,
|
||||
void(DawnBuilderErrorStatus status,
|
||||
const char* message,
|
||||
DawnCallbackUserdata userdata1,
|
||||
DawnCallbackUserdata userdata2));
|
||||
};
|
||||
|
||||
std::unique_ptr<StrictMock<MockBuilderErrorCallback>> mockBuilderErrorCallback;
|
||||
void ToMockBuilderErrorCallback(DawnBuilderErrorStatus status,
|
||||
const char* message,
|
||||
DawnCallbackUserdata userdata1,
|
||||
DawnCallbackUserdata userdata2) {
|
||||
mockBuilderErrorCallback->Call(status, message, userdata1, userdata2);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
class WireCallbackTests : public WireTest {
|
||||
public:
|
||||
WireCallbackTests() : WireTest(true) {
|
||||
}
|
||||
~WireCallbackTests() override = default;
|
||||
|
||||
void SetUp() override {
|
||||
WireTest::SetUp();
|
||||
|
||||
mockDeviceErrorCallback = std::make_unique<StrictMock<MockDeviceErrorCallback>>();
|
||||
mockBuilderErrorCallback = std::make_unique<StrictMock<MockBuilderErrorCallback>>();
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
WireTest::TearDown();
|
||||
|
||||
mockDeviceErrorCallback = nullptr;
|
||||
mockBuilderErrorCallback = nullptr;
|
||||
}
|
||||
|
||||
void FlushServer() {
|
||||
WireTest::FlushServer();
|
||||
|
||||
Mock::VerifyAndClearExpectations(&mockDeviceErrorCallback);
|
||||
Mock::VerifyAndClearExpectations(&mockBuilderErrorCallback);
|
||||
}
|
||||
};
|
||||
|
||||
// Test that we get a success builder error status when no error happens
|
||||
TEST_F(WireCallbackTests, SuccessCallbackOnBuilderSuccess) {
|
||||
DawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
|
||||
dawnBufferBuilderSetErrorCallback(bufferBuilder, ToMockBuilderErrorCallback, 1, 2);
|
||||
dawnBufferBuilderGetResult(bufferBuilder);
|
||||
|
||||
DawnBufferBuilder apiBufferBuilder = api.GetNewBufferBuilder();
|
||||
EXPECT_CALL(api, DeviceCreateBufferBuilderForTesting(apiDevice))
|
||||
.WillOnce(Return(apiBufferBuilder));
|
||||
|
||||
DawnBuffer apiBuffer = api.GetNewBuffer();
|
||||
EXPECT_CALL(api, BufferBuilderGetResult(apiBufferBuilder))
|
||||
.WillOnce(InvokeWithoutArgs([&]() -> DawnBuffer {
|
||||
api.CallBuilderErrorCallback(apiBufferBuilder, DAWN_BUILDER_ERROR_STATUS_SUCCESS,
|
||||
"I like cheese");
|
||||
return apiBuffer;
|
||||
}));
|
||||
|
||||
FlushClient();
|
||||
|
||||
EXPECT_CALL(*mockBuilderErrorCallback, Call(DAWN_BUILDER_ERROR_STATUS_SUCCESS, _, 1, 2));
|
||||
|
||||
FlushServer();
|
||||
}
|
||||
|
||||
// Test that the client calls the builder callback with unknown when it HAS to fire the callback but
|
||||
// can't know the status yet.
|
||||
TEST_F(WireCallbackTests, UnknownBuilderErrorStatusCallback) {
|
||||
// The builder is destroyed before the object is built
|
||||
{
|
||||
DawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
|
||||
dawnBufferBuilderSetErrorCallback(bufferBuilder, ToMockBuilderErrorCallback, 1, 2);
|
||||
|
||||
EXPECT_CALL(*mockBuilderErrorCallback, Call(DAWN_BUILDER_ERROR_STATUS_UNKNOWN, _, 1, 2))
|
||||
.Times(1);
|
||||
|
||||
dawnBufferBuilderRelease(bufferBuilder);
|
||||
}
|
||||
|
||||
// If the builder has been consumed, it doesn't fire the callback with unknown
|
||||
{
|
||||
DawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
|
||||
dawnBufferBuilderSetErrorCallback(bufferBuilder, ToMockBuilderErrorCallback, 3, 4);
|
||||
dawnBufferBuilderGetResult(bufferBuilder);
|
||||
|
||||
EXPECT_CALL(*mockBuilderErrorCallback, Call(DAWN_BUILDER_ERROR_STATUS_UNKNOWN, _, 3, 4))
|
||||
.Times(0);
|
||||
|
||||
dawnBufferBuilderRelease(bufferBuilder);
|
||||
}
|
||||
|
||||
// If the builder has been consumed, and the object is destroyed before the result comes from
|
||||
// the server, then the callback is fired with unknown
|
||||
{
|
||||
DawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
|
||||
dawnBufferBuilderSetErrorCallback(bufferBuilder, ToMockBuilderErrorCallback, 5, 6);
|
||||
DawnBuffer buffer = dawnBufferBuilderGetResult(bufferBuilder);
|
||||
|
||||
EXPECT_CALL(*mockBuilderErrorCallback, Call(DAWN_BUILDER_ERROR_STATUS_UNKNOWN, _, 5, 6))
|
||||
.Times(1);
|
||||
|
||||
dawnBufferRelease(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
// Test that a builder success status doesn't get forwarded to the device
|
||||
TEST_F(WireCallbackTests, SuccessCallbackNotForwardedToDevice) {
|
||||
dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, 0);
|
||||
|
||||
DawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
|
||||
dawnBufferBuilderGetResult(bufferBuilder);
|
||||
|
||||
DawnBufferBuilder apiBufferBuilder = api.GetNewBufferBuilder();
|
||||
EXPECT_CALL(api, DeviceCreateBufferBuilderForTesting(apiDevice))
|
||||
.WillOnce(Return(apiBufferBuilder));
|
||||
|
||||
DawnBuffer apiBuffer = api.GetNewBuffer();
|
||||
EXPECT_CALL(api, BufferBuilderGetResult(apiBufferBuilder))
|
||||
.WillOnce(InvokeWithoutArgs([&]() -> DawnBuffer {
|
||||
api.CallBuilderErrorCallback(apiBufferBuilder, DAWN_BUILDER_ERROR_STATUS_SUCCESS,
|
||||
"I like cheese");
|
||||
return apiBuffer;
|
||||
}));
|
||||
|
||||
FlushClient();
|
||||
FlushServer();
|
||||
}
|
||||
|
||||
// Test that a builder error status gets forwarded to the device
|
||||
TEST_F(WireCallbackTests, ErrorCallbackForwardedToDevice) {
|
||||
uint64_t userdata = 30495;
|
||||
dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, userdata);
|
||||
|
||||
DawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
|
||||
dawnBufferBuilderGetResult(bufferBuilder);
|
||||
|
||||
DawnBufferBuilder apiBufferBuilder = api.GetNewBufferBuilder();
|
||||
EXPECT_CALL(api, DeviceCreateBufferBuilderForTesting(apiDevice))
|
||||
.WillOnce(Return(apiBufferBuilder));
|
||||
|
||||
EXPECT_CALL(api, BufferBuilderGetResult(apiBufferBuilder))
|
||||
.WillOnce(InvokeWithoutArgs([&]() -> DawnBuffer {
|
||||
api.CallBuilderErrorCallback(apiBufferBuilder, DAWN_BUILDER_ERROR_STATUS_ERROR,
|
||||
"Error :(");
|
||||
return nullptr;
|
||||
}));
|
||||
|
||||
FlushClient();
|
||||
|
||||
EXPECT_CALL(*mockDeviceErrorCallback, Call(_, userdata)).Times(1);
|
||||
|
||||
FlushServer();
|
||||
}
|
||||
|
||||
// Test the return wire for device error callbacks
|
||||
TEST_F(WireCallbackTests, DeviceErrorCallback) {
|
||||
uint64_t userdata = 3049785;
|
||||
dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, userdata);
|
||||
|
||||
// Setting the error callback should stay on the client side and do nothing
|
||||
FlushClient();
|
||||
|
||||
// Calling the callback on the server side will result in the callback being called on the
|
||||
// client side
|
||||
api.CallDeviceErrorCallback(apiDevice, "Some error message");
|
||||
|
||||
EXPECT_CALL(*mockDeviceErrorCallback, Call(StrEq("Some error message"), userdata)).Times(1);
|
||||
|
||||
FlushServer();
|
||||
}
|
||||
|
||||
// Test the return wire for device error callbacks
|
||||
TEST_F(WireCallbackTests, BuilderErrorCallback) {
|
||||
uint64_t userdata1 = 982734;
|
||||
uint64_t userdata2 = 982734239028;
|
||||
|
||||
// Create the buffer builder, the callback is set immediately on the server side
|
||||
DawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
|
||||
|
||||
DawnBufferBuilder apiBufferBuilder = api.GetNewBufferBuilder();
|
||||
EXPECT_CALL(api, DeviceCreateBufferBuilderForTesting(apiDevice))
|
||||
.WillOnce(Return(apiBufferBuilder));
|
||||
|
||||
EXPECT_CALL(api, OnBuilderSetErrorCallback(apiBufferBuilder, _, _, _)).Times(1);
|
||||
|
||||
FlushClient();
|
||||
|
||||
// Setting the callback on the client side doesn't do anything on the server side
|
||||
dawnBufferBuilderSetErrorCallback(bufferBuilder, ToMockBuilderErrorCallback, userdata1,
|
||||
userdata2);
|
||||
FlushClient();
|
||||
|
||||
// Create an object so that it is a valid case to call the error callback
|
||||
dawnBufferBuilderGetResult(bufferBuilder);
|
||||
|
||||
DawnBuffer apiBuffer = api.GetNewBuffer();
|
||||
EXPECT_CALL(api, BufferBuilderGetResult(apiBufferBuilder))
|
||||
.WillOnce(InvokeWithoutArgs([&]() -> DawnBuffer {
|
||||
api.CallBuilderErrorCallback(apiBufferBuilder, DAWN_BUILDER_ERROR_STATUS_SUCCESS,
|
||||
"Success!");
|
||||
return apiBuffer;
|
||||
}));
|
||||
|
||||
FlushClient();
|
||||
|
||||
// The error callback gets called on the client side
|
||||
EXPECT_CALL(*mockBuilderErrorCallback,
|
||||
Call(DAWN_BUILDER_ERROR_STATUS_SUCCESS, StrEq("Success!"), userdata1, userdata2))
|
||||
.Times(1);
|
||||
|
||||
FlushServer();
|
||||
}
|
||||
75
src/tests/unittests/wire/WireErrorCallbackTests.cpp
Normal file
75
src/tests/unittests/wire/WireErrorCallbackTests.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
// Copyright 2019 The Dawn Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "tests/unittests/wire/WireTest.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace dawn_wire;
|
||||
|
||||
namespace {
|
||||
|
||||
// Mock classes to add expectations on the wire calling callbacks
|
||||
class MockDeviceErrorCallback {
|
||||
public:
|
||||
MOCK_METHOD2(Call, void(const char* message, DawnCallbackUserdata userdata));
|
||||
};
|
||||
|
||||
std::unique_ptr<StrictMock<MockDeviceErrorCallback>> mockDeviceErrorCallback;
|
||||
void ToMockDeviceErrorCallback(const char* message, DawnCallbackUserdata userdata) {
|
||||
mockDeviceErrorCallback->Call(message, userdata);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
class WireErrorCallbackTests : public WireTest {
|
||||
public:
|
||||
WireErrorCallbackTests() {
|
||||
}
|
||||
~WireErrorCallbackTests() override = default;
|
||||
|
||||
void SetUp() override {
|
||||
WireTest::SetUp();
|
||||
|
||||
mockDeviceErrorCallback = std::make_unique<StrictMock<MockDeviceErrorCallback>>();
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
WireTest::TearDown();
|
||||
|
||||
mockDeviceErrorCallback = nullptr;
|
||||
}
|
||||
|
||||
void FlushServer() {
|
||||
WireTest::FlushServer();
|
||||
|
||||
Mock::VerifyAndClearExpectations(&mockDeviceErrorCallback);
|
||||
}
|
||||
};
|
||||
|
||||
// Test the return wire for device error callbacks
|
||||
TEST_F(WireErrorCallbackTests, DeviceErrorCallback) {
|
||||
uint64_t userdata = 3049785;
|
||||
dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, userdata);
|
||||
|
||||
// Setting the error callback should stay on the client side and do nothing
|
||||
FlushClient();
|
||||
|
||||
// Calling the callback on the server side will result in the callback being called on the
|
||||
// client side
|
||||
api.CallDeviceErrorCallback(apiDevice, "Some error message");
|
||||
|
||||
EXPECT_CALL(*mockDeviceErrorCallback, Call(StrEq("Some error message"), userdata)).Times(1);
|
||||
|
||||
FlushServer();
|
||||
}
|
||||
@@ -45,7 +45,7 @@ namespace {
|
||||
|
||||
class WireFenceTests : public WireTest {
|
||||
public:
|
||||
WireFenceTests() : WireTest(true) {
|
||||
WireFenceTests() {
|
||||
}
|
||||
~WireFenceTests() override = default;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ using namespace dawn_wire;
|
||||
|
||||
class WireInjectTextureTests : public WireTest {
|
||||
public:
|
||||
WireInjectTextureTests() : WireTest(true) {
|
||||
WireInjectTextureTests() {
|
||||
}
|
||||
~WireInjectTextureTests() override = default;
|
||||
};
|
||||
|
||||
@@ -19,7 +19,7 @@ using namespace dawn_wire;
|
||||
|
||||
class WireOptionalTests : public WireTest {
|
||||
public:
|
||||
WireOptionalTests() : WireTest(true) {
|
||||
WireOptionalTests() {
|
||||
}
|
||||
~WireOptionalTests() override = default;
|
||||
};
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
using namespace testing;
|
||||
using namespace dawn_wire;
|
||||
|
||||
WireTest::WireTest(bool ignoreSetCallbackCalls) : mIgnoreSetCallbackCalls(ignoreSetCallbackCalls) {
|
||||
WireTest::WireTest() {
|
||||
}
|
||||
|
||||
WireTest::~WireTest() {
|
||||
@@ -87,8 +87,5 @@ void WireTest::DeleteServer() {
|
||||
}
|
||||
|
||||
void WireTest::SetupIgnoredCallExpectations() {
|
||||
if (mIgnoreSetCallbackCalls) {
|
||||
EXPECT_CALL(api, OnBuilderSetErrorCallback(_, _, _, _)).Times(AnyNumber());
|
||||
}
|
||||
EXPECT_CALL(api, DeviceTick(_)).Times(AnyNumber());
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace utils {
|
||||
|
||||
class WireTest : public testing::Test {
|
||||
protected:
|
||||
WireTest(bool ignoreSetCallbackCalls);
|
||||
WireTest();
|
||||
~WireTest() override;
|
||||
|
||||
void SetUp() override;
|
||||
@@ -96,7 +96,6 @@ class WireTest : public testing::Test {
|
||||
|
||||
private:
|
||||
void SetupIgnoredCallExpectations();
|
||||
bool mIgnoreSetCallbackCalls = false;
|
||||
|
||||
std::unique_ptr<dawn_wire::WireServer> mWireServer;
|
||||
std::unique_ptr<dawn_wire::WireClient> mWireClient;
|
||||
|
||||
Reference in New Issue
Block a user