blob: ae7429c93984b5c6514c8041c822cf14e8232cae [file] [log] [blame]
Michael Ensing7c58e652020-05-12 00:41:30 -07001/*
2 * Copyright 2020 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
21namespace android {
22
23extern "C" int LLVMFuzzerTestOneInput(uint8_t* data, size_t size) {
24 std::shared_ptr<FuzzedDataProvider> fdp = std::make_shared<FuzzedDataProvider>(data, size);
25 FuzzContainer fuzzer = FuzzContainer(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 RawEvent rawEvent{fdp->ConsumeIntegral<nsecs_t>(),
40 fdp->ConsumeIntegral<int32_t>(),
41 fdp->ConsumeIntegral<int32_t>(),
42 fdp->ConsumeIntegral<int32_t>(),
43 fdp->ConsumeIntegral<int32_t>()};
44 mapper.process(&rawEvent);
45 },
46 [&]() -> void {
47 mapper.getSwitchState(fdp->ConsumeIntegral<uint32_t>(),
48 fdp->ConsumeIntegral<int32_t>());
49 },
50 })();
51 }
52
53 return 0;
54}
55
56} // namespace android