Corentin Wallez | 0ae00a1 | 2019-03-28 17:12:47 +0000 | [diff] [blame] | 1 | // Copyright 2019 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 | #include "tests/unittests/wire/WireTest.h" |
| 16 | |
Austin Eng | b70a5b0 | 2020-11-11 21:01:18 +0000 | [diff] [blame] | 17 | #include "dawn_wire/WireClient.h" |
| 18 | |
Corentin Wallez | 0ae00a1 | 2019-03-28 17:12:47 +0000 | [diff] [blame] | 19 | using namespace testing; |
| 20 | using namespace dawn_wire; |
| 21 | |
| 22 | namespace { |
| 23 | |
| 24 | // Mock classes to add expectations on the wire calling callbacks |
| 25 | class MockDeviceErrorCallback { |
| 26 | public: |
Corentin Wallez | f941205 | 2020-04-16 16:39:06 +0000 | [diff] [blame] | 27 | MOCK_METHOD(void, Call, (WGPUErrorType type, const char* message, void* userdata)); |
Corentin Wallez | 0ae00a1 | 2019-03-28 17:12:47 +0000 | [diff] [blame] | 28 | }; |
| 29 | |
| 30 | std::unique_ptr<StrictMock<MockDeviceErrorCallback>> mockDeviceErrorCallback; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 31 | void ToMockDeviceErrorCallback(WGPUErrorType type, const char* message, void* userdata) { |
Austin Eng | cb0cb65 | 2019-08-27 21:41:56 +0000 | [diff] [blame] | 32 | mockDeviceErrorCallback->Call(type, message, userdata); |
Corentin Wallez | 0ae00a1 | 2019-03-28 17:12:47 +0000 | [diff] [blame] | 33 | } |
| 34 | |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 35 | class MockDevicePopErrorScopeCallback { |
| 36 | public: |
Corentin Wallez | f941205 | 2020-04-16 16:39:06 +0000 | [diff] [blame] | 37 | MOCK_METHOD(void, Call, (WGPUErrorType type, const char* message, void* userdata)); |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | std::unique_ptr<StrictMock<MockDevicePopErrorScopeCallback>> mockDevicePopErrorScopeCallback; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 41 | void ToMockDevicePopErrorScopeCallback(WGPUErrorType type, |
| 42 | const char* message, |
| 43 | void* userdata) { |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 44 | mockDevicePopErrorScopeCallback->Call(type, message, userdata); |
| 45 | } |
| 46 | |
Natasha Lee | 9bba4a9 | 2019-12-18 18:59:20 +0000 | [diff] [blame] | 47 | class MockDeviceLostCallback { |
| 48 | public: |
Corentin Wallez | f941205 | 2020-04-16 16:39:06 +0000 | [diff] [blame] | 49 | MOCK_METHOD(void, Call, (const char* message, void* userdata)); |
Natasha Lee | 9bba4a9 | 2019-12-18 18:59:20 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | std::unique_ptr<StrictMock<MockDeviceLostCallback>> mockDeviceLostCallback; |
| 53 | void ToMockDeviceLostCallback(const char* message, void* userdata) { |
| 54 | mockDeviceLostCallback->Call(message, userdata); |
| 55 | } |
| 56 | |
Corentin Wallez | 0ae00a1 | 2019-03-28 17:12:47 +0000 | [diff] [blame] | 57 | } // anonymous namespace |
| 58 | |
| 59 | class WireErrorCallbackTests : public WireTest { |
| 60 | public: |
| 61 | WireErrorCallbackTests() { |
| 62 | } |
| 63 | ~WireErrorCallbackTests() override = default; |
| 64 | |
| 65 | void SetUp() override { |
| 66 | WireTest::SetUp(); |
| 67 | |
| 68 | mockDeviceErrorCallback = std::make_unique<StrictMock<MockDeviceErrorCallback>>(); |
Kai Ninomiya | 2afea0c | 2020-07-10 20:33:08 +0000 | [diff] [blame] | 69 | mockDevicePopErrorScopeCallback = |
| 70 | std::make_unique<StrictMock<MockDevicePopErrorScopeCallback>>(); |
Natasha Lee | 9bba4a9 | 2019-12-18 18:59:20 +0000 | [diff] [blame] | 71 | mockDeviceLostCallback = std::make_unique<StrictMock<MockDeviceLostCallback>>(); |
Corentin Wallez | 0ae00a1 | 2019-03-28 17:12:47 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | void TearDown() override { |
| 75 | WireTest::TearDown(); |
| 76 | |
| 77 | mockDeviceErrorCallback = nullptr; |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 78 | mockDevicePopErrorScopeCallback = nullptr; |
Natasha Lee | 9bba4a9 | 2019-12-18 18:59:20 +0000 | [diff] [blame] | 79 | mockDeviceLostCallback = nullptr; |
Corentin Wallez | 0ae00a1 | 2019-03-28 17:12:47 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | void FlushServer() { |
| 83 | WireTest::FlushServer(); |
| 84 | |
| 85 | Mock::VerifyAndClearExpectations(&mockDeviceErrorCallback); |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 86 | Mock::VerifyAndClearExpectations(&mockDevicePopErrorScopeCallback); |
Corentin Wallez | 0ae00a1 | 2019-03-28 17:12:47 +0000 | [diff] [blame] | 87 | } |
| 88 | }; |
| 89 | |
| 90 | // Test the return wire for device error callbacks |
| 91 | TEST_F(WireErrorCallbackTests, DeviceErrorCallback) { |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 92 | wgpuDeviceSetUncapturedErrorCallback(device, ToMockDeviceErrorCallback, this); |
Corentin Wallez | 0ae00a1 | 2019-03-28 17:12:47 +0000 | [diff] [blame] | 93 | |
| 94 | // Setting the error callback should stay on the client side and do nothing |
| 95 | FlushClient(); |
| 96 | |
| 97 | // Calling the callback on the server side will result in the callback being called on the |
| 98 | // client side |
Austin Eng | 8d38c01 | 2020-12-17 17:59:37 +0000 | [diff] [blame] | 99 | api.CallDeviceSetUncapturedErrorCallbackCallback(apiDevice, WGPUErrorType_Validation, |
| 100 | "Some error message"); |
Corentin Wallez | 0ae00a1 | 2019-03-28 17:12:47 +0000 | [diff] [blame] | 101 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 102 | EXPECT_CALL(*mockDeviceErrorCallback, |
| 103 | Call(WGPUErrorType_Validation, StrEq("Some error message"), this)) |
| 104 | .Times(1); |
Corentin Wallez | 0ae00a1 | 2019-03-28 17:12:47 +0000 | [diff] [blame] | 105 | |
| 106 | FlushServer(); |
| 107 | } |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 108 | |
| 109 | // Test the return wire for error scopes. |
| 110 | TEST_F(WireErrorCallbackTests, PushPopErrorScopeCallback) { |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 111 | wgpuDevicePushErrorScope(device, WGPUErrorFilter_Validation); |
| 112 | EXPECT_CALL(api, DevicePushErrorScope(apiDevice, WGPUErrorFilter_Validation)).Times(1); |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 113 | |
| 114 | FlushClient(); |
| 115 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 116 | wgpuDevicePopErrorScope(device, ToMockDevicePopErrorScopeCallback, this); |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 117 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 118 | WGPUErrorCallback callback; |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 119 | void* userdata; |
Austin Eng | 8d38c01 | 2020-12-17 17:59:37 +0000 | [diff] [blame] | 120 | EXPECT_CALL(api, OnDevicePopErrorScope(apiDevice, _, _)) |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 121 | .WillOnce(DoAll(SaveArg<1>(&callback), SaveArg<2>(&userdata), Return(true))); |
| 122 | |
| 123 | FlushClient(); |
| 124 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 125 | callback(WGPUErrorType_Validation, "Some error message", userdata); |
| 126 | EXPECT_CALL(*mockDevicePopErrorScopeCallback, |
| 127 | Call(WGPUErrorType_Validation, StrEq("Some error message"), this)) |
| 128 | .Times(1); |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 129 | |
| 130 | FlushServer(); |
| 131 | } |
| 132 | |
| 133 | // Test the return wire for error scopes when callbacks return in a various orders. |
| 134 | TEST_F(WireErrorCallbackTests, PopErrorScopeCallbackOrdering) { |
| 135 | // Two error scopes are popped, and the first one returns first. |
| 136 | { |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 137 | wgpuDevicePushErrorScope(device, WGPUErrorFilter_Validation); |
| 138 | wgpuDevicePushErrorScope(device, WGPUErrorFilter_Validation); |
| 139 | EXPECT_CALL(api, DevicePushErrorScope(apiDevice, WGPUErrorFilter_Validation)).Times(2); |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 140 | |
| 141 | FlushClient(); |
| 142 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 143 | wgpuDevicePopErrorScope(device, ToMockDevicePopErrorScopeCallback, this); |
| 144 | wgpuDevicePopErrorScope(device, ToMockDevicePopErrorScopeCallback, this + 1); |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 145 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 146 | WGPUErrorCallback callback1; |
| 147 | WGPUErrorCallback callback2; |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 148 | void* userdata1; |
| 149 | void* userdata2; |
Austin Eng | 8d38c01 | 2020-12-17 17:59:37 +0000 | [diff] [blame] | 150 | EXPECT_CALL(api, OnDevicePopErrorScope(apiDevice, _, _)) |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 151 | .WillOnce(DoAll(SaveArg<1>(&callback1), SaveArg<2>(&userdata1), Return(true))) |
| 152 | .WillOnce(DoAll(SaveArg<1>(&callback2), SaveArg<2>(&userdata2), Return(true))); |
| 153 | |
| 154 | FlushClient(); |
| 155 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 156 | callback1(WGPUErrorType_Validation, "First error message", userdata1); |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 157 | EXPECT_CALL(*mockDevicePopErrorScopeCallback, |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 158 | Call(WGPUErrorType_Validation, StrEq("First error message"), this)) |
| 159 | .Times(1); |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 160 | FlushServer(); |
| 161 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 162 | callback2(WGPUErrorType_Validation, "Second error message", userdata2); |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 163 | EXPECT_CALL(*mockDevicePopErrorScopeCallback, |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 164 | Call(WGPUErrorType_Validation, StrEq("Second error message"), this + 1)) |
| 165 | .Times(1); |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 166 | FlushServer(); |
| 167 | } |
| 168 | |
| 169 | // Two error scopes are popped, and the second one returns first. |
| 170 | { |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 171 | wgpuDevicePushErrorScope(device, WGPUErrorFilter_Validation); |
| 172 | wgpuDevicePushErrorScope(device, WGPUErrorFilter_Validation); |
| 173 | EXPECT_CALL(api, DevicePushErrorScope(apiDevice, WGPUErrorFilter_Validation)).Times(2); |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 174 | |
| 175 | FlushClient(); |
| 176 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 177 | wgpuDevicePopErrorScope(device, ToMockDevicePopErrorScopeCallback, this); |
| 178 | wgpuDevicePopErrorScope(device, ToMockDevicePopErrorScopeCallback, this + 1); |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 179 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 180 | WGPUErrorCallback callback1; |
| 181 | WGPUErrorCallback callback2; |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 182 | void* userdata1; |
| 183 | void* userdata2; |
Austin Eng | 8d38c01 | 2020-12-17 17:59:37 +0000 | [diff] [blame] | 184 | EXPECT_CALL(api, OnDevicePopErrorScope(apiDevice, _, _)) |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 185 | .WillOnce(DoAll(SaveArg<1>(&callback1), SaveArg<2>(&userdata1), Return(true))) |
| 186 | .WillOnce(DoAll(SaveArg<1>(&callback2), SaveArg<2>(&userdata2), Return(true))); |
| 187 | |
| 188 | FlushClient(); |
| 189 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 190 | callback2(WGPUErrorType_Validation, "Second error message", userdata2); |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 191 | EXPECT_CALL(*mockDevicePopErrorScopeCallback, |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 192 | Call(WGPUErrorType_Validation, StrEq("Second error message"), this + 1)) |
| 193 | .Times(1); |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 194 | FlushServer(); |
| 195 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 196 | callback1(WGPUErrorType_Validation, "First error message", userdata1); |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 197 | EXPECT_CALL(*mockDevicePopErrorScopeCallback, |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 198 | Call(WGPUErrorType_Validation, StrEq("First error message"), this)) |
| 199 | .Times(1); |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 200 | FlushServer(); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | // Test the return wire for error scopes in flight when the device is destroyed. |
| 205 | TEST_F(WireErrorCallbackTests, PopErrorScopeDeviceDestroyed) { |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 206 | wgpuDevicePushErrorScope(device, WGPUErrorFilter_Validation); |
| 207 | EXPECT_CALL(api, DevicePushErrorScope(apiDevice, WGPUErrorFilter_Validation)).Times(1); |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 208 | |
| 209 | FlushClient(); |
| 210 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 211 | EXPECT_TRUE(wgpuDevicePopErrorScope(device, ToMockDevicePopErrorScopeCallback, this)); |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 212 | |
Austin Eng | 8d38c01 | 2020-12-17 17:59:37 +0000 | [diff] [blame] | 213 | EXPECT_CALL(api, OnDevicePopErrorScope(apiDevice, _, _)).WillOnce(Return(true)); |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 214 | FlushClient(); |
| 215 | |
| 216 | // Incomplete callback called in Device destructor. |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 217 | EXPECT_CALL(*mockDevicePopErrorScopeCallback, |
| 218 | Call(WGPUErrorType_Unknown, ValidStringMessage(), this)) |
| 219 | .Times(1); |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 220 | } |
| 221 | |
Austin Eng | b70a5b0 | 2020-11-11 21:01:18 +0000 | [diff] [blame] | 222 | // Test that registering a callback then wire disconnect calls the callback with |
| 223 | // DeviceLost. |
| 224 | TEST_F(WireErrorCallbackTests, PopErrorScopeThenDisconnect) { |
| 225 | wgpuDevicePushErrorScope(device, WGPUErrorFilter_Validation); |
| 226 | EXPECT_CALL(api, DevicePushErrorScope(apiDevice, WGPUErrorFilter_Validation)).Times(1); |
| 227 | |
| 228 | EXPECT_TRUE(wgpuDevicePopErrorScope(device, ToMockDevicePopErrorScopeCallback, this)); |
Austin Eng | 8d38c01 | 2020-12-17 17:59:37 +0000 | [diff] [blame] | 229 | EXPECT_CALL(api, OnDevicePopErrorScope(apiDevice, _, _)).WillOnce(Return(true)); |
Austin Eng | b70a5b0 | 2020-11-11 21:01:18 +0000 | [diff] [blame] | 230 | |
| 231 | FlushClient(); |
| 232 | |
| 233 | EXPECT_CALL(*mockDevicePopErrorScopeCallback, |
| 234 | Call(WGPUErrorType_DeviceLost, ValidStringMessage(), this)) |
| 235 | .Times(1); |
| 236 | GetWireClient()->Disconnect(); |
| 237 | } |
| 238 | |
Austin Eng | 7ceffe8 | 2020-11-12 18:03:42 +0000 | [diff] [blame] | 239 | // Test that registering a callback after wire disconnect calls the callback with |
| 240 | // DeviceLost. |
| 241 | TEST_F(WireErrorCallbackTests, PopErrorScopeAfterDisconnect) { |
| 242 | wgpuDevicePushErrorScope(device, WGPUErrorFilter_Validation); |
| 243 | EXPECT_CALL(api, DevicePushErrorScope(apiDevice, WGPUErrorFilter_Validation)).Times(1); |
| 244 | |
| 245 | FlushClient(); |
| 246 | |
| 247 | GetWireClient()->Disconnect(); |
| 248 | |
| 249 | EXPECT_CALL(*mockDevicePopErrorScopeCallback, |
| 250 | Call(WGPUErrorType_DeviceLost, ValidStringMessage(), this)) |
| 251 | .Times(1); |
| 252 | EXPECT_TRUE(wgpuDevicePopErrorScope(device, ToMockDevicePopErrorScopeCallback, this)); |
| 253 | } |
| 254 | |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 255 | // Test that PopErrorScope returns false if there are no error scopes. |
| 256 | TEST_F(WireErrorCallbackTests, PopErrorScopeEmptyStack) { |
| 257 | // Empty stack |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 258 | { EXPECT_FALSE(wgpuDevicePopErrorScope(device, ToMockDevicePopErrorScopeCallback, this)); } |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 259 | |
| 260 | // Pop too many times |
| 261 | { |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 262 | wgpuDevicePushErrorScope(device, WGPUErrorFilter_Validation); |
| 263 | EXPECT_CALL(api, DevicePushErrorScope(apiDevice, WGPUErrorFilter_Validation)).Times(1); |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 264 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 265 | EXPECT_TRUE(wgpuDevicePopErrorScope(device, ToMockDevicePopErrorScopeCallback, this)); |
| 266 | EXPECT_FALSE(wgpuDevicePopErrorScope(device, ToMockDevicePopErrorScopeCallback, this + 1)); |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 267 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 268 | WGPUErrorCallback callback; |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 269 | void* userdata; |
Austin Eng | 8d38c01 | 2020-12-17 17:59:37 +0000 | [diff] [blame] | 270 | EXPECT_CALL(api, OnDevicePopErrorScope(apiDevice, _, _)) |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 271 | .WillOnce(DoAll(SaveArg<1>(&callback), SaveArg<2>(&userdata), Return(true))); |
| 272 | |
| 273 | FlushClient(); |
| 274 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 275 | callback(WGPUErrorType_Validation, "Some error message", userdata); |
| 276 | EXPECT_CALL(*mockDevicePopErrorScopeCallback, |
| 277 | Call(WGPUErrorType_Validation, StrEq("Some error message"), this)) |
| 278 | .Times(1); |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 279 | |
| 280 | FlushServer(); |
| 281 | } |
| 282 | } |
Natasha Lee | 9bba4a9 | 2019-12-18 18:59:20 +0000 | [diff] [blame] | 283 | |
| 284 | // Test the return wire for device lost callback |
| 285 | TEST_F(WireErrorCallbackTests, DeviceLostCallback) { |
| 286 | wgpuDeviceSetDeviceLostCallback(device, ToMockDeviceLostCallback, this); |
| 287 | |
| 288 | // Setting the error callback should stay on the client side and do nothing |
| 289 | FlushClient(); |
| 290 | |
| 291 | // Calling the callback on the server side will result in the callback being called on the |
| 292 | // client side |
Austin Eng | 8d38c01 | 2020-12-17 17:59:37 +0000 | [diff] [blame] | 293 | api.CallDeviceSetDeviceLostCallbackCallback(apiDevice, "Some error message"); |
Natasha Lee | 9bba4a9 | 2019-12-18 18:59:20 +0000 | [diff] [blame] | 294 | |
| 295 | EXPECT_CALL(*mockDeviceLostCallback, Call(StrEq("Some error message"), this)).Times(1); |
| 296 | |
| 297 | FlushServer(); |
| 298 | } |