// Copyright 2023 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 <gtest/gtest.h> #include <webgpu/webgpu_cpp.h> #include <string_view> #include <utility> #include "dawn/native/ChainUtils.h" #include "dawn/tests/MockCallback.h" #include "mocks/BufferMock.h" #include "mocks/ComputePipelineMock.h" #include "mocks/DawnMockTest.h" #include "mocks/DeviceMock.h" #include "mocks/ExternalTextureMock.h" #include "mocks/PipelineLayoutMock.h" #include "mocks/RenderPipelineMock.h" #include "mocks/ShaderModuleMock.h" #include "mocks/TextureMock.h" namespace dawn::native { namespace { _; ByMove; HasSubstr; MockCallback; MockCppCallback; NiceMock; Return; StrictMock; Test; MockComputePipelineAsyncCallback; MockRenderPipelineAsyncCallback; static constexpr char kOomErrorMessage[] = …; static constexpr char kInternalErrorMessage[] = …; static constexpr std::string_view kComputeShader = …; static constexpr std::string_view kVertexShader = …; class AllowedErrorTests : public DawnMockTest { … }; // // Exercise APIs where OOM errors cause a device lost. // TEST_F(AllowedErrorTests, QueueSubmit) { … } TEST_F(AllowedErrorTests, QueueWriteBuffer) { … } TEST_F(AllowedErrorTests, QueueWriteTexture) { … } // Even though OOM is allowed in buffer creation, when creating a buffer in internal workaround the // OOM should be masked as a device loss. TEST_F(AllowedErrorTests, QueueCopyTextureForBrowserOomBuffer) { … } // Even though OOM is allowed in buffer creation, when creating a buffer in internal workaround the // OOM should be masked as a device loss. TEST_F(AllowedErrorTests, QueueCopyExternalTextureForBrowserOomBuffer) { … } // OOM error from synchronously initializing a compute pipeline should result in a device loss. TEST_F(AllowedErrorTests, CreateComputePipeline) { … } // OOM error from synchronously initializing a render pipeline should result in a device loss. TEST_F(AllowedErrorTests, CreateRenderPipeline) { … } // Internal error from synchronously initializing a compute pipeline should not result in a device // loss. TEST_F(AllowedErrorTests, CreateComputePipelineInternalError) { … } // Internal error from synchronously initializing a render pipeline should not result in a device // loss. TEST_F(AllowedErrorTests, CreateRenderPipelineInternalError) { … } // // Exercise async APIs where OOM errors do NOT currently cause a device lost. // // OOM error from asynchronously initializing a compute pipeline should not result in a device loss. TEST_F(AllowedErrorTests, CreateComputePipelineAsync) { … } // OOM error from asynchronously initializing a render pipeline should not result in a device loss. TEST_F(AllowedErrorTests, CreateRenderPipelineAsync) { … } // Internal error from asynchronously initializing a compute pipeline should not result in a device // loss. TEST_F(AllowedErrorTests, CreateComputePipelineAsyncInternalError) { … } // Internal error from asynchronously initializing a render pipeline should not result in a device // loss. TEST_F(AllowedErrorTests, CreateRenderPipelineAsyncInternalError) { … } // // Exercise APIs where OOM error are allowed and surfaced. // // OOM error from buffer creation is allowed and surfaced directly. TEST_F(AllowedErrorTests, CreateBuffer) { … } // OOM error from texture creation is allowed and surfaced directly. TEST_F(AllowedErrorTests, CreateTexture) { … } // OOM error from query set creation is allowed and surfaced directly. TEST_F(AllowedErrorTests, CreateQuerySet) { … } TEST_F(AllowedErrorTests, InjectError) { … } } // anonymous namespace } // namespace dawn::native