Add the user-visible logging interface.

Details:
- Add the logging level type WGPULoggingType, including levels verbose,
info, warning, and error,
- Add the API SetLoggingCallback, which bind the callback to deal with
logging string,
- Add the return command DeviceLoggingCallback and related code,
- Add DeviceBase::EmitLog(WGPULoggingType, const char*) , and
DeviceBase::EmitLog(const char*) use WGPULoggingType_info as default,
to post logging from native or server device to bound callback
via CallbackTaskManager.

BUG: dawn:792
Change-Id: I107b9134ff8567a46fa452509799e10b6862b8d3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/52200
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Zhaoming Jiang <zhaoming.jiang@intel.com>
This commit is contained in:
Zhaoming Jiang
2021-06-04 07:10:56 +00:00
committed by Dawn LUCI CQ
parent 9d911d4957
commit b44000e7af
16 changed files with 221 additions and 16 deletions

View File

@@ -363,6 +363,9 @@ TEST_F(WireCreatePipelineAsyncTest, DeviceDeletedBeforeCallback) {
EXPECT_CALL(api, OnDeviceSetUncapturedErrorCallback(apiDevice, nullptr, nullptr))
.Times(1)
.InSequence(s1, s2);
EXPECT_CALL(api, OnDeviceSetLoggingCallback(apiDevice, nullptr, nullptr))
.Times(1)
.InSequence(s1, s2);
EXPECT_CALL(api, OnDeviceSetDeviceLostCallback(apiDevice, nullptr, nullptr))
.Times(1)
.InSequence(s1, s2);

View File

@@ -39,6 +39,9 @@ TEST_F(WireDestroyObjectTests, DestroyDeviceDestroysChildren) {
EXPECT_CALL(api, OnDeviceSetUncapturedErrorCallback(apiDevice, nullptr, nullptr))
.Times(1)
.InSequence(s1, s2);
EXPECT_CALL(api, OnDeviceSetLoggingCallback(apiDevice, nullptr, nullptr))
.Times(1)
.InSequence(s1, s2);
EXPECT_CALL(api, OnDeviceSetDeviceLostCallback(apiDevice, nullptr, nullptr))
.Times(1)
.InSequence(s1, s2);
@@ -94,6 +97,9 @@ TEST_F(WireDestroyObjectTests, ImplicitInjectErrorAfterDestroyDevice) {
EXPECT_CALL(api, OnDeviceSetUncapturedErrorCallback(apiDevice, nullptr, nullptr))
.Times(1)
.InSequence(s1, s2);
EXPECT_CALL(api, OnDeviceSetLoggingCallback(apiDevice, nullptr, nullptr))
.Times(1)
.InSequence(s1, s2);
EXPECT_CALL(api, OnDeviceSetDeviceLostCallback(apiDevice, nullptr, nullptr))
.Times(1)
.InSequence(s1, s2);

View File

@@ -152,6 +152,9 @@ TEST_F(WireDisconnectTests, DeleteClientDestroysObjects) {
EXPECT_CALL(api, OnDeviceSetUncapturedErrorCallback(apiDevice, nullptr, nullptr))
.Times(1)
.InSequence(s1, s2);
EXPECT_CALL(api, OnDeviceSetLoggingCallback(apiDevice, nullptr, nullptr))
.Times(1)
.InSequence(s1, s2);
EXPECT_CALL(api, OnDeviceSetDeviceLostCallback(apiDevice, nullptr, nullptr))
.Times(1)
.InSequence(s1, s2);

View File

@@ -44,6 +44,16 @@ namespace {
mockDevicePopErrorScopeCallback->Call(type, message, userdata);
}
class MockDeviceLoggingCallback {
public:
MOCK_METHOD(void, Call, (WGPULoggingType type, const char* message, void* userdata));
};
std::unique_ptr<StrictMock<MockDeviceLoggingCallback>> mockDeviceLoggingCallback;
void ToMockDeviceLoggingCallback(WGPULoggingType type, const char* message, void* userdata) {
mockDeviceLoggingCallback->Call(type, message, userdata);
}
class MockDeviceLostCallback {
public:
MOCK_METHOD(void, Call, (const char* message, void* userdata));
@@ -66,6 +76,7 @@ class WireErrorCallbackTests : public WireTest {
WireTest::SetUp();
mockDeviceErrorCallback = std::make_unique<StrictMock<MockDeviceErrorCallback>>();
mockDeviceLoggingCallback = std::make_unique<StrictMock<MockDeviceLoggingCallback>>();
mockDevicePopErrorScopeCallback =
std::make_unique<StrictMock<MockDevicePopErrorScopeCallback>>();
mockDeviceLostCallback = std::make_unique<StrictMock<MockDeviceLostCallback>>();
@@ -75,6 +86,7 @@ class WireErrorCallbackTests : public WireTest {
WireTest::TearDown();
mockDeviceErrorCallback = nullptr;
mockDeviceLoggingCallback = nullptr;
mockDevicePopErrorScopeCallback = nullptr;
mockDeviceLostCallback = nullptr;
}
@@ -106,6 +118,23 @@ TEST_F(WireErrorCallbackTests, DeviceErrorCallback) {
FlushServer();
}
// Test the return wire for device user warning callbacks
TEST_F(WireErrorCallbackTests, DeviceLoggingCallback) {
wgpuDeviceSetLoggingCallback(device, ToMockDeviceLoggingCallback, this);
// Setting the injected warning callback should stay on the client side and do nothing
FlushClient();
// Calling the callback on the server side will result in the callback being called on the
// client side
api.CallDeviceSetLoggingCallbackCallback(apiDevice, WGPULoggingType_Info, "Some message");
EXPECT_CALL(*mockDeviceLoggingCallback, Call(WGPULoggingType_Info, StrEq("Some message"), this))
.Times(1);
FlushServer();
}
// Test the return wire for error scopes.
TEST_F(WireErrorCallbackTests, PushPopErrorScopeCallback) {
wgpuDevicePushErrorScope(device, WGPUErrorFilter_Validation);

View File

@@ -35,6 +35,7 @@ TEST_F(WireInjectDeviceTests, CallAfterReserveInject) {
WGPUDevice serverDevice = api.GetNewDevice();
EXPECT_CALL(api, DeviceReference(serverDevice));
EXPECT_CALL(api, OnDeviceSetUncapturedErrorCallback(serverDevice, _, _));
EXPECT_CALL(api, OnDeviceSetLoggingCallback(serverDevice, _, _));
EXPECT_CALL(api, OnDeviceSetDeviceLostCallback(serverDevice, _, _));
ASSERT_TRUE(
GetWireServer()->InjectDevice(serverDevice, reservation.id, reservation.generation));
@@ -48,6 +49,7 @@ TEST_F(WireInjectDeviceTests, CallAfterReserveInject) {
// Called on shutdown.
EXPECT_CALL(api, OnDeviceSetUncapturedErrorCallback(serverDevice, nullptr, nullptr))
.Times(Exactly(1));
EXPECT_CALL(api, OnDeviceSetLoggingCallback(serverDevice, nullptr, nullptr)).Times(Exactly(1));
EXPECT_CALL(api, OnDeviceSetDeviceLostCallback(serverDevice, nullptr, nullptr))
.Times(Exactly(1));
}
@@ -68,6 +70,7 @@ TEST_F(WireInjectDeviceTests, InjectExistingID) {
WGPUDevice serverDevice = api.GetNewDevice();
EXPECT_CALL(api, DeviceReference(serverDevice));
EXPECT_CALL(api, OnDeviceSetUncapturedErrorCallback(serverDevice, _, _));
EXPECT_CALL(api, OnDeviceSetLoggingCallback(serverDevice, _, _));
EXPECT_CALL(api, OnDeviceSetDeviceLostCallback(serverDevice, _, _));
ASSERT_TRUE(
GetWireServer()->InjectDevice(serverDevice, reservation.id, reservation.generation));
@@ -79,6 +82,7 @@ TEST_F(WireInjectDeviceTests, InjectExistingID) {
// Called on shutdown.
EXPECT_CALL(api, OnDeviceSetUncapturedErrorCallback(serverDevice, nullptr, nullptr))
.Times(Exactly(1));
EXPECT_CALL(api, OnDeviceSetLoggingCallback(serverDevice, nullptr, nullptr)).Times(Exactly(1));
EXPECT_CALL(api, OnDeviceSetDeviceLostCallback(serverDevice, nullptr, nullptr))
.Times(Exactly(1));
}
@@ -91,6 +95,7 @@ TEST_F(WireInjectDeviceTests, InjectedDeviceLifetime) {
WGPUDevice serverDevice = api.GetNewDevice();
EXPECT_CALL(api, DeviceReference(serverDevice));
EXPECT_CALL(api, OnDeviceSetUncapturedErrorCallback(serverDevice, _, _));
EXPECT_CALL(api, OnDeviceSetLoggingCallback(serverDevice, _, _));
EXPECT_CALL(api, OnDeviceSetDeviceLostCallback(serverDevice, _, _));
ASSERT_TRUE(
GetWireServer()->InjectDevice(serverDevice, reservation.id, reservation.generation));
@@ -99,6 +104,7 @@ TEST_F(WireInjectDeviceTests, InjectedDeviceLifetime) {
wgpuDeviceRelease(reservation.device);
EXPECT_CALL(api, DeviceRelease(serverDevice));
EXPECT_CALL(api, OnDeviceSetUncapturedErrorCallback(serverDevice, nullptr, nullptr)).Times(1);
EXPECT_CALL(api, OnDeviceSetLoggingCallback(serverDevice, nullptr, nullptr)).Times(1);
EXPECT_CALL(api, OnDeviceSetDeviceLostCallback(serverDevice, nullptr, nullptr)).Times(1);
FlushClient();
@@ -124,6 +130,7 @@ TEST_F(WireInjectDeviceTests, GetQueueAfterInject) {
WGPUDevice serverDevice = api.GetNewDevice();
EXPECT_CALL(api, DeviceReference(serverDevice));
EXPECT_CALL(api, OnDeviceSetUncapturedErrorCallback(serverDevice, _, _));
EXPECT_CALL(api, OnDeviceSetLoggingCallback(serverDevice, _, _));
EXPECT_CALL(api, OnDeviceSetDeviceLostCallback(serverDevice, _, _));
ASSERT_TRUE(
GetWireServer()->InjectDevice(serverDevice, reservation.id, reservation.generation));
@@ -137,6 +144,7 @@ TEST_F(WireInjectDeviceTests, GetQueueAfterInject) {
// Called on shutdown.
EXPECT_CALL(api, OnDeviceSetUncapturedErrorCallback(serverDevice, nullptr, nullptr))
.Times(Exactly(1));
EXPECT_CALL(api, OnDeviceSetLoggingCallback(serverDevice, nullptr, nullptr)).Times(Exactly(1));
EXPECT_CALL(api, OnDeviceSetDeviceLostCallback(serverDevice, nullptr, nullptr))
.Times(Exactly(1));
}
@@ -152,6 +160,7 @@ TEST_F(WireInjectDeviceTests, ReflectLiveDevices) {
WGPUDevice serverDevice1 = api.GetNewDevice();
EXPECT_CALL(api, DeviceReference(serverDevice1));
EXPECT_CALL(api, OnDeviceSetUncapturedErrorCallback(serverDevice1, _, _));
EXPECT_CALL(api, OnDeviceSetLoggingCallback(serverDevice1, _, _));
EXPECT_CALL(api, OnDeviceSetDeviceLostCallback(serverDevice1, _, _));
ASSERT_TRUE(
GetWireServer()->InjectDevice(serverDevice1, reservation1.id, reservation1.generation));
@@ -159,6 +168,7 @@ TEST_F(WireInjectDeviceTests, ReflectLiveDevices) {
WGPUDevice serverDevice2 = api.GetNewDevice();
EXPECT_CALL(api, DeviceReference(serverDevice2));
EXPECT_CALL(api, OnDeviceSetUncapturedErrorCallback(serverDevice2, _, _));
EXPECT_CALL(api, OnDeviceSetLoggingCallback(serverDevice2, _, _));
EXPECT_CALL(api, OnDeviceSetDeviceLostCallback(serverDevice2, _, _));
ASSERT_TRUE(
GetWireServer()->InjectDevice(serverDevice2, reservation2.id, reservation2.generation));
@@ -171,6 +181,7 @@ TEST_F(WireInjectDeviceTests, ReflectLiveDevices) {
wgpuDeviceRelease(reservation1.device);
EXPECT_CALL(api, DeviceRelease(serverDevice1));
EXPECT_CALL(api, OnDeviceSetUncapturedErrorCallback(serverDevice1, nullptr, nullptr)).Times(1);
EXPECT_CALL(api, OnDeviceSetLoggingCallback(serverDevice1, nullptr, nullptr)).Times(1);
EXPECT_CALL(api, OnDeviceSetDeviceLostCallback(serverDevice1, nullptr, nullptr)).Times(1);
FlushClient();
@@ -180,6 +191,7 @@ TEST_F(WireInjectDeviceTests, ReflectLiveDevices) {
// Called on shutdown.
EXPECT_CALL(api, OnDeviceSetUncapturedErrorCallback(serverDevice2, nullptr, nullptr)).Times(1);
EXPECT_CALL(api, OnDeviceSetLoggingCallback(serverDevice2, nullptr, nullptr)).Times(1);
EXPECT_CALL(api, OnDeviceSetDeviceLostCallback(serverDevice2, nullptr, nullptr)).Times(1);
}
@@ -193,6 +205,7 @@ TEST_F(WireInjectDeviceTests, TrackChildObjectsWithTwoReservedDevices) {
WGPUDevice serverDevice1 = api.GetNewDevice();
EXPECT_CALL(api, DeviceReference(serverDevice1));
EXPECT_CALL(api, OnDeviceSetUncapturedErrorCallback(serverDevice1, _, _));
EXPECT_CALL(api, OnDeviceSetLoggingCallback(serverDevice1, _, _));
EXPECT_CALL(api, OnDeviceSetDeviceLostCallback(serverDevice1, _, _));
ASSERT_TRUE(
GetWireServer()->InjectDevice(serverDevice1, reservation1.id, reservation1.generation));
@@ -211,6 +224,7 @@ TEST_F(WireInjectDeviceTests, TrackChildObjectsWithTwoReservedDevices) {
WGPUDevice serverDevice2 = api.GetNewDevice();
EXPECT_CALL(api, DeviceReference(serverDevice2));
EXPECT_CALL(api, OnDeviceSetUncapturedErrorCallback(serverDevice2, _, _));
EXPECT_CALL(api, OnDeviceSetLoggingCallback(serverDevice2, _, _));
EXPECT_CALL(api, OnDeviceSetDeviceLostCallback(serverDevice2, _, _));
ASSERT_TRUE(
GetWireServer()->InjectDevice(serverDevice2, reservation2.id, reservation2.generation));
@@ -224,8 +238,10 @@ TEST_F(WireInjectDeviceTests, TrackChildObjectsWithTwoReservedDevices) {
// Called on shutdown.
EXPECT_CALL(api, OnDeviceSetUncapturedErrorCallback(serverDevice1, nullptr, nullptr)).Times(1);
EXPECT_CALL(api, OnDeviceSetLoggingCallback(serverDevice1, nullptr, nullptr)).Times(1);
EXPECT_CALL(api, OnDeviceSetDeviceLostCallback(serverDevice1, nullptr, nullptr)).Times(1);
EXPECT_CALL(api, OnDeviceSetUncapturedErrorCallback(serverDevice2, nullptr, nullptr)).Times(1);
EXPECT_CALL(api, OnDeviceSetLoggingCallback(serverDevice2, nullptr, nullptr)).Times(1);
EXPECT_CALL(api, OnDeviceSetDeviceLostCallback(serverDevice2, nullptr, nullptr)).Times(1);
}

View File

@@ -43,6 +43,7 @@ void WireTest::SetUp() {
// This SetCallback call cannot be ignored because it is done as soon as we start the server
EXPECT_CALL(api, OnDeviceSetUncapturedErrorCallback(_, _, _)).Times(Exactly(1));
EXPECT_CALL(api, OnDeviceSetLoggingCallback(_, _, _)).Times(Exactly(1));
EXPECT_CALL(api, OnDeviceSetDeviceLostCallback(_, _, _)).Times(Exactly(1));
SetupIgnoredCallExpectations();
@@ -95,6 +96,7 @@ void WireTest::TearDown() {
// called after the server is destroyed.
EXPECT_CALL(api, OnDeviceSetUncapturedErrorCallback(apiDevice, nullptr, nullptr))
.Times(Exactly(1));
EXPECT_CALL(api, OnDeviceSetLoggingCallback(apiDevice, nullptr, nullptr)).Times(Exactly(1));
EXPECT_CALL(api, OnDeviceSetDeviceLostCallback(apiDevice, nullptr, nullptr))
.Times(Exactly(1));
}
@@ -135,6 +137,7 @@ void WireTest::DeleteServer() {
// called after the server is destroyed.
EXPECT_CALL(api, OnDeviceSetUncapturedErrorCallback(apiDevice, nullptr, nullptr))
.Times(Exactly(1));
EXPECT_CALL(api, OnDeviceSetLoggingCallback(apiDevice, nullptr, nullptr)).Times(Exactly(1));
EXPECT_CALL(api, OnDeviceSetDeviceLostCallback(apiDevice, nullptr, nullptr))
.Times(Exactly(1));
}