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 | |
| 40 | bool FuzzerBase::LoadTargetComponent(const char* target_dll_path) { |
| 41 | target_dll_path_ = target_dll_path; |
| 42 | if (!target_loader_.Load(target_dll_path_)) return false; |
Keun Soo Yim | d455988 | 2016-05-13 20:03:12 -0700 | [diff] [blame] | 43 | if (target_class_ != LEGACY_HAL) { |
| 44 | return (device_ = target_loader_.GetHWDevice()) != NULL; |
| 45 | } else { |
| 46 | return true; |
| 47 | } |
Keun Soo Yim | 6f25faa | 2016-03-03 13:28:22 -0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | |
Keun Soo Yim | c5d092a | 2016-04-28 16:51:56 +0000 | [diff] [blame] | 51 | bool FuzzerBase::Fuzz(const vts::InterfaceSpecificationMessage& message, |
Keun Soo Yim | 2ee9079 | 2016-04-27 14:53:54 -0700 | [diff] [blame] | 52 | void** result) { |
Keun Soo Yim | 6f25faa | 2016-03-03 13:28:22 -0800 | [diff] [blame] | 53 | cout << "Fuzzing target component: " |
| 54 | << "class " << message.component_class() |
| 55 | << " type " << message.component_type() |
| 56 | << " version " << message.component_type_version() << endl; |
| 57 | |
| 58 | string function_name_prefix = GetFunctionNamePrefix(message); |
| 59 | function_name_prefix_ = function_name_prefix.c_str(); |
| 60 | for (const vts::FunctionSpecificationMessage& func_msg : message.api()) { |
Keun Soo Yim | c5d092a | 2016-04-28 16:51:56 +0000 | [diff] [blame] | 61 | Fuzz(func_msg, result); |
Keun Soo Yim | 6f25faa | 2016-03-03 13:28:22 -0800 | [diff] [blame] | 62 | } |
| 63 | return true; |
| 64 | } |
| 65 | |
Keun Soo Yim | 6f25faa | 2016-03-03 13:28:22 -0800 | [diff] [blame] | 66 | } // namespace vts |
| 67 | } // namespace android |