• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_COMPILATION_TOOLS_VTSC_CODE_GEN_FUZZER_HALHIDLFUZZERCODEGEN_H_
18 #define VTS_COMPILATION_TOOLS_VTSC_CODE_GEN_FUZZER_HALHIDLFUZZERCODEGEN_H_
19 
20 #include "code_gen/fuzzer/FuzzerCodeGenBase.h"
21 
22 namespace android {
23 namespace vts {
24 
25 // Generates fuzzer code for HIDL HALs.
26 class HalHidlFuzzerCodeGen : public FuzzerCodeGenBase {
27  public:
HalHidlFuzzerCodeGen(const ComponentSpecificationMessage & comp_spec)28   explicit HalHidlFuzzerCodeGen(const ComponentSpecificationMessage &comp_spec)
29       : FuzzerCodeGenBase(comp_spec) {}
30 
31   void GenerateSourceIncludeFiles(Formatter &out) override;
32   void GenerateUsingDeclaration(Formatter &out) override;
33   void GenerateGlobalVars(Formatter &out) override;
34   void GenerateLLVMFuzzerInitialize(Formatter &out) override;
35   void GenerateLLVMFuzzerTestOneInput(Formatter &out) override;
36 
37  private:
38   // Generates return callback function for HAL function being fuzzed.
39   void GenerateReturnCallback(Formatter &out,
40                               const FunctionSpecificationMessage &func_spec);
41   // Generates function call.
42   void GenerateHalFunctionCall(Formatter &out,
43                                const FunctionSpecificationMessage &func_spec);
44   // Returns name of pointer to hal instance.
45   std::string GetHalPointerName();
46   // Returns true if we could omit the callback function and return result
47   // directly.
48   bool CanElideCallback(const FunctionSpecificationMessage &func_spec);
49   // Returns a vector of strings containing type names of function arguments.
50   std::vector<std::string> GetFuncArgTypes(
51       const FunctionSpecificationMessage &func_spec);
52   // Name of return callback. Since we only fuzz one function, we'll need at
53   // most one return callback.
54   const std::string return_cb_name = "hidl_cb";
55 };
56 
57 }  // namespace vts
58 }  // namespace android
59 
60 #endif  // VTS_COMPILATION_TOOLS_VTSC_CODE_GEN_FUZZER_HALHIDLFUZZERCODEGEN_H_
61