From 02beecaec5cdfa809f1dbea883a60bb040629590 Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Mon, 11 May 2020 20:55:22 +0000 Subject: [PATCH] Fuzzer: Wait for all commands to complete before destroying the wire Bug: chromium:1074739 Change-Id: I32591efe42559299234053f112a2f846d43612ab Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/21366 Commit-Queue: Austin Eng Reviewed-by: Corentin Wallez --- src/fuzzers/BUILD.gn | 1 + src/fuzzers/DawnWireServerFuzzer.cpp | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/fuzzers/BUILD.gn b/src/fuzzers/BUILD.gn index 4479cef67a..71a6d88a96 100644 --- a/src/fuzzers/BUILD.gn +++ b/src/fuzzers/BUILD.gn @@ -90,6 +90,7 @@ static_library("dawn_wire_server_fuzzer_common") { "${dawn_root}/src/dawn:dawncpp", "${dawn_root}/src/dawn_native:dawn_native_static", "${dawn_root}/src/dawn_wire:dawn_wire_static", + "${dawn_root}/src/utils:dawn_utils", ] } diff --git a/src/fuzzers/DawnWireServerFuzzer.cpp b/src/fuzzers/DawnWireServerFuzzer.cpp index aa0da429c3..81be868d05 100644 --- a/src/fuzzers/DawnWireServerFuzzer.cpp +++ b/src/fuzzers/DawnWireServerFuzzer.cpp @@ -21,6 +21,7 @@ #include "dawn/webgpu_cpp.h" #include "dawn_native/DawnNative.h" #include "dawn_wire/WireServer.h" +#include "utils/SystemUtils.h" #include #include @@ -149,8 +150,17 @@ int DawnWireServerFuzzer::Run(const uint8_t* data, wireServer->HandleCommands(reinterpret_cast(data), size); - // Fake waiting for all previous commands before destroying the server. - device.Tick(); + // Wait for all previous commands before destroying the server. + // TODO(enga): Improve this when we improve/finalize how processing events happens. + { + wgpu::Queue queue = device.GetDefaultQueue(); + wgpu::Fence fence = queue.CreateFence(); + queue.Signal(fence, 1u); + while (fence.GetCompletedValue() != 1u) { + device.Tick(); + utils::USleep(100); + } + } // Destroy the server before the device because it needs to free all objects. wireServer = nullptr;