hv_vos_Assert.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * @file hv_vos_Assert.h
  3. * @brief Header file of vos Assert.
  4. *
  5. * @verbatim
  6. * ==============================================================================
  7. * ##### How to use #####
  8. * ==============================================================================
  9. * (+) Use ()
  10. *
  11. * @endverbatim
  12. * @author HiView SoC Software Team
  13. * @version 1.0.0
  14. * @date 2023-03-01
  15. */
  16. #ifndef _HV_VOS_ASSERT_H
  17. #define _HV_VOS_ASSERT_H
  18. #include "hv_vos_Types.h"
  19. VOS_EXTERN_C_BEGIN
  20. #define HV_MSG_NOT_IMPL "not implemented"
  21. #define HV_MSG_NOT_READY "not ready"
  22. #define HV_MSG_INV_ARG "invalid argument"
  23. #define HV_MSG_OUT_OF_MEMORY "out of memory"
  24. #define HV_MSG_OUT_OF_BOUNDS "out of bounds"
  25. /// assert report routine
  26. void Hv_Vos_Assert_Report(const char *condition, int line,
  27. const char *function, const char *message);
  28. /// HS portable assertion
  29. /// @param cond logical condition
  30. #define HV_ASSERT(cond) HV_ASSERT_IMPL((cond), __LINE__, __FUNCTION__, NULL)
  31. /// simple way to assert HV_RESULT
  32. #define HV_ASSERT_RESULT(result) HV_ASSERT(result >= 0)
  33. /// HS portable assertion implementation
  34. #define HV_ASSERT_IMPL(cond, line, function, msg) \
  35. do { \
  36. if (!(cond)) { \
  37. Hv_Vos_Assert_Report(#cond, line, function, msg); \
  38. } \
  39. } while (0)
  40. /// assert for arguement checking
  41. #define HV_ASSERT_CHK_ARG(cond) \
  42. HV_ASSERT_IMPL((cond), __LINE__, __FUNCTION__, HV_MSG_INV_ARG)
  43. /// assert for not implemented function
  44. #define HV_ASSERT_NOT_IMPL() \
  45. HV_ASSERT_IMPL(0, __LINE__, __FUNCTION__, HV_MSG_NOT_IMPL)
  46. #define HV_ASSERT_OUT_OF_MEMORY() \
  47. HV_ASSERT_IMPL(0, __LINE__, __FUNCTION__, HV_MSG_OUT_OF_MEMORY)
  48. /** @} */
  49. VOS_EXTERN_C_END
  50. #endif