test_utils.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2020-2021 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include <common_functions.h>
  17. #include <stdio.h>
  18. /* mult value range */
  19. #define MULT_MAX INT32_MAX
  20. #define MULT_MIN 0
  21. /* shift value range */
  22. #define SHIFT_MIN -31
  23. #define SHIFT_MAX 30
  24. /**
  25. * @brief callback function to run before C function
  26. */
  27. void profile_c_start();
  28. /**
  29. * @brief callback function to run after C function
  30. */
  31. void profile_c_end();
  32. /**
  33. * @brief callback function to run before optimized function
  34. */
  35. void profile_opt_start();
  36. /**
  37. * @brief callback function to run after optimized function
  38. */
  39. void profile_opt_end();
  40. #define ANSI_COLOR_RED "\x1b[31m"
  41. #define ANSI_COLOR_GREEN "\x1b[32m"
  42. #define ANSI_COLOR_YELLOW "\x1b[33m"
  43. #define ANSI_COLOR_BLUE "\x1b[34m"
  44. #define ANSI_COLOR_MAGENTA "\x1b[35m"
  45. #define ANSI_COLOR_CYAN "\x1b[36m"
  46. #define ANSI_COLOR_RESET "\x1b[0m"
  47. #define CHECK_EQUAL(ARRAY1, ARRAY2, size) ({ \
  48. bool res = true; \
  49. for (int _i = 0; _i < size; _i++) { \
  50. if (ARRAY1[_i] != ARRAY2[_i]) { \
  51. res = false; \
  52. break; \
  53. } \
  54. } \
  55. res; \
  56. })
  57. #define PRINT_ARRAY_INT(ARRAY, width, height) ({ \
  58. int *_array = (int *) ARRAY; \
  59. for (int _j = 0; _j < height; _j++) { \
  60. for (int _i = 0; _i < width; _i++) { \
  61. printf("%d\t", _array[width * _j + _i]); \
  62. } \
  63. printf("\n"); \
  64. } \
  65. printf("\n"); \
  66. })
  67. #define PRINT_ARRAY_HEX(ARRAY, width, height) ({ \
  68. uint8_t *_array = (uint8_t *) ARRAY; \
  69. for (int _j = 0; _j < height; _j++) { \
  70. for (int _i = 0; _i < width; _i++) { \
  71. printf("%02x\t", _array[width * _j + _i]); \
  72. } \
  73. printf("\n"); \
  74. } \
  75. printf("\n"); \
  76. })