no-OS
Loading...
Searching...
No Matches
test_framework.c File Reference

Platform-agnostic test framework source for capi_selftest project. Copyright (c) 2025-2026 Analog Devices, Inc. More...

#include <errno.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include "test_framework.h"
Include dependency graph for test_framework.c:

Macros

#define TEST_FRAMEWORK_BUFFER_SIZE   256U
 

Functions

int test_framework_init (const struct test_framework_config *config)
 Initialize the test framework.
 
void test_framework_remove (void)
 Remove the test framework configuration.
 
void test_framework_reset (void)
 Reset the current test context and counts.
 
void test_framework_run_start (void)
 Start a test run, reset its counts and arm the watchdog.
 
void test_framework_run_end (void)
 Disarm the watchdog, print the final counts and end the run.
 
void test_framework_checkpoint (const char *func, int line)
 Record the last reached source location (function and line).
 
void test_framework_on_timeout (void)
 Report from the platform watchdog handler that the run hung.
 
void test_framework_begin (const char *module, const char *name)
 Select the current test module and test name.
 
void test_framework_set_name (const char *name)
 Select the current test name.
 
void test_framework_begin_uart (const char *backend, const char *name, const char *func, int line)
 Begin a UART test as a special case.
 
void test_framework_pass (void)
 Record and report a passing test.
 
void test_framework_fail (const char *format,...)
 Record and report a failing test.
 
void test_framework_skip (const char *category, const char *message)
 Record and report a skipped test.
 
void test_framework_info (const char *message)
 Report test information without changing the counts.
 
void test_framework_value (const char *name, uint64_t value)
 Report a named test value without changing the counts.
 
void test_framework_section (const char *name)
 Print a human-readable section marker.
 
void test_framework_wait_us (uint32_t duration_us)
 Invoke the configured microsecond delay callback.
 
void test_framework_get_count (struct test_framework_count *count)
 Read the current test counts.
 
int test_framework_run_cases (const char *module, const struct test_case *cases, size_t count)
 Run a table of test cases, respecting skip flags.
 

Detailed Description

Platform-agnostic test framework source for capi_selftest project. Copyright (c) 2025-2026 Analog Devices, Inc.

SPDX-License-Identifier: BSD-3-Clause

Macro Definition Documentation

◆ TEST_FRAMEWORK_BUFFER_SIZE

#define TEST_FRAMEWORK_BUFFER_SIZE   256U

Function Documentation

◆ test_framework_begin()

void test_framework_begin ( const char * module,
const char * name )

Select the current test module and test name.

Parameters
module- Test module name.
name- Test name.

◆ test_framework_begin_uart()

void test_framework_begin_uart ( const char * backend,
const char * name,
const char * func,
int line )

Begin a UART test as a special case.

UART tests can hang (for example when reconfiguring the console UART). This announces the test and records a checkpoint BEFORE the body runs, so a hang is attributable to this exact test. Prefer the TEST_BEGIN_UART() macro.

Parameters
backend- UART backend name.
name- Test name.
func- Enclosing function name (func).
line- Source line number (LINE).

◆ test_framework_checkpoint()

void test_framework_checkpoint ( const char * func,
int line )

Record the last reached source location (function and line).

Used so a whole-run hang can report where execution stopped. Prefer the TEST_CHECKPOINT() macro over calling this directly. Uses func and LINE rather than FILE: on a microcontroller FILE bakes the full build-host path into flash, while func is a small literal and LINE costs nothing.

Parameters
func- Enclosing function name (func).
line- Source line number (LINE).

◆ test_framework_fail()

void test_framework_fail ( const char * format,
... )

Record and report a failing test.

Parameters
format- Failure detail format.

◆ test_framework_get_count()

void test_framework_get_count ( struct test_framework_count * count)

Read the current test counts.

Parameters
count- Destination counts.

◆ test_framework_info()

void test_framework_info ( const char * message)

Report test information without changing the counts.

Parameters
message- Information message.

◆ test_framework_init()

int test_framework_init ( const struct test_framework_config * config)

Initialize the test framework.

Parameters
config- Framework configuration.
Returns
0 in case of success, negative error code otherwise.

◆ test_framework_on_timeout()

void test_framework_on_timeout ( void )

Report from the platform watchdog handler that the run hung.

Prints the last test context, the last reached source location and the partial counts. Safe to call once from the timeout handler; it does not itself halt the processor.

◆ test_framework_pass()

void test_framework_pass ( void )

Record and report a passing test.

◆ test_framework_remove()

void test_framework_remove ( void )

Remove the test framework configuration.

◆ test_framework_reset()

void test_framework_reset ( void )

Reset the current test context and counts.

◆ test_framework_run_cases()

int test_framework_run_cases ( const char * module,
const struct test_case * cases,
size_t count )

Run a table of test cases, respecting skip flags.

Iterates through the table, calling TEST_BEGIN for each entry:

  • skip == true -> reported via test_framework_skip(SKIP_FEATURE_DISABLED).
  • run == NULL -> reported as a SKIP_NOT_IMPLEMENTED skip.
  • otherwise -> run() is executed.

Every case is visited even if an earlier one fails, so the run summary stays complete; the first non-zero run() result is returned.

Parameters
module- Test module name (passed to TEST_BEGIN).
cases- Array of test cases.
count- Number of entries in the cases array.
Returns
0 if all pass/skip, first non-zero run() result otherwise.

◆ test_framework_run_end()

void test_framework_run_end ( void )

Disarm the watchdog, print the final counts and end the run.

◆ test_framework_run_start()

void test_framework_run_start ( void )

Start a test run, reset its counts and arm the watchdog.

◆ test_framework_section()

void test_framework_section ( const char * name)

Print a human-readable section marker.

Parameters
name- Section name.

◆ test_framework_set_name()

void test_framework_set_name ( const char * name)

Select the current test name.

Parameters
name- Test name.

◆ test_framework_skip()

void test_framework_skip ( const char * category,
const char * message )

Record and report a skipped test.

Parameters
category- Optional skip category.
message- Skip reason.

◆ test_framework_value()

void test_framework_value ( const char * name,
uint64_t value )

Report a named test value without changing the counts.

Parameters
name- Value name.
value- Value to report.

◆ test_framework_wait_us()

void test_framework_wait_us ( uint32_t duration_us)

Invoke the configured microsecond delay callback.

Parameters
duration_us- Delay duration in microseconds.