bh_assert.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "bh_platform.h"
  17. #include "bh_assert.h"
  18. #include <stdarg.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #ifdef BH_TEST
  22. #include <setjmp.h>
  23. #endif
  24. #ifdef BH_TEST
  25. /* for exception throwing */
  26. jmp_buf bh_test_jb;
  27. #endif
  28. void bh_assert_internal(int v, const char *file_name, int line_number, const char *expr_string)
  29. {
  30. if(v) return;
  31. if(!file_name) file_name = "NULL FILENAME";
  32. if(!expr_string) expr_string = "NULL EXPR_STRING";
  33. printf("\nASSERTION FAILED: %s, at FILE=%s, LINE=%d\n", expr_string, file_name, line_number);
  34. #ifdef BH_TEST
  35. longjmp(bh_test_jb, 1);
  36. #endif
  37. aos_reboot();
  38. }
  39. void bh_debug_internal(const char *file_name, int line_number, const char *fmt, ...)
  40. {
  41. #ifndef JEFF_TEST_VERIFIER
  42. va_list args;
  43. va_start(args, fmt);
  44. bh_assert(file_name);
  45. printf("\nDebug info FILE=%s, LINE=%d: ", file_name, line_number);
  46. vprintf(fmt, args);
  47. va_end(args);
  48. printf("\n");
  49. #endif
  50. }