Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
tc_capture.h File Reference

Test output capture helper. More...

#include <stdbool.h>
#include <stddef.h>

Go to the source code of this file.

Functions

void tc_capture_start (void)
 Start capturing test output.
void tc_capture_stop (void)
 Stop capturing test output.
bool tc_capture_contains (const char *substr)
 Check whether the captured output contains a substring.
size_t tc_capture_get (char *dst, size_t size)
 Copy the captured output into a caller-provided buffer.
void tc_capture_clear (void)
 Discard any captured output without stopping capture.

Detailed Description

Test output capture helper.

Captures the textual diagnostic output produced during a test into an in-memory buffer so it can be asserted on, without each test having to wire up its own log backend or printk hook. Both output routes are handled transparently:

  • printk() output (and logging in CONFIG_LOG_MODE_MINIMAL, which is routed through printk) is captured by wrapping the printk character-output hook.
  • Full logging output ( CONFIG_LOG with a real backend mode) is captured through a dedicated log backend.

Typical use:

do_something_that_prints();
#define zassert_true(cond,...)
Assert that cond is true.
Definition ztest_assert.h:275
void tc_capture_stop(void)
Stop capturing test output.
void tc_capture_start(void)
Start capturing test output.
bool tc_capture_contains(const char *substr)
Check whether the captured output contains a substring.
Note
When capturing logging output, the message must reach the backend before tc_capture_stop() is called. Use CONFIG_LOG_MODE_IMMEDIATE (or otherwise flush the logs) so deferred messages are not missed.

Function Documentation

◆ tc_capture_clear()

void tc_capture_clear ( void )

Discard any captured output without stopping capture.

◆ tc_capture_contains()

bool tc_capture_contains ( const char * substr)

Check whether the captured output contains a substring.

Parameters
substrNUL-terminated substring to search for.
Return values
trueif substr is present in the captured output.
falseotherwise.

◆ tc_capture_get()

size_t tc_capture_get ( char * dst,
size_t size )

Copy the captured output into a caller-provided buffer.

The copy is always NUL-terminated (unless size is 0) and is truncated to fit size.

Parameters
dstDestination buffer.
sizeSize of dst in bytes.
Returns
Number of bytes copied, excluding the NUL terminator.

◆ tc_capture_start()

void tc_capture_start ( void )

Start capturing test output.

Clears any previously captured data and begins recording printk and logging output into the internal capture buffer. Capturing continues until tc_capture_stop() is called. Output is still forwarded to the normal console so ordinary test logs are unaffected.

◆ tc_capture_stop()

void tc_capture_stop ( void )

Stop capturing test output.

Restores the normal output path. The captured data remains available for inspection with tc_capture_contains() and tc_capture_get() until the next tc_capture_start() or tc_capture_clear().