mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-18 01:15:39 +00:00
Add Dawn Wire Server LPM Fuzzer [3/N]
Add ability to define custom protobuf structures for commands that need to be hand written. Bug: chromium:1374747 Change-Id: I69d5c55d69c3544835a23e4e0360900b991ccbd3 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/114643 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Brendon Tiszka <tiszka@chromium.org>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
ebafab6556
commit
1f8413f50a
@@ -128,26 +128,42 @@ if (is_dawn_lpm_fuzzer && build_with_chromium && dawn_use_swiftshader) {
|
||||
|
||||
dawn_json_lpm_generator("dawn_lpmfuzz_proto") {
|
||||
target = "dawn_lpmfuzz_proto"
|
||||
outputs = [ "src/dawn/fuzzers/lpmfuzz/dawn_lpm_autogen.proto" ]
|
||||
outputs = [
|
||||
"src/dawn/fuzzers/lpmfuzz/dawn_lpm_autogen.proto",
|
||||
"src/dawn/fuzzers/lpmfuzz/dawn_object_types_lpm_autogen.proto",
|
||||
]
|
||||
}
|
||||
|
||||
copy("copy_dawn_custom_lpms") {
|
||||
# Hardcoded paths because we can't get_target_outputs from a proto_library
|
||||
# TODO(tiszka): crbug.com/1410213
|
||||
sources = [ "${dawn_root}/src/dawn/fuzzers/lpmfuzz/dawn_custom_lpm.proto" ]
|
||||
outputs = [ "$root_out_dir/gen/third_party/dawn/src/dawn/fuzzers/lpmfuzz/dawn_custom_lpm.proto" ]
|
||||
}
|
||||
|
||||
proto_library("dawn_lpm_proto") {
|
||||
proto_in_dir = "//"
|
||||
proto_in_dir = "$root_out_dir/gen"
|
||||
sources = get_target_outputs(":dawn_lpmfuzz_proto")
|
||||
sources += get_target_outputs(":copy_dawn_custom_lpms")
|
||||
|
||||
use_protobuf_full = true
|
||||
deps = [
|
||||
":copy_dawn_custom_lpms",
|
||||
":dawn_lpmfuzz_proto",
|
||||
"//third_party/protobuf:protobuf_full",
|
||||
]
|
||||
}
|
||||
|
||||
copy("copy_dawn_lpm_proto_outputs") {
|
||||
# Hardcoded filenames because we can't get_target_outputs from a proto_library
|
||||
# Hardcoded paths because we can't get_target_outputs from a proto_library
|
||||
# TODO(tiszka): crbug.com/1410213
|
||||
sources = [
|
||||
"$root_out_dir/gen/$root_out_dir/gen/third_party/dawn/src/dawn/fuzzers/lpmfuzz/dawn_custom_lpm.pb.cc",
|
||||
"$root_out_dir/gen/$root_out_dir/gen/third_party/dawn/src/dawn/fuzzers/lpmfuzz/dawn_custom_lpm.pb.h",
|
||||
"$root_out_dir/gen/$root_out_dir/gen/third_party/dawn/src/dawn/fuzzers/lpmfuzz/dawn_lpm_autogen.pb.cc",
|
||||
"$root_out_dir/gen/$root_out_dir/gen/third_party/dawn/src/dawn/fuzzers/lpmfuzz/dawn_lpm_autogen.pb.h",
|
||||
"$root_out_dir/gen/$root_out_dir/gen/third_party/dawn/src/dawn/fuzzers/lpmfuzz/dawn_object_types_lpm_autogen.pb.cc",
|
||||
"$root_out_dir/gen/$root_out_dir/gen/third_party/dawn/src/dawn/fuzzers/lpmfuzz/dawn_object_types_lpm_autogen.pb.h",
|
||||
]
|
||||
outputs = [ "$root_out_dir/gen/third_party/dawn/src/dawn/fuzzers/lpmfuzz/{{source_file_part}}" ]
|
||||
deps = [ ":dawn_lpm_proto" ]
|
||||
|
||||
@@ -54,18 +54,8 @@ class DevNull : public dawn::wire::CommandSerializer {
|
||||
};
|
||||
|
||||
std::unique_ptr<dawn::native::Instance> sInstance;
|
||||
WGPUProcDeviceCreateSwapChain sOriginalDeviceCreateSwapChain = nullptr;
|
||||
static bool (*sAdapterSupported)(const dawn::native::Adapter&) = nullptr;
|
||||
|
||||
WGPUSwapChain ErrorDeviceCreateSwapChain(WGPUDevice device,
|
||||
WGPUSurface surface,
|
||||
const WGPUSwapChainDescriptor*) {
|
||||
WGPUSwapChainDescriptor desc = {};
|
||||
// A 0 implementation will trigger a swapchain creation error.
|
||||
desc.implementation = 0;
|
||||
return sOriginalDeviceCreateSwapChain(device, surface, &desc);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace DawnLPMFuzzer {
|
||||
@@ -85,13 +75,6 @@ int Run(const fuzzing::Program& program, bool (*AdapterSupported)(const dawn::na
|
||||
|
||||
DawnProcTable procs = dawn::native::GetProcs();
|
||||
|
||||
// Swapchains receive a pointer to an implementation. The fuzzer will pass garbage in so we
|
||||
// intercept calls to create swapchains and make sure they always return error swapchains.
|
||||
// This is ok for fuzzing because embedders of dawn_wire would always define their own
|
||||
// swapchain handling.
|
||||
sOriginalDeviceCreateSwapChain = procs.deviceCreateSwapChain;
|
||||
procs.deviceCreateSwapChain = ErrorDeviceCreateSwapChain;
|
||||
|
||||
// Override requestAdapter to find an adapter that the fuzzer supports.
|
||||
procs.instanceRequestAdapter = [](WGPUInstance cInstance,
|
||||
const WGPURequestAdapterOptions* options,
|
||||
|
||||
27
src/dawn/fuzzers/lpmfuzz/dawn_custom_lpm.proto
Normal file
27
src/dawn/fuzzers/lpmfuzz/dawn_custom_lpm.proto
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright 2023 The Dawn Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
syntax = "proto2";
|
||||
package fuzzing;
|
||||
|
||||
import "third_party/dawn/src/dawn/fuzzers/lpmfuzz/dawn_object_types_lpm_autogen.proto";
|
||||
|
||||
message DeviceCreateShaderModule {
|
||||
required uint32 self = 1;
|
||||
}
|
||||
|
||||
message DestroyObject {
|
||||
required ObjectType objectType = 1;
|
||||
required uint32 objectId = 2;
|
||||
}
|
||||
@@ -17,16 +17,16 @@
|
||||
|
||||
"_doc": "See docs/dawn/codegen.md",
|
||||
|
||||
"custom_cmds": [],
|
||||
|
||||
"blocklisted_cmds": [
|
||||
"surface descriptor from windows core window",
|
||||
"surface descriptor from windows swap chain panel",
|
||||
"surface descriptor from canvas html selector",
|
||||
"device create render pipeline",
|
||||
"device create render pipeline async",
|
||||
"custom_cmds": [
|
||||
"device create shader module",
|
||||
"destroy object"
|
||||
]
|
||||
],
|
||||
|
||||
"blocklisted_cmds": [
|
||||
"device create render pipeline",
|
||||
"device create render pipeline async",
|
||||
"surface descriptor from windows core window",
|
||||
"surface descriptor from windows swap chain panel",
|
||||
"surface descriptor from canvas html selector"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user