API
 
Loading...
Searching...
No Matches
Collaboration diagram for flatlogs Unit Tests:

Catch2 Test Generator for MagAOX Flatlogs

Background

The MagAO-X ecosystem is largely based on C++. Type-safe logging requirements play a key role in the ecosystem's robustness. The MagAO-X logging system is based on Flatfile (created by Facebook), and is controlled through the Flatlog classes within MagAO-X. Individual entries within Flatlogs may each contain different data and be of a different type. The types are defined as C++ classes generated from the Flatfile configuration. Lastly, MagAO-X installations may each utilize different classes for their logging needs.

While Flatlogs is an excellent method of logging variadic data of multiple types, testing the flatlog classes is difficult. Entry classes need to be tested singularly with generated data, and also need to be tested together in longer sequences of logs.

To this end, the Catch2 Test Generator will automatically review the class definitions in the Flatfile .fbs schema files. Once analyzed, the generator will create singular C++ tests using Catch2, compile, run, and report their results. In addition, the generator will also generate a combined test of multiple "random" types and compile, run and report their results.

Getting started

The test generator is composed of two files, generateTemplatedCatch2Tests.py and catch2TestTemplate.jinja2. When run, Catch2 test files for each flatlog type will be created.

How To Run

Pre-requisites

  1. Python must be installed with version >= 3.9. This is checked by the script. (As of this writing, the generator has been tested with Python 3.12.)
  2. jinja2 must be installed. The script will check for jinja2 and automatically install it if not present. It can be installed manually with the following command:

    python3 -m pip install Jinja2

It is assumed that any libraries and dependencies for the flatlog types have already been installed.

Generating the tests

The generator can be run by either running the python script directly, or calling the Makefile target. They are functionally equivalent.

To run the generator, do:

python3 ./generateTemplatedCatch2Tests.py

or

make generated_tests

Upon success, a folder titled generated_tests will be created, containing generated tests with the title <log_type>_generated_tests.cpp.

Running the tests

To build and run the tests, do:

make do_catch2_test

If the generated test files are not present, they will be generated by the Makefile.

Notes/Caveats:


Entropy Test Generator

In order to test flatlogs further, 'entropy' tests can be generated. These tests consist of a number of flatlogs being created with random values, and then each field is verified one-by-one.

The entropy generator is composed of entropyTestTemplate.jinja2 and generateEntropyTests.py. Both files should be in the same directory as types/.

How to Run

Pre-requisites

The Catch2 Test Generator described above must be run before entropy tests can be generated, since entropy tests include these test files.

The easiest way to generate, compile, and run the entropy test is through the makefile target:

make do_entropy_test <OPTIONS>

The generated file is written to gen_entropy_tests/generated_test_e<ENTROPY>_n<NTYPES>.cpp

For example, if e=3 and n=12, the cpp file is titled generated_test_e3_n12.cpp

and the test executable is generated_test_e3_n12.

Options

Note: It is not required to provide these options on the commandline. Their default values are stored as variables in the makefile, and can be set there as well.

Example usage

make do_entropy_test

make do_entropy_test s=123 n=25 e=2

make do_entropy_test n=5 e=5 t="config_log, git_state"

Notes/Caveats