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