RyanMqttTestUtile.h 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #ifndef __RyanMqttTestUtile__
  2. #define __RyanMqttTestUtile__
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include <stdio.h>
  7. #include <stdint.h>
  8. #include <string.h>
  9. #include <time.h>
  10. #include <stdlib.h>
  11. #include <stdbool.h>
  12. #include <unistd.h>
  13. #include <semaphore.h>
  14. #include <pthread.h>
  15. #include <sched.h>
  16. #include "valloc.h"
  17. #define malloc v_malloc
  18. #define calloc v_calloc
  19. #define free v_free
  20. #define realloc v_realloc
  21. #include "RyanMqttLog.h"
  22. #include "RyanMqttClient.h"
  23. #include "RyanMqttUtil.h"
  24. #define delay(ms) usleep((ms) * 1000)
  25. #define delay_us(us) usleep((us))
  26. #define getArraySize(arr) ((int32_t)(sizeof(arr) / sizeof((arr)[0])))
  27. extern uint32_t destroyCount;
  28. #define checkMemory \
  29. do \
  30. { \
  31. for (uint32_t aaa = 0;; aaa++) \
  32. { \
  33. RyanMqttTestEnableCritical(); \
  34. uint32_t destoryCount2 = destroyCount; \
  35. RyanMqttTestExitCritical(); \
  36. if (0 == destoryCount2) break; \
  37. if (aaa > 10 * 1000) \
  38. { \
  39. printf("aaaaaaaa %d\r\n", destoryCount2); \
  40. break; \
  41. } \
  42. delay(1); \
  43. } \
  44. int area = 0, use = 0; \
  45. v_mcheck(&area, &use); \
  46. if (area != 0 || use != 0) \
  47. { \
  48. RyanMqttLog_e("内存泄漏"); \
  49. while (1) \
  50. { \
  51. v_mcheck(&area, &use); \
  52. RyanMqttLog_e("|||----------->>> area = %d, size = %d", area, use); \
  53. delay(3000); \
  54. } \
  55. } \
  56. } while (0)
  57. extern uint32_t randomCount;
  58. extern uint32_t sendRandomCount;
  59. extern uint32_t memoryRandomCount;
  60. extern RyanMqttBool_e isEnableRandomNetworkFault;
  61. extern RyanMqttBool_e isEnableRandomMemoryFault;
  62. extern void enableRandomNetworkFault(void);
  63. extern void disableRandomNetworkFault(void);
  64. extern void toggleRandomNetworkFault(void);
  65. extern void enableRandomMemoryFault(void);
  66. extern void disableRandomMemoryFault(void);
  67. extern void toggleRandomMemoryFault(void);
  68. extern uint32_t RyanRand(int32_t min, int32_t max);
  69. // 定义枚举类型
  70. // 定义结构体类型
  71. #define RyanMqttTestEventUserDataMagic (123456789)
  72. /* extern variables-----------------------------------------------------------*/
  73. extern void RyanMqttTestEnableCritical(void);
  74. extern void RyanMqttTestExitCritical(void);
  75. extern void printfArrStr(uint8_t *buf, uint32_t len, char *userData);
  76. extern void RyanMqttTestUtileInit(void);
  77. extern void RyanMqttTestUtileDeInit(void);
  78. #ifdef __cplusplus
  79. }
  80. #endif
  81. #endif