Implement Binary Golden Test Framework for C++ Backend
- Dominant language
- Python
- Stars
- 92
- Forks
- 30
- PR merge metrics
- No merged PRs in 30d
Description
This work introduces a new testing framework for the C++ backend that verifies the correctness of binary serialization and deserialization. This framework, called "Binary Golden Tests," allows for the rapid development of tests that cover a wide range of Emboss features and data types. The goal is to make it easy to expand these tests to alternate language backends.
## Core Components
1. **Test Asset Format:** A new test is defined by a set of three files:
* An .emb file defining the structure.
* A .json file containing the expected field values and types.
* A .bin file containing the "golden" raw binary data.
2. **Test Generator Script (`generate_cpp_gtest.py`)**: A Python script that reads the test asset files and automatically generates a C++ GTest source file. The generated test includes two primary test cases:
* **Read Test:** Verifies that reading from the golden .bin file produces the expected values from the .json file.
* **Write Test:** Verifies that creating a new view, writing the expected values, and serializing it produces a binary identical to the golden .bin file.
3. **Bazel Macro (`binary_golden_test`):** A new Bazel macro that encapsulates the test generation and compilation logic. This allows a new binary golden test to be added to the build with a single, clean rule, significantly improving the maintainability of the BUILD files.
## Initial Test Coverage
As a starting point for coverage of the C++ backend, the following test cases were implemented using the new framework:
* `simple_structure`: A basic test to validate the initial infrastructure.
* `integer_types`: Verifies integers of all supported sizes, from 8 to 64 bits.
* `big_endian`: Ensures correct handling of non-default (big-endian) byte ordering.
* `floating_point`: Tests Float(32) and Float(64) data types.
* `enums_and_bools`: Verifies Flag (boolean) and enum types.
* `bitfields`: Tests bits structures with non-byte-aligned fields.
* `fixed_arrays`: Verifies support for fixed-size arrays
Contributor guide
Assessment
This issue has not been assessed yet.