VSF Documented
Macros | Functions
vsf_test.c File Reference
#include "./vsf_test.h"
#include <string.h>
#include "./port/vsf_test_port_file.h"
#include "./port/vsf_test_port_appcfg.h"
#include "service/trace/vsf_trace.h"

Macros

#define __VSF_TEST_TRACE_INFO(...)   vsf_trace_info(__VA_ARGS__)
 
#define __VSF_TEST_TRACE_DEBUG(...)   vsf_trace_debug(__VA_ARGS__)
 
#define __VSF_TEST_TRACE_ERROR(...)   vsf_trace_error(__VA_ARGS__)
 

Functions

void vsf_test_init (const vsf_test_cfg_t *cfg)
 initialize vsf test
 
bool vsf_test_add_ex (vsf_test_case_t *test_case)
 API Selection Guide.
 
bool vsf_test_add_simple_case (vsf_test_jmp_fn_t *jmp_fn, char *cfg_str)
 Add a test case of VSF_TEST_TYPE_LONGJMP_FN type (simplified, expect_wdt=0)
 
bool vsf_test_add_bool_fn (vsf_test_bool_fn_t *b_fn, char *cfg_str)
 Add to add a test case of VSF_TEST_TYPE_BOOL_FN type.
 
bool vsf_test_add_case (vsf_test_jmp_fn_t *fn, char *cfg, uint8_t expect_wdt)
 Add a test case of VSF_TEST_TYPE_LONGJMP_FN type.
 
bool vsf_test_add_bool_fn_case (vsf_test_bool_fn_t *fn, char *cfg, uint8_t expect_wdt)
 Add a test case of VSF_TEST_TYPE_BOOL_FN type.
 
bool vsf_test_add_ex_case (vsf_test_jmp_fn_t *fn, char *cfg, vsf_test_type_t type, uint8_t expect_wdt, uint8_t expect_assert)
 Add a test case of any type.
 
bool vsf_test_add_expect_assert_case (vsf_test_jmp_fn_t *fn, char *cfg, uint8_t expect_wdt)
 Add a test case that expects an assertion.
 
void __vsf_test_longjmp (vsf_test_result_t result, const char *file_name, uint32_t line, const char *function_name, const char *condition)
 rong jump. the user does not need to directly call this API
 
void vsf_test_reboot (vsf_test_result_t result, const char *file_name, uint32_t line, const char *function_name, const char *condition)
 reboot, usually called inside an exception.
 
void vsf_test_run_tests (void)
 Run all tests. Should be called after all use cases have been initialized.
 

Macro Definition Documentation

◆ __VSF_TEST_TRACE_INFO

#define __VSF_TEST_TRACE_INFO (   ...)    vsf_trace_info(__VA_ARGS__)

◆ __VSF_TEST_TRACE_DEBUG

#define __VSF_TEST_TRACE_DEBUG (   ...)    vsf_trace_debug(__VA_ARGS__)

◆ __VSF_TEST_TRACE_ERROR

#define __VSF_TEST_TRACE_ERROR (   ...)    vsf_trace_error(__VA_ARGS__)

Function Documentation

◆ vsf_test_init()

void vsf_test_init ( const vsf_test_cfg_t cfg)

initialize vsf test

Parameters
[in]cfga pointer to configuration structure vsf_test_cfg_t

◆ vsf_test_add_ex()

bool vsf_test_add_ex ( vsf_test_case_t test_case)

API Selection Guide.

Choose the appropriate API based on your test case requirements:

  1. vsf_test_add_simple_case() - Use for simple LONGJMP_FN test cases
    • No watchdog reset expected (expect_wdt=0)
    • No assertion expected (expect_assert=0)
    • Example: vsf_test_add_simple_case(__test_func, "cfg_string");
  2. vsf_test_add_case() - Use for LONGJMP_FN test cases with watchdog option
    • Can specify expect_wdt
    • No assertion expected (expect_assert=0)
    • Example: vsf_test_add_case(__test_func, "cfg_string", 1);
  3. vsf_test_add_bool_fn() - Use for simple BOOL_FN test cases
    • No watchdog reset expected (expect_wdt=0)
    • Returns bool instead of using VSF_TEST_ASSERT
    • Example: vsf_test_add_bool_fn(__test_func, "cfg_string");
  4. vsf_test_add_bool_fn_case() - Use for BOOL_FN test cases with watchdog option
    • Can specify expect_wdt
    • Returns bool instead of using VSF_TEST_ASSERT
    • Example: vsf_test_add_bool_fn_case(__test_func, "cfg_string", 1);
  5. vsf_test_add_expect_assert_case() - Use when test expects an assertion
    • expect_assert=1 (test passes if assertion occurs)
    • Can specify expect_wdt
    • Example: vsf_test_add_expect_assert_case(__test_func, "cfg_string", 0);
  6. vsf_test_add_ex_case() - Use for full control over all parameters
    • Can specify type, expect_wdt, and expect_assert
    • Most flexible but more verbose
    • Example: vsf_test_add_ex_case(__test_func, "cfg_string", VSF_TEST_TYPE_LONGJMP_FN, 0, 1);
  7. vsf_test_add_ex() - Use when you already have a vsf_test_case_t structure
    • For advanced use cases or when building test cases dynamically
    • Example: vsf_test_add_ex(&my_test_case);

Add to add a test case of any type

Parameters
[in]test_casea pointer to array vsf_test_case_t
Returns
bool: true if add was successfully, or false

◆ vsf_test_add_simple_case()

bool vsf_test_add_simple_case ( vsf_test_jmp_fn_t jmp_fn,
char *  cfg 
)

Add a test case of VSF_TEST_TYPE_LONGJMP_FN type (simplified, expect_wdt=0)

Parameters
[in]jmp_fna pointer to function vsf_test_jmp_fn_t
[in]cfga string of request information for the test case
Returns
bool: true if add was successfully, or false

◆ vsf_test_add_bool_fn()

bool vsf_test_add_bool_fn ( vsf_test_bool_fn_t b_fn,
char *  cfg 
)

Add to add a test case of VSF_TEST_TYPE_BOOL_FN type.

Parameters
[in]b_fna pointer to function vsf_test_bool_fn_t
[in]cfga string of request information for the test case
Returns
bool: true if add was successfully, or false

◆ vsf_test_add_case()

bool vsf_test_add_case ( vsf_test_jmp_fn_t fn,
char *  cfg,
uint8_t  expect_wdt 
)

Add a test case of VSF_TEST_TYPE_LONGJMP_FN type.

Parameters
[in]fnpointer to test function
[in]cfgrequest string for test case
[in]expect_wdtwhether to expect a watchdog reset (default: 0)
Returns
bool: true if add was successfully, or false

◆ vsf_test_add_bool_fn_case()

bool vsf_test_add_bool_fn_case ( vsf_test_bool_fn_t fn,
char *  cfg,
uint8_t  expect_wdt 
)

Add a test case of VSF_TEST_TYPE_BOOL_FN type.

Parameters
[in]fnpointer to test function
[in]cfgrequest string for test case
[in]expect_wdtwhether to expect a watchdog reset (default: 0)
Returns
bool: true if add was successfully, or false

◆ vsf_test_add_ex_case()

bool vsf_test_add_ex_case ( vsf_test_jmp_fn_t fn,
char *  cfg,
vsf_test_type_t  type,
uint8_t  expect_wdt,
uint8_t  expect_assert 
)

Add a test case of any type.

Parameters
[in]fnpointer to test function
[in]cfgrequest string for test case
[in]typetest type vsf_test_type_t
[in]expect_wdtwhether to expect a watchdog reset (default: 0)
[in]expect_assertwhether to expect an assertion (default: 0)
Returns
bool: true if add was successfully, or false

◆ vsf_test_add_expect_assert_case()

bool vsf_test_add_expect_assert_case ( vsf_test_jmp_fn_t fn,
char *  cfg,
uint8_t  expect_wdt 
)

Add a test case that expects an assertion.

Parameters
[in]fnpointer to test function
[in]cfgrequest string for test case
[in]expect_wdtwhether to expect a watchdog reset (default: 0)
Returns
bool: true if add was successfully, or false

◆ __vsf_test_longjmp()

void __vsf_test_longjmp ( vsf_test_result_t  result,
const char *  file_name,
uint32_t  line,
const char *  function_name,
const char *  condition 
)

rong jump. the user does not need to directly call this API

Parameters
[in]resulttest result, vsf_test_result_t
[in]file_namethen name of the file where the assertion occurred
[in]linethe line number of the code where the assertion occurred
[in]function_namethe name of the function where the assertion occurred
[in]conditionString of asserted code
Note
This function will be called when the test case asserts that the condition is not satisfied.

◆ vsf_test_reboot()

void vsf_test_reboot ( vsf_test_result_t  result,
const char *  file_name,
uint32_t  line,
const char *  function_name,
const char *  additional_str 
)

reboot, usually called inside an exception.

Parameters
[in]resulttest result, vsf_test_result_t
[in]file_namethen name of the file where the assertion occurred
[in]linethe line number of the code where the assertion occurred
[in]function_namethe name of the function where the assertion occurred
[in]additional_strprovide additional exception information

◆ vsf_test_run_tests()

void vsf_test_run_tests ( void  )

Run all tests. Should be called after all use cases have been initialized.

Generated from commit: vsfteam/vsf@b2e9e8a