[Concept,00/21] test: Add support for passing arguments to C unit tests

Message ID 20251214175449.3799539-1-sjg@u-boot.org
Headers
Series test: Add support for passing arguments to C unit tests |

Message

Simon Glass Dec. 14, 2025, 5:54 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

This series adds infrastructure for passing runtime arguments from Python
tests to C unit tests. This makes it easier to support a hybrid testing
approach where Python handles complex setup (filesystem images,
environment configuration) while C handles the actual test logic with
better debuggability.

A few other things are included to make this work:

- A fix for linker list alignment that was causing garbage values like
  "Running -858993444 bloblist tests" due to GCC's magic-number division
  optimization failing when padding breaks exact multiples

- A fix fix for serial output with sandbox, since it sometimes misses
  output at the end when running tests with gnome terminal

- Improvements to the linker-list script to detect padding and
  pointer-arithmetic bugs

- A new UNIT_TEST_ARGS() macro for declaring tests with typed arguments,
  along with argument parsing in the ut command (name=value format)

- Argument-accessor macros ut_str(), ut_int(), and ut_bool() with
  type-checking and bounds validation

- A private buffer (uts->priv) for test-local temporary data, which
  makes it a little easier to write shorter tests

- Tests for the argument feature (test_args) covering type checking,
  bounds checking, and argument-parsing failures

As an example, the basic filesystem tests are converted from pure Python
to C with Python wrappers.

Some improved printf documentation and support for Linux's %pV format
are provided.

The slight increase in size causes qemu-riscv64_spl to fail, so this
series also includes a patch to increase the SPL-malloc() space.


Heinrich Schuchardt (1):
  configs: raise SPL_SYS_MALLOC_SIZE to 8 MiB on RISC-V

Simon Glass (20):
  serial: Retry output if it fails
  sandbox: serial: Report output failurs
  doc: Expand printf documentation
  doc: Document tiny printf for SPL
  vsprintf: Add support for the %pV format-specifier
  check_linker_lists: Enhance detection of alignment problems
  linker_lists: Fix end-marker alignment to prevent padding
  test: vbe: Fix the ut-flag order in vbe_test_fixup_norun()
  test: Add a helper to check the next line against a regex
  test: Add argument-type definitions
  test: Add a macro to declare unit tests with arguments
  test: Add support for passing arguments to C tests
  test: Enhance the ut command to pass test arguments
  test: Add type-checked argument accessor functions
  test: Add a private buffer for tests
  test: Allow preserving console recording on failure
  test: Add tests for unit-test arguments
  test: fs: add C-based filesystem tests
  test: fs: Update Python tests to call C implementations
  test: Add documentation for test parameters

 arch/sandbox/cpu/spl.c              |   3 +-
 common/spl/Kconfig                  |   1 +
 doc/develop/printf.rst              | 174 +++++++++-
 doc/develop/tests_writing.rst       |  58 ++++
 doc/usage/cmd/ut.rst                |  18 +-
 drivers/serial/sandbox.c            |   7 +-
 drivers/serial/serial-uclass.c      |   2 +
 include/linker_lists.h              |  22 +-
 include/linux/printk.h              |   5 +
 include/test/fs.h                   |  39 +++
 include/test/test.h                 | 109 ++++++
 include/test/ut.h                   |  83 ++++-
 lib/vsprintf.c                      |  12 +
 scripts/check_linker_lists.py       | 206 ++++++++----
 test/Makefile                       |   1 +
 test/cmd_ut.c                       |  38 ++-
 test/common/Makefile                |   1 +
 test/common/print.c                 |  48 +++
 test/common/test_args.c             | 186 +++++++++++
 test/fs/Makefile                    |   3 +
 test/fs/fs_basic.c                  | 492 ++++++++++++++++++++++++++++
 test/py/tests/test_fs/conftest.py   |   4 +-
 test/py/tests/test_fs/test_basic.py | 346 ++++++-------------
 test/py/tests/test_vbe.py           |   2 +-
 test/test-main.c                    | 170 +++++++++-
 test/ut.c                           |  94 +++++-
 26 files changed, 1776 insertions(+), 348 deletions(-)
 create mode 100644 include/test/fs.h
 create mode 100644 test/common/test_args.c
 create mode 100644 test/fs/Makefile
 create mode 100644 test/fs/fs_basic.c