| Michael Ensing | b8d9326 | 2020-05-12 00:41:30 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright 2022 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
|  | 17 | #include <FuzzContainer.h> | 
|  | 18 | #include <SwitchInputMapper.h> | 
|  | 19 | #include <fuzzer/FuzzedDataProvider.h> | 
|  | 20 |  | 
|  | 21 | namespace android { | 
|  | 22 |  | 
|  | 23 | extern "C" int LLVMFuzzerTestOneInput(uint8_t* data, size_t size) { | 
|  | 24 | std::shared_ptr<FuzzedDataProvider> fdp = std::make_shared<FuzzedDataProvider>(data, size); | 
|  | 25 | FuzzContainer fuzzer(fdp); | 
|  | 26 |  | 
|  | 27 | SwitchInputMapper& mapper = fuzzer.getMapper<SwitchInputMapper>(); | 
|  | 28 | auto policyConfig = fuzzer.getPolicyConfig(); | 
|  | 29 |  | 
|  | 30 | // Loop through mapper operations until randomness is exhausted. | 
|  | 31 | while (fdp->remaining_bytes() > 0) { | 
|  | 32 | fdp->PickValueInArray<std::function<void()>>({ | 
|  | 33 | [&]() -> void { | 
|  | 34 | std::string dump; | 
|  | 35 | mapper.dump(dump); | 
|  | 36 | }, | 
|  | 37 | [&]() -> void { mapper.getSources(); }, | 
|  | 38 | [&]() -> void { | 
|  | 39 | int32_t type = fdp->ConsumeBool() ? fdp->PickValueInArray(kValidTypes) | 
|  | 40 | : fdp->ConsumeIntegral<int32_t>(); | 
|  | 41 | int32_t code = fdp->ConsumeBool() ? fdp->PickValueInArray(kValidCodes) | 
|  | 42 | : fdp->ConsumeIntegral<int32_t>(); | 
|  | 43 | RawEvent rawEvent{fdp->ConsumeIntegral<nsecs_t>(), | 
|  | 44 | fdp->ConsumeIntegral<nsecs_t>(), | 
|  | 45 | fdp->ConsumeIntegral<int32_t>(), | 
|  | 46 | type, | 
|  | 47 | code, | 
|  | 48 | fdp->ConsumeIntegral<int32_t>()}; | 
| Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 49 | std::list<NotifyArgs> unused = mapper.process(&rawEvent); | 
| Michael Ensing | b8d9326 | 2020-05-12 00:41:30 -0700 | [diff] [blame] | 50 | }, | 
|  | 51 | [&]() -> void { | 
|  | 52 | mapper.getSwitchState(fdp->ConsumeIntegral<uint32_t>(), | 
|  | 53 | fdp->ConsumeIntegral<int32_t>()); | 
|  | 54 | }, | 
|  | 55 | })(); | 
|  | 56 | } | 
|  | 57 |  | 
|  | 58 | return 0; | 
|  | 59 | } | 
|  | 60 |  | 
|  | 61 | } // namespace android |