blob: 292c80e7b634dcf671006336fa6aa3cb4d0f7270 [file] [log] [blame]
Yu Shan4b2850f2022-09-20 18:52:07 -07001/*
2 * Copyright (C) 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 <RemoteAccessService.h>
18#include <fuzzbinder/libbinder_ndk_driver.h>
19#include <fuzzer/FuzzedDataProvider.h>
20#include <gmock/gmock.h>
21#include <grpcpp/test/mock_stream.h>
22#include <wakeup_client.grpc.pb.h>
23
24namespace android {
25namespace hardware {
26namespace automotive {
27namespace remoteaccess {
28
29using ::grpc::ClientAsyncReaderInterface;
30using ::grpc::ClientAsyncResponseReaderInterface;
31using ::grpc::ClientContext;
32using ::grpc::ClientReader;
33using ::grpc::ClientReaderInterface;
34using ::grpc::CompletionQueue;
35using ::grpc::Status;
36using ::grpc::testing::MockClientReader;
37using ::testing::_;
38using ::testing::Return;
39
40class MockGrpcClientStub : public WakeupClient::StubInterface {
41 public:
42 ClientReaderInterface<GetRemoteTasksResponse>* GetRemoteTasksRaw(
43 [[maybe_unused]] ClientContext* context,
44 [[maybe_unused]] const GetRemoteTasksRequest& request) override {
45 MockClientReader<GetRemoteTasksResponse>* mockClientReader =
46 new MockClientReader<GetRemoteTasksResponse>();
47 ON_CALL(*mockClientReader, Finish()).WillByDefault(Return(Status::OK));
48 ON_CALL(*mockClientReader, Read(_)).WillByDefault(Return(false));
49 return mockClientReader;
50 }
51
52 Status NotifyWakeupRequired([[maybe_unused]] ClientContext* context,
53 [[maybe_unused]] const NotifyWakeupRequiredRequest& request,
54 [[maybe_unused]] NotifyWakeupRequiredResponse* response) {
55 return Status::OK;
56 }
57
58 // Async methods which we do not care.
59 ClientAsyncReaderInterface<GetRemoteTasksResponse>* AsyncGetRemoteTasksRaw(
60 [[maybe_unused]] ClientContext* context,
61 [[maybe_unused]] const GetRemoteTasksRequest& request,
62 [[maybe_unused]] CompletionQueue* cq, [[maybe_unused]] void* tag) {
63 return nullptr;
64 }
65
66 ClientAsyncReaderInterface<GetRemoteTasksResponse>* PrepareAsyncGetRemoteTasksRaw(
67 [[maybe_unused]] ClientContext* context,
68 [[maybe_unused]] const GetRemoteTasksRequest& request,
69 [[maybe_unused]] CompletionQueue* cq) {
70 return nullptr;
71 }
72
73 ClientAsyncResponseReaderInterface<NotifyWakeupRequiredResponse>* AsyncNotifyWakeupRequiredRaw(
74 [[maybe_unused]] ClientContext* context,
75 [[maybe_unused]] const NotifyWakeupRequiredRequest& request,
76 [[maybe_unused]] CompletionQueue* cq) {
77 return nullptr;
78 }
79
80 ClientAsyncResponseReaderInterface<NotifyWakeupRequiredResponse>*
81 PrepareAsyncNotifyWakeupRequiredRaw([[maybe_unused]] ClientContext* context,
82 [[maybe_unused]] const NotifyWakeupRequiredRequest& request,
83 [[maybe_unused]] CompletionQueue* c) {
84 return nullptr;
85 }
86};
87
88} // namespace remoteaccess
89} // namespace automotive
90} // namespace hardware
91} // namespace android
92
93extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
94 android::hardware::automotive::remoteaccess::MockGrpcClientStub stub;
95 std::shared_ptr<android::hardware::automotive::remoteaccess::RemoteAccessService> service =
96 ndk::SharedRefBase::make<
97 android::hardware::automotive::remoteaccess::RemoteAccessService>(&stub);
98 android::fuzzService(service->asBinder().get(), FuzzedDataProvider(data, size));
99
100 return 0;
101}