blob: 9009f82c2dae868a5242a236da4aee0c9325b917 [file] [log] [blame]
Austin Engcc2516a2023-10-17 20:57:54 +00001// Copyright 2021 The Dawn & Tint Authors
Loko Kung2f3fe952021-10-12 18:53:57 +00002//
Austin Engcc2516a2023-10-17 20:57:54 +00003// Redistribution and use in source and binary forms, with or without
4// modification, are permitted provided that the following conditions are met:
Loko Kung2f3fe952021-10-12 18:53:57 +00005//
Austin Engcc2516a2023-10-17 20:57:54 +00006// 1. Redistributions of source code must retain the above copyright notice, this
7// list of conditions and the following disclaimer.
Loko Kung2f3fe952021-10-12 18:53:57 +00008//
Austin Engcc2516a2023-10-17 20:57:54 +00009// 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 Kung2f3fe952021-10-12 18:53:57 +000027
dan sinclair479dc6b2022-04-11 18:30:50 +000028#ifndef SRC_DAWN_TESTS_DAWNNATIVETEST_H_
29#define SRC_DAWN_TESTS_DAWNNATIVETEST_H_
Loko Kung2f3fe952021-10-12 18:53:57 +000030
Loko Kungc2aeab72024-07-25 20:08:34 +000031#include <gtest/gtest.h>
32#include <webgpu/webgpu_cpp.h>
33
dan sinclair13e96992022-04-20 00:58:34 +000034#include <memory>
Loko Kung2f3fe952021-10-12 18:53:57 +000035
Ben Clayton818001d2022-02-04 17:07:46 +000036#include "dawn/native/DawnNative.h"
37#include "dawn/native/ErrorData.h"
Loko Kung2f3fe952021-10-12 18:53:57 +000038
Corentin Wallezec9cf2a2022-01-12 09:17:35 +000039namespace dawn::native {
Loko Kung2f3fe952021-10-12 18:53:57 +000040
dan sinclair41e4d9a2022-05-01 14:40:55 +000041// This is similar to DAWN_TRY_ASSIGN but produces a fatal GTest error if EXPR is an error.
Loko Kung2f3fe952021-10-12 18:53:57 +000042#define DAWN_ASSERT_AND_ASSIGN(VAR, EXPR) \
43 DAWN_TRY_ASSIGN_WITH_CLEANUP(VAR, EXPR, {}, AddFatalDawnFailure(#EXPR, error.get()))
44
dan sinclair41e4d9a2022-05-01 14:40:55 +000045void AddFatalDawnFailure(const char* expression, const ErrorData* error);
Loko Kung2f3fe952021-10-12 18:53:57 +000046
Corentin Wallezec9cf2a2022-01-12 09:17:35 +000047} // namespace dawn::native
Loko Kung2f3fe952021-10-12 18:53:57 +000048
Austin Engbcfa7b12021-10-29 18:52:33 +000049class DawnNativeTest : public ::testing::Test {
50 public:
51 DawnNativeTest();
52 ~DawnNativeTest() override;
53
54 void SetUp() override;
Austin Engbcfa7b12021-10-29 18:52:33 +000055
Austin Engd3fa3f02022-06-11 03:50:33 +000056 virtual std::unique_ptr<dawn::platform::Platform> CreateTestPlatform();
Zhaoming Jiang86578e22025-08-05 01:45:49 -070057 virtual wgpu::DawnTogglesDescriptor DeviceToggles();
Loko Kungf2a5e572024-06-20 21:56:42 +000058 WGPUDevice CreateTestDevice();
Austin Engbcfa7b12021-10-29 18:52:33 +000059
60 protected:
Austin Engd3fa3f02022-06-11 03:50:33 +000061 std::unique_ptr<dawn::platform::Platform> platform;
Jiawei Shao37fe8872024-03-14 07:35:08 +000062 std::unique_ptr<dawn::native::Instance> instance;
Corentin Wallezec9cf2a2022-01-12 09:17:35 +000063 dawn::native::Adapter adapter;
Austin Engbcfa7b12021-10-29 18:52:33 +000064 wgpu::Device device;
65
66 private:
67 static void OnDeviceError(WGPUErrorType type, const char* message, void* userdata);
68};
69
dan sinclair479dc6b2022-04-11 18:30:50 +000070#endif // SRC_DAWN_TESTS_DAWNNATIVETEST_H_