Files
2026-02-26 17:41:05 +01:00

2.7 KiB

Test Generator

A command-line tool that reads JSON configuration files and generates C++ test code.

Features

  • Parses JSON configuration files without external dependencies
  • Generates C++ test classes from templates
  • Supports multiple instrument configurations
  • Merges common and variant-specific setups
  • Variable substitution in configurations

Building

Requirements

  • GCC (g++) with C++11 support
  • Standard C++ library only (no external dependencies)

On Windows

build.bat

On Linux/Mac

make

This will create the testgen (or testgen.exe on Windows) executable.

Usage

Generate Test Code

testgen -commonPath <common_path> -variantPath <variant_path>

Example:

testgen -commonPath ..\SMT_PlayGround\hw_ext_tests -variantPath ..\SMT_PlayGround\hw_ext_variants\Avi64\Driver\TestSetup

Validate JSON File

testgen -dry <json_file>

Example:

testgen -dry test.json

Display Help

testgen -help

Generated Files

The tool generates C++ files in <variantPath>/generatedTests/:

  • Instruments.h - Instrument definitions
  • Measurement.h - Measurement interface (stub)
  • Test_*.cpp - Generated test classes
  • main.cpp - Main entry point that runs all tests
  • build.bat - Windows build script for generated tests
  • Makefile - Linux/Mac build script for generated tests

Building Generated Tests

After generation, build and run the tests:

Windows:

cd <variantPath>/generatedTests
build.bat
test_runner.exe

Linux/Mac:

cd <variantPath>/generatedTests
make
./test_runner

Project Structure

TestGenerator/
├── src/
│   ├── main.cpp              # Entry point and command-line parsing
│   ├── json_parser.h/.cpp    # JSON parser implementation
│   ├── file_utils.h/.cpp     # File I/O utilities
│   ├── code_generator.h/.cpp # Code generation logic
│   └── data_structures.h     # Data structure definitions
├── Makefile                  # Build script for Linux/Mac
├── build.bat                 # Build script for Windows
└── README.md                 # This file

Architecture

  1. JSON Parser - Simple recursive descent parser for JSON
  2. Data Structures - Type-safe structures for configuration data
  3. File Utils - Cross-platform file and directory operations
  4. Code Generator - Template-based C++ code generation
  5. Main - Command-line interface and orchestration

Notes

  • All code uses only the C++ standard library
  • No terminal/console APIs are used in the domain logic
  • Generated code requires linking with actual Measurement implementation
  • Variable substitution supports expressions like 0.03*gangCount