Skip to content

[WIP] Add Binary Golden Test Framework for C++ backend#108

Draft
Copilot wants to merge 1 commit intomasterfrom
copilot/implement-binary-golden-test-framework
Draft

[WIP] Add Binary Golden Test Framework for C++ backend#108
Copilot wants to merge 1 commit intomasterfrom
copilot/implement-binary-golden-test-framework

Conversation

Copy link

Copilot AI commented Dec 6, 2025

Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.

Original prompt

This section details on the original issue you should resolve

<issue_title>Implement Binary Golden Test Framework for C++ Backend</issue_title>
<issue_description>This issue was copied from the upstream repository google/emboss.

Original issue: google#225
Original state: open, created at: 2025-07-08T00:04:36Z, updated at: 2025-07-08T05:01:55Z, by @EricRahm


Original 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</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Binary Golden Test Framework for C++ Backend

2 participants