Add wire tests and mocks for the MemoryTransferService

This CL tests integration of the MemoryTransferService with buffer mapping.
It tests the basic success and error cases for buffer mapping, and it tests
mocked failures of each fallible MemoryTransferService method that an embedder
could implement.

Change-Id: Iece660fb49664cc6a09a0b0b8dbe59e2882a6017
Bug: dawn:156
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/8841
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Austin Eng 2019-07-19 16:16:58 +00:00 committed by Commit Bot service account
parent 6a5418a760
commit 72724b8d25
8 changed files with 1504 additions and 6 deletions

View File

@ -577,6 +577,12 @@ test("dawn_unittests") {
configs += [ ":libdawn_native_internal" ] configs += [ ":libdawn_native_internal" ]
sources = get_target_outputs(":mock_dawn_gen") sources = get_target_outputs(":mock_dawn_gen")
sources += [
"src/dawn_wire/client/ClientMemoryTransferService_mock.cpp",
"src/dawn_wire/client/ClientMemoryTransferService_mock.h",
"src/dawn_wire/server/ServerMemoryTransferService_mock.cpp",
"src/dawn_wire/server/ServerMemoryTransferService_mock.h",
]
sources += [ sources += [
"src/tests/unittests/BitSetIteratorTests.cpp", "src/tests/unittests/BitSetIteratorTests.cpp",
"src/tests/unittests/CommandAllocatorTests.cpp", "src/tests/unittests/CommandAllocatorTests.cpp",
@ -620,6 +626,7 @@ test("dawn_unittests") {
"src/tests/unittests/wire/WireErrorCallbackTests.cpp", "src/tests/unittests/wire/WireErrorCallbackTests.cpp",
"src/tests/unittests/wire/WireFenceTests.cpp", "src/tests/unittests/wire/WireFenceTests.cpp",
"src/tests/unittests/wire/WireInjectTextureTests.cpp", "src/tests/unittests/wire/WireInjectTextureTests.cpp",
"src/tests/unittests/wire/WireMemoryTransferServiceTests.cpp",
"src/tests/unittests/wire/WireOptionalTests.cpp", "src/tests/unittests/wire/WireOptionalTests.cpp",
"src/tests/unittests/wire/WireTest.cpp", "src/tests/unittests/wire/WireTest.cpp",
"src/tests/unittests/wire/WireTest.h", "src/tests/unittests/wire/WireTest.h",

View File

@ -0,0 +1,86 @@
// 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 "dawn_wire/client/ClientMemoryTransferService_mock.h"
#include <cstdio>
#include "common/Assert.h"
namespace dawn_wire { namespace client {
MockMemoryTransferService::MockReadHandle::MockReadHandle(MockMemoryTransferService* service)
: ReadHandle(), mService(service) {
}
MockMemoryTransferService::MockReadHandle::~MockReadHandle() {
mService->OnReadHandleDestroy(this);
}
size_t MockMemoryTransferService::MockReadHandle::SerializeCreate(void* serializePointer) {
return mService->OnReadHandleSerializeCreate(this, serializePointer);
}
bool MockMemoryTransferService::MockReadHandle::DeserializeInitialData(
const void* deserializePointer,
size_t deserializeSize,
const void** data,
size_t* dataLength) {
ASSERT(deserializeSize % sizeof(uint32_t) == 0);
return mService->OnReadHandleDeserializeInitialData(
this, reinterpret_cast<const uint32_t*>(deserializePointer), deserializeSize, data,
dataLength);
}
MockMemoryTransferService::MockWriteHandle::MockWriteHandle(MockMemoryTransferService* service)
: WriteHandle(), mService(service) {
}
MockMemoryTransferService::MockWriteHandle::~MockWriteHandle() {
mService->OnWriteHandleDestroy(this);
}
size_t MockMemoryTransferService::MockWriteHandle::SerializeCreate(void* serializePointer) {
return mService->OnWriteHandleSerializeCreate(this, serializePointer);
}
std::pair<void*, size_t> MockMemoryTransferService::MockWriteHandle::Open() {
return mService->OnWriteHandleOpen(this);
}
size_t MockMemoryTransferService::MockWriteHandle::SerializeFlush(void* serializePointer) {
return mService->OnWriteHandleSerializeFlush(this, serializePointer);
}
MockMemoryTransferService::MockMemoryTransferService() = default;
MockMemoryTransferService::~MockMemoryTransferService() = default;
MockMemoryTransferService::ReadHandle* MockMemoryTransferService::CreateReadHandle(
size_t size) {
return OnCreateReadHandle(size);
}
MockMemoryTransferService::WriteHandle* MockMemoryTransferService::CreateWriteHandle(
size_t size) {
return OnCreateWriteHandle(size);
}
MockMemoryTransferService::MockReadHandle* MockMemoryTransferService::NewReadHandle() {
return new MockReadHandle(this);
}
MockMemoryTransferService::MockWriteHandle* MockMemoryTransferService::NewWriteHandle() {
return new MockWriteHandle(this);
}
}} // namespace dawn_wire::client

View File

@ -0,0 +1,87 @@
// 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.
#ifndef DAWNWIRE_CLIENT_CLIENTMEMORYTRANSFERSERVICE_MOCK_H_
#define DAWNWIRE_CLIENT_CLIENTMEMORYTRANSFERSERVICE_MOCK_H_
#include <gmock/gmock.h>
#include "dawn_wire/WireClient.h"
#include "dawn_wire/client/Client.h"
namespace dawn_wire { namespace client {
class MockMemoryTransferService : public MemoryTransferService {
public:
class MockReadHandle : public ReadHandle {
public:
explicit MockReadHandle(MockMemoryTransferService* service);
~MockReadHandle() override;
size_t SerializeCreate(void* serializePointer) override;
bool DeserializeInitialData(const void* deserializePointer,
size_t deserializeSize,
const void** data,
size_t* dataLength) override;
private:
MockMemoryTransferService* mService;
};
class MockWriteHandle : public WriteHandle {
public:
explicit MockWriteHandle(MockMemoryTransferService* service);
~MockWriteHandle() override;
size_t SerializeCreate(void* serializePointer) override;
std::pair<void*, size_t> Open() override;
size_t SerializeFlush(void* serializePointer) override;
private:
MockMemoryTransferService* mService;
};
MockMemoryTransferService();
~MockMemoryTransferService() override;
ReadHandle* CreateReadHandle(size_t) override;
WriteHandle* CreateWriteHandle(size_t) override;
MockReadHandle* NewReadHandle();
MockWriteHandle* NewWriteHandle();
MOCK_METHOD1(OnCreateReadHandle, ReadHandle*(size_t));
MOCK_METHOD1(OnCreateWriteHandle, WriteHandle*(size_t));
MOCK_METHOD2(OnReadHandleSerializeCreate,
size_t(const ReadHandle*, void* serializePointer));
MOCK_METHOD5(OnReadHandleDeserializeInitialData,
bool(const ReadHandle*,
const uint32_t* deserializePointer,
size_t deserializeSize,
const void** data,
size_t* dataLength));
MOCK_METHOD1(OnReadHandleDestroy, void(const ReadHandle*));
MOCK_METHOD2(OnWriteHandleSerializeCreate,
size_t(const void* WriteHandle, void* serializePointer));
MOCK_METHOD1(OnWriteHandleOpen, std::pair<void*, size_t>(const void* WriteHandle));
MOCK_METHOD2(OnWriteHandleSerializeFlush,
size_t(const void* WriteHandle, void* serializePointer));
MOCK_METHOD1(OnWriteHandleDestroy, void(const void* WriteHandle));
};
}} // namespace dawn_wire::client
#endif // DAWNWIRE_CLIENT_CLIENTMEMORYTRANSFERSERVICE_MOCK_H_

View File

@ -0,0 +1,82 @@
// 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 "dawn_wire/server/ServerMemoryTransferService_mock.h"
#include "common/Assert.h"
namespace dawn_wire { namespace server {
MockMemoryTransferService::MockReadHandle::MockReadHandle(MockMemoryTransferService* service)
: ReadHandle(), mService(service) {
}
MockMemoryTransferService::MockReadHandle::~MockReadHandle() {
mService->OnReadHandleDestroy(this);
}
size_t MockMemoryTransferService::MockReadHandle::SerializeInitialData(const void* data,
size_t dataLength,
void* serializePointer) {
return mService->OnReadHandleSerializeInitialData(this, data, dataLength, serializePointer);
}
MockMemoryTransferService::MockWriteHandle::MockWriteHandle(MockMemoryTransferService* service)
: WriteHandle(), mService(service) {
}
MockMemoryTransferService::MockWriteHandle::~MockWriteHandle() {
mService->OnWriteHandleDestroy(this);
}
bool MockMemoryTransferService::MockWriteHandle::DeserializeFlush(
const void* deserializePointer,
size_t deserializeSize) {
ASSERT(deserializeSize % sizeof(uint32_t) == 0);
return mService->OnWriteHandleDeserializeFlush(
this, reinterpret_cast<const uint32_t*>(deserializePointer), deserializeSize);
}
const uint32_t* MockMemoryTransferService::MockWriteHandle::GetData() const {
return reinterpret_cast<const uint32_t*>(mTargetData);
}
MockMemoryTransferService::MockMemoryTransferService() = default;
MockMemoryTransferService::~MockMemoryTransferService() = default;
bool MockMemoryTransferService::DeserializeReadHandle(const void* deserializePointer,
size_t deserializeSize,
ReadHandle** readHandle) {
ASSERT(deserializeSize % sizeof(uint32_t) == 0);
return OnDeserializeReadHandle(reinterpret_cast<const uint32_t*>(deserializePointer),
deserializeSize, readHandle);
}
bool MockMemoryTransferService::DeserializeWriteHandle(const void* deserializePointer,
size_t deserializeSize,
WriteHandle** writeHandle) {
ASSERT(deserializeSize % sizeof(uint32_t) == 0);
return OnDeserializeWriteHandle(reinterpret_cast<const uint32_t*>(deserializePointer),
deserializeSize, writeHandle);
}
MockMemoryTransferService::MockReadHandle* MockMemoryTransferService::NewReadHandle() {
return new MockReadHandle(this);
}
MockMemoryTransferService::MockWriteHandle* MockMemoryTransferService::NewWriteHandle() {
return new MockWriteHandle(this);
}
}} // namespace dawn_wire::server

View File

@ -0,0 +1,93 @@
// 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.
#ifndef DAWNWIRE_SERVER_SERVERMEMORYTRANSFERSERVICE_MOCK_H_
#define DAWNWIRE_SERVER_SERVERMEMORYTRANSFERSERVICE_MOCK_H_
#include <gmock/gmock.h>
#include "dawn_wire/WireServer.h"
#include "dawn_wire/server/Server.h"
namespace dawn_wire { namespace server {
class MockMemoryTransferService : public MemoryTransferService {
public:
class MockReadHandle : public ReadHandle {
public:
MockReadHandle(MockMemoryTransferService* service);
~MockReadHandle() override;
size_t SerializeInitialData(const void* data,
size_t dataLength,
void* serializePointer) override;
private:
MockMemoryTransferService* mService;
};
class MockWriteHandle : public WriteHandle {
public:
MockWriteHandle(MockMemoryTransferService* service);
~MockWriteHandle() override;
bool DeserializeFlush(const void* deserializePointer, size_t deserializeSize) override;
const uint32_t* GetData() const;
private:
MockMemoryTransferService* mService;
};
MockMemoryTransferService();
~MockMemoryTransferService() override;
bool DeserializeReadHandle(const void* deserializePointer,
size_t deserializeSize,
ReadHandle** readHandle) override;
bool DeserializeWriteHandle(const void* deserializePointer,
size_t deserializeSize,
WriteHandle** writeHandle) override;
MockReadHandle* NewReadHandle();
MockWriteHandle* NewWriteHandle();
MOCK_METHOD3(OnDeserializeReadHandle,
bool(const uint32_t* deserializePointer,
size_t deserializeSize,
ReadHandle** readHandle));
MOCK_METHOD3(OnDeserializeWriteHandle,
bool(const uint32_t* deserializePointer,
size_t deserializeSize,
WriteHandle** writeHandle));
MOCK_METHOD4(OnReadHandleSerializeInitialData,
size_t(const ReadHandle* readHandle,
const void* data,
size_t dataLength,
void* serializePointer));
MOCK_METHOD1(OnReadHandleDestroy, void(const ReadHandle* readHandle));
MOCK_METHOD3(OnWriteHandleDeserializeFlush,
bool(const WriteHandle* writeHandle,
const uint32_t* deserializePointer,
size_t deserializeSize));
MOCK_METHOD1(OnWriteHandleDestroy, void(const WriteHandle* writeHandle));
};
}} // namespace dawn_wire::server
#endif // DAWNWIRE_SERVER_SERVERMEMORYTRANSFERSERVICE_MOCK_H_

File diff suppressed because it is too large Load Diff

View File

@ -27,6 +27,14 @@ WireTest::WireTest() {
WireTest::~WireTest() { WireTest::~WireTest() {
} }
client::MemoryTransferService* WireTest::GetClientMemoryTransferService() {
return nullptr;
}
server::MemoryTransferService* WireTest::GetServerMemoryTransferService() {
return nullptr;
}
void WireTest::SetUp() { void WireTest::SetUp() {
DawnProcTable mockProcs; DawnProcTable mockProcs;
DawnDevice mockDevice; DawnDevice mockDevice;
@ -43,12 +51,14 @@ void WireTest::SetUp() {
serverDesc.device = mockDevice; serverDesc.device = mockDevice;
serverDesc.procs = &mockProcs; serverDesc.procs = &mockProcs;
serverDesc.serializer = mS2cBuf.get(); serverDesc.serializer = mS2cBuf.get();
serverDesc.memoryTransferService = GetServerMemoryTransferService();
mWireServer.reset(new WireServer(serverDesc)); mWireServer.reset(new WireServer(serverDesc));
mC2sBuf->SetHandler(mWireServer.get()); mC2sBuf->SetHandler(mWireServer.get());
WireClientDescriptor clientDesc = {}; WireClientDescriptor clientDesc = {};
clientDesc.serializer = mC2sBuf.get(); clientDesc.serializer = mC2sBuf.get();
clientDesc.memoryTransferService = GetClientMemoryTransferService();
mWireClient.reset(new WireClient(clientDesc)); mWireClient.reset(new WireClient(clientDesc));
mS2cBuf->SetHandler(mWireClient.get()); mS2cBuf->SetHandler(mWireClient.get());
@ -69,17 +79,18 @@ void WireTest::TearDown() {
// cannot be null. // cannot be null.
api.IgnoreAllReleaseCalls(); api.IgnoreAllReleaseCalls();
mWireClient = nullptr; mWireClient = nullptr;
mWireServer = nullptr;
} }
void WireTest::FlushClient() { void WireTest::FlushClient(bool success) {
ASSERT_TRUE(mC2sBuf->Flush()); ASSERT_EQ(mC2sBuf->Flush(), success);
Mock::VerifyAndClearExpectations(&api); Mock::VerifyAndClearExpectations(&api);
SetupIgnoredCallExpectations(); SetupIgnoredCallExpectations();
} }
void WireTest::FlushServer() { void WireTest::FlushServer(bool success) {
ASSERT_TRUE(mS2cBuf->Flush()); ASSERT_EQ(mS2cBuf->Flush(), success);
} }
dawn_wire::WireServer* WireTest::GetWireServer() { dawn_wire::WireServer* WireTest::GetWireServer() {

View File

@ -69,6 +69,12 @@ inline testing::Matcher<MatcherLambdaArgument<Lambda>> MatchesLambda(Lambda lamb
namespace dawn_wire { namespace dawn_wire {
class WireClient; class WireClient;
class WireServer; class WireServer;
namespace client {
class MemoryTransferService;
} // namespace client
namespace server {
class MemoryTransferService;
} // namespace server
} // namespace dawn_wire } // namespace dawn_wire
namespace utils { namespace utils {
@ -82,8 +88,9 @@ class WireTest : public testing::Test {
void SetUp() override; void SetUp() override;
void TearDown() override; void TearDown() override;
void FlushClient();
void FlushServer(); void FlushClient(bool success = true);
void FlushServer(bool success = true);
testing::StrictMock<MockProcTable> api; testing::StrictMock<MockProcTable> api;
DawnDevice apiDevice; DawnDevice apiDevice;
@ -97,6 +104,9 @@ class WireTest : public testing::Test {
private: private:
void SetupIgnoredCallExpectations(); void SetupIgnoredCallExpectations();
virtual dawn_wire::client::MemoryTransferService* GetClientMemoryTransferService();
virtual dawn_wire::server::MemoryTransferService* GetServerMemoryTransferService();
std::unique_ptr<dawn_wire::WireServer> mWireServer; std::unique_ptr<dawn_wire::WireServer> mWireServer;
std::unique_ptr<dawn_wire::WireClient> mWireClient; std::unique_ptr<dawn_wire::WireClient> mWireClient;
std::unique_ptr<utils::TerribleCommandBuffer> mS2cBuf; std::unique_ptr<utils::TerribleCommandBuffer> mS2cBuf;