// Copyright 2019 The Dawn & Tint Authors // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // 1. Redistributions of source code must retain the above copyright notice, this // list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // 3. Neither the name of the copyright holder nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <memory> #include <utility> #include "dawn/tests/unittests/wire/WireTest.h" #include "dawn/wire/client/ClientMemoryTransferService_mock.h" #include "dawn/wire/server/ServerMemoryTransferService_mock.h" namespace dawn::wire { namespace { _; Eq; InvokeWithoutArgs; Mock; Pointee; Return; StrictMock; WithArg; // Mock class to add expectations on the wire calling callbacks class MockBufferMapCallback { … }; std::unique_ptr<StrictMock<MockBufferMapCallback>> mockBufferMapCallback; void ToMockBufferMapCallback(WGPUBufferMapAsyncStatus status, void* userdata) { … } // WireMemoryTransferServiceTests test the MemoryTransferService with buffer mapping. // They test the basic success and error cases for buffer mapping, and they test // mocked failures of each fallible MemoryTransferService method that an embedder // could implement. // The test harness defines multiple helpers for expecting operations on Read/Write handles // and for mocking failures. The helpers are designed such that for a given run of a test, // a Serialization expection has a corresponding Deserialization expectation for which the // serialized data must match. // There are tests which check for Success for every mapping operation which mock an entire // mapping operation from map to unmap, and add all MemoryTransferService expectations. Tests // which check for errors perform the same mapping operations but insert mocked failures for // various mapping or MemoryTransferService operations. class WireMemoryTransferServiceTests : public WireTest { … }; uint32_t WireMemoryTransferServiceTests::mBufferContent = …; uint32_t WireMemoryTransferServiceTests::mUpdatedBufferContent = …; uint32_t WireMemoryTransferServiceTests::mSerializeCreateInfo = …; uint32_t WireMemoryTransferServiceTests::mReadHandleSerializeDataInfo = …; uint32_t WireMemoryTransferServiceTests::mWriteHandleSerializeDataInfo = …; // Test successful mapping for reading. TEST_F(WireMemoryTransferServiceTests, BufferMapReadSuccess) { … } // Test ReadHandle destroy behavior TEST_F(WireMemoryTransferServiceTests, BufferMapReadDestroy) { … } // Test unsuccessful mapping for reading. TEST_F(WireMemoryTransferServiceTests, BufferMapReadError) { … } // Test ReadHandle creation failure. TEST_F(WireMemoryTransferServiceTests, BufferMapReadHandleCreationFailure) { … } // Test MapRead DeserializeReadHandle failure. TEST_F(WireMemoryTransferServiceTests, BufferMapReadDeserializeReadHandleFailure) { … } // Test read handle DeserializeDataUpdate failure. TEST_F(WireMemoryTransferServiceTests, BufferMapReadDeserializeDataUpdateFailure) { … } // Test mapping for reading destroying the buffer before unmapping on the client side. TEST_F(WireMemoryTransferServiceTests, BufferMapReadDestroyBeforeUnmap) { … } // Test successful mapping for writing. TEST_F(WireMemoryTransferServiceTests, BufferMapWriteSuccess) { … } // Test WriteHandle destroy behavior TEST_F(WireMemoryTransferServiceTests, BufferMapWriteDestroy) { … } // Test unsuccessful MapWrite. TEST_F(WireMemoryTransferServiceTests, BufferMapWriteError) { … } // Test WriteHandle creation failure. TEST_F(WireMemoryTransferServiceTests, BufferMapWriteHandleCreationFailure) { … } // Test MapWrite DeserializeWriteHandle failure. TEST_F(WireMemoryTransferServiceTests, BufferMapWriteDeserializeWriteHandleFailure) { … } // Test MapWrite DeserializeDataUpdate failure. TEST_F(WireMemoryTransferServiceTests, BufferMapWriteDeserializeDataUpdateFailure) { … } // Test MapWrite destroying the buffer before unmapping on the client side. TEST_F(WireMemoryTransferServiceTests, BufferMapWriteDestroyBeforeUnmap) { … } // Test successful buffer creation with mappedAtCreation = true. TEST_F(WireMemoryTransferServiceTests, MappedAtCreationSuccess) { … } // Test buffer creation with mappedAtCreation WriteHandle creation failure. TEST_F(WireMemoryTransferServiceTests, MappedAtCreationWriteHandleCreationFailure) { … } // Test buffer creation with mappedAtCreation DeserializeWriteHandle failure. TEST_F(WireMemoryTransferServiceTests, MappedAtCreationDeserializeWriteHandleFailure) { … } // Test buffer creation with mappedAtCreation = true DeserializeDataUpdate failure. TEST_F(WireMemoryTransferServiceTests, MappedAtCreationDeserializeDataUpdateFailure) { … } // Test mappedAtCreation=true destroying the buffer before unmapping on the client side. TEST_F(WireMemoryTransferServiceTests, MappedAtCreationDestroyBeforeUnmap) { … } // Test a buffer with mappedAtCreation and MapRead usage destroy WriteHandle on unmap and switch // data pointer to ReadHandle TEST_F(WireMemoryTransferServiceTests, MappedAtCreationAndMapReadSuccess) { … } // Test WriteHandle preserves after unmap for a buffer with mappedAtCreation and MapWrite usage TEST_F(WireMemoryTransferServiceTests, MappedAtCreationAndMapWriteSuccess) { … } } // anonymous namespace } // namespace dawn::wire