Skip to content

Add symbol-based testing infrastructure#1

Merged
olaugh merged 1 commit intomainfrom
symbol-instrumentation
Jan 20, 2026
Merged

Add symbol-based testing infrastructure#1
olaugh merged 1 commit intomainfrom
symbol-instrumentation

Conversation

@olaugh
Copy link
Owner

@olaugh olaugh commented Jan 20, 2026

Add support for asserting on Genesis ROM variables by name instead of hardcoded addresses. This improves test readability and provides compile-time safety when ROM symbols change.

New components:

  • tools/elf2sym.py: Extracts symbols from ELF and generates C++ headers
  • roms/symbol_example/: Example ROM with global variables for testing
  • tests/symbol_example_test.cpp: 13 tests demonstrating symbol-based assertions

The symbol extraction pipeline:

  1. Compile ROM with m68k-elf-gcc (produces .elf with symbol table)
  2. Run nm to extract symbols, filter to RAM range (0xFF0000-0xFFFFFF)
  3. Generate C++ header with constexpr addresses in Sym:: namespace
  4. Include header in tests and assert using Sym::variable_name

CMake integration supports both:

  • GXTEST_BUILD_ROMS=ON: Build ROMs and generate symbols at build time
  • Pre-built headers: Install headers from roms/*/Makefile for CI without toolchain

Also adds comprehensive README documenting gxtest features and usage.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds symbol-based testing infrastructure to gxtest, enabling tests to reference ROM variables by name rather than hardcoded memory addresses. The feature extracts symbol information from ELF files during the build process and generates C++ headers with constexpr address definitions.

Changes:

  • New Python tool (tools/elf2sym.py) to extract symbols from nm output and generate C++ headers
  • Example ROM implementation with 13 comprehensive tests demonstrating symbol-based assertions
  • CMake integration supporting both on-demand ROM builds (with m68k-elf-gcc) and pre-built headers
  • Comprehensive README documenting all gxtest features including the new symbol-based testing workflow

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
tools/elf2sym.py Python script that parses nm output, filters RAM symbols, and generates C++ headers with constexpr addresses
tests/symbol_example_test.cpp 13 test cases demonstrating symbol-based testing patterns including initialization, state transitions, memory injection, and collision detection
tests/symbol_example_symbols.h Generated C++ header with symbol addresses in Sym namespace for use in tests
tests/symbol_example_rom.h Generated header embedding the compiled ROM binary as a byte array
roms/symbol_example/main.c C source for example ROM implementing a simple game loop with global variables for testing
roms/symbol_example/genesis.ld Linker script defining Genesis memory layout (ROM, RAM sections)
roms/symbol_example/crt0.s Assembly startup code with ROM header and BSS initialization
roms/symbol_example/Makefile Build system for cross-compiling the ROM and generating headers
roms/symbol_example/symbol_example_symbols.txt Intermediate nm output showing extracted symbols
roms/symbol_example/symbol_example_symbols.h Generated symbol header (duplicate of tests version)
roms/symbol_example/symbol_example_rom.h Generated ROM header (duplicate of tests version)
CMakeLists.txt CMake integration for ROM building with toolchain detection and pre-built header fallback
README.md Comprehensive documentation covering all gxtest features, APIs, and symbol-based testing workflow

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@olaugh olaugh force-pushed the symbol-instrumentation branch 9 times, most recently from c35a307 to 4b0265f Compare January 20, 2026 16:21
@olaugh olaugh requested a review from Copilot January 20, 2026 16:23
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Add support for asserting on Genesis ROM variables by name instead of
hardcoded addresses. This improves test readability and provides
compile-time safety when ROM symbols change.

New components:
- tools/elf2sym.py: Extracts symbols from ELF and generates C++ headers
- roms/symbol_example/: Example ROM with global variables for testing
- tests/symbol_example_test.cpp: 13 tests demonstrating symbol-based assertions

The symbol extraction pipeline:
1. Compile ROM with m68k-elf-gcc (produces .elf with symbol table)
2. Run nm to extract symbols, filter to RAM range (0xFF0000-0xFFFFFF)
3. Generate C++ header with constexpr addresses in Sym:: namespace
4. Include header in tests and assert using Sym::variable_name

CMake integration supports both:
- GXTEST_BUILD_ROMS=ON: Build ROMs and generate symbols at build time
- Pre-built headers: Install headers from roms/*/Makefile for CI without toolchain

Also adds comprehensive README documenting gxtest features and usage.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@olaugh olaugh force-pushed the symbol-instrumentation branch from 4b0265f to 8d7d1c3 Compare January 20, 2026 16:28
@olaugh olaugh merged commit c96c601 into main Jan 20, 2026
4 checks passed
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.

2 participants