common.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2023-03-20 WangXiaoyao Complete testcase for mm_aspace.c
  9. */
  10. #ifndef __TEST_MM_COMMON_H__
  11. #define __TEST_MM_COMMON_H__
  12. #include <stddef.h>
  13. #include <stdint.h>
  14. #include <string.h>
  15. #include <utest.h>
  16. #include <board.h>
  17. #include <rtthread.h>
  18. #include <rthw.h>
  19. #include <mmu.h>
  20. #include <tlb.h>
  21. #ifdef RT_USING_SMART
  22. #include <lwp_arch.h>
  23. #endif
  24. #include <ioremap.h>
  25. #include <mm_aspace.h>
  26. #include <mm_flag.h>
  27. #include <mm_page.h>
  28. #include <mm_private.h>
  29. extern rt_base_t rt_heap_lock(void);
  30. extern void rt_heap_unlock(rt_base_t level);
  31. /**
  32. * @brief During the operations, is heap still the same;
  33. */
  34. #define CONSIST_HEAP(statement) do { \
  35. rt_size_t total, used, max_used; \
  36. rt_size_t totala, useda, max_useda; \
  37. rt_ubase_t level = rt_heap_lock(); \
  38. rt_memory_info(&total, &used, &max_used); \
  39. statement; \
  40. rt_memory_info(&totala, &useda, &max_useda); \
  41. rt_heap_unlock(level); \
  42. uassert_true(total == totala); \
  43. uassert_true(used == useda); \
  44. uassert_true(max_used == max_useda); \
  45. } while (0)
  46. rt_inline int memtest(volatile char *buf, int value, size_t buf_sz)
  47. {
  48. int ret = 0;
  49. for (size_t i = 0; i < buf_sz; i++)
  50. {
  51. if (buf[i] != value)
  52. {
  53. ret = -1;
  54. break;
  55. }
  56. }
  57. return ret;
  58. }
  59. #endif /* __TEST_MM_COMMON_H__ */