1 /* 2 * Copyright 2016 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_SYSFUZZER_COMMON_FUZZER_BASE_H__ 18 #define __VTS_SYSFUZZER_COMMON_FUZZER_BASE_H__ 19 20 #include "component_loader/DllLoader.h" 21 #include "test/vts/proto/ComponentSpecificationMessage.pb.h" 22 23 using namespace std; 24 25 namespace android { 26 namespace vts { 27 28 class DriverBase { 29 public: 30 DriverBase(int target_class); 31 virtual ~DriverBase(); 32 33 // Loads a target component where the argument is the file path. 34 // Returns true iff successful. 35 bool LoadTargetComponent(const char* target_dll_path); 36 37 // Gets the HIDL service. 38 // Returns true iff successful. 39 virtual bool GetService(bool /*get_stub*/, const char* /*service_name*/) { 40 return false; 41 }; 42 43 // Fuzz tests the loaded component using the provided interface specification. 44 // Returns true iff the testing is conducted completely. 45 bool Fuzz(vts::ComponentSpecificationMessage* message, void** result); 46 47 // Actual implementation of routines to test a specific function using the 48 // provided function interface specification message. 49 // Returns true iff the testing is conducted completely. 50 virtual bool Fuzz(vts::FunctionSpecificationMessage* /*func_msg*/, 51 void** /*result*/, const string& /*callback_socket_name*/) { 52 return false; 53 }; 54 55 virtual bool CallFunction( 56 const vts::FunctionSpecificationMessage& /*func_msg*/, 57 const string& /*callback_socket_name*/, 58 vts::FunctionSpecificationMessage* /*result_msg*/) { 59 return false; 60 }; 61 62 virtual bool VerifyResults( 63 const vts::FunctionSpecificationMessage& /*expected_result_msg*/, 64 const vts::FunctionSpecificationMessage& /*actual_result_msg*/) { 65 return false; 66 }; 67 68 virtual bool GetAttribute(vts::FunctionSpecificationMessage* /*func_msg*/, 69 void** /*result*/) { 70 return false; 71 } 72 73 // Called before calling a target function. 74 void FunctionCallBegin(); 75 76 // Called after calling a target function. Fills in the code coverage info. 77 bool FunctionCallEnd(FunctionSpecificationMessage* msg); 78 79 // Scans all GCDA files under a given dir and adds to the message. 80 bool ScanAllGcdaFiles(const string& basepath, 81 FunctionSpecificationMessage* msg); 82 83 protected: 84 bool ReadGcdaFile(const string& basepath, const string& filename, 85 FunctionSpecificationMessage* msg); 86 87 // a pointer to a HAL data structure of the loaded component. 88 struct hw_device_t* device_; 89 90 // DLL Loader class. 91 DllLoader target_loader_; 92 93 // a pointer to the HAL_MODULE_INFO_SYM data structure of the loaded 94 // component. 95 struct hw_module_t* hmi_; 96 97 private: 98 // a pointer to the string which contains the loaded component. 99 char* target_dll_path_; 100 101 // function name prefix. 102 const char* function_name_prefix_; 103 104 // target class 105 const int target_class_; 106 107 // target component file name (without extension) 108 char* component_filename_; 109 110 // path to store the gcov output files. 111 char* gcov_output_basepath_; 112 }; 113 114 } // namespace vts 115 } // namespace android 116 117 #endif // __VTS_SYSFUZZER_COMMON_FUZZER_BASE_H__ 118