Skip to content

boschglobal/AutoDepMocker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AutoDepMocker

A simple utility that helps identifying dependencies of your test unit and generate Google Mock class out of that

Why AutoDepMocker

Writting mock classes for test units can often be tedious and time-consuming. It requires the identification of the classes, methods, and declarations that need to be mocked

AutoDepMocker comes here to simplify the mocking process. The tool has the intelligence to identify the dependencies of your class and will generate google mock class

How it works

AutoDepMocker is using clang frontend parsing libraries(libtooling, AST, ...) to parse the given input file and note downs each declarations and function calls. Once parsing is complete, it uses MockClassGenerator to construct mock class
Please refer CMakeLists.txt include list to know more about the list of clang libraries used in AutoDepMocker

How to Build

Build from source:

  • Run Build.sh in your linux machine
    This script takes care of installing the necessary packages required to build this utility, Finally the executable will be installed in ~/.bin/ directory.

Prebuild binaries

  • This support is yet to be added

How to generate mock class

Basically AutoDepMocker provides below utilities

  1. AutoDepMocker
    The core utility which takes care of parsing the given source file and generate mock class
     Note: AutoDepMocker expects right compilation settings to be passed along with source file like your compiler
    So always use plugin script to execute AutoDepMocker until unless you know all such compilation settings of your test unit

  2. Python plugin
    A plugin which helps identifying the right include paths from cmake build output files and execute AutoDepMocker with necessary includes, sysroot and compiler settings
    A plugin which is developed for Yocto environment which uses CMake Ninja build system is available here
     Please refer here if you want to write a plugin suitable for your build environment

    Yocto project which uses CMake and Ninja:

    A python utility AutoDepMocker_YoctoCMake.py is written to parse CMake and ninja files for Yocto based project. It executes AutoDepMocker with necessary options

    1. Run AutoDepMocker_YoctoCMake.py:
      Example: AutoDepMocker_YoctoCMake.py -s MyProject/MySourceFile.cpp -r MyProject/ -sr /repo/out/MyProject/git/recipe-sysroot/
      -s: The source file you intend to test.
      -r: Typically your git repository path.
      -sr: The Yocto recipe-sysroot path of your recipe.
    2. Choose either interactive or non-interactive mode.
    3. That's all! Mock class would be generated and available in ./GeneratedMocks directory

How to use AutoDepMocker on other build environment

Consider AutoDepMocker as like any compiler. It needs to know all such compiler options to work correctly and since this has been developed using clang libraries, below clang compier options to be passed when executing

So You need to perform below steps to execute AutoDepMocker with right compilation options in your build environment

  1. Write a utility to fetch compilation settings information from build files
    List of options to be read from build files and to be passed to AutoDepMocker

    1. Your test unit(either .c or .cpp file)
    2. sysroot - sysroot directory. Example-./MyRecipe/git/recipe-sysroot/
    3. target - Target for which the file is developed for. Example-arm-v5-nvidia-linux-hard
    4. mfpu - FPU options for a specific processor or architecture. Example-neon or vfp
    5. mfloat-abi - Mostly either hard or soft
    6. march - Target architecture for which the code is being compiled
    7. List of include directories - Example- -I/MyIncludeDir
      Example: AutoDepMocker MyFile.cpp -- --sysroot=/path/to/my/sysroot/ --target=arm-v5-nvidia-linux-hard -mfpu=neon -mfloat-abi=hard -march=armv7-a -mthumb --std=c++17 -I/MyInclude/Directory1/ -I/MyInclude/Directory2/
      Note: All options should be passed only after the double dash(--) like above
  2. Execute AutoDepMocker with necessary compilation options like above from the utility
    Lets say you want to use it in yocto environment which has meson build system.
    Write a utility to grab your compilation include information from build output/config files and pass it to AutoDepMocker. That's it!

How to use AutoDepMocker for other Mocking framework

  • Current AutoDepMocker has CodeGenUtils which supports to build GMOCK classes
  • Just replace this component with your own component to support for other mocking frameworks
  • Task has been planned to move code generation part CodeGenUtils as a plugin for convenience

Possible error when mocking

  • Make sure you don't have previous GeneratedMocks directory
  • Make sure your build directory is not broken if you are using any plugin

Limitations

  • AutoDepMocker does not offer support for mocking classes that lack methods
  • AutoDepMocker supports only in mocking class methods, C/C++ enums and C functions
  • AutoDepMocker does not provide support for mocking class member variables
  • Due to the intricate nature of C++ standard include files, the inclusion of "bits/stdc++.h" becomes necessary in generated files
  • The performance and effectiveness of AutoDepMocker rely entirely on the provided input

Author

Maintainer

License

AutoDepMocker is open-sourced under the Apache-2.0 license. See the LICENSE file for details

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published