Skip to content

Commit b1c2a34

Browse files
committed
Merge tag 'linux-kselftest-4.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull kselftest updates from Shuah Khan: "This update to Kselftest consists of cleanup patches, fixes, and a new test for ion buffer sharing. Fixes include changes to skip firmware tests on systems that aren't configured to support them, as opposed to failing them" * tag 'linux-kselftest-4.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: selftests: firmware: skip unsupported custom firmware fallback tests selftests: firmware: skip unsupported async loading tests selftests: memfd_test.c: fix compilation warning. selftests/ftrace: Introduce exit_pass and exit_fail selftests: ftrace: add more config fragments android/ion: userspace test utility for ion buffer sharing selftests: remove obsolete kconfig fragment for cpu-hotplug selftests: vdso_test: support ARM64 targets selftests/ftrace: Do not use arch dependent do_IRQ as a target function selftests: breakpoints: fix compile error on breakpoint_test_arm64 selftests: add missing test result status in memory-hotplug test selftests/exec: include cwd in long path calculation selftests: seccomp: update .gitignore with newly added tests selftests: vm: Update .gitignore with newly added tests selftests: timers: Update .gitignore with newly added tests
2 parents 190b103 + c3e0d17 commit b1c2a34

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1303
-71
lines changed

tools/testing/selftests/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0
2-
TARGETS = bpf
2+
TARGETS = android
3+
TARGETS += bpf
34
TARGETS += breakpoints
45
TARGETS += capabilities
56
TARGETS += cpufreq
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
SUBDIRS := ion
2+
3+
TEST_PROGS := run.sh
4+
5+
.PHONY: all clean
6+
7+
include ../lib.mk
8+
9+
all:
10+
@for DIR in $(SUBDIRS); do \
11+
BUILD_TARGET=$(OUTPUT)/$$DIR; \
12+
mkdir $$BUILD_TARGET -p; \
13+
make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\
14+
#SUBDIR test prog name should be in the form: SUBDIR_test.sh
15+
TEST=$$DIR"_test.sh"; \
16+
if [ -e $$DIR/$$TEST ]; then
17+
rsync -a $$DIR/$$TEST $$BUILD_TARGET/;
18+
fi
19+
done
20+
21+
override define RUN_TESTS
22+
@cd $(OUTPUT); ./run.sh
23+
endef
24+
25+
override define INSTALL_RULE
26+
mkdir -p $(INSTALL_PATH)
27+
install -t $(INSTALL_PATH) $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES)
28+
29+
@for SUBDIR in $(SUBDIRS); do \
30+
BUILD_TARGET=$(OUTPUT)/$$SUBDIR; \
31+
mkdir $$BUILD_TARGET -p; \
32+
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$SUBDIR INSTALL_PATH=$(INSTALL_PATH)/$$SUBDIR install; \
33+
done;
34+
endef
35+
36+
override define EMIT_TESTS
37+
echo "./run.sh"
38+
endef
39+
40+
override define CLEAN
41+
@for DIR in $(SUBDIRS); do \
42+
BUILD_TARGET=$(OUTPUT)/$$DIR; \
43+
mkdir $$BUILD_TARGET -p; \
44+
make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\
45+
done
46+
endef
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ionapp_export
2+
ionapp_import
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
INCLUDEDIR := -I. -I../../../../../drivers/staging/android/uapi/
3+
CFLAGS := $(CFLAGS) $(INCLUDEDIR) -Wall -O2 -g
4+
5+
TEST_GEN_FILES := ionapp_export ionapp_import
6+
7+
all: $(TEST_GEN_FILES)
8+
9+
$(TEST_GEN_FILES): ipcsocket.c ionutils.c
10+
11+
TEST_PROGS := ion_test.sh
12+
13+
include ../../lib.mk
14+
15+
$(OUTPUT)/ionapp_export: ionapp_export.c ipcsocket.c ionutils.c
16+
$(OUTPUT)/ionapp_import: ionapp_import.c ipcsocket.c ionutils.c
+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
ION BUFFER SHARING UTILITY
2+
==========================
3+
File: ion_test.sh : Utility to test ION driver buffer sharing mechanism.
4+
Author: Pintu Kumar <[email protected]>
5+
6+
Introduction:
7+
-------------
8+
This is a test utility to verify ION buffer sharing in user space
9+
between 2 independent processes.
10+
It uses unix domain socket (with SCM_RIGHTS) as IPC to transfer an FD to
11+
another process to share the same buffer.
12+
This utility demonstrates how ION buffer sharing can be implemented between
13+
two user space processes, using various heap types.
14+
The following heap types are supported by ION driver.
15+
ION_HEAP_TYPE_SYSTEM (0)
16+
ION_HEAP_TYPE_SYSTEM_CONTIG (1)
17+
ION_HEAP_TYPE_CARVEOUT (2)
18+
ION_HEAP_TYPE_CHUNK (3)
19+
ION_HEAP_TYPE_DMA (4)
20+
21+
By default only the SYSTEM and SYSTEM_CONTIG heaps are supported.
22+
Each heap is associated with the respective heap id.
23+
This utility is designed in the form of client/server program.
24+
The server part (ionapp_export) is the exporter of the buffer.
25+
It is responsible for creating an ION client, allocating the buffer based on
26+
the heap id, writing some data to this buffer and then exporting the FD
27+
(associated with this buffer) to another process using socket IPC.
28+
This FD is called as buffer FD (which is different than the ION client FD).
29+
30+
The client part (ionapp_import) is the importer of the buffer.
31+
It retrives the FD from the socket data and installs into its address space.
32+
This new FD internally points to the same kernel buffer.
33+
So first it reads the data that is stored in this buffer and prints it.
34+
Then it writes the different size of data (it could be different data) to the
35+
same buffer.
36+
Finally the buffer FD must be closed by both the exporter and importer.
37+
Thus the same kernel buffer is shared among two user space processes using
38+
ION driver and only one time allocation.
39+
40+
Prerequisite:
41+
-------------
42+
This utility works only if /dev/ion interface is present.
43+
The following configs needs to be enabled in kernel to include ion driver.
44+
CONFIG_ANDROID=y
45+
CONFIG_STAGING=y
46+
CONFIG_ION=y
47+
CONFIG_ION_SYSTEM_HEAP=y
48+
49+
This utility requires to be run as root user.
50+
51+
52+
Compile and test:
53+
-----------------
54+
This utility is made to be run as part of kselftest framework in kernel.
55+
To compile and run using kselftest you can simply do the following from the
56+
kernel top directory.
57+
linux$ make TARGETS=android kselftest
58+
Or you can also use:
59+
linux$ make -C tools/testing/selftests TARGETS=android run_tests
60+
Using the selftest it can directly execute the ion_test.sh script to test the
61+
buffer sharing using ion system heap.
62+
Currently the heap size is hard coded as just 10 bytes inside this script.
63+
You need to be a root user to run under selftest.
64+
65+
You can also compile and test manually using the following steps:
66+
ion$ make
67+
These will generate 2 executable: ionapp_export, ionapp_import
68+
Now you can run the export and import manually by specifying the heap type
69+
and the heap size.
70+
You can also directly execute the shell script to run the test automatically.
71+
Simply use the following command to run the test.
72+
ion$ sudo ./ion_test.sh
73+
74+
Test Results:
75+
-------------
76+
The utility is verified on Ubuntu-32 bit system with Linux Kernel 4.14.
77+
Here is the snapshot of the test result using kselftest.
78+
79+
linux# make TARGETS=android kselftest
80+
heap_type: 0, heap_size: 10
81+
--------------------------------------
82+
heap type: 0
83+
heap id: 1
84+
heap name: ion_system_heap
85+
--------------------------------------
86+
Fill buffer content:
87+
0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd
88+
Sharing fd: 6, Client fd: 5
89+
<ion_close_buffer_fd>: buffer release successfully....
90+
Received buffer fd: 4
91+
Read buffer content:
92+
0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0x0 0x0 0x0 0x0 0x0 0x0
93+
0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
94+
Fill buffer content:
95+
0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd
96+
0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd
97+
0xfd 0xfd
98+
<ion_close_buffer_fd>: buffer release successfully....
99+
ion_test.sh: heap_type: 0 - [PASS]
100+
101+
ion_test.sh: done
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CONFIG_ANDROID=y
2+
CONFIG_STAGING=y
3+
CONFIG_ION=y
4+
CONFIG_ION_SYSTEM_HEAP=y
+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/*
2+
* ion.h
3+
*
4+
* Copyright (C) 2011 Google, Inc.
5+
*
6+
* This software is licensed under the terms of the GNU General Public
7+
* License version 2, as published by the Free Software Foundation, and
8+
* may be copied, distributed, and modified under those terms.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
*/
16+
17+
/* This file is copied from drivers/staging/android/uapi/ion.h
18+
* This local copy is required for the selftest to pass, when build
19+
* outside the kernel source tree.
20+
* Please keep this file in sync with its original file until the
21+
* ion driver is moved outside the staging tree.
22+
*/
23+
24+
#ifndef _UAPI_LINUX_ION_H
25+
#define _UAPI_LINUX_ION_H
26+
27+
#include <linux/ioctl.h>
28+
#include <linux/types.h>
29+
30+
/**
31+
* enum ion_heap_types - list of all possible types of heaps
32+
* @ION_HEAP_TYPE_SYSTEM: memory allocated via vmalloc
33+
* @ION_HEAP_TYPE_SYSTEM_CONTIG: memory allocated via kmalloc
34+
* @ION_HEAP_TYPE_CARVEOUT: memory allocated from a prereserved
35+
* carveout heap, allocations are physically
36+
* contiguous
37+
* @ION_HEAP_TYPE_DMA: memory allocated via DMA API
38+
* @ION_NUM_HEAPS: helper for iterating over heaps, a bit mask
39+
* is used to identify the heaps, so only 32
40+
* total heap types are supported
41+
*/
42+
enum ion_heap_type {
43+
ION_HEAP_TYPE_SYSTEM,
44+
ION_HEAP_TYPE_SYSTEM_CONTIG,
45+
ION_HEAP_TYPE_CARVEOUT,
46+
ION_HEAP_TYPE_CHUNK,
47+
ION_HEAP_TYPE_DMA,
48+
ION_HEAP_TYPE_CUSTOM, /*
49+
* must be last so device specific heaps always
50+
* are at the end of this enum
51+
*/
52+
};
53+
54+
#define ION_NUM_HEAP_IDS (sizeof(unsigned int) * 8)
55+
56+
/**
57+
* allocation flags - the lower 16 bits are used by core ion, the upper 16
58+
* bits are reserved for use by the heaps themselves.
59+
*/
60+
61+
/*
62+
* mappings of this buffer should be cached, ion will do cache maintenance
63+
* when the buffer is mapped for dma
64+
*/
65+
#define ION_FLAG_CACHED 1
66+
67+
/**
68+
* DOC: Ion Userspace API
69+
*
70+
* create a client by opening /dev/ion
71+
* most operations handled via following ioctls
72+
*
73+
*/
74+
75+
/**
76+
* struct ion_allocation_data - metadata passed from userspace for allocations
77+
* @len: size of the allocation
78+
* @heap_id_mask: mask of heap ids to allocate from
79+
* @flags: flags passed to heap
80+
* @handle: pointer that will be populated with a cookie to use to
81+
* refer to this allocation
82+
*
83+
* Provided by userspace as an argument to the ioctl
84+
*/
85+
struct ion_allocation_data {
86+
__u64 len;
87+
__u32 heap_id_mask;
88+
__u32 flags;
89+
__u32 fd;
90+
__u32 unused;
91+
};
92+
93+
#define MAX_HEAP_NAME 32
94+
95+
/**
96+
* struct ion_heap_data - data about a heap
97+
* @name - first 32 characters of the heap name
98+
* @type - heap type
99+
* @heap_id - heap id for the heap
100+
*/
101+
struct ion_heap_data {
102+
char name[MAX_HEAP_NAME];
103+
__u32 type;
104+
__u32 heap_id;
105+
__u32 reserved0;
106+
__u32 reserved1;
107+
__u32 reserved2;
108+
};
109+
110+
/**
111+
* struct ion_heap_query - collection of data about all heaps
112+
* @cnt - total number of heaps to be copied
113+
* @heaps - buffer to copy heap data
114+
*/
115+
struct ion_heap_query {
116+
__u32 cnt; /* Total number of heaps to be copied */
117+
__u32 reserved0; /* align to 64bits */
118+
__u64 heaps; /* buffer to be populated */
119+
__u32 reserved1;
120+
__u32 reserved2;
121+
};
122+
123+
#define ION_IOC_MAGIC 'I'
124+
125+
/**
126+
* DOC: ION_IOC_ALLOC - allocate memory
127+
*
128+
* Takes an ion_allocation_data struct and returns it with the handle field
129+
* populated with the opaque handle for the allocation.
130+
*/
131+
#define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \
132+
struct ion_allocation_data)
133+
134+
/**
135+
* DOC: ION_IOC_HEAP_QUERY - information about available heaps
136+
*
137+
* Takes an ion_heap_query structure and populates information about
138+
* available Ion heaps.
139+
*/
140+
#define ION_IOC_HEAP_QUERY _IOWR(ION_IOC_MAGIC, 8, \
141+
struct ion_heap_query)
142+
143+
#endif /* _UAPI_LINUX_ION_H */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
3+
heapsize=4096
4+
TCID="ion_test.sh"
5+
errcode=0
6+
7+
run_test()
8+
{
9+
heaptype=$1
10+
./ionapp_export -i $heaptype -s $heapsize &
11+
sleep 1
12+
./ionapp_import
13+
if [ $? -ne 0 ]; then
14+
echo "$TCID: heap_type: $heaptype - [FAIL]"
15+
errcode=1
16+
else
17+
echo "$TCID: heap_type: $heaptype - [PASS]"
18+
fi
19+
sleep 1
20+
echo ""
21+
}
22+
23+
check_root()
24+
{
25+
uid=$(id -u)
26+
if [ $uid -ne 0 ]; then
27+
echo $TCID: must be run as root >&2
28+
exit 0
29+
fi
30+
}
31+
32+
check_device()
33+
{
34+
DEVICE=/dev/ion
35+
if [ ! -e $DEVICE ]; then
36+
echo $TCID: No $DEVICE device found >&2
37+
echo $TCID: May be CONFIG_ION is not set >&2
38+
exit 0
39+
fi
40+
}
41+
42+
main_function()
43+
{
44+
check_device
45+
check_root
46+
47+
# ION_SYSTEM_HEAP TEST
48+
run_test 0
49+
# ION_SYSTEM_CONTIG_HEAP TEST
50+
run_test 1
51+
}
52+
53+
main_function
54+
echo "$TCID: done"
55+
exit $errcode

0 commit comments

Comments
 (0)