Skip to content

Comments

codegen: emit nested JSON arrays in testbench#10

Merged
strimo378 merged 1 commit intomainfrom
codex/add-testbench-with-main-function
Jan 10, 2026
Merged

codegen: emit nested JSON arrays in testbench#10
strimo378 merged 1 commit intomainfrom
codex/add-testbench-with-main-function

Conversation

@strimo378
Copy link
Contributor

Motivation

  • Emit N-dimensional (ndim) JSON arrays for tensor data in the generated C testbench instead of flat arrays.
  • Make testbench emission opt-in so callers can request nested JSON output via compiler options.
  • Produce deterministic, template-driven testbench output that is easy to review and compare with golden files.

Description

  • Add emit_testbench: bool to CompilerOptions and thread it into CEmitter.emit_model to enable optional testbench emission.
  • Compute per-tensor loop metadata and linear index expressions with new helpers (_element_count, _index_expr) and include loop_vars, loop_indents, inner_indent, and rank in the template context.
  • Replace the testbench template with templates/testbench.c.j2 that renders nested JSON arrays for inputs and outputs using the loop metadata, and include #include <stdio.h>/#include <stdlib.h> only when emit_testbench is enabled.
  • Refresh the golden output tests/golden/add_model_testbench.c and add the test test_codegen_includes_testbench in tests/test_add_mvp.py which exercises CompilerOptions(template_dir=Path("templates"), emit_testbench=True).

Testing

  • Ran the test suite with pytest -n auto -q and all tests passed (11 passed).
  • The new golden comparison test test_codegen_includes_testbench executed as part of the suite and succeeded against tests/golden/add_model_testbench.c.
  • The updated template was exercised by compiling the sample add model and writing the refreshed golden file before running tests.

Codex Task

@strimo378 strimo378 merged commit 9fc2019 into main Jan 10, 2026
0 of 2 checks passed
@strimo378 strimo378 deleted the codex/add-testbench-with-main-function branch January 10, 2026 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant