Corentin Wallez | 4a9ef4e | 2018-07-18 11:40:26 +0200 | [diff] [blame] | 1 | // Copyright 2017 The Dawn Authors |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 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 | |
Austin Eng | ca0eac3 | 2019-08-28 23:18:10 +0000 | [diff] [blame] | 15 | #ifndef TESTS_DAWNTEST_H_ |
| 16 | #define TESTS_DAWNTEST_H_ |
| 17 | |
Corentin Wallez | 95586ff | 2019-12-05 11:13:01 +0000 | [diff] [blame] | 18 | #include "common/Log.h" |
Corentin Wallez | 9649682 | 2019-10-15 11:44:38 +0000 | [diff] [blame] | 19 | #include "dawn/dawn_proc_table.h" |
Corentin Wallez | cab352c | 2019-10-28 13:27:36 +0000 | [diff] [blame] | 20 | #include "dawn/webgpu_cpp.h" |
Jiawei Shao | 58809d4 | 2018-09-19 00:32:52 +0000 | [diff] [blame] | 21 | #include "dawn_native/DawnNative.h" |
Ryan Harrison | acdc35d | 2021-04-14 14:55:07 +0000 | [diff] [blame] | 22 | #include "tests/ToggleParser.h" |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 23 | |
Bryan Bernhart | 41b3f9c | 2020-11-20 20:38:37 +0000 | [diff] [blame] | 24 | #include <dawn_platform/DawnPlatform.h> |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 25 | #include <gtest/gtest.h> |
Jiawei Shao | 15d4c2e | 2019-04-26 07:52:57 +0000 | [diff] [blame] | 26 | |
Austin Eng | 4234c39 | 2017-07-17 09:37:08 -0400 | [diff] [blame] | 27 | #include <memory> |
Corentin Wallez | 0b2f552 | 2019-02-21 16:29:12 +0000 | [diff] [blame] | 28 | #include <unordered_map> |
Jiawei Shao | 93373ab | 2019-05-29 00:07:37 +0000 | [diff] [blame] | 29 | #include <vector> |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 30 | |
Corentin Wallez | 9fc6534 | 2018-07-18 15:28:38 +0200 | [diff] [blame] | 31 | // Getting data back from Dawn is done in an async manners so all expectations are "deferred" |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 32 | // until the end of the test. Also expectations use a copy to a MapRead buffer to get the data |
Corentin Wallez | ec05355 | 2019-07-08 10:05:46 +0000 | [diff] [blame] | 33 | // so resources should have the CopySrc allowed usage bit if you want to add expectations on |
Corentin Wallez | a4da032 | 2018-07-18 15:18:25 +0200 | [diff] [blame] | 34 | // them. |
Xinghua Cao | db8f804 | 2020-06-08 12:18:21 +0000 | [diff] [blame] | 35 | |
Hao Li | c0acb25 | 2020-08-04 06:41:56 +0000 | [diff] [blame] | 36 | #define EXPECT_BUFFER(buffer, offset, size, expectation) \ |
| 37 | AddBufferExpectation(__FILE__, __LINE__, buffer, offset, size, expectation) |
Xinghua Cao | db8f804 | 2020-06-08 12:18:21 +0000 | [diff] [blame] | 38 | |
Hao Li | c0acb25 | 2020-08-04 06:41:56 +0000 | [diff] [blame] | 39 | #define EXPECT_BUFFER_U16_EQ(expected, buffer, offset) \ |
| 40 | EXPECT_BUFFER(buffer, offset, sizeof(uint16_t), new ::detail::ExpectEq<uint16_t>(expected)) |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 41 | |
Hao Li | c0acb25 | 2020-08-04 06:41:56 +0000 | [diff] [blame] | 42 | #define EXPECT_BUFFER_U16_RANGE_EQ(expected, buffer, offset, count) \ |
| 43 | EXPECT_BUFFER(buffer, offset, sizeof(uint16_t) * (count), \ |
| 44 | new ::detail::ExpectEq<uint16_t>(expected, count)) |
Austin Eng | 49fe566 | 2017-07-04 10:53:42 -0400 | [diff] [blame] | 45 | |
Hao Li | c0acb25 | 2020-08-04 06:41:56 +0000 | [diff] [blame] | 46 | #define EXPECT_BUFFER_U32_EQ(expected, buffer, offset) \ |
| 47 | EXPECT_BUFFER(buffer, offset, sizeof(uint32_t), new ::detail::ExpectEq<uint32_t>(expected)) |
Austin Eng | 8f9523e | 2020-06-19 16:21:33 +0000 | [diff] [blame] | 48 | |
Hao Li | c0acb25 | 2020-08-04 06:41:56 +0000 | [diff] [blame] | 49 | #define EXPECT_BUFFER_U32_RANGE_EQ(expected, buffer, offset, count) \ |
| 50 | EXPECT_BUFFER(buffer, offset, sizeof(uint32_t) * (count), \ |
| 51 | new ::detail::ExpectEq<uint32_t>(expected, count)) |
| 52 | |
Hao Li | 9ff83f6 | 2021-01-12 01:44:01 +0000 | [diff] [blame] | 53 | #define EXPECT_BUFFER_U64_EQ(expected, buffer, offset) \ |
| 54 | EXPECT_BUFFER(buffer, offset, sizeof(uint64_t), new ::detail::ExpectEq<uint64_t>(expected)) |
| 55 | |
Hao Li | c0acb25 | 2020-08-04 06:41:56 +0000 | [diff] [blame] | 56 | #define EXPECT_BUFFER_U64_RANGE_EQ(expected, buffer, offset, count) \ |
| 57 | EXPECT_BUFFER(buffer, offset, sizeof(uint64_t) * (count), \ |
| 58 | new ::detail::ExpectEq<uint64_t>(expected, count)) |
| 59 | |
| 60 | #define EXPECT_BUFFER_FLOAT_EQ(expected, buffer, offset) \ |
| 61 | EXPECT_BUFFER(buffer, offset, sizeof(float), new ::detail::ExpectEq<float>(expected)) |
| 62 | |
| 63 | #define EXPECT_BUFFER_FLOAT_RANGE_EQ(expected, buffer, offset, count) \ |
| 64 | EXPECT_BUFFER(buffer, offset, sizeof(float) * (count), \ |
| 65 | new ::detail::ExpectEq<float>(expected, count)) |
Austin Eng | 8f9523e | 2020-06-19 16:21:33 +0000 | [diff] [blame] | 66 | |
Corentin Wallez | 4cd65f0 | 2017-06-27 00:11:16 -0400 | [diff] [blame] | 67 | // Test a pixel of the mip level 0 of a 2D texture. |
Austin Eng | 0a43427 | 2020-08-04 19:46:37 +0000 | [diff] [blame] | 68 | #define EXPECT_PIXEL_RGBA8_EQ(expected, texture, x, y) \ |
Yunchao He | 4eb40c1 | 2021-03-31 22:15:53 +0000 | [diff] [blame] | 69 | AddTextureExpectation(__FILE__, __LINE__, expected, texture, {x, y}) |
Austin Eng | e5bd3e0 | 2017-07-17 16:16:50 -0400 | [diff] [blame] | 70 | |
Austin Eng | 0a43427 | 2020-08-04 19:46:37 +0000 | [diff] [blame] | 71 | #define EXPECT_PIXEL_FLOAT_EQ(expected, texture, x, y) \ |
Yunchao He | 4eb40c1 | 2021-03-31 22:15:53 +0000 | [diff] [blame] | 72 | AddTextureExpectation(__FILE__, __LINE__, expected, texture, {x, y}) |
Austin Eng | 0d66198 | 2020-01-16 00:12:10 +0000 | [diff] [blame] | 73 | |
shrekshao | f8c5e4a | 2020-12-24 03:11:17 +0000 | [diff] [blame] | 74 | #define EXPECT_PIXEL_RGBA8_BETWEEN(color0, color1, texture, x, y) \ |
| 75 | AddTextureBetweenColorsExpectation(__FILE__, __LINE__, color0, color1, texture, x, y) |
| 76 | |
Austin Eng | 0a43427 | 2020-08-04 19:46:37 +0000 | [diff] [blame] | 77 | // TODO(enga): Migrate other texure expectation helpers to this common one. |
| 78 | #define EXPECT_TEXTURE_EQ(...) AddTextureExpectation(__FILE__, __LINE__, __VA_ARGS__) |
Austin Eng | 0d66198 | 2020-01-16 00:12:10 +0000 | [diff] [blame] | 79 | |
Corentin Wallez | 2dfb3f0 | 2019-02-28 09:45:48 +0000 | [diff] [blame] | 80 | // Should only be used to test validation of function that can't be tested by regular validation |
| 81 | // tests; |
Austin Eng | 3aa5be9 | 2020-04-16 21:36:33 +0000 | [diff] [blame] | 82 | #define ASSERT_DEVICE_ERROR(statement) \ |
| 83 | StartExpectDeviceError(); \ |
| 84 | statement; \ |
| 85 | FlushWire(); \ |
| 86 | if (!EndExpectDeviceError()) { \ |
| 87 | FAIL() << "Expected device error in:\n " << #statement; \ |
| 88 | } \ |
| 89 | do { \ |
| 90 | } while (0) |
Corentin Wallez | 2dfb3f0 | 2019-02-28 09:45:48 +0000 | [diff] [blame] | 91 | |
Corentin Wallez | 4cd65f0 | 2017-06-27 00:11:16 -0400 | [diff] [blame] | 92 | struct RGBA8 { |
Corentin Wallez | a4da032 | 2018-07-18 15:18:25 +0200 | [diff] [blame] | 93 | constexpr RGBA8() : RGBA8(0, 0, 0, 0) { |
| 94 | } |
| 95 | constexpr RGBA8(uint8_t r, uint8_t g, uint8_t b, uint8_t a) : r(r), g(g), b(b), a(a) { |
Corentin Wallez | 4cd65f0 | 2017-06-27 00:11:16 -0400 | [diff] [blame] | 96 | } |
| 97 | bool operator==(const RGBA8& other) const; |
| 98 | bool operator!=(const RGBA8& other) const; |
shrekshao | f8c5e4a | 2020-12-24 03:11:17 +0000 | [diff] [blame] | 99 | bool operator<=(const RGBA8& other) const; |
| 100 | bool operator>=(const RGBA8& other) const; |
Corentin Wallez | 4cd65f0 | 2017-06-27 00:11:16 -0400 | [diff] [blame] | 101 | |
| 102 | uint8_t r, g, b, a; |
Yunchao He | 0c02f54 | 2019-11-19 17:57:30 +0000 | [diff] [blame] | 103 | |
| 104 | static const RGBA8 kZero; |
| 105 | static const RGBA8 kBlack; |
| 106 | static const RGBA8 kRed; |
| 107 | static const RGBA8 kGreen; |
| 108 | static const RGBA8 kBlue; |
| 109 | static const RGBA8 kYellow; |
| 110 | static const RGBA8 kWhite; |
Corentin Wallez | 4cd65f0 | 2017-06-27 00:11:16 -0400 | [diff] [blame] | 111 | }; |
Corentin Wallez | a4da032 | 2018-07-18 15:18:25 +0200 | [diff] [blame] | 112 | std::ostream& operator<<(std::ostream& stream, const RGBA8& color); |
Corentin Wallez | 4cd65f0 | 2017-06-27 00:11:16 -0400 | [diff] [blame] | 113 | |
Austin Eng | da722ad | 2020-05-15 20:28:05 +0000 | [diff] [blame] | 114 | struct BackendTestConfig { |
| 115 | BackendTestConfig(wgpu::BackendType backendType, |
| 116 | std::initializer_list<const char*> forceEnabledWorkarounds = {}, |
| 117 | std::initializer_list<const char*> forceDisabledWorkarounds = {}); |
| 118 | |
| 119 | wgpu::BackendType backendType; |
| 120 | |
| 121 | std::vector<const char*> forceEnabledWorkarounds; |
| 122 | std::vector<const char*> forceDisabledWorkarounds; |
| 123 | }; |
| 124 | |
Austin Eng | 25c747c | 2020-05-15 16:07:12 +0000 | [diff] [blame] | 125 | struct TestAdapterProperties : wgpu::AdapterProperties { |
| 126 | TestAdapterProperties(const wgpu::AdapterProperties& properties, bool selected); |
| 127 | std::string adapterName; |
| 128 | bool selected; |
| 129 | |
| 130 | private: |
| 131 | // This may be temporary, so it is copied into |adapterName| and made private. |
| 132 | using wgpu::AdapterProperties::name; |
| 133 | }; |
| 134 | |
Austin Eng | da722ad | 2020-05-15 20:28:05 +0000 | [diff] [blame] | 135 | struct AdapterTestParam { |
| 136 | AdapterTestParam(const BackendTestConfig& config, |
| 137 | const TestAdapterProperties& adapterProperties); |
Jiawei Shao | 15d4c2e | 2019-04-26 07:52:57 +0000 | [diff] [blame] | 138 | |
Austin Eng | da722ad | 2020-05-15 20:28:05 +0000 | [diff] [blame] | 139 | TestAdapterProperties adapterProperties; |
Jiawei Shao | 93373ab | 2019-05-29 00:07:37 +0000 | [diff] [blame] | 140 | std::vector<const char*> forceEnabledWorkarounds; |
Natasha Lee | 28232ce | 2019-06-11 18:11:05 +0000 | [diff] [blame] | 141 | std::vector<const char*> forceDisabledWorkarounds; |
Jiawei Shao | 15d4c2e | 2019-04-26 07:52:57 +0000 | [diff] [blame] | 142 | }; |
| 143 | |
Austin Eng | da722ad | 2020-05-15 20:28:05 +0000 | [diff] [blame] | 144 | std::ostream& operator<<(std::ostream& os, const AdapterTestParam& param); |
Brian Ho | e25a3ae | 2019-08-27 01:44:29 +0000 | [diff] [blame] | 145 | |
Austin Eng | da722ad | 2020-05-15 20:28:05 +0000 | [diff] [blame] | 146 | BackendTestConfig D3D12Backend(std::initializer_list<const char*> forceEnabledWorkarounds = {}, |
| 147 | std::initializer_list<const char*> forceDisabledWorkarounds = {}); |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 148 | |
Austin Eng | da722ad | 2020-05-15 20:28:05 +0000 | [diff] [blame] | 149 | BackendTestConfig MetalBackend(std::initializer_list<const char*> forceEnabledWorkarounds = {}, |
| 150 | std::initializer_list<const char*> forceDisabledWorkarounds = {}); |
Austin Eng | 6c1d646 | 2020-02-25 16:23:17 +0000 | [diff] [blame] | 151 | |
Austin Eng | da722ad | 2020-05-15 20:28:05 +0000 | [diff] [blame] | 152 | BackendTestConfig NullBackend(std::initializer_list<const char*> forceEnabledWorkarounds = {}, |
| 153 | std::initializer_list<const char*> forceDisabledWorkarounds = {}); |
Corentin Wallez | 11652ff | 2020-03-20 17:07:20 +0000 | [diff] [blame] | 154 | |
Austin Eng | da722ad | 2020-05-15 20:28:05 +0000 | [diff] [blame] | 155 | BackendTestConfig OpenGLBackend(std::initializer_list<const char*> forceEnabledWorkarounds = {}, |
| 156 | std::initializer_list<const char*> forceDisabledWorkarounds = {}); |
Austin Eng | 6c1d646 | 2020-02-25 16:23:17 +0000 | [diff] [blame] | 157 | |
Stephen White | d45ab07 | 2020-11-25 16:45:04 +0000 | [diff] [blame] | 158 | BackendTestConfig OpenGLESBackend(std::initializer_list<const char*> forceEnabledWorkarounds = {}, |
| 159 | std::initializer_list<const char*> forceDisabledWorkarounds = {}); |
| 160 | |
Austin Eng | da722ad | 2020-05-15 20:28:05 +0000 | [diff] [blame] | 161 | BackendTestConfig VulkanBackend(std::initializer_list<const char*> forceEnabledWorkarounds = {}, |
| 162 | std::initializer_list<const char*> forceDisabledWorkarounds = {}); |
Austin Eng | 6c1d646 | 2020-02-25 16:23:17 +0000 | [diff] [blame] | 163 | |
Stephen White | d45ab07 | 2020-11-25 16:45:04 +0000 | [diff] [blame] | 164 | struct GLFWwindow; |
| 165 | |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 166 | namespace utils { |
Austin Eng | f580096 | 2020-08-14 21:02:12 +0000 | [diff] [blame] | 167 | class PlatformDebugLogger; |
Corentin Wallez | bdc8677 | 2018-07-26 15:07:57 +0200 | [diff] [blame] | 168 | class TerribleCommandBuffer; |
Austin Eng | e58d5a3 | 2021-01-27 22:54:04 +0000 | [diff] [blame] | 169 | class WireHelper; |
Jiawei Shao | 93373ab | 2019-05-29 00:07:37 +0000 | [diff] [blame] | 170 | } // namespace utils |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 171 | |
| 172 | namespace detail { |
| 173 | class Expectation; |
Austin Eng | 0a43427 | 2020-08-04 19:46:37 +0000 | [diff] [blame] | 174 | |
| 175 | template <typename T> |
| 176 | class ExpectEq; |
shrekshao | f8c5e4a | 2020-12-24 03:11:17 +0000 | [diff] [blame] | 177 | template <typename T> |
| 178 | class ExpectBetweenColors; |
Jiawei Shao | 93373ab | 2019-05-29 00:07:37 +0000 | [diff] [blame] | 179 | } // namespace detail |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 180 | |
Corentin Wallez | bdc8677 | 2018-07-26 15:07:57 +0200 | [diff] [blame] | 181 | namespace dawn_wire { |
Austin Eng | cbc206e | 2019-12-10 23:32:48 +0000 | [diff] [blame] | 182 | class CommandHandler; |
Austin Eng | e2c8513 | 2019-02-11 21:50:16 +0000 | [diff] [blame] | 183 | class WireClient; |
| 184 | class WireServer; |
Corentin Wallez | bdc8677 | 2018-07-26 15:07:57 +0200 | [diff] [blame] | 185 | } // namespace dawn_wire |
Corentin Wallez | 419e984 | 2018-06-07 13:10:44 +0200 | [diff] [blame] | 186 | |
Corentin Wallez | 0b2f552 | 2019-02-21 16:29:12 +0000 | [diff] [blame] | 187 | void InitDawnEnd2EndTestEnvironment(int argc, char** argv); |
| 188 | |
| 189 | class DawnTestEnvironment : public testing::Environment { |
| 190 | public: |
| 191 | DawnTestEnvironment(int argc, char** argv); |
Austin Eng | f580096 | 2020-08-14 21:02:12 +0000 | [diff] [blame] | 192 | ~DawnTestEnvironment() override; |
Corentin Wallez | 0b2f552 | 2019-02-21 16:29:12 +0000 | [diff] [blame] | 193 | |
Austin Eng | ca0eac3 | 2019-08-28 23:18:10 +0000 | [diff] [blame] | 194 | static void SetEnvironment(DawnTestEnvironment* env); |
| 195 | |
Austin Eng | da722ad | 2020-05-15 20:28:05 +0000 | [diff] [blame] | 196 | std::vector<AdapterTestParam> GetAvailableAdapterTestParamsForBackends( |
| 197 | const BackendTestConfig* params, |
| 198 | size_t numParams); |
Austin Eng | 25c747c | 2020-05-15 16:07:12 +0000 | [diff] [blame] | 199 | |
Corentin Wallez | 0b2f552 | 2019-02-21 16:29:12 +0000 | [diff] [blame] | 200 | void SetUp() override; |
Jiajie Hu | 9e5b9ed | 2019-11-20 09:45:41 +0000 | [diff] [blame] | 201 | void TearDown() override; |
Corentin Wallez | 0b2f552 | 2019-02-21 16:29:12 +0000 | [diff] [blame] | 202 | |
Corentin Wallez | 0ee9859 | 2019-05-01 12:57:27 +0000 | [diff] [blame] | 203 | bool UsesWire() const; |
Brandon Jones | bdbf98a | 2021-02-04 19:32:12 +0000 | [diff] [blame] | 204 | dawn_native::BackendValidationLevel GetBackendValidationLevel() const; |
Corentin Wallez | 0b2f552 | 2019-02-21 16:29:12 +0000 | [diff] [blame] | 205 | dawn_native::Instance* GetInstance() const; |
Li, Hao | 35716c2 | 2019-07-08 03:25:54 +0000 | [diff] [blame] | 206 | bool HasVendorIdFilter() const; |
| 207 | uint32_t GetVendorIdFilter() const; |
Stephen White | eb71aaf | 2021-02-17 17:07:08 +0000 | [diff] [blame] | 208 | bool HasBackendTypeFilter() const; |
| 209 | wgpu::BackendType GetBackendTypeFilter() const; |
Austin Eng | cbc206e | 2019-12-10 23:32:48 +0000 | [diff] [blame] | 210 | const char* GetWireTraceDir() const; |
Stephen White | d45ab07 | 2020-11-25 16:45:04 +0000 | [diff] [blame] | 211 | GLFWwindow* GetOpenGLWindow() const; |
| 212 | GLFWwindow* GetOpenGLESWindow() const; |
Corentin Wallez | 0b2f552 | 2019-02-21 16:29:12 +0000 | [diff] [blame] | 213 | |
Austin Eng | b38a9c3 | 2020-11-14 01:09:23 +0000 | [diff] [blame] | 214 | const std::vector<std::string>& GetEnabledToggles() const; |
| 215 | const std::vector<std::string>& GetDisabledToggles() const; |
| 216 | |
Austin Eng | 92a011a | 2019-10-17 19:00:32 +0000 | [diff] [blame] | 217 | protected: |
| 218 | std::unique_ptr<dawn_native::Instance> mInstance; |
| 219 | |
Corentin Wallez | 0b2f552 | 2019-02-21 16:29:12 +0000 | [diff] [blame] | 220 | private: |
Austin Eng | 25c747c | 2020-05-15 16:07:12 +0000 | [diff] [blame] | 221 | void ParseArgs(int argc, char** argv); |
Stephen White | d45ab07 | 2020-11-25 16:45:04 +0000 | [diff] [blame] | 222 | std::unique_ptr<dawn_native::Instance> CreateInstanceAndDiscoverAdapters(); |
Austin Eng | da722ad | 2020-05-15 20:28:05 +0000 | [diff] [blame] | 223 | void SelectPreferredAdapterProperties(const dawn_native::Instance* instance); |
Austin Eng | b38a9c3 | 2020-11-14 01:09:23 +0000 | [diff] [blame] | 224 | void PrintTestConfigurationAndAdapterInfo(dawn_native::Instance* instance) const; |
Corentin Wallez | 0b2f552 | 2019-02-21 16:29:12 +0000 | [diff] [blame] | 225 | |
| 226 | bool mUseWire = false; |
Brandon Jones | bdbf98a | 2021-02-04 19:32:12 +0000 | [diff] [blame] | 227 | dawn_native::BackendValidationLevel mBackendValidationLevel = |
| 228 | dawn_native::BackendValidationLevel::Disabled; |
Rafael Cintron | 4729b15 | 2019-06-21 02:09:05 +0000 | [diff] [blame] | 229 | bool mBeginCaptureOnStartup = false; |
Li, Hao | 35716c2 | 2019-07-08 03:25:54 +0000 | [diff] [blame] | 230 | bool mHasVendorIdFilter = false; |
| 231 | uint32_t mVendorIdFilter = 0; |
Stephen White | eb71aaf | 2021-02-17 17:07:08 +0000 | [diff] [blame] | 232 | bool mHasBackendTypeFilter = false; |
| 233 | wgpu::BackendType mBackendTypeFilter; |
Austin Eng | cbc206e | 2019-12-10 23:32:48 +0000 | [diff] [blame] | 234 | std::string mWireTraceDir; |
Austin Eng | b38a9c3 | 2020-11-14 01:09:23 +0000 | [diff] [blame] | 235 | |
Ryan Harrison | acdc35d | 2021-04-14 14:55:07 +0000 | [diff] [blame] | 236 | ToggleParser mToggleParser; |
| 237 | |
Austin Eng | da722ad | 2020-05-15 20:28:05 +0000 | [diff] [blame] | 238 | std::vector<dawn_native::DeviceType> mDevicePreferences; |
Austin Eng | 25c747c | 2020-05-15 16:07:12 +0000 | [diff] [blame] | 239 | std::vector<TestAdapterProperties> mAdapterProperties; |
Austin Eng | f580096 | 2020-08-14 21:02:12 +0000 | [diff] [blame] | 240 | |
| 241 | std::unique_ptr<utils::PlatformDebugLogger> mPlatformDebugLogger; |
Stephen White | d45ab07 | 2020-11-25 16:45:04 +0000 | [diff] [blame] | 242 | GLFWwindow* mOpenGLWindow; |
| 243 | GLFWwindow* mOpenGLESWindow; |
Corentin Wallez | 0b2f552 | 2019-02-21 16:29:12 +0000 | [diff] [blame] | 244 | }; |
| 245 | |
Austin Eng | ca0eac3 | 2019-08-28 23:18:10 +0000 | [diff] [blame] | 246 | class DawnTestBase { |
| 247 | friend class DawnPerfTestBase; |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 248 | |
Austin Eng | ca0eac3 | 2019-08-28 23:18:10 +0000 | [diff] [blame] | 249 | public: |
Austin Eng | da722ad | 2020-05-15 20:28:05 +0000 | [diff] [blame] | 250 | DawnTestBase(const AdapterTestParam& param); |
Austin Eng | ca0eac3 | 2019-08-28 23:18:10 +0000 | [diff] [blame] | 251 | virtual ~DawnTestBase(); |
| 252 | |
| 253 | void SetUp(); |
| 254 | void TearDown(); |
Corentin Wallez | 134e080 | 2017-07-17 17:13:57 -0400 | [diff] [blame] | 255 | |
Corentin Wallez | 419e984 | 2018-06-07 13:10:44 +0200 | [diff] [blame] | 256 | bool IsD3D12() const; |
| 257 | bool IsMetal() const; |
Corentin Wallez | 11652ff | 2020-03-20 17:07:20 +0000 | [diff] [blame] | 258 | bool IsNull() const; |
Corentin Wallez | 419e984 | 2018-06-07 13:10:44 +0200 | [diff] [blame] | 259 | bool IsOpenGL() const; |
Stephen White | d45ab07 | 2020-11-25 16:45:04 +0000 | [diff] [blame] | 260 | bool IsOpenGLES() const; |
Corentin Wallez | 419e984 | 2018-06-07 13:10:44 +0200 | [diff] [blame] | 261 | bool IsVulkan() const; |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 262 | |
Jiawei Shao | 58809d4 | 2018-09-19 00:32:52 +0000 | [diff] [blame] | 263 | bool IsAMD() const; |
| 264 | bool IsARM() const; |
| 265 | bool IsImgTec() const; |
| 266 | bool IsIntel() const; |
| 267 | bool IsNvidia() const; |
| 268 | bool IsQualcomm() const; |
Corentin Wallez | d56b69f | 2020-04-09 08:16:30 +0000 | [diff] [blame] | 269 | bool IsSwiftshader() const; |
Stephen White | f09a670 | 2021-01-18 17:47:07 +0000 | [diff] [blame] | 270 | bool IsANGLE() const; |
Bryan Bernhart | 8c255ac | 2020-07-10 22:58:48 +0000 | [diff] [blame] | 271 | bool IsWARP() const; |
Jiawei Shao | 58809d4 | 2018-09-19 00:32:52 +0000 | [diff] [blame] | 272 | |
| 273 | bool IsWindows() const; |
| 274 | bool IsLinux() const; |
| 275 | bool IsMacOS() const; |
| 276 | |
Corentin Wallez | 0ee9859 | 2019-05-01 12:57:27 +0000 | [diff] [blame] | 277 | bool UsesWire() const; |
Li, Hao | 6fa398e | 2019-06-25 00:49:56 +0000 | [diff] [blame] | 278 | bool IsBackendValidationEnabled() const; |
Corentin Wallez | 0ee9859 | 2019-05-01 12:57:27 +0000 | [diff] [blame] | 279 | |
Austin Eng | 0e9e5ee | 2020-06-19 17:35:33 +0000 | [diff] [blame] | 280 | bool IsAsan() const; |
| 281 | |
Enrico Galli | 2b6b0f4 | 2020-11-05 18:52:49 +0000 | [diff] [blame] | 282 | bool HasToggleEnabled(const char* workaround) const; |
| 283 | |
Corentin Wallez | 2dfb3f0 | 2019-02-28 09:45:48 +0000 | [diff] [blame] | 284 | void StartExpectDeviceError(); |
| 285 | bool EndExpectDeviceError(); |
| 286 | |
Li, Hao | 35716c2 | 2019-07-08 03:25:54 +0000 | [diff] [blame] | 287 | bool HasVendorIdFilter() const; |
| 288 | uint32_t GetVendorIdFilter() const; |
| 289 | |
Stephen White | eb71aaf | 2021-02-17 17:07:08 +0000 | [diff] [blame] | 290 | bool HasBackendTypeFilter() const; |
| 291 | wgpu::BackendType GetBackendTypeFilter() const; |
| 292 | |
Corentin Wallez | 11652ff | 2020-03-20 17:07:20 +0000 | [diff] [blame] | 293 | wgpu::Instance GetInstance() const; |
| 294 | dawn_native::Adapter GetAdapter() const; |
| 295 | |
Bryan Bernhart | 41b3f9c | 2020-11-20 20:38:37 +0000 | [diff] [blame] | 296 | virtual std::unique_ptr<dawn_platform::Platform> CreateTestPlatform(); |
| 297 | |
Corentin Wallez | 419e984 | 2018-06-07 13:10:44 +0200 | [diff] [blame] | 298 | protected: |
Corentin Wallez | cab352c | 2019-10-28 13:27:36 +0000 | [diff] [blame] | 299 | wgpu::Device device; |
| 300 | wgpu::Queue queue; |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 301 | |
Austin Eng | 8aa036e | 2019-05-24 22:31:36 +0000 | [diff] [blame] | 302 | DawnProcTable backendProcs = {}; |
Corentin Wallez | cab352c | 2019-10-28 13:27:36 +0000 | [diff] [blame] | 303 | WGPUDevice backendDevice = nullptr; |
Austin Eng | 8aa036e | 2019-05-24 22:31:36 +0000 | [diff] [blame] | 304 | |
Kai Ninomiya | 2bb8035 | 2020-10-28 21:23:45 +0000 | [diff] [blame] | 305 | size_t mLastWarningCount = 0; |
| 306 | |
Corentin Wallez | 419e984 | 2018-06-07 13:10:44 +0200 | [diff] [blame] | 307 | // Helper methods to implement the EXPECT_ macros |
| 308 | std::ostringstream& AddBufferExpectation(const char* file, |
| 309 | int line, |
Corentin Wallez | cab352c | 2019-10-28 13:27:36 +0000 | [diff] [blame] | 310 | const wgpu::Buffer& buffer, |
Austin Eng | cf52d71 | 2019-04-05 20:51:29 +0000 | [diff] [blame] | 311 | uint64_t offset, |
| 312 | uint64_t size, |
Corentin Wallez | 419e984 | 2018-06-07 13:10:44 +0200 | [diff] [blame] | 313 | detail::Expectation* expectation); |
Austin Eng | 0a43427 | 2020-08-04 19:46:37 +0000 | [diff] [blame] | 314 | |
| 315 | template <typename T> |
Corentin Wallez | 419e984 | 2018-06-07 13:10:44 +0200 | [diff] [blame] | 316 | std::ostringstream& AddTextureExpectation(const char* file, |
| 317 | int line, |
Austin Eng | 0a43427 | 2020-08-04 19:46:37 +0000 | [diff] [blame] | 318 | const T* expectedData, |
Corentin Wallez | cab352c | 2019-10-28 13:27:36 +0000 | [diff] [blame] | 319 | const wgpu::Texture& texture, |
Yunchao He | 4eb40c1 | 2021-03-31 22:15:53 +0000 | [diff] [blame] | 320 | wgpu::Origin3D origin, |
| 321 | wgpu::Extent3D extent, |
Austin Eng | 0a43427 | 2020-08-04 19:46:37 +0000 | [diff] [blame] | 322 | uint32_t level = 0, |
Austin Eng | 0a43427 | 2020-08-04 19:46:37 +0000 | [diff] [blame] | 323 | wgpu::TextureAspect aspect = wgpu::TextureAspect::All, |
| 324 | uint32_t bytesPerRow = 0) { |
| 325 | return AddTextureExpectationImpl( |
Yunchao He | 4eb40c1 | 2021-03-31 22:15:53 +0000 | [diff] [blame] | 326 | file, line, |
| 327 | new detail::ExpectEq<T>(expectedData, |
| 328 | extent.width * extent.height * extent.depthOrArrayLayers), |
Yunchao He | ff55b2f | 2021-04-07 16:57:11 +0000 | [diff] [blame] | 329 | texture, origin, extent, level, aspect, sizeof(T), bytesPerRow); |
Austin Eng | 0a43427 | 2020-08-04 19:46:37 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | template <typename T> |
| 333 | std::ostringstream& AddTextureExpectation(const char* file, |
| 334 | int line, |
| 335 | const T& expectedData, |
| 336 | const wgpu::Texture& texture, |
Yunchao He | 4eb40c1 | 2021-03-31 22:15:53 +0000 | [diff] [blame] | 337 | wgpu::Origin3D origin, |
Austin Eng | 0a43427 | 2020-08-04 19:46:37 +0000 | [diff] [blame] | 338 | uint32_t level = 0, |
Austin Eng | 0a43427 | 2020-08-04 19:46:37 +0000 | [diff] [blame] | 339 | wgpu::TextureAspect aspect = wgpu::TextureAspect::All, |
| 340 | uint32_t bytesPerRow = 0) { |
| 341 | return AddTextureExpectationImpl(file, line, new detail::ExpectEq<T>(expectedData), texture, |
Yunchao He | ff55b2f | 2021-04-07 16:57:11 +0000 | [diff] [blame] | 342 | origin, {1, 1}, level, aspect, sizeof(T), bytesPerRow); |
Austin Eng | 0a43427 | 2020-08-04 19:46:37 +0000 | [diff] [blame] | 343 | } |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 344 | |
shrekshao | f8c5e4a | 2020-12-24 03:11:17 +0000 | [diff] [blame] | 345 | template <typename T> |
| 346 | std::ostringstream& AddTextureBetweenColorsExpectation( |
| 347 | const char* file, |
| 348 | int line, |
| 349 | const T& color0, |
| 350 | const T& color1, |
| 351 | const wgpu::Texture& texture, |
| 352 | uint32_t x, |
| 353 | uint32_t y, |
| 354 | uint32_t level = 0, |
shrekshao | f8c5e4a | 2020-12-24 03:11:17 +0000 | [diff] [blame] | 355 | wgpu::TextureAspect aspect = wgpu::TextureAspect::All, |
| 356 | uint32_t bytesPerRow = 0) { |
| 357 | return AddTextureExpectationImpl( |
Yunchao He | 4eb40c1 | 2021-03-31 22:15:53 +0000 | [diff] [blame] | 358 | file, line, new detail::ExpectBetweenColors<T>(color0, color1), texture, {x, y}, {1, 1}, |
Yunchao He | ff55b2f | 2021-04-07 16:57:11 +0000 | [diff] [blame] | 359 | level, aspect, sizeof(T), bytesPerRow); |
shrekshao | f8c5e4a | 2020-12-24 03:11:17 +0000 | [diff] [blame] | 360 | } |
| 361 | |
Corentin Wallez | 419e984 | 2018-06-07 13:10:44 +0200 | [diff] [blame] | 362 | void WaitABit(); |
Corentin Wallez | cc14179 | 2019-05-01 12:07:37 +0000 | [diff] [blame] | 363 | void FlushWire(); |
Natasha Lee | 51af1b4 | 2020-10-12 22:32:33 +0000 | [diff] [blame] | 364 | void WaitForAllOperations(); |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 365 | |
Jiawei Shao | 574b951 | 2019-08-02 00:06:38 +0000 | [diff] [blame] | 366 | bool SupportsExtensions(const std::vector<const char*>& extensions); |
| 367 | |
| 368 | // Called in SetUp() to get the extensions required to be enabled in the tests. The tests must |
| 369 | // check if the required extensions are supported by the adapter in this function and guarantee |
| 370 | // the returned extensions are all supported by the adapter. The tests may provide different |
| 371 | // code path to handle the situation when not all extensions are supported. |
| 372 | virtual std::vector<const char*> GetRequiredExtensions(); |
| 373 | |
Corentin Wallez | f12c9db | 2020-01-10 13:28:18 +0000 | [diff] [blame] | 374 | const wgpu::AdapterProperties& GetAdapterProperties() const; |
| 375 | |
Corentin Wallez | 419e984 | 2018-06-07 13:10:44 +0200 | [diff] [blame] | 376 | private: |
Austin Eng | da722ad | 2020-05-15 20:28:05 +0000 | [diff] [blame] | 377 | AdapterTestParam mParam; |
Austin Eng | e58d5a3 | 2021-01-27 22:54:04 +0000 | [diff] [blame] | 378 | std::unique_ptr<utils::WireHelper> mWireHelper; |
Austin Eng | cbc206e | 2019-12-10 23:32:48 +0000 | [diff] [blame] | 379 | |
Corentin Wallez | 2dfb3f0 | 2019-02-28 09:45:48 +0000 | [diff] [blame] | 380 | // Tracking for validation errors |
Corentin Wallez | cab352c | 2019-10-28 13:27:36 +0000 | [diff] [blame] | 381 | static void OnDeviceError(WGPUErrorType type, const char* message, void* userdata); |
Natasha Lee | 0ecc48e | 2020-01-15 19:02:13 +0000 | [diff] [blame] | 382 | static void OnDeviceLost(const char* message, void* userdata); |
Corentin Wallez | 2dfb3f0 | 2019-02-28 09:45:48 +0000 | [diff] [blame] | 383 | bool mExpectError = false; |
| 384 | bool mError = false; |
| 385 | |
Austin Eng | 0a43427 | 2020-08-04 19:46:37 +0000 | [diff] [blame] | 386 | std::ostringstream& AddTextureExpectationImpl(const char* file, |
| 387 | int line, |
| 388 | detail::Expectation* expectation, |
| 389 | const wgpu::Texture& texture, |
Yunchao He | 4eb40c1 | 2021-03-31 22:15:53 +0000 | [diff] [blame] | 390 | wgpu::Origin3D origin, |
| 391 | wgpu::Extent3D extent, |
Austin Eng | 0a43427 | 2020-08-04 19:46:37 +0000 | [diff] [blame] | 392 | uint32_t level, |
Austin Eng | 0a43427 | 2020-08-04 19:46:37 +0000 | [diff] [blame] | 393 | wgpu::TextureAspect aspect, |
| 394 | uint32_t dataSize, |
| 395 | uint32_t bytesPerRow); |
| 396 | |
Corentin Wallez | 419e984 | 2018-06-07 13:10:44 +0200 | [diff] [blame] | 397 | // MapRead buffers used to get data for the expectations |
| 398 | struct ReadbackSlot { |
Corentin Wallez | cab352c | 2019-10-28 13:27:36 +0000 | [diff] [blame] | 399 | wgpu::Buffer buffer; |
Austin Eng | cf52d71 | 2019-04-05 20:51:29 +0000 | [diff] [blame] | 400 | uint64_t bufferSize; |
Corentin Wallez | 419e984 | 2018-06-07 13:10:44 +0200 | [diff] [blame] | 401 | const void* mappedData = nullptr; |
| 402 | }; |
| 403 | std::vector<ReadbackSlot> mReadbackSlots; |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 404 | |
Corentin Wallez | 419e984 | 2018-06-07 13:10:44 +0200 | [diff] [blame] | 405 | // Maps all the buffers and fill ReadbackSlot::mappedData |
| 406 | void MapSlotsSynchronously(); |
Corentin Wallez | 2a232ba | 2020-07-16 16:35:40 +0000 | [diff] [blame] | 407 | static void SlotMapCallback(WGPUBufferMapAsyncStatus status, void* userdata); |
Corentin Wallez | 419e984 | 2018-06-07 13:10:44 +0200 | [diff] [blame] | 408 | size_t mNumPendingMapOperations = 0; |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 409 | |
Corentin Wallez | 419e984 | 2018-06-07 13:10:44 +0200 | [diff] [blame] | 410 | // Reserve space where the data for an expectation can be copied |
| 411 | struct ReadbackReservation { |
Corentin Wallez | cab352c | 2019-10-28 13:27:36 +0000 | [diff] [blame] | 412 | wgpu::Buffer buffer; |
Corentin Wallez | 419e984 | 2018-06-07 13:10:44 +0200 | [diff] [blame] | 413 | size_t slot; |
Austin Eng | cf52d71 | 2019-04-05 20:51:29 +0000 | [diff] [blame] | 414 | uint64_t offset; |
Corentin Wallez | 419e984 | 2018-06-07 13:10:44 +0200 | [diff] [blame] | 415 | }; |
Austin Eng | cf52d71 | 2019-04-05 20:51:29 +0000 | [diff] [blame] | 416 | ReadbackReservation ReserveReadback(uint64_t readbackSize); |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 417 | |
Corentin Wallez | 419e984 | 2018-06-07 13:10:44 +0200 | [diff] [blame] | 418 | struct DeferredExpectation { |
| 419 | const char* file; |
| 420 | int line; |
| 421 | size_t readbackSlot; |
Austin Eng | cf52d71 | 2019-04-05 20:51:29 +0000 | [diff] [blame] | 422 | uint64_t readbackOffset; |
| 423 | uint64_t size; |
Corentin Wallez | 419e984 | 2018-06-07 13:10:44 +0200 | [diff] [blame] | 424 | uint32_t rowBytes; |
Corentin Wallez | cdf2d8d | 2020-04-24 10:02:43 +0000 | [diff] [blame] | 425 | uint32_t bytesPerRow; |
Corentin Wallez | cca9c69 | 2018-09-06 15:26:48 +0200 | [diff] [blame] | 426 | std::unique_ptr<detail::Expectation> expectation; |
Corentin Wallez | 419e984 | 2018-06-07 13:10:44 +0200 | [diff] [blame] | 427 | // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54316 |
| 428 | // Use unique_ptr because of missing move/copy constructors on std::basic_ostringstream |
| 429 | std::unique_ptr<std::ostringstream> message; |
| 430 | }; |
| 431 | std::vector<DeferredExpectation> mDeferredExpectations; |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 432 | |
Corentin Wallez | 419e984 | 2018-06-07 13:10:44 +0200 | [diff] [blame] | 433 | // Assuming the data is mapped, checks all expectations |
| 434 | void ResolveExpectations(); |
| 435 | |
Jiawei Shao | 574b951 | 2019-08-02 00:06:38 +0000 | [diff] [blame] | 436 | dawn_native::Adapter mBackendAdapter; |
Bryan Bernhart | 41b3f9c | 2020-11-20 20:38:37 +0000 | [diff] [blame] | 437 | |
| 438 | std::unique_ptr<dawn_platform::Platform> mTestPlatform; |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 439 | }; |
| 440 | |
Austin Eng | e79b061 | 2019-10-09 16:23:22 +0000 | [diff] [blame] | 441 | // Skip a test when the given condition is satisfied. |
Zhenyao Mo | 5b7292c | 2020-04-11 03:22:33 +0000 | [diff] [blame] | 442 | #define DAWN_SKIP_TEST_IF(condition) \ |
| 443 | do { \ |
| 444 | if (condition) { \ |
| 445 | dawn::InfoLog() << "Test skipped: " #condition "."; \ |
| 446 | GTEST_SKIP(); \ |
| 447 | return; \ |
| 448 | } \ |
| 449 | } while (0) |
Austin Eng | e79b061 | 2019-10-09 16:23:22 +0000 | [diff] [blame] | 450 | |
Kai Ninomiya | 2bb8035 | 2020-10-28 21:23:45 +0000 | [diff] [blame] | 451 | #define EXPECT_DEPRECATION_WARNING(statement) \ |
| 452 | do { \ |
| 453 | if (UsesWire()) { \ |
| 454 | statement; \ |
| 455 | } else { \ |
| 456 | size_t warningsBefore = \ |
| 457 | dawn_native::GetDeprecationWarningCountForTesting(device.Get()); \ |
| 458 | statement; \ |
| 459 | size_t warningsAfter = \ |
| 460 | dawn_native::GetDeprecationWarningCountForTesting(device.Get()); \ |
| 461 | EXPECT_EQ(mLastWarningCount, warningsBefore); \ |
Austin Eng | b38a9c3 | 2020-11-14 01:09:23 +0000 | [diff] [blame] | 462 | if (!HasToggleEnabled("skip_validation")) { \ |
Kai Ninomiya | 2bb8035 | 2020-10-28 21:23:45 +0000 | [diff] [blame] | 463 | EXPECT_EQ(warningsAfter, warningsBefore + 1); \ |
| 464 | } \ |
| 465 | mLastWarningCount = warningsAfter; \ |
| 466 | } \ |
| 467 | } while (0) |
| 468 | |
Austin Eng | da722ad | 2020-05-15 20:28:05 +0000 | [diff] [blame] | 469 | template <typename Params = AdapterTestParam> |
Austin Eng | ca0eac3 | 2019-08-28 23:18:10 +0000 | [diff] [blame] | 470 | class DawnTestWithParams : public DawnTestBase, public ::testing::TestWithParam<Params> { |
| 471 | protected: |
| 472 | DawnTestWithParams(); |
| 473 | ~DawnTestWithParams() override = default; |
| 474 | |
Austin Eng | 40dc5d3 | 2020-05-15 22:06:35 +0000 | [diff] [blame] | 475 | void SetUp() override { |
| 476 | DawnTestBase::SetUp(); |
Austin Eng | ca0eac3 | 2019-08-28 23:18:10 +0000 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | void TearDown() override { |
| 480 | DawnTestBase::TearDown(); |
| 481 | } |
| 482 | }; |
| 483 | |
| 484 | template <typename Params> |
| 485 | DawnTestWithParams<Params>::DawnTestWithParams() : DawnTestBase(this->GetParam()) { |
| 486 | } |
| 487 | |
| 488 | using DawnTest = DawnTestWithParams<>; |
| 489 | |
Corentin Wallez | 60bb88d | 2020-05-13 08:01:55 +0000 | [diff] [blame] | 490 | // Helpers to get the first element of a __VA_ARGS__ without triggering empty __VA_ARGS__ warnings. |
| 491 | #define DAWN_INTERNAL_PP_GET_HEAD(firstParam, ...) firstParam |
| 492 | #define DAWN_PP_GET_HEAD(...) DAWN_INTERNAL_PP_GET_HEAD(__VA_ARGS__, dummyArg) |
| 493 | |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 494 | // Instantiate the test once for each backend provided after the first argument. Use it like this: |
Corentin Wallez | ae187ef | 2018-07-18 15:16:37 +0200 | [diff] [blame] | 495 | // DAWN_INSTANTIATE_TEST(MyTestFixture, MetalBackend, OpenGLBackend) |
Corentin Wallez | 60bb88d | 2020-05-13 08:01:55 +0000 | [diff] [blame] | 496 | #define DAWN_INSTANTIATE_TEST(testName, ...) \ |
| 497 | const decltype(DAWN_PP_GET_HEAD(__VA_ARGS__)) testName##params[] = {__VA_ARGS__}; \ |
| 498 | INSTANTIATE_TEST_SUITE_P( \ |
| 499 | , testName, \ |
Austin Eng | da722ad | 2020-05-15 20:28:05 +0000 | [diff] [blame] | 500 | testing::ValuesIn(::detail::GetAvailableAdapterTestParamsForBackends( \ |
Corentin Wallez | 60bb88d | 2020-05-13 08:01:55 +0000 | [diff] [blame] | 501 | testName##params, sizeof(testName##params) / sizeof(testName##params[0]))), \ |
Corentin Wallez | bf1e953 | 2020-11-04 09:44:47 +0000 | [diff] [blame] | 502 | testing::PrintToStringParamName()); \ |
| 503 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(testName) |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 504 | |
| 505 | namespace detail { |
Corentin Wallez | ae187ef | 2018-07-18 15:16:37 +0200 | [diff] [blame] | 506 | // Helper functions used for DAWN_INSTANTIATE_TEST |
Corentin Wallez | f12c9db | 2020-01-10 13:28:18 +0000 | [diff] [blame] | 507 | bool IsBackendAvailable(wgpu::BackendType type); |
Austin Eng | da722ad | 2020-05-15 20:28:05 +0000 | [diff] [blame] | 508 | std::vector<AdapterTestParam> GetAvailableAdapterTestParamsForBackends( |
| 509 | const BackendTestConfig* params, |
| 510 | size_t numParams); |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 511 | |
| 512 | // All classes used to implement the deferred expectations should inherit from this. |
| 513 | class Expectation { |
Corentin Wallez | a4da032 | 2018-07-18 15:18:25 +0200 | [diff] [blame] | 514 | public: |
| 515 | virtual ~Expectation() = default; |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 516 | |
Corentin Wallez | a4da032 | 2018-07-18 15:18:25 +0200 | [diff] [blame] | 517 | // Will be called with the buffer or texture data the expectation should check. |
| 518 | virtual testing::AssertionResult Check(const void* data, size_t size) = 0; |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 519 | }; |
| 520 | |
| 521 | // Expectation that checks the data is equal to some expected values. |
Corentin Wallez | a4da032 | 2018-07-18 15:18:25 +0200 | [diff] [blame] | 522 | template <typename T> |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 523 | class ExpectEq : public Expectation { |
Corentin Wallez | a4da032 | 2018-07-18 15:18:25 +0200 | [diff] [blame] | 524 | public: |
| 525 | ExpectEq(T singleValue); |
| 526 | ExpectEq(const T* values, const unsigned int count); |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 527 | |
Corentin Wallez | a4da032 | 2018-07-18 15:18:25 +0200 | [diff] [blame] | 528 | testing::AssertionResult Check(const void* data, size_t size) override; |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 529 | |
Corentin Wallez | a4da032 | 2018-07-18 15:18:25 +0200 | [diff] [blame] | 530 | private: |
| 531 | std::vector<T> mExpected; |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 532 | }; |
Stephen White | e5ae327 | 2018-02-04 11:07:02 -0500 | [diff] [blame] | 533 | extern template class ExpectEq<uint8_t>; |
Xinghua Cao | db8f804 | 2020-06-08 12:18:21 +0000 | [diff] [blame] | 534 | extern template class ExpectEq<int16_t>; |
Corentin Wallez | eaae746 | 2017-06-16 18:34:35 -0400 | [diff] [blame] | 535 | extern template class ExpectEq<uint32_t>; |
Hao Li | c0acb25 | 2020-08-04 06:41:56 +0000 | [diff] [blame] | 536 | extern template class ExpectEq<uint64_t>; |
Corentin Wallez | 4cd65f0 | 2017-06-27 00:11:16 -0400 | [diff] [blame] | 537 | extern template class ExpectEq<RGBA8>; |
Austin Eng | 0d66198 | 2020-01-16 00:12:10 +0000 | [diff] [blame] | 538 | extern template class ExpectEq<float>; |
shrekshao | f8c5e4a | 2020-12-24 03:11:17 +0000 | [diff] [blame] | 539 | |
| 540 | template <typename T> |
| 541 | class ExpectBetweenColors : public Expectation { |
| 542 | public: |
| 543 | // Inclusive for now |
| 544 | ExpectBetweenColors(T value0, T value1); |
| 545 | testing::AssertionResult Check(const void* data, size_t size) override; |
| 546 | |
| 547 | private: |
| 548 | std::vector<T> mLowerColorChannels; |
| 549 | std::vector<T> mHigherColorChannels; |
| 550 | |
| 551 | // used for printing error |
| 552 | std::vector<T> mValues0; |
| 553 | std::vector<T> mValues1; |
| 554 | }; |
| 555 | // A color is considered between color0 and color1 when all channel values are within range of |
| 556 | // each counterparts. It doesn't matter which value is higher or lower. Essentially color = |
| 557 | // lerp(color0, color1, t) where t is [0,1]. But I don't want to be too strict here. |
| 558 | extern template class ExpectBetweenColors<RGBA8>; |
Corentin Wallez | a4da032 | 2018-07-18 15:18:25 +0200 | [diff] [blame] | 559 | } // namespace detail |
Austin Eng | ca0eac3 | 2019-08-28 23:18:10 +0000 | [diff] [blame] | 560 | |
| 561 | #endif // TESTS_DAWNTEST_H_ |