Home | History | Annotate | Download | only in fuzzer
      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_FUZZERCODEGENBASE_H_
     18 #define VTS_COMPILATION_TOOLS_VTSC_CODE_GEN_FUZZER_FUZZERCODEGENBASE_H_
     19 
     20 #include <hidl-util/Formatter.h>
     21 #include <iostream>
     22 #include <string>
     23 
     24 #include "test/vts/proto/ComponentSpecificationMessage.pb.h"
     25 
     26 namespace android {
     27 namespace vts {
     28 
     29 // Base class generates LLVM libfuzzer code for HAL interfaces.
     30 // Takes VTS spec in the form of a ComponentSpecificationMessage and generates
     31 // one source file per interface function in the spec.
     32 // All fuzzer code generators should derive from this class.
     33 class FuzzerCodeGenBase {
     34  public:
     35   FuzzerCodeGenBase(const ComponentSpecificationMessage &comp_spec)
     36       : comp_spec_(comp_spec) {}
     37 
     38   virtual ~FuzzerCodeGenBase(){};
     39 
     40   // Generates all files.
     41   void GenerateAll(Formatter &header_out, Formatter &source_out);
     42   // Generates fuzzer header file.
     43   void GenerateHeaderFile(Formatter &out);
     44   // Generates fuzzer source file.
     45   void GenerateSourceFile(Formatter &out);
     46 
     47  protected:
     48   // Generates "#include" declarations.
     49   virtual void GenerateSourceIncludeFiles(Formatter &out) = 0;
     50   // Generates "using" declarations.
     51   virtual void GenerateUsingDeclaration(Formatter &out) = 0;
     52   // Generates global variable declarations.
     53   virtual void GenerateGlobalVars(Formatter &out) = 0;
     54   // Generates definition of LLVMFuzzerInitialize function.
     55   virtual void GenerateLLVMFuzzerInitialize(Formatter &out) = 0;
     56   // Generates definition of LLVMFuzzerTestOneInput function.
     57   virtual void GenerateLLVMFuzzerTestOneInput(Formatter &out) = 0;
     58   virtual void GenerateOpenNameSpaces(Formatter &out);
     59   virtual void GenerateCloseNameSpaces(Formatter &out);
     60 
     61   // Generates warning that file was auto-generated.
     62   virtual void GenerateWarningComment(Formatter &out);
     63 
     64   // Contains all information about the component.
     65   const ComponentSpecificationMessage &comp_spec_;
     66 };
     67 
     68 }  // namespace vts
     69 }  // namespace android
     70 
     71 #endif  // VTS_COMPILATION_TOOLS_VTSC_CODE_GEN_FUZZER_FUZZERCODEGENBASE_H_
     72