Keun Soo Yim | 6f25faa | 2016-03-03 13:28:22 -0800 | [diff] [blame] | 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 | #include "fuzz_tester/FuzzerBase.h" |
| 18 | |
| 19 | #include <string> |
| 20 | #include <iostream> |
| 21 | |
| 22 | #include "test/vts/sysfuzzer/common/proto/InterfaceSpecificationMessage.pb.h" |
| 23 | |
| 24 | #include "component_loader/DllLoader.h" |
| 25 | #include "utils/InterfaceSpecUtil.h" |
| 26 | |
| 27 | using namespace std; |
| 28 | using namespace android; |
| 29 | |
| 30 | namespace android { |
| 31 | namespace vts { |
| 32 | |
Keun Soo Yim | d455988 | 2016-05-13 20:03:12 -0700 | [diff] [blame] | 33 | FuzzerBase::FuzzerBase(int target_class) |
| 34 | : target_class_(target_class) {} |
Keun Soo Yim | 6f25faa | 2016-03-03 13:28:22 -0800 | [diff] [blame] | 35 | |
| 36 | |
| 37 | FuzzerBase::~FuzzerBase() {} |
| 38 | |
| 39 | |
Keun Soo Yim | 34067de | 2016-05-17 09:46:37 -0700 | [diff] [blame] | 40 | bool FuzzerBase::LoadTargetComponent( |
| 41 | const char* target_dll_path, const char* module_name) { |
| 42 | cout << __FUNCTION__ << ":" << __LINE__ << " " << "LoadTargetCompooent entry" << endl; |
Keun Soo Yim | 6f25faa | 2016-03-03 13:28:22 -0800 | [diff] [blame] | 43 | target_dll_path_ = target_dll_path; |
| 44 | if (!target_loader_.Load(target_dll_path_)) return false; |
Keun Soo Yim | 34067de | 2016-05-17 09:46:37 -0700 | [diff] [blame] | 45 | cout << __FUNCTION__ << ":" << __LINE__ << " " << "LoadTargetCompooent loaded the target" << endl; |
| 46 | if (target_class_ == LEGACY_HAL) return true; |
| 47 | cout << __FUNCTION__ << ": loaded a non-legacy HAL file." << endl; |
| 48 | device_ = target_loader_.GetHWDevice(module_name); |
| 49 | cout << __FUNCTION__ << ": device_ " << device_ << endl; |
| 50 | return (device_ != NULL); |
Keun Soo Yim | 6f25faa | 2016-03-03 13:28:22 -0800 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | |
Keun Soo Yim | c5d092a | 2016-04-28 16:51:56 +0000 | [diff] [blame] | 54 | bool FuzzerBase::Fuzz(const vts::InterfaceSpecificationMessage& message, |
Keun Soo Yim | 2ee9079 | 2016-04-27 14:53:54 -0700 | [diff] [blame] | 55 | void** result) { |
Keun Soo Yim | 6f25faa | 2016-03-03 13:28:22 -0800 | [diff] [blame] | 56 | cout << "Fuzzing target component: " |
| 57 | << "class " << message.component_class() |
| 58 | << " type " << message.component_type() |
| 59 | << " version " << message.component_type_version() << endl; |
| 60 | |
| 61 | string function_name_prefix = GetFunctionNamePrefix(message); |
| 62 | function_name_prefix_ = function_name_prefix.c_str(); |
| 63 | for (const vts::FunctionSpecificationMessage& func_msg : message.api()) { |
Keun Soo Yim | c5d092a | 2016-04-28 16:51:56 +0000 | [diff] [blame] | 64 | Fuzz(func_msg, result); |
Keun Soo Yim | 6f25faa | 2016-03-03 13:28:22 -0800 | [diff] [blame] | 65 | } |
| 66 | return true; |
| 67 | } |
| 68 | |
Keun Soo Yim | 6f25faa | 2016-03-03 13:28:22 -0800 | [diff] [blame] | 69 | } // namespace vts |
| 70 | } // namespace android |