Skip to content

[Feature] Unit test development tracking #488

@chenshengxin2026

Description

@chenshengxin2026

Summary

Tracking issue for unit test (UT) development across the simpler project. The goal is to build comprehensive offline-runnable unit tests for C++ runtime modules and Python utilities, enabling faster development iteration without requiring hardware.

Current Progress

Initial UT infrastructure and first batch of tests landed in PR #427 (add-unit-tests-cpp-and-python branch):

C++ Unit Tests (tests/ut/cpp/) — GoogleTest-based

Covering the a2a3/tensormap_and_ringbuffer runtime:

Test File Module Under Test Status
test_ring_buffer.cpp pto_ring_buffer.h/cpp 2 intentional failures (expose known heap wrap-around & dep-pool entry-0 bugs)
test_scheduler_state.cpp pto_scheduler.h/cpp Pass
test_tensormap.cpp pto_tensormap.h/cpp Pass
test_shared_memory.cpp pto_shared_memory.h/cpp Pass
test_ready_queue.cpp ready queue logic Pass
test_core_types.cpp core type definitions Pass
test_submit_types.cpp pto_submit_types.h Pass
test_tensor.cpp tensor.h Pass
test_dispatch_payload.cpp pto2_dispatch_payload.h Pass
test_pto_types.cpp pto_types.h Pass

Python Unit Tests (tests/ut/) — pytest-based

Test File Module Under Test Status
test_elf_parser.py python/elf_parser.py 12 tests, all pass
test_env_manager.py python/env_manager.py 7 tests, all pass
test_task_interface.py python/task_interface.py (nanobind bindings) Pass
test_runtime_builder.py python/runtime_compiler.py + examples/scripts/runtime_builder.py Pass
test_chip_worker.py src/common/worker/chip_worker.h/cpp Pass

CI

  • ut-cpp job added to .github/workflows/ci.yml — builds and runs C++ tests on ubuntu-latest (no hardware required)

Remaining Coverage Gaps

C++ — High Priority

  • aicpu_build_graph runtimepto_runtime2, pto_orchestrator, pto_scheduler, pto_shared_memory, pto_ring_buffer (shared source with tensormap_and_ringbuffer but different build config)
  • host_build_graph runtimeruntime.h/cpp, aicore/aicpu executors
  • Platform modulesmemory_allocator, function_cache, host_regs, raii_scope_guard, runtime_compile_info (host-side, testable offline)
  • Common modulestask_interface/task_args.h, data_type.h, arg_direction.h type correctness tests
  • a5 architecture — verify tests also compile against a5 headers (shared runtime source)

Python — Medium Priority

  • kernel_compiler.pyKernelCompiler class, toolchain selection, flag generation
  • toolchain.pyGxxToolchain, Aarch64GxxToolchain, CCECToolchain flag/path logic
  • examples/scripts/platform_info.py — architecture detection, platform discovery
  • examples/scripts/run_example.py — argument parsing, config loading (unit-testable parts)
  • examples/scripts/code_runner.py — execution flow logic

Infrastructure

  • Python UT CI job (pytest on ubuntu-latest)
  • Coverage reporting (optional)
  • Fix the 2 known bug-exposing failures in test_ring_buffer (tracked separately as bug fixes)

Motivation / Use Case

Unit tests that run offline (no Ascend hardware) enable:

  1. Faster CI feedback — catch regressions in seconds, not minutes
  2. Safer refactoring — runtime internals (ring buffer, scheduler, shared memory) are complex and subtle
  3. Bug detection — the initial batch already found 2 bugs in ring buffer logic
  4. Developer onboarding — tests serve as executable documentation of module contracts

Proposed Approach

  • C++ tests use GoogleTest with lightweight stubs for platform headers (no hardware dependency)
  • Python tests use pytest with mocking for external dependencies (compilers, file system)
  • Tests target module-level contracts, not integration behavior
  • Bug-exposing tests are kept with correct expected values; they fail until the bug is fixed

Additional Context

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions