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