bh_assert.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #include "bh_platform.h"
  6. #include "bh_assert.h"
  7. #include <stdarg.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #ifdef BH_TEST
  11. #include <setjmp.h>
  12. #endif
  13. #ifdef BH_TEST
  14. /* for exception throwing */
  15. jmp_buf bh_test_jb;
  16. #endif
  17. void bh_assert_internal(int v, const char *file_name, int line_number, const char *expr_string)
  18. {
  19. if(v) return;
  20. if(!file_name) file_name = "NULL FILENAME";
  21. if(!expr_string) expr_string = "NULL EXPR_STRING";
  22. printf("\nASSERTION FAILED: %s, at FILE=%s, LINE=%d\n", expr_string, file_name, line_number);
  23. #ifdef BH_TEST
  24. longjmp(bh_test_jb, 1);
  25. #endif
  26. aos_reboot();
  27. }
  28. void bh_debug_internal(const char *file_name, int line_number, const char *fmt, ...)
  29. {
  30. #ifndef JEFF_TEST_VERIFIER
  31. va_list args;
  32. va_start(args, fmt);
  33. bh_assert(file_name);
  34. printf("\nDebug info FILE=%s, LINE=%d: ", file_name, line_number);
  35. vprintf(fmt, args);
  36. va_end(args);
  37. printf("\n");
  38. #endif
  39. }