blob: 381e7b5f8fd3d590bbadb4b381cf9f790d1bc3d5 [file] [log] [blame]
Michael Ensingb8d93262020-05-12 00:41:30 -07001/*
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 Cutts656e0ad2023-06-16 16:39:55 +000018#include <MapperHelpers.h>
Michael Ensingb8d93262020-05-12 00:41:30 -070019#include <SwitchInputMapper.h>
Michael Ensingb8d93262020-05-12 00:41:30 -070020
21namespace android {
22
23extern "C" int LLVMFuzzerTestOneInput(uint8_t* data, size_t size) {
Aditya Wazireea5be02022-10-31 12:40:10 +053024 std::shared_ptr<ThreadSafeFuzzedDataProvider> fdp =
25 std::make_shared<ThreadSafeFuzzedDataProvider>(data, size);
Michael Ensingb8d93262020-05-12 00:41:30 -070026 FuzzContainer fuzzer(fdp);
27
Michael Ensingb8d93262020-05-12 00:41:30 -070028 auto policyConfig = fuzzer.getPolicyConfig();
Arpit Singh8e6fb252023-04-06 11:49:17 +000029 SwitchInputMapper& mapper = fuzzer.getMapper<SwitchInputMapper>(policyConfig);
Michael Ensingb8d93262020-05-12 00:41:30 -070030
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 Cutts656e0ad2023-06-16 16:39:55 +000040 RawEvent rawEvent = getFuzzedRawEvent(*fdp);
Siarhei Vishniakou2935db72022-09-22 13:35:22 -070041 std::list<NotifyArgs> unused = mapper.process(&rawEvent);
Michael Ensingb8d93262020-05-12 00:41:30 -070042 },
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