blob: 5a7513f0fcb9fab447394e0f092d5fc5ef5206ea [file] [log] [blame]
Keun Soo Yim6f25faa2016-03-03 13:28:22 -08001/*
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
27using namespace std;
28using namespace android;
29
30namespace android {
31namespace vts {
32
Keun Soo Yimd4559882016-05-13 20:03:12 -070033FuzzerBase::FuzzerBase(int target_class)
34 : target_class_(target_class) {}
Keun Soo Yim6f25faa2016-03-03 13:28:22 -080035
36
37FuzzerBase::~FuzzerBase() {}
38
39
Keun Soo Yim34067de2016-05-17 09:46:37 -070040bool FuzzerBase::LoadTargetComponent(
41 const char* target_dll_path, const char* module_name) {
42 cout << __FUNCTION__ << ":" << __LINE__ << " " << "LoadTargetCompooent entry" << endl;
Keun Soo Yim6f25faa2016-03-03 13:28:22 -080043 target_dll_path_ = target_dll_path;
44 if (!target_loader_.Load(target_dll_path_)) return false;
Keun Soo Yim34067de2016-05-17 09:46:37 -070045 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 Yim6f25faa2016-03-03 13:28:22 -080051}
52
53
Keun Soo Yimc5d092a2016-04-28 16:51:56 +000054bool FuzzerBase::Fuzz(const vts::InterfaceSpecificationMessage& message,
Keun Soo Yim2ee90792016-04-27 14:53:54 -070055 void** result) {
Keun Soo Yim6f25faa2016-03-03 13:28:22 -080056 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 Yimc5d092a2016-04-28 16:51:56 +000064 Fuzz(func_msg, result);
Keun Soo Yim6f25faa2016-03-03 13:28:22 -080065 }
66 return true;
67}
68
Keun Soo Yim6f25faa2016-03-03 13:28:22 -080069} // namespace vts
70} // namespace android