1 // Copyright 2021 The Dawn Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef TESTS_DAWNNATIVETEST_H_ 16 #define TESTS_DAWNNATIVETEST_H_ 17 18 #include <gtest/gtest.h> 19 20 #include "dawn/webgpu_cpp.h" 21 #include "dawn_native/DawnNative.h" 22 #include "dawn_native/ErrorData.h" 23 24 namespace dawn_native { 25 26 // This is similar to DAWN_TRY_ASSIGN but produces a fatal GTest error if EXPR is an error. 27 #define DAWN_ASSERT_AND_ASSIGN(VAR, EXPR) \ 28 DAWN_TRY_ASSIGN_WITH_CLEANUP(VAR, EXPR, {}, AddFatalDawnFailure(#EXPR, error.get())) 29 30 void AddFatalDawnFailure(const char* expression, const ErrorData* error); 31 32 } // namespace dawn_native 33 34 class DawnNativeTest : public ::testing::Test { 35 public: 36 DawnNativeTest(); 37 ~DawnNativeTest() override; 38 39 void SetUp() override; 40 void TearDown() override; 41 42 virtual WGPUDevice CreateTestDevice(); 43 44 protected: 45 std::unique_ptr<dawn_native::Instance> instance; 46 dawn_native::Adapter adapter; 47 wgpu::Device device; 48 49 private: 50 static void OnDeviceError(WGPUErrorType type, const char* message, void* userdata); 51 }; 52 53 #endif // TESTS_DAWNNATIVETEST_H_ 54