Mock Generator

The mock generator is planned to automatically create functional mocks based on the source files of a component. Ideally this creates a complete mock/<component> folder with all necessary files, including a CMakeLists file, Should we be able to gain all the needed information.

All mock generator related files are located under <elos>/test/tools/mock.

The mocks are generated by using clang AST bindings from within a python script, which allows us to step through the AST tree for a given source file. This is a powerful feature that, when expanded upon, could be used for much more than mock generation, like further checking of source code (e.g. is there only one return present per function?)

For this use case, everything clang related is located in ast_parser.py.

ast_parser.py is intended to be included in other python scripts like for example generate.py, and has functions for creating a dictionary with all found functions and their respective parameters as well as the return types.

generate.py is responsible for creating the mock sources and header files, and can be used in the following manner:

cd <elos>
./test/tools/mock/generate.py ./src/components/eventbuffer /tmp/mock

The first parameter is the component, the second parameter is the folder in which the mock files are created. The folder is created in case is doesn’t exist, while the mock files themselves are either created from scratch or overwritten.

Note: While the mock files are largely functional, there are still some issues with the autogeneration that need to be worked out. That being said, correcting these issues should take a lot less time than writing everything from scratch, so experimentation is encouraged.