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> |
Harry Cutts | e36d835 | 2023-07-10 13:28:45 +0000 | [diff] [blame^] | 18 | #include <InputReaderBase.h> |
Harry Cutts | 656e0ad | 2023-06-16 16:39:55 +0000 | [diff] [blame] | 19 | #include <MapperHelpers.h> |
Michael Ensing | b8d9326 | 2020-05-12 00:41:30 -0700 | [diff] [blame] | 20 | #include <SwitchInputMapper.h> |
Michael Ensing | b8d9326 | 2020-05-12 00:41:30 -0700 | [diff] [blame] | 21 | |
| 22 | namespace android { |
| 23 | |
| 24 | extern "C" int LLVMFuzzerTestOneInput(uint8_t* data, size_t size) { |
Aditya Wazir | eea5be0 | 2022-10-31 12:40:10 +0530 | [diff] [blame] | 25 | std::shared_ptr<ThreadSafeFuzzedDataProvider> fdp = |
| 26 | std::make_shared<ThreadSafeFuzzedDataProvider>(data, size); |
Michael Ensing | b8d9326 | 2020-05-12 00:41:30 -0700 | [diff] [blame] | 27 | FuzzContainer fuzzer(fdp); |
| 28 | |
Harry Cutts | e36d835 | 2023-07-10 13:28:45 +0000 | [diff] [blame^] | 29 | SwitchInputMapper& mapper = fuzzer.getMapper<SwitchInputMapper>(InputReaderConfiguration{}); |
Michael Ensing | b8d9326 | 2020-05-12 00:41:30 -0700 | [diff] [blame] | 30 | |
| 31 | // Loop through mapper operations until randomness is exhausted. |
| 32 | while (fdp->remaining_bytes() > 0) { |
| 33 | fdp->PickValueInArray<std::function<void()>>({ |
| 34 | [&]() -> void { |
| 35 | std::string dump; |
| 36 | mapper.dump(dump); |
| 37 | }, |
| 38 | [&]() -> void { mapper.getSources(); }, |
| 39 | [&]() -> void { |
Harry Cutts | 656e0ad | 2023-06-16 16:39:55 +0000 | [diff] [blame] | 40 | RawEvent rawEvent = getFuzzedRawEvent(*fdp); |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 41 | std::list<NotifyArgs> unused = mapper.process(&rawEvent); |
Michael Ensing | b8d9326 | 2020-05-12 00:41:30 -0700 | [diff] [blame] | 42 | }, |
| 43 | [&]() -> void { |
| 44 | mapper.getSwitchState(fdp->ConsumeIntegral<uint32_t>(), |
| 45 | fdp->ConsumeIntegral<int32_t>()); |
| 46 | }, |
| 47 | })(); |
| 48 | } |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | } // namespace android |