/* * Copyright (c) Technologies Co., Ltd. 2020-2020. All rights reserved. * Description: vi st print head file * Author: vi * Create: 2020-11-02 */ #ifndef __TEST_VI_PRINT_H__ #define __TEST_VI_PRINT_H__ #include "soc_log.h" #define US_TO_NS 1000 #define MS_TO_NS 1000000 #define MS_TO_US 1000 #define S_TO_NS 1000000000 #define S_TO_US 1000000 #define S_TO_MS 1000 #define VI_EOK 0 typedef td_s32 vi_osal_error_t; #define vi_pr_fmt(fmt) "[%s %d]" fmt, __func__, __LINE__ #define vi_print(fmt, ...) printf(fmt, ##__VA_ARGS__) #define vi_log_print(fmt, ...) printf(vi_pr_fmt(fmt), ##__VA_ARGS__) #define vi_log_dbg(fmt, ...) #define vi_log_info(fmt, ...) printf(vi_pr_fmt(fmt), ##__VA_ARGS__) #define vi_log_notice(fmt, ...) printf(vi_pr_fmt(fmt), ##__VA_ARGS__) #define vi_log_warn(fmt, ...) printf(vi_pr_fmt(fmt), ##__VA_ARGS__) #define vi_log_err(fmt, ...) printf(vi_pr_fmt(fmt), ##__VA_ARGS__) /* used for displaying more detailed information */ #define vi_print_s32(val) vi_log_print("%s = %d\n", #val, val) #define vi_print_u32(val) vi_log_print("%s = %u\n", #val, val) #define vi_print_s64(val) vi_log_print("%s = %lld\n", #val, val) #define vi_print_u64(val) vi_log_print("%s = %llu\n", #val, val) #define vi_print_h32(val) vi_log_print("%s = 0x%08X\n", #val, val) #define vi_print_h64(val) vi_log_print("%s = 0x%016llX\n", #val, val) #define vi_print_str(val) vi_log_print("%s = %s\n", #val, val) #define vi_print_void(val) vi_log_print("%s = %p\n", #val, val) #define vi_print_float(val) vi_log_print("%s = %f\n", #val, val) #define vi_print_info(val) vi_log_print("<%s>\n", val) #define vi_print_bool(val) vi_log_print("%s = %s\n", #val, (val) ? "True" : "False") /* used for displaying more detailed error information */ #define vi_err_print_s32(val) vi_log_err("%s = %d\n", #val, val) #define vi_err_print_u32(val) vi_log_err("%s = %u\n", #val, val) #define vi_err_print_s64(val) vi_log_err("%s = %lld\n", #val, val) #define vi_err_print_u64(val) vi_log_err("%s = %llu\n", #val, val) #define vi_err_print_h32(val) vi_log_err("%s = 0x%08X\n", #val, val) #define vi_err_print_h64(val) vi_log_err("%s = 0x%016llX\n", #val, val) #define vi_err_print_str(val) vi_log_err("%s = %s\n", #val, val) #define vi_err_print_void(val) vi_log_err("%s = %p\n", #val, val) #define vi_err_print_float(val) vi_log_err("%s = %f\n", #val, val) #define vi_err_print_info(val) vi_log_err("<%s>\n", val) #define vi_err_print_bool(val) vi_log_err("%s = %s\n", #val, (val) ? "True" : "False") /* used for displaying more detailed warning information */ #define vi_warn_print_s32(val) vi_log_warn("%s = %d\n", #val, val) #define vi_warn_print_u32(val) vi_log_warn("%s = %u\n", #val, val) #define vi_warn_print_s64(val) vi_log_warn("%s = %lld\n", #val, val) #define vi_warn_print_u64(val) vi_log_warn("%s = %llu\n", #val, val) #define vi_warn_print_h32(val) vi_log_warn("%s = 0x%08X\n", #val, val) #define vi_warn_print_h64(val) vi_log_warn("%s = 0x%016llX\n", #val, val) #define vi_warn_print_str(val) vi_log_warn("%s = %s\n", #val, val) #define vi_warn_print_void(val) vi_log_warn("%s = %p\n", #val, val) #define vi_warn_print_float(val) vi_log_warn("%s = %f\n", #val, val) #define vi_warn_print_info(val) vi_log_warn("<%s>\n", val) #define vi_warn_print_bool(val) vi_log_warn("%s = %s\n", #val, (val) ? "True" : "False") /* used for displaying normal but significant information */ #define vi_notice_print_s32(val) vi_log_notice("%s = %d\n", #val, val) #define vi_notice_print_u32(val) vi_log_notice("%s = %u\n", #val, val) #define vi_notice_print_s64(val) vi_log_notice("%s = %lld\n", #val, val) #define vi_notice_print_u64(val) vi_log_notice("%s = %llu\n", #val, val) #define vi_notice_print_h32(val) vi_log_notice("%s = 0x%08X\n", #val, val) #define vi_notice_print_h64(val) vi_log_notice("%s = 0x%016llX\n", #val, val) #define vi_notice_print_str(val) vi_log_notice("%s = %s\n", #val, val) #define vi_notice_print_void(val) vi_log_notice("%s = %p\n", #val, val) #define vi_notice_print_float(val) vi_log_notice("%s = %f\n", #val, val) #define vi_notice_print_info(val) vi_log_notice("<%s>\n", val) #define vi_notice_print_bool(val) vi_log_notice("%s = %s\n", #val, (val) ? "True" : "False") /* only used for key info, can be expanded as needed */ #define vi_info_print_s32(val) vi_log_info("%s = %d\n", #val, val) #define vi_info_print_u32(val) vi_log_info("%s = %u\n", #val, val) #define vi_info_print_s64(val) vi_log_info("%s = %lld\n", #val, val) #define vi_info_print_u64(val) vi_log_info("%s = %llu\n", #val, val) #define vi_info_print_h32(val) vi_log_info("%s = 0x%08X\n", #val, val) #define vi_info_print_h64(val) vi_log_info("%s = 0x%016llX\n", #val, val) #define vi_info_print_str(val) vi_log_info("%s = %s\n", #val, val) #define vi_info_print_void(val) vi_log_info("%s = %p\n", #val, val) #define vi_info_print_float(val) vi_log_info("%s = %f\n", #val, val) #define vi_info_print_info(val) vi_log_info("<%s>\n", val) #define vi_info_print_bool(val) vi_log_info("%s = %s\n", #val, (val) ? "True" : "False") /* only used for self debug, can be expanded as needed */ #define vi_dbg_print_s32(val) vi_log_dbg("%s = %d\n", #val, val) #define vi_dbg_print_u32(val) vi_log_dbg("%s = %u\n", #val, val) #define vi_dbg_print_s64(val) vi_log_dbg("%s = %lld\n", #val, val) #define vi_dbg_print_u64(val) vi_log_dbg("%s = %llu\n", #val, val) #define vi_dbg_print_h32(val) vi_log_dbg("%s = 0x%08X\n", #val, val) #define vi_dbg_print_h64(val) vi_log_dbg("%s = 0x%016llX\n", #val, val) #define vi_dbg_print_str(val) vi_log_dbg("%s = %s\n", #val, val) #define vi_dbg_print_void(val) vi_log_dbg("%s = %p\n", #val, val) #define vi_dbg_print_float(val) vi_log_dbg("%s = %f\n", #val, val) #define vi_dbg_print_info(val) vi_log_dbg("<%s>\n", val) #define vi_dbg_print_bool(val) vi_log_dbg("%s = %s\n", #val, (val) ? "True" : "False") #define vi_err_print_null_pointer(val) vi_log_err("%s = %pK, null pointer!\n", #val, val) #define vi_err_print_call_fun_err(func, err_code) vi_log_err("call %s fail, error code: %d!\n", #func, err_code) #define vi_err_print_call_ptr_fun_err(func) vi_log_err("call %s fail, error code: null pointer!\n", #func) #define vi_assert(facto, expr) do { \ td_s32 tmp_facto = (facto); \ if ((tmp_facto) != (expr)) { \ vi_log_err("\nvi assert failed! {facto: %s <=> %d, expr: %d}\n", #facto, (tmp_facto), (expr)); \ return TD_FAILURE; \ } \ } while (0) #define vi_assert_ret_void(facto, expr) do { \ td_s32 tmp_facto = (facto); \ if ((tmp_facto) != (expr)) { \ vi_log_err("\nvi assert failed! {facto: %s <=> %d, expr: %d}\n", #facto, (tmp_facto), (expr)); \ return; \ } \ } while (0) #define vi_assert_ret_ptr(facto, expr) do { \ td_s32 tmp_facto = (facto); \ if ((tmp_facto) != (expr)) { \ vi_log_err("\nvi assert failed! {facto: %s <=> %d, expr: %d}\n", #facto, (tmp_facto), (expr)); \ return TD_NULL; \ } \ } while (0) #define vi_assert_no_ret(facto, expr) do { \ td_s32 tmp_facto = (facto); \ if ((tmp_facto) != (expr)) { \ vi_log_err("\nvi assert failed! {facto: %s <=> %d, expr: %d}\n", #facto, (tmp_facto), (expr)); \ } \ } while (0) #define vi_check_null_ptr(ptr) do { \ if ((ptr) == TD_NULL) { \ vi_err_print_null_pointer(ptr); \ return TD_FAILURE; \ } \ } while (0) #define vi_check_null_ptr_ret_void(ptr) do { \ if ((ptr) == TD_NULL) { \ vi_err_print_null_pointer(ptr); \ return; \ } \ } while (0) #define vi_check_null_ptr_ret_ptr(ptr) do { \ if ((ptr) == TD_NULL) { \ vi_err_print_null_pointer(ptr); \ return TD_NULL; \ } \ } while (0) #define vi_check_null_ptr_no_ret(ptr) do { \ if ((ptr) == TD_NULL) { \ vi_err_print_null_pointer(ptr); \ } \ } while (0) #define vi_check_bool(bool_val) do { \ if (((bool_val) != TD_FALSE) && ((bool_val) != TD_TRUE)) { \ vi_err_print_u32(bool_val); \ return TD_FAILURE; \ } \ } while (0) #define vi_check_bool_ret_void(bool_val) do { \ if (((bool_val) != TD_FALSE) && ((bool_val) != TD_TRUE)) { \ vi_err_print_u32(bool_val); \ return; \ } \ } while (0) #define vi_check_bool_ret_ptr(bool_val) do { \ if (((bool_val) != TD_FALSE) && ((bool_val) != TD_TRUE)) { \ vi_err_print_u32(bool_val); \ return TD_NULL; \ } \ } while (0) #define vi_check_bool_no_ret(bool_val) do { \ if (((bool_val) != TD_FALSE) && ((bool_val) != TD_TRUE)) { \ vi_err_print_u32(bool_val); \ } \ } while (0) #define vi_check_func(ret) do { \ td_s32 tmp_ret = (ret); \ if (tmp_ret != TD_SUCCESS) { \ vi_err_print_call_fun_err(ret, tmp_ret); \ return tmp_ret; \ } \ } while (0) #define vi_check_func_ret_void(ret) do { \ td_s32 tmp_ret = (ret); \ if (tmp_ret != TD_SUCCESS) { \ vi_err_print_call_fun_err(ret, tmp_ret); \ return; \ } \ } while (0) #define vi_check_func_ret_ptr(ret) do { \ td_s32 tmp_ret = (ret); \ if (tmp_ret != TD_SUCCESS) { \ vi_err_print_call_fun_err(ret, tmp_ret); \ return TD_NULL; \ } \ } while (0) #define vi_check_func_no_ret(ret) do { \ td_s32 tmp_ret = (ret); \ if (tmp_ret != TD_SUCCESS) { \ vi_err_print_call_fun_err(ret, tmp_ret); \ } \ } while (0) #define vi_check_func_print(ret, fmt) do { \ td_s32 tmp_ret = (ret); \ if ((tmp_ret) != TD_SUCCESS) { \ vi_err_print_call_fun_err(fmt, tmp_ret); \ return tmp_ret; \ } \ } while (0) #define vi_check_func_ret_void_print(ret, fmt) do { \ td_s32 tmp_ret = (ret); \ if (tmp_ret != TD_SUCCESS) { \ vi_err_print_call_fun_err(fmt, tmp_ret); \ return; \ } \ } while (0) #define vi_check_func_ret_ptr_print(ret, fmt) do { \ td_s32 tmp_ret = (ret); \ if (tmp_ret != TD_SUCCESS) { \ vi_err_print_call_fun_err(fmt, tmp_ret); \ return TD_NULL; \ } \ } while (0) #define vi_check_func_no_ret_print(ret, fmt) do { \ td_s32 tmp_ret = ret; \ if (tmp_ret != TD_SUCCESS) { \ vi_err_print_call_fun_err(fmt, tmp_ret); \ } \ } while (0) #define vi_check_ptr_func(ret) do { \ td_void *tmp_ret = ret; \ if ((tmp_ret) == TD_NULL) { \ vi_err_print_call_ptr_fun_err(ret); \ return TD_FAILURE; \ } \ } while (0) #define vi_check_ptr_func_ret_void(ret) do { \ td_void *tmp_ret = ret; \ if ((tmp_ret) == TD_NULL) { \ vi_err_print_call_ptr_fun_err(ret); \ return; \ } \ } while (0) #define vi_check_ptr_func_ret_ptr(ret) do { \ td_void *tmp_ret = ret; \ if ((tmp_ret) == TD_NULL) { \ vi_err_print_call_ptr_fun_err(ret); \ return TD_NULL; \ } \ } while (0) #define vi_check_ptr_func_no_ret(ret) do { \ td_void *tmp_ret = ret; \ if ((tmp_ret) == TD_NULL) { \ vi_err_print_call_ptr_fun_err(ret); \ } \ } while (0) #define vi_check_ptr_func_print(ret, fmt) do { \ td_void *tmp_ret = ret; \ if ((tmp_ret) == TD_NULL) { \ vi_err_print_call_ptr_fun_err(fmt); \ return TD_FAILURE; \ } \ } while (0) #define vi_check_ptr_func_ret_void_print(ret, fmt) do { \ td_void *tmp_ret = ret; \ if ((tmp_ret) == TD_NULL) { \ vi_err_print_call_ptr_fun_err(fmt); \ return; \ } \ } while (0) #define vi_check_ptr_func_ret_ptr_print(ret, fmt) do { \ td_void *tmp_ret = ret; \ if ((tmp_ret) == TD_NULL) { \ vi_err_print_call_ptr_fun_err(fmt); \ return TD_NULL; \ } \ } while (0) #define vi_check_ptr_func_no_ret_print(ret, fmt) do { \ td_void *tmp_ret = ret; \ if ((tmp_ret) == TD_NULL) { \ vi_err_print_call_ptr_fun_err(fmt); \ } \ } while (0) #define vi_check_sec_func(ret) do { \ vi_osal_error_t tmp_ret = ret; \ if (tmp_ret != VI_EOK) { \ vi_err_print_call_fun_err(ret, tmp_ret); \ return TD_FAILURE; \ } \ } while (0) #define vi_check_sec_func_ret_void(ret) do { \ vi_osal_error_t tmp_ret = ret; \ if (tmp_ret != VI_EOK) { \ vi_err_print_call_fun_err(ret, tmp_ret); \ return; \ } \ } while (0) #define vi_check_sec_func_ret_ptr(ret) do { \ vi_osal_error_t tmp_ret = ret; \ if (tmp_ret != VI_EOK) { \ vi_err_print_call_fun_err(ret, tmp_ret); \ return TD_NULL; \ } \ } while (0) #define vi_check_sec_func_no_ret(ret) do { \ vi_osal_error_t tmp_ret = ret; \ if (tmp_ret != VI_EOK) { \ vi_err_print_call_fun_err(ret, tmp_ret); \ } \ } while (0) #define vi_check_sec_func_print(ret, fmt) do { \ vi_osal_error_t tmp_ret = ret; \ if (tmp_ret != VI_EOK) { \ vi_err_print_call_fun_err(fmt, tmp_ret); \ return TD_FAILURE; \ } \ } while (0) #define vi_check_sec_func_ret_void_print(ret, fmt) do { \ vi_osal_error_t tmp_ret = ret; \ if (tmp_ret != VI_EOK) { \ vi_err_print_call_fun_err(fmt, tmp_ret); \ return; \ } \ } while (0) #define vi_check_sec_func_ret_ptr_print(ret, fmt) do { \ vi_osal_error_t tmp_ret = ret; \ if (tmp_ret != VI_EOK) { \ vi_err_print_call_fun_err(fmt, tmp_ret); \ return TD_NULL; \ } \ } while (0) #define vi_check_sec_func_no_ret_print(ret, fmt) do { \ vi_osal_error_t tmp_ret = ret; \ if (tmp_ret != VI_EOK) { \ vi_err_print_call_fun_err(fmt, tmp_ret); \ } \ } while (0) #endif