test: Add a private buffer for tests

Add a priv[] buffer to struct unit_test_state that tests can use for
their own data. This avoids the need to allocate memory or use global
variables for test-specific state.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
This commit is contained in:
Simon Glass
2025-12-12 15:18:38 -07:00
parent a9d6c0322e
commit f4e11a4052
2 changed files with 17 additions and 0 deletions

View File

@@ -486,6 +486,20 @@ ut_check_delta(last)
Return the change in free memory since ``last`` was obtained from
``ut_check_free()``. A positive value means more memory has been allocated.
Private buffer
~~~~~~~~~~~~~~
Each test has access to a private buffer ``uts->priv`` (256 bytes) for temporary
data. This avoids the need to allocate memory or use global variables::
static int my_test(struct unit_test_state *uts)
{
snprintf(uts->priv, sizeof(uts->priv), "/%s", filename);
/* use uts->priv as a path string */
return 0;
}
Writing Python tests
--------------------