README 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. ION BUFFER SHARING UTILITY
  2. ==========================
  3. File: ion_test.sh : Utility to test ION driver buffer sharing mechanism.
  4. Author: Pintu Kumar <pintu.ping@gmail.com>
  5. Introduction:
  6. -------------
  7. This is a test utility to verify ION buffer sharing in user space
  8. between 2 independent processes.
  9. It uses unix domain socket (with SCM_RIGHTS) as IPC to transfer an FD to
  10. another process to share the same buffer.
  11. This utility demonstrates how ION buffer sharing can be implemented between
  12. two user space processes, using various heap types.
  13. The following heap types are supported by ION driver.
  14. ION_HEAP_TYPE_SYSTEM (0)
  15. ION_HEAP_TYPE_SYSTEM_CONTIG (1)
  16. ION_HEAP_TYPE_CARVEOUT (2)
  17. ION_HEAP_TYPE_CHUNK (3)
  18. ION_HEAP_TYPE_DMA (4)
  19. By default only the SYSTEM and SYSTEM_CONTIG heaps are supported.
  20. Each heap is associated with the respective heap id.
  21. This utility is designed in the form of client/server program.
  22. The server part (ionapp_export) is the exporter of the buffer.
  23. It is responsible for creating an ION client, allocating the buffer based on
  24. the heap id, writing some data to this buffer and then exporting the FD
  25. (associated with this buffer) to another process using socket IPC.
  26. This FD is called as buffer FD (which is different than the ION client FD).
  27. The client part (ionapp_import) is the importer of the buffer.
  28. It retrives the FD from the socket data and installs into its address space.
  29. This new FD internally points to the same kernel buffer.
  30. So first it reads the data that is stored in this buffer and prints it.
  31. Then it writes the different size of data (it could be different data) to the
  32. same buffer.
  33. Finally the buffer FD must be closed by both the exporter and importer.
  34. Thus the same kernel buffer is shared among two user space processes using
  35. ION driver and only one time allocation.
  36. Prerequisite:
  37. -------------
  38. This utility works only if /dev/ion interface is present.
  39. The following configs needs to be enabled in kernel to include ion driver.
  40. CONFIG_ANDROID=y
  41. CONFIG_STAGING=y
  42. CONFIG_ION=y
  43. CONFIG_ION_SYSTEM_HEAP=y
  44. This utility requires to be run as root user.
  45. Compile and test:
  46. -----------------
  47. This utility is made to be run as part of kselftest framework in kernel.
  48. To compile and run using kselftest you can simply do the following from the
  49. kernel top directory.
  50. linux$ make TARGETS=android kselftest
  51. Or you can also use:
  52. linux$ make -C tools/testing/selftests TARGETS=android run_tests
  53. Using the selftest it can directly execute the ion_test.sh script to test the
  54. buffer sharing using ion system heap.
  55. Currently the heap size is hard coded as just 10 bytes inside this script.
  56. You need to be a root user to run under selftest.
  57. You can also compile and test manually using the following steps:
  58. ion$ make
  59. These will generate 2 executable: ionapp_export, ionapp_import
  60. Now you can run the export and import manually by specifying the heap type
  61. and the heap size.
  62. You can also directly execute the shell script to run the test automatically.
  63. Simply use the following command to run the test.
  64. ion$ sudo ./ion_test.sh
  65. Test Results:
  66. -------------
  67. The utility is verified on Ubuntu-32 bit system with Linux Kernel 4.14.
  68. Here is the snapshot of the test result using kselftest.
  69. linux# make TARGETS=android kselftest
  70. heap_type: 0, heap_size: 10
  71. --------------------------------------
  72. heap type: 0
  73. heap id: 1
  74. heap name: ion_system_heap
  75. --------------------------------------
  76. Fill buffer content:
  77. 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd
  78. Sharing fd: 6, Client fd: 5
  79. <ion_close_buffer_fd>: buffer release successfully....
  80. Received buffer fd: 4
  81. Read buffer content:
  82. 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0x0 0x0 0x0 0x0 0x0 0x0
  83. 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
  84. Fill buffer content:
  85. 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd
  86. 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd
  87. 0xfd 0xfd
  88. <ion_close_buffer_fd>: buffer release successfully....
  89. ion_test.sh: heap_type: 0 - [PASS]
  90. ion_test.sh: done