rt_ioremap.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. * 2022-12-14 WangXiaoyao the first version
  9. * 2023-03-20 WangXiaoyao Format & add more testcases for API under mm_aspace.h
  10. * 2026-03-19 cl2t Add standardized utest documentation block
  11. */
  12. /**
  13. * Test Case Name: I/O Remap Test
  14. *
  15. * Test Objectives:
  16. * - Verify the rt_ioremap_cached() API for mapping physical addresses to
  17. * virtual addresses with cached memory access.
  18. * - Test core APIs: rt_pages_alloc(), rt_ioremap_cached(), rt_iounmap(),
  19. * rt_pages_free().
  20. *
  21. * Test Scenarios:
  22. * - Allocates a physical page (4KB), maps it to a virtual address using
  23. * rt_ioremap_cached(), verifies data consistency between the physical
  24. * and virtual addresses, then unmaps and frees the resources.
  25. *
  26. * Verification Metrics:
  27. * - The value read through the virtual address must equal the value at the
  28. * corresponding physical address.
  29. * - No memory leaks after unmap and free operations (validated via
  30. * CONSIST_HEAP wrapper).
  31. *
  32. * Dependencies:
  33. * - Software configuration: RT_USING_SMART must be enabled.
  34. * - Environmental assumptions: MMU support must be available on the target
  35. * platform.
  36. *
  37. * Expected Results:
  38. * - Final output: "[ PASSED ] [ result ] testcase (testcases.mm.ioremap)"
  39. * - No assertion failures during test execution.
  40. */
  41. #include "common.h"
  42. void ioremap_tc(void)
  43. {
  44. const size_t bufsz = 0x1000;
  45. void *paddr = (void *)rt_pages_alloc(rt_page_bits(bufsz)) + PV_OFFSET;
  46. int *vaddr;
  47. vaddr = rt_ioremap_cached(paddr, bufsz);
  48. if (vaddr)
  49. {
  50. TC_ASSERT(*vaddr == *(int *)(paddr - PV_OFFSET));
  51. rt_iounmap(vaddr);
  52. rt_pages_free(paddr - PV_OFFSET, 0);
  53. }
  54. }
  55. static rt_err_t utest_tc_init(void)
  56. {
  57. return RT_EOK;
  58. }
  59. static rt_err_t utest_tc_cleanup(void)
  60. {
  61. return RT_EOK;
  62. }
  63. static void test_main(void)
  64. {
  65. CONSIST_HEAP(ioremap_tc());
  66. }
  67. UTEST_TC_EXPORT(test_main, "testcases.mm.ioremap", utest_tc_init, utest_tc_cleanup, 20);