1 // Copyright 2018 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 "DawnWireServerFuzzer.h"
16
17 #include "common/Assert.h"
18 #include "dawn_native/DawnNative.h"
19 #include "testing/libfuzzer/libfuzzer_exports.h"
20
LLVMFuzzerInitialize(int * argc,char *** argv)21 extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) {
22 return DawnWireServerFuzzer::Initialize(argc, argv);
23 }
24
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)25 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
26 return DawnWireServerFuzzer::Run(
27 data, size,
28 [](dawn_native::Instance* instance) {
29 std::vector<dawn_native::Adapter> adapters = instance->GetAdapters();
30
31 wgpu::Device nullDevice;
32 for (dawn_native::Adapter adapter : adapters) {
33 wgpu::AdapterProperties properties;
34 adapter.GetProperties(&properties);
35
36 if (properties.backendType == wgpu::BackendType::Null) {
37 nullDevice = wgpu::Device::Acquire(adapter.CreateDevice());
38 break;
39 }
40 }
41
42 ASSERT(nullDevice.Get() != nullptr);
43 return nullDevice;
44 },
45 false /* supportsErrorInjection */);
46 }
47