| Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 1 | // Copyright 2021 The Dawn & Tint Authors |
| Loko Kung | 2f3fe95 | 2021-10-12 18:53:57 +0000 | [diff] [blame] | 2 | // |
| Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 3 | // Redistribution and use in source and binary forms, with or without |
| 4 | // modification, are permitted provided that the following conditions are met: |
| Loko Kung | 2f3fe95 | 2021-10-12 18:53:57 +0000 | [diff] [blame] | 5 | // |
| Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 6 | // 1. Redistributions of source code must retain the above copyright notice, this |
| 7 | // list of conditions and the following disclaimer. |
| Loko Kung | 2f3fe95 | 2021-10-12 18:53:57 +0000 | [diff] [blame] | 8 | // |
| Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 9 | // 2. Redistributions in binary form must reproduce the above copyright notice, |
| 10 | // this list of conditions and the following disclaimer in the documentation |
| 11 | // and/or other materials provided with the distribution. |
| 12 | // |
| 13 | // 3. Neither the name of the copyright holder nor the names of its |
| 14 | // contributors may be used to endorse or promote products derived from |
| 15 | // this software without specific prior written permission. |
| 16 | // |
| 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 20 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 21 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 24 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 25 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| Loko Kung | 2f3fe95 | 2021-10-12 18:53:57 +0000 | [diff] [blame] | 27 | |
| dan sinclair | 479dc6b | 2022-04-11 18:30:50 +0000 | [diff] [blame] | 28 | #ifndef SRC_DAWN_TESTS_DAWNNATIVETEST_H_ |
| 29 | #define SRC_DAWN_TESTS_DAWNNATIVETEST_H_ |
| Loko Kung | 2f3fe95 | 2021-10-12 18:53:57 +0000 | [diff] [blame] | 30 | |
| Loko Kung | c2aeab7 | 2024-07-25 20:08:34 +0000 | [diff] [blame] | 31 | #include <gtest/gtest.h> |
| 32 | #include <webgpu/webgpu_cpp.h> |
| 33 | |
| dan sinclair | 13e9699 | 2022-04-20 00:58:34 +0000 | [diff] [blame] | 34 | #include <memory> |
| Loko Kung | 2f3fe95 | 2021-10-12 18:53:57 +0000 | [diff] [blame] | 35 | |
| Ben Clayton | 818001d | 2022-02-04 17:07:46 +0000 | [diff] [blame] | 36 | #include "dawn/native/DawnNative.h" |
| 37 | #include "dawn/native/ErrorData.h" |
| Loko Kung | 2f3fe95 | 2021-10-12 18:53:57 +0000 | [diff] [blame] | 38 | |
| Corentin Wallez | ec9cf2a | 2022-01-12 09:17:35 +0000 | [diff] [blame] | 39 | namespace dawn::native { |
| Loko Kung | 2f3fe95 | 2021-10-12 18:53:57 +0000 | [diff] [blame] | 40 | |
| dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 41 | // This is similar to DAWN_TRY_ASSIGN but produces a fatal GTest error if EXPR is an error. |
| Loko Kung | 2f3fe95 | 2021-10-12 18:53:57 +0000 | [diff] [blame] | 42 | #define DAWN_ASSERT_AND_ASSIGN(VAR, EXPR) \ |
| 43 | DAWN_TRY_ASSIGN_WITH_CLEANUP(VAR, EXPR, {}, AddFatalDawnFailure(#EXPR, error.get())) |
| 44 | |
| dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 45 | void AddFatalDawnFailure(const char* expression, const ErrorData* error); |
| Loko Kung | 2f3fe95 | 2021-10-12 18:53:57 +0000 | [diff] [blame] | 46 | |
| Corentin Wallez | ec9cf2a | 2022-01-12 09:17:35 +0000 | [diff] [blame] | 47 | } // namespace dawn::native |
| Loko Kung | 2f3fe95 | 2021-10-12 18:53:57 +0000 | [diff] [blame] | 48 | |
| Austin Eng | bcfa7b1 | 2021-10-29 18:52:33 +0000 | [diff] [blame] | 49 | class DawnNativeTest : public ::testing::Test { |
| 50 | public: |
| 51 | DawnNativeTest(); |
| 52 | ~DawnNativeTest() override; |
| 53 | |
| 54 | void SetUp() override; |
| Austin Eng | bcfa7b1 | 2021-10-29 18:52:33 +0000 | [diff] [blame] | 55 | |
| Austin Eng | d3fa3f0 | 2022-06-11 03:50:33 +0000 | [diff] [blame] | 56 | virtual std::unique_ptr<dawn::platform::Platform> CreateTestPlatform(); |
| Zhaoming Jiang | 86578e2 | 2025-08-05 01:45:49 -0700 | [diff] [blame] | 57 | virtual wgpu::DawnTogglesDescriptor DeviceToggles(); |
| Loko Kung | f2a5e57 | 2024-06-20 21:56:42 +0000 | [diff] [blame] | 58 | WGPUDevice CreateTestDevice(); |
| Austin Eng | bcfa7b1 | 2021-10-29 18:52:33 +0000 | [diff] [blame] | 59 | |
| 60 | protected: |
| Austin Eng | d3fa3f0 | 2022-06-11 03:50:33 +0000 | [diff] [blame] | 61 | std::unique_ptr<dawn::platform::Platform> platform; |
| Jiawei Shao | 37fe887 | 2024-03-14 07:35:08 +0000 | [diff] [blame] | 62 | std::unique_ptr<dawn::native::Instance> instance; |
| Corentin Wallez | ec9cf2a | 2022-01-12 09:17:35 +0000 | [diff] [blame] | 63 | dawn::native::Adapter adapter; |
| Austin Eng | bcfa7b1 | 2021-10-29 18:52:33 +0000 | [diff] [blame] | 64 | wgpu::Device device; |
| 65 | |
| 66 | private: |
| 67 | static void OnDeviceError(WGPUErrorType type, const char* message, void* userdata); |
| 68 | }; |
| 69 | |
| dan sinclair | 479dc6b | 2022-04-11 18:30:50 +0000 | [diff] [blame] | 70 | #endif // SRC_DAWN_TESTS_DAWNNATIVETEST_H_ |