VSF Documented
Data Structures | Macros | Typedefs | Enumerations | Functions
vsf_test.h File Reference
#include "component/vsf_component_cfg.h"
#include "utilities/vsf_utilities.h"
#include "./port/vsf_test_port_hal.h"
#include "./port/vsf_test_port_stdio.h"
#include "./port/vsf_test_port_file.h"
#include "./port/vsf_test_port_appcfg.h"

Go to the source code of this file.

Data Structures

struct  vsf_test_wdt_t
 
struct  vsf_test_data_t
 
struct  vsf_test_case_t
 
struct  vsf_test_cfg_t
 Test framework configuration structure. More...
 
struct  vsf_test_t
 

Macros

#define VSF_TEST_CFG_LONGJMP   ENABLED
 < Using longjmp/setjmp for assertions
 
#define VSF_TEST_CFG_INTERNAL_TIMEOUT_MS   1000
 External Watchdog Default Timeout.
 
#define VSF_TEST_CFG_EXTERNAL_TIMEOUT_MS   1500
 Using the hal wdt device.
 
#define VSF_TEST_CFG_USE_HAL_WDT   DISABLED
 Using stdio to save persistent data to assist device.
 
#define VSF_TEST_CFG_USE_STDIO_DATA_SYNC   DISABLED
 Using file interface to save persistent data to assist device.
 
#define VSF_TEST_CFG_USE_FILE_DATA_SYNC   DISABLED
 Using appcfg command to save persistent data to assist device.
 
#define VSF_TEST_CFG_USE_APPCFG_DATA_SYNC   DISABLED
 Enable trace output for test framework.
 
#define VSF_TEST_CFG_USE_TRACE   ENABLED
 Test case array size.
 
#define VSF_TEST_CFG_ARRAY_SIZE   100
 
#define VSF_TEST_ASSERT(__v)
 Add an assertion to the test case.
 

Typedefs

typedef enum vsf_test_status_t vsf_test_status_t
 
typedef enum vsf_test_req_t vsf_test_req_t
 
typedef enum vsf_test_result_t vsf_test_result_t
 
typedef enum vsf_test_type_t vsf_test_type_t
 Test the type of the function,.
 
typedef void vsf_test_reboot_t(void)
 
typedef struct vsf_test_wdt_t vsf_test_wdt_t
 
typedef enum vsf_test_data_cmd_t vsf_test_data_cmd_t
 Device commands during data synchronization.
 
typedef struct vsf_test_data_t vsf_test_data_t
 
typedef bool vsf_test_bool_fn_t(void)
 
typedef void vsf_test_jmp_fn_t(void)
 
typedef struct vsf_test_case_t vsf_test_case_t
 
typedef struct vsf_test_cfg_t vsf_test_cfg_t
 Test framework configuration structure.
 
typedef struct vsf_test_t vsf_test_t
 

Enumerations

enum  vsf_test_status_t {
  VSF_TEST_STATUS_IDLE = 0 ,
  VSF_TEST_STATUS_RUNNING = 1
}
 
enum  vsf_test_req_t {
  VSF_TEST_REQ_NO_SUPPORT = 0 ,
  VSF_TEST_REQ_SUPPORT = 1
}
 
enum  vsf_test_result_t {
  VSF_TEST_RESULT_PASS = 0x0u << 0 ,
  VSF_TEST_RESULT_SKIP = 0x1u << 0 ,
  VSF_TEST_RESULT_WDT_PASS = 0x2u << 0 ,
  VSF_TEST_RESULT_FAIL = 0x3u << 0 ,
  VSF_TEST_RESULT_ASSERT_FAIL = VSF_TEST_RESULT_FAIL ,
  VSF_TEST_RESULT_WDT_FAIL = 0x4u << 0 ,
  VSF_TEST_RESULT_ASSIST_FAIL = 0x5u << 0 ,
  VSF_TEST_RESULT_FAULT_HANDLER_FAIL = 0x6u << 0
}
 
enum  vsf_test_type_t {
  VSF_TEST_TYPE_LONGJMP_FN = 0 ,
  VSF_TEST_TYPE_BOOL_FN
}
 Test the type of the function,. More...
 
enum  vsf_test_data_cmd_t {
  VSF_TEST_STATUS_READ ,
  VSF_TEST_STATUS_WRITE ,
  VSF_TEST_TESTCASE_INDEX_READ ,
  VSF_TEST_TESTCASE_INDEX_WRITE ,
  VSF_TEST_TESECASE_REQUEST_WRITE ,
  VSF_TEST_TESTCASE_RESULT_WRITE ,
  VSF_TEST_DONE
}
 Device commands during data synchronization. More...
 

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)
 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)
 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_run_tests (void)
 Run all tests. Should be called after all use cases have been initialized.
 
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 *additional_str)
 reboot, usually called inside an exception.
 

Macro Definition Documentation

◆ VSF_TEST_CFG_LONGJMP

#define VSF_TEST_CFG_LONGJMP   ENABLED

< Using longjmp/setjmp for assertions

Note
do not move this pre-processor statement to other places Internal watchdog default timeout

◆ VSF_TEST_CFG_INTERNAL_TIMEOUT_MS

#define VSF_TEST_CFG_INTERNAL_TIMEOUT_MS   1000

External Watchdog Default Timeout.

◆ VSF_TEST_CFG_EXTERNAL_TIMEOUT_MS

#define VSF_TEST_CFG_EXTERNAL_TIMEOUT_MS   1500

Using the hal wdt device.

◆ VSF_TEST_CFG_USE_HAL_WDT

#define VSF_TEST_CFG_USE_HAL_WDT   DISABLED

Using stdio to save persistent data to assist device.

◆ VSF_TEST_CFG_USE_STDIO_DATA_SYNC

#define VSF_TEST_CFG_USE_STDIO_DATA_SYNC   DISABLED

Using file interface to save persistent data to assist device.

◆ VSF_TEST_CFG_USE_FILE_DATA_SYNC

#define VSF_TEST_CFG_USE_FILE_DATA_SYNC   DISABLED

Using appcfg command to save persistent data to assist device.

◆ VSF_TEST_CFG_USE_APPCFG_DATA_SYNC

#define VSF_TEST_CFG_USE_APPCFG_DATA_SYNC   DISABLED

Enable trace output for test framework.

◆ VSF_TEST_CFG_USE_TRACE

#define VSF_TEST_CFG_USE_TRACE   ENABLED

Test case array size.

◆ VSF_TEST_CFG_ARRAY_SIZE

#define VSF_TEST_CFG_ARRAY_SIZE   100

◆ VSF_TEST_ASSERT

#define VSF_TEST_ASSERT (   __v)
Value:
do { \
if (!(__v)) { \
__vsf_test_longjmp(VSF_TEST_RESULT_FAIL, __FILE__, \
__LINE__, __FUNCTION__, #__v); \
} \
} while (0)
@ VSF_TEST_RESULT_FAIL
Definition vsf_test.h:243

Add an assertion to the test case.

Parameters
__vexpressions for test conditions

Typedef Documentation

◆ vsf_test_status_t

◆ vsf_test_req_t

◆ vsf_test_result_t

◆ vsf_test_type_t

Test the type of the function,.

◆ vsf_test_reboot_t

typedef void vsf_test_reboot_t(void)

◆ vsf_test_wdt_t

◆ vsf_test_data_cmd_t

Device commands during data synchronization.

◆ vsf_test_data_t

All data here needs to be synchronized with the assist device after modification. After powering up, we need to read the data from the assist device first.

◆ vsf_test_bool_fn_t

typedef bool vsf_test_bool_fn_t(void)

◆ vsf_test_jmp_fn_t

typedef void vsf_test_jmp_fn_t(void)

◆ vsf_test_case_t

◆ vsf_test_cfg_t

Test framework configuration structure.

◆ vsf_test_t

typedef struct vsf_test_t vsf_test_t

Enumeration Type Documentation

◆ vsf_test_status_t

Enumerator
VSF_TEST_STATUS_IDLE 
VSF_TEST_STATUS_RUNNING 

◆ vsf_test_req_t

Enumerator
VSF_TEST_REQ_NO_SUPPORT 
VSF_TEST_REQ_SUPPORT 

◆ vsf_test_result_t

Enumerator
VSF_TEST_RESULT_PASS 
VSF_TEST_RESULT_SKIP 
VSF_TEST_RESULT_WDT_PASS 
VSF_TEST_RESULT_FAIL 
VSF_TEST_RESULT_ASSERT_FAIL 
VSF_TEST_RESULT_WDT_FAIL 
VSF_TEST_RESULT_ASSIST_FAIL 
VSF_TEST_RESULT_FAULT_HANDLER_FAIL 

◆ vsf_test_type_t

Test the type of the function,.

Enumerator
VSF_TEST_TYPE_LONGJMP_FN 

Functions with no return value can use VSF_TEST_ASSERT, which depends on setjmp/longjmp.

VSF_TEST_TYPE_BOOL_FN 

Functions with boolean return values do not depend on longjmp but cannot use VSF_TEST_ASSERT

◆ vsf_test_data_cmd_t

Device commands during data synchronization.

Enumerator
VSF_TEST_STATUS_READ 

Reading the current state requires a response from the assist device.

VSF_TEST_STATUS_WRITE 

Write current state, no assist device response required.

VSF_TEST_TESTCASE_INDEX_READ 

Reading the current index requires a response from the assist device.

VSF_TEST_TESTCASE_INDEX_WRITE 

Write current index, no assist device response required.

VSF_TEST_TESECASE_REQUEST_WRITE 

Send test request information, requires an assist device response.

VSF_TEST_TESTCASE_RESULT_WRITE 

Write the result of the current test, does not require a response from the assist device.

VSF_TEST_DONE 

All tests are completed without a response from the assist device. The Assist Device should output a test report and be ready for the next test.

Function Documentation

◆ vsf_test_init()

void vsf_test_init ( const vsf_test_cfg_t cfg)
extern

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)
extern

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 
)
extern

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 
)
extern

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 
)
extern

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 
)
extern

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 
)
extern

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 
)
extern

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_run_tests()

void vsf_test_run_tests ( void  )
extern

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

◆ __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 
)
extern

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 
)
extern

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
Generated from commit: vsfteam/vsf@b2e9e8a