1 /* 2 * Copyright 2017 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 #ifndef __VTS_PROTO_FUZZER_RUNNER_H_ 18 #define __VTS_PROTO_FUZZER_RUNNER_H_ 19 20 #include "ProtoFuzzerUtils.h" 21 22 #include <memory> 23 24 namespace android { 25 namespace vts { 26 namespace fuzzer { 27 28 // Describes a HIDL HAL interface. 29 struct IfaceDesc { 30 // VTS spec of the interface. 31 const CompSpec *comp_spec_; 32 // Handle to an interface instance. 33 std::shared_ptr<DriverBase> hal_; 34 }; 35 36 using IfaceDescTbl = std::unordered_map<std::string, IfaceDesc>; 37 38 // Responsible for issuing function calls to the HAL and keeps track of 39 // HAL-related information, e.g. which interfaces has been opened so far. 40 class ProtoFuzzerRunner { 41 public: 42 ProtoFuzzerRunner(const std::vector<CompSpec> &comp_specs); 43 44 // Initializes interface descriptor table by opening the root interface. 45 void Init(const std::string &, bool); 46 // Call every API from call sequence specified by the ExecSpec. 47 void Execute(const ExecSpec &); 48 // Execute the specified interface function call. 49 void Execute(const FuncCall &); 50 // Accessor to interface descriptor table containing currently opened 51 // interfaces. GetOpenedIfaces()52 const IfaceDescTbl &GetOpenedIfaces() const { return opened_ifaces_; } 53 54 private: 55 // Looks up interface spec by name. 56 const CompSpec *FindCompSpec(std::string); 57 // Processes return value from a function call. 58 void ProcessReturnValue(const FuncSpec &result); 59 // Loads the interface corresponding to the given VTS spec. Interface is 60 // constructed with the given argument. 61 DriverBase *LoadInterface(const CompSpec &, uint64_t); 62 63 // Keeps track of opened interfaces. 64 IfaceDescTbl opened_ifaces_; 65 // All loaded VTS specs indexed by name. 66 std::unordered_map<std::string, CompSpec> comp_specs_; 67 // Handle to the driver library. 68 void *driver_handle_; 69 }; 70 71 } // namespace fuzzer 72 } // namespace vts 73 } // namespace android 74 75 #endif // __VTS_PROTO_FUZZER_RUNNER_H__ 76