Skip to content

[WIP] Add unit test framework with C++ (GoogleTest) and Python (pytest) test suites#341

Open
chenshengxin2026 wants to merge 2 commits intohw-native-sys:mainfrom
chenshengxin2026:UT/dev-v1
Open

[WIP] Add unit test framework with C++ (GoogleTest) and Python (pytest) test suites#341
chenshengxin2026 wants to merge 2 commits intohw-native-sys:mainfrom
chenshengxin2026:UT/dev-v1

Conversation

@chenshengxin2026
Copy link
Copy Markdown
Contributor

@chenshengxin2026 chenshengxin2026 commented Mar 23, 2026

Summary

  • Add 12 C++ GoogleTest tests covering runtime internals: task graph
    construction (host_build_graph), ring buffers (HeapRing, TaskRing),
    dependency pool, tensor overlap detection, TensorMap hash table,
    ReadyQueue (lock-free MPMC), shared memory layout, task state machine,
    scope mechanism, and handshake protocol macros
  • Add 5 Python pytest tests covering build infrastructure: ELF/Mach-O
    parsing (elf_parser), toolchain flag generation (toolchain), kernel
    compilation pipeline (kernel_compiler), CMake-based runtime compilation
    (runtime_compiler), and ctypes bindings (bindings)
  • Add CMake build system (tests/cpp/CMakeLists.txt) with GoogleTest
    auto-fetch fallback and stub library for host-side testing
  • Update ci.sh to run both unit test suites before platform-specific
    integration tests, requiring no hardware or simulation environment

Motivation

The existing test infrastructure relies on end-to-end device tests or simulation
(ci.sh -p a2a3 / a2a3sim), which are slow and require specific environments. These
unit tests validate individual data structures and Python modules in isolation, enabling
faster development feedback loops and CI gating without hardware dependencies.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the project's testing infrastructure by integrating dedicated unit test frameworks for both C++ and Python components. This initiative aims to provide faster development feedback loops and enable more efficient continuous integration by validating individual modules in isolation, thereby reducing reliance on slower, environment-dependent end-to-end device tests.

Highlights

  • C++ Unit Test Framework: Added a C++ unit test framework under 'tests/cpp/' utilizing GoogleTest and CMake, including a stub library to decouple tests from device-specific platform code.
  • C++ Test Suites for Core Runtime Data Structures: Introduced four new C++ test suites for critical runtime data structures: 'HeapRing' (ring buffer allocator), 'PTO2ReadyQueue' (lock-free MPMC scheduler queue), 'Runtime' (task DAG in 'host_build_graph'), and 'TensorMapEntry' overlap detection.
  • Python Unit Tests: Implemented Python unit tests under 'tests/unit/' using pytest to validate 'elf_parser.py' (ELF64/Mach-O binary parsing) and 'toolchain.py' (compiler toolchain configuration).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a comprehensive unit test framework for both C++ and Python components, which is a significant improvement for code quality and development velocity. The tests are well-structured and cover a wide range of scenarios, including core data structures, binary parsing, and toolchain configuration. My feedback focuses on a few areas to enhance maintainability and test robustness: improving the CMake helper function for consistency, cleaning up test code, and strengthening the logic in a concurrent stress test to ensure it's more effective.

@chenshengxin2026 chenshengxin2026 force-pushed the UT/dev-v1 branch 2 times, most recently from 32b5caa to 05f2fa7 Compare March 24, 2026 05:22
@chenshengxin2026 chenshengxin2026 changed the title Add unit test framework with C++ (GoogleTest) and Python (pytest) test suites [WIP] Add unit test framework with C++ (GoogleTest) and Python (pytest) test suites Mar 24, 2026
…structure

Introduce two unit test suites (12 C++ GoogleTest, 5 Python pytest) that
validate core runtime data structures and the Python compilation pipeline
without requiring hardware or simulation. Integrate both into ci.sh as a
pre-integration-test stage.
- Add test_coupling.cpp with 27 tests across 5 suites (ComponentIsolation,
  InitializationOrder, CrossComponentContract, StateLeakage, CompileTimeCoupling)
  using full TMR runtime linkage to detect and document coupling defects
- Add test_coupling_stub.cpp with 20 tests across 5 suites (DepPoolStubIsolation,
  SchedulerWithoutOrchestrator, TensorMapLinkDecoupling, CompileTimeIncludeCoupling,
  ProfilingBehaviorCoupling) using selective linking to prove isolation boundaries
- Update CMakeLists.txt with two new test targets: test_coupling (full linkage)
  and test_coupling_stub (orchestrator excluded to verify link-time isolation)
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